tuple_pattern.carbon 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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/destroy.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/tuple/tuple_pattern.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/tuple_pattern.carbon
  12. // --- basic.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F() {
  15. //@dump-sem-ir-begin
  16. let (x: {}, y: {}) = ({}, {});
  17. var (a: {}, b: {});
  18. var (c: {}, d: {}) = ({}, {});
  19. //@dump-sem-ir-end
  20. }
  21. // --- variable.carbon
  22. library "[[@TEST_NAME]]";
  23. fn F() {
  24. //@dump-sem-ir-begin
  25. var tuple: ({}, {}) = ({}, {});
  26. var (x: {}, y: {}) = tuple;
  27. //@dump-sem-ir-end
  28. }
  29. fn G() {
  30. //@dump-sem-ir-begin
  31. let tuple: ({}, {}) = ({}, {});
  32. var (x: {}, y: {}) = tuple;
  33. //@dump-sem-ir-end
  34. }
  35. fn MakeTuple() -> ({}, {});
  36. fn H() {
  37. //@dump-sem-ir-begin
  38. var (x: {}, y: {}) = MakeTuple();
  39. //@dump-sem-ir-end
  40. }
  41. // --- nested.carbon
  42. library "[[@TEST_NAME]]";
  43. fn F() {
  44. //@dump-sem-ir-begin
  45. let (x: {}, (y: {}, z: {})) = ({}, ({}, {}));
  46. //@dump-sem-ir-end
  47. }
  48. // --- package_scope.carbon
  49. library "[[@TEST_NAME]]";
  50. //@dump-sem-ir-begin
  51. let (x: {}, y: {}) = ({}, {});
  52. //@dump-sem-ir-end
  53. // --- fail_in_interface.carbon
  54. library "[[@TEST_NAME]]";
  55. interface I {
  56. // CHECK:STDERR: fail_in_interface.carbon:[[@LINE+12]]:8: error: found runtime binding pattern in associated constant declaration; expected a `:!` binding [ExpectedSymbolicBindingInAssociatedConstant]
  57. // CHECK:STDERR: let (x: {}, y: {});
  58. // CHECK:STDERR: ^~~~~
  59. // CHECK:STDERR:
  60. // CHECK:STDERR: fail_in_interface.carbon:[[@LINE+8]]:15: error: found runtime binding pattern in associated constant declaration; expected a `:!` binding [ExpectedSymbolicBindingInAssociatedConstant]
  61. // CHECK:STDERR: let (x: {}, y: {});
  62. // CHECK:STDERR: ^~~~~
  63. // CHECK:STDERR:
  64. // CHECK:STDERR: fail_in_interface.carbon:[[@LINE+4]]:7: error: found tuple pattern in associated constant declaration; expected symbolic binding pattern [ExpectedSingleBindingInAssociatedConstant]
  65. // CHECK:STDERR: let (x: {}, y: {});
  66. // CHECK:STDERR: ^~~~~~~~~~~~~~
  67. // CHECK:STDERR:
  68. let (x: {}, y: {});
  69. }
  70. // --- fail_in_class.carbon
  71. library "[[@TEST_NAME]]";
  72. class C {
  73. // CHECK:STDERR: fail_in_class.carbon:[[@LINE+8]]:7: error: expected identifier in field declaration [ExpectedFieldIdentifier]
  74. // CHECK:STDERR: var (x: {}, y: {});
  75. // CHECK:STDERR: ^
  76. // CHECK:STDERR:
  77. // CHECK:STDERR: fail_in_class.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  78. // CHECK:STDERR: var (x: {}, y: {});
  79. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  80. // CHECK:STDERR:
  81. var (x: {}, y: {});
  82. }
  83. // --- fail_initializer_mismatch.carbon
  84. library "[[@TEST_NAME]]";
  85. // CHECK:STDERR: fail_initializer_mismatch.carbon:[[@LINE+4]]:5: error: tuple pattern expects 2 elements, but tuple literal has 1 [TuplePatternSizeDoesntMatchLiteral]
  86. // CHECK:STDERR: let (x: {}, y: {}) = ({},);
  87. // CHECK:STDERR: ^~~~~~~~~~~~~~
  88. // CHECK:STDERR:
  89. let (x: {}, y: {}) = ({},);
  90. // CHECK:STDERR: fail_initializer_mismatch.carbon:[[@LINE+4]]:5: error: tuple pattern expects 2 elements, but tuple literal has 3 [TuplePatternSizeDoesntMatchLiteral]
  91. // CHECK:STDERR: let (a: {}, b: {}) = ({}, {}, {});
  92. // CHECK:STDERR: ^~~~~~~~~~~~~~
  93. // CHECK:STDERR:
  94. let (a: {}, b: {}) = ({}, {}, {});
  95. // CHECK:STDOUT: --- basic.carbon
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: constants {
  98. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  99. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  100. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  101. // CHECK:STDOUT: %tuple.type.b6b: type = tuple_type (%empty_struct_type, %empty_struct_type) [concrete]
  102. // CHECK:STDOUT: %pattern_type.de4: type = pattern_type %tuple.type.b6b [concrete]
  103. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  104. // CHECK:STDOUT: %tuple: %tuple.type.b6b = tuple_value (%empty_struct, %empty_struct) [concrete]
  105. // CHECK:STDOUT: %Op.type.72a: type = fn_type @Op.2, @Destroy.impl(%tuple.type.b6b) [concrete]
  106. // CHECK:STDOUT: %Op.973: %Op.type.72a = struct_value () [concrete]
  107. // CHECK:STDOUT: %ptr.8fc: type = ptr_type %tuple.type.b6b [concrete]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: imports {
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @F() {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: name_binding_decl {
  116. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  117. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  118. // CHECK:STDOUT: %.loc6_20: %pattern_type.de4 = tuple_pattern (%x.patt, %y.patt) [concrete]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %.loc6_26.1: %empty_struct_type = struct_literal ()
  121. // CHECK:STDOUT: %.loc6_30.1: %empty_struct_type = struct_literal ()
  122. // CHECK:STDOUT: %.loc6_31: %tuple.type.b6b = tuple_literal (%.loc6_26.1, %.loc6_30.1)
  123. // CHECK:STDOUT: %.loc6_12.1: type = splice_block %.loc6_12.3 [concrete = constants.%empty_struct_type] {
  124. // CHECK:STDOUT: %.loc6_12.2: %empty_struct_type = struct_literal ()
  125. // CHECK:STDOUT: %.loc6_12.3: type = converted %.loc6_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %empty_struct.loc6_26: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  128. // CHECK:STDOUT: %.loc6_26.2: %empty_struct_type = converted %.loc6_26.1, %empty_struct.loc6_26 [concrete = constants.%empty_struct]
  129. // CHECK:STDOUT: %x: %empty_struct_type = bind_name x, %.loc6_26.2
  130. // CHECK:STDOUT: %.loc6_19.1: type = splice_block %.loc6_19.3 [concrete = constants.%empty_struct_type] {
  131. // CHECK:STDOUT: %.loc6_19.2: %empty_struct_type = struct_literal ()
  132. // CHECK:STDOUT: %.loc6_19.3: type = converted %.loc6_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %empty_struct.loc6_30: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  135. // CHECK:STDOUT: %.loc6_30.2: %empty_struct_type = converted %.loc6_30.1, %empty_struct.loc6_30 [concrete = constants.%empty_struct]
  136. // CHECK:STDOUT: %y: %empty_struct_type = bind_name y, %.loc6_30.2
  137. // CHECK:STDOUT: name_binding_decl {
  138. // CHECK:STDOUT: %a.patt: %pattern_type.a96 = binding_pattern a [concrete]
  139. // CHECK:STDOUT: %b.patt: %pattern_type.a96 = binding_pattern b [concrete]
  140. // CHECK:STDOUT: %.loc7_20: %pattern_type.de4 = tuple_pattern (%a.patt, %b.patt) [concrete]
  141. // CHECK:STDOUT: %.var_patt.loc7: %pattern_type.de4 = var_pattern %.loc7_20 [concrete]
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %.var.loc7: ref %tuple.type.b6b = var %.var_patt.loc7
  144. // CHECK:STDOUT: %tuple.elem0.loc7: ref %empty_struct_type = tuple_access %.var.loc7, element0
  145. // CHECK:STDOUT: %tuple.elem1.loc7: ref %empty_struct_type = tuple_access %.var.loc7, element1
  146. // CHECK:STDOUT: %.loc7_12.1: type = splice_block %.loc7_12.3 [concrete = constants.%empty_struct_type] {
  147. // CHECK:STDOUT: %.loc7_12.2: %empty_struct_type = struct_literal ()
  148. // CHECK:STDOUT: %.loc7_12.3: type = converted %.loc7_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %a: ref %empty_struct_type = bind_name a, %tuple.elem0.loc7
  151. // CHECK:STDOUT: %.loc7_19.1: type = splice_block %.loc7_19.3 [concrete = constants.%empty_struct_type] {
  152. // CHECK:STDOUT: %.loc7_19.2: %empty_struct_type = struct_literal ()
  153. // CHECK:STDOUT: %.loc7_19.3: type = converted %.loc7_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: %b: ref %empty_struct_type = bind_name b, %tuple.elem1.loc7
  156. // CHECK:STDOUT: name_binding_decl {
  157. // CHECK:STDOUT: %c.patt: %pattern_type.a96 = binding_pattern c [concrete]
  158. // CHECK:STDOUT: %d.patt: %pattern_type.a96 = binding_pattern d [concrete]
  159. // CHECK:STDOUT: %.loc8_20: %pattern_type.de4 = tuple_pattern (%c.patt, %d.patt) [concrete]
  160. // CHECK:STDOUT: %.var_patt.loc8: %pattern_type.de4 = var_pattern %.loc8_20 [concrete]
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: %.var.loc8: ref %tuple.type.b6b = var %.var_patt.loc8
  163. // CHECK:STDOUT: %.loc8_26.1: %empty_struct_type = struct_literal ()
  164. // CHECK:STDOUT: %.loc8_30.1: %empty_struct_type = struct_literal ()
  165. // CHECK:STDOUT: %.loc8_31.1: %tuple.type.b6b = tuple_literal (%.loc8_26.1, %.loc8_30.1)
  166. // CHECK:STDOUT: %tuple.elem0.loc8_31: ref %empty_struct_type = tuple_access %.var.loc8, element0
  167. // CHECK:STDOUT: %.loc8_26.2: init %empty_struct_type = struct_init () to %tuple.elem0.loc8_31 [concrete = constants.%empty_struct]
  168. // CHECK:STDOUT: %.loc8_31.2: init %empty_struct_type = converted %.loc8_26.1, %.loc8_26.2 [concrete = constants.%empty_struct]
  169. // CHECK:STDOUT: %tuple.elem1.loc8_31: ref %empty_struct_type = tuple_access %.var.loc8, element1
  170. // CHECK:STDOUT: %.loc8_30.2: init %empty_struct_type = struct_init () to %tuple.elem1.loc8_31 [concrete = constants.%empty_struct]
  171. // CHECK:STDOUT: %.loc8_31.3: init %empty_struct_type = converted %.loc8_30.1, %.loc8_30.2 [concrete = constants.%empty_struct]
  172. // CHECK:STDOUT: %.loc8_31.4: init %tuple.type.b6b = tuple_init (%.loc8_31.2, %.loc8_31.3) to %.var.loc8 [concrete = constants.%tuple]
  173. // CHECK:STDOUT: %.loc8_3: init %tuple.type.b6b = converted %.loc8_31.1, %.loc8_31.4 [concrete = constants.%tuple]
  174. // CHECK:STDOUT: assign %.var.loc8, %.loc8_3
  175. // CHECK:STDOUT: %tuple.elem0.loc8_3: ref %empty_struct_type = tuple_access %.var.loc8, element0
  176. // CHECK:STDOUT: %tuple.elem1.loc8_3: ref %empty_struct_type = tuple_access %.var.loc8, element1
  177. // CHECK:STDOUT: %.loc8_12.1: type = splice_block %.loc8_12.3 [concrete = constants.%empty_struct_type] {
  178. // CHECK:STDOUT: %.loc8_12.2: %empty_struct_type = struct_literal ()
  179. // CHECK:STDOUT: %.loc8_12.3: type = converted %.loc8_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %c: ref %empty_struct_type = bind_name c, %tuple.elem0.loc8_3
  182. // CHECK:STDOUT: %.loc8_19.1: type = splice_block %.loc8_19.3 [concrete = constants.%empty_struct_type] {
  183. // CHECK:STDOUT: %.loc8_19.2: %empty_struct_type = struct_literal ()
  184. // CHECK:STDOUT: %.loc8_19.3: type = converted %.loc8_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT: %d: ref %empty_struct_type = bind_name d, %tuple.elem1.loc8_3
  187. // CHECK:STDOUT: %Op.bound.loc8: <bound method> = bound_method %.var.loc8, constants.%Op.973
  188. // CHECK:STDOUT: <elided>
  189. // CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %.var.loc8, %Op.specific_fn.1
  190. // CHECK:STDOUT: %addr.loc8: %ptr.8fc = addr_of %.var.loc8
  191. // CHECK:STDOUT: %no_op.loc8: init %empty_tuple.type = call %bound_method.loc8(%addr.loc8)
  192. // CHECK:STDOUT: %Op.bound.loc7: <bound method> = bound_method %.var.loc7, constants.%Op.973
  193. // CHECK:STDOUT: <elided>
  194. // CHECK:STDOUT: %bound_method.loc7: <bound method> = bound_method %.var.loc7, %Op.specific_fn.2
  195. // CHECK:STDOUT: %addr.loc7: %ptr.8fc = addr_of %.var.loc7
  196. // CHECK:STDOUT: %no_op.loc7: init %empty_tuple.type = call %bound_method.loc7(%addr.loc7)
  197. // CHECK:STDOUT: <elided>
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: --- variable.carbon
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: constants {
  203. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  204. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  205. // CHECK:STDOUT: %tuple.type.b6b: type = tuple_type (%empty_struct_type, %empty_struct_type) [concrete]
  206. // CHECK:STDOUT: %pattern_type.de4: type = pattern_type %tuple.type.b6b [concrete]
  207. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  208. // CHECK:STDOUT: %tuple: %tuple.type.b6b = tuple_value (%empty_struct, %empty_struct) [concrete]
  209. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  210. // CHECK:STDOUT: %Op.type.72a: type = fn_type @Op.2, @Destroy.impl(%tuple.type.b6b) [concrete]
  211. // CHECK:STDOUT: %Op.973: %Op.type.72a = struct_value () [concrete]
  212. // CHECK:STDOUT: %ptr.8fc: type = ptr_type %tuple.type.b6b [concrete]
  213. // CHECK:STDOUT: %MakeTuple.type: type = fn_type @MakeTuple [concrete]
  214. // CHECK:STDOUT: %MakeTuple: %MakeTuple.type = struct_value () [concrete]
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: imports {
  218. // CHECK:STDOUT: }
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: fn @F() {
  221. // CHECK:STDOUT: !entry:
  222. // CHECK:STDOUT: name_binding_decl {
  223. // CHECK:STDOUT: %tuple.patt: %pattern_type.de4 = binding_pattern tuple [concrete]
  224. // CHECK:STDOUT: %tuple.var_patt: %pattern_type.de4 = var_pattern %tuple.patt [concrete]
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT: %tuple.var: ref %tuple.type.b6b = var %tuple.var_patt
  227. // CHECK:STDOUT: %.loc6_27.1: %empty_struct_type = struct_literal ()
  228. // CHECK:STDOUT: %.loc6_31.1: %empty_struct_type = struct_literal ()
  229. // CHECK:STDOUT: %.loc6_32.1: %tuple.type.b6b = tuple_literal (%.loc6_27.1, %.loc6_31.1)
  230. // CHECK:STDOUT: %tuple.elem0.loc6: ref %empty_struct_type = tuple_access %tuple.var, element0
  231. // CHECK:STDOUT: %.loc6_27.2: init %empty_struct_type = struct_init () to %tuple.elem0.loc6 [concrete = constants.%empty_struct]
  232. // CHECK:STDOUT: %.loc6_32.2: init %empty_struct_type = converted %.loc6_27.1, %.loc6_27.2 [concrete = constants.%empty_struct]
  233. // CHECK:STDOUT: %tuple.elem1.loc6: ref %empty_struct_type = tuple_access %tuple.var, element1
  234. // CHECK:STDOUT: %.loc6_31.2: init %empty_struct_type = struct_init () to %tuple.elem1.loc6 [concrete = constants.%empty_struct]
  235. // CHECK:STDOUT: %.loc6_32.3: init %empty_struct_type = converted %.loc6_31.1, %.loc6_31.2 [concrete = constants.%empty_struct]
  236. // CHECK:STDOUT: %.loc6_32.4: init %tuple.type.b6b = tuple_init (%.loc6_32.2, %.loc6_32.3) to %tuple.var [concrete = constants.%tuple]
  237. // CHECK:STDOUT: %.loc6_3: init %tuple.type.b6b = converted %.loc6_32.1, %.loc6_32.4 [concrete = constants.%tuple]
  238. // CHECK:STDOUT: assign %tuple.var, %.loc6_3
  239. // CHECK:STDOUT: %.loc6_21.1: type = splice_block %.loc6_21.5 [concrete = constants.%tuple.type.b6b] {
  240. // CHECK:STDOUT: %.loc6_16: %empty_struct_type = struct_literal ()
  241. // CHECK:STDOUT: %.loc6_20: %empty_struct_type = struct_literal ()
  242. // CHECK:STDOUT: %.loc6_21.2: %tuple.type.b6b = tuple_literal (%.loc6_16, %.loc6_20)
  243. // CHECK:STDOUT: %.loc6_21.3: type = converted %.loc6_16, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  244. // CHECK:STDOUT: %.loc6_21.4: type = converted %.loc6_20, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  245. // CHECK:STDOUT: %.loc6_21.5: type = converted %.loc6_21.2, constants.%tuple.type.b6b [concrete = constants.%tuple.type.b6b]
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT: %tuple: ref %tuple.type.b6b = bind_name tuple, %tuple.var
  248. // CHECK:STDOUT: name_binding_decl {
  249. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  250. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  251. // CHECK:STDOUT: %.loc7_20: %pattern_type.de4 = tuple_pattern (%x.patt, %y.patt) [concrete]
  252. // CHECK:STDOUT: %.var_patt: %pattern_type.de4 = var_pattern %.loc7_20 [concrete]
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT: %.var: ref %tuple.type.b6b = var %.var_patt
  255. // CHECK:STDOUT: %tuple.ref: ref %tuple.type.b6b = name_ref tuple, %tuple
  256. // CHECK:STDOUT: %tuple.elem0.loc7_24.1: ref %empty_struct_type = tuple_access %tuple.ref, element0
  257. // CHECK:STDOUT: %tuple.elem0.loc7_24.2: ref %empty_struct_type = tuple_access %.var, element0
  258. // CHECK:STDOUT: %.loc7_24.1: init %empty_struct_type = struct_init () to %tuple.elem0.loc7_24.2 [concrete = constants.%empty_struct]
  259. // CHECK:STDOUT: %.loc7_24.2: init %empty_struct_type = converted %tuple.elem0.loc7_24.1, %.loc7_24.1 [concrete = constants.%empty_struct]
  260. // CHECK:STDOUT: %tuple.elem1.loc7_24.1: ref %empty_struct_type = tuple_access %tuple.ref, element1
  261. // CHECK:STDOUT: %tuple.elem1.loc7_24.2: ref %empty_struct_type = tuple_access %.var, element1
  262. // CHECK:STDOUT: %.loc7_24.3: init %empty_struct_type = struct_init () to %tuple.elem1.loc7_24.2 [concrete = constants.%empty_struct]
  263. // CHECK:STDOUT: %.loc7_24.4: init %empty_struct_type = converted %tuple.elem1.loc7_24.1, %.loc7_24.3 [concrete = constants.%empty_struct]
  264. // CHECK:STDOUT: %.loc7_24.5: init %tuple.type.b6b = tuple_init (%.loc7_24.2, %.loc7_24.4) to %.var [concrete = constants.%tuple]
  265. // CHECK:STDOUT: %.loc7_3: init %tuple.type.b6b = converted %tuple.ref, %.loc7_24.5 [concrete = constants.%tuple]
  266. // CHECK:STDOUT: assign %.var, %.loc7_3
  267. // CHECK:STDOUT: %tuple.elem0.loc7_3: ref %empty_struct_type = tuple_access %.var, element0
  268. // CHECK:STDOUT: %tuple.elem1.loc7_3: ref %empty_struct_type = tuple_access %.var, element1
  269. // CHECK:STDOUT: %.loc7_12.1: type = splice_block %.loc7_12.3 [concrete = constants.%empty_struct_type] {
  270. // CHECK:STDOUT: %.loc7_12.2: %empty_struct_type = struct_literal ()
  271. // CHECK:STDOUT: %.loc7_12.3: type = converted %.loc7_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %x: ref %empty_struct_type = bind_name x, %tuple.elem0.loc7_3
  274. // CHECK:STDOUT: %.loc7_19.1: type = splice_block %.loc7_19.3 [concrete = constants.%empty_struct_type] {
  275. // CHECK:STDOUT: %.loc7_19.2: %empty_struct_type = struct_literal ()
  276. // CHECK:STDOUT: %.loc7_19.3: type = converted %.loc7_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT: %y: ref %empty_struct_type = bind_name y, %tuple.elem1.loc7_3
  279. // CHECK:STDOUT: %Op.bound.loc7: <bound method> = bound_method %.var, constants.%Op.973
  280. // CHECK:STDOUT: <elided>
  281. // CHECK:STDOUT: %bound_method.loc7: <bound method> = bound_method %.var, %Op.specific_fn.1
  282. // CHECK:STDOUT: %addr.loc7: %ptr.8fc = addr_of %.var
  283. // CHECK:STDOUT: %no_op.loc7: init %empty_tuple.type = call %bound_method.loc7(%addr.loc7)
  284. // CHECK:STDOUT: %Op.bound.loc6: <bound method> = bound_method %tuple.var, constants.%Op.973
  285. // CHECK:STDOUT: <elided>
  286. // CHECK:STDOUT: %bound_method.loc6: <bound method> = bound_method %tuple.var, %Op.specific_fn.2
  287. // CHECK:STDOUT: %addr.loc6: %ptr.8fc = addr_of %tuple.var
  288. // CHECK:STDOUT: %no_op.loc6: init %empty_tuple.type = call %bound_method.loc6(%addr.loc6)
  289. // CHECK:STDOUT: <elided>
  290. // CHECK:STDOUT: }
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: fn @G() {
  293. // CHECK:STDOUT: !entry:
  294. // CHECK:STDOUT: name_binding_decl {
  295. // CHECK:STDOUT: %tuple.patt: %pattern_type.de4 = binding_pattern tuple [concrete]
  296. // CHECK:STDOUT: }
  297. // CHECK:STDOUT: %.loc13_27: %empty_struct_type = struct_literal ()
  298. // CHECK:STDOUT: %.loc13_31: %empty_struct_type = struct_literal ()
  299. // CHECK:STDOUT: %.loc13_32.1: %tuple.type.b6b = tuple_literal (%.loc13_27, %.loc13_31)
  300. // CHECK:STDOUT: %.loc13_21.1: type = splice_block %.loc13_21.5 [concrete = constants.%tuple.type.b6b] {
  301. // CHECK:STDOUT: %.loc13_16: %empty_struct_type = struct_literal ()
  302. // CHECK:STDOUT: %.loc13_20: %empty_struct_type = struct_literal ()
  303. // CHECK:STDOUT: %.loc13_21.2: %tuple.type.b6b = tuple_literal (%.loc13_16, %.loc13_20)
  304. // CHECK:STDOUT: %.loc13_21.3: type = converted %.loc13_16, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  305. // CHECK:STDOUT: %.loc13_21.4: type = converted %.loc13_20, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  306. // CHECK:STDOUT: %.loc13_21.5: type = converted %.loc13_21.2, constants.%tuple.type.b6b [concrete = constants.%tuple.type.b6b]
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT: %empty_struct.loc13_27: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  309. // CHECK:STDOUT: %.loc13_32.2: %empty_struct_type = converted %.loc13_27, %empty_struct.loc13_27 [concrete = constants.%empty_struct]
  310. // CHECK:STDOUT: %empty_struct.loc13_31: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  311. // CHECK:STDOUT: %.loc13_32.3: %empty_struct_type = converted %.loc13_31, %empty_struct.loc13_31 [concrete = constants.%empty_struct]
  312. // CHECK:STDOUT: %tuple.loc13_32: %tuple.type.b6b = tuple_value (%.loc13_32.2, %.loc13_32.3) [concrete = constants.%tuple]
  313. // CHECK:STDOUT: %.loc13_32.4: %tuple.type.b6b = converted %.loc13_32.1, %tuple.loc13_32 [concrete = constants.%tuple]
  314. // CHECK:STDOUT: %tuple.loc13_7: %tuple.type.b6b = bind_name tuple, %.loc13_32.4
  315. // CHECK:STDOUT: name_binding_decl {
  316. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  317. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  318. // CHECK:STDOUT: %.loc14_20: %pattern_type.de4 = tuple_pattern (%x.patt, %y.patt) [concrete]
  319. // CHECK:STDOUT: %.var_patt: %pattern_type.de4 = var_pattern %.loc14_20 [concrete]
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT: %.var: ref %tuple.type.b6b = var %.var_patt
  322. // CHECK:STDOUT: %tuple.ref: %tuple.type.b6b = name_ref tuple, %tuple.loc13_7
  323. // CHECK:STDOUT: %tuple.elem0.loc14_24.1: %empty_struct_type = tuple_access %tuple.ref, element0
  324. // CHECK:STDOUT: %tuple.elem0.loc14_24.2: ref %empty_struct_type = tuple_access %.var, element0
  325. // CHECK:STDOUT: %.loc14_24.1: init %empty_struct_type = struct_init () to %tuple.elem0.loc14_24.2 [concrete = constants.%empty_struct]
  326. // CHECK:STDOUT: %.loc14_24.2: init %empty_struct_type = converted %tuple.elem0.loc14_24.1, %.loc14_24.1 [concrete = constants.%empty_struct]
  327. // CHECK:STDOUT: %tuple.elem1.loc14_24.1: %empty_struct_type = tuple_access %tuple.ref, element1
  328. // CHECK:STDOUT: %tuple.elem1.loc14_24.2: ref %empty_struct_type = tuple_access %.var, element1
  329. // CHECK:STDOUT: %.loc14_24.3: init %empty_struct_type = struct_init () to %tuple.elem1.loc14_24.2 [concrete = constants.%empty_struct]
  330. // CHECK:STDOUT: %.loc14_24.4: init %empty_struct_type = converted %tuple.elem1.loc14_24.1, %.loc14_24.3 [concrete = constants.%empty_struct]
  331. // CHECK:STDOUT: %.loc14_24.5: init %tuple.type.b6b = tuple_init (%.loc14_24.2, %.loc14_24.4) to %.var [concrete = constants.%tuple]
  332. // CHECK:STDOUT: %.loc14_3: init %tuple.type.b6b = converted %tuple.ref, %.loc14_24.5 [concrete = constants.%tuple]
  333. // CHECK:STDOUT: assign %.var, %.loc14_3
  334. // CHECK:STDOUT: %tuple.elem0.loc14_3: ref %empty_struct_type = tuple_access %.var, element0
  335. // CHECK:STDOUT: %tuple.elem1.loc14_3: ref %empty_struct_type = tuple_access %.var, element1
  336. // CHECK:STDOUT: %.loc14_12.1: type = splice_block %.loc14_12.3 [concrete = constants.%empty_struct_type] {
  337. // CHECK:STDOUT: %.loc14_12.2: %empty_struct_type = struct_literal ()
  338. // CHECK:STDOUT: %.loc14_12.3: type = converted %.loc14_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  339. // CHECK:STDOUT: }
  340. // CHECK:STDOUT: %x: ref %empty_struct_type = bind_name x, %tuple.elem0.loc14_3
  341. // CHECK:STDOUT: %.loc14_19.1: type = splice_block %.loc14_19.3 [concrete = constants.%empty_struct_type] {
  342. // CHECK:STDOUT: %.loc14_19.2: %empty_struct_type = struct_literal ()
  343. // CHECK:STDOUT: %.loc14_19.3: type = converted %.loc14_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  344. // CHECK:STDOUT: }
  345. // CHECK:STDOUT: %y: ref %empty_struct_type = bind_name y, %tuple.elem1.loc14_3
  346. // CHECK:STDOUT: %Op.bound: <bound method> = bound_method %.var, constants.%Op.973
  347. // CHECK:STDOUT: <elided>
  348. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.var, %Op.specific_fn
  349. // CHECK:STDOUT: %addr: %ptr.8fc = addr_of %.var
  350. // CHECK:STDOUT: %no_op: init %empty_tuple.type = call %bound_method(%addr)
  351. // CHECK:STDOUT: <elided>
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: fn @H() {
  355. // CHECK:STDOUT: !entry:
  356. // CHECK:STDOUT: name_binding_decl {
  357. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  358. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  359. // CHECK:STDOUT: %.loc22_20: %pattern_type.de4 = tuple_pattern (%x.patt, %y.patt) [concrete]
  360. // CHECK:STDOUT: %.var_patt: %pattern_type.de4 = var_pattern %.loc22_20 [concrete]
  361. // CHECK:STDOUT: }
  362. // CHECK:STDOUT: %.var: ref %tuple.type.b6b = var %.var_patt
  363. // CHECK:STDOUT: %MakeTuple.ref: %MakeTuple.type = name_ref MakeTuple, file.%MakeTuple.decl [concrete = constants.%MakeTuple]
  364. // CHECK:STDOUT: %.loc22_3: ref %tuple.type.b6b = splice_block %.var {}
  365. // CHECK:STDOUT: %MakeTuple.call: init %tuple.type.b6b = call %MakeTuple.ref() to %.loc22_3
  366. // CHECK:STDOUT: assign %.var, %MakeTuple.call
  367. // CHECK:STDOUT: %tuple.elem0: ref %empty_struct_type = tuple_access %.var, element0
  368. // CHECK:STDOUT: %tuple.elem1: ref %empty_struct_type = tuple_access %.var, element1
  369. // CHECK:STDOUT: %.loc22_12.1: type = splice_block %.loc22_12.3 [concrete = constants.%empty_struct_type] {
  370. // CHECK:STDOUT: %.loc22_12.2: %empty_struct_type = struct_literal ()
  371. // CHECK:STDOUT: %.loc22_12.3: type = converted %.loc22_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  372. // CHECK:STDOUT: }
  373. // CHECK:STDOUT: %x: ref %empty_struct_type = bind_name x, %tuple.elem0
  374. // CHECK:STDOUT: %.loc22_19.1: type = splice_block %.loc22_19.3 [concrete = constants.%empty_struct_type] {
  375. // CHECK:STDOUT: %.loc22_19.2: %empty_struct_type = struct_literal ()
  376. // CHECK:STDOUT: %.loc22_19.3: type = converted %.loc22_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  377. // CHECK:STDOUT: }
  378. // CHECK:STDOUT: %y: ref %empty_struct_type = bind_name y, %tuple.elem1
  379. // CHECK:STDOUT: %Op.bound.loc22_3.1: <bound method> = bound_method %.loc22_3, constants.%Op.973
  380. // CHECK:STDOUT: <elided>
  381. // CHECK:STDOUT: %bound_method.loc22_3.1: <bound method> = bound_method %.loc22_3, %Op.specific_fn.1
  382. // CHECK:STDOUT: %addr.loc22_3.1: %ptr.8fc = addr_of %.loc22_3
  383. // CHECK:STDOUT: %no_op.loc22_3.1: init %empty_tuple.type = call %bound_method.loc22_3.1(%addr.loc22_3.1)
  384. // CHECK:STDOUT: %Op.bound.loc22_3.2: <bound method> = bound_method %.var, constants.%Op.973
  385. // CHECK:STDOUT: <elided>
  386. // CHECK:STDOUT: %bound_method.loc22_3.2: <bound method> = bound_method %.var, %Op.specific_fn.2
  387. // CHECK:STDOUT: %addr.loc22_3.2: %ptr.8fc = addr_of %.var
  388. // CHECK:STDOUT: %no_op.loc22_3.2: init %empty_tuple.type = call %bound_method.loc22_3.2(%addr.loc22_3.2)
  389. // CHECK:STDOUT: <elided>
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: --- nested.carbon
  393. // CHECK:STDOUT:
  394. // CHECK:STDOUT: constants {
  395. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  396. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  397. // CHECK:STDOUT: %tuple.type.b6b: type = tuple_type (%empty_struct_type, %empty_struct_type) [concrete]
  398. // CHECK:STDOUT: %pattern_type.de4: type = pattern_type %tuple.type.b6b [concrete]
  399. // CHECK:STDOUT: %tuple.type.6ca: type = tuple_type (%empty_struct_type, %tuple.type.b6b) [concrete]
  400. // CHECK:STDOUT: %pattern_type.361: type = pattern_type %tuple.type.6ca [concrete]
  401. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  402. // CHECK:STDOUT: }
  403. // CHECK:STDOUT:
  404. // CHECK:STDOUT: imports {
  405. // CHECK:STDOUT: }
  406. // CHECK:STDOUT:
  407. // CHECK:STDOUT: fn @F() {
  408. // CHECK:STDOUT: !entry:
  409. // CHECK:STDOUT: name_binding_decl {
  410. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  411. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  412. // CHECK:STDOUT: %z.patt: %pattern_type.a96 = binding_pattern z [concrete]
  413. // CHECK:STDOUT: %.loc6_28: %pattern_type.de4 = tuple_pattern (%y.patt, %z.patt) [concrete]
  414. // CHECK:STDOUT: %.loc6_29: %pattern_type.361 = tuple_pattern (%x.patt, %.loc6_28) [concrete]
  415. // CHECK:STDOUT: }
  416. // CHECK:STDOUT: %.loc6_35.1: %empty_struct_type = struct_literal ()
  417. // CHECK:STDOUT: %.loc6_40.1: %empty_struct_type = struct_literal ()
  418. // CHECK:STDOUT: %.loc6_44.1: %empty_struct_type = struct_literal ()
  419. // CHECK:STDOUT: %.loc6_45: %tuple.type.b6b = tuple_literal (%.loc6_40.1, %.loc6_44.1)
  420. // CHECK:STDOUT: %.loc6_46: %tuple.type.6ca = tuple_literal (%.loc6_35.1, %.loc6_45)
  421. // CHECK:STDOUT: %.loc6_12.1: type = splice_block %.loc6_12.3 [concrete = constants.%empty_struct_type] {
  422. // CHECK:STDOUT: %.loc6_12.2: %empty_struct_type = struct_literal ()
  423. // CHECK:STDOUT: %.loc6_12.3: type = converted %.loc6_12.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  424. // CHECK:STDOUT: }
  425. // CHECK:STDOUT: %empty_struct.loc6_35: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  426. // CHECK:STDOUT: %.loc6_35.2: %empty_struct_type = converted %.loc6_35.1, %empty_struct.loc6_35 [concrete = constants.%empty_struct]
  427. // CHECK:STDOUT: %x: %empty_struct_type = bind_name x, %.loc6_35.2
  428. // CHECK:STDOUT: %.loc6_20.1: type = splice_block %.loc6_20.3 [concrete = constants.%empty_struct_type] {
  429. // CHECK:STDOUT: %.loc6_20.2: %empty_struct_type = struct_literal ()
  430. // CHECK:STDOUT: %.loc6_20.3: type = converted %.loc6_20.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT: %empty_struct.loc6_40: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  433. // CHECK:STDOUT: %.loc6_40.2: %empty_struct_type = converted %.loc6_40.1, %empty_struct.loc6_40 [concrete = constants.%empty_struct]
  434. // CHECK:STDOUT: %y: %empty_struct_type = bind_name y, %.loc6_40.2
  435. // CHECK:STDOUT: %.loc6_27.1: type = splice_block %.loc6_27.3 [concrete = constants.%empty_struct_type] {
  436. // CHECK:STDOUT: %.loc6_27.2: %empty_struct_type = struct_literal ()
  437. // CHECK:STDOUT: %.loc6_27.3: type = converted %.loc6_27.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT: %empty_struct.loc6_44: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  440. // CHECK:STDOUT: %.loc6_44.2: %empty_struct_type = converted %.loc6_44.1, %empty_struct.loc6_44 [concrete = constants.%empty_struct]
  441. // CHECK:STDOUT: %z: %empty_struct_type = bind_name z, %.loc6_44.2
  442. // CHECK:STDOUT: <elided>
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT:
  445. // CHECK:STDOUT: --- package_scope.carbon
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: constants {
  448. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  449. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  450. // CHECK:STDOUT: %tuple.type: type = tuple_type (%empty_struct_type, %empty_struct_type) [concrete]
  451. // CHECK:STDOUT: %pattern_type.de4: type = pattern_type %tuple.type [concrete]
  452. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  453. // CHECK:STDOUT: }
  454. // CHECK:STDOUT:
  455. // CHECK:STDOUT: imports {
  456. // CHECK:STDOUT: }
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: file {
  459. // CHECK:STDOUT: name_binding_decl {
  460. // CHECK:STDOUT: %x.patt: %pattern_type.a96 = binding_pattern x [concrete]
  461. // CHECK:STDOUT: %y.patt: %pattern_type.a96 = binding_pattern y [concrete]
  462. // CHECK:STDOUT: %.loc5_18: %pattern_type.de4 = tuple_pattern (%x.patt, %y.patt) [concrete]
  463. // CHECK:STDOUT: }
  464. // CHECK:STDOUT: %.loc5_10.1: type = splice_block %.loc5_10.3 [concrete = constants.%empty_struct_type] {
  465. // CHECK:STDOUT: %.loc5_10.2: %empty_struct_type = struct_literal ()
  466. // CHECK:STDOUT: %.loc5_10.3: type = converted %.loc5_10.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  467. // CHECK:STDOUT: }
  468. // CHECK:STDOUT: %empty_struct.loc5_24: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  469. // CHECK:STDOUT: %.loc5_24: %empty_struct_type = converted @__global_init.%.loc5_24, %empty_struct.loc5_24 [concrete = constants.%empty_struct]
  470. // CHECK:STDOUT: %x: %empty_struct_type = bind_name x, %.loc5_24
  471. // CHECK:STDOUT: %.loc5_17.1: type = splice_block %.loc5_17.3 [concrete = constants.%empty_struct_type] {
  472. // CHECK:STDOUT: %.loc5_17.2: %empty_struct_type = struct_literal ()
  473. // CHECK:STDOUT: %.loc5_17.3: type = converted %.loc5_17.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  474. // CHECK:STDOUT: }
  475. // CHECK:STDOUT: %empty_struct.loc5_28: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  476. // CHECK:STDOUT: %.loc5_28: %empty_struct_type = converted @__global_init.%.loc5_28, %empty_struct.loc5_28 [concrete = constants.%empty_struct]
  477. // CHECK:STDOUT: %y: %empty_struct_type = bind_name y, %.loc5_28
  478. // CHECK:STDOUT: }
  479. // CHECK:STDOUT:
  480. // CHECK:STDOUT: fn @__global_init() {
  481. // CHECK:STDOUT: !entry:
  482. // CHECK:STDOUT: %.loc5_24: %empty_struct_type = struct_literal ()
  483. // CHECK:STDOUT: %.loc5_28: %empty_struct_type = struct_literal ()
  484. // CHECK:STDOUT: %.loc5_29: %tuple.type = tuple_literal (%.loc5_24, %.loc5_28)
  485. // CHECK:STDOUT: <elided>
  486. // CHECK:STDOUT: }
  487. // CHECK:STDOUT: