tuple.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/min_prelude/destroy.carbon
  6. // EXTRA-ARGS: --custom-core
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/as/min_prelude/tuple.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/min_prelude/tuple.carbon
  13. // --- test.carbon
  14. library "[[@TEST_NAME]]";
  15. class X {
  16. // ...
  17. }
  18. fn Make() -> X;
  19. fn Let() {
  20. // This should create value bindings for both tuple elements.
  21. let a: (X, X) = (Make(), Make()) as (X, X);
  22. }
  23. fn Var() {
  24. // This should initialize both tuple elements in place.
  25. var b: (X, X) = (Make(), Make()) as (X, X);
  26. }
  27. // CHECK:STDOUT: --- test.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  31. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  32. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  33. // CHECK:STDOUT: %pattern_type.019: type = pattern_type %X [concrete]
  34. // CHECK:STDOUT: %Make.type: type = fn_type @Make [concrete]
  35. // CHECK:STDOUT: %Make: %Make.type = struct_value () [concrete]
  36. // CHECK:STDOUT: %Let.type: type = fn_type @Let [concrete]
  37. // CHECK:STDOUT: %Let: %Let.type = struct_value () [concrete]
  38. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
  39. // CHECK:STDOUT: %tuple.type.b67: type = tuple_type (%X, %X) [concrete]
  40. // CHECK:STDOUT: %pattern_type.bb7: type = pattern_type %tuple.type.b67 [concrete]
  41. // CHECK:STDOUT: %Var.type: type = fn_type @Var [concrete]
  42. // CHECK:STDOUT: %Var: %Var.type = struct_value () [concrete]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  47. // CHECK:STDOUT: import Core//prelude
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .X = %X.decl
  55. // CHECK:STDOUT: .Make = %Make.decl
  56. // CHECK:STDOUT: .Let = %Let.decl
  57. // CHECK:STDOUT: .Var = %Var.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  61. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [concrete = constants.%Make] {
  62. // CHECK:STDOUT: %return.patt: %pattern_type.019 = return_slot_pattern [concrete]
  63. // CHECK:STDOUT: %return.param_patt: %pattern_type.019 = out_param_pattern %return.patt, call_param0 [concrete]
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [concrete = constants.%X]
  66. // CHECK:STDOUT: %return.param: ref %X = out_param call_param0
  67. // CHECK:STDOUT: %return: ref %X = return_slot %return.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Let.decl: %Let.type = fn_decl @Let [concrete = constants.%Let] {} {}
  70. // CHECK:STDOUT: %Var.decl: %Var.type = fn_decl @Var [concrete = constants.%Var] {} {}
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: class @X {
  74. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  75. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  76. // CHECK:STDOUT: complete_type_witness = %complete_type
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !members:
  79. // CHECK:STDOUT: .Self = constants.%X
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @Make() -> %return.param: %X;
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @Let() {
  85. // CHECK:STDOUT: !entry:
  86. // CHECK:STDOUT: name_binding_decl {
  87. // CHECK:STDOUT: %a.patt: %pattern_type.bb7 = binding_pattern a [concrete]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %Make.ref.loc12_20: %Make.type = name_ref Make, file.%Make.decl [concrete = constants.%Make]
  90. // CHECK:STDOUT: %.loc12_25.1: ref %X = temporary_storage
  91. // CHECK:STDOUT: %Make.call.loc12_25: init %X = call %Make.ref.loc12_20() to %.loc12_25.1
  92. // CHECK:STDOUT: %Make.ref.loc12_28: %Make.type = name_ref Make, file.%Make.decl [concrete = constants.%Make]
  93. // CHECK:STDOUT: %.loc12_33.1: ref %X = temporary_storage
  94. // CHECK:STDOUT: %Make.call.loc12_33: init %X = call %Make.ref.loc12_28() to %.loc12_33.1
  95. // CHECK:STDOUT: %.loc12_34.1: %tuple.type.b67 = tuple_literal (%Make.call.loc12_25, %Make.call.loc12_33)
  96. // CHECK:STDOUT: %X.ref.loc12_40: type = name_ref X, file.%X.decl [concrete = constants.%X]
  97. // CHECK:STDOUT: %X.ref.loc12_43: type = name_ref X, file.%X.decl [concrete = constants.%X]
  98. // CHECK:STDOUT: %.loc12_44.1: %tuple.type.24b = tuple_literal (%X.ref.loc12_40, %X.ref.loc12_43)
  99. // CHECK:STDOUT: %.loc12_44.2: type = converted %.loc12_44.1, constants.%tuple.type.b67 [concrete = constants.%tuple.type.b67]
  100. // CHECK:STDOUT: %.loc12_15.1: type = splice_block %.loc12_15.3 [concrete = constants.%tuple.type.b67] {
  101. // CHECK:STDOUT: %X.ref.loc12_11: type = name_ref X, file.%X.decl [concrete = constants.%X]
  102. // CHECK:STDOUT: %X.ref.loc12_14: type = name_ref X, file.%X.decl [concrete = constants.%X]
  103. // CHECK:STDOUT: %.loc12_15.2: %tuple.type.24b = tuple_literal (%X.ref.loc12_11, %X.ref.loc12_14)
  104. // CHECK:STDOUT: %.loc12_15.3: type = converted %.loc12_15.2, constants.%tuple.type.b67 [concrete = constants.%tuple.type.b67]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %.loc12_25.2: ref %X = temporary %.loc12_25.1, %Make.call.loc12_25
  107. // CHECK:STDOUT: %.loc12_25.3: %X = bind_value %.loc12_25.2
  108. // CHECK:STDOUT: %.loc12_33.2: ref %X = temporary %.loc12_33.1, %Make.call.loc12_33
  109. // CHECK:STDOUT: %.loc12_33.3: %X = bind_value %.loc12_33.2
  110. // CHECK:STDOUT: %tuple: %tuple.type.b67 = tuple_value (%.loc12_25.3, %.loc12_33.3)
  111. // CHECK:STDOUT: %.loc12_34.2: %tuple.type.b67 = converted %.loc12_34.1, %tuple
  112. // CHECK:STDOUT: %a: %tuple.type.b67 = bind_name a, %.loc12_34.2
  113. // CHECK:STDOUT: return
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @Var() {
  117. // CHECK:STDOUT: !entry:
  118. // CHECK:STDOUT: name_binding_decl {
  119. // CHECK:STDOUT: %b.patt: %pattern_type.bb7 = binding_pattern b [concrete]
  120. // CHECK:STDOUT: %.loc17_3.1: %pattern_type.bb7 = var_pattern %b.patt [concrete]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %b.var: ref %tuple.type.b67 = var b
  123. // CHECK:STDOUT: %Make.ref.loc17_20: %Make.type = name_ref Make, file.%Make.decl [concrete = constants.%Make]
  124. // CHECK:STDOUT: %tuple.elem0: ref %X = tuple_access %b.var, element0
  125. // CHECK:STDOUT: %Make.call.loc17_25: init %X = call %Make.ref.loc17_20() to %tuple.elem0
  126. // CHECK:STDOUT: %Make.ref.loc17_28: %Make.type = name_ref Make, file.%Make.decl [concrete = constants.%Make]
  127. // CHECK:STDOUT: %tuple.elem1: ref %X = tuple_access %b.var, element1
  128. // CHECK:STDOUT: %Make.call.loc17_33: init %X = call %Make.ref.loc17_28() to %tuple.elem1
  129. // CHECK:STDOUT: %.loc17_34.1: %tuple.type.b67 = tuple_literal (%Make.call.loc17_25, %Make.call.loc17_33)
  130. // CHECK:STDOUT: %X.ref.loc17_40: type = name_ref X, file.%X.decl [concrete = constants.%X]
  131. // CHECK:STDOUT: %X.ref.loc17_43: type = name_ref X, file.%X.decl [concrete = constants.%X]
  132. // CHECK:STDOUT: %.loc17_44.1: %tuple.type.24b = tuple_literal (%X.ref.loc17_40, %X.ref.loc17_43)
  133. // CHECK:STDOUT: %.loc17_44.2: type = converted %.loc17_44.1, constants.%tuple.type.b67 [concrete = constants.%tuple.type.b67]
  134. // CHECK:STDOUT: %.loc17_34.2: init %tuple.type.b67 = tuple_init (%Make.call.loc17_25, %Make.call.loc17_33) to %b.var
  135. // CHECK:STDOUT: %.loc17_3.2: init %tuple.type.b67 = converted %.loc17_34.1, %.loc17_34.2
  136. // CHECK:STDOUT: assign %b.var, %.loc17_3.2
  137. // CHECK:STDOUT: %.loc17_15.1: type = splice_block %.loc17_15.3 [concrete = constants.%tuple.type.b67] {
  138. // CHECK:STDOUT: %X.ref.loc17_11: type = name_ref X, file.%X.decl [concrete = constants.%X]
  139. // CHECK:STDOUT: %X.ref.loc17_14: type = name_ref X, file.%X.decl [concrete = constants.%X]
  140. // CHECK:STDOUT: %.loc17_15.2: %tuple.type.24b = tuple_literal (%X.ref.loc17_11, %X.ref.loc17_14)
  141. // CHECK:STDOUT: %.loc17_15.3: type = converted %.loc17_15.2, constants.%tuple.type.b67 [concrete = constants.%tuple.type.b67]
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %b: ref %tuple.type.b67 = bind_name b, %b.var
  144. // CHECK:STDOUT: return
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: --- include_files/destroy.carbon
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: file {
  150. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {}
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: