interface_args.carbon 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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/interface_args.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/interface_args.carbon
  10. // --- action.carbon
  11. library "[[@TEST_NAME]]";
  12. interface Action(T:! type) {
  13. fn Op();
  14. }
  15. class A {}
  16. class B {}
  17. class C {}
  18. impl A as Action(B) {
  19. fn Op() {}
  20. }
  21. fn F(a: A) { a.(Action(B).Op)(); }
  22. // --- action.impl.carbon
  23. impl library "[[@TEST_NAME]]";
  24. fn G(a: A) { a.(Action(B).Op)(); }
  25. // --- fail_action.impl.carbon
  26. impl library "[[@TEST_NAME]]";
  27. // CHECK:STDERR: fail_action.impl.carbon:[[@LINE+4]]:14: ERROR: Cannot access member of interface `Action` in type `A` that does not implement that interface.
  28. // CHECK:STDERR: fn G(a: A) { a.(Action(C).Op)(); }
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  30. // CHECK:STDERR:
  31. fn G(a: A) { a.(Action(C).Op)(); }
  32. // --- factory.carbon
  33. library "[[@TEST_NAME]]";
  34. interface Factory(T:! type) {
  35. fn Make() -> T;
  36. }
  37. class A {}
  38. class B {}
  39. impl A as Factory(B) {
  40. fn Make() -> B;
  41. }
  42. // --- factory.impl.carbon
  43. impl library "[[@TEST_NAME]]";
  44. fn MakeB(a: A) -> B {
  45. return a.(Factory(B).Make)();
  46. }
  47. // --- fail_factory.impl.carbon
  48. impl library "[[@TEST_NAME]]";
  49. class C {}
  50. fn MakeC(a: A) -> C {
  51. // CHECK:STDERR: fail_factory.impl.carbon:[[@LINE+3]]:10: ERROR: Cannot access member of interface `Factory` in type `A` that does not implement that interface.
  52. // CHECK:STDERR: return a.(Factory(C).Make)();
  53. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  54. return a.(Factory(C).Make)();
  55. }
  56. // CHECK:STDOUT: --- action.carbon
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: constants {
  59. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  60. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  61. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  62. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  63. // CHECK:STDOUT: %.2: type = interface_type @Action, @Action(%T) [symbolic]
  64. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  65. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1, @Action(%T) [symbolic]
  66. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [symbolic]
  67. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, %Op.type.1 [symbolic]
  68. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Action.%Op.decl [symbolic]
  69. // CHECK:STDOUT: %A: type = class_type @A [template]
  70. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  71. // CHECK:STDOUT: %B: type = class_type @B [template]
  72. // CHECK:STDOUT: %C: type = class_type @C [template]
  73. // CHECK:STDOUT: %.6: type = interface_type @Action, @Action(%B) [template]
  74. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  75. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  76. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.1, @Action(%B) [template]
  77. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  78. // CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %Op.type.3 [template]
  79. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, @Action.%Op.decl [template]
  80. // CHECK:STDOUT: %.9: <witness> = interface_witness (%Op.2) [template]
  81. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  82. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  83. // CHECK:STDOUT: %.10: type = ptr_type %.5 [template]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: file {
  87. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  88. // CHECK:STDOUT: .Action = %Action.decl
  89. // CHECK:STDOUT: .A = %A.decl
  90. // CHECK:STDOUT: .B = %B.decl
  91. // CHECK:STDOUT: .C = %C.decl
  92. // CHECK:STDOUT: .F = %F.decl
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %Action.decl: %Action.type = interface_decl @Action [template = constants.%Action] {
  95. // CHECK:STDOUT: %T.loc4_18.1: type = param T, runtime_param<invalid>
  96. // CHECK:STDOUT: %T.loc4_18.2: type = bind_symbolic_name T 0, %T.loc4_18.1 [symbolic = @Action.%T (constants.%T)]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  99. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  100. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  101. // CHECK:STDOUT: impl_decl @impl {
  102. // CHECK:STDOUT: %A.ref.loc12: type = name_ref A, %A.decl [template = constants.%A]
  103. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, %Action.decl [template = constants.%Action]
  104. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  105. // CHECK:STDOUT: %.loc12: type = interface_type @Action, @Action(constants.%B) [template = constants.%.6]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  108. // CHECK:STDOUT: %A.ref.loc16: type = name_ref A, %A.decl [template = constants.%A]
  109. // CHECK:STDOUT: %a.loc16_6.1: %A = param a, runtime_param0
  110. // CHECK:STDOUT: @F.%a: %A = bind_name a, %a.loc16_6.1
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: generic interface @Action(file.%T.loc4_18.2: type) {
  115. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !definition:
  118. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.2)]
  119. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  120. // CHECK:STDOUT: %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
  121. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
  122. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.2), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.3)]
  123. // CHECK:STDOUT: %.3: @Action.%.2 (%.3) = assoc_entity element0, %Op.decl [symbolic = %.3 (constants.%.4)]
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: interface {
  126. // CHECK:STDOUT: %Self.1: @Action.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  127. // CHECK:STDOUT: %Op.decl: @Action.%Op.type (%Op.type.1) = fn_decl @Op.1 [symbolic = %Op (constants.%Op.1)] {}
  128. // CHECK:STDOUT: %.loc5: @Action.%.2 (%.3) = assoc_entity element0, %Op.decl [symbolic = %.3 (constants.%.4)]
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: !members:
  131. // CHECK:STDOUT: .Self = %Self.1
  132. // CHECK:STDOUT: .Op = %.loc5
  133. // CHECK:STDOUT: witness = (%Op.decl)
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: impl @impl: %A as %.6 {
  138. // CHECK:STDOUT: %Op.decl: %Op.type.2 = fn_decl @Op.2 [template = constants.%Op.2] {}
  139. // CHECK:STDOUT: %.loc12: <witness> = interface_witness (%Op.decl) [template = constants.%.9]
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: !members:
  142. // CHECK:STDOUT: .Op = %Op.decl
  143. // CHECK:STDOUT: witness = %.loc12
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: class @A {
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = constants.%A
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: class @B {
  152. // CHECK:STDOUT: !members:
  153. // CHECK:STDOUT: .Self = constants.%B
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: class @C {
  157. // CHECK:STDOUT: !members:
  158. // CHECK:STDOUT: .Self = constants.%C
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: generic fn @Op.1(file.%T.loc4_18.2: type, @Action.%Self.1: @Action.%.1 (%.2)) {
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn();
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: fn @Op.2() {
  167. // CHECK:STDOUT: !entry:
  168. // CHECK:STDOUT: return
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: fn @F(%a: %A) {
  172. // CHECK:STDOUT: !entry:
  173. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  174. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, file.%Action.decl [template = constants.%Action]
  175. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  176. // CHECK:STDOUT: %.loc16_23: type = interface_type @Action, @Action(constants.%B) [template = constants.%.6]
  177. // CHECK:STDOUT: %.loc16_26: %.7 = specific_constant @Action.%.loc5, @Action(constants.%B) [template = constants.%.8]
  178. // CHECK:STDOUT: %Op.ref: %.7 = name_ref Op, %.loc16_26 [template = constants.%.8]
  179. // CHECK:STDOUT: %.loc16_15: %Op.type.3 = interface_witness_access @impl.%.loc12, element0 [template = constants.%Op.2]
  180. // CHECK:STDOUT: %Op.call: init %.1 = call %.loc16_15()
  181. // CHECK:STDOUT: return
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: specific @Action(constants.%T) {
  185. // CHECK:STDOUT: %T => constants.%T
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: specific @Op.1(constants.%T, constants.%Self) {}
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: specific @Action(@Action.%T) {
  191. // CHECK:STDOUT: %T => constants.%T
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: specific @Action(constants.%B) {
  195. // CHECK:STDOUT: %T => constants.%B
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: !definition:
  198. // CHECK:STDOUT: %.1 => constants.%.6
  199. // CHECK:STDOUT: %Self.2 => constants.%Self
  200. // CHECK:STDOUT: %Op.type => constants.%Op.type.3
  201. // CHECK:STDOUT: %Op => constants.%Op.3
  202. // CHECK:STDOUT: %.2 => constants.%.7
  203. // CHECK:STDOUT: %.3 => constants.%.8
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: specific @Op.1(constants.%B, constants.%A) {}
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: --- action.impl.carbon
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: constants {
  211. // CHECK:STDOUT: %A: type = class_type @A [template]
  212. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  213. // CHECK:STDOUT: %B: type = class_type @B [template]
  214. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  215. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  216. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  217. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  218. // CHECK:STDOUT: %.3: type = interface_type @Action, @Action(%T) [symbolic]
  219. // CHECK:STDOUT: %Self.1: @Action.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  220. // CHECK:STDOUT: %.4: type = interface_type @Action, @Action(%B) [template]
  221. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  222. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1, @Action(%T) [symbolic]
  223. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [symbolic]
  224. // CHECK:STDOUT: %.5: type = assoc_entity_type %.3, %Op.type.1 [symbolic]
  225. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.11 [symbolic]
  226. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.1, @Action(%B) [template]
  227. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  228. // CHECK:STDOUT: %.7: type = assoc_entity_type %.4, %Op.type.2 [template]
  229. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.12 [template]
  230. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  231. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  232. // CHECK:STDOUT: %.9: type = ptr_type %.1 [template]
  233. // CHECK:STDOUT: %.10: %.5 = assoc_entity element0, imports.%import_ref.14 [symbolic]
  234. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.2 [template]
  235. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  236. // CHECK:STDOUT: %.11: <witness> = interface_witness (%Op.3) [template]
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: imports {
  240. // CHECK:STDOUT: %import_ref.1: %Action.type = import_ref Main//action, inst+4, loaded [template = constants.%Action]
  241. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
  242. // CHECK:STDOUT: %import_ref.3: type = import_ref Main//action, inst+27, loaded [template = constants.%B]
  243. // CHECK:STDOUT: %import_ref.4 = import_ref Main//action, inst+29, unloaded
  244. // CHECK:STDOUT: %import_ref.5 = import_ref Main//action, inst+50, unloaded
  245. // CHECK:STDOUT: %import_ref.6 = import_ref Main//action, inst+25, unloaded
  246. // CHECK:STDOUT: %import_ref.7 = import_ref Main//action, inst+28, unloaded
  247. // CHECK:STDOUT: %import_ref.8 = import_ref Main//action, inst+10, unloaded
  248. // CHECK:STDOUT: %import_ref.9: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.10)]
  249. // CHECK:STDOUT: %import_ref.10 = import_ref Main//action, inst+12, unloaded
  250. // CHECK:STDOUT: %import_ref.11 = import_ref Main//action, inst+12, unloaded
  251. // CHECK:STDOUT: %import_ref.12 = import_ref Main//action, inst+12, unloaded
  252. // CHECK:STDOUT: %import_ref.13: <witness> = import_ref Main//action, inst+44, loaded [template = constants.%.11]
  253. // CHECK:STDOUT: %import_ref.14 = import_ref Main//action, inst+12, unloaded
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: file {
  257. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  258. // CHECK:STDOUT: .Action = imports.%import_ref.1
  259. // CHECK:STDOUT: .A = imports.%import_ref.2
  260. // CHECK:STDOUT: .B = imports.%import_ref.3
  261. // CHECK:STDOUT: .C = imports.%import_ref.4
  262. // CHECK:STDOUT: .F = imports.%import_ref.5
  263. // CHECK:STDOUT: .G = %G.decl
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  266. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  267. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  268. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  269. // CHECK:STDOUT: %a.loc4_6.1: %A = param a, runtime_param0
  270. // CHECK:STDOUT: @G.%a: %A = bind_name a, %a.loc4_6.1
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: generic interface @Action(constants.%T: type) {
  275. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: !definition:
  278. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
  279. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  280. // CHECK:STDOUT: %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
  281. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
  282. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.5)]
  283. // CHECK:STDOUT: %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.11 [symbolic = %.3 (constants.%.6)]
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: interface {
  286. // CHECK:STDOUT: !members:
  287. // CHECK:STDOUT: .Self = imports.%import_ref.8
  288. // CHECK:STDOUT: .Op = imports.%import_ref.9
  289. // CHECK:STDOUT: witness = (imports.%import_ref.10)
  290. // CHECK:STDOUT: }
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: impl @impl: %A as %.4 {
  294. // CHECK:STDOUT: !members:
  295. // CHECK:STDOUT: witness = imports.%import_ref.13
  296. // CHECK:STDOUT: }
  297. // CHECK:STDOUT:
  298. // CHECK:STDOUT: class @A {
  299. // CHECK:STDOUT: !members:
  300. // CHECK:STDOUT: .Self = imports.%import_ref.6
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: class @B {
  304. // CHECK:STDOUT: !members:
  305. // CHECK:STDOUT: .Self = imports.%import_ref.7
  306. // CHECK:STDOUT: }
  307. // CHECK:STDOUT:
  308. // CHECK:STDOUT: generic fn @Op.1(constants.%T: type, constants.%Self.1: @Action.%.1 (%.3)) {
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: fn();
  311. // CHECK:STDOUT: }
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: fn @G(%a: %A) {
  314. // CHECK:STDOUT: !entry:
  315. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  316. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
  317. // CHECK:STDOUT: %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
  318. // CHECK:STDOUT: %.loc4_23: type = interface_type @Action, @Action(constants.%B) [template = constants.%.4]
  319. // CHECK:STDOUT: %.loc4_26: %.7 = specific_constant imports.%import_ref.9, @Action(constants.%B) [template = constants.%.8]
  320. // CHECK:STDOUT: %Op.ref: %.7 = name_ref Op, %.loc4_26 [template = constants.%.8]
  321. // CHECK:STDOUT: %.loc4_15: %Op.type.2 = interface_witness_access imports.%import_ref.13, element0 [template = constants.%Op.3]
  322. // CHECK:STDOUT: %Op.call: init %.2 = call %.loc4_15()
  323. // CHECK:STDOUT: return
  324. // CHECK:STDOUT: }
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: fn @Op.2();
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: specific @Action(constants.%T) {
  329. // CHECK:STDOUT: %T => constants.%T
  330. // CHECK:STDOUT: }
  331. // CHECK:STDOUT:
  332. // CHECK:STDOUT: specific @Action(constants.%B) {
  333. // CHECK:STDOUT: %T => constants.%B
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: !definition:
  336. // CHECK:STDOUT: %.1 => constants.%.4
  337. // CHECK:STDOUT: %Self => constants.%Self.2
  338. // CHECK:STDOUT: %Op.type => constants.%Op.type.2
  339. // CHECK:STDOUT: %Op => constants.%Op.2
  340. // CHECK:STDOUT: %.2 => constants.%.7
  341. // CHECK:STDOUT: %.3 => constants.%.8
  342. // CHECK:STDOUT: }
  343. // CHECK:STDOUT:
  344. // CHECK:STDOUT: specific @Action(@Action.%T) {
  345. // CHECK:STDOUT: %T => constants.%T
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: specific @Op.1(constants.%T, constants.%Self.1) {}
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: --- fail_action.impl.carbon
  351. // CHECK:STDOUT:
  352. // CHECK:STDOUT: constants {
  353. // CHECK:STDOUT: %A: type = class_type @A [template]
  354. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  355. // CHECK:STDOUT: %B: type = class_type @B [template]
  356. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  357. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  358. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  359. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  360. // CHECK:STDOUT: %.3: type = interface_type @Action, @Action(%T) [symbolic]
  361. // CHECK:STDOUT: %Self.1: @Action.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  362. // CHECK:STDOUT: %.4: type = interface_type @Action, @Action(%B) [template]
  363. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  364. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op, @Action(%T) [symbolic]
  365. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [symbolic]
  366. // CHECK:STDOUT: %.5: type = assoc_entity_type %.3, %Op.type.1 [symbolic]
  367. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.11 [symbolic]
  368. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op, @Action(%B) [template]
  369. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  370. // CHECK:STDOUT: %.7: type = assoc_entity_type %.4, %Op.type.2 [template]
  371. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.12 [template]
  372. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  373. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  374. // CHECK:STDOUT: %.9: type = ptr_type %.1 [template]
  375. // CHECK:STDOUT: %C: type = class_type @C [template]
  376. // CHECK:STDOUT: %.10: type = interface_type @Action, @Action(%C) [template]
  377. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op, @Action(%C) [template]
  378. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  379. // CHECK:STDOUT: %.11: type = assoc_entity_type %.10, %Op.type.3 [template]
  380. // CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.11 [template]
  381. // CHECK:STDOUT: %.13: %.5 = assoc_entity element0, imports.%import_ref.15 [symbolic]
  382. // CHECK:STDOUT: }
  383. // CHECK:STDOUT:
  384. // CHECK:STDOUT: imports {
  385. // CHECK:STDOUT: %import_ref.1: %Action.type = import_ref Main//action, inst+4, loaded [template = constants.%Action]
  386. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
  387. // CHECK:STDOUT: %import_ref.3 = import_ref Main//action, inst+27, unloaded
  388. // CHECK:STDOUT: %import_ref.4: type = import_ref Main//action, inst+29, loaded [template = constants.%C]
  389. // CHECK:STDOUT: %import_ref.5 = import_ref Main//action, inst+50, unloaded
  390. // CHECK:STDOUT: %import_ref.6 = import_ref Main//action, inst+25, unloaded
  391. // CHECK:STDOUT: %import_ref.7 = import_ref Main//action, inst+28, unloaded
  392. // CHECK:STDOUT: %import_ref.8 = import_ref Main//action, inst+10, unloaded
  393. // CHECK:STDOUT: %import_ref.9: @Action.%.2 (%.5) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.13)]
  394. // CHECK:STDOUT: %import_ref.10 = import_ref Main//action, inst+12, unloaded
  395. // CHECK:STDOUT: %import_ref.11 = import_ref Main//action, inst+12, unloaded
  396. // CHECK:STDOUT: %import_ref.12 = import_ref Main//action, inst+12, unloaded
  397. // CHECK:STDOUT: %import_ref.13 = import_ref Main//action, inst+44, unloaded
  398. // CHECK:STDOUT: %import_ref.14 = import_ref Main//action, inst+30, unloaded
  399. // CHECK:STDOUT: %import_ref.15 = import_ref Main//action, inst+12, unloaded
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: file {
  403. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  404. // CHECK:STDOUT: .Action = imports.%import_ref.1
  405. // CHECK:STDOUT: .A = imports.%import_ref.2
  406. // CHECK:STDOUT: .B = imports.%import_ref.3
  407. // CHECK:STDOUT: .C = imports.%import_ref.4
  408. // CHECK:STDOUT: .F = imports.%import_ref.5
  409. // CHECK:STDOUT: .G = %G.decl
  410. // CHECK:STDOUT: }
  411. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  412. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  413. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  414. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  415. // CHECK:STDOUT: %a.loc8_6.1: %A = param a, runtime_param0
  416. // CHECK:STDOUT: @G.%a: %A = bind_name a, %a.loc8_6.1
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT: }
  419. // CHECK:STDOUT:
  420. // CHECK:STDOUT: generic interface @Action(constants.%T: type) {
  421. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: !definition:
  424. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
  425. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  426. // CHECK:STDOUT: %Op.type: type = fn_type @Op, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
  427. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
  428. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.5)]
  429. // CHECK:STDOUT: %.3: @Action.%.2 (%.5) = assoc_entity element0, imports.%import_ref.11 [symbolic = %.3 (constants.%.6)]
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: interface {
  432. // CHECK:STDOUT: !members:
  433. // CHECK:STDOUT: .Self = imports.%import_ref.8
  434. // CHECK:STDOUT: .Op = imports.%import_ref.9
  435. // CHECK:STDOUT: witness = (imports.%import_ref.10)
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT: }
  438. // CHECK:STDOUT:
  439. // CHECK:STDOUT: impl @impl: %A as %.4 {
  440. // CHECK:STDOUT: !members:
  441. // CHECK:STDOUT: witness = imports.%import_ref.13
  442. // CHECK:STDOUT: }
  443. // CHECK:STDOUT:
  444. // CHECK:STDOUT: class @A {
  445. // CHECK:STDOUT: !members:
  446. // CHECK:STDOUT: .Self = imports.%import_ref.6
  447. // CHECK:STDOUT: }
  448. // CHECK:STDOUT:
  449. // CHECK:STDOUT: class @B {
  450. // CHECK:STDOUT: !members:
  451. // CHECK:STDOUT: .Self = imports.%import_ref.7
  452. // CHECK:STDOUT: }
  453. // CHECK:STDOUT:
  454. // CHECK:STDOUT: class @C {
  455. // CHECK:STDOUT: !members:
  456. // CHECK:STDOUT: .Self = imports.%import_ref.14
  457. // CHECK:STDOUT: }
  458. // CHECK:STDOUT:
  459. // CHECK:STDOUT: generic fn @Op(constants.%T: type, constants.%Self.1: @Action.%.1 (%.3)) {
  460. // CHECK:STDOUT:
  461. // CHECK:STDOUT: fn();
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: fn @G(%a: %A) {
  465. // CHECK:STDOUT: !entry:
  466. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  467. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
  468. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%import_ref.4 [template = constants.%C]
  469. // CHECK:STDOUT: %.loc8_23: type = interface_type @Action, @Action(constants.%C) [template = constants.%.10]
  470. // CHECK:STDOUT: %.loc8_26: %.11 = specific_constant imports.%import_ref.9, @Action(constants.%C) [template = constants.%.12]
  471. // CHECK:STDOUT: %Op.ref: %.11 = name_ref Op, %.loc8_26 [template = constants.%.12]
  472. // CHECK:STDOUT: return
  473. // CHECK:STDOUT: }
  474. // CHECK:STDOUT:
  475. // CHECK:STDOUT: specific @Action(constants.%T) {
  476. // CHECK:STDOUT: %T => constants.%T
  477. // CHECK:STDOUT: }
  478. // CHECK:STDOUT:
  479. // CHECK:STDOUT: specific @Action(constants.%B) {
  480. // CHECK:STDOUT: %T => constants.%B
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: !definition:
  483. // CHECK:STDOUT: %.1 => constants.%.4
  484. // CHECK:STDOUT: %Self => constants.%Self.2
  485. // CHECK:STDOUT: %Op.type => constants.%Op.type.2
  486. // CHECK:STDOUT: %Op => constants.%Op.2
  487. // CHECK:STDOUT: %.2 => constants.%.7
  488. // CHECK:STDOUT: %.3 => constants.%.8
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT:
  491. // CHECK:STDOUT: specific @Action(@Action.%T) {
  492. // CHECK:STDOUT: %T => constants.%T
  493. // CHECK:STDOUT: }
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: specific @Op(constants.%T, constants.%Self.1) {}
  496. // CHECK:STDOUT:
  497. // CHECK:STDOUT: specific @Action(constants.%C) {
  498. // CHECK:STDOUT: %T => constants.%C
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: !definition:
  501. // CHECK:STDOUT: %.1 => constants.%.10
  502. // CHECK:STDOUT: %Self => constants.%Self.2
  503. // CHECK:STDOUT: %Op.type => constants.%Op.type.3
  504. // CHECK:STDOUT: %Op => constants.%Op.3
  505. // CHECK:STDOUT: %.2 => constants.%.11
  506. // CHECK:STDOUT: %.3 => constants.%.12
  507. // CHECK:STDOUT: }
  508. // CHECK:STDOUT:
  509. // CHECK:STDOUT: --- factory.carbon
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: constants {
  512. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  513. // CHECK:STDOUT: %Factory.type: type = generic_interface_type @Factory [template]
  514. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  515. // CHECK:STDOUT: %Factory: %Factory.type = struct_value () [template]
  516. // CHECK:STDOUT: %.2: type = interface_type @Factory, @Factory(%T) [symbolic]
  517. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  518. // CHECK:STDOUT: %Make.type.1: type = fn_type @Make.1, @Factory(%T) [symbolic]
  519. // CHECK:STDOUT: %Make.1: %Make.type.1 = struct_value () [symbolic]
  520. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, %Make.type.1 [symbolic]
  521. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Factory.%Make.decl [symbolic]
  522. // CHECK:STDOUT: %A: type = class_type @A [template]
  523. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  524. // CHECK:STDOUT: %B: type = class_type @B [template]
  525. // CHECK:STDOUT: %.6: type = interface_type @Factory, @Factory(%B) [template]
  526. // CHECK:STDOUT: %Make.type.2: type = fn_type @Make.2 [template]
  527. // CHECK:STDOUT: %Make.2: %Make.type.2 = struct_value () [template]
  528. // CHECK:STDOUT: %Make.type.3: type = fn_type @Make.1, @Factory(%B) [template]
  529. // CHECK:STDOUT: %Make.3: %Make.type.3 = struct_value () [template]
  530. // CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %Make.type.3 [template]
  531. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, @Factory.%Make.decl [template]
  532. // CHECK:STDOUT: %.9: <witness> = interface_witness (%Make.2) [template]
  533. // CHECK:STDOUT: }
  534. // CHECK:STDOUT:
  535. // CHECK:STDOUT: file {
  536. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  537. // CHECK:STDOUT: .Factory = %Factory.decl
  538. // CHECK:STDOUT: .A = %A.decl
  539. // CHECK:STDOUT: .B = %B.decl
  540. // CHECK:STDOUT: }
  541. // CHECK:STDOUT: %Factory.decl: %Factory.type = interface_decl @Factory [template = constants.%Factory] {
  542. // CHECK:STDOUT: %T.loc4_19.1: type = param T, runtime_param<invalid>
  543. // CHECK:STDOUT: %T.loc4_19.2: type = bind_symbolic_name T 0, %T.loc4_19.1 [symbolic = @Factory.%T (constants.%T)]
  544. // CHECK:STDOUT: }
  545. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  546. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  547. // CHECK:STDOUT: impl_decl @impl {
  548. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  549. // CHECK:STDOUT: %Factory.ref: %Factory.type = name_ref Factory, %Factory.decl [template = constants.%Factory]
  550. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  551. // CHECK:STDOUT: %.loc11: type = interface_type @Factory, @Factory(constants.%B) [template = constants.%.6]
  552. // CHECK:STDOUT: }
  553. // CHECK:STDOUT: }
  554. // CHECK:STDOUT:
  555. // CHECK:STDOUT: generic interface @Factory(file.%T.loc4_19.2: type) {
  556. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  557. // CHECK:STDOUT:
  558. // CHECK:STDOUT: !definition:
  559. // CHECK:STDOUT: %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.2)]
  560. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  561. // CHECK:STDOUT: %Make.type: type = fn_type @Make.1, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
  562. // CHECK:STDOUT: %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
  563. // CHECK:STDOUT: %.2: type = assoc_entity_type @Factory.%.1 (%.2), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.3)]
  564. // CHECK:STDOUT: %.3: @Factory.%.2 (%.3) = assoc_entity element0, %Make.decl [symbolic = %.3 (constants.%.4)]
  565. // CHECK:STDOUT:
  566. // CHECK:STDOUT: interface {
  567. // CHECK:STDOUT: %Self.1: @Factory.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  568. // CHECK:STDOUT: %Make.decl: @Factory.%Make.type (%Make.type.1) = fn_decl @Make.1 [symbolic = %Make (constants.%Make.1)] {
  569. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc4_19.2 [symbolic = @Make.1.%T (constants.%T)]
  570. // CHECK:STDOUT: %return.var: ref @Make.1.%T (%T) = var <return slot>
  571. // CHECK:STDOUT: }
  572. // CHECK:STDOUT: %.loc5: @Factory.%.2 (%.3) = assoc_entity element0, %Make.decl [symbolic = %.3 (constants.%.4)]
  573. // CHECK:STDOUT:
  574. // CHECK:STDOUT: !members:
  575. // CHECK:STDOUT: .Self = %Self.1
  576. // CHECK:STDOUT: .Make = %.loc5
  577. // CHECK:STDOUT: witness = (%Make.decl)
  578. // CHECK:STDOUT: }
  579. // CHECK:STDOUT: }
  580. // CHECK:STDOUT:
  581. // CHECK:STDOUT: impl @impl: %A as %.6 {
  582. // CHECK:STDOUT: %Make.decl: %Make.type.2 = fn_decl @Make.2 [template = constants.%Make.2] {
  583. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  584. // CHECK:STDOUT: %return.var: ref %B = var <return slot>
  585. // CHECK:STDOUT: }
  586. // CHECK:STDOUT: %.loc11: <witness> = interface_witness (%Make.decl) [template = constants.%.9]
  587. // CHECK:STDOUT:
  588. // CHECK:STDOUT: !members:
  589. // CHECK:STDOUT: .Make = %Make.decl
  590. // CHECK:STDOUT: witness = %.loc11
  591. // CHECK:STDOUT: }
  592. // CHECK:STDOUT:
  593. // CHECK:STDOUT: class @A {
  594. // CHECK:STDOUT: !members:
  595. // CHECK:STDOUT: .Self = constants.%A
  596. // CHECK:STDOUT: }
  597. // CHECK:STDOUT:
  598. // CHECK:STDOUT: class @B {
  599. // CHECK:STDOUT: !members:
  600. // CHECK:STDOUT: .Self = constants.%B
  601. // CHECK:STDOUT: }
  602. // CHECK:STDOUT:
  603. // CHECK:STDOUT: generic fn @Make.1(file.%T.loc4_19.2: type, @Factory.%Self.1: @Factory.%.1 (%.2)) {
  604. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  605. // CHECK:STDOUT:
  606. // CHECK:STDOUT: fn() -> @Make.1.%T (%T);
  607. // CHECK:STDOUT: }
  608. // CHECK:STDOUT:
  609. // CHECK:STDOUT: fn @Make.2() -> %B;
  610. // CHECK:STDOUT:
  611. // CHECK:STDOUT: specific @Factory(constants.%T) {
  612. // CHECK:STDOUT: %T => constants.%T
  613. // CHECK:STDOUT: }
  614. // CHECK:STDOUT:
  615. // CHECK:STDOUT: specific @Make.1(constants.%T, constants.%Self) {
  616. // CHECK:STDOUT: %T => constants.%T
  617. // CHECK:STDOUT: }
  618. // CHECK:STDOUT:
  619. // CHECK:STDOUT: specific @Factory(@Factory.%T) {
  620. // CHECK:STDOUT: %T => constants.%T
  621. // CHECK:STDOUT: }
  622. // CHECK:STDOUT:
  623. // CHECK:STDOUT: specific @Factory(constants.%B) {
  624. // CHECK:STDOUT: %T => constants.%B
  625. // CHECK:STDOUT:
  626. // CHECK:STDOUT: !definition:
  627. // CHECK:STDOUT: %.1 => constants.%.6
  628. // CHECK:STDOUT: %Self.2 => constants.%Self
  629. // CHECK:STDOUT: %Make.type => constants.%Make.type.3
  630. // CHECK:STDOUT: %Make => constants.%Make.3
  631. // CHECK:STDOUT: %.2 => constants.%.7
  632. // CHECK:STDOUT: %.3 => constants.%.8
  633. // CHECK:STDOUT: }
  634. // CHECK:STDOUT:
  635. // CHECK:STDOUT: specific @Make.1(constants.%B, constants.%A) {
  636. // CHECK:STDOUT: %T => constants.%B
  637. // CHECK:STDOUT: }
  638. // CHECK:STDOUT:
  639. // CHECK:STDOUT: --- factory.impl.carbon
  640. // CHECK:STDOUT:
  641. // CHECK:STDOUT: constants {
  642. // CHECK:STDOUT: %A: type = class_type @A [template]
  643. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  644. // CHECK:STDOUT: %B: type = class_type @B [template]
  645. // CHECK:STDOUT: %Factory.type: type = generic_interface_type @Factory [template]
  646. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  647. // CHECK:STDOUT: %Factory: %Factory.type = struct_value () [template]
  648. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  649. // CHECK:STDOUT: %.3: type = interface_type @Factory, @Factory(%T) [symbolic]
  650. // CHECK:STDOUT: %Self.1: @Factory.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  651. // CHECK:STDOUT: %.4: type = interface_type @Factory, @Factory(%B) [template]
  652. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  653. // CHECK:STDOUT: %Make.type.1: type = fn_type @Make.1, @Factory(%T) [symbolic]
  654. // CHECK:STDOUT: %Make.1: %Make.type.1 = struct_value () [symbolic]
  655. // CHECK:STDOUT: %.5: type = assoc_entity_type %.3, %Make.type.1 [symbolic]
  656. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.9 [symbolic]
  657. // CHECK:STDOUT: %Make.type.2: type = fn_type @Make.1, @Factory(%B) [template]
  658. // CHECK:STDOUT: %Make.2: %Make.type.2 = struct_value () [template]
  659. // CHECK:STDOUT: %.7: type = assoc_entity_type %.4, %Make.type.2 [template]
  660. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.10 [template]
  661. // CHECK:STDOUT: %MakeB.type: type = fn_type @MakeB [template]
  662. // CHECK:STDOUT: %MakeB: %MakeB.type = struct_value () [template]
  663. // CHECK:STDOUT: %.9: type = ptr_type %.1 [template]
  664. // CHECK:STDOUT: %.10: %.5 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  665. // CHECK:STDOUT: %Make.type.3: type = fn_type @Make.2 [template]
  666. // CHECK:STDOUT: %Make.3: %Make.type.3 = struct_value () [template]
  667. // CHECK:STDOUT: %.11: <witness> = interface_witness (%Make.3) [template]
  668. // CHECK:STDOUT: }
  669. // CHECK:STDOUT:
  670. // CHECK:STDOUT: imports {
  671. // CHECK:STDOUT: %import_ref.1: %Factory.type = import_ref Main//factory, inst+4, loaded [template = constants.%Factory]
  672. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//factory, inst+27, loaded [template = constants.%A]
  673. // CHECK:STDOUT: %import_ref.3: type = import_ref Main//factory, inst+30, loaded [template = constants.%B]
  674. // CHECK:STDOUT: %import_ref.4 = import_ref Main//factory, inst+28, unloaded
  675. // CHECK:STDOUT: %import_ref.5 = import_ref Main//factory, inst+31, unloaded
  676. // CHECK:STDOUT: %import_ref.6 = import_ref Main//factory, inst+10, unloaded
  677. // CHECK:STDOUT: %import_ref.7: @Factory.%.2 (%.5) = import_ref Main//factory, inst+19, loaded [symbolic = @Factory.%.3 (constants.%.10)]
  678. // CHECK:STDOUT: %import_ref.8 = import_ref Main//factory, inst+14, unloaded
  679. // CHECK:STDOUT: %import_ref.9 = import_ref Main//factory, inst+14, unloaded
  680. // CHECK:STDOUT: %import_ref.10 = import_ref Main//factory, inst+14, unloaded
  681. // CHECK:STDOUT: %import_ref.11: <witness> = import_ref Main//factory, inst+47, loaded [template = constants.%.11]
  682. // CHECK:STDOUT: %import_ref.12 = import_ref Main//factory, inst+14, unloaded
  683. // CHECK:STDOUT: }
  684. // CHECK:STDOUT:
  685. // CHECK:STDOUT: file {
  686. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  687. // CHECK:STDOUT: .Factory = imports.%import_ref.1
  688. // CHECK:STDOUT: .A = imports.%import_ref.2
  689. // CHECK:STDOUT: .B = imports.%import_ref.3
  690. // CHECK:STDOUT: .MakeB = %MakeB.decl
  691. // CHECK:STDOUT: }
  692. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  693. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  694. // CHECK:STDOUT: %MakeB.decl: %MakeB.type = fn_decl @MakeB [template = constants.%MakeB] {
  695. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  696. // CHECK:STDOUT: %a.loc4_10.1: %A = param a, runtime_param0
  697. // CHECK:STDOUT: @MakeB.%a: %A = bind_name a, %a.loc4_10.1
  698. // CHECK:STDOUT: %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
  699. // CHECK:STDOUT: @MakeB.%return: ref %B = var <return slot>
  700. // CHECK:STDOUT: }
  701. // CHECK:STDOUT: }
  702. // CHECK:STDOUT:
  703. // CHECK:STDOUT: generic interface @Factory(constants.%T: type) {
  704. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  705. // CHECK:STDOUT:
  706. // CHECK:STDOUT: !definition:
  707. // CHECK:STDOUT: %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.3)]
  708. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  709. // CHECK:STDOUT: %Make.type: type = fn_type @Make.1, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
  710. // CHECK:STDOUT: %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
  711. // CHECK:STDOUT: %.2: type = assoc_entity_type @Factory.%.1 (%.3), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.5)]
  712. // CHECK:STDOUT: %.3: @Factory.%.2 (%.5) = assoc_entity element0, imports.%import_ref.9 [symbolic = %.3 (constants.%.6)]
  713. // CHECK:STDOUT:
  714. // CHECK:STDOUT: interface {
  715. // CHECK:STDOUT: !members:
  716. // CHECK:STDOUT: .Self = imports.%import_ref.6
  717. // CHECK:STDOUT: .Make = imports.%import_ref.7
  718. // CHECK:STDOUT: witness = (imports.%import_ref.8)
  719. // CHECK:STDOUT: }
  720. // CHECK:STDOUT: }
  721. // CHECK:STDOUT:
  722. // CHECK:STDOUT: impl @impl: %A as %.4 {
  723. // CHECK:STDOUT: !members:
  724. // CHECK:STDOUT: witness = imports.%import_ref.11
  725. // CHECK:STDOUT: }
  726. // CHECK:STDOUT:
  727. // CHECK:STDOUT: class @A {
  728. // CHECK:STDOUT: !members:
  729. // CHECK:STDOUT: .Self = imports.%import_ref.4
  730. // CHECK:STDOUT: }
  731. // CHECK:STDOUT:
  732. // CHECK:STDOUT: class @B {
  733. // CHECK:STDOUT: !members:
  734. // CHECK:STDOUT: .Self = imports.%import_ref.5
  735. // CHECK:STDOUT: }
  736. // CHECK:STDOUT:
  737. // CHECK:STDOUT: generic fn @Make.1(constants.%T: type, constants.%Self.1: @Factory.%.1 (%.3)) {
  738. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  739. // CHECK:STDOUT:
  740. // CHECK:STDOUT: fn() -> @Make.1.%T (%T);
  741. // CHECK:STDOUT: }
  742. // CHECK:STDOUT:
  743. // CHECK:STDOUT: fn @MakeB(%a: %A) -> %return: %B {
  744. // CHECK:STDOUT: !entry:
  745. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  746. // CHECK:STDOUT: %Factory.ref: %Factory.type = name_ref Factory, imports.%import_ref.1 [template = constants.%Factory]
  747. // CHECK:STDOUT: %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
  748. // CHECK:STDOUT: %.loc5_20: type = interface_type @Factory, @Factory(constants.%B) [template = constants.%.4]
  749. // CHECK:STDOUT: %.loc5_23: %.7 = specific_constant imports.%import_ref.7, @Factory(constants.%B) [template = constants.%.8]
  750. // CHECK:STDOUT: %Make.ref: %.7 = name_ref Make, %.loc5_23 [template = constants.%.8]
  751. // CHECK:STDOUT: %.loc5_11: %Make.type.2 = interface_witness_access imports.%import_ref.11, element0 [template = constants.%Make.3]
  752. // CHECK:STDOUT: %.loc4: ref %B = splice_block %return {}
  753. // CHECK:STDOUT: %Make.call: init %B = call %.loc5_11() to %.loc4
  754. // CHECK:STDOUT: return %Make.call to %return
  755. // CHECK:STDOUT: }
  756. // CHECK:STDOUT:
  757. // CHECK:STDOUT: fn @Make.2() -> %B;
  758. // CHECK:STDOUT:
  759. // CHECK:STDOUT: specific @Factory(constants.%T) {
  760. // CHECK:STDOUT: %T => constants.%T
  761. // CHECK:STDOUT: }
  762. // CHECK:STDOUT:
  763. // CHECK:STDOUT: specific @Factory(constants.%B) {
  764. // CHECK:STDOUT: %T => constants.%B
  765. // CHECK:STDOUT:
  766. // CHECK:STDOUT: !definition:
  767. // CHECK:STDOUT: %.1 => constants.%.4
  768. // CHECK:STDOUT: %Self => constants.%Self.2
  769. // CHECK:STDOUT: %Make.type => constants.%Make.type.2
  770. // CHECK:STDOUT: %Make => constants.%Make.2
  771. // CHECK:STDOUT: %.2 => constants.%.7
  772. // CHECK:STDOUT: %.3 => constants.%.8
  773. // CHECK:STDOUT: }
  774. // CHECK:STDOUT:
  775. // CHECK:STDOUT: specific @Factory(@Factory.%T) {
  776. // CHECK:STDOUT: %T => constants.%T
  777. // CHECK:STDOUT: }
  778. // CHECK:STDOUT:
  779. // CHECK:STDOUT: specific @Make.1(constants.%T, constants.%Self.1) {
  780. // CHECK:STDOUT: %T => constants.%T
  781. // CHECK:STDOUT: }
  782. // CHECK:STDOUT:
  783. // CHECK:STDOUT: --- fail_factory.impl.carbon
  784. // CHECK:STDOUT:
  785. // CHECK:STDOUT: constants {
  786. // CHECK:STDOUT: %A: type = class_type @A [template]
  787. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  788. // CHECK:STDOUT: %B: type = class_type @B [template]
  789. // CHECK:STDOUT: %Factory.type: type = generic_interface_type @Factory [template]
  790. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  791. // CHECK:STDOUT: %Factory: %Factory.type = struct_value () [template]
  792. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  793. // CHECK:STDOUT: %.3: type = interface_type @Factory, @Factory(%T) [symbolic]
  794. // CHECK:STDOUT: %Self.1: @Factory.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  795. // CHECK:STDOUT: %.4: type = interface_type @Factory, @Factory(%B) [template]
  796. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  797. // CHECK:STDOUT: %Make.type.1: type = fn_type @Make, @Factory(%T) [symbolic]
  798. // CHECK:STDOUT: %Make.1: %Make.type.1 = struct_value () [symbolic]
  799. // CHECK:STDOUT: %.5: type = assoc_entity_type %.3, %Make.type.1 [symbolic]
  800. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.9 [symbolic]
  801. // CHECK:STDOUT: %Make.type.2: type = fn_type @Make, @Factory(%B) [template]
  802. // CHECK:STDOUT: %Make.2: %Make.type.2 = struct_value () [template]
  803. // CHECK:STDOUT: %.7: type = assoc_entity_type %.4, %Make.type.2 [template]
  804. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.10 [template]
  805. // CHECK:STDOUT: %C: type = class_type @C [template]
  806. // CHECK:STDOUT: %MakeC.type: type = fn_type @MakeC [template]
  807. // CHECK:STDOUT: %MakeC: %MakeC.type = struct_value () [template]
  808. // CHECK:STDOUT: %.9: type = ptr_type %.1 [template]
  809. // CHECK:STDOUT: %.10: type = interface_type @Factory, @Factory(%C) [template]
  810. // CHECK:STDOUT: %Make.type.3: type = fn_type @Make, @Factory(%C) [template]
  811. // CHECK:STDOUT: %Make.3: %Make.type.3 = struct_value () [template]
  812. // CHECK:STDOUT: %.11: type = assoc_entity_type %.10, %Make.type.3 [template]
  813. // CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.9 [template]
  814. // CHECK:STDOUT: %.13: %.5 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  815. // CHECK:STDOUT: }
  816. // CHECK:STDOUT:
  817. // CHECK:STDOUT: imports {
  818. // CHECK:STDOUT: %import_ref.1: %Factory.type = import_ref Main//factory, inst+4, loaded [template = constants.%Factory]
  819. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//factory, inst+27, loaded [template = constants.%A]
  820. // CHECK:STDOUT: %import_ref.3 = import_ref Main//factory, inst+30, unloaded
  821. // CHECK:STDOUT: %import_ref.4 = import_ref Main//factory, inst+28, unloaded
  822. // CHECK:STDOUT: %import_ref.5 = import_ref Main//factory, inst+31, unloaded
  823. // CHECK:STDOUT: %import_ref.6 = import_ref Main//factory, inst+10, unloaded
  824. // CHECK:STDOUT: %import_ref.7: @Factory.%.2 (%.5) = import_ref Main//factory, inst+19, loaded [symbolic = @Factory.%.3 (constants.%.13)]
  825. // CHECK:STDOUT: %import_ref.8 = import_ref Main//factory, inst+14, unloaded
  826. // CHECK:STDOUT: %import_ref.9 = import_ref Main//factory, inst+14, unloaded
  827. // CHECK:STDOUT: %import_ref.10 = import_ref Main//factory, inst+14, unloaded
  828. // CHECK:STDOUT: %import_ref.11 = import_ref Main//factory, inst+47, unloaded
  829. // CHECK:STDOUT: %import_ref.12 = import_ref Main//factory, inst+14, unloaded
  830. // CHECK:STDOUT: }
  831. // CHECK:STDOUT:
  832. // CHECK:STDOUT: file {
  833. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  834. // CHECK:STDOUT: .Factory = imports.%import_ref.1
  835. // CHECK:STDOUT: .A = imports.%import_ref.2
  836. // CHECK:STDOUT: .B = imports.%import_ref.3
  837. // CHECK:STDOUT: .C = %C.decl
  838. // CHECK:STDOUT: .MakeC = %MakeC.decl
  839. // CHECK:STDOUT: }
  840. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  841. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  842. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  843. // CHECK:STDOUT: %MakeC.decl: %MakeC.type = fn_decl @MakeC [template = constants.%MakeC] {
  844. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  845. // CHECK:STDOUT: %a.loc6_10.1: %A = param a, runtime_param0
  846. // CHECK:STDOUT: @MakeC.%a: %A = bind_name a, %a.loc6_10.1
  847. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  848. // CHECK:STDOUT: @MakeC.%return: ref %C = var <return slot>
  849. // CHECK:STDOUT: }
  850. // CHECK:STDOUT: }
  851. // CHECK:STDOUT:
  852. // CHECK:STDOUT: generic interface @Factory(constants.%T: type) {
  853. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  854. // CHECK:STDOUT:
  855. // CHECK:STDOUT: !definition:
  856. // CHECK:STDOUT: %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.3)]
  857. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  858. // CHECK:STDOUT: %Make.type: type = fn_type @Make, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
  859. // CHECK:STDOUT: %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
  860. // CHECK:STDOUT: %.2: type = assoc_entity_type @Factory.%.1 (%.3), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.5)]
  861. // CHECK:STDOUT: %.3: @Factory.%.2 (%.5) = assoc_entity element0, imports.%import_ref.9 [symbolic = %.3 (constants.%.6)]
  862. // CHECK:STDOUT:
  863. // CHECK:STDOUT: interface {
  864. // CHECK:STDOUT: !members:
  865. // CHECK:STDOUT: .Self = imports.%import_ref.6
  866. // CHECK:STDOUT: .Make = imports.%import_ref.7
  867. // CHECK:STDOUT: witness = (imports.%import_ref.8)
  868. // CHECK:STDOUT: }
  869. // CHECK:STDOUT: }
  870. // CHECK:STDOUT:
  871. // CHECK:STDOUT: impl @impl: %A as %.4 {
  872. // CHECK:STDOUT: !members:
  873. // CHECK:STDOUT: witness = imports.%import_ref.11
  874. // CHECK:STDOUT: }
  875. // CHECK:STDOUT:
  876. // CHECK:STDOUT: class @A {
  877. // CHECK:STDOUT: !members:
  878. // CHECK:STDOUT: .Self = imports.%import_ref.4
  879. // CHECK:STDOUT: }
  880. // CHECK:STDOUT:
  881. // CHECK:STDOUT: class @B {
  882. // CHECK:STDOUT: !members:
  883. // CHECK:STDOUT: .Self = imports.%import_ref.5
  884. // CHECK:STDOUT: }
  885. // CHECK:STDOUT:
  886. // CHECK:STDOUT: class @C {
  887. // CHECK:STDOUT: !members:
  888. // CHECK:STDOUT: .Self = constants.%C
  889. // CHECK:STDOUT: }
  890. // CHECK:STDOUT:
  891. // CHECK:STDOUT: generic fn @Make(constants.%T: type, constants.%Self.1: @Factory.%.1 (%.3)) {
  892. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  893. // CHECK:STDOUT:
  894. // CHECK:STDOUT: fn() -> @Make.%T (%T);
  895. // CHECK:STDOUT: }
  896. // CHECK:STDOUT:
  897. // CHECK:STDOUT: fn @MakeC(%a: %A) -> %return: %C {
  898. // CHECK:STDOUT: !entry:
  899. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  900. // CHECK:STDOUT: %Factory.ref: %Factory.type = name_ref Factory, imports.%import_ref.1 [template = constants.%Factory]
  901. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  902. // CHECK:STDOUT: %.loc10_20: type = interface_type @Factory, @Factory(constants.%C) [template = constants.%.10]
  903. // CHECK:STDOUT: %.loc10_23: %.11 = specific_constant imports.%import_ref.7, @Factory(constants.%C) [template = constants.%.12]
  904. // CHECK:STDOUT: %Make.ref: %.11 = name_ref Make, %.loc10_23 [template = constants.%.12]
  905. // CHECK:STDOUT: return <error> to %return
  906. // CHECK:STDOUT: }
  907. // CHECK:STDOUT:
  908. // CHECK:STDOUT: specific @Factory(constants.%T) {
  909. // CHECK:STDOUT: %T => constants.%T
  910. // CHECK:STDOUT: }
  911. // CHECK:STDOUT:
  912. // CHECK:STDOUT: specific @Factory(constants.%B) {
  913. // CHECK:STDOUT: %T => constants.%B
  914. // CHECK:STDOUT:
  915. // CHECK:STDOUT: !definition:
  916. // CHECK:STDOUT: %.1 => constants.%.4
  917. // CHECK:STDOUT: %Self => constants.%Self.2
  918. // CHECK:STDOUT: %Make.type => constants.%Make.type.2
  919. // CHECK:STDOUT: %Make => constants.%Make.2
  920. // CHECK:STDOUT: %.2 => constants.%.7
  921. // CHECK:STDOUT: %.3 => constants.%.8
  922. // CHECK:STDOUT: }
  923. // CHECK:STDOUT:
  924. // CHECK:STDOUT: specific @Factory(@Factory.%T) {
  925. // CHECK:STDOUT: %T => constants.%T
  926. // CHECK:STDOUT: }
  927. // CHECK:STDOUT:
  928. // CHECK:STDOUT: specific @Make(constants.%T, constants.%Self.1) {
  929. // CHECK:STDOUT: %T => constants.%T
  930. // CHECK:STDOUT: }
  931. // CHECK:STDOUT:
  932. // CHECK:STDOUT: specific @Factory(constants.%C) {
  933. // CHECK:STDOUT: %T => constants.%C
  934. // CHECK:STDOUT:
  935. // CHECK:STDOUT: !definition:
  936. // CHECK:STDOUT: %.1 => constants.%.10
  937. // CHECK:STDOUT: %Self => constants.%Self.2
  938. // CHECK:STDOUT: %Make.type => constants.%Make.type.3
  939. // CHECK:STDOUT: %Make => constants.%Make.3
  940. // CHECK:STDOUT: %.2 => constants.%.11
  941. // CHECK:STDOUT: %.3 => constants.%.12
  942. // CHECK:STDOUT: }
  943. // CHECK:STDOUT: