generic.carbon 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/generic.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/generic.carbon
  14. // --- generic.carbon
  15. library "[[@TEST_NAME]]";
  16. interface Simple(T:! type) {}
  17. class X {}
  18. interface WithAssocFn(T:! type) {
  19. // TODO: Take `Self`, return `T`, once that works.
  20. fn F() -> X;
  21. }
  22. class C {
  23. impl as Simple(C) {}
  24. impl as WithAssocFn(C) {
  25. fn F() -> X {
  26. return {};
  27. }
  28. }
  29. }
  30. interface WithImplicitArgs[T:! type](N:! T);
  31. fn Receive(T:! Simple(C)) {}
  32. fn Pass(T:! Simple(C)) {
  33. Receive(T);
  34. }
  35. // --- fail_mismatched_args.carbon
  36. library "[[@TEST_NAME]]";
  37. interface Generic(T:! type) {}
  38. class A {}
  39. class B {}
  40. fn F(T:! Generic(A));
  41. fn G(T:! Generic(B)) {
  42. // CHECK:STDERR: fail_mismatched_args.carbon:[[@LINE+7]]:3: error: cannot convert type `T` that implements `Generic(B)` into type implementing `Generic(A)` [ConversionFailureFacetToFacet]
  43. // CHECK:STDERR: F(T);
  44. // CHECK:STDERR: ^~~~
  45. // CHECK:STDERR: fail_mismatched_args.carbon:[[@LINE-5]]:6: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  46. // CHECK:STDERR: fn F(T:! Generic(A));
  47. // CHECK:STDERR: ^
  48. // CHECK:STDERR:
  49. F(T);
  50. }
  51. // CHECK:STDOUT: --- generic.carbon
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: constants {
  54. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  55. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self]
  56. // CHECK:STDOUT: %T.8b3: type = bind_symbolic_name T, 0 [symbolic]
  57. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  58. // CHECK:STDOUT: %Simple.type.3b3: type = generic_interface_type @Simple [concrete]
  59. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  60. // CHECK:STDOUT: %Simple.generic: %Simple.type.3b3 = struct_value () [concrete]
  61. // CHECK:STDOUT: %Simple.type.a1f: type = facet_type <@Simple, @Simple(%T.8b3)> [symbolic]
  62. // CHECK:STDOUT: %Self.4c2: %Simple.type.a1f = bind_symbolic_name Self, 1 [symbolic]
  63. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  64. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  66. // CHECK:STDOUT: %WithAssocFn.type.509: type = generic_interface_type @WithAssocFn [concrete]
  67. // CHECK:STDOUT: %WithAssocFn.generic: %WithAssocFn.type.509 = struct_value () [concrete]
  68. // CHECK:STDOUT: %WithAssocFn.type.61b: type = facet_type <@WithAssocFn, @WithAssocFn(%T.8b3)> [symbolic]
  69. // CHECK:STDOUT: %Self.c02: %WithAssocFn.type.61b = bind_symbolic_name Self, 1 [symbolic]
  70. // CHECK:STDOUT: %pattern_type.019: type = pattern_type %X [concrete]
  71. // CHECK:STDOUT: %WithAssocFn.F.type.1af: type = fn_type @WithAssocFn.F, @WithAssocFn(%T.8b3) [symbolic]
  72. // CHECK:STDOUT: %WithAssocFn.F.b7d: %WithAssocFn.F.type.1af = struct_value () [symbolic]
  73. // CHECK:STDOUT: %WithAssocFn.assoc_type.b2f: type = assoc_entity_type @WithAssocFn, @WithAssocFn(%T.8b3) [symbolic]
  74. // CHECK:STDOUT: %assoc0.fc5: %WithAssocFn.assoc_type.b2f = assoc_entity element0, @WithAssocFn.%WithAssocFn.F.decl [symbolic]
  75. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  76. // CHECK:STDOUT: %Simple.type.ebf: type = facet_type <@Simple, @Simple(%C)> [concrete]
  77. // CHECK:STDOUT: %Self.ae2: %Simple.type.ebf = bind_symbolic_name Self, 1 [symbolic]
  78. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness @C.%Simple.impl_witness_table [concrete]
  79. // CHECK:STDOUT: %WithAssocFn.type.fc9: type = facet_type <@WithAssocFn, @WithAssocFn(%C)> [concrete]
  80. // CHECK:STDOUT: %Self.8cc: %WithAssocFn.type.fc9 = bind_symbolic_name Self, 1 [symbolic]
  81. // CHECK:STDOUT: %WithAssocFn.F.type.18c: type = fn_type @WithAssocFn.F, @WithAssocFn(%C) [concrete]
  82. // CHECK:STDOUT: %WithAssocFn.F.e46: %WithAssocFn.F.type.18c = struct_value () [concrete]
  83. // CHECK:STDOUT: %WithAssocFn.assoc_type.9ea: type = assoc_entity_type @WithAssocFn, @WithAssocFn(%C) [concrete]
  84. // CHECK:STDOUT: %assoc0.cad: %WithAssocFn.assoc_type.9ea = assoc_entity element0, @WithAssocFn.%WithAssocFn.F.decl [concrete]
  85. // CHECK:STDOUT: %WithAssocFn.impl_witness: <witness> = impl_witness @C.%WithAssocFn.impl_witness_table [concrete]
  86. // CHECK:STDOUT: %C.as.WithAssocFn.impl.F.type: type = fn_type @C.as.WithAssocFn.impl.F [concrete]
  87. // CHECK:STDOUT: %C.as.WithAssocFn.impl.F: %C.as.WithAssocFn.impl.F.type = struct_value () [concrete]
  88. // CHECK:STDOUT: %WithAssocFn.facet: %WithAssocFn.type.fc9 = facet_value %C, (%WithAssocFn.impl_witness) [concrete]
  89. // CHECK:STDOUT: %X.val: %X = struct_value () [concrete]
  90. // CHECK:STDOUT: %N: %T.8b3 = bind_symbolic_name N, 1 [symbolic]
  91. // CHECK:STDOUT: %pattern_type.7dc: type = pattern_type %T.8b3 [symbolic]
  92. // CHECK:STDOUT: %WithImplicitArgs.type: type = generic_interface_type @WithImplicitArgs [concrete]
  93. // CHECK:STDOUT: %WithImplicitArgs.generic: %WithImplicitArgs.type = struct_value () [concrete]
  94. // CHECK:STDOUT: %T.0a9: %Simple.type.ebf = bind_symbolic_name T, 0 [symbolic]
  95. // CHECK:STDOUT: %pattern_type.eee: type = pattern_type %Simple.type.ebf [concrete]
  96. // CHECK:STDOUT: %Receive.type: type = fn_type @Receive [concrete]
  97. // CHECK:STDOUT: %Receive: %Receive.type = struct_value () [concrete]
  98. // CHECK:STDOUT: %Pass.type: type = fn_type @Pass [concrete]
  99. // CHECK:STDOUT: %Pass: %Pass.type = struct_value () [concrete]
  100. // CHECK:STDOUT: %Receive.specific_fn: <specific function> = specific_function %Receive, @Receive(%T.0a9) [symbolic]
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: file {
  104. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  105. // CHECK:STDOUT: .Simple = %Simple.decl
  106. // CHECK:STDOUT: .X = %X.decl
  107. // CHECK:STDOUT: .WithAssocFn = %WithAssocFn.decl
  108. // CHECK:STDOUT: .C = %C.decl
  109. // CHECK:STDOUT: .WithImplicitArgs = %WithImplicitArgs.decl
  110. // CHECK:STDOUT: .Receive = %Receive.decl
  111. // CHECK:STDOUT: .Pass = %Pass.decl
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %Simple.decl: %Simple.type.3b3 = interface_decl @Simple [concrete = constants.%Simple.generic] {
  114. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  115. // CHECK:STDOUT: } {
  116. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  117. // CHECK:STDOUT: %T.loc4_18.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_18.1 (constants.%T.8b3)]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  120. // CHECK:STDOUT: %WithAssocFn.decl: %WithAssocFn.type.509 = interface_decl @WithAssocFn [concrete = constants.%WithAssocFn.generic] {
  121. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  122. // CHECK:STDOUT: } {
  123. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  124. // CHECK:STDOUT: %T.loc8_23.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc8_23.1 (constants.%T.8b3)]
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  127. // CHECK:STDOUT: %WithImplicitArgs.decl: %WithImplicitArgs.type = interface_decl @WithImplicitArgs [concrete = constants.%WithImplicitArgs.generic] {
  128. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  129. // CHECK:STDOUT: %N.patt: @WithImplicitArgs.%pattern_type (%pattern_type.7dc) = symbolic_binding_pattern N, 1 [concrete]
  130. // CHECK:STDOUT: } {
  131. // CHECK:STDOUT: %.Self.1: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  132. // CHECK:STDOUT: %T.loc22_28.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc22_28.1 (constants.%T.8b3)]
  133. // CHECK:STDOUT: %.loc22: type = splice_block %T.ref [symbolic = %T.loc22_28.1 (constants.%T.8b3)] {
  134. // CHECK:STDOUT: %.Self.2: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  135. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc22_28.2 [symbolic = %T.loc22_28.1 (constants.%T.8b3)]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: %N.loc22_38.2: @WithImplicitArgs.%T.loc22_28.1 (%T.8b3) = bind_symbolic_name N, 1 [symbolic = %N.loc22_38.1 (constants.%N)]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: %Receive.decl: %Receive.type = fn_decl @Receive [concrete = constants.%Receive] {
  140. // CHECK:STDOUT: %T.patt: %pattern_type.eee = symbolic_binding_pattern T, 0 [concrete]
  141. // CHECK:STDOUT: } {
  142. // CHECK:STDOUT: %.loc24: type = splice_block %Simple.type [concrete = constants.%Simple.type.ebf] {
  143. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  144. // CHECK:STDOUT: %Simple.ref: %Simple.type.3b3 = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.generic]
  145. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  146. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple, @Simple(constants.%C)> [concrete = constants.%Simple.type.ebf]
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: %T.loc24_12.2: %Simple.type.ebf = bind_symbolic_name T, 0 [symbolic = %T.loc24_12.1 (constants.%T.0a9)]
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %Pass.decl: %Pass.type = fn_decl @Pass [concrete = constants.%Pass] {
  151. // CHECK:STDOUT: %T.patt: %pattern_type.eee = symbolic_binding_pattern T, 0 [concrete]
  152. // CHECK:STDOUT: } {
  153. // CHECK:STDOUT: %.loc25: type = splice_block %Simple.type [concrete = constants.%Simple.type.ebf] {
  154. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  155. // CHECK:STDOUT: %Simple.ref: %Simple.type.3b3 = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.generic]
  156. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  157. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple, @Simple(constants.%C)> [concrete = constants.%Simple.type.ebf]
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT: %T.loc25_9.2: %Simple.type.ebf = bind_symbolic_name T, 0 [symbolic = %T.loc25_9.1 (constants.%T.0a9)]
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: generic interface @Simple(%T.loc4_18.2: type) {
  164. // CHECK:STDOUT: %T.loc4_18.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_18.1 (constants.%T.8b3)]
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: !definition:
  167. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple, @Simple(%T.loc4_18.1)> [symbolic = %Simple.type (constants.%Simple.type.a1f)]
  168. // CHECK:STDOUT: %Self.2: @Simple.%Simple.type (%Simple.type.a1f) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.4c2)]
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: interface {
  171. // CHECK:STDOUT: %Self.1: @Simple.%Simple.type (%Simple.type.a1f) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.4c2)]
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: !members:
  174. // CHECK:STDOUT: .Self = %Self.1
  175. // CHECK:STDOUT: witness = ()
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: generic interface @WithAssocFn(%T.loc8_23.2: type) {
  180. // CHECK:STDOUT: %T.loc8_23.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc8_23.1 (constants.%T.8b3)]
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: !definition:
  183. // CHECK:STDOUT: %WithAssocFn.type: type = facet_type <@WithAssocFn, @WithAssocFn(%T.loc8_23.1)> [symbolic = %WithAssocFn.type (constants.%WithAssocFn.type.61b)]
  184. // CHECK:STDOUT: %Self.2: @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.61b) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.c02)]
  185. // CHECK:STDOUT: %WithAssocFn.F.type: type = fn_type @WithAssocFn.F, @WithAssocFn(%T.loc8_23.1) [symbolic = %WithAssocFn.F.type (constants.%WithAssocFn.F.type.1af)]
  186. // CHECK:STDOUT: %WithAssocFn.F: @WithAssocFn.%WithAssocFn.F.type (%WithAssocFn.F.type.1af) = struct_value () [symbolic = %WithAssocFn.F (constants.%WithAssocFn.F.b7d)]
  187. // CHECK:STDOUT: %WithAssocFn.assoc_type: type = assoc_entity_type @WithAssocFn, @WithAssocFn(%T.loc8_23.1) [symbolic = %WithAssocFn.assoc_type (constants.%WithAssocFn.assoc_type.b2f)]
  188. // CHECK:STDOUT: %assoc0.loc10_14.2: @WithAssocFn.%WithAssocFn.assoc_type (%WithAssocFn.assoc_type.b2f) = assoc_entity element0, %WithAssocFn.F.decl [symbolic = %assoc0.loc10_14.2 (constants.%assoc0.fc5)]
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: interface {
  191. // CHECK:STDOUT: %Self.1: @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.61b) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.c02)]
  192. // CHECK:STDOUT: %WithAssocFn.F.decl: @WithAssocFn.%WithAssocFn.F.type (%WithAssocFn.F.type.1af) = fn_decl @WithAssocFn.F [symbolic = @WithAssocFn.%WithAssocFn.F (constants.%WithAssocFn.F.b7d)] {
  193. // CHECK:STDOUT: %return.patt: %pattern_type.019 = return_slot_pattern [concrete]
  194. // CHECK:STDOUT: %return.param_patt: %pattern_type.019 = out_param_pattern %return.patt, call_param0 [concrete]
  195. // CHECK:STDOUT: } {
  196. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [concrete = constants.%X]
  197. // CHECK:STDOUT: %return.param: ref %X = out_param call_param0
  198. // CHECK:STDOUT: %return: ref %X = return_slot %return.param
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT: %assoc0.loc10_14.1: @WithAssocFn.%WithAssocFn.assoc_type (%WithAssocFn.assoc_type.b2f) = assoc_entity element0, %WithAssocFn.F.decl [symbolic = %assoc0.loc10_14.2 (constants.%assoc0.fc5)]
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: !members:
  203. // CHECK:STDOUT: .Self = %Self.1
  204. // CHECK:STDOUT: .X = <poisoned>
  205. // CHECK:STDOUT: .F = %assoc0.loc10_14.1
  206. // CHECK:STDOUT: witness = (%WithAssocFn.F.decl)
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: generic interface @WithImplicitArgs(%T.loc22_28.2: type, %N.loc22_38.2: @WithImplicitArgs.%T.loc22_28.1 (%T.8b3)) {
  211. // CHECK:STDOUT: %T.loc22_28.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc22_28.1 (constants.%T.8b3)]
  212. // CHECK:STDOUT: %N.loc22_38.1: @WithImplicitArgs.%T.loc22_28.1 (%T.8b3) = bind_symbolic_name N, 1 [symbolic = %N.loc22_38.1 (constants.%N)]
  213. // CHECK:STDOUT: %pattern_type: type = pattern_type %T.loc22_28.1 [symbolic = %pattern_type (constants.%pattern_type.7dc)]
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: interface;
  216. // CHECK:STDOUT: }
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: impl @C.as.Simple.impl: %Self.ref as %Simple.type {
  219. // CHECK:STDOUT: !members:
  220. // CHECK:STDOUT: witness = @C.%Simple.impl_witness
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: impl @C.as.WithAssocFn.impl: %Self.ref as %WithAssocFn.type {
  224. // CHECK:STDOUT: %C.as.WithAssocFn.impl.F.decl: %C.as.WithAssocFn.impl.F.type = fn_decl @C.as.WithAssocFn.impl.F [concrete = constants.%C.as.WithAssocFn.impl.F] {
  225. // CHECK:STDOUT: %return.patt: %pattern_type.019 = return_slot_pattern [concrete]
  226. // CHECK:STDOUT: %return.param_patt: %pattern_type.019 = out_param_pattern %return.patt, call_param0 [concrete]
  227. // CHECK:STDOUT: } {
  228. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [concrete = constants.%X]
  229. // CHECK:STDOUT: %return.param: ref %X = out_param call_param0
  230. // CHECK:STDOUT: %return: ref %X = return_slot %return.param
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: !members:
  234. // CHECK:STDOUT: .X = <poisoned>
  235. // CHECK:STDOUT: .F = %C.as.WithAssocFn.impl.F.decl
  236. // CHECK:STDOUT: witness = @C.%WithAssocFn.impl_witness
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: class @X {
  240. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  241. // CHECK:STDOUT: complete_type_witness = %complete_type
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: !members:
  244. // CHECK:STDOUT: .Self = constants.%X
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: class @C {
  248. // CHECK:STDOUT: impl_decl @C.as.Simple.impl [concrete] {} {
  249. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  250. // CHECK:STDOUT: %Simple.ref: %Simple.type.3b3 = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.generic]
  251. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  252. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple, @Simple(constants.%C)> [concrete = constants.%Simple.type.ebf]
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT: %Simple.impl_witness_table = impl_witness_table (), @C.as.Simple.impl [concrete]
  255. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness %Simple.impl_witness_table [concrete = constants.%Simple.impl_witness]
  256. // CHECK:STDOUT: impl_decl @C.as.WithAssocFn.impl [concrete] {} {
  257. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  258. // CHECK:STDOUT: %WithAssocFn.ref: %WithAssocFn.type.509 = name_ref WithAssocFn, file.%WithAssocFn.decl [concrete = constants.%WithAssocFn.generic]
  259. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  260. // CHECK:STDOUT: %WithAssocFn.type: type = facet_type <@WithAssocFn, @WithAssocFn(constants.%C)> [concrete = constants.%WithAssocFn.type.fc9]
  261. // CHECK:STDOUT: }
  262. // CHECK:STDOUT: %WithAssocFn.impl_witness_table = impl_witness_table (@C.as.WithAssocFn.impl.%C.as.WithAssocFn.impl.F.decl), @C.as.WithAssocFn.impl [concrete]
  263. // CHECK:STDOUT: %WithAssocFn.impl_witness: <witness> = impl_witness %WithAssocFn.impl_witness_table [concrete = constants.%WithAssocFn.impl_witness]
  264. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  265. // CHECK:STDOUT: complete_type_witness = %complete_type
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: !members:
  268. // CHECK:STDOUT: .Self = constants.%C
  269. // CHECK:STDOUT: .Simple = <poisoned>
  270. // CHECK:STDOUT: .C = <poisoned>
  271. // CHECK:STDOUT: .WithAssocFn = <poisoned>
  272. // CHECK:STDOUT: .X = <poisoned>
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT:
  275. // CHECK:STDOUT: generic fn @WithAssocFn.F(@WithAssocFn.%T.loc8_23.2: type, @WithAssocFn.%Self.1: @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.61b)) {
  276. // CHECK:STDOUT: fn() -> %return.param: %X;
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: fn @C.as.WithAssocFn.impl.F() -> %return.param: %X {
  280. // CHECK:STDOUT: !entry:
  281. // CHECK:STDOUT: %.loc17_15.1: %empty_struct_type = struct_literal ()
  282. // CHECK:STDOUT: %.loc17_15.2: init %X = class_init (), %return [concrete = constants.%X.val]
  283. // CHECK:STDOUT: %.loc17_16: init %X = converted %.loc17_15.1, %.loc17_15.2 [concrete = constants.%X.val]
  284. // CHECK:STDOUT: return %.loc17_16 to %return
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: generic fn @Receive(%T.loc24_12.2: %Simple.type.ebf) {
  288. // CHECK:STDOUT: %T.loc24_12.1: %Simple.type.ebf = bind_symbolic_name T, 0 [symbolic = %T.loc24_12.1 (constants.%T.0a9)]
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: !definition:
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: fn() {
  293. // CHECK:STDOUT: !entry:
  294. // CHECK:STDOUT: return
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT: }
  297. // CHECK:STDOUT:
  298. // CHECK:STDOUT: generic fn @Pass(%T.loc25_9.2: %Simple.type.ebf) {
  299. // CHECK:STDOUT: %T.loc25_9.1: %Simple.type.ebf = bind_symbolic_name T, 0 [symbolic = %T.loc25_9.1 (constants.%T.0a9)]
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: !definition:
  302. // CHECK:STDOUT: %Receive.specific_fn.loc26_3.2: <specific function> = specific_function constants.%Receive, @Receive(%T.loc25_9.1) [symbolic = %Receive.specific_fn.loc26_3.2 (constants.%Receive.specific_fn)]
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: fn() {
  305. // CHECK:STDOUT: !entry:
  306. // CHECK:STDOUT: %Receive.ref: %Receive.type = name_ref Receive, file.%Receive.decl [concrete = constants.%Receive]
  307. // CHECK:STDOUT: %T.ref: %Simple.type.ebf = name_ref T, %T.loc25_9.2 [symbolic = %T.loc25_9.1 (constants.%T.0a9)]
  308. // CHECK:STDOUT: %Receive.specific_fn.loc26_3.1: <specific function> = specific_function %Receive.ref, @Receive(constants.%T.0a9) [symbolic = %Receive.specific_fn.loc26_3.2 (constants.%Receive.specific_fn)]
  309. // CHECK:STDOUT: %Receive.call: init %empty_tuple.type = call %Receive.specific_fn.loc26_3.1()
  310. // CHECK:STDOUT: return
  311. // CHECK:STDOUT: }
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: specific @Simple(constants.%T.8b3) {
  315. // CHECK:STDOUT: %T.loc4_18.1 => constants.%T.8b3
  316. // CHECK:STDOUT: }
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: specific @WithAssocFn(constants.%T.8b3) {
  319. // CHECK:STDOUT: %T.loc8_23.1 => constants.%T.8b3
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: specific @WithAssocFn.F(constants.%T.8b3, constants.%Self.c02) {}
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: specific @Simple(constants.%C) {
  325. // CHECK:STDOUT: %T.loc4_18.1 => constants.%C
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: !definition:
  328. // CHECK:STDOUT: %Simple.type => constants.%Simple.type.ebf
  329. // CHECK:STDOUT: %Self.2 => constants.%Self.ae2
  330. // CHECK:STDOUT: }
  331. // CHECK:STDOUT:
  332. // CHECK:STDOUT: specific @WithAssocFn(constants.%C) {
  333. // CHECK:STDOUT: %T.loc8_23.1 => constants.%C
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: !definition:
  336. // CHECK:STDOUT: %WithAssocFn.type => constants.%WithAssocFn.type.fc9
  337. // CHECK:STDOUT: %Self.2 => constants.%Self.8cc
  338. // CHECK:STDOUT: %WithAssocFn.F.type => constants.%WithAssocFn.F.type.18c
  339. // CHECK:STDOUT: %WithAssocFn.F => constants.%WithAssocFn.F.e46
  340. // CHECK:STDOUT: %WithAssocFn.assoc_type => constants.%WithAssocFn.assoc_type.9ea
  341. // CHECK:STDOUT: %assoc0.loc10_14.2 => constants.%assoc0.cad
  342. // CHECK:STDOUT: }
  343. // CHECK:STDOUT:
  344. // CHECK:STDOUT: specific @WithAssocFn.F(constants.%C, constants.%WithAssocFn.facet) {}
  345. // CHECK:STDOUT:
  346. // CHECK:STDOUT: specific @WithImplicitArgs(constants.%T.8b3, constants.%N) {
  347. // CHECK:STDOUT: %T.loc22_28.1 => constants.%T.8b3
  348. // CHECK:STDOUT: %N.loc22_38.1 => constants.%N
  349. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dc
  350. // CHECK:STDOUT: }
  351. // CHECK:STDOUT:
  352. // CHECK:STDOUT: specific @Receive(constants.%T.0a9) {
  353. // CHECK:STDOUT: %T.loc24_12.1 => constants.%T.0a9
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: !definition:
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: specific @Pass(constants.%T.0a9) {
  359. // CHECK:STDOUT: %T.loc25_9.1 => constants.%T.0a9
  360. // CHECK:STDOUT: }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: --- fail_mismatched_args.carbon
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: constants {
  365. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  366. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self]
  367. // CHECK:STDOUT: %T.8b3: type = bind_symbolic_name T, 0 [symbolic]
  368. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  369. // CHECK:STDOUT: %Generic.type.c21: type = generic_interface_type @Generic [concrete]
  370. // CHECK:STDOUT: %Generic.generic: %Generic.type.c21 = struct_value () [concrete]
  371. // CHECK:STDOUT: %Generic.type.2db: type = facet_type <@Generic, @Generic(%T.8b3)> [symbolic]
  372. // CHECK:STDOUT: %Self.899: %Generic.type.2db = bind_symbolic_name Self, 1 [symbolic]
  373. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  374. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  375. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  376. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  377. // CHECK:STDOUT: %Generic.type.185: type = facet_type <@Generic, @Generic(%A)> [concrete]
  378. // CHECK:STDOUT: %T.000: %Generic.type.185 = bind_symbolic_name T, 0 [symbolic]
  379. // CHECK:STDOUT: %pattern_type.99a: type = pattern_type %Generic.type.185 [concrete]
  380. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  381. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  382. // CHECK:STDOUT: %Generic.type.227: type = facet_type <@Generic, @Generic(%B)> [concrete]
  383. // CHECK:STDOUT: %T.03b: %Generic.type.227 = bind_symbolic_name T, 0 [symbolic]
  384. // CHECK:STDOUT: %pattern_type.b43: type = pattern_type %Generic.type.227 [concrete]
  385. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  386. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  387. // CHECK:STDOUT: %Self.a3e: %Generic.type.227 = bind_symbolic_name Self, 1 [symbolic]
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: file {
  391. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  392. // CHECK:STDOUT: .Generic = %Generic.decl
  393. // CHECK:STDOUT: .A = %A.decl
  394. // CHECK:STDOUT: .B = %B.decl
  395. // CHECK:STDOUT: .F = %F.decl
  396. // CHECK:STDOUT: .G = %G.decl
  397. // CHECK:STDOUT: }
  398. // CHECK:STDOUT: %Generic.decl: %Generic.type.c21 = interface_decl @Generic [concrete = constants.%Generic.generic] {
  399. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  400. // CHECK:STDOUT: } {
  401. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  402. // CHECK:STDOUT: %T.loc4_19.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_19.1 (constants.%T.8b3)]
  403. // CHECK:STDOUT: }
  404. // CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
  405. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  406. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  407. // CHECK:STDOUT: %T.patt: %pattern_type.99a = symbolic_binding_pattern T, 0 [concrete]
  408. // CHECK:STDOUT: } {
  409. // CHECK:STDOUT: %.loc9: type = splice_block %Generic.type [concrete = constants.%Generic.type.185] {
  410. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  411. // CHECK:STDOUT: %Generic.ref: %Generic.type.c21 = name_ref Generic, file.%Generic.decl [concrete = constants.%Generic.generic]
  412. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  413. // CHECK:STDOUT: %Generic.type: type = facet_type <@Generic, @Generic(constants.%A)> [concrete = constants.%Generic.type.185]
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT: %T.loc9_6.2: %Generic.type.185 = bind_symbolic_name T, 0 [symbolic = %T.loc9_6.1 (constants.%T.000)]
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  418. // CHECK:STDOUT: %T.patt: %pattern_type.b43 = symbolic_binding_pattern T, 0 [concrete]
  419. // CHECK:STDOUT: } {
  420. // CHECK:STDOUT: %.loc10: type = splice_block %Generic.type [concrete = constants.%Generic.type.227] {
  421. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  422. // CHECK:STDOUT: %Generic.ref: %Generic.type.c21 = name_ref Generic, file.%Generic.decl [concrete = constants.%Generic.generic]
  423. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  424. // CHECK:STDOUT: %Generic.type: type = facet_type <@Generic, @Generic(constants.%B)> [concrete = constants.%Generic.type.227]
  425. // CHECK:STDOUT: }
  426. // CHECK:STDOUT: %T.loc10_6.2: %Generic.type.227 = bind_symbolic_name T, 0 [symbolic = %T.loc10_6.1 (constants.%T.03b)]
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: generic interface @Generic(%T.loc4_19.2: type) {
  431. // CHECK:STDOUT: %T.loc4_19.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_19.1 (constants.%T.8b3)]
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: !definition:
  434. // CHECK:STDOUT: %Generic.type: type = facet_type <@Generic, @Generic(%T.loc4_19.1)> [symbolic = %Generic.type (constants.%Generic.type.2db)]
  435. // CHECK:STDOUT: %Self.2: @Generic.%Generic.type (%Generic.type.2db) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.899)]
  436. // CHECK:STDOUT:
  437. // CHECK:STDOUT: interface {
  438. // CHECK:STDOUT: %Self.1: @Generic.%Generic.type (%Generic.type.2db) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.899)]
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: !members:
  441. // CHECK:STDOUT: .Self = %Self.1
  442. // CHECK:STDOUT: witness = ()
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: class @A {
  447. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  448. // CHECK:STDOUT: complete_type_witness = %complete_type
  449. // CHECK:STDOUT:
  450. // CHECK:STDOUT: !members:
  451. // CHECK:STDOUT: .Self = constants.%A
  452. // CHECK:STDOUT: }
  453. // CHECK:STDOUT:
  454. // CHECK:STDOUT: class @B {
  455. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  456. // CHECK:STDOUT: complete_type_witness = %complete_type
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: !members:
  459. // CHECK:STDOUT: .Self = constants.%B
  460. // CHECK:STDOUT: }
  461. // CHECK:STDOUT:
  462. // CHECK:STDOUT: generic fn @F(%T.loc9_6.2: %Generic.type.185) {
  463. // CHECK:STDOUT: %T.loc9_6.1: %Generic.type.185 = bind_symbolic_name T, 0 [symbolic = %T.loc9_6.1 (constants.%T.000)]
  464. // CHECK:STDOUT:
  465. // CHECK:STDOUT: fn();
  466. // CHECK:STDOUT: }
  467. // CHECK:STDOUT:
  468. // CHECK:STDOUT: generic fn @G(%T.loc10_6.2: %Generic.type.227) {
  469. // CHECK:STDOUT: %T.loc10_6.1: %Generic.type.227 = bind_symbolic_name T, 0 [symbolic = %T.loc10_6.1 (constants.%T.03b)]
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: !definition:
  472. // CHECK:STDOUT:
  473. // CHECK:STDOUT: fn() {
  474. // CHECK:STDOUT: !entry:
  475. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  476. // CHECK:STDOUT: %T.ref: %Generic.type.227 = name_ref T, %T.loc10_6.2 [symbolic = %T.loc10_6.1 (constants.%T.03b)]
  477. // CHECK:STDOUT: return
  478. // CHECK:STDOUT: }
  479. // CHECK:STDOUT: }
  480. // CHECK:STDOUT:
  481. // CHECK:STDOUT: specific @Generic(constants.%T.8b3) {
  482. // CHECK:STDOUT: %T.loc4_19.1 => constants.%T.8b3
  483. // CHECK:STDOUT: }
  484. // CHECK:STDOUT:
  485. // CHECK:STDOUT: specific @Generic(constants.%A) {
  486. // CHECK:STDOUT: %T.loc4_19.1 => constants.%A
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: specific @F(constants.%T.000) {
  490. // CHECK:STDOUT: %T.loc9_6.1 => constants.%T.000
  491. // CHECK:STDOUT: }
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: specific @Generic(constants.%B) {
  494. // CHECK:STDOUT: %T.loc4_19.1 => constants.%B
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: !definition:
  497. // CHECK:STDOUT: %Generic.type => constants.%Generic.type.227
  498. // CHECK:STDOUT: %Self.2 => constants.%Self.a3e
  499. // CHECK:STDOUT: }
  500. // CHECK:STDOUT:
  501. // CHECK:STDOUT: specific @G(constants.%T.03b) {
  502. // CHECK:STDOUT: %T.loc10_6.1 => constants.%T.03b
  503. // CHECK:STDOUT: }
  504. // CHECK:STDOUT: