import.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/import.carbon
  12. // --- header.h
  13. auto foo_short(short x) -> void;
  14. auto foo_int(int x) -> void;
  15. // --- api.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "header.h";
  18. alias FooShort = Cpp.foo_short;
  19. alias FooInt = Cpp.foo_int;
  20. // --- fail_todo_import_api.carbon
  21. // CHECK:STDERR: fail_todo_import_api.carbon: error: semantics TODO: `Unsupported: Importing C++ functions that require thunks indirectly` [SemanticsTodo]
  22. // CHECK:STDERR:
  23. library "[[@TEST_NAME]]";
  24. import library "api";
  25. fn F() {
  26. //@dump-sem-ir-begin
  27. FooShort(8 as i16);
  28. FooInt(9);
  29. //@dump-sem-ir-end
  30. }
  31. // CHECK:STDOUT: --- fail_todo_import_api.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  35. // CHECK:STDOUT: %foo_short.type: type = fn_type @foo_short [concrete]
  36. // CHECK:STDOUT: %foo_short: %foo_short.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete]
  38. // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete]
  39. // CHECK:STDOUT: %int_8.b85: Core.IntLiteral = int_value 8 [concrete]
  40. // CHECK:STDOUT: %As.type.f58: type = facet_type <@As, @As(%i16)> [concrete]
  41. // CHECK:STDOUT: %As.Convert.type.8b6: type = fn_type @As.Convert, @As(%i16) [concrete]
  42. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.0b2: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  44. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.6d7: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.0b2 = struct_value () [symbolic]
  45. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.6c8: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%To) [symbolic]
  46. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.1ee: %Core.IntLiteral.as.As.impl.Convert.type.6c8 = struct_value () [symbolic]
  47. // CHECK:STDOUT: %As.impl_witness.ef2: <witness> = impl_witness imports.%As.impl_witness_table.a72, @Core.IntLiteral.as.As.impl(%int_16) [concrete]
  48. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.type.fee: type = fn_type @Core.IntLiteral.as.As.impl.Convert, @Core.IntLiteral.as.As.impl(%int_16) [concrete]
  49. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.dc5: %Core.IntLiteral.as.As.impl.Convert.type.fee = struct_value () [concrete]
  50. // CHECK:STDOUT: %As.facet: %As.type.f58 = facet_value Core.IntLiteral, (%As.impl_witness.ef2) [concrete]
  51. // CHECK:STDOUT: %.026: type = fn_type_with_self_type %As.Convert.type.8b6, %As.facet [concrete]
  52. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.bound: <bound method> = bound_method %int_8.b85, %Core.IntLiteral.as.As.impl.Convert.dc5 [concrete]
  53. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.As.impl.Convert.dc5, @Core.IntLiteral.as.As.impl.Convert(%int_16) [concrete]
  54. // CHECK:STDOUT: %bound_method.b6e: <bound method> = bound_method %int_8.b85, %Core.IntLiteral.as.As.impl.Convert.specific_fn [concrete]
  55. // CHECK:STDOUT: %int_8.892: %i16 = int_value 8 [concrete]
  56. // CHECK:STDOUT: %foo_int.type: type = fn_type @foo_int [concrete]
  57. // CHECK:STDOUT: %foo_int: %foo_int.type = struct_value () [concrete]
  58. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  59. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  60. // CHECK:STDOUT: %int_9.988: Core.IntLiteral = int_value 9 [concrete]
  61. // CHECK:STDOUT: %ImplicitAs.type.9ba: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  62. // CHECK:STDOUT: %ImplicitAs.Convert.type.6da: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  63. // CHECK:STDOUT: %ImplicitAs.impl_witness.e34: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.e36, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  64. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.ed5: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  65. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.16d: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.ed5 = struct_value () [concrete]
  66. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.9ba = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.e34) [concrete]
  67. // CHECK:STDOUT: %.d6a: type = fn_type_with_self_type %ImplicitAs.Convert.type.6da, %ImplicitAs.facet [concrete]
  68. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_9.988, %Core.IntLiteral.as.ImplicitAs.impl.Convert.16d [concrete]
  69. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.16d, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  70. // CHECK:STDOUT: %bound_method.8e3: <bound method> = bound_method %int_9.988, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  71. // CHECK:STDOUT: %int_9.114: %i32 = int_value 9 [concrete]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: imports {
  75. // CHECK:STDOUT: %Main.FooShort: %foo_short.type = import_ref Main//api, FooShort, loaded [concrete = constants.%foo_short]
  76. // CHECK:STDOUT: %Main.FooInt: %foo_int.type = import_ref Main//api, FooInt, loaded [concrete = constants.%foo_int]
  77. // CHECK:STDOUT: %Core.import_ref.a86c: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.0b2) = import_ref Core//prelude/parts/int, loc16_39, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.6d7)]
  78. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.e36 = impl_witness_table (%Core.import_ref.a86c), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  79. // CHECK:STDOUT: %Core.import_ref.ea5: @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert.type (%Core.IntLiteral.as.As.impl.Convert.type.6c8) = import_ref Core//prelude/parts/int, loc25_39, loaded [symbolic = @Core.IntLiteral.as.As.impl.%Core.IntLiteral.as.As.impl.Convert (constants.%Core.IntLiteral.as.As.impl.Convert.1ee)]
  80. // CHECK:STDOUT: %As.impl_witness_table.a72 = impl_witness_table (%Core.import_ref.ea5), @Core.IntLiteral.as.As.impl [concrete]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @F() {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %FooShort.ref: %foo_short.type = name_ref FooShort, imports.%Main.FooShort [concrete = constants.%foo_short]
  86. // CHECK:STDOUT: %int_8: Core.IntLiteral = int_value 8 [concrete = constants.%int_8.b85]
  87. // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16]
  88. // CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16]
  89. // CHECK:STDOUT: %impl.elem0.loc10: %.026 = impl_witness_access constants.%As.impl_witness.ef2, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.dc5]
  90. // CHECK:STDOUT: %bound_method.loc10_14.1: <bound method> = bound_method %int_8, %impl.elem0.loc10 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
  91. // CHECK:STDOUT: %specific_fn.loc10: <specific function> = specific_function %impl.elem0.loc10, @Core.IntLiteral.as.As.impl.Convert(constants.%int_16) [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.specific_fn]
  92. // CHECK:STDOUT: %bound_method.loc10_14.2: <bound method> = bound_method %int_8, %specific_fn.loc10 [concrete = constants.%bound_method.b6e]
  93. // CHECK:STDOUT: %Core.IntLiteral.as.As.impl.Convert.call: init %i16 = call %bound_method.loc10_14.2(%int_8) [concrete = constants.%int_8.892]
  94. // CHECK:STDOUT: %.loc10_14.1: %i16 = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_8.892]
  95. // CHECK:STDOUT: %.loc10_14.2: %i16 = converted %int_8, %.loc10_14.1 [concrete = constants.%int_8.892]
  96. // CHECK:STDOUT: %foo_short.call: init %empty_tuple.type = call %FooShort.ref(%.loc10_14.2)
  97. // CHECK:STDOUT: %FooInt.ref: %foo_int.type = name_ref FooInt, imports.%Main.FooInt [concrete = constants.%foo_int]
  98. // CHECK:STDOUT: %int_9: Core.IntLiteral = int_value 9 [concrete = constants.%int_9.988]
  99. // CHECK:STDOUT: %impl.elem0.loc11: %.d6a = impl_witness_access constants.%ImplicitAs.impl_witness.e34, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.16d]
  100. // CHECK:STDOUT: %bound_method.loc11_10.1: <bound method> = bound_method %int_9, %impl.elem0.loc11 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  101. // CHECK:STDOUT: %specific_fn.loc11: <specific function> = specific_function %impl.elem0.loc11, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  102. // CHECK:STDOUT: %bound_method.loc11_10.2: <bound method> = bound_method %int_9, %specific_fn.loc11 [concrete = constants.%bound_method.8e3]
  103. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc11_10.2(%int_9) [concrete = constants.%int_9.114]
  104. // CHECK:STDOUT: %.loc11_10.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_9.114]
  105. // CHECK:STDOUT: %.loc11_10.2: %i32 = converted %int_9, %.loc11_10.1 [concrete = constants.%int_9.114]
  106. // CHECK:STDOUT: %foo_int.call: init %empty_tuple.type = call %FooInt.ref(%.loc11_10.2)
  107. // CHECK:STDOUT: <elided>
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: