nested_tuple_in_place.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/tuples/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/tuples/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: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: type = tuple_type (type, type, type) [template]
  24. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32, i32) [template]
  25. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  26. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  27. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  28. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  29. // CHECK:STDOUT: %.4: type = tuple_type (%.2, %.2) [template]
  30. // CHECK:STDOUT: %.5: type = tuple_type (%.3, %.3) [template]
  31. // CHECK:STDOUT: %.6: type = ptr_type %.3 [template]
  32. // CHECK:STDOUT: %.7: type = tuple_type (%.6, %.6) [template]
  33. // CHECK:STDOUT: %.8: type = ptr_type %.7 [template]
  34. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  35. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  36. // CHECK:STDOUT: %.9: type = tuple_type (type, %.2, type) [template]
  37. // CHECK:STDOUT: %.10: type = tuple_type (i32, %.3, i32) [template]
  38. // CHECK:STDOUT: %.11: type = tuple_type (i32, %.6, i32) [template]
  39. // CHECK:STDOUT: %.12: type = ptr_type %.11 [template]
  40. // CHECK:STDOUT: %.13: i32 = int_literal 1 [template]
  41. // CHECK:STDOUT: %.14: i32 = int_literal 2 [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = %Core
  47. // CHECK:STDOUT: .F = %F.decl
  48. // CHECK:STDOUT: .G = %G.decl
  49. // CHECK:STDOUT: .H = %H.decl
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  52. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  53. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  54. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  55. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  56. // CHECK:STDOUT: %int.make_type_32.loc11_12: init type = call constants.%Int32() [template = i32]
  57. // CHECK:STDOUT: %int.make_type_32.loc11_17: init type = call constants.%Int32() [template = i32]
  58. // CHECK:STDOUT: %int.make_type_32.loc11_22: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc11_25.1: %.2 = tuple_literal (%int.make_type_32.loc11_12, %int.make_type_32.loc11_17, %int.make_type_32.loc11_22)
  60. // CHECK:STDOUT: %.loc11_25.2: type = value_of_initializer %int.make_type_32.loc11_12 [template = i32]
  61. // CHECK:STDOUT: %.loc11_25.3: type = converted %int.make_type_32.loc11_12, %.loc11_25.2 [template = i32]
  62. // CHECK:STDOUT: %.loc11_25.4: type = value_of_initializer %int.make_type_32.loc11_17 [template = i32]
  63. // CHECK:STDOUT: %.loc11_25.5: type = converted %int.make_type_32.loc11_17, %.loc11_25.4 [template = i32]
  64. // CHECK:STDOUT: %.loc11_25.6: type = value_of_initializer %int.make_type_32.loc11_22 [template = i32]
  65. // CHECK:STDOUT: %.loc11_25.7: type = converted %int.make_type_32.loc11_22, %.loc11_25.6 [template = i32]
  66. // CHECK:STDOUT: %.loc11_25.8: type = converted %.loc11_25.1, constants.%.3 [template = constants.%.3]
  67. // CHECK:STDOUT: @F.%return: ref %.3 = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {}
  70. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  71. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  72. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  73. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  74. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  75. // CHECK:STDOUT: %import_ref.9: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  76. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {}
  77. // CHECK:STDOUT: %import_ref.10: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  78. // CHECK:STDOUT: %import_ref.11: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  79. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  80. // CHECK:STDOUT: %import_ref.13: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  81. // CHECK:STDOUT: %import_ref.14: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @F() -> %.3;
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @G() {
  89. // CHECK:STDOUT: !entry:
  90. // CHECK:STDOUT: %int.make_type_32.loc14_12: init type = call constants.%Int32() [template = i32]
  91. // CHECK:STDOUT: %int.make_type_32.loc14_17: init type = call constants.%Int32() [template = i32]
  92. // CHECK:STDOUT: %int.make_type_32.loc14_22: init type = call constants.%Int32() [template = i32]
  93. // CHECK:STDOUT: %.loc14_25: %.2 = tuple_literal (%int.make_type_32.loc14_12, %int.make_type_32.loc14_17, %int.make_type_32.loc14_22)
  94. // CHECK:STDOUT: %int.make_type_32.loc14_29: init type = call constants.%Int32() [template = i32]
  95. // CHECK:STDOUT: %int.make_type_32.loc14_34: init type = call constants.%Int32() [template = i32]
  96. // CHECK:STDOUT: %int.make_type_32.loc14_39: init type = call constants.%Int32() [template = i32]
  97. // CHECK:STDOUT: %.loc14_42: %.2 = tuple_literal (%int.make_type_32.loc14_29, %int.make_type_32.loc14_34, %int.make_type_32.loc14_39)
  98. // CHECK:STDOUT: %.loc14_43.1: %.4 = tuple_literal (%.loc14_25, %.loc14_42)
  99. // CHECK:STDOUT: %.loc14_43.2: type = value_of_initializer %int.make_type_32.loc14_12 [template = i32]
  100. // CHECK:STDOUT: %.loc14_43.3: type = converted %int.make_type_32.loc14_12, %.loc14_43.2 [template = i32]
  101. // CHECK:STDOUT: %.loc14_43.4: type = value_of_initializer %int.make_type_32.loc14_17 [template = i32]
  102. // CHECK:STDOUT: %.loc14_43.5: type = converted %int.make_type_32.loc14_17, %.loc14_43.4 [template = i32]
  103. // CHECK:STDOUT: %.loc14_43.6: type = value_of_initializer %int.make_type_32.loc14_22 [template = i32]
  104. // CHECK:STDOUT: %.loc14_43.7: type = converted %int.make_type_32.loc14_22, %.loc14_43.6 [template = i32]
  105. // CHECK:STDOUT: %.loc14_43.8: type = converted %.loc14_25, constants.%.3 [template = constants.%.3]
  106. // CHECK:STDOUT: %.loc14_43.9: type = value_of_initializer %int.make_type_32.loc14_29 [template = i32]
  107. // CHECK:STDOUT: %.loc14_43.10: type = converted %int.make_type_32.loc14_29, %.loc14_43.9 [template = i32]
  108. // CHECK:STDOUT: %.loc14_43.11: type = value_of_initializer %int.make_type_32.loc14_34 [template = i32]
  109. // CHECK:STDOUT: %.loc14_43.12: type = converted %int.make_type_32.loc14_34, %.loc14_43.11 [template = i32]
  110. // CHECK:STDOUT: %.loc14_43.13: type = value_of_initializer %int.make_type_32.loc14_39 [template = i32]
  111. // CHECK:STDOUT: %.loc14_43.14: type = converted %int.make_type_32.loc14_39, %.loc14_43.13 [template = i32]
  112. // CHECK:STDOUT: %.loc14_43.15: type = converted %.loc14_42, constants.%.3 [template = constants.%.3]
  113. // CHECK:STDOUT: %.loc14_43.16: type = converted %.loc14_43.1, constants.%.5 [template = constants.%.5]
  114. // CHECK:STDOUT: %v.var: ref %.5 = var v
  115. // CHECK:STDOUT: %v: ref %.5 = bind_name v, %v.var
  116. // CHECK:STDOUT: %F.ref.loc14_48: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  117. // CHECK:STDOUT: %.loc14_56.1: ref %.3 = tuple_access %v.var, element0
  118. // CHECK:STDOUT: %F.call.loc14_49: init %.3 = call %F.ref.loc14_48() to %.loc14_56.1
  119. // CHECK:STDOUT: %F.ref.loc14_53: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  120. // CHECK:STDOUT: %.loc14_56.2: ref %.3 = tuple_access %v.var, element1
  121. // CHECK:STDOUT: %F.call.loc14_54: init %.3 = call %F.ref.loc14_53() to %.loc14_56.2
  122. // CHECK:STDOUT: %.loc14_56.3: %.5 = tuple_literal (%F.call.loc14_49, %F.call.loc14_54)
  123. // CHECK:STDOUT: %.loc14_56.4: init %.5 = tuple_init (%F.call.loc14_49, %F.call.loc14_54) to %v.var
  124. // CHECK:STDOUT: %.loc14_57: init %.5 = converted %.loc14_56.3, %.loc14_56.4
  125. // CHECK:STDOUT: assign %v.var, %.loc14_57
  126. // CHECK:STDOUT: return
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @H() {
  130. // CHECK:STDOUT: !entry:
  131. // CHECK:STDOUT: %int.make_type_32.loc18_11: init type = call constants.%Int32() [template = i32]
  132. // CHECK:STDOUT: %int.make_type_32.loc18_17: init type = call constants.%Int32() [template = i32]
  133. // CHECK:STDOUT: %int.make_type_32.loc18_22: init type = call constants.%Int32() [template = i32]
  134. // CHECK:STDOUT: %int.make_type_32.loc18_27: init type = call constants.%Int32() [template = i32]
  135. // CHECK:STDOUT: %.loc18_30: %.2 = tuple_literal (%int.make_type_32.loc18_17, %int.make_type_32.loc18_22, %int.make_type_32.loc18_27)
  136. // CHECK:STDOUT: %int.make_type_32.loc18_33: init type = call constants.%Int32() [template = i32]
  137. // CHECK:STDOUT: %.loc18_36.1: %.9 = tuple_literal (%int.make_type_32.loc18_11, %.loc18_30, %int.make_type_32.loc18_33)
  138. // CHECK:STDOUT: %.loc18_36.2: type = value_of_initializer %int.make_type_32.loc18_11 [template = i32]
  139. // CHECK:STDOUT: %.loc18_36.3: type = converted %int.make_type_32.loc18_11, %.loc18_36.2 [template = i32]
  140. // CHECK:STDOUT: %.loc18_36.4: type = value_of_initializer %int.make_type_32.loc18_17 [template = i32]
  141. // CHECK:STDOUT: %.loc18_36.5: type = converted %int.make_type_32.loc18_17, %.loc18_36.4 [template = i32]
  142. // CHECK:STDOUT: %.loc18_36.6: type = value_of_initializer %int.make_type_32.loc18_22 [template = i32]
  143. // CHECK:STDOUT: %.loc18_36.7: type = converted %int.make_type_32.loc18_22, %.loc18_36.6 [template = i32]
  144. // CHECK:STDOUT: %.loc18_36.8: type = value_of_initializer %int.make_type_32.loc18_27 [template = i32]
  145. // CHECK:STDOUT: %.loc18_36.9: type = converted %int.make_type_32.loc18_27, %.loc18_36.8 [template = i32]
  146. // CHECK:STDOUT: %.loc18_36.10: type = converted %.loc18_30, constants.%.3 [template = constants.%.3]
  147. // CHECK:STDOUT: %.loc18_36.11: type = value_of_initializer %int.make_type_32.loc18_33 [template = i32]
  148. // CHECK:STDOUT: %.loc18_36.12: type = converted %int.make_type_32.loc18_33, %.loc18_36.11 [template = i32]
  149. // CHECK:STDOUT: %.loc18_36.13: type = converted %.loc18_36.1, constants.%.10 [template = constants.%.10]
  150. // CHECK:STDOUT: %v.var: ref %.10 = var v
  151. // CHECK:STDOUT: %v: ref %.10 = bind_name v, %v.var
  152. // CHECK:STDOUT: %.loc18_41: i32 = int_literal 1 [template = constants.%.13]
  153. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  154. // CHECK:STDOUT: %.loc18_50.1: ref %.3 = tuple_access %v.var, element1
  155. // CHECK:STDOUT: %F.call: init %.3 = call %F.ref() to %.loc18_50.1
  156. // CHECK:STDOUT: %.loc18_49: i32 = int_literal 2 [template = constants.%.14]
  157. // CHECK:STDOUT: %.loc18_50.2: %.10 = tuple_literal (%.loc18_41, %F.call, %.loc18_49)
  158. // CHECK:STDOUT: %.loc18_50.3: ref i32 = tuple_access %v.var, element0
  159. // CHECK:STDOUT: %.loc18_50.4: init i32 = initialize_from %.loc18_41 to %.loc18_50.3 [template = constants.%.13]
  160. // CHECK:STDOUT: %.loc18_50.5: ref i32 = tuple_access %v.var, element2
  161. // CHECK:STDOUT: %.loc18_50.6: init i32 = initialize_from %.loc18_49 to %.loc18_50.5 [template = constants.%.14]
  162. // CHECK:STDOUT: %.loc18_50.7: init %.10 = tuple_init (%.loc18_50.4, %F.call, %.loc18_50.6) to %v.var
  163. // CHECK:STDOUT: %.loc18_51: init %.10 = converted %.loc18_50.2, %.loc18_50.7
  164. // CHECK:STDOUT: assign %v.var, %.loc18_51
  165. // CHECK:STDOUT: return
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: