interface_args.carbon 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 "action";
  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. // --- action.impl.carbon
  22. impl library "action";
  23. fn F(a: A) { a.(Action(B).Op)(); }
  24. // --- fail_action.impl.carbon
  25. impl library "action";
  26. // 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.
  27. // CHECK:STDERR: fn G(a: A) { a.(Action(C).Op)(); }
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. fn G(a: A) { a.(Action(C).Op)(); }
  31. // --- fail_todo_factory.carbon
  32. library "fail_todo_factory";
  33. interface Factory(T:! type) {
  34. fn Make() -> T;
  35. }
  36. class A {}
  37. class B {}
  38. impl A as Factory(B) {
  39. // CHECK:STDERR: fail_todo_factory.carbon:[[@LINE+6]]:3: ERROR: Function redeclaration differs because return type is `B`.
  40. // CHECK:STDERR: fn Make() -> B;
  41. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  42. // CHECK:STDERR: fail_todo_factory.carbon:[[@LINE-10]]:3: Previously declared with return type `T`.
  43. // CHECK:STDERR: fn Make() -> T;
  44. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  45. fn Make() -> B;
  46. }
  47. // CHECK:STDOUT: --- action.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  51. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  52. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  53. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  54. // CHECK:STDOUT: %.2: type = interface_type @Action, @Action(%T) [symbolic]
  55. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  56. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1, @Action(%T) [symbolic]
  57. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [symbolic]
  58. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, %Op.type.1 [symbolic]
  59. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Action.%Op.decl [symbolic]
  60. // CHECK:STDOUT: %A: type = class_type @A [template]
  61. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  62. // CHECK:STDOUT: %B: type = class_type @B [template]
  63. // CHECK:STDOUT: %C: type = class_type @C [template]
  64. // CHECK:STDOUT: %.6: type = interface_type @Action, @Action(%B) [template]
  65. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  66. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  67. // CHECK:STDOUT: %.7: <witness> = interface_witness (%Op.2) [template]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  72. // CHECK:STDOUT: .Action = %Action.decl
  73. // CHECK:STDOUT: .A = %A.decl
  74. // CHECK:STDOUT: .B = %B.decl
  75. // CHECK:STDOUT: .C = %C.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Action.decl: %Action.type = interface_decl @Action [template = constants.%Action] {
  78. // CHECK:STDOUT: %T.loc4_18.1: type = param T
  79. // CHECK:STDOUT: %T.loc4_18.2: type = bind_symbolic_name T 0, %T.loc4_18.1 [symbolic = @Action.%T (constants.%T)]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  82. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  83. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  84. // CHECK:STDOUT: %.loc12_19.1: type = value_of_initializer %.loc12_17 [template = constants.%.6]
  85. // CHECK:STDOUT: %.loc12_19.2: type = converted %.loc12_17, %.loc12_19.1 [template = constants.%.6]
  86. // CHECK:STDOUT: impl_decl @impl {
  87. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  88. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, %Action.decl [template = constants.%Action]
  89. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  90. // CHECK:STDOUT: %.loc12_17: init type = call %Action.ref(%B.ref) [template = constants.%.6]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic interface @Action(file.%T.loc4_18.2: type) {
  95. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !definition:
  98. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.2)]
  99. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  100. // CHECK:STDOUT: %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.1)]
  101. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.1) = struct_value () [symbolic = %Op (constants.%Op.1)]
  102. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.2), @Action.%Op.type (%Op.type.1) [symbolic = %.2 (constants.%.3)]
  103. // CHECK:STDOUT: %.3: @Action.%.2 (%.3) = assoc_entity element0, %Op.decl [symbolic = %.3 (constants.%.4)]
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: interface {
  106. // CHECK:STDOUT: %Self.1: @Action.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  107. // CHECK:STDOUT: %Op.decl: @Action.%Op.type (%Op.type.1) = fn_decl @Op.1 [symbolic = %Op (constants.%Op.1)] {}
  108. // CHECK:STDOUT: %.loc5: @Action.%.2 (%.3) = assoc_entity element0, %Op.decl [symbolic = %.3 (constants.%.4)]
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !members:
  111. // CHECK:STDOUT: .Self = %Self.1
  112. // CHECK:STDOUT: .Op = %.loc5
  113. // CHECK:STDOUT: witness = (%Op.decl)
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: impl @impl: %A as %.6 {
  118. // CHECK:STDOUT: %Op.decl: %Op.type.2 = fn_decl @Op.2 [template = constants.%Op.2] {}
  119. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.7]
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Op = %Op.decl
  123. // CHECK:STDOUT: witness = %.1
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: class @A {
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%A
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: class @B {
  132. // CHECK:STDOUT: !members:
  133. // CHECK:STDOUT: .Self = constants.%B
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: class @C {
  137. // CHECK:STDOUT: !members:
  138. // CHECK:STDOUT: .Self = constants.%C
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: generic fn @Op.1(file.%T.loc4_18.2: type, @Action.%Self.1: @Action.%.1 (%.2)) {
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn();
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @Op.2() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: return
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: specific @Action(constants.%T) {
  152. // CHECK:STDOUT: %T => constants.%T
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: specific @Op.1(constants.%T, constants.%Self) {}
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: specific @Action(@Action.%T) {
  158. // CHECK:STDOUT: %T => constants.%T
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: specific @Action(constants.%B) {
  162. // CHECK:STDOUT: %T => constants.%B
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: --- action.impl.carbon
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: constants {
  168. // CHECK:STDOUT: %A: type = class_type @A [template]
  169. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  170. // CHECK:STDOUT: %B: type = class_type @B [template]
  171. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  172. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  173. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  174. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  175. // CHECK:STDOUT: %.3: type = interface_type @Action, @Action(%T) [symbolic]
  176. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic]
  177. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  178. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  179. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.1, @Action(%T) [symbolic]
  180. // CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %Op.type.2 [symbolic]
  181. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  182. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [symbolic]
  183. // CHECK:STDOUT: %.6: type = interface_type @Action, @Action(%B) [template]
  184. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  185. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  186. // CHECK:STDOUT: %.7: type = ptr_type %.1 [template]
  187. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.1, @Action(%B) [template]
  188. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  189. // CHECK:STDOUT: %.8: type = assoc_entity_type %.6, %Op.type.3 [template]
  190. // CHECK:STDOUT: %.9: %.8 = assoc_entity element0, imports.%import_ref.7 [template]
  191. // CHECK:STDOUT: %.10: %.4 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  192. // CHECK:STDOUT: %Op.type.4: type = fn_type @Op.2 [template]
  193. // CHECK:STDOUT: %Op.4: %Op.type.4 = struct_value () [template]
  194. // CHECK:STDOUT: %.11: <witness> = interface_witness (%Op.4) [template]
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: imports {
  198. // CHECK:STDOUT: %import_ref.1: %Action.type = import_ref Main//action, inst+4, loaded [template = constants.%Action]
  199. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
  200. // CHECK:STDOUT: %import_ref.3: type = import_ref Main//action, inst+27, loaded [template = constants.%B]
  201. // CHECK:STDOUT: %import_ref.4 = import_ref Main//action, inst+29, unloaded
  202. // CHECK:STDOUT: %import_ref.5 = import_ref Main//action, inst+25, unloaded
  203. // CHECK:STDOUT: %import_ref.6 = import_ref Main//action, inst+28, unloaded
  204. // CHECK:STDOUT: %import_ref.7 = import_ref Main//action, inst+12, unloaded
  205. // CHECK:STDOUT: %import_ref.8 = import_ref Main//action, inst+10, unloaded
  206. // CHECK:STDOUT: %import_ref.9: @Action.%.2 (%.4) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.10)]
  207. // CHECK:STDOUT: %import_ref.10 = import_ref Main//action, inst+12, unloaded
  208. // CHECK:STDOUT: %import_ref.11: <witness> = import_ref Main//action, inst+42, loaded [template = constants.%.11]
  209. // CHECK:STDOUT: %import_ref.12 = import_ref Main//action, inst+12, unloaded
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: file {
  213. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  214. // CHECK:STDOUT: .Action = imports.%import_ref.1
  215. // CHECK:STDOUT: .A = imports.%import_ref.2
  216. // CHECK:STDOUT: .B = imports.%import_ref.3
  217. // CHECK:STDOUT: .C = imports.%import_ref.4
  218. // CHECK:STDOUT: .F = %F.decl
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  221. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  222. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  223. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  224. // CHECK:STDOUT: %a.loc4_6.1: %A = param a
  225. // CHECK:STDOUT: @F.%a: %A = bind_name a, %a.loc4_6.1
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: generic interface @Action(constants.%T: type) {
  230. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: !definition:
  233. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
  234. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self)]
  235. // CHECK:STDOUT: %Op.type: type = fn_type @Op.1, @Action(%T) [symbolic = %Op.type (constants.%Op.type.2)]
  236. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.2) = struct_value () [symbolic = %Op (constants.%Op.2)]
  237. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.2) [symbolic = %.2 (constants.%.4)]
  238. // CHECK:STDOUT: %.3: @Action.%.2 (%.4) = assoc_entity element0, imports.%import_ref.7 [symbolic = %.3 (constants.%.5)]
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: interface {
  241. // CHECK:STDOUT: !members:
  242. // CHECK:STDOUT: .Self = imports.%import_ref.8
  243. // CHECK:STDOUT: .Op = imports.%import_ref.9
  244. // CHECK:STDOUT: witness = (imports.%import_ref.10)
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: impl @impl: %A as %.6 {
  249. // CHECK:STDOUT: !members:
  250. // CHECK:STDOUT: witness = imports.%import_ref.11
  251. // CHECK:STDOUT: }
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: class @A {
  254. // CHECK:STDOUT: !members:
  255. // CHECK:STDOUT: .Self = imports.%import_ref.5
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: class @B {
  259. // CHECK:STDOUT: !members:
  260. // CHECK:STDOUT: .Self = imports.%import_ref.6
  261. // CHECK:STDOUT: }
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: generic fn @Op.1(constants.%T: type, constants.%Self: %.3) {
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: fn();
  266. // CHECK:STDOUT: }
  267. // CHECK:STDOUT:
  268. // CHECK:STDOUT: fn @F(%a: %A) {
  269. // CHECK:STDOUT: !entry:
  270. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  271. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
  272. // CHECK:STDOUT: %B.ref: type = name_ref B, imports.%import_ref.3 [template = constants.%B]
  273. // CHECK:STDOUT: %.loc4_23: init type = call %Action.ref(%B.ref) [template = constants.%.6]
  274. // CHECK:STDOUT: %.loc4_26: %.8 = specific_constant imports.%import_ref.9, @Action(constants.%B) [template = constants.%.9]
  275. // CHECK:STDOUT: %Op.ref: %.8 = name_ref Op, %.loc4_26 [template = constants.%.9]
  276. // CHECK:STDOUT: %.1: %Op.type.3 = interface_witness_access imports.%import_ref.11, element0 [template = constants.%Op.4]
  277. // CHECK:STDOUT: %Op.call: init %.2 = call %.1()
  278. // CHECK:STDOUT: return
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: fn @Op.2();
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: specific @Action(constants.%T) {
  284. // CHECK:STDOUT: %T => constants.%T
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: specific @Action(@Action.%T) {
  288. // CHECK:STDOUT: %T => constants.%T
  289. // CHECK:STDOUT: }
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: specific @Action(constants.%B) {
  292. // CHECK:STDOUT: %T => constants.%B
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: !definition:
  295. // CHECK:STDOUT: %.1 => constants.%.6
  296. // CHECK:STDOUT: %Self => constants.%Self
  297. // CHECK:STDOUT: %Op.type => constants.%Op.type.3
  298. // CHECK:STDOUT: %Op => constants.%Op.3
  299. // CHECK:STDOUT: %.2 => constants.%.8
  300. // CHECK:STDOUT: %.3 => constants.%.9
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: --- fail_action.impl.carbon
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: constants {
  306. // CHECK:STDOUT: %A: type = class_type @A [template]
  307. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  308. // CHECK:STDOUT: %B: type = class_type @B [template]
  309. // CHECK:STDOUT: %Action.type: type = generic_interface_type @Action [template]
  310. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  311. // CHECK:STDOUT: %Action: %Action.type = struct_value () [template]
  312. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  313. // CHECK:STDOUT: %.3: type = interface_type @Action, @Action(%T) [symbolic]
  314. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic]
  315. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op [template]
  316. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  317. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op, @Action(%T) [symbolic]
  318. // CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %Op.type.2 [symbolic]
  319. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  320. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [symbolic]
  321. // CHECK:STDOUT: %.6: type = interface_type @Action, @Action(%B) [template]
  322. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  323. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  324. // CHECK:STDOUT: %.7: type = ptr_type %.1 [template]
  325. // CHECK:STDOUT: %C: type = class_type @C [template]
  326. // CHECK:STDOUT: %.8: type = interface_type @Action, @Action(%C) [template]
  327. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op, @Action(%C) [template]
  328. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  329. // CHECK:STDOUT: %.9: type = assoc_entity_type %.8, %Op.type.3 [template]
  330. // CHECK:STDOUT: %.10: %.9 = assoc_entity element0, imports.%import_ref.7 [template]
  331. // CHECK:STDOUT: %.11: %.4 = assoc_entity element0, imports.%import_ref.13 [symbolic]
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: imports {
  335. // CHECK:STDOUT: %import_ref.1: %Action.type = import_ref Main//action, inst+4, loaded [template = constants.%Action]
  336. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//action, inst+24, loaded [template = constants.%A]
  337. // CHECK:STDOUT: %import_ref.3 = import_ref Main//action, inst+27, unloaded
  338. // CHECK:STDOUT: %import_ref.4: type = import_ref Main//action, inst+29, loaded [template = constants.%C]
  339. // CHECK:STDOUT: %import_ref.5 = import_ref Main//action, inst+25, unloaded
  340. // CHECK:STDOUT: %import_ref.6 = import_ref Main//action, inst+28, unloaded
  341. // CHECK:STDOUT: %import_ref.7 = import_ref Main//action, inst+12, unloaded
  342. // CHECK:STDOUT: %import_ref.8 = import_ref Main//action, inst+10, unloaded
  343. // CHECK:STDOUT: %import_ref.9: @Action.%.2 (%.4) = import_ref Main//action, inst+16, loaded [symbolic = @Action.%.3 (constants.%.11)]
  344. // CHECK:STDOUT: %import_ref.10 = import_ref Main//action, inst+12, unloaded
  345. // CHECK:STDOUT: %import_ref.11 = import_ref Main//action, inst+42, unloaded
  346. // CHECK:STDOUT: %import_ref.12 = import_ref Main//action, inst+30, unloaded
  347. // CHECK:STDOUT: %import_ref.13 = import_ref Main//action, inst+12, unloaded
  348. // CHECK:STDOUT: }
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: file {
  351. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  352. // CHECK:STDOUT: .Action = imports.%import_ref.1
  353. // CHECK:STDOUT: .A = imports.%import_ref.2
  354. // CHECK:STDOUT: .B = imports.%import_ref.3
  355. // CHECK:STDOUT: .C = imports.%import_ref.4
  356. // CHECK:STDOUT: .G = %G.decl
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  359. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  360. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  361. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  362. // CHECK:STDOUT: %a.loc8_6.1: %A = param a
  363. // CHECK:STDOUT: @G.%a: %A = bind_name a, %a.loc8_6.1
  364. // CHECK:STDOUT: }
  365. // CHECK:STDOUT: }
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: generic interface @Action(constants.%T: type) {
  368. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: !definition:
  371. // CHECK:STDOUT: %.1: type = interface_type @Action, @Action(%T) [symbolic = %.1 (constants.%.3)]
  372. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self)]
  373. // CHECK:STDOUT: %Op.type: type = fn_type @Op, @Action(%T) [symbolic = %Op.type (constants.%Op.type.2)]
  374. // CHECK:STDOUT: %Op: @Action.%Op.type (%Op.type.2) = struct_value () [symbolic = %Op (constants.%Op.2)]
  375. // CHECK:STDOUT: %.2: type = assoc_entity_type @Action.%.1 (%.3), @Action.%Op.type (%Op.type.2) [symbolic = %.2 (constants.%.4)]
  376. // CHECK:STDOUT: %.3: @Action.%.2 (%.4) = assoc_entity element0, imports.%import_ref.7 [symbolic = %.3 (constants.%.5)]
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: interface {
  379. // CHECK:STDOUT: !members:
  380. // CHECK:STDOUT: .Self = imports.%import_ref.8
  381. // CHECK:STDOUT: .Op = imports.%import_ref.9
  382. // CHECK:STDOUT: witness = (imports.%import_ref.10)
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT: }
  385. // CHECK:STDOUT:
  386. // CHECK:STDOUT: impl @impl: %A as %.6 {
  387. // CHECK:STDOUT: !members:
  388. // CHECK:STDOUT: witness = imports.%import_ref.11
  389. // CHECK:STDOUT: }
  390. // CHECK:STDOUT:
  391. // CHECK:STDOUT: class @A {
  392. // CHECK:STDOUT: !members:
  393. // CHECK:STDOUT: .Self = imports.%import_ref.5
  394. // CHECK:STDOUT: }
  395. // CHECK:STDOUT:
  396. // CHECK:STDOUT: class @B {
  397. // CHECK:STDOUT: !members:
  398. // CHECK:STDOUT: .Self = imports.%import_ref.6
  399. // CHECK:STDOUT: }
  400. // CHECK:STDOUT:
  401. // CHECK:STDOUT: class @C {
  402. // CHECK:STDOUT: !members:
  403. // CHECK:STDOUT: .Self = imports.%import_ref.12
  404. // CHECK:STDOUT: }
  405. // CHECK:STDOUT:
  406. // CHECK:STDOUT: generic fn @Op(constants.%T: type, constants.%Self: %.3) {
  407. // CHECK:STDOUT:
  408. // CHECK:STDOUT: fn();
  409. // CHECK:STDOUT: }
  410. // CHECK:STDOUT:
  411. // CHECK:STDOUT: fn @G(%a: %A) {
  412. // CHECK:STDOUT: !entry:
  413. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  414. // CHECK:STDOUT: %Action.ref: %Action.type = name_ref Action, imports.%import_ref.1 [template = constants.%Action]
  415. // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%import_ref.4 [template = constants.%C]
  416. // CHECK:STDOUT: %.loc8_23: init type = call %Action.ref(%C.ref) [template = constants.%.8]
  417. // CHECK:STDOUT: %.loc8_26: %.9 = specific_constant imports.%import_ref.9, @Action(constants.%C) [template = constants.%.10]
  418. // CHECK:STDOUT: %Op.ref: %.9 = name_ref Op, %.loc8_26 [template = constants.%.10]
  419. // CHECK:STDOUT: return
  420. // CHECK:STDOUT: }
  421. // CHECK:STDOUT:
  422. // CHECK:STDOUT: specific @Action(constants.%T) {
  423. // CHECK:STDOUT: %T => constants.%T
  424. // CHECK:STDOUT: }
  425. // CHECK:STDOUT:
  426. // CHECK:STDOUT: specific @Action(@Action.%T) {
  427. // CHECK:STDOUT: %T => constants.%T
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: specific @Action(constants.%B) {
  431. // CHECK:STDOUT: %T => constants.%B
  432. // CHECK:STDOUT: }
  433. // CHECK:STDOUT:
  434. // CHECK:STDOUT: specific @Action(constants.%C) {
  435. // CHECK:STDOUT: %T => constants.%C
  436. // CHECK:STDOUT:
  437. // CHECK:STDOUT: !definition:
  438. // CHECK:STDOUT: %.1 => constants.%.8
  439. // CHECK:STDOUT: %Self => constants.%Self
  440. // CHECK:STDOUT: %Op.type => constants.%Op.type.3
  441. // CHECK:STDOUT: %Op => constants.%Op.3
  442. // CHECK:STDOUT: %.2 => constants.%.9
  443. // CHECK:STDOUT: %.3 => constants.%.10
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: --- fail_todo_factory.carbon
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: constants {
  449. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  450. // CHECK:STDOUT: %Factory.type: type = generic_interface_type @Factory [template]
  451. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  452. // CHECK:STDOUT: %Factory: %Factory.type = struct_value () [template]
  453. // CHECK:STDOUT: %.2: type = interface_type @Factory, @Factory(%T) [symbolic]
  454. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  455. // CHECK:STDOUT: %Make.type.1: type = fn_type @Make.1, @Factory(%T) [symbolic]
  456. // CHECK:STDOUT: %Make.1: %Make.type.1 = struct_value () [symbolic]
  457. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, %Make.type.1 [symbolic]
  458. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Factory.%Make.decl [symbolic]
  459. // CHECK:STDOUT: %A: type = class_type @A [template]
  460. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  461. // CHECK:STDOUT: %B: type = class_type @B [template]
  462. // CHECK:STDOUT: %.6: type = interface_type @Factory, @Factory(%B) [template]
  463. // CHECK:STDOUT: %Make.type.2: type = fn_type @Make.2 [template]
  464. // CHECK:STDOUT: %Make.2: %Make.type.2 = struct_value () [template]
  465. // CHECK:STDOUT: }
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: file {
  468. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  469. // CHECK:STDOUT: .Factory = %Factory.decl
  470. // CHECK:STDOUT: .A = %A.decl
  471. // CHECK:STDOUT: .B = %B.decl
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT: %Factory.decl: %Factory.type = interface_decl @Factory [template = constants.%Factory] {
  474. // CHECK:STDOUT: %T.loc4_19.1: type = param T
  475. // CHECK:STDOUT: %T.loc4_19.2: type = bind_symbolic_name T 0, %T.loc4_19.1 [symbolic = @Factory.%T (constants.%T)]
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  478. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  479. // CHECK:STDOUT: %.loc11_20.1: type = value_of_initializer %.loc11_18 [template = constants.%.6]
  480. // CHECK:STDOUT: %.loc11_20.2: type = converted %.loc11_18, %.loc11_20.1 [template = constants.%.6]
  481. // CHECK:STDOUT: impl_decl @impl {
  482. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  483. // CHECK:STDOUT: %Factory.ref: %Factory.type = name_ref Factory, %Factory.decl [template = constants.%Factory]
  484. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  485. // CHECK:STDOUT: %.loc11_18: init type = call %Factory.ref(%B.ref) [template = constants.%.6]
  486. // CHECK:STDOUT: }
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: generic interface @Factory(file.%T.loc4_19.2: type) {
  490. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  491. // CHECK:STDOUT:
  492. // CHECK:STDOUT: !definition:
  493. // CHECK:STDOUT: %.1: type = interface_type @Factory, @Factory(%T) [symbolic = %.1 (constants.%.2)]
  494. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  495. // CHECK:STDOUT: %Make.type: type = fn_type @Make.1, @Factory(%T) [symbolic = %Make.type (constants.%Make.type.1)]
  496. // CHECK:STDOUT: %Make: @Factory.%Make.type (%Make.type.1) = struct_value () [symbolic = %Make (constants.%Make.1)]
  497. // CHECK:STDOUT: %.2: type = assoc_entity_type @Factory.%.1 (%.2), @Factory.%Make.type (%Make.type.1) [symbolic = %.2 (constants.%.3)]
  498. // CHECK:STDOUT: %.3: @Factory.%.2 (%.3) = assoc_entity element0, %Make.decl [symbolic = %.3 (constants.%.4)]
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: interface {
  501. // CHECK:STDOUT: %Self.1: @Factory.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  502. // CHECK:STDOUT: %Make.decl: @Factory.%Make.type (%Make.type.1) = fn_decl @Make.1 [symbolic = %Make (constants.%Make.1)] {
  503. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc4_19.2 [symbolic = @Make.1.%T (constants.%T)]
  504. // CHECK:STDOUT: %return.var: ref @Make.1.%T (%T) = var <return slot>
  505. // CHECK:STDOUT: }
  506. // CHECK:STDOUT: %.loc5: @Factory.%.2 (%.3) = assoc_entity element0, %Make.decl [symbolic = %.3 (constants.%.4)]
  507. // CHECK:STDOUT:
  508. // CHECK:STDOUT: !members:
  509. // CHECK:STDOUT: .Self = %Self.1
  510. // CHECK:STDOUT: .Make = %.loc5
  511. // CHECK:STDOUT: witness = (%Make.decl)
  512. // CHECK:STDOUT: }
  513. // CHECK:STDOUT: }
  514. // CHECK:STDOUT:
  515. // CHECK:STDOUT: impl @impl: %A as %.6 {
  516. // CHECK:STDOUT: %Make.decl: %Make.type.2 = fn_decl @Make.2 [template = constants.%Make.2] {
  517. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  518. // CHECK:STDOUT: %return.var: ref %B = var <return slot>
  519. // CHECK:STDOUT: }
  520. // CHECK:STDOUT: %.1: <witness> = interface_witness (<error>) [template = <error>]
  521. // CHECK:STDOUT:
  522. // CHECK:STDOUT: !members:
  523. // CHECK:STDOUT: .Make = %Make.decl
  524. // CHECK:STDOUT: witness = %.1
  525. // CHECK:STDOUT: }
  526. // CHECK:STDOUT:
  527. // CHECK:STDOUT: class @A {
  528. // CHECK:STDOUT: !members:
  529. // CHECK:STDOUT: .Self = constants.%A
  530. // CHECK:STDOUT: }
  531. // CHECK:STDOUT:
  532. // CHECK:STDOUT: class @B {
  533. // CHECK:STDOUT: !members:
  534. // CHECK:STDOUT: .Self = constants.%B
  535. // CHECK:STDOUT: }
  536. // CHECK:STDOUT:
  537. // CHECK:STDOUT: generic fn @Make.1(file.%T.loc4_19.2: type, @Factory.%Self.1: @Factory.%.1 (%.2)) {
  538. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  539. // CHECK:STDOUT:
  540. // CHECK:STDOUT: fn() -> @Make.1.%T (%T);
  541. // CHECK:STDOUT: }
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: fn @Make.2() -> %B;
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: specific @Factory(constants.%T) {
  546. // CHECK:STDOUT: %T => constants.%T
  547. // CHECK:STDOUT: }
  548. // CHECK:STDOUT:
  549. // CHECK:STDOUT: specific @Make.1(constants.%T, constants.%Self) {
  550. // CHECK:STDOUT: %T => constants.%T
  551. // CHECK:STDOUT: }
  552. // CHECK:STDOUT:
  553. // CHECK:STDOUT: specific @Factory(@Factory.%T) {
  554. // CHECK:STDOUT: %T => constants.%T
  555. // CHECK:STDOUT: }
  556. // CHECK:STDOUT:
  557. // CHECK:STDOUT: specific @Factory(constants.%B) {
  558. // CHECK:STDOUT: %T => constants.%B
  559. // CHECK:STDOUT: }
  560. // CHECK:STDOUT: