extend_impl_generic.carbon 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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/extend_impl_generic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/extend_impl_generic.carbon
  10. // --- extend_impl_generic_interface.carbon
  11. library "[[@TEST_NAME]]";
  12. interface HasF(T:! type) {
  13. fn F() -> T;
  14. }
  15. class Param {
  16. var x: i32;
  17. }
  18. class C {
  19. extend impl as HasF(Param) {
  20. fn F() -> Param {
  21. return {.x = 2};
  22. }
  23. }
  24. }
  25. fn G(c: C) {
  26. let a: i32 = C.F().x;
  27. var b: i32 = c.F().x;
  28. }
  29. // --- extend_impl_generic_class.carbon
  30. library "[[@TEST_NAME]]";
  31. interface I(T:! type) {
  32. fn F[self: Self](t: T);
  33. }
  34. class X(U:! type) {
  35. extend impl as I(U) {
  36. fn F[self: Self](t: U) { }
  37. }
  38. }
  39. // CHECK:STDOUT: --- extend_impl_generic_interface.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  43. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  44. // CHECK:STDOUT: %HasF.type.1: type = generic_interface_type @HasF [template]
  45. // CHECK:STDOUT: %HasF: %HasF.type.1 = struct_value () [template]
  46. // CHECK:STDOUT: %HasF.type.2: type = facet_type <@HasF, @HasF(%T)> [symbolic]
  47. // CHECK:STDOUT: %Self.1: %HasF.type.2 = bind_symbolic_name Self, 1 [symbolic]
  48. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @HasF(%T) [symbolic]
  49. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  50. // CHECK:STDOUT: %.1: type = assoc_entity_type %HasF.type.2, %F.type.1 [symbolic]
  51. // CHECK:STDOUT: %.2: %.1 = assoc_entity element0, @HasF.%F.decl [symbolic]
  52. // CHECK:STDOUT: %Param: type = class_type @Param [template]
  53. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 32 [template]
  54. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  55. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  56. // CHECK:STDOUT: %i32: type = int_type signed, %.3 [template]
  57. // CHECK:STDOUT: %.4: type = unbound_element_type %Param, %i32 [template]
  58. // CHECK:STDOUT: %.5: type = struct_type {.x: %i32} [template]
  59. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  60. // CHECK:STDOUT: %C: type = class_type @C [template]
  61. // CHECK:STDOUT: %HasF.type.3: type = facet_type <@HasF, @HasF(%Param)> [template]
  62. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @HasF(%Param) [template]
  63. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  64. // CHECK:STDOUT: %.7: type = assoc_entity_type %HasF.type.3, %F.type.2 [template]
  65. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, @HasF.%F.decl [template]
  66. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
  67. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  68. // CHECK:STDOUT: %.9: %HasF.type.2 = facet_value %C, %C [symbolic]
  69. // CHECK:STDOUT: %.10: <witness> = interface_witness (%F.3) [template]
  70. // CHECK:STDOUT: %.11: type = struct_type {} [template]
  71. // CHECK:STDOUT: %.12: <witness> = complete_type_witness %.11 [template]
  72. // CHECK:STDOUT: %.14: Core.IntLiteral = int_value 2 [template]
  73. // CHECK:STDOUT: %.15: type = struct_type {.x: Core.IntLiteral} [template]
  74. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  75. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.2(%.3) [template]
  76. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  77. // CHECK:STDOUT: %.39: <witness> = interface_witness (%Convert.14) [template]
  78. // CHECK:STDOUT: %.40: <bound method> = bound_method %.14, %Convert.14 [template]
  79. // CHECK:STDOUT: %.41: <specific function> = specific_function %.40, @Convert.2(%.3) [template]
  80. // CHECK:STDOUT: %.42: %i32 = int_value 2 [template]
  81. // CHECK:STDOUT: %struct: %Param = struct_value (%.42) [template]
  82. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  83. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: imports {
  87. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  88. // CHECK:STDOUT: .Int = %import_ref.1
  89. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  90. // CHECK:STDOUT: import Core//prelude
  91. // CHECK:STDOUT: import Core//prelude/...
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  97. // CHECK:STDOUT: .Core = imports.%Core
  98. // CHECK:STDOUT: .HasF = %HasF.decl
  99. // CHECK:STDOUT: .Param = %Param.decl
  100. // CHECK:STDOUT: .C = %C.decl
  101. // CHECK:STDOUT: .G = %G.decl
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %Core.import = import Core
  104. // CHECK:STDOUT: %HasF.decl: %HasF.type.1 = interface_decl @HasF [template = constants.%HasF] {
  105. // CHECK:STDOUT: %T.patt.loc4_16.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_16.2 (constants.%T.patt)]
  106. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc4_16.1, runtime_param<invalid> [symbolic = %T.patt.loc4_16.2 (constants.%T.patt)]
  107. // CHECK:STDOUT: } {
  108. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  109. // CHECK:STDOUT: %T.loc4_16.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_16.2 (constants.%T)]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %Param.decl: type = class_decl @Param [template = constants.%Param] {} {}
  112. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  113. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  114. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  115. // CHECK:STDOUT: %c.param_patt: %C = value_param_pattern %c.patt, runtime_param0
  116. // CHECK:STDOUT: } {
  117. // CHECK:STDOUT: %C.ref.loc20: type = name_ref C, file.%C.decl [template = constants.%C]
  118. // CHECK:STDOUT: %c.param: %C = value_param runtime_param0
  119. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: generic interface @HasF(%T.loc4_16.1: type) {
  124. // CHECK:STDOUT: %T.loc4_16.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_16.2 (constants.%T)]
  125. // CHECK:STDOUT: %T.patt.loc4_16.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_16.2 (constants.%T.patt)]
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !definition:
  128. // CHECK:STDOUT: %HasF.type: type = facet_type <@HasF, @HasF(%T.loc4_16.2)> [symbolic = %HasF.type (constants.%HasF.type.2)]
  129. // CHECK:STDOUT: %Self.2: %HasF.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.1)]
  130. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @HasF(%T.loc4_16.2) [symbolic = %F.type (constants.%F.type.1)]
  131. // CHECK:STDOUT: %F: @HasF.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  132. // CHECK:STDOUT: %.loc5_14.2: type = assoc_entity_type @HasF.%HasF.type (%HasF.type.2), @HasF.%F.type (%F.type.1) [symbolic = %.loc5_14.2 (constants.%.1)]
  133. // CHECK:STDOUT: %.loc5_14.3: @HasF.%.loc5_14.2 (%.1) = assoc_entity element0, %F.decl [symbolic = %.loc5_14.3 (constants.%.2)]
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: interface {
  136. // CHECK:STDOUT: %Self.1: @HasF.%HasF.type (%HasF.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.1)]
  137. // CHECK:STDOUT: %F.decl: @HasF.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = @HasF.%F (constants.%F.1)] {
  138. // CHECK:STDOUT: %return.patt: @F.1.%T (%T) = return_slot_pattern
  139. // CHECK:STDOUT: %return.param_patt: @F.1.%T (%T) = out_param_pattern %return.patt, runtime_param0
  140. // CHECK:STDOUT: } {
  141. // CHECK:STDOUT: %T.ref: type = name_ref T, @HasF.%T.loc4_16.1 [symbolic = %T (constants.%T)]
  142. // CHECK:STDOUT: %return.param: ref @F.1.%T (%T) = out_param runtime_param0
  143. // CHECK:STDOUT: %return: ref @F.1.%T (%T) = return_slot %return.param
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %.loc5_14.1: @HasF.%.loc5_14.2 (%.1) = assoc_entity element0, %F.decl [symbolic = %.loc5_14.3 (constants.%.2)]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = %Self.1
  149. // CHECK:STDOUT: .F = %.loc5_14.1
  150. // CHECK:STDOUT: witness = (%F.decl)
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: impl @impl.1: %Self.ref as %HasF.type {
  155. // CHECK:STDOUT: %F.decl: %F.type.3 = fn_decl @F.2 [template = constants.%F.3] {
  156. // CHECK:STDOUT: %return.patt: %Param = return_slot_pattern
  157. // CHECK:STDOUT: %return.param_patt: %Param = out_param_pattern %return.patt, runtime_param0
  158. // CHECK:STDOUT: } {
  159. // CHECK:STDOUT: %Param.ref: type = name_ref Param, file.%Param.decl [template = constants.%Param]
  160. // CHECK:STDOUT: %return.param: ref %Param = out_param runtime_param0
  161. // CHECK:STDOUT: %return: ref %Param = return_slot %return.param
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: %.loc13: <witness> = interface_witness (%F.decl) [template = constants.%.10]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .F = %F.decl
  167. // CHECK:STDOUT: witness = %.loc13
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: class @Param {
  171. // CHECK:STDOUT: %.loc9_10.1: Core.IntLiteral = int_value 32 [template = constants.%.3]
  172. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc9_10.1) [template = constants.%i32]
  173. // CHECK:STDOUT: %.loc9_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  174. // CHECK:STDOUT: %.loc9_10.3: type = converted %int.make_type_signed, %.loc9_10.2 [template = constants.%i32]
  175. // CHECK:STDOUT: %.loc9_8: %.4 = field_decl x, element0 [template]
  176. // CHECK:STDOUT: %.loc10: <witness> = complete_type_witness %.5 [template = constants.%.6]
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: !members:
  179. // CHECK:STDOUT: .Self = constants.%Param
  180. // CHECK:STDOUT: .x = %.loc9_8
  181. // CHECK:STDOUT: complete_type_witness = %.loc10
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: class @C {
  185. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  186. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  187. // CHECK:STDOUT: %HasF.ref: %HasF.type.1 = name_ref HasF, file.%HasF.decl [template = constants.%HasF]
  188. // CHECK:STDOUT: %Param.ref: type = name_ref Param, file.%Param.decl [template = constants.%Param]
  189. // CHECK:STDOUT: %HasF.type: type = facet_type <@HasF, @HasF(constants.%Param)> [template = constants.%HasF.type.3]
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT: %.loc18: <witness> = complete_type_witness %.11 [template = constants.%.12]
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: !members:
  194. // CHECK:STDOUT: .Self = constants.%C
  195. // CHECK:STDOUT: extend @impl.1.%HasF.type
  196. // CHECK:STDOUT: complete_type_witness = %.loc18
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: generic fn @F.1(@HasF.%T.loc4_16.1: type, @HasF.%Self.1: @HasF.%HasF.type (%HasF.type.2)) {
  200. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: fn() -> @F.1.%T (%T);
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: fn @F.2() -> %return: %Param {
  206. // CHECK:STDOUT: !entry:
  207. // CHECK:STDOUT: %.loc15_20: Core.IntLiteral = int_value 2 [template = constants.%.14]
  208. // CHECK:STDOUT: %.loc15_21.1: %.15 = struct_literal (%.loc15_20)
  209. // CHECK:STDOUT: %.loc15_21.2: %Convert.type.2 = interface_witness_access constants.%.39, element0 [template = constants.%Convert.14]
  210. // CHECK:STDOUT: %.loc15_21.3: <bound method> = bound_method %.loc15_20, %.loc15_21.2 [template = constants.%.40]
  211. // CHECK:STDOUT: %.loc15_21.4: <specific function> = specific_function %.loc15_21.3, @Convert.2(constants.%.3) [template = constants.%.41]
  212. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc15_21.4(%.loc15_20) [template = constants.%.42]
  213. // CHECK:STDOUT: %.loc15_21.5: init %i32 = converted %.loc15_20, %int.convert_checked [template = constants.%.42]
  214. // CHECK:STDOUT: %.loc15_21.6: ref %i32 = class_element_access %return, element0
  215. // CHECK:STDOUT: %.loc15_21.7: init %i32 = initialize_from %.loc15_21.5 to %.loc15_21.6 [template = constants.%.42]
  216. // CHECK:STDOUT: %.loc15_21.8: init %Param = class_init (%.loc15_21.7), %return [template = constants.%struct]
  217. // CHECK:STDOUT: %.loc15_22: init %Param = converted %.loc15_21.1, %.loc15_21.8 [template = constants.%struct]
  218. // CHECK:STDOUT: return %.loc15_22 to %return
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: fn @G(%c.param_patt: %C) {
  222. // CHECK:STDOUT: !entry:
  223. // CHECK:STDOUT: %.loc21_10.1: Core.IntLiteral = int_value 32 [template = constants.%.3]
  224. // CHECK:STDOUT: %int.make_type_signed.loc21: init type = call constants.%Int(%.loc21_10.1) [template = constants.%i32]
  225. // CHECK:STDOUT: %.loc21_10.2: type = value_of_initializer %int.make_type_signed.loc21 [template = constants.%i32]
  226. // CHECK:STDOUT: %.loc21_10.3: type = converted %int.make_type_signed.loc21, %.loc21_10.2 [template = constants.%i32]
  227. // CHECK:STDOUT: %C.ref.loc21: type = name_ref C, file.%C.decl [template = constants.%C]
  228. // CHECK:STDOUT: %.loc21_17.1: %.7 = specific_constant @HasF.%.loc5_14.1, @HasF(constants.%Param) [template = constants.%.8]
  229. // CHECK:STDOUT: %F.ref.loc21: %.7 = name_ref F, %.loc21_17.1 [template = constants.%.8]
  230. // CHECK:STDOUT: %.loc21_17.2: %F.type.2 = interface_witness_access constants.%.10, element0 [template = constants.%F.3]
  231. // CHECK:STDOUT: %.loc21_20.1: ref %Param = temporary_storage
  232. // CHECK:STDOUT: %F.call.loc21: init %Param = call %.loc21_17.2() to %.loc21_20.1
  233. // CHECK:STDOUT: %.loc21_20.2: ref %Param = temporary %.loc21_20.1, %F.call.loc21
  234. // CHECK:STDOUT: %x.ref.loc21: %.4 = name_ref x, @Param.%.loc9_8 [template = @Param.%.loc9_8]
  235. // CHECK:STDOUT: %.loc21_21.1: ref %i32 = class_element_access %.loc21_20.2, element0
  236. // CHECK:STDOUT: %.loc21_21.2: %i32 = bind_value %.loc21_21.1
  237. // CHECK:STDOUT: %a: %i32 = bind_name a, %.loc21_21.2
  238. // CHECK:STDOUT: %.loc22_10.1: Core.IntLiteral = int_value 32 [template = constants.%.3]
  239. // CHECK:STDOUT: %int.make_type_signed.loc22: init type = call constants.%Int(%.loc22_10.1) [template = constants.%i32]
  240. // CHECK:STDOUT: %.loc22_10.2: type = value_of_initializer %int.make_type_signed.loc22 [template = constants.%i32]
  241. // CHECK:STDOUT: %.loc22_10.3: type = converted %int.make_type_signed.loc22, %.loc22_10.2 [template = constants.%i32]
  242. // CHECK:STDOUT: %b.var: ref %i32 = var b
  243. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  244. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  245. // CHECK:STDOUT: %.loc22_17.1: %.7 = specific_constant @HasF.%.loc5_14.1, @HasF(constants.%Param) [template = constants.%.8]
  246. // CHECK:STDOUT: %F.ref.loc22: %.7 = name_ref F, %.loc22_17.1 [template = constants.%.8]
  247. // CHECK:STDOUT: %.loc22_17.2: %F.type.2 = interface_witness_access constants.%.10, element0 [template = constants.%F.3]
  248. // CHECK:STDOUT: %.loc22_20.1: ref %Param = temporary_storage
  249. // CHECK:STDOUT: %F.call.loc22: init %Param = call %.loc22_17.2() to %.loc22_20.1
  250. // CHECK:STDOUT: %.loc22_20.2: ref %Param = temporary %.loc22_20.1, %F.call.loc22
  251. // CHECK:STDOUT: %x.ref.loc22: %.4 = name_ref x, @Param.%.loc9_8 [template = @Param.%.loc9_8]
  252. // CHECK:STDOUT: %.loc22_21.1: ref %i32 = class_element_access %.loc22_20.2, element0
  253. // CHECK:STDOUT: %.loc22_21.2: %i32 = bind_value %.loc22_21.1
  254. // CHECK:STDOUT: assign %b.var, %.loc22_21.2
  255. // CHECK:STDOUT: return
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: specific @HasF(constants.%T) {
  259. // CHECK:STDOUT: %T.loc4_16.2 => constants.%T
  260. // CHECK:STDOUT: %T.patt.loc4_16.2 => constants.%T
  261. // CHECK:STDOUT: }
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: specific @F.1(constants.%T, constants.%Self.1) {
  264. // CHECK:STDOUT: %T => constants.%T
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: specific @HasF(%T.loc4_16.2) {
  268. // CHECK:STDOUT: %T.loc4_16.2 => constants.%T
  269. // CHECK:STDOUT: %T.patt.loc4_16.2 => constants.%T
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: specific @HasF(constants.%Param) {
  273. // CHECK:STDOUT: %T.loc4_16.2 => constants.%Param
  274. // CHECK:STDOUT: %T.patt.loc4_16.2 => constants.%Param
  275. // CHECK:STDOUT:
  276. // CHECK:STDOUT: !definition:
  277. // CHECK:STDOUT: %HasF.type => constants.%HasF.type.3
  278. // CHECK:STDOUT: %Self.2 => constants.%Self.1
  279. // CHECK:STDOUT: %F.type => constants.%F.type.2
  280. // CHECK:STDOUT: %F => constants.%F.2
  281. // CHECK:STDOUT: %.loc5_14.2 => constants.%.7
  282. // CHECK:STDOUT: %.loc5_14.3 => constants.%.8
  283. // CHECK:STDOUT: }
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: specific @F.1(constants.%Param, constants.%.9) {
  286. // CHECK:STDOUT: %T => constants.%Param
  287. // CHECK:STDOUT: }
  288. // CHECK:STDOUT:
  289. // CHECK:STDOUT: --- extend_impl_generic_class.carbon
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: constants {
  292. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  293. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  294. // CHECK:STDOUT: %I.type.1: type = generic_interface_type @I [template]
  295. // CHECK:STDOUT: %I: %I.type.1 = struct_value () [template]
  296. // CHECK:STDOUT: %I.type.2: type = facet_type <@I, @I(%T)> [symbolic]
  297. // CHECK:STDOUT: %Self: %I.type.2 = bind_symbolic_name Self, 1 [symbolic]
  298. // CHECK:STDOUT: %.1: type = facet_access_type %Self [symbolic]
  299. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @I(%T) [symbolic]
  300. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  301. // CHECK:STDOUT: %.2: type = assoc_entity_type %I.type.2, %F.type.1 [symbolic]
  302. // CHECK:STDOUT: %.3: %.2 = assoc_entity element0, @I.%F.decl [symbolic]
  303. // CHECK:STDOUT: %U: type = bind_symbolic_name U, 0 [symbolic]
  304. // CHECK:STDOUT: %U.patt: type = symbolic_binding_pattern U, 0 [symbolic]
  305. // CHECK:STDOUT: %X.type: type = generic_class_type @X [template]
  306. // CHECK:STDOUT: %X.1: %X.type = struct_value () [template]
  307. // CHECK:STDOUT: %X.2: type = class_type @X, @X(%U) [symbolic]
  308. // CHECK:STDOUT: %I.type.3: type = facet_type <@I, @I(%U)> [symbolic]
  309. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @I(%U) [symbolic]
  310. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [symbolic]
  311. // CHECK:STDOUT: %.4: type = assoc_entity_type %I.type.3, %F.type.2 [symbolic]
  312. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, @I.%F.decl [symbolic]
  313. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2, @impl(%U) [symbolic]
  314. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [symbolic]
  315. // CHECK:STDOUT: %.6: %I.type.2 = facet_value %X.2, %X.2 [symbolic]
  316. // CHECK:STDOUT: %.7: <witness> = interface_witness (%F.3) [symbolic]
  317. // CHECK:STDOUT: %.8: type = struct_type {} [template]
  318. // CHECK:STDOUT: %.9: <witness> = complete_type_witness %.8 [template]
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: imports {
  322. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  323. // CHECK:STDOUT: import Core//prelude
  324. // CHECK:STDOUT: import Core//prelude/...
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: file {
  329. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  330. // CHECK:STDOUT: .Core = imports.%Core
  331. // CHECK:STDOUT: .I = %I.decl
  332. // CHECK:STDOUT: .X = %X.decl
  333. // CHECK:STDOUT: }
  334. // CHECK:STDOUT: %Core.import = import Core
  335. // CHECK:STDOUT: %I.decl: %I.type.1 = interface_decl @I [template = constants.%I] {
  336. // CHECK:STDOUT: %T.patt.loc4_13.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_13.2 (constants.%T.patt)]
  337. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc4_13.1, runtime_param<invalid> [symbolic = %T.patt.loc4_13.2 (constants.%T.patt)]
  338. // CHECK:STDOUT: } {
  339. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  340. // CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_13.2 (constants.%T)]
  341. // CHECK:STDOUT: }
  342. // CHECK:STDOUT: %X.decl: %X.type = class_decl @X [template = constants.%X.1] {
  343. // CHECK:STDOUT: %U.patt.loc8_9.1: type = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc8_9.2 (constants.%U.patt)]
  344. // CHECK:STDOUT: %U.param_patt: type = value_param_pattern %U.patt.loc8_9.1, runtime_param<invalid> [symbolic = %U.patt.loc8_9.2 (constants.%U.patt)]
  345. // CHECK:STDOUT: } {
  346. // CHECK:STDOUT: %U.param: type = value_param runtime_param<invalid>
  347. // CHECK:STDOUT: %U.loc8_9.1: type = bind_symbolic_name U, 0, %U.param [symbolic = %U.loc8_9.2 (constants.%U)]
  348. // CHECK:STDOUT: }
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: generic interface @I(%T.loc4_13.1: type) {
  352. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  353. // CHECK:STDOUT: %T.patt.loc4_13.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_13.2 (constants.%T.patt)]
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: !definition:
  356. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T.loc4_13.2)> [symbolic = %I.type (constants.%I.type.2)]
  357. // CHECK:STDOUT: %Self.2: %I.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  358. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @I(%T.loc4_13.2) [symbolic = %F.type (constants.%F.type.1)]
  359. // CHECK:STDOUT: %F: @I.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  360. // CHECK:STDOUT: %.loc5_25.2: type = assoc_entity_type @I.%I.type (%I.type.2), @I.%F.type (%F.type.1) [symbolic = %.loc5_25.2 (constants.%.2)]
  361. // CHECK:STDOUT: %.loc5_25.3: @I.%.loc5_25.2 (%.2) = assoc_entity element0, %F.decl [symbolic = %.loc5_25.3 (constants.%.3)]
  362. // CHECK:STDOUT:
  363. // CHECK:STDOUT: interface {
  364. // CHECK:STDOUT: %Self.1: @I.%I.type (%I.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  365. // CHECK:STDOUT: %F.decl: @I.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = @I.%F (constants.%F.1)] {
  366. // CHECK:STDOUT: %self.patt: @F.1.%.loc5_14.1 (%.1) = binding_pattern self
  367. // CHECK:STDOUT: %self.param_patt: @F.1.%.loc5_14.1 (%.1) = value_param_pattern %self.patt, runtime_param0
  368. // CHECK:STDOUT: %t.patt: @F.1.%T (%T) = binding_pattern t
  369. // CHECK:STDOUT: %t.param_patt: @F.1.%T (%T) = value_param_pattern %t.patt, runtime_param1
  370. // CHECK:STDOUT: } {
  371. // CHECK:STDOUT: %.loc5_14.2: @F.1.%I.type (%I.type.2) = specific_constant @I.%Self.1, @I(constants.%T) [symbolic = %Self (constants.%Self)]
  372. // CHECK:STDOUT: %Self.ref: @F.1.%I.type (%I.type.2) = name_ref Self, %.loc5_14.2 [symbolic = %Self (constants.%Self)]
  373. // CHECK:STDOUT: %.loc5_14.3: type = facet_access_type %Self.ref [symbolic = %.loc5_14.1 (constants.%.1)]
  374. // CHECK:STDOUT: %.loc5_14.4: type = converted %Self.ref, %.loc5_14.3 [symbolic = %.loc5_14.1 (constants.%.1)]
  375. // CHECK:STDOUT: %T.ref: type = name_ref T, @I.%T.loc4_13.1 [symbolic = %T (constants.%T)]
  376. // CHECK:STDOUT: %self.param: @F.1.%.loc5_14.1 (%.1) = value_param runtime_param0
  377. // CHECK:STDOUT: %self: @F.1.%.loc5_14.1 (%.1) = bind_name self, %self.param
  378. // CHECK:STDOUT: %t.param: @F.1.%T (%T) = value_param runtime_param1
  379. // CHECK:STDOUT: %t: @F.1.%T (%T) = bind_name t, %t.param
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT: %.loc5_25.1: @I.%.loc5_25.2 (%.2) = assoc_entity element0, %F.decl [symbolic = %.loc5_25.3 (constants.%.3)]
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: !members:
  384. // CHECK:STDOUT: .Self = %Self.1
  385. // CHECK:STDOUT: .F = %.loc5_25.1
  386. // CHECK:STDOUT: witness = (%F.decl)
  387. // CHECK:STDOUT: }
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: generic impl @impl(@X.%U.loc8_9.1: type) {
  391. // CHECK:STDOUT: %U: type = bind_symbolic_name U, 0 [symbolic = %U (constants.%U)]
  392. // CHECK:STDOUT: %X: type = class_type @X, @X(%U) [symbolic = %X (constants.%X.2)]
  393. // CHECK:STDOUT: %I.type.loc9_21.2: type = facet_type <@I, @I(%U)> [symbolic = %I.type.loc9_21.2 (constants.%I.type.3)]
  394. // CHECK:STDOUT:
  395. // CHECK:STDOUT: !definition:
  396. // CHECK:STDOUT: %F.type: type = fn_type @F.2, @impl(%U) [symbolic = %F.type (constants.%F.type.3)]
  397. // CHECK:STDOUT: %F: @impl.%F.type (%F.type.3) = struct_value () [symbolic = %F (constants.%F.3)]
  398. // CHECK:STDOUT: %.loc9_23.2: <witness> = interface_witness (%F) [symbolic = %.loc9_23.2 (constants.%.7)]
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: impl: %Self.ref as %I.type.loc9_21.1 {
  401. // CHECK:STDOUT: %F.decl: @impl.%F.type (%F.type.3) = fn_decl @F.2 [symbolic = @impl.%F (constants.%F.3)] {
  402. // CHECK:STDOUT: %self.patt: @F.2.%X (%X.2) = binding_pattern self
  403. // CHECK:STDOUT: %self.param_patt: @F.2.%X (%X.2) = value_param_pattern %self.patt, runtime_param0
  404. // CHECK:STDOUT: %t.patt: @F.2.%U (%U) = binding_pattern t
  405. // CHECK:STDOUT: %t.param_patt: @F.2.%U (%U) = value_param_pattern %t.patt, runtime_param1
  406. // CHECK:STDOUT: } {
  407. // CHECK:STDOUT: %.loc10: type = specific_constant constants.%X.2, @X(constants.%U) [symbolic = %X (constants.%X.2)]
  408. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc10 [symbolic = %X (constants.%X.2)]
  409. // CHECK:STDOUT: %U.ref: type = name_ref U, @X.%U.loc8_9.1 [symbolic = %U (constants.%U)]
  410. // CHECK:STDOUT: %self.param: @F.2.%X (%X.2) = value_param runtime_param0
  411. // CHECK:STDOUT: %self: @F.2.%X (%X.2) = bind_name self, %self.param
  412. // CHECK:STDOUT: %t.param: @F.2.%U (%U) = value_param runtime_param1
  413. // CHECK:STDOUT: %t: @F.2.%U (%U) = bind_name t, %t.param
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT: %.loc9_23.1: <witness> = interface_witness (%F.decl) [symbolic = %.loc9_23.2 (constants.%.7)]
  416. // CHECK:STDOUT:
  417. // CHECK:STDOUT: !members:
  418. // CHECK:STDOUT: .F = %F.decl
  419. // CHECK:STDOUT: witness = %.loc9_23.1
  420. // CHECK:STDOUT: }
  421. // CHECK:STDOUT: }
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: generic class @X(%U.loc8_9.1: type) {
  424. // CHECK:STDOUT: %U.loc8_9.2: type = bind_symbolic_name U, 0 [symbolic = %U.loc8_9.2 (constants.%U)]
  425. // CHECK:STDOUT: %U.patt.loc8_9.2: type = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc8_9.2 (constants.%U.patt)]
  426. // CHECK:STDOUT:
  427. // CHECK:STDOUT: !definition:
  428. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%U.loc8_9.2)> [symbolic = %I.type (constants.%I.type.3)]
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: class {
  431. // CHECK:STDOUT: impl_decl @impl [template] {} {
  432. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%X.2 [symbolic = %X (constants.%X.2)]
  433. // CHECK:STDOUT: %I.ref: %I.type.1 = name_ref I, file.%I.decl [template = constants.%I]
  434. // CHECK:STDOUT: %U.ref: type = name_ref U, @X.%U.loc8_9.1 [symbolic = %U (constants.%U)]
  435. // CHECK:STDOUT: %I.type.loc9_21.1: type = facet_type <@I, @I(constants.%U)> [symbolic = %I.type.loc9_21.2 (constants.%I.type.3)]
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT: %.loc9: type = specific_constant @impl.%I.type.loc9_21.1, @impl(constants.%U) [symbolic = %I.type (constants.%I.type.3)]
  438. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.8 [template = constants.%.9]
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: !members:
  441. // CHECK:STDOUT: .Self = constants.%X.2
  442. // CHECK:STDOUT: extend %.loc9
  443. // CHECK:STDOUT: complete_type_witness = %.loc12
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT: }
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: generic fn @F.1(@I.%T.loc4_13.1: type, @I.%Self.1: @I.%I.type (%I.type.2)) {
  448. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  449. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T)> [symbolic = %I.type (constants.%I.type.2)]
  450. // CHECK:STDOUT: %Self: %I.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self)]
  451. // CHECK:STDOUT: %.loc5_14.1: type = facet_access_type %Self [symbolic = %.loc5_14.1 (constants.%.1)]
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: fn[%self.param_patt: @F.1.%.loc5_14.1 (%.1)](%t.param_patt: @F.1.%T (%T));
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT:
  456. // CHECK:STDOUT: generic fn @F.2(@X.%U.loc8_9.1: type) {
  457. // CHECK:STDOUT: %U: type = bind_symbolic_name U, 0 [symbolic = %U (constants.%U)]
  458. // CHECK:STDOUT: %X: type = class_type @X, @X(%U) [symbolic = %X (constants.%X.2)]
  459. // CHECK:STDOUT:
  460. // CHECK:STDOUT: !definition:
  461. // CHECK:STDOUT:
  462. // CHECK:STDOUT: fn[%self.param_patt: @F.2.%X (%X.2)](%t.param_patt: @F.2.%U (%U)) {
  463. // CHECK:STDOUT: !entry:
  464. // CHECK:STDOUT: return
  465. // CHECK:STDOUT: }
  466. // CHECK:STDOUT: }
  467. // CHECK:STDOUT:
  468. // CHECK:STDOUT: specific @I(constants.%T) {
  469. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  470. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%T
  471. // CHECK:STDOUT: }
  472. // CHECK:STDOUT:
  473. // CHECK:STDOUT: specific @I(@F.1.%T) {
  474. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  475. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%T
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT:
  478. // CHECK:STDOUT: specific @F.1(constants.%T, constants.%Self) {
  479. // CHECK:STDOUT: %T => constants.%T
  480. // CHECK:STDOUT: %I.type => constants.%I.type.2
  481. // CHECK:STDOUT: %Self => constants.%Self
  482. // CHECK:STDOUT: %.loc5_14.1 => constants.%.1
  483. // CHECK:STDOUT: }
  484. // CHECK:STDOUT:
  485. // CHECK:STDOUT: specific @I(%T.loc4_13.2) {
  486. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  487. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%T
  488. // CHECK:STDOUT: }
  489. // CHECK:STDOUT:
  490. // CHECK:STDOUT: specific @X(constants.%U) {
  491. // CHECK:STDOUT: %U.loc8_9.2 => constants.%U
  492. // CHECK:STDOUT: %U.patt.loc8_9.2 => constants.%U
  493. // CHECK:STDOUT:
  494. // CHECK:STDOUT: !definition:
  495. // CHECK:STDOUT: %I.type => constants.%I.type.3
  496. // CHECK:STDOUT: }
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: specific @I(constants.%U) {
  499. // CHECK:STDOUT: %T.loc4_13.2 => constants.%U
  500. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%U
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: !definition:
  503. // CHECK:STDOUT: %I.type => constants.%I.type.3
  504. // CHECK:STDOUT: %Self.2 => constants.%Self
  505. // CHECK:STDOUT: %F.type => constants.%F.type.2
  506. // CHECK:STDOUT: %F => constants.%F.2
  507. // CHECK:STDOUT: %.loc5_25.2 => constants.%.4
  508. // CHECK:STDOUT: %.loc5_25.3 => constants.%.5
  509. // CHECK:STDOUT: }
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: specific @X(@impl.%U) {
  512. // CHECK:STDOUT: %U.loc8_9.2 => constants.%U
  513. // CHECK:STDOUT: %U.patt.loc8_9.2 => constants.%U
  514. // CHECK:STDOUT: }
  515. // CHECK:STDOUT:
  516. // CHECK:STDOUT: specific @I(@impl.%U) {
  517. // CHECK:STDOUT: %T.loc4_13.2 => constants.%U
  518. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%U
  519. // CHECK:STDOUT: }
  520. // CHECK:STDOUT:
  521. // CHECK:STDOUT: specific @impl(constants.%U) {
  522. // CHECK:STDOUT: %U => constants.%U
  523. // CHECK:STDOUT: %X => constants.%X.2
  524. // CHECK:STDOUT: %I.type.loc9_21.2 => constants.%I.type.3
  525. // CHECK:STDOUT:
  526. // CHECK:STDOUT: !definition:
  527. // CHECK:STDOUT: %F.type => constants.%F.type.3
  528. // CHECK:STDOUT: %F => constants.%F.3
  529. // CHECK:STDOUT: %.loc9_23.2 => constants.%.7
  530. // CHECK:STDOUT: }
  531. // CHECK:STDOUT:
  532. // CHECK:STDOUT: specific @X(@F.2.%U) {
  533. // CHECK:STDOUT: %U.loc8_9.2 => constants.%U
  534. // CHECK:STDOUT: %U.patt.loc8_9.2 => constants.%U
  535. // CHECK:STDOUT: }
  536. // CHECK:STDOUT:
  537. // CHECK:STDOUT: specific @F.2(constants.%U) {
  538. // CHECK:STDOUT: %U => constants.%U
  539. // CHECK:STDOUT: %X => constants.%X.2
  540. // CHECK:STDOUT: }
  541. // CHECK:STDOUT:
  542. // CHECK:STDOUT: specific @F.1(constants.%U, constants.%.6) {
  543. // CHECK:STDOUT: %T => constants.%U
  544. // CHECK:STDOUT: %I.type => constants.%I.type.3
  545. // CHECK:STDOUT: %Self => constants.%.6
  546. // CHECK:STDOUT: %.loc5_14.1 => constants.%X.2
  547. // CHECK:STDOUT: }
  548. // CHECK:STDOUT:
  549. // CHECK:STDOUT: specific @impl(%U) {
  550. // CHECK:STDOUT: %U => constants.%U
  551. // CHECK:STDOUT: %X => constants.%X.2
  552. // CHECK:STDOUT: %I.type.loc9_21.2 => constants.%I.type.3
  553. // CHECK:STDOUT: }
  554. // CHECK:STDOUT:
  555. // CHECK:STDOUT: specific @I(@X.%U.loc8_9.2) {
  556. // CHECK:STDOUT: %T.loc4_13.2 => constants.%U
  557. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%U
  558. // CHECK:STDOUT: }
  559. // CHECK:STDOUT: