generic_import.carbon 12 KB

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