import.carbon 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/array/import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/import.carbon
  12. // --- library.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F() -> array(i32, 42);
  15. // --- user.carbon
  16. import library "library";
  17. fn G(n: i32) -> i32 {
  18. //@dump-sem-ir-begin
  19. return F()[n];
  20. //@dump-sem-ir-end
  21. }
  22. // --- symbolic_decl.carbon
  23. library "[[@TEST_NAME]]";
  24. interface I {
  25. let value:! array(i32, 1);
  26. }
  27. class C {}
  28. impl C as I where .value = (1,) {}
  29. // --- import_symbolic_decl.carbon
  30. library "[[@TEST_NAME]]";
  31. import library "symbolic_decl";
  32. fn F() -> i32 {
  33. //@dump-sem-ir-begin
  34. let a: array(i32, 1) = (C as I).value;
  35. //@dump-sem-ir-end
  36. return a[0];
  37. }
  38. // CHECK:STDOUT: --- user.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  42. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  43. // CHECK:STDOUT: %N: Core.IntLiteral = symbolic_binding N, 0 [symbolic]
  44. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  45. // CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [concrete]
  46. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  47. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  48. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  49. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  50. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  51. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.824: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  52. // CHECK:STDOUT: %Int.as.Copy.impl.Op.9b9: %Int.as.Copy.impl.Op.type.824 = struct_value () [symbolic]
  53. // CHECK:STDOUT: %Copy.impl_witness.f17: <witness> = impl_witness imports.%Copy.impl_witness_table.e76, @Int.as.Copy.impl(%int_32) [concrete]
  54. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.546: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  55. // CHECK:STDOUT: %Int.as.Copy.impl.Op.664: %Int.as.Copy.impl.Op.type.546 = struct_value () [concrete]
  56. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %i32, (%Copy.impl_witness.f17) [concrete]
  57. // CHECK:STDOUT: %Copy.WithSelf.Op.type.081: type = fn_type @Copy.WithSelf.Op, @Copy.WithSelf(%Copy.facet) [concrete]
  58. // CHECK:STDOUT: %.8e2: type = fn_type_with_self_type %Copy.WithSelf.Op.type.081, %Copy.facet [concrete]
  59. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.664, @Int.as.Copy.impl.Op(%int_32) [concrete]
  60. // CHECK:STDOUT: %Destroy.Op.type.bae255.3: type = fn_type @Destroy.Op.loc6_12.3 [concrete]
  61. // CHECK:STDOUT: %Destroy.Op.651ba6.3: %Destroy.Op.type.bae255.3 = struct_value () [concrete]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: imports {
  65. // CHECK:STDOUT: %Main.F: %F.type = import_ref Main//library, F, loaded [concrete = constants.%F]
  66. // CHECK:STDOUT: %Core.import_ref.18d: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.824) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.9b9)]
  67. // CHECK:STDOUT: %Copy.impl_witness_table.e76 = impl_witness_table (%Core.import_ref.18d), @Int.as.Copy.impl [concrete]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @G(%n.param: %i32) -> out %return.param: %i32 {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
  73. // CHECK:STDOUT: %.loc6_12.1: ref %array_type = temporary_storage
  74. // CHECK:STDOUT: %F.call: init %array_type to %.loc6_12.1 = call %F.ref()
  75. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  76. // CHECK:STDOUT: %.loc6_12.2: ref %array_type = temporary %.loc6_12.1, %F.call
  77. // CHECK:STDOUT: %.loc6_15.1: ref %i32 = array_index %.loc6_12.2, %n.ref
  78. // CHECK:STDOUT: %.loc6_15.2: %i32 = acquire_value %.loc6_15.1
  79. // CHECK:STDOUT: %impl.elem0: %.8e2 = impl_witness_access constants.%Copy.impl_witness.f17, element0 [concrete = constants.%Int.as.Copy.impl.Op.664]
  80. // CHECK:STDOUT: %bound_method.loc6_15.1: <bound method> = bound_method %.loc6_15.2, %impl.elem0
  81. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  82. // CHECK:STDOUT: %bound_method.loc6_15.2: <bound method> = bound_method %.loc6_15.2, %specific_fn
  83. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc6_15.2(%.loc6_15.2)
  84. // CHECK:STDOUT: %Destroy.Op.bound: <bound method> = bound_method %.loc6_12.2, constants.%Destroy.Op.651ba6.3
  85. // CHECK:STDOUT: %Destroy.Op.call: init %empty_tuple.type = call %Destroy.Op.bound(%.loc6_12.2)
  86. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @Destroy.Op.loc6_12.1(%self.param: ref %i32.builtin) = "no_op";
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @Destroy.Op.loc6_12.2(%self.param: ref %i32) {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @Destroy.Op.loc6_12.3(%self.param: ref %array_type) {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: return
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: --- import_symbolic_decl.carbon
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: constants {
  104. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  105. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  106. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  107. // CHECK:STDOUT: %array_type: type = array_type %int_1.5b8, %i32 [concrete]
  108. // CHECK:STDOUT: %pattern_type.a98: type = pattern_type %array_type [concrete]
  109. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  110. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  111. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  112. // CHECK:STDOUT: %array: %array_type = tuple_value (%int_1.5d2) [concrete]
  113. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness imports.%I.impl_witness_table [concrete]
  114. // CHECK:STDOUT: %I.facet: %I.type = facet_value %C, (%I.impl_witness) [concrete]
  115. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  116. // CHECK:STDOUT: %assoc0.5b3: %I.assoc_type = assoc_entity element0, imports.%Main.import_ref.ae1 [concrete]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: imports {
  120. // CHECK:STDOUT: %Main.I: type = import_ref Main//symbolic_decl, I, loaded [concrete = constants.%I.type]
  121. // CHECK:STDOUT: %Main.C: type = import_ref Main//symbolic_decl, C, loaded [concrete = constants.%C]
  122. // CHECK:STDOUT: %Main.import_ref.353: %I.assoc_type = import_ref Main//symbolic_decl, loc5_12, loaded [concrete = constants.%assoc0.5b3]
  123. // CHECK:STDOUT: %Main.import_ref.e29: %array_type = import_ref Main//symbolic_decl, loc10_33, loaded [concrete = constants.%array]
  124. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (%Main.import_ref.e29), @C.as.I.impl [concrete]
  125. // CHECK:STDOUT: %Main.import_ref.ae1: %array_type = import_ref Main//symbolic_decl, loc5_12, loaded [concrete = %value]
  126. // CHECK:STDOUT: %value: %array_type = assoc_const_decl @value [concrete] {}
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @F() -> out %return.param: %i32 {
  130. // CHECK:STDOUT: !entry:
  131. // CHECK:STDOUT: name_binding_decl {
  132. // CHECK:STDOUT: %a.patt: %pattern_type.a98 = value_binding_pattern a [concrete]
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Main.C [concrete = constants.%C]
  135. // CHECK:STDOUT: %I.ref: type = name_ref I, imports.%Main.I [concrete = constants.%I.type]
  136. // CHECK:STDOUT: %I.facet: %I.type = facet_value %C.ref, (constants.%I.impl_witness) [concrete = constants.%I.facet]
  137. // CHECK:STDOUT: %.loc7_29: %I.type = converted %C.ref, %I.facet [concrete = constants.%I.facet]
  138. // CHECK:STDOUT: %as_type: type = facet_access_type %.loc7_29 [concrete = constants.%C]
  139. // CHECK:STDOUT: %.loc7_34: type = converted %.loc7_29, %as_type [concrete = constants.%C]
  140. // CHECK:STDOUT: %value.ref: %I.assoc_type = name_ref value, imports.%Main.import_ref.353 [concrete = constants.%assoc0.5b3]
  141. // CHECK:STDOUT: %impl.elem0.loc7: %array_type = impl_witness_access constants.%I.impl_witness, element0 [concrete = constants.%array]
  142. // CHECK:STDOUT: %.loc7_22: type = splice_block %array_type [concrete = constants.%array_type] {
  143. // CHECK:STDOUT: %i32.loc7: type = type_literal constants.%i32 [concrete = constants.%i32]
  144. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  145. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32.loc7 [concrete = constants.%array_type]
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %a: %array_type = value_binding a, %impl.elem0.loc7
  148. // CHECK:STDOUT: <elided>
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: