generic.carbon 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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/interface/no_prelude/generic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/no_prelude/generic.carbon
  10. // --- generic.carbon
  11. library "[[@TEST_NAME]]";
  12. interface Simple(T:! type) {}
  13. class X {}
  14. interface WithAssocFn(T:! type) {
  15. // TODO: Take `Self`, return `T`, once that works.
  16. fn F() -> X;
  17. }
  18. class C {
  19. impl as Simple(C) {}
  20. impl as WithAssocFn(C) {
  21. fn F() -> X {
  22. return {};
  23. }
  24. }
  25. }
  26. interface WithImplicitArgs[T:! type](N:! T);
  27. fn Receive(T:! Simple(C)) {}
  28. fn Pass(T:! Simple(C)) {
  29. Receive(T);
  30. }
  31. // --- fail_mismatched_args.carbon
  32. library "[[@TEST_NAME]]";
  33. interface Generic(T:! type) {}
  34. class A {}
  35. class B {}
  36. fn F(T:! Generic(A));
  37. fn G(T:! Generic(B)) {
  38. // TODO: Include generic arguments in the type name.
  39. // CHECK:STDERR: fail_mismatched_args.carbon:[[@LINE+3]]:3: error: package `Core` implicitly referenced here, but not found
  40. // CHECK:STDERR: F(T);
  41. // CHECK:STDERR: ^~
  42. F(T);
  43. }
  44. // CHECK:STDOUT: --- generic.carbon
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: constants {
  47. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T, 0 [symbolic]
  48. // CHECK:STDOUT: %T.patt.1: type = symbolic_binding_pattern T, 0 [symbolic]
  49. // CHECK:STDOUT: %Simple.type.1: type = generic_interface_type @Simple [template]
  50. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  51. // CHECK:STDOUT: %Simple: %Simple.type.1 = struct_value () [template]
  52. // CHECK:STDOUT: %Simple.type.2: type = interface_type @Simple, @Simple(%T.1) [symbolic]
  53. // CHECK:STDOUT: %Self.1: %Simple.type.2 = bind_symbolic_name Self, 1 [symbolic]
  54. // CHECK:STDOUT: %X: type = class_type @X [template]
  55. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  56. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  57. // CHECK:STDOUT: %T.patt.2: type = symbolic_binding_pattern T, 0 [symbolic]
  58. // CHECK:STDOUT: %WithAssocFn.type.1: type = generic_interface_type @WithAssocFn [template]
  59. // CHECK:STDOUT: %WithAssocFn: %WithAssocFn.type.1 = struct_value () [template]
  60. // CHECK:STDOUT: %WithAssocFn.type.2: type = interface_type @WithAssocFn, @WithAssocFn(%T.1) [symbolic]
  61. // CHECK:STDOUT: %Self.2: %WithAssocFn.type.2 = bind_symbolic_name Self, 1 [symbolic]
  62. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @WithAssocFn(%T.1) [symbolic]
  63. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  64. // CHECK:STDOUT: %.4: type = assoc_entity_type %WithAssocFn.type.2, %F.type.1 [symbolic]
  65. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, @WithAssocFn.%F.decl [symbolic]
  66. // CHECK:STDOUT: %C: type = class_type @C [template]
  67. // CHECK:STDOUT: %Simple.type.3: type = interface_type @Simple, @Simple(%C) [template]
  68. // CHECK:STDOUT: %.6: <witness> = interface_witness () [template]
  69. // CHECK:STDOUT: %WithAssocFn.type.3: type = interface_type @WithAssocFn, @WithAssocFn(%C) [template]
  70. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  71. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  72. // CHECK:STDOUT: %F.type.3: type = fn_type @F.1, @WithAssocFn(%C) [template]
  73. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  74. // CHECK:STDOUT: %.7: type = assoc_entity_type %WithAssocFn.type.3, %F.type.3 [template]
  75. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, @WithAssocFn.%F.decl [template]
  76. // CHECK:STDOUT: %.9: <witness> = interface_witness (%F.2) [template]
  77. // CHECK:STDOUT: %.10: type = ptr_type %.2 [template]
  78. // CHECK:STDOUT: %struct: %X = struct_value () [template]
  79. // CHECK:STDOUT: %T.patt.3: type = symbolic_binding_pattern T, 0 [symbolic]
  80. // CHECK:STDOUT: %N: %T.1 = bind_symbolic_name N, 1 [symbolic]
  81. // CHECK:STDOUT: %N.patt: %T.1 = symbolic_binding_pattern N, 1 [symbolic]
  82. // CHECK:STDOUT: %WithImplicitArgs.type: type = generic_interface_type @WithImplicitArgs [template]
  83. // CHECK:STDOUT: %WithImplicitArgs: %WithImplicitArgs.type = struct_value () [template]
  84. // CHECK:STDOUT: %T.2: %Simple.type.3 = bind_symbolic_name T, 0 [symbolic]
  85. // CHECK:STDOUT: %T.patt.4: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic]
  86. // CHECK:STDOUT: %Receive.type: type = fn_type @Receive [template]
  87. // CHECK:STDOUT: %Receive: %Receive.type = struct_value () [template]
  88. // CHECK:STDOUT: %T.patt.5: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic]
  89. // CHECK:STDOUT: %Pass.type: type = fn_type @Pass [template]
  90. // CHECK:STDOUT: %Pass: %Pass.type = struct_value () [template]
  91. // CHECK:STDOUT: %.11: <specific function> = specific_function %Receive, @Receive(%T.2) [symbolic]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: file {
  95. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  96. // CHECK:STDOUT: .Simple = %Simple.decl
  97. // CHECK:STDOUT: .X = %X.decl
  98. // CHECK:STDOUT: .WithAssocFn = %WithAssocFn.decl
  99. // CHECK:STDOUT: .C = %C.decl
  100. // CHECK:STDOUT: .WithImplicitArgs = %WithImplicitArgs.decl
  101. // CHECK:STDOUT: .Receive = %Receive.decl
  102. // CHECK:STDOUT: .Pass = %Pass.decl
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %Simple.decl: %Simple.type.1 = interface_decl @Simple [template = constants.%Simple] {
  105. // CHECK:STDOUT: %T.patt.loc4_18.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_18.2 (constants.%T.patt.1)]
  106. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc4_18.1, runtime_param<invalid> [symbolic = %T.patt.loc4_18.2 (constants.%T.patt.1)]
  107. // CHECK:STDOUT: } {
  108. // CHECK:STDOUT: %param: type = param runtime_param<invalid>
  109. // CHECK:STDOUT: %T.loc4_18.1: type = bind_symbolic_name T, 0, %param [symbolic = %T.loc4_18.2 (constants.%T.1)]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {} {}
  112. // CHECK:STDOUT: %WithAssocFn.decl: %WithAssocFn.type.1 = interface_decl @WithAssocFn [template = constants.%WithAssocFn] {
  113. // CHECK:STDOUT: %T.patt.loc8_23.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_23.2 (constants.%T.patt.2)]
  114. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc8_23.1, runtime_param<invalid> [symbolic = %T.patt.loc8_23.2 (constants.%T.patt.2)]
  115. // CHECK:STDOUT: } {
  116. // CHECK:STDOUT: %param: type = param runtime_param<invalid>
  117. // CHECK:STDOUT: %T.loc8_23.1: type = bind_symbolic_name T, 0, %param [symbolic = %T.loc8_23.2 (constants.%T.1)]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  120. // CHECK:STDOUT: %WithImplicitArgs.decl: %WithImplicitArgs.type = interface_decl @WithImplicitArgs [template = constants.%WithImplicitArgs] {
  121. // CHECK:STDOUT: %T.patt.loc22_28.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc22_28.2 (constants.%T.patt.3)]
  122. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc22_28.1, runtime_param<invalid> [symbolic = %T.patt.loc22_28.2 (constants.%T.patt.3)]
  123. // CHECK:STDOUT: %N.patt.loc22_38.1: @WithImplicitArgs.%T.loc22_28.2 (%T.1) = symbolic_binding_pattern N, 1 [symbolic = %N.patt.loc22_38.2 (constants.%N.patt)]
  124. // CHECK:STDOUT: %N.param_patt: @WithImplicitArgs.%T.loc22_28.2 (%T.1) = param_pattern %N.patt.loc22_38.1, runtime_param<invalid> [symbolic = %N.patt.loc22_38.2 (constants.%N.patt)]
  125. // CHECK:STDOUT: } {
  126. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc22_28.1 [symbolic = %T.loc22_28.2 (constants.%T.1)]
  127. // CHECK:STDOUT: %param.loc22_28: type = param runtime_param<invalid>
  128. // CHECK:STDOUT: %T.loc22_28.1: type = bind_symbolic_name T, 0, %param.loc22_28 [symbolic = %T.loc22_28.2 (constants.%T.1)]
  129. // CHECK:STDOUT: %param.loc22_38: @WithImplicitArgs.%T.loc22_28.2 (%T.1) = param runtime_param<invalid>
  130. // CHECK:STDOUT: %N.loc22_38.1: @WithImplicitArgs.%T.loc22_28.2 (%T.1) = bind_symbolic_name N, 1, %param.loc22_38 [symbolic = %N.loc22_38.2 (constants.%N)]
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: %Receive.decl: %Receive.type = fn_decl @Receive [template = constants.%Receive] {
  133. // CHECK:STDOUT: %T.patt.loc24_12.1: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc24_12.2 (constants.%T.patt.4)]
  134. // CHECK:STDOUT: %T.param_patt: %Simple.type.3 = param_pattern %T.patt.loc24_12.1, runtime_param<invalid> [symbolic = %T.patt.loc24_12.2 (constants.%T.patt.4)]
  135. // CHECK:STDOUT: } {
  136. // CHECK:STDOUT: %Simple.ref: %Simple.type.1 = name_ref Simple, file.%Simple.decl [template = constants.%Simple]
  137. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  138. // CHECK:STDOUT: %Simple.type: type = interface_type @Simple, @Simple(constants.%C) [template = constants.%Simple.type.3]
  139. // CHECK:STDOUT: %param: %Simple.type.3 = param runtime_param<invalid>
  140. // CHECK:STDOUT: %T.loc24_12.1: %Simple.type.3 = bind_symbolic_name T, 0, %param [symbolic = %T.loc24_12.2 (constants.%T.2)]
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %Pass.decl: %Pass.type = fn_decl @Pass [template = constants.%Pass] {
  143. // CHECK:STDOUT: %T.patt.loc25_9.1: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc25_9.2 (constants.%T.patt.5)]
  144. // CHECK:STDOUT: %T.param_patt: %Simple.type.3 = param_pattern %T.patt.loc25_9.1, runtime_param<invalid> [symbolic = %T.patt.loc25_9.2 (constants.%T.patt.5)]
  145. // CHECK:STDOUT: } {
  146. // CHECK:STDOUT: %Simple.ref: %Simple.type.1 = name_ref Simple, file.%Simple.decl [template = constants.%Simple]
  147. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  148. // CHECK:STDOUT: %Simple.type: type = interface_type @Simple, @Simple(constants.%C) [template = constants.%Simple.type.3]
  149. // CHECK:STDOUT: %param: %Simple.type.3 = param runtime_param<invalid>
  150. // CHECK:STDOUT: %T.loc25_9.1: %Simple.type.3 = bind_symbolic_name T, 0, %param [symbolic = %T.loc25_9.2 (constants.%T.2)]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: generic interface @Simple(%T.loc4_18.1: type) {
  155. // CHECK:STDOUT: %T.loc4_18.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_18.2 (constants.%T.1)]
  156. // CHECK:STDOUT: %T.patt.loc4_18.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_18.2 (constants.%T.patt.1)]
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !definition:
  159. // CHECK:STDOUT: %Simple.type: type = interface_type @Simple, @Simple(%T.loc4_18.2) [symbolic = %Simple.type (constants.%Simple.type.2)]
  160. // CHECK:STDOUT: %Self.2: %Simple.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.1)]
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: interface {
  163. // CHECK:STDOUT: %Self.1: @Simple.%Simple.type (%Simple.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.1)]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .Self = %Self.1
  167. // CHECK:STDOUT: witness = ()
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: generic interface @WithAssocFn(%T.loc8_23.1: type) {
  172. // CHECK:STDOUT: %T.loc8_23.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc8_23.2 (constants.%T.1)]
  173. // CHECK:STDOUT: %T.patt.loc8_23.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_23.2 (constants.%T.patt.2)]
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: !definition:
  176. // CHECK:STDOUT: %WithAssocFn.type: type = interface_type @WithAssocFn, @WithAssocFn(%T.loc8_23.2) [symbolic = %WithAssocFn.type (constants.%WithAssocFn.type.2)]
  177. // CHECK:STDOUT: %Self.2: %WithAssocFn.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.2)]
  178. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @WithAssocFn(%T.loc8_23.2) [symbolic = %F.type (constants.%F.type.1)]
  179. // CHECK:STDOUT: %F: @WithAssocFn.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  180. // CHECK:STDOUT: %.loc10_14.2: type = assoc_entity_type @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.2), @WithAssocFn.%F.type (%F.type.1) [symbolic = %.loc10_14.2 (constants.%.4)]
  181. // CHECK:STDOUT: %.loc10_14.3: @WithAssocFn.%.loc10_14.2 (%.4) = assoc_entity element0, %F.decl [symbolic = %.loc10_14.3 (constants.%.5)]
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: interface {
  184. // CHECK:STDOUT: %Self.1: @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.2)]
  185. // CHECK:STDOUT: %F.decl: @WithAssocFn.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = @WithAssocFn.%F (constants.%F.1)] {} {
  186. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  187. // CHECK:STDOUT: %return: ref %X = var <return slot>
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %.loc10_14.1: @WithAssocFn.%.loc10_14.2 (%.4) = assoc_entity element0, %F.decl [symbolic = %.loc10_14.3 (constants.%.5)]
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: !members:
  192. // CHECK:STDOUT: .Self = %Self.1
  193. // CHECK:STDOUT: .F = %.loc10_14.1
  194. // CHECK:STDOUT: witness = (%F.decl)
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: generic interface @WithImplicitArgs(%T.loc22_28.1: type, %N.loc22_38.1: @WithImplicitArgs.%T.loc22_28.2 (%T.1)) {
  199. // CHECK:STDOUT: %T.loc22_28.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc22_28.2 (constants.%T.1)]
  200. // CHECK:STDOUT: %T.patt.loc22_28.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc22_28.2 (constants.%T.patt.3)]
  201. // CHECK:STDOUT: %N.loc22_38.2: %T.1 = bind_symbolic_name N, 1 [symbolic = %N.loc22_38.2 (constants.%N)]
  202. // CHECK:STDOUT: %N.patt.loc22_38.2: %T.1 = symbolic_binding_pattern N, 1 [symbolic = %N.patt.loc22_38.2 (constants.%N.patt)]
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: interface;
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: impl @impl.1: %Self.ref as %Simple.type {
  208. // CHECK:STDOUT: %.loc14: <witness> = interface_witness () [template = constants.%.6]
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: !members:
  211. // CHECK:STDOUT: witness = %.loc14
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: impl @impl.2: %Self.ref as %WithAssocFn.type {
  215. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {
  216. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  217. // CHECK:STDOUT: %return: ref %X = var <return slot>
  218. // CHECK:STDOUT: }
  219. // CHECK:STDOUT: %.loc15: <witness> = interface_witness (%F.decl) [template = constants.%.9]
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: !members:
  222. // CHECK:STDOUT: .F = %F.decl
  223. // CHECK:STDOUT: witness = %.loc15
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: class @X {
  227. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: !members:
  230. // CHECK:STDOUT: .Self = constants.%X
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: class @C {
  234. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  235. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  236. // CHECK:STDOUT: %Simple.ref: %Simple.type.1 = name_ref Simple, file.%Simple.decl [template = constants.%Simple]
  237. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  238. // CHECK:STDOUT: %Simple.type: type = interface_type @Simple, @Simple(constants.%C) [template = constants.%Simple.type.3]
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT: impl_decl @impl.2 [template] {} {
  241. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  242. // CHECK:STDOUT: %WithAssocFn.ref: %WithAssocFn.type.1 = name_ref WithAssocFn, file.%WithAssocFn.decl [template = constants.%WithAssocFn]
  243. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  244. // CHECK:STDOUT: %WithAssocFn.type: type = interface_type @WithAssocFn, @WithAssocFn(constants.%C) [template = constants.%WithAssocFn.type.3]
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT: %.loc20: <witness> = complete_type_witness %.2 [template = constants.%.3]
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: !members:
  249. // CHECK:STDOUT: .Self = constants.%C
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: generic fn @F.1(@WithAssocFn.%T.loc8_23.1: type, @WithAssocFn.%Self.1: @WithAssocFn.%WithAssocFn.type (%WithAssocFn.type.2)) {
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: fn() -> %X;
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT:
  257. // CHECK:STDOUT: fn @F.2() -> %return: %X {
  258. // CHECK:STDOUT: !entry:
  259. // CHECK:STDOUT: %.loc17_15.1: %.2 = struct_literal ()
  260. // CHECK:STDOUT: %.loc17_15.2: init %X = class_init (), %return [template = constants.%struct]
  261. // CHECK:STDOUT: %.loc17_16: init %X = converted %.loc17_15.1, %.loc17_15.2 [template = constants.%struct]
  262. // CHECK:STDOUT: return %.loc17_16 to %return
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: generic fn @Receive(%T.loc24_12.1: %Simple.type.3) {
  266. // CHECK:STDOUT: %T.loc24_12.2: %Simple.type.3 = bind_symbolic_name T, 0 [symbolic = %T.loc24_12.2 (constants.%T.2)]
  267. // CHECK:STDOUT: %T.patt.loc24_12.2: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc24_12.2 (constants.%T.patt.4)]
  268. // CHECK:STDOUT:
  269. // CHECK:STDOUT: !definition:
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: fn(%T.param_patt: %Simple.type.3) {
  272. // CHECK:STDOUT: !entry:
  273. // CHECK:STDOUT: return
  274. // CHECK:STDOUT: }
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: generic fn @Pass(%T.loc25_9.1: %Simple.type.3) {
  278. // CHECK:STDOUT: %T.loc25_9.2: %Simple.type.3 = bind_symbolic_name T, 0 [symbolic = %T.loc25_9.2 (constants.%T.2)]
  279. // CHECK:STDOUT: %T.patt.loc25_9.2: %Simple.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc25_9.2 (constants.%T.patt.5)]
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: !definition:
  282. // CHECK:STDOUT: %.loc26_3.2: <specific function> = specific_function constants.%Receive, @Receive(%T.loc25_9.2) [symbolic = %.loc26_3.2 (constants.%.11)]
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: fn(%T.param_patt: %Simple.type.3) {
  285. // CHECK:STDOUT: !entry:
  286. // CHECK:STDOUT: %Receive.ref: %Receive.type = name_ref Receive, file.%Receive.decl [template = constants.%Receive]
  287. // CHECK:STDOUT: %T.ref: %Simple.type.3 = name_ref T, %T.loc25_9.1 [symbolic = %T.loc25_9.2 (constants.%T.2)]
  288. // CHECK:STDOUT: %.loc26_3.1: <specific function> = specific_function %Receive.ref, @Receive(constants.%T.2) [symbolic = %.loc26_3.2 (constants.%.11)]
  289. // CHECK:STDOUT: %Receive.call: init %.1 = call %.loc26_3.1()
  290. // CHECK:STDOUT: return
  291. // CHECK:STDOUT: }
  292. // CHECK:STDOUT: }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: specific @Simple(constants.%T.1) {
  295. // CHECK:STDOUT: %T.loc4_18.2 => constants.%T.1
  296. // CHECK:STDOUT: %T.patt.loc4_18.2 => constants.%T.1
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: specific @Simple(@Simple.%T.loc4_18.2) {
  300. // CHECK:STDOUT: %T.loc4_18.2 => constants.%T.1
  301. // CHECK:STDOUT: %T.patt.loc4_18.2 => constants.%T.1
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: specific @WithAssocFn(constants.%T.1) {
  305. // CHECK:STDOUT: %T.loc8_23.2 => constants.%T.1
  306. // CHECK:STDOUT: %T.patt.loc8_23.2 => constants.%T.1
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: specific @F.1(constants.%T.1, constants.%Self.2) {}
  310. // CHECK:STDOUT:
  311. // CHECK:STDOUT: specific @WithAssocFn(@WithAssocFn.%T.loc8_23.2) {
  312. // CHECK:STDOUT: %T.loc8_23.2 => constants.%T.1
  313. // CHECK:STDOUT: %T.patt.loc8_23.2 => constants.%T.1
  314. // CHECK:STDOUT: }
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: specific @Simple(constants.%C) {
  317. // CHECK:STDOUT: %T.loc4_18.2 => constants.%C
  318. // CHECK:STDOUT: %T.patt.loc4_18.2 => constants.%C
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: !definition:
  321. // CHECK:STDOUT: %Simple.type => constants.%Simple.type.3
  322. // CHECK:STDOUT: %Self.2 => constants.%Self.1
  323. // CHECK:STDOUT: }
  324. // CHECK:STDOUT:
  325. // CHECK:STDOUT: specific @WithAssocFn(constants.%C) {
  326. // CHECK:STDOUT: %T.loc8_23.2 => constants.%C
  327. // CHECK:STDOUT: %T.patt.loc8_23.2 => constants.%C
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: !definition:
  330. // CHECK:STDOUT: %WithAssocFn.type => constants.%WithAssocFn.type.3
  331. // CHECK:STDOUT: %Self.2 => constants.%Self.2
  332. // CHECK:STDOUT: %F.type => constants.%F.type.3
  333. // CHECK:STDOUT: %F => constants.%F.3
  334. // CHECK:STDOUT: %.loc10_14.2 => constants.%.7
  335. // CHECK:STDOUT: %.loc10_14.3 => constants.%.8
  336. // CHECK:STDOUT: }
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: specific @F.1(constants.%C, constants.%C) {}
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: specific @WithImplicitArgs(constants.%T.1, constants.%N) {
  341. // CHECK:STDOUT: %T.loc22_28.2 => constants.%T.1
  342. // CHECK:STDOUT: %T.patt.loc22_28.2 => constants.%T.1
  343. // CHECK:STDOUT: %N.loc22_38.2 => constants.%N
  344. // CHECK:STDOUT: %N.patt.loc22_38.2 => constants.%N
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: specific @Receive(constants.%T.2) {
  348. // CHECK:STDOUT: %T.loc24_12.2 => constants.%T.2
  349. // CHECK:STDOUT: %T.patt.loc24_12.2 => constants.%T.2
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: !definition:
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: specific @Pass(constants.%T.2) {
  355. // CHECK:STDOUT: %T.loc25_9.2 => constants.%T.2
  356. // CHECK:STDOUT: %T.patt.loc25_9.2 => constants.%T.2
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: specific @Receive(@Pass.%T.loc25_9.2) {
  360. // CHECK:STDOUT: %T.loc24_12.2 => constants.%T.2
  361. // CHECK:STDOUT: %T.patt.loc24_12.2 => constants.%T.2
  362. // CHECK:STDOUT: }
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: --- fail_mismatched_args.carbon
  365. // CHECK:STDOUT:
  366. // CHECK:STDOUT: constants {
  367. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T, 0 [symbolic]
  368. // CHECK:STDOUT: %T.patt.1: type = symbolic_binding_pattern T, 0 [symbolic]
  369. // CHECK:STDOUT: %Generic.type.1: type = generic_interface_type @Generic [template]
  370. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  371. // CHECK:STDOUT: %Generic: %Generic.type.1 = struct_value () [template]
  372. // CHECK:STDOUT: %Generic.type.2: type = interface_type @Generic, @Generic(%T.1) [symbolic]
  373. // CHECK:STDOUT: %Self: %Generic.type.2 = bind_symbolic_name Self, 1 [symbolic]
  374. // CHECK:STDOUT: %A: type = class_type @A [template]
  375. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  376. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  377. // CHECK:STDOUT: %B: type = class_type @B [template]
  378. // CHECK:STDOUT: %Generic.type.3: type = interface_type @Generic, @Generic(%A) [template]
  379. // CHECK:STDOUT: %T.2: %Generic.type.3 = bind_symbolic_name T, 0 [symbolic]
  380. // CHECK:STDOUT: %T.patt.2: %Generic.type.3 = symbolic_binding_pattern T, 0 [symbolic]
  381. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  382. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  383. // CHECK:STDOUT: %Generic.type.4: type = interface_type @Generic, @Generic(%B) [template]
  384. // CHECK:STDOUT: %T.3: %Generic.type.4 = bind_symbolic_name T, 0 [symbolic]
  385. // CHECK:STDOUT: %T.patt.3: %Generic.type.4 = symbolic_binding_pattern T, 0 [symbolic]
  386. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  387. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: file {
  391. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  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.1 = interface_decl @Generic [template = constants.%Generic] {
  399. // CHECK:STDOUT: %T.patt.loc4_19.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_19.2 (constants.%T.patt.1)]
  400. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc4_19.1, runtime_param<invalid> [symbolic = %T.patt.loc4_19.2 (constants.%T.patt.1)]
  401. // CHECK:STDOUT: } {
  402. // CHECK:STDOUT: %param: type = param runtime_param<invalid>
  403. // CHECK:STDOUT: %T.loc4_19.1: type = bind_symbolic_name T, 0, %param [symbolic = %T.loc4_19.2 (constants.%T.1)]
  404. // CHECK:STDOUT: }
  405. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  406. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  407. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  408. // CHECK:STDOUT: %T.patt.loc9_6.1: %Generic.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc9_6.2 (constants.%T.patt.2)]
  409. // CHECK:STDOUT: %T.param_patt: %Generic.type.3 = param_pattern %T.patt.loc9_6.1, runtime_param<invalid> [symbolic = %T.patt.loc9_6.2 (constants.%T.patt.2)]
  410. // CHECK:STDOUT: } {
  411. // CHECK:STDOUT: %Generic.ref: %Generic.type.1 = name_ref Generic, file.%Generic.decl [template = constants.%Generic]
  412. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  413. // CHECK:STDOUT: %Generic.type: type = interface_type @Generic, @Generic(constants.%A) [template = constants.%Generic.type.3]
  414. // CHECK:STDOUT: %param: %Generic.type.3 = param runtime_param<invalid>
  415. // CHECK:STDOUT: %T.loc9_6.1: %Generic.type.3 = bind_symbolic_name T, 0, %param [symbolic = %T.loc9_6.2 (constants.%T.2)]
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  418. // CHECK:STDOUT: %T.patt.loc10_6.1: %Generic.type.4 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc10_6.2 (constants.%T.patt.3)]
  419. // CHECK:STDOUT: %T.param_patt: %Generic.type.4 = param_pattern %T.patt.loc10_6.1, runtime_param<invalid> [symbolic = %T.patt.loc10_6.2 (constants.%T.patt.3)]
  420. // CHECK:STDOUT: } {
  421. // CHECK:STDOUT: %Generic.ref: %Generic.type.1 = name_ref Generic, file.%Generic.decl [template = constants.%Generic]
  422. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  423. // CHECK:STDOUT: %Generic.type: type = interface_type @Generic, @Generic(constants.%B) [template = constants.%Generic.type.4]
  424. // CHECK:STDOUT: %param: %Generic.type.4 = param runtime_param<invalid>
  425. // CHECK:STDOUT: %T.loc10_6.1: %Generic.type.4 = bind_symbolic_name T, 0, %param [symbolic = %T.loc10_6.2 (constants.%T.3)]
  426. // CHECK:STDOUT: }
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT:
  429. // CHECK:STDOUT: generic interface @Generic(%T.loc4_19.1: type) {
  430. // CHECK:STDOUT: %T.loc4_19.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_19.2 (constants.%T.1)]
  431. // CHECK:STDOUT: %T.patt.loc4_19.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_19.2 (constants.%T.patt.1)]
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: !definition:
  434. // CHECK:STDOUT: %Generic.type: type = interface_type @Generic, @Generic(%T.loc4_19.2) [symbolic = %Generic.type (constants.%Generic.type.2)]
  435. // CHECK:STDOUT: %Self.2: %Generic.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  436. // CHECK:STDOUT:
  437. // CHECK:STDOUT: interface {
  438. // CHECK:STDOUT: %Self.1: @Generic.%Generic.type (%Generic.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  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: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  448. // CHECK:STDOUT:
  449. // CHECK:STDOUT: !members:
  450. // CHECK:STDOUT: .Self = constants.%A
  451. // CHECK:STDOUT: }
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: class @B {
  454. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.2 [template = constants.%.3]
  455. // CHECK:STDOUT:
  456. // CHECK:STDOUT: !members:
  457. // CHECK:STDOUT: .Self = constants.%B
  458. // CHECK:STDOUT: }
  459. // CHECK:STDOUT:
  460. // CHECK:STDOUT: generic fn @F(%T.loc9_6.1: %Generic.type.3) {
  461. // CHECK:STDOUT: %T.loc9_6.2: %Generic.type.3 = bind_symbolic_name T, 0 [symbolic = %T.loc9_6.2 (constants.%T.2)]
  462. // CHECK:STDOUT: %T.patt.loc9_6.2: %Generic.type.3 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc9_6.2 (constants.%T.patt.2)]
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: fn(%T.param_patt: %Generic.type.3);
  465. // CHECK:STDOUT: }
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: generic fn @G(%T.loc10_6.1: %Generic.type.4) {
  468. // CHECK:STDOUT: %T.loc10_6.2: %Generic.type.4 = bind_symbolic_name T, 0 [symbolic = %T.loc10_6.2 (constants.%T.3)]
  469. // CHECK:STDOUT: %T.patt.loc10_6.2: %Generic.type.4 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc10_6.2 (constants.%T.patt.3)]
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: !definition:
  472. // CHECK:STDOUT:
  473. // CHECK:STDOUT: fn(%T.param_patt: %Generic.type.4) {
  474. // CHECK:STDOUT: !entry:
  475. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  476. // CHECK:STDOUT: %T.ref: %Generic.type.4 = name_ref T, %T.loc10_6.1 [symbolic = %T.loc10_6.2 (constants.%T.3)]
  477. // CHECK:STDOUT: %.loc15: %Generic.type.3 = converted %T.ref, <error> [template = <error>]
  478. // CHECK:STDOUT: return
  479. // CHECK:STDOUT: }
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: specific @Generic(constants.%T.1) {
  483. // CHECK:STDOUT: %T.loc4_19.2 => constants.%T.1
  484. // CHECK:STDOUT: %T.patt.loc4_19.2 => constants.%T.1
  485. // CHECK:STDOUT: }
  486. // CHECK:STDOUT:
  487. // CHECK:STDOUT: specific @Generic(@Generic.%T.loc4_19.2) {
  488. // CHECK:STDOUT: %T.loc4_19.2 => constants.%T.1
  489. // CHECK:STDOUT: %T.patt.loc4_19.2 => constants.%T.1
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT:
  492. // CHECK:STDOUT: specific @Generic(constants.%A) {
  493. // CHECK:STDOUT: %T.loc4_19.2 => constants.%A
  494. // CHECK:STDOUT: %T.patt.loc4_19.2 => constants.%A
  495. // CHECK:STDOUT: }
  496. // CHECK:STDOUT:
  497. // CHECK:STDOUT: specific @F(constants.%T.2) {
  498. // CHECK:STDOUT: %T.loc9_6.2 => constants.%T.2
  499. // CHECK:STDOUT: %T.patt.loc9_6.2 => constants.%T.2
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: specific @Generic(constants.%B) {
  503. // CHECK:STDOUT: %T.loc4_19.2 => constants.%B
  504. // CHECK:STDOUT: %T.patt.loc4_19.2 => constants.%B
  505. // CHECK:STDOUT: }
  506. // CHECK:STDOUT:
  507. // CHECK:STDOUT: specific @G(constants.%T.3) {
  508. // CHECK:STDOUT: %T.loc10_6.2 => constants.%T.3
  509. // CHECK:STDOUT: %T.patt.loc10_6.2 => constants.%T.3
  510. // CHECK:STDOUT: }
  511. // CHECK:STDOUT: