tuple.carbon 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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/deduce/tuple.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/deduce/tuple.carbon
  10. // --- tuple_type.carbon
  11. library "[[@TEST_NAME]]";
  12. class C {}
  13. class D {}
  14. fn F[T:! type, U:! type](pair: (T, U)) -> U { return F(pair); }
  15. fn G(pair: (C, D)) -> D {
  16. return F(pair);
  17. }
  18. // --- tuple_value.carbon
  19. library "[[@TEST_NAME]]";
  20. class HasPair(Pair:! (i32, i32)) {}
  21. fn F[A:! i32, B:! i32](h: HasPair((A, B))) -> i32 { return B; }
  22. fn G(h: HasPair((1, 2))) -> i32 {
  23. return F(h);
  24. }
  25. // --- fail_inconsistent.carbon
  26. library "[[@TEST_NAME]]";
  27. class C {}
  28. class D {}
  29. fn F[T:! type](pair: (T, T)) -> T;
  30. fn G(pair: (C, D)) -> D {
  31. // CHECK:STDERR: fail_inconsistent.carbon:[[@LINE+6]]:10: error: inconsistent deductions for value of generic parameter `T`
  32. // CHECK:STDERR: return F(pair);
  33. // CHECK:STDERR: ^~
  34. // CHECK:STDERR: fail_inconsistent.carbon:[[@LINE-6]]:1: note: while deducing parameters of generic declared here
  35. // CHECK:STDERR: fn F[T:! type](pair: (T, T)) -> T;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. return F(pair);
  38. }
  39. // CHECK:STDOUT: --- tuple_type.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %C: type = class_type @C [template]
  43. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  44. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  45. // CHECK:STDOUT: %D: type = class_type @D [template]
  46. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  47. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  48. // CHECK:STDOUT: %U: type = bind_symbolic_name U, 1 [symbolic]
  49. // CHECK:STDOUT: %U.patt: type = symbolic_binding_pattern U, 1 [symbolic]
  50. // CHECK:STDOUT: %.3: type = tuple_type (type, type) [template]
  51. // CHECK:STDOUT: %.4: type = tuple_type (%T, %U) [symbolic]
  52. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  53. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  54. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  55. // CHECK:STDOUT: %.6: type = ptr_type %.4 [symbolic]
  56. // CHECK:STDOUT: %.7: <specific function> = specific_function %F, @F(%T, %U) [symbolic]
  57. // CHECK:STDOUT: %.8: type = tuple_type (%C, %D) [template]
  58. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  59. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  60. // CHECK:STDOUT: %.9: type = ptr_type %.1 [template]
  61. // CHECK:STDOUT: %.10: type = tuple_type (%.9, %.9) [template]
  62. // CHECK:STDOUT: %.11: type = ptr_type %.10 [template]
  63. // CHECK:STDOUT: %.12: <specific function> = specific_function %F, @F(%C, %D) [template]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  68. // CHECK:STDOUT: import Core//prelude
  69. // CHECK:STDOUT: import Core//prelude/operators
  70. // CHECK:STDOUT: import Core//prelude/types
  71. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  72. // CHECK:STDOUT: import Core//prelude/operators/as
  73. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  74. // CHECK:STDOUT: import Core//prelude/operators/comparison
  75. // CHECK:STDOUT: import Core//prelude/types/bool
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: file {
  80. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  81. // CHECK:STDOUT: .Core = imports.%Core
  82. // CHECK:STDOUT: .C = %C.decl
  83. // CHECK:STDOUT: .D = %D.decl
  84. // CHECK:STDOUT: .F = %F.decl
  85. // CHECK:STDOUT: .G = %G.decl
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %Core.import = import Core
  88. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  89. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  90. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  91. // CHECK:STDOUT: %T.patt.loc7_6.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  92. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc7_6.1, runtime_param<invalid> [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  93. // CHECK:STDOUT: %U.patt.loc7_16.1: type = symbolic_binding_pattern U, 1 [symbolic = %U.patt.loc7_16.2 (constants.%U.patt)]
  94. // CHECK:STDOUT: %U.param_patt: type = param_pattern %U.patt.loc7_16.1, runtime_param<invalid> [symbolic = %U.patt.loc7_16.2 (constants.%U.patt)]
  95. // CHECK:STDOUT: %pair.patt: @F.%.loc7_37.3 (%.4) = binding_pattern pair
  96. // CHECK:STDOUT: %pair.param_patt: @F.%.loc7_37.3 (%.4) = param_pattern %pair.patt, runtime_param0
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc7_6.1 [symbolic = %T.loc7_6.2 (constants.%T)]
  99. // CHECK:STDOUT: %U.ref.loc7_36: type = name_ref U, %U.loc7_16.1 [symbolic = %U.loc7_16.2 (constants.%U)]
  100. // CHECK:STDOUT: %.loc7_37.1: %.3 = tuple_literal (%T.ref, %U.ref.loc7_36)
  101. // CHECK:STDOUT: %.loc7_37.2: type = converted %.loc7_37.1, constants.%.4 [symbolic = %.loc7_37.3 (constants.%.4)]
  102. // CHECK:STDOUT: %U.ref.loc7_43: type = name_ref U, %U.loc7_16.1 [symbolic = %U.loc7_16.2 (constants.%U)]
  103. // CHECK:STDOUT: %return: ref @F.%U.loc7_16.2 (%U) = var <return slot>
  104. // CHECK:STDOUT: %param.loc7_6: type = param runtime_param<invalid>
  105. // CHECK:STDOUT: %T.loc7_6.1: type = bind_symbolic_name T, 0, %param.loc7_6 [symbolic = %T.loc7_6.2 (constants.%T)]
  106. // CHECK:STDOUT: %param.loc7_16: type = param runtime_param<invalid>
  107. // CHECK:STDOUT: %U.loc7_16.1: type = bind_symbolic_name U, 1, %param.loc7_16 [symbolic = %U.loc7_16.2 (constants.%U)]
  108. // CHECK:STDOUT: %param.loc7_26: @F.%.loc7_37.3 (%.4) = param runtime_param0
  109. // CHECK:STDOUT: %pair: @F.%.loc7_37.3 (%.4) = bind_name pair, %param.loc7_26
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  112. // CHECK:STDOUT: %pair.patt: %.8 = binding_pattern pair
  113. // CHECK:STDOUT: %pair.param_patt: %.8 = param_pattern %pair.patt, runtime_param0
  114. // CHECK:STDOUT: } {
  115. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  116. // CHECK:STDOUT: %D.ref.loc9_16: type = name_ref D, file.%D.decl [template = constants.%D]
  117. // CHECK:STDOUT: %.loc9_17.1: %.3 = tuple_literal (%C.ref, %D.ref.loc9_16)
  118. // CHECK:STDOUT: %.loc9_17.2: type = converted %.loc9_17.1, constants.%.8 [template = constants.%.8]
  119. // CHECK:STDOUT: %D.ref.loc9_23: type = name_ref D, file.%D.decl [template = constants.%D]
  120. // CHECK:STDOUT: %return: ref %D = var <return slot>
  121. // CHECK:STDOUT: %param: %.8 = param runtime_param0
  122. // CHECK:STDOUT: %pair: %.8 = bind_name pair, %param
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: class @C {
  127. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: !members:
  130. // CHECK:STDOUT: .Self = constants.%C
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: class @D {
  134. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: !members:
  137. // CHECK:STDOUT: .Self = constants.%D
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic fn @F(%T.loc7_6.1: type, %U.loc7_16.1: type) {
  141. // CHECK:STDOUT: %T.loc7_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc7_6.2 (constants.%T)]
  142. // CHECK:STDOUT: %T.patt.loc7_6.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  143. // CHECK:STDOUT: %U.loc7_16.2: type = bind_symbolic_name U, 1 [symbolic = %U.loc7_16.2 (constants.%U)]
  144. // CHECK:STDOUT: %U.patt.loc7_16.2: type = symbolic_binding_pattern U, 1 [symbolic = %U.patt.loc7_16.2 (constants.%U.patt)]
  145. // CHECK:STDOUT: %.loc7_37.3: type = tuple_type (@F.%T.loc7_6.2 (%T), @F.%U.loc7_16.2 (%U)) [symbolic = %.loc7_37.3 (constants.%.4)]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !definition:
  148. // CHECK:STDOUT: %.loc7_54.2: <specific function> = specific_function constants.%F, @F(%T.loc7_6.2, %U.loc7_16.2) [symbolic = %.loc7_54.2 (constants.%.7)]
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn[%T.param_patt: type, %U.param_patt: type](%pair.param_patt: @F.%.loc7_37.3 (%.4)) -> @F.%U.loc7_16.2 (%U) {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  153. // CHECK:STDOUT: %pair.ref: @F.%.loc7_37.3 (%.4) = name_ref pair, %pair
  154. // CHECK:STDOUT: %.loc7_54.1: <specific function> = specific_function %F.ref, @F(constants.%T, constants.%U) [symbolic = %.loc7_54.2 (constants.%.7)]
  155. // CHECK:STDOUT: %F.call: init @F.%U.loc7_16.2 (%U) = call %.loc7_54.1(%pair.ref)
  156. // CHECK:STDOUT: %.loc7_61.1: @F.%U.loc7_16.2 (%U) = value_of_initializer %F.call
  157. // CHECK:STDOUT: %.loc7_61.2: @F.%U.loc7_16.2 (%U) = converted %F.call, %.loc7_61.1
  158. // CHECK:STDOUT: return %.loc7_61.2
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: fn @G(%pair.param_patt: %.8) -> %return: %D {
  163. // CHECK:STDOUT: !entry:
  164. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  165. // CHECK:STDOUT: %pair.ref: %.8 = name_ref pair, %pair
  166. // CHECK:STDOUT: %.loc10: <specific function> = specific_function %F.ref, @F(constants.%C, constants.%D) [template = constants.%.12]
  167. // CHECK:STDOUT: %.loc9_20: ref %D = splice_block %return {}
  168. // CHECK:STDOUT: %F.call: init %D = call %.loc10(%pair.ref) to %.loc9_20
  169. // CHECK:STDOUT: return %F.call to %return
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: specific @F(constants.%T, constants.%U) {
  173. // CHECK:STDOUT: %T.loc7_6.2 => constants.%T
  174. // CHECK:STDOUT: %T.patt.loc7_6.2 => constants.%T
  175. // CHECK:STDOUT: %U.loc7_16.2 => constants.%U
  176. // CHECK:STDOUT: %U.patt.loc7_16.2 => constants.%U
  177. // CHECK:STDOUT: %.loc7_37.3 => constants.%.4
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: !definition:
  180. // CHECK:STDOUT: %.loc7_54.2 => constants.%.7
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: specific @F(@F.%T.loc7_6.2, @F.%U.loc7_16.2) {
  184. // CHECK:STDOUT: %T.loc7_6.2 => constants.%T
  185. // CHECK:STDOUT: %T.patt.loc7_6.2 => constants.%T
  186. // CHECK:STDOUT: %U.loc7_16.2 => constants.%U
  187. // CHECK:STDOUT: %U.patt.loc7_16.2 => constants.%U
  188. // CHECK:STDOUT: %.loc7_37.3 => constants.%.4
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: specific @F(constants.%C, constants.%D) {
  192. // CHECK:STDOUT: %T.loc7_6.2 => constants.%C
  193. // CHECK:STDOUT: %T.patt.loc7_6.2 => constants.%C
  194. // CHECK:STDOUT: %U.loc7_16.2 => constants.%D
  195. // CHECK:STDOUT: %U.patt.loc7_16.2 => constants.%D
  196. // CHECK:STDOUT: %.loc7_37.3 => constants.%.8
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: !definition:
  199. // CHECK:STDOUT: %.loc7_54.2 => constants.%.12
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: --- tuple_value.carbon
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: constants {
  205. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  206. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  207. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  208. // CHECK:STDOUT: %.2: type = tuple_type (type, type) [template]
  209. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32) [template]
  210. // CHECK:STDOUT: %Pair: %.3 = bind_symbolic_name Pair, 0 [symbolic]
  211. // CHECK:STDOUT: %Pair.patt: %.3 = symbolic_binding_pattern Pair, 0 [symbolic]
  212. // CHECK:STDOUT: %HasPair.type: type = generic_class_type @HasPair [template]
  213. // CHECK:STDOUT: %HasPair.1: %HasPair.type = struct_value () [template]
  214. // CHECK:STDOUT: %HasPair.2: type = class_type @HasPair, @HasPair(%Pair) [symbolic]
  215. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  216. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  217. // CHECK:STDOUT: %A: i32 = bind_symbolic_name A, 0 [symbolic]
  218. // CHECK:STDOUT: %A.patt: i32 = symbolic_binding_pattern A, 0 [symbolic]
  219. // CHECK:STDOUT: %B: i32 = bind_symbolic_name B, 1 [symbolic]
  220. // CHECK:STDOUT: %B.patt: i32 = symbolic_binding_pattern B, 1 [symbolic]
  221. // CHECK:STDOUT: %.6: type = ptr_type %.3 [template]
  222. // CHECK:STDOUT: %tuple.1: %.3 = tuple_value (%A, %B) [symbolic]
  223. // CHECK:STDOUT: %HasPair.3: type = class_type @HasPair, @HasPair(%tuple.1) [symbolic]
  224. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  225. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  226. // CHECK:STDOUT: %.7: type = ptr_type %.4 [template]
  227. // CHECK:STDOUT: %.8: i32 = int_literal 1 [template]
  228. // CHECK:STDOUT: %.9: i32 = int_literal 2 [template]
  229. // CHECK:STDOUT: %tuple.2: %.3 = tuple_value (%.8, %.9) [template]
  230. // CHECK:STDOUT: %HasPair.4: type = class_type @HasPair, @HasPair(%tuple.2) [template]
  231. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  232. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  233. // CHECK:STDOUT: %.10: <specific function> = specific_function %F, @F(%.8, %.9) [template]
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: imports {
  237. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  238. // CHECK:STDOUT: .Int32 = %import_ref
  239. // CHECK:STDOUT: import Core//prelude
  240. // CHECK:STDOUT: import Core//prelude/operators
  241. // CHECK:STDOUT: import Core//prelude/types
  242. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  243. // CHECK:STDOUT: import Core//prelude/operators/as
  244. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  245. // CHECK:STDOUT: import Core//prelude/operators/comparison
  246. // CHECK:STDOUT: import Core//prelude/types/bool
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: file {
  252. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  253. // CHECK:STDOUT: .Core = imports.%Core
  254. // CHECK:STDOUT: .HasPair = %HasPair.decl
  255. // CHECK:STDOUT: .F = %F.decl
  256. // CHECK:STDOUT: .G = %G.decl
  257. // CHECK:STDOUT: }
  258. // CHECK:STDOUT: %Core.import = import Core
  259. // CHECK:STDOUT: %HasPair.decl: %HasPair.type = class_decl @HasPair [template = constants.%HasPair.1] {
  260. // CHECK:STDOUT: %Pair.patt.loc4_15.1: %.3 = symbolic_binding_pattern Pair, 0 [symbolic = %Pair.patt.loc4_15.2 (constants.%Pair.patt)]
  261. // CHECK:STDOUT: %Pair.param_patt: %.3 = param_pattern %Pair.patt.loc4_15.1, runtime_param<invalid> [symbolic = %Pair.patt.loc4_15.2 (constants.%Pair.patt)]
  262. // CHECK:STDOUT: } {
  263. // CHECK:STDOUT: %int.make_type_32.loc4_23: init type = call constants.%Int32() [template = i32]
  264. // CHECK:STDOUT: %int.make_type_32.loc4_28: init type = call constants.%Int32() [template = i32]
  265. // CHECK:STDOUT: %.loc4_31.1: %.2 = tuple_literal (%int.make_type_32.loc4_23, %int.make_type_32.loc4_28)
  266. // CHECK:STDOUT: %.loc4_31.2: type = value_of_initializer %int.make_type_32.loc4_23 [template = i32]
  267. // CHECK:STDOUT: %.loc4_31.3: type = converted %int.make_type_32.loc4_23, %.loc4_31.2 [template = i32]
  268. // CHECK:STDOUT: %.loc4_31.4: type = value_of_initializer %int.make_type_32.loc4_28 [template = i32]
  269. // CHECK:STDOUT: %.loc4_31.5: type = converted %int.make_type_32.loc4_28, %.loc4_31.4 [template = i32]
  270. // CHECK:STDOUT: %.loc4_31.6: type = converted %.loc4_31.1, constants.%.3 [template = constants.%.3]
  271. // CHECK:STDOUT: %param: %.3 = param runtime_param<invalid>
  272. // CHECK:STDOUT: %Pair.loc4_15.1: %.3 = bind_symbolic_name Pair, 0, %param [symbolic = %Pair.loc4_15.2 (constants.%Pair)]
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  275. // CHECK:STDOUT: %A.patt.loc6_6.1: i32 = symbolic_binding_pattern A, 0 [symbolic = %A.patt.loc6_6.2 (constants.%A.patt)]
  276. // CHECK:STDOUT: %A.param_patt: i32 = param_pattern %A.patt.loc6_6.1, runtime_param<invalid> [symbolic = %A.patt.loc6_6.2 (constants.%A.patt)]
  277. // CHECK:STDOUT: %B.patt.loc6_15.1: i32 = symbolic_binding_pattern B, 1 [symbolic = %B.patt.loc6_15.2 (constants.%B.patt)]
  278. // CHECK:STDOUT: %B.param_patt: i32 = param_pattern %B.patt.loc6_15.1, runtime_param<invalid> [symbolic = %B.patt.loc6_15.2 (constants.%B.patt)]
  279. // CHECK:STDOUT: %h.patt: @F.%HasPair.loc6_34.2 (%HasPair.3) = binding_pattern h
  280. // CHECK:STDOUT: %h.param_patt: @F.%HasPair.loc6_34.2 (%HasPair.3) = param_pattern %h.patt, runtime_param0
  281. // CHECK:STDOUT: } {
  282. // CHECK:STDOUT: %int.make_type_32.loc6_10: init type = call constants.%Int32() [template = i32]
  283. // CHECK:STDOUT: %.loc6_10.1: type = value_of_initializer %int.make_type_32.loc6_10 [template = i32]
  284. // CHECK:STDOUT: %.loc6_10.2: type = converted %int.make_type_32.loc6_10, %.loc6_10.1 [template = i32]
  285. // CHECK:STDOUT: %int.make_type_32.loc6_19: init type = call constants.%Int32() [template = i32]
  286. // CHECK:STDOUT: %.loc6_19.1: type = value_of_initializer %int.make_type_32.loc6_19 [template = i32]
  287. // CHECK:STDOUT: %.loc6_19.2: type = converted %int.make_type_32.loc6_19, %.loc6_19.1 [template = i32]
  288. // CHECK:STDOUT: %HasPair.ref: %HasPair.type = name_ref HasPair, file.%HasPair.decl [template = constants.%HasPair.1]
  289. // CHECK:STDOUT: %A.ref: i32 = name_ref A, %A.loc6_6.1 [symbolic = %A.loc6_6.2 (constants.%A)]
  290. // CHECK:STDOUT: %B.ref.loc6_39: i32 = name_ref B, %B.loc6_15.1 [symbolic = %B.loc6_15.2 (constants.%B)]
  291. // CHECK:STDOUT: %.loc6_40: %.3 = tuple_literal (%A.ref, %B.ref.loc6_39)
  292. // CHECK:STDOUT: %tuple.loc6_40.1: %.3 = tuple_value (%A.ref, %B.ref.loc6_39) [symbolic = %tuple.loc6_40.2 (constants.%tuple.1)]
  293. // CHECK:STDOUT: %.loc6_34: %.3 = converted %.loc6_40, %tuple.loc6_40.1 [symbolic = %tuple.loc6_40.2 (constants.%tuple.1)]
  294. // CHECK:STDOUT: %HasPair.loc6_34.1: type = class_type @HasPair, @HasPair(constants.%tuple.1) [symbolic = %HasPair.loc6_34.2 (constants.%HasPair.3)]
  295. // CHECK:STDOUT: %int.make_type_32.loc6_47: init type = call constants.%Int32() [template = i32]
  296. // CHECK:STDOUT: %.loc6_47.1: type = value_of_initializer %int.make_type_32.loc6_47 [template = i32]
  297. // CHECK:STDOUT: %.loc6_47.2: type = converted %int.make_type_32.loc6_47, %.loc6_47.1 [template = i32]
  298. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  299. // CHECK:STDOUT: %param.loc6_6: i32 = param runtime_param<invalid>
  300. // CHECK:STDOUT: %A.loc6_6.1: i32 = bind_symbolic_name A, 0, %param.loc6_6 [symbolic = %A.loc6_6.2 (constants.%A)]
  301. // CHECK:STDOUT: %param.loc6_15: i32 = param runtime_param<invalid>
  302. // CHECK:STDOUT: %B.loc6_15.1: i32 = bind_symbolic_name B, 1, %param.loc6_15 [symbolic = %B.loc6_15.2 (constants.%B)]
  303. // CHECK:STDOUT: %param.loc6_24: @F.%HasPair.loc6_34.2 (%HasPair.3) = param runtime_param0
  304. // CHECK:STDOUT: %h: @F.%HasPair.loc6_34.2 (%HasPair.3) = bind_name h, %param.loc6_24
  305. // CHECK:STDOUT: }
  306. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  307. // CHECK:STDOUT: %h.patt: %HasPair.4 = binding_pattern h
  308. // CHECK:STDOUT: %h.param_patt: %HasPair.4 = param_pattern %h.patt, runtime_param0
  309. // CHECK:STDOUT: } {
  310. // CHECK:STDOUT: %HasPair.ref: %HasPair.type = name_ref HasPair, file.%HasPair.decl [template = constants.%HasPair.1]
  311. // CHECK:STDOUT: %.loc8_18: i32 = int_literal 1 [template = constants.%.8]
  312. // CHECK:STDOUT: %.loc8_21: i32 = int_literal 2 [template = constants.%.9]
  313. // CHECK:STDOUT: %.loc8_22: %.3 = tuple_literal (%.loc8_18, %.loc8_21)
  314. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.loc8_18, %.loc8_21) [template = constants.%tuple.2]
  315. // CHECK:STDOUT: %.loc8_16: %.3 = converted %.loc8_22, %tuple [template = constants.%tuple.2]
  316. // CHECK:STDOUT: %HasPair: type = class_type @HasPair, @HasPair(constants.%tuple.2) [template = constants.%HasPair.4]
  317. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  318. // CHECK:STDOUT: %.loc8_29.1: type = value_of_initializer %int.make_type_32 [template = i32]
  319. // CHECK:STDOUT: %.loc8_29.2: type = converted %int.make_type_32, %.loc8_29.1 [template = i32]
  320. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  321. // CHECK:STDOUT: %param: %HasPair.4 = param runtime_param0
  322. // CHECK:STDOUT: %h: %HasPair.4 = bind_name h, %param
  323. // CHECK:STDOUT: }
  324. // CHECK:STDOUT: }
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: generic class @HasPair(%Pair.loc4_15.1: %.3) {
  327. // CHECK:STDOUT: %Pair.loc4_15.2: %.3 = bind_symbolic_name Pair, 0 [symbolic = %Pair.loc4_15.2 (constants.%Pair)]
  328. // CHECK:STDOUT: %Pair.patt.loc4_15.2: %.3 = symbolic_binding_pattern Pair, 0 [symbolic = %Pair.patt.loc4_15.2 (constants.%Pair.patt)]
  329. // CHECK:STDOUT:
  330. // CHECK:STDOUT: !definition:
  331. // CHECK:STDOUT:
  332. // CHECK:STDOUT: class {
  333. // CHECK:STDOUT: %.loc4_35: <witness> = complete_type_witness %.4 [template = constants.%.5]
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: !members:
  336. // CHECK:STDOUT: .Self = constants.%HasPair.2
  337. // CHECK:STDOUT: }
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: generic fn @F(%A.loc6_6.1: i32, %B.loc6_15.1: i32) {
  343. // CHECK:STDOUT: %A.loc6_6.2: i32 = bind_symbolic_name A, 0 [symbolic = %A.loc6_6.2 (constants.%A)]
  344. // CHECK:STDOUT: %A.patt.loc6_6.2: i32 = symbolic_binding_pattern A, 0 [symbolic = %A.patt.loc6_6.2 (constants.%A.patt)]
  345. // CHECK:STDOUT: %B.loc6_15.2: i32 = bind_symbolic_name B, 1 [symbolic = %B.loc6_15.2 (constants.%B)]
  346. // CHECK:STDOUT: %B.patt.loc6_15.2: i32 = symbolic_binding_pattern B, 1 [symbolic = %B.patt.loc6_15.2 (constants.%B.patt)]
  347. // CHECK:STDOUT: %tuple.loc6_40.2: %.3 = tuple_value (%A.loc6_6.2, %B.loc6_15.2) [symbolic = %tuple.loc6_40.2 (constants.%tuple.1)]
  348. // CHECK:STDOUT: %HasPair.loc6_34.2: type = class_type @HasPair, @HasPair(%tuple.loc6_40.2) [symbolic = %HasPair.loc6_34.2 (constants.%HasPair.3)]
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: !definition:
  351. // CHECK:STDOUT:
  352. // CHECK:STDOUT: fn[%A.param_patt: i32, %B.param_patt: i32](%h.param_patt: @F.%HasPair.loc6_34.2 (%HasPair.3)) -> i32 {
  353. // CHECK:STDOUT: !entry:
  354. // CHECK:STDOUT: %B.ref.loc6_60: i32 = name_ref B, %B.loc6_15.1 [symbolic = %B.loc6_15.2 (constants.%B)]
  355. // CHECK:STDOUT: return %B.ref.loc6_60
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: fn @G(%h.param_patt: %HasPair.4) -> i32 {
  360. // CHECK:STDOUT: !entry:
  361. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  362. // CHECK:STDOUT: %h.ref: %HasPair.4 = name_ref h, %h
  363. // CHECK:STDOUT: %.loc9_10: <specific function> = specific_function %F.ref, @F(constants.%.8, constants.%.9) [template = constants.%.10]
  364. // CHECK:STDOUT: %F.call: init i32 = call %.loc9_10(%h.ref)
  365. // CHECK:STDOUT: %.loc9_14.1: i32 = value_of_initializer %F.call
  366. // CHECK:STDOUT: %.loc9_14.2: i32 = converted %F.call, %.loc9_14.1
  367. // CHECK:STDOUT: return %.loc9_14.2
  368. // CHECK:STDOUT: }
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: specific @HasPair(constants.%Pair) {
  371. // CHECK:STDOUT: %Pair.loc4_15.2 => constants.%Pair
  372. // CHECK:STDOUT: %Pair.patt.loc4_15.2 => constants.%Pair
  373. // CHECK:STDOUT: }
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: specific @HasPair(constants.%tuple.1) {
  376. // CHECK:STDOUT: %Pair.loc4_15.2 => constants.%tuple.1
  377. // CHECK:STDOUT: %Pair.patt.loc4_15.2 => constants.%tuple.1
  378. // CHECK:STDOUT:
  379. // CHECK:STDOUT: !definition:
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: specific @HasPair(@F.%tuple.loc6_40.2) {
  383. // CHECK:STDOUT: %Pair.loc4_15.2 => constants.%tuple.1
  384. // CHECK:STDOUT: %Pair.patt.loc4_15.2 => constants.%tuple.1
  385. // CHECK:STDOUT: }
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: specific @F(constants.%A, constants.%B) {
  388. // CHECK:STDOUT: %A.loc6_6.2 => constants.%A
  389. // CHECK:STDOUT: %A.patt.loc6_6.2 => constants.%A
  390. // CHECK:STDOUT: %B.loc6_15.2 => constants.%B
  391. // CHECK:STDOUT: %B.patt.loc6_15.2 => constants.%B
  392. // CHECK:STDOUT: %tuple.loc6_40.2 => constants.%tuple.1
  393. // CHECK:STDOUT: %HasPair.loc6_34.2 => constants.%HasPair.3
  394. // CHECK:STDOUT: }
  395. // CHECK:STDOUT:
  396. // CHECK:STDOUT: specific @HasPair(constants.%tuple.2) {
  397. // CHECK:STDOUT: %Pair.loc4_15.2 => constants.%tuple.2
  398. // CHECK:STDOUT: %Pair.patt.loc4_15.2 => constants.%tuple.2
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: !definition:
  401. // CHECK:STDOUT: }
  402. // CHECK:STDOUT:
  403. // CHECK:STDOUT: specific @F(constants.%.8, constants.%.9) {
  404. // CHECK:STDOUT: %A.loc6_6.2 => constants.%.8
  405. // CHECK:STDOUT: %A.patt.loc6_6.2 => constants.%.8
  406. // CHECK:STDOUT: %B.loc6_15.2 => constants.%.9
  407. // CHECK:STDOUT: %B.patt.loc6_15.2 => constants.%.9
  408. // CHECK:STDOUT: %tuple.loc6_40.2 => constants.%tuple.2
  409. // CHECK:STDOUT: %HasPair.loc6_34.2 => constants.%HasPair.4
  410. // CHECK:STDOUT:
  411. // CHECK:STDOUT: !definition:
  412. // CHECK:STDOUT: }
  413. // CHECK:STDOUT:
  414. // CHECK:STDOUT: --- fail_inconsistent.carbon
  415. // CHECK:STDOUT:
  416. // CHECK:STDOUT: constants {
  417. // CHECK:STDOUT: %C: type = class_type @C [template]
  418. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  419. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  420. // CHECK:STDOUT: %D: type = class_type @D [template]
  421. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  422. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  423. // CHECK:STDOUT: %.3: type = tuple_type (type, type) [template]
  424. // CHECK:STDOUT: %.4: type = tuple_type (%T, %T) [symbolic]
  425. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  426. // CHECK:STDOUT: %.5: type = tuple_type () [template]
  427. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  428. // CHECK:STDOUT: %.6: type = tuple_type (%C, %D) [template]
  429. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  430. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  431. // CHECK:STDOUT: %.7: type = ptr_type %.1 [template]
  432. // CHECK:STDOUT: %.8: type = tuple_type (%.7, %.7) [template]
  433. // CHECK:STDOUT: %.9: type = ptr_type %.8 [template]
  434. // CHECK:STDOUT: }
  435. // CHECK:STDOUT:
  436. // CHECK:STDOUT: imports {
  437. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  438. // CHECK:STDOUT: import Core//prelude
  439. // CHECK:STDOUT: import Core//prelude/operators
  440. // CHECK:STDOUT: import Core//prelude/types
  441. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  442. // CHECK:STDOUT: import Core//prelude/operators/as
  443. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  444. // CHECK:STDOUT: import Core//prelude/operators/comparison
  445. // CHECK:STDOUT: import Core//prelude/types/bool
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT: }
  448. // CHECK:STDOUT:
  449. // CHECK:STDOUT: file {
  450. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  451. // CHECK:STDOUT: .Core = imports.%Core
  452. // CHECK:STDOUT: .C = %C.decl
  453. // CHECK:STDOUT: .D = %D.decl
  454. // CHECK:STDOUT: .F = %F.decl
  455. // CHECK:STDOUT: .G = %G.decl
  456. // CHECK:STDOUT: }
  457. // CHECK:STDOUT: %Core.import = import Core
  458. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  459. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  460. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  461. // CHECK:STDOUT: %T.patt.loc7_6.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  462. // CHECK:STDOUT: %T.param_patt: type = param_pattern %T.patt.loc7_6.1, runtime_param<invalid> [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  463. // CHECK:STDOUT: %pair.patt: @F.%.loc7_27.3 (%.4) = binding_pattern pair
  464. // CHECK:STDOUT: %pair.param_patt: @F.%.loc7_27.3 (%.4) = param_pattern %pair.patt, runtime_param0
  465. // CHECK:STDOUT: } {
  466. // CHECK:STDOUT: %T.ref.loc7_23: type = name_ref T, %T.loc7_6.1 [symbolic = %T.loc7_6.2 (constants.%T)]
  467. // CHECK:STDOUT: %T.ref.loc7_26: type = name_ref T, %T.loc7_6.1 [symbolic = %T.loc7_6.2 (constants.%T)]
  468. // CHECK:STDOUT: %.loc7_27.1: %.3 = tuple_literal (%T.ref.loc7_23, %T.ref.loc7_26)
  469. // CHECK:STDOUT: %.loc7_27.2: type = converted %.loc7_27.1, constants.%.4 [symbolic = %.loc7_27.3 (constants.%.4)]
  470. // CHECK:STDOUT: %T.ref.loc7_33: type = name_ref T, %T.loc7_6.1 [symbolic = %T.loc7_6.2 (constants.%T)]
  471. // CHECK:STDOUT: %return: ref @F.%T.loc7_6.2 (%T) = var <return slot>
  472. // CHECK:STDOUT: %param.loc7_6: type = param runtime_param<invalid>
  473. // CHECK:STDOUT: %T.loc7_6.1: type = bind_symbolic_name T, 0, %param.loc7_6 [symbolic = %T.loc7_6.2 (constants.%T)]
  474. // CHECK:STDOUT: %param.loc7_16: @F.%.loc7_27.3 (%.4) = param runtime_param0
  475. // CHECK:STDOUT: %pair: @F.%.loc7_27.3 (%.4) = bind_name pair, %param.loc7_16
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  478. // CHECK:STDOUT: %pair.patt: %.6 = binding_pattern pair
  479. // CHECK:STDOUT: %pair.param_patt: %.6 = param_pattern %pair.patt, runtime_param0
  480. // CHECK:STDOUT: } {
  481. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  482. // CHECK:STDOUT: %D.ref.loc9_16: type = name_ref D, file.%D.decl [template = constants.%D]
  483. // CHECK:STDOUT: %.loc9_17.1: %.3 = tuple_literal (%C.ref, %D.ref.loc9_16)
  484. // CHECK:STDOUT: %.loc9_17.2: type = converted %.loc9_17.1, constants.%.6 [template = constants.%.6]
  485. // CHECK:STDOUT: %D.ref.loc9_23: type = name_ref D, file.%D.decl [template = constants.%D]
  486. // CHECK:STDOUT: %return: ref %D = var <return slot>
  487. // CHECK:STDOUT: %param: %.6 = param runtime_param0
  488. // CHECK:STDOUT: %pair: %.6 = bind_name pair, %param
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT:
  492. // CHECK:STDOUT: class @C {
  493. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: !members:
  496. // CHECK:STDOUT: .Self = constants.%C
  497. // CHECK:STDOUT: }
  498. // CHECK:STDOUT:
  499. // CHECK:STDOUT: class @D {
  500. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: !members:
  503. // CHECK:STDOUT: .Self = constants.%D
  504. // CHECK:STDOUT: }
  505. // CHECK:STDOUT:
  506. // CHECK:STDOUT: generic fn @F(%T.loc7_6.1: type) {
  507. // CHECK:STDOUT: %T.loc7_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc7_6.2 (constants.%T)]
  508. // CHECK:STDOUT: %T.patt.loc7_6.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc7_6.2 (constants.%T.patt)]
  509. // CHECK:STDOUT: %.loc7_27.3: type = tuple_type (@F.%T.loc7_6.2 (%T), @F.%T.loc7_6.2 (%T)) [symbolic = %.loc7_27.3 (constants.%.4)]
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: fn[%T.param_patt: type](%pair.param_patt: @F.%.loc7_27.3 (%.4)) -> @F.%T.loc7_6.2 (%T);
  512. // CHECK:STDOUT: }
  513. // CHECK:STDOUT:
  514. // CHECK:STDOUT: fn @G(%pair.param_patt: %.6) -> %return: %D {
  515. // CHECK:STDOUT: !entry:
  516. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  517. // CHECK:STDOUT: %pair.ref: %.6 = name_ref pair, %pair
  518. // CHECK:STDOUT: return <error> to %return
  519. // CHECK:STDOUT: }
  520. // CHECK:STDOUT:
  521. // CHECK:STDOUT: specific @F(constants.%T) {
  522. // CHECK:STDOUT: %T.loc7_6.2 => constants.%T
  523. // CHECK:STDOUT: %T.patt.loc7_6.2 => constants.%T
  524. // CHECK:STDOUT: %.loc7_27.3 => constants.%.4
  525. // CHECK:STDOUT: }
  526. // CHECK:STDOUT: