nested_tuple_in_place.carbon 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/tuple/nested_tuple_in_place.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/nested_tuple_in_place.carbon
  10. fn F() -> (i32, i32, i32);
  11. fn G() {
  12. var v: ((i32, i32, i32), (i32, i32, i32)) = (F(), F());
  13. }
  14. fn H() {
  15. var v: (i32, (i32, i32, i32), i32) = (1, F(), 2);
  16. }
  17. // CHECK:STDOUT: --- nested_tuple_in_place.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  21. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  22. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  23. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  24. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type, type, type) [template]
  25. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (%i32, %i32, %i32) [template]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  28. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  29. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  30. // CHECK:STDOUT: %tuple.type.3: type = tuple_type (%tuple.type.1, %tuple.type.1) [template]
  31. // CHECK:STDOUT: %tuple.type.4: type = tuple_type (%tuple.type.2, %tuple.type.2) [template]
  32. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  33. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  34. // CHECK:STDOUT: %tuple.type.6: type = tuple_type (type, %tuple.type.1, type) [template]
  35. // CHECK:STDOUT: %tuple.type.7: type = tuple_type (%i32, %tuple.type.2, %i32) [template]
  36. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 1 [template]
  37. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 2 [template]
  38. // CHECK:STDOUT: %tuple.type.9: type = tuple_type (Core.IntLiteral, %tuple.type.2, Core.IntLiteral) [template]
  39. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  40. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  41. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  42. // CHECK:STDOUT: %.26: <witness> = interface_witness (%Convert.14) [template]
  43. // CHECK:STDOUT: %.27: <bound method> = bound_method %.5, %Convert.14 [template]
  44. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  45. // CHECK:STDOUT: %.29: %i32 = int_value 1 [template]
  46. // CHECK:STDOUT: %.30: <bound method> = bound_method %.6, %Convert.14 [template]
  47. // CHECK:STDOUT: %.31: <specific function> = specific_function %.30, @Convert.2(%.1) [template]
  48. // CHECK:STDOUT: %.32: %i32 = int_value 2 [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  53. // CHECK:STDOUT: .Int = %import_ref.1
  54. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  55. // CHECK:STDOUT: import Core//prelude
  56. // CHECK:STDOUT: import Core//prelude/...
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: file {
  61. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  62. // CHECK:STDOUT: .Core = imports.%Core
  63. // CHECK:STDOUT: .F = %F.decl
  64. // CHECK:STDOUT: .G = %G.decl
  65. // CHECK:STDOUT: .H = %H.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  69. // CHECK:STDOUT: %return.patt: %tuple.type.2 = return_slot_pattern
  70. // CHECK:STDOUT: %return.param_patt: %tuple.type.2 = out_param_pattern %return.patt, runtime_param0
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %.loc11_12: Core.IntLiteral = int_value 32 [template = constants.%.1]
  73. // CHECK:STDOUT: %int.make_type_signed.loc11_12: init type = call constants.%Int(%.loc11_12) [template = constants.%i32]
  74. // CHECK:STDOUT: %.loc11_17: Core.IntLiteral = int_value 32 [template = constants.%.1]
  75. // CHECK:STDOUT: %int.make_type_signed.loc11_17: init type = call constants.%Int(%.loc11_17) [template = constants.%i32]
  76. // CHECK:STDOUT: %.loc11_22: Core.IntLiteral = int_value 32 [template = constants.%.1]
  77. // CHECK:STDOUT: %int.make_type_signed.loc11_22: init type = call constants.%Int(%.loc11_22) [template = constants.%i32]
  78. // CHECK:STDOUT: %.loc11_25.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc11_12, %int.make_type_signed.loc11_17, %int.make_type_signed.loc11_22)
  79. // CHECK:STDOUT: %.loc11_25.2: type = value_of_initializer %int.make_type_signed.loc11_12 [template = constants.%i32]
  80. // CHECK:STDOUT: %.loc11_25.3: type = converted %int.make_type_signed.loc11_12, %.loc11_25.2 [template = constants.%i32]
  81. // CHECK:STDOUT: %.loc11_25.4: type = value_of_initializer %int.make_type_signed.loc11_17 [template = constants.%i32]
  82. // CHECK:STDOUT: %.loc11_25.5: type = converted %int.make_type_signed.loc11_17, %.loc11_25.4 [template = constants.%i32]
  83. // CHECK:STDOUT: %.loc11_25.6: type = value_of_initializer %int.make_type_signed.loc11_22 [template = constants.%i32]
  84. // CHECK:STDOUT: %.loc11_25.7: type = converted %int.make_type_signed.loc11_22, %.loc11_25.6 [template = constants.%i32]
  85. // CHECK:STDOUT: %.loc11_25.8: type = converted %.loc11_25.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  86. // CHECK:STDOUT: %return.param: ref %tuple.type.2 = out_param runtime_param0
  87. // CHECK:STDOUT: %return: ref %tuple.type.2 = return_slot %return.param
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  90. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @F() -> %tuple.type.2;
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @G() {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: %.loc14_12: Core.IntLiteral = int_value 32 [template = constants.%.1]
  98. // CHECK:STDOUT: %int.make_type_signed.loc14_12: init type = call constants.%Int(%.loc14_12) [template = constants.%i32]
  99. // CHECK:STDOUT: %.loc14_17: Core.IntLiteral = int_value 32 [template = constants.%.1]
  100. // CHECK:STDOUT: %int.make_type_signed.loc14_17: init type = call constants.%Int(%.loc14_17) [template = constants.%i32]
  101. // CHECK:STDOUT: %.loc14_22: Core.IntLiteral = int_value 32 [template = constants.%.1]
  102. // CHECK:STDOUT: %int.make_type_signed.loc14_22: init type = call constants.%Int(%.loc14_22) [template = constants.%i32]
  103. // CHECK:STDOUT: %.loc14_25: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc14_12, %int.make_type_signed.loc14_17, %int.make_type_signed.loc14_22)
  104. // CHECK:STDOUT: %.loc14_29: Core.IntLiteral = int_value 32 [template = constants.%.1]
  105. // CHECK:STDOUT: %int.make_type_signed.loc14_29: init type = call constants.%Int(%.loc14_29) [template = constants.%i32]
  106. // CHECK:STDOUT: %.loc14_34: Core.IntLiteral = int_value 32 [template = constants.%.1]
  107. // CHECK:STDOUT: %int.make_type_signed.loc14_34: init type = call constants.%Int(%.loc14_34) [template = constants.%i32]
  108. // CHECK:STDOUT: %.loc14_39: Core.IntLiteral = int_value 32 [template = constants.%.1]
  109. // CHECK:STDOUT: %int.make_type_signed.loc14_39: init type = call constants.%Int(%.loc14_39) [template = constants.%i32]
  110. // CHECK:STDOUT: %.loc14_42: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc14_29, %int.make_type_signed.loc14_34, %int.make_type_signed.loc14_39)
  111. // CHECK:STDOUT: %.loc14_43.1: %tuple.type.3 = tuple_literal (%.loc14_25, %.loc14_42)
  112. // CHECK:STDOUT: %.loc14_43.2: type = value_of_initializer %int.make_type_signed.loc14_12 [template = constants.%i32]
  113. // CHECK:STDOUT: %.loc14_43.3: type = converted %int.make_type_signed.loc14_12, %.loc14_43.2 [template = constants.%i32]
  114. // CHECK:STDOUT: %.loc14_43.4: type = value_of_initializer %int.make_type_signed.loc14_17 [template = constants.%i32]
  115. // CHECK:STDOUT: %.loc14_43.5: type = converted %int.make_type_signed.loc14_17, %.loc14_43.4 [template = constants.%i32]
  116. // CHECK:STDOUT: %.loc14_43.6: type = value_of_initializer %int.make_type_signed.loc14_22 [template = constants.%i32]
  117. // CHECK:STDOUT: %.loc14_43.7: type = converted %int.make_type_signed.loc14_22, %.loc14_43.6 [template = constants.%i32]
  118. // CHECK:STDOUT: %.loc14_43.8: type = converted %.loc14_25, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  119. // CHECK:STDOUT: %.loc14_43.9: type = value_of_initializer %int.make_type_signed.loc14_29 [template = constants.%i32]
  120. // CHECK:STDOUT: %.loc14_43.10: type = converted %int.make_type_signed.loc14_29, %.loc14_43.9 [template = constants.%i32]
  121. // CHECK:STDOUT: %.loc14_43.11: type = value_of_initializer %int.make_type_signed.loc14_34 [template = constants.%i32]
  122. // CHECK:STDOUT: %.loc14_43.12: type = converted %int.make_type_signed.loc14_34, %.loc14_43.11 [template = constants.%i32]
  123. // CHECK:STDOUT: %.loc14_43.13: type = value_of_initializer %int.make_type_signed.loc14_39 [template = constants.%i32]
  124. // CHECK:STDOUT: %.loc14_43.14: type = converted %int.make_type_signed.loc14_39, %.loc14_43.13 [template = constants.%i32]
  125. // CHECK:STDOUT: %.loc14_43.15: type = converted %.loc14_42, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  126. // CHECK:STDOUT: %.loc14_43.16: type = converted %.loc14_43.1, constants.%tuple.type.4 [template = constants.%tuple.type.4]
  127. // CHECK:STDOUT: %v.var: ref %tuple.type.4 = var v
  128. // CHECK:STDOUT: %v: ref %tuple.type.4 = bind_name v, %v.var
  129. // CHECK:STDOUT: %F.ref.loc14_48: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  130. // CHECK:STDOUT: %.loc14_56.1: ref %tuple.type.2 = tuple_access %v.var, element0
  131. // CHECK:STDOUT: %F.call.loc14_49: init %tuple.type.2 = call %F.ref.loc14_48() to %.loc14_56.1
  132. // CHECK:STDOUT: %F.ref.loc14_53: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  133. // CHECK:STDOUT: %.loc14_56.2: ref %tuple.type.2 = tuple_access %v.var, element1
  134. // CHECK:STDOUT: %F.call.loc14_54: init %tuple.type.2 = call %F.ref.loc14_53() to %.loc14_56.2
  135. // CHECK:STDOUT: %.loc14_56.3: %tuple.type.4 = tuple_literal (%F.call.loc14_49, %F.call.loc14_54)
  136. // CHECK:STDOUT: %.loc14_56.4: init %tuple.type.4 = tuple_init (%F.call.loc14_49, %F.call.loc14_54) to %v.var
  137. // CHECK:STDOUT: %.loc14_57: init %tuple.type.4 = converted %.loc14_56.3, %.loc14_56.4
  138. // CHECK:STDOUT: assign %v.var, %.loc14_57
  139. // CHECK:STDOUT: return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: fn @H() {
  143. // CHECK:STDOUT: !entry:
  144. // CHECK:STDOUT: %.loc18_11: Core.IntLiteral = int_value 32 [template = constants.%.1]
  145. // CHECK:STDOUT: %int.make_type_signed.loc18_11: init type = call constants.%Int(%.loc18_11) [template = constants.%i32]
  146. // CHECK:STDOUT: %.loc18_17: Core.IntLiteral = int_value 32 [template = constants.%.1]
  147. // CHECK:STDOUT: %int.make_type_signed.loc18_17: init type = call constants.%Int(%.loc18_17) [template = constants.%i32]
  148. // CHECK:STDOUT: %.loc18_22: Core.IntLiteral = int_value 32 [template = constants.%.1]
  149. // CHECK:STDOUT: %int.make_type_signed.loc18_22: init type = call constants.%Int(%.loc18_22) [template = constants.%i32]
  150. // CHECK:STDOUT: %.loc18_27: Core.IntLiteral = int_value 32 [template = constants.%.1]
  151. // CHECK:STDOUT: %int.make_type_signed.loc18_27: init type = call constants.%Int(%.loc18_27) [template = constants.%i32]
  152. // CHECK:STDOUT: %.loc18_30: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc18_17, %int.make_type_signed.loc18_22, %int.make_type_signed.loc18_27)
  153. // CHECK:STDOUT: %.loc18_33: Core.IntLiteral = int_value 32 [template = constants.%.1]
  154. // CHECK:STDOUT: %int.make_type_signed.loc18_33: init type = call constants.%Int(%.loc18_33) [template = constants.%i32]
  155. // CHECK:STDOUT: %.loc18_36.1: %tuple.type.6 = tuple_literal (%int.make_type_signed.loc18_11, %.loc18_30, %int.make_type_signed.loc18_33)
  156. // CHECK:STDOUT: %.loc18_36.2: type = value_of_initializer %int.make_type_signed.loc18_11 [template = constants.%i32]
  157. // CHECK:STDOUT: %.loc18_36.3: type = converted %int.make_type_signed.loc18_11, %.loc18_36.2 [template = constants.%i32]
  158. // CHECK:STDOUT: %.loc18_36.4: type = value_of_initializer %int.make_type_signed.loc18_17 [template = constants.%i32]
  159. // CHECK:STDOUT: %.loc18_36.5: type = converted %int.make_type_signed.loc18_17, %.loc18_36.4 [template = constants.%i32]
  160. // CHECK:STDOUT: %.loc18_36.6: type = value_of_initializer %int.make_type_signed.loc18_22 [template = constants.%i32]
  161. // CHECK:STDOUT: %.loc18_36.7: type = converted %int.make_type_signed.loc18_22, %.loc18_36.6 [template = constants.%i32]
  162. // CHECK:STDOUT: %.loc18_36.8: type = value_of_initializer %int.make_type_signed.loc18_27 [template = constants.%i32]
  163. // CHECK:STDOUT: %.loc18_36.9: type = converted %int.make_type_signed.loc18_27, %.loc18_36.8 [template = constants.%i32]
  164. // CHECK:STDOUT: %.loc18_36.10: type = converted %.loc18_30, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  165. // CHECK:STDOUT: %.loc18_36.11: type = value_of_initializer %int.make_type_signed.loc18_33 [template = constants.%i32]
  166. // CHECK:STDOUT: %.loc18_36.12: type = converted %int.make_type_signed.loc18_33, %.loc18_36.11 [template = constants.%i32]
  167. // CHECK:STDOUT: %.loc18_36.13: type = converted %.loc18_36.1, constants.%tuple.type.7 [template = constants.%tuple.type.7]
  168. // CHECK:STDOUT: %v.var: ref %tuple.type.7 = var v
  169. // CHECK:STDOUT: %v: ref %tuple.type.7 = bind_name v, %v.var
  170. // CHECK:STDOUT: %.loc18_41: Core.IntLiteral = int_value 1 [template = constants.%.5]
  171. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  172. // CHECK:STDOUT: %.loc18_50.1: ref %tuple.type.2 = tuple_access %v.var, element1
  173. // CHECK:STDOUT: %F.call: init %tuple.type.2 = call %F.ref() to %.loc18_50.1
  174. // CHECK:STDOUT: %.loc18_49: Core.IntLiteral = int_value 2 [template = constants.%.6]
  175. // CHECK:STDOUT: %.loc18_50.2: %tuple.type.9 = tuple_literal (%.loc18_41, %F.call, %.loc18_49)
  176. // CHECK:STDOUT: %.loc18_50.3: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  177. // CHECK:STDOUT: %.loc18_50.4: <bound method> = bound_method %.loc18_41, %.loc18_50.3 [template = constants.%.27]
  178. // CHECK:STDOUT: %.loc18_50.5: <specific function> = specific_function %.loc18_50.4, @Convert.2(constants.%.1) [template = constants.%.28]
  179. // CHECK:STDOUT: %int.convert_checked.loc18_50.1: init %i32 = call %.loc18_50.5(%.loc18_41) [template = constants.%.29]
  180. // CHECK:STDOUT: %.loc18_50.6: init %i32 = converted %.loc18_41, %int.convert_checked.loc18_50.1 [template = constants.%.29]
  181. // CHECK:STDOUT: %.loc18_50.7: ref %i32 = tuple_access %v.var, element0
  182. // CHECK:STDOUT: %.loc18_50.8: init %i32 = initialize_from %.loc18_50.6 to %.loc18_50.7 [template = constants.%.29]
  183. // CHECK:STDOUT: %.loc18_50.9: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  184. // CHECK:STDOUT: %.loc18_50.10: <bound method> = bound_method %.loc18_49, %.loc18_50.9 [template = constants.%.30]
  185. // CHECK:STDOUT: %.loc18_50.11: <specific function> = specific_function %.loc18_50.10, @Convert.2(constants.%.1) [template = constants.%.31]
  186. // CHECK:STDOUT: %int.convert_checked.loc18_50.2: init %i32 = call %.loc18_50.11(%.loc18_49) [template = constants.%.32]
  187. // CHECK:STDOUT: %.loc18_50.12: init %i32 = converted %.loc18_49, %int.convert_checked.loc18_50.2 [template = constants.%.32]
  188. // CHECK:STDOUT: %.loc18_50.13: ref %i32 = tuple_access %v.var, element2
  189. // CHECK:STDOUT: %.loc18_50.14: init %i32 = initialize_from %.loc18_50.12 to %.loc18_50.13 [template = constants.%.32]
  190. // CHECK:STDOUT: %.loc18_50.15: init %tuple.type.7 = tuple_init (%.loc18_50.8, %F.call, %.loc18_50.14) to %v.var
  191. // CHECK:STDOUT: %.loc18_51: init %tuple.type.7 = converted %.loc18_50.2, %.loc18_50.15
  192. // CHECK:STDOUT: assign %v.var, %.loc18_51
  193. // CHECK:STDOUT: return
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: