import_extend_impl.carbon 9.8 KB

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