import_extend_impl.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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/impl/import_extend_impl.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/import_extend_impl.carbon
  14. // --- extend_impl_library.carbon
  15. library "[[@TEST_NAME]]";
  16. interface I {
  17. fn F();
  18. }
  19. class C {
  20. extend impl as I {
  21. fn F() {}
  22. }
  23. }
  24. // --- use_imported_class_extend_impl.carbon
  25. library "[[@TEST_NAME]]";
  26. import library "extend_impl_library";
  27. fn G(c: C) {
  28. C.F();
  29. c.F();
  30. }
  31. // CHECK:STDOUT: --- extend_impl_library.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  35. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  36. // CHECK:STDOUT: %F.type.cf0: type = fn_type @F.loc5 [concrete]
  37. // CHECK:STDOUT: %F.bc6: %F.type.cf0 = struct_value () [concrete]
  38. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  39. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%F.decl [concrete]
  40. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  41. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness @C.%I.impl_witness_table [concrete]
  42. // CHECK:STDOUT: %F.type.f36: type = fn_type @F.loc10 [concrete]
  43. // CHECK:STDOUT: %F.4c3: %F.type.f36 = struct_value () [concrete]
  44. // CHECK:STDOUT: %I.facet: %I.type = facet_value %C, (%I.impl_witness) [concrete]
  45. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  46. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  51. // CHECK:STDOUT: .I = %I.decl
  52. // CHECK:STDOUT: .C = %C.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  55. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: interface @I {
  59. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  60. // CHECK:STDOUT: %F.decl: %F.type.cf0 = fn_decl @F.loc5 [concrete = constants.%F.bc6] {} {}
  61. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !members:
  64. // CHECK:STDOUT: .Self = %Self
  65. // CHECK:STDOUT: .F = %assoc0
  66. // CHECK:STDOUT: witness = (%F.decl)
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: impl @I.impl: %Self.ref as %I.ref {
  70. // CHECK:STDOUT: %F.decl: %F.type.f36 = fn_decl @F.loc10 [concrete = constants.%F.4c3] {} {}
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !members:
  73. // CHECK:STDOUT: .F = %F.decl
  74. // CHECK:STDOUT: witness = @C.%I.impl_witness
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: class @C {
  78. // CHECK:STDOUT: impl_decl @I.impl [concrete] {} {
  79. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  80. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (@I.impl.%F.decl), @I.impl [concrete]
  83. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness]
  84. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  85. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  86. // CHECK:STDOUT: complete_type_witness = %complete_type
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !members:
  89. // CHECK:STDOUT: .Self = constants.%C
  90. // CHECK:STDOUT: .I = <poisoned>
  91. // CHECK:STDOUT: extend @I.impl.%I.ref
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic fn @F.loc5(@I.%Self: %I.type) {
  95. // CHECK:STDOUT: fn();
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @F.loc10() {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: specific @F.loc5(constants.%Self) {}
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: specific @F.loc5(constants.%I.facet) {}
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: --- use_imported_class_extend_impl.carbon
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: constants {
  110. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  111. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  112. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  113. // CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
  114. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  115. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  116. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  117. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  118. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  119. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  120. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, imports.%Main.import_ref.e03 [concrete]
  121. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness imports.%I.impl_witness_table [concrete]
  122. // CHECK:STDOUT: %F.type.cf0: type = fn_type @F.1 [concrete]
  123. // CHECK:STDOUT: %F.bc6: %F.type.cf0 = struct_value () [concrete]
  124. // CHECK:STDOUT: %I.facet: %I.type = facet_value %C, (%I.impl_witness) [concrete]
  125. // CHECK:STDOUT: %.038: type = fn_type_with_self_type %F.type.cf0, %I.facet [concrete]
  126. // CHECK:STDOUT: %F.type.f36: type = fn_type @F.2 [concrete]
  127. // CHECK:STDOUT: %F.4c3: %F.type.f36 = struct_value () [concrete]
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: imports {
  131. // CHECK:STDOUT: %Main.I = import_ref Main//extend_impl_library, I, unloaded
  132. // CHECK:STDOUT: %Main.C: type = import_ref Main//extend_impl_library, C, loaded [concrete = constants.%C]
  133. // CHECK:STDOUT: %Main.import_ref.8f2: <witness> = import_ref Main//extend_impl_library, loc12_1, loaded [concrete = constants.%complete_type]
  134. // CHECK:STDOUT: %Main.import_ref.2c4 = import_ref Main//extend_impl_library, inst28 [no loc], unloaded
  135. // CHECK:STDOUT: %Main.import_ref.3019d1.1: type = import_ref Main//extend_impl_library, loc9_18, loaded [concrete = constants.%I.type]
  136. // CHECK:STDOUT: %Main.import_ref.e5d = import_ref Main//extend_impl_library, inst17 [no loc], unloaded
  137. // CHECK:STDOUT: %Main.import_ref.c44: %I.assoc_type = import_ref Main//extend_impl_library, loc5_9, loaded [concrete = constants.%assoc0]
  138. // CHECK:STDOUT: %Main.F = import_ref Main//extend_impl_library, F, unloaded
  139. // CHECK:STDOUT: %Main.import_ref.e03: %F.type.cf0 = import_ref Main//extend_impl_library, loc5_9, loaded [concrete = constants.%F.bc6]
  140. // CHECK:STDOUT: %Main.import_ref.9d1: <witness> = import_ref Main//extend_impl_library, loc9_20, loaded [concrete = constants.%I.impl_witness]
  141. // CHECK:STDOUT: %Main.import_ref.0ed: type = import_ref Main//extend_impl_library, loc9_15, loaded [concrete = constants.%C]
  142. // CHECK:STDOUT: %Main.import_ref.3019d1.2: type = import_ref Main//extend_impl_library, loc9_18, loaded [concrete = constants.%I.type]
  143. // CHECK:STDOUT: %Main.import_ref.f6d: %F.type.f36 = import_ref Main//extend_impl_library, loc10_12, loaded [concrete = constants.%F.4c3]
  144. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (%Main.import_ref.f6d), @I.impl [concrete]
  145. // CHECK:STDOUT: %Main.import_ref.5dd: %I.type = import_ref Main//extend_impl_library, inst17 [no loc], loaded [symbolic = constants.%Self]
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: file {
  149. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  150. // CHECK:STDOUT: .I = imports.%Main.I
  151. // CHECK:STDOUT: .C = imports.%Main.C
  152. // CHECK:STDOUT: .G = %G.decl
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: %default.import = import <none>
  155. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  156. // CHECK:STDOUT: %c.patt: %pattern_type = binding_pattern c [concrete]
  157. // CHECK:STDOUT: %c.param_patt: %pattern_type = value_param_pattern %c.patt, call_param0 [concrete]
  158. // CHECK:STDOUT: } {
  159. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  160. // CHECK:STDOUT: %C.ref.loc6: type = name_ref C, imports.%Main.C [concrete = constants.%C]
  161. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: interface @I [from "extend_impl_library.carbon"] {
  166. // CHECK:STDOUT: !members:
  167. // CHECK:STDOUT: .Self = imports.%Main.import_ref.e5d
  168. // CHECK:STDOUT: .F = imports.%Main.import_ref.c44
  169. // CHECK:STDOUT: witness = (imports.%Main.F)
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: impl @I.impl: imports.%Main.import_ref.0ed as imports.%Main.import_ref.3019d1.2 [from "extend_impl_library.carbon"] {
  173. // CHECK:STDOUT: !members:
  174. // CHECK:STDOUT: witness = imports.%Main.import_ref.9d1
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: class @C [from "extend_impl_library.carbon"] {
  178. // CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f2
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: !members:
  181. // CHECK:STDOUT: .Self = imports.%Main.import_ref.2c4
  182. // CHECK:STDOUT: .F = <poisoned>
  183. // CHECK:STDOUT: extend imports.%Main.import_ref.3019d1.1
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @G(%c.param: %C) {
  187. // CHECK:STDOUT: !entry:
  188. // CHECK:STDOUT: %C.ref.loc7: type = name_ref C, imports.%Main.C [concrete = constants.%C]
  189. // CHECK:STDOUT: %F.ref.loc7: %I.assoc_type = name_ref F, imports.%Main.import_ref.c44 [concrete = constants.%assoc0]
  190. // CHECK:STDOUT: %impl.elem0.loc7: %.038 = impl_witness_access constants.%I.impl_witness, element0 [concrete = constants.%F.4c3]
  191. // CHECK:STDOUT: %F.call.loc7: init %empty_tuple.type = call %impl.elem0.loc7()
  192. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  193. // CHECK:STDOUT: %F.ref.loc8: %I.assoc_type = name_ref F, imports.%Main.import_ref.c44 [concrete = constants.%assoc0]
  194. // CHECK:STDOUT: %impl.elem0.loc8: %.038 = impl_witness_access constants.%I.impl_witness, element0 [concrete = constants.%F.4c3]
  195. // CHECK:STDOUT: %F.call.loc8: init %empty_tuple.type = call %impl.elem0.loc8()
  196. // CHECK:STDOUT: return
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: generic fn @F.1(imports.%Main.import_ref.5dd: %I.type) [from "extend_impl_library.carbon"] {
  200. // CHECK:STDOUT: fn;
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: fn @F.2 [from "extend_impl_library.carbon"];
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  206. // CHECK:STDOUT: