generic_import.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/generic_import.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/generic_import.carbon
  14. // --- a.carbon
  15. library "[[@TEST_NAME]]";
  16. interface AddWith(T:! type) {
  17. fn F();
  18. }
  19. // --- b.carbon
  20. library "[[@TEST_NAME]]";
  21. import library "a";
  22. class C {}
  23. impl C as AddWith(C) {
  24. fn F() {}
  25. }
  26. // CHECK:STDOUT: --- a.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  30. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  31. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
  32. // CHECK:STDOUT: %pattern_type: type = pattern_type type [concrete]
  33. // CHECK:STDOUT: %AddWith.type.b35: type = generic_interface_type @AddWith [concrete]
  34. // CHECK:STDOUT: %AddWith.generic: %AddWith.type.b35 = struct_value () [concrete]
  35. // CHECK:STDOUT: %AddWith.type.302: type = facet_type <@AddWith, @AddWith(%T)> [symbolic]
  36. // CHECK:STDOUT: %Self: %AddWith.type.302 = symbolic_binding Self, 1 [symbolic]
  37. // CHECK:STDOUT: %AddWith.F.type: type = fn_type @AddWith.F, @AddWith(%T) [symbolic]
  38. // CHECK:STDOUT: %AddWith.F: %AddWith.F.type = struct_value () [symbolic]
  39. // CHECK:STDOUT: %AddWith.assoc_type: type = assoc_entity_type @AddWith, @AddWith(%T) [symbolic]
  40. // CHECK:STDOUT: %assoc0: %AddWith.assoc_type = assoc_entity element0, @AddWith.%AddWith.F.decl [symbolic]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  45. // CHECK:STDOUT: .AddWith = %AddWith.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %AddWith.decl: %AddWith.type.b35 = interface_decl @AddWith [concrete = constants.%AddWith.generic] {
  48. // CHECK:STDOUT: %T.patt: %pattern_type = symbolic_binding_pattern T, 0 [concrete]
  49. // CHECK:STDOUT: } {
  50. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  51. // CHECK:STDOUT: %T.loc4_19.2: type = symbolic_binding T, 0 [symbolic = %T.loc4_19.1 (constants.%T)]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: generic interface @AddWith(%T.loc4_19.2: type) {
  56. // CHECK:STDOUT: %T.loc4_19.1: type = symbolic_binding T, 0 [symbolic = %T.loc4_19.1 (constants.%T)]
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: !definition:
  59. // CHECK:STDOUT: %AddWith.type: type = facet_type <@AddWith, @AddWith(%T.loc4_19.1)> [symbolic = %AddWith.type (constants.%AddWith.type.302)]
  60. // CHECK:STDOUT: %Self.loc4_29.2: @AddWith.%AddWith.type (%AddWith.type.302) = symbolic_binding Self, 1 [symbolic = %Self.loc4_29.2 (constants.%Self)]
  61. // CHECK:STDOUT: %AddWith.F.type: type = fn_type @AddWith.F, @AddWith(%T.loc4_19.1) [symbolic = %AddWith.F.type (constants.%AddWith.F.type)]
  62. // CHECK:STDOUT: %AddWith.F: @AddWith.%AddWith.F.type (%AddWith.F.type) = struct_value () [symbolic = %AddWith.F (constants.%AddWith.F)]
  63. // CHECK:STDOUT: %AddWith.assoc_type: type = assoc_entity_type @AddWith, @AddWith(%T.loc4_19.1) [symbolic = %AddWith.assoc_type (constants.%AddWith.assoc_type)]
  64. // CHECK:STDOUT: %assoc0.loc5_9.2: @AddWith.%AddWith.assoc_type (%AddWith.assoc_type) = assoc_entity element0, %AddWith.F.decl [symbolic = %assoc0.loc5_9.2 (constants.%assoc0)]
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: interface {
  67. // CHECK:STDOUT: %Self.loc4_29.1: @AddWith.%AddWith.type (%AddWith.type.302) = symbolic_binding Self, 1 [symbolic = %Self.loc4_29.2 (constants.%Self)]
  68. // CHECK:STDOUT: %AddWith.F.decl: @AddWith.%AddWith.F.type (%AddWith.F.type) = fn_decl @AddWith.F [symbolic = @AddWith.%AddWith.F (constants.%AddWith.F)] {} {}
  69. // CHECK:STDOUT: %assoc0.loc5_9.1: @AddWith.%AddWith.assoc_type (%AddWith.assoc_type) = assoc_entity element0, %AddWith.F.decl [symbolic = %assoc0.loc5_9.2 (constants.%assoc0)]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = %Self.loc4_29.1
  73. // CHECK:STDOUT: .F = %assoc0.loc5_9.1
  74. // CHECK:STDOUT: witness = (%AddWith.F.decl)
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !requires:
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: generic fn @AddWith.F(@AddWith.%T.loc4_19.2: type, @AddWith.%Self.loc4_29.1: @AddWith.%AddWith.type (%AddWith.type.302)) {
  81. // CHECK:STDOUT: fn();
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: specific @AddWith(constants.%T) {
  85. // CHECK:STDOUT: %T.loc4_19.1 => constants.%T
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: specific @AddWith.F(constants.%T, constants.%Self) {}
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: --- b.carbon
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: constants {
  93. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  94. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  95. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  96. // CHECK:STDOUT: %AddWith.type.b35: type = generic_interface_type @AddWith [concrete]
  97. // CHECK:STDOUT: %AddWith.generic: %AddWith.type.b35 = struct_value () [concrete]
  98. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
  99. // CHECK:STDOUT: %AddWith.type.302: type = facet_type <@AddWith, @AddWith(%T)> [symbolic]
  100. // CHECK:STDOUT: %Self.236: %AddWith.type.302 = symbolic_binding Self, 1 [symbolic]
  101. // CHECK:STDOUT: %AddWith.F.type.d64: type = fn_type @AddWith.F, @AddWith(%T) [symbolic]
  102. // CHECK:STDOUT: %AddWith.F.fa8: %AddWith.F.type.d64 = struct_value () [symbolic]
  103. // CHECK:STDOUT: %AddWith.assoc_type.fb4: type = assoc_entity_type @AddWith, @AddWith(%T) [symbolic]
  104. // CHECK:STDOUT: %assoc0.9a4: %AddWith.assoc_type.fb4 = assoc_entity element0, imports.%Main.import_ref.543 [symbolic]
  105. // CHECK:STDOUT: %AddWith.type.bf6: type = facet_type <@AddWith, @AddWith(%C)> [concrete]
  106. // CHECK:STDOUT: %Self.991: %AddWith.type.bf6 = symbolic_binding Self, 1 [symbolic]
  107. // CHECK:STDOUT: %AddWith.F.type.cd2: type = fn_type @AddWith.F, @AddWith(%C) [concrete]
  108. // CHECK:STDOUT: %AddWith.F.b58: %AddWith.F.type.cd2 = struct_value () [concrete]
  109. // CHECK:STDOUT: %AddWith.assoc_type.3f0: type = assoc_entity_type @AddWith, @AddWith(%C) [concrete]
  110. // CHECK:STDOUT: %assoc0.c0b: %AddWith.assoc_type.3f0 = assoc_entity element0, imports.%Main.import_ref.543 [concrete]
  111. // CHECK:STDOUT: %AddWith.impl_witness: <witness> = impl_witness file.%AddWith.impl_witness_table [concrete]
  112. // CHECK:STDOUT: %C.as.AddWith.impl.F.type: type = fn_type @C.as.AddWith.impl.F [concrete]
  113. // CHECK:STDOUT: %C.as.AddWith.impl.F: %C.as.AddWith.impl.F.type = struct_value () [concrete]
  114. // CHECK:STDOUT: %AddWith.facet: %AddWith.type.bf6 = facet_value %C, (%AddWith.impl_witness) [concrete]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: imports {
  118. // CHECK:STDOUT: %Main.AddWith: %AddWith.type.b35 = import_ref Main//a, AddWith, loaded [concrete = constants.%AddWith.generic]
  119. // CHECK:STDOUT: %Main.import_ref.efcd44.1: type = import_ref Main//a, loc4_19, loaded [symbolic = @AddWith.%T (constants.%T)]
  120. // CHECK:STDOUT: %Main.import_ref.833 = import_ref Main//a, loc4_29, unloaded
  121. // CHECK:STDOUT: %Main.import_ref.073 = import_ref Main//a, loc5_9, unloaded
  122. // CHECK:STDOUT: %Main.F: @AddWith.%AddWith.F.type (%AddWith.F.type.d64) = import_ref Main//a, F, loaded [symbolic = @AddWith.%AddWith.F (constants.%AddWith.F.fa8)]
  123. // CHECK:STDOUT: %Main.import_ref.efcd44.2: type = import_ref Main//a, loc4_19, loaded [symbolic = @AddWith.%T (constants.%T)]
  124. // CHECK:STDOUT: %Main.import_ref.2bd: @AddWith.%AddWith.type (%AddWith.type.302) = import_ref Main//a, loc4_29, loaded [symbolic = @AddWith.%Self (constants.%Self.236)]
  125. // CHECK:STDOUT: %Main.import_ref.543 = import_ref Main//a, loc5_9, unloaded
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: file {
  129. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  130. // CHECK:STDOUT: .AddWith = imports.%Main.AddWith
  131. // CHECK:STDOUT: .C = %C.decl
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %default.import = import <none>
  134. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  135. // CHECK:STDOUT: impl_decl @C.as.AddWith.impl [concrete] {} {
  136. // CHECK:STDOUT: %C.ref.loc7_6: type = name_ref C, file.%C.decl [concrete = constants.%C]
  137. // CHECK:STDOUT: %AddWith.ref: %AddWith.type.b35 = name_ref AddWith, imports.%Main.AddWith [concrete = constants.%AddWith.generic]
  138. // CHECK:STDOUT: %C.ref.loc7_19: type = name_ref C, file.%C.decl [concrete = constants.%C]
  139. // CHECK:STDOUT: %AddWith.type: type = facet_type <@AddWith, @AddWith(constants.%C)> [concrete = constants.%AddWith.type.bf6]
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %AddWith.impl_witness_table = impl_witness_table (@C.as.AddWith.impl.%C.as.AddWith.impl.F.decl), @C.as.AddWith.impl [concrete]
  142. // CHECK:STDOUT: %AddWith.impl_witness: <witness> = impl_witness %AddWith.impl_witness_table [concrete = constants.%AddWith.impl_witness]
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: generic interface @AddWith(imports.%Main.import_ref.efcd44.1: type) [from "a.carbon"] {
  146. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic = %T (constants.%T)]
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: !definition:
  149. // CHECK:STDOUT: %AddWith.type: type = facet_type <@AddWith, @AddWith(%T)> [symbolic = %AddWith.type (constants.%AddWith.type.302)]
  150. // CHECK:STDOUT: %Self: @AddWith.%AddWith.type (%AddWith.type.302) = symbolic_binding Self, 1 [symbolic = %Self (constants.%Self.236)]
  151. // CHECK:STDOUT: %AddWith.F.type: type = fn_type @AddWith.F, @AddWith(%T) [symbolic = %AddWith.F.type (constants.%AddWith.F.type.d64)]
  152. // CHECK:STDOUT: %AddWith.F: @AddWith.%AddWith.F.type (%AddWith.F.type.d64) = struct_value () [symbolic = %AddWith.F (constants.%AddWith.F.fa8)]
  153. // CHECK:STDOUT: %AddWith.assoc_type: type = assoc_entity_type @AddWith, @AddWith(%T) [symbolic = %AddWith.assoc_type (constants.%AddWith.assoc_type.fb4)]
  154. // CHECK:STDOUT: %assoc0: @AddWith.%AddWith.assoc_type (%AddWith.assoc_type.fb4) = assoc_entity element0, imports.%Main.import_ref.543 [symbolic = %assoc0 (constants.%assoc0.9a4)]
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: interface {
  157. // CHECK:STDOUT: !members:
  158. // CHECK:STDOUT: .Self = imports.%Main.import_ref.833
  159. // CHECK:STDOUT: .F = imports.%Main.import_ref.073
  160. // CHECK:STDOUT: witness = (imports.%Main.F)
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: !requires:
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: impl @C.as.AddWith.impl: %C.ref.loc7_6 as %AddWith.type {
  167. // CHECK:STDOUT: %C.as.AddWith.impl.F.decl: %C.as.AddWith.impl.F.type = fn_decl @C.as.AddWith.impl.F [concrete = constants.%C.as.AddWith.impl.F] {} {}
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: !members:
  170. // CHECK:STDOUT: .F = %C.as.AddWith.impl.F.decl
  171. // CHECK:STDOUT: witness = file.%AddWith.impl_witness
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: class @C {
  175. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  176. // CHECK:STDOUT: complete_type_witness = %complete_type
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: !members:
  179. // CHECK:STDOUT: .Self = constants.%C
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: generic fn @AddWith.F(imports.%Main.import_ref.efcd44.2: type, imports.%Main.import_ref.2bd: @AddWith.%AddWith.type (%AddWith.type.302)) [from "a.carbon"] {
  183. // CHECK:STDOUT: fn;
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @C.as.AddWith.impl.F() {
  187. // CHECK:STDOUT: !entry:
  188. // CHECK:STDOUT: return
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: specific @AddWith(constants.%T) {
  192. // CHECK:STDOUT: %T => constants.%T
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: specific @AddWith.F(constants.%T, constants.%Self.236) {}
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: specific @AddWith(constants.%C) {
  198. // CHECK:STDOUT: %T => constants.%C
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: !definition:
  201. // CHECK:STDOUT: %AddWith.type => constants.%AddWith.type.bf6
  202. // CHECK:STDOUT: %Self => constants.%Self.991
  203. // CHECK:STDOUT: %AddWith.F.type => constants.%AddWith.F.type.cd2
  204. // CHECK:STDOUT: %AddWith.F => constants.%AddWith.F.b58
  205. // CHECK:STDOUT: %AddWith.assoc_type => constants.%AddWith.assoc_type.3f0
  206. // CHECK:STDOUT: %assoc0 => constants.%assoc0.c0b
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: specific @AddWith.F(constants.%C, constants.%AddWith.facet) {}
  210. // CHECK:STDOUT: