tuple.carbon 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/as/no_prelude/tuple.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/no_prelude/tuple.carbon
  10. class X {
  11. // ...
  12. }
  13. fn Make() -> X;
  14. fn Let() {
  15. // This should create value bindings for both tuple elements.
  16. let a: (X, X) = (Make(), Make()) as (X, X);
  17. }
  18. fn Var() {
  19. // This should initialize both tuple elements in place.
  20. var b: (X, X) = (Make(), Make()) as (X, X);
  21. }
  22. // CHECK:STDOUT: --- tuple.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %X: type = class_type @X [template]
  26. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  27. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  28. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  29. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  30. // CHECK:STDOUT: %Let.type: type = fn_type @Let [template]
  31. // CHECK:STDOUT: %Let: %Let.type = struct_value () [template]
  32. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [template]
  33. // CHECK:STDOUT: %tuple.type.b67: type = tuple_type (%X, %X) [template]
  34. // CHECK:STDOUT: %Var.type: type = fn_type @Var [template]
  35. // CHECK:STDOUT: %Var: %Var.type = struct_value () [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .X = %X.decl
  41. // CHECK:STDOUT: .Make = %Make.decl
  42. // CHECK:STDOUT: .Let = %Let.decl
  43. // CHECK:STDOUT: .Var = %Var.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {} {}
  46. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  47. // CHECK:STDOUT: %return.patt: %X = return_slot_pattern
  48. // CHECK:STDOUT: %return.param_patt: %X = out_param_pattern %return.patt, runtime_param0
  49. // CHECK:STDOUT: } {
  50. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  51. // CHECK:STDOUT: %return.param: ref %X = out_param runtime_param0
  52. // CHECK:STDOUT: %return: ref %X = return_slot %return.param
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Let.decl: %Let.type = fn_decl @Let [template = constants.%Let] {} {}
  55. // CHECK:STDOUT: %Var.decl: %Var.type = fn_decl @Var [template = constants.%Var] {} {}
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: class @X {
  59. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  60. // CHECK:STDOUT: complete_type_witness = %complete_type
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = constants.%X
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @Make() -> %X;
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @Let() {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: name_binding_decl {
  71. // CHECK:STDOUT: %a.patt: %tuple.type.b67 = binding_pattern a
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Make.ref.loc19_20: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  74. // CHECK:STDOUT: %.loc19_25.1: ref %X = temporary_storage
  75. // CHECK:STDOUT: %Make.call.loc19_25: init %X = call %Make.ref.loc19_20() to %.loc19_25.1
  76. // CHECK:STDOUT: %Make.ref.loc19_28: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  77. // CHECK:STDOUT: %.loc19_33.1: ref %X = temporary_storage
  78. // CHECK:STDOUT: %Make.call.loc19_33: init %X = call %Make.ref.loc19_28() to %.loc19_33.1
  79. // CHECK:STDOUT: %.loc19_34.1: %tuple.type.b67 = tuple_literal (%Make.call.loc19_25, %Make.call.loc19_33)
  80. // CHECK:STDOUT: %X.ref.loc19_40: type = name_ref X, file.%X.decl [template = constants.%X]
  81. // CHECK:STDOUT: %X.ref.loc19_43: type = name_ref X, file.%X.decl [template = constants.%X]
  82. // CHECK:STDOUT: %.loc19_44.1: %tuple.type.24b = tuple_literal (%X.ref.loc19_40, %X.ref.loc19_43)
  83. // CHECK:STDOUT: %.loc19_44.2: type = converted %.loc19_44.1, constants.%tuple.type.b67 [template = constants.%tuple.type.b67]
  84. // CHECK:STDOUT: %.loc19_15.1: type = splice_block %.loc19_15.3 [template = constants.%tuple.type.b67] {
  85. // CHECK:STDOUT: %X.ref.loc19_11: type = name_ref X, file.%X.decl [template = constants.%X]
  86. // CHECK:STDOUT: %X.ref.loc19_14: type = name_ref X, file.%X.decl [template = constants.%X]
  87. // CHECK:STDOUT: %.loc19_15.2: %tuple.type.24b = tuple_literal (%X.ref.loc19_11, %X.ref.loc19_14)
  88. // CHECK:STDOUT: %.loc19_15.3: type = converted %.loc19_15.2, constants.%tuple.type.b67 [template = constants.%tuple.type.b67]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %.loc19_25.2: ref %X = temporary %.loc19_25.1, %Make.call.loc19_25
  91. // CHECK:STDOUT: %.loc19_25.3: %X = bind_value %.loc19_25.2
  92. // CHECK:STDOUT: %.loc19_33.2: ref %X = temporary %.loc19_33.1, %Make.call.loc19_33
  93. // CHECK:STDOUT: %.loc19_33.3: %X = bind_value %.loc19_33.2
  94. // CHECK:STDOUT: %tuple: %tuple.type.b67 = tuple_value (%.loc19_25.3, %.loc19_33.3)
  95. // CHECK:STDOUT: %.loc19_34.2: %tuple.type.b67 = converted %.loc19_34.1, %tuple
  96. // CHECK:STDOUT: %a: %tuple.type.b67 = bind_name a, %.loc19_34.2
  97. // CHECK:STDOUT: return
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @Var() {
  101. // CHECK:STDOUT: !entry:
  102. // CHECK:STDOUT: name_binding_decl {
  103. // CHECK:STDOUT: %b.patt: %tuple.type.b67 = binding_pattern b
  104. // CHECK:STDOUT: %.loc24_3.1: %tuple.type.b67 = var_pattern %b.patt
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %b.var: ref %tuple.type.b67 = var b
  107. // CHECK:STDOUT: %Make.ref.loc24_20: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  108. // CHECK:STDOUT: %tuple.elem0: ref %X = tuple_access %b.var, element0
  109. // CHECK:STDOUT: %Make.call.loc24_25: init %X = call %Make.ref.loc24_20() to %tuple.elem0
  110. // CHECK:STDOUT: %Make.ref.loc24_28: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  111. // CHECK:STDOUT: %tuple.elem1: ref %X = tuple_access %b.var, element1
  112. // CHECK:STDOUT: %Make.call.loc24_33: init %X = call %Make.ref.loc24_28() to %tuple.elem1
  113. // CHECK:STDOUT: %.loc24_34.1: %tuple.type.b67 = tuple_literal (%Make.call.loc24_25, %Make.call.loc24_33)
  114. // CHECK:STDOUT: %X.ref.loc24_40: type = name_ref X, file.%X.decl [template = constants.%X]
  115. // CHECK:STDOUT: %X.ref.loc24_43: type = name_ref X, file.%X.decl [template = constants.%X]
  116. // CHECK:STDOUT: %.loc24_44.1: %tuple.type.24b = tuple_literal (%X.ref.loc24_40, %X.ref.loc24_43)
  117. // CHECK:STDOUT: %.loc24_44.2: type = converted %.loc24_44.1, constants.%tuple.type.b67 [template = constants.%tuple.type.b67]
  118. // CHECK:STDOUT: %.loc24_34.2: init %tuple.type.b67 = tuple_init (%Make.call.loc24_25, %Make.call.loc24_33) to %b.var
  119. // CHECK:STDOUT: %.loc24_3.2: init %tuple.type.b67 = converted %.loc24_34.1, %.loc24_34.2
  120. // CHECK:STDOUT: assign %b.var, %.loc24_3.2
  121. // CHECK:STDOUT: %.loc24_15.1: type = splice_block %.loc24_15.3 [template = constants.%tuple.type.b67] {
  122. // CHECK:STDOUT: %X.ref.loc24_11: type = name_ref X, file.%X.decl [template = constants.%X]
  123. // CHECK:STDOUT: %X.ref.loc24_14: type = name_ref X, file.%X.decl [template = constants.%X]
  124. // CHECK:STDOUT: %.loc24_15.2: %tuple.type.24b = tuple_literal (%X.ref.loc24_11, %X.ref.loc24_14)
  125. // CHECK:STDOUT: %.loc24_15.3: type = converted %.loc24_15.2, constants.%tuple.type.b67 [template = constants.%tuple.type.b67]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %b: ref %tuple.type.b67 = bind_name b, %b.var
  128. // CHECK:STDOUT: return
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: