tuple_as_element.carbon 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/struct/tuple_as_element.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/tuple_as_element.carbon
  10. var x: {.a: i32, .b: (i32,)} = {.a = 1, .b = (2,)};
  11. var y: {.a: i32, .b: (i32,)} = x;
  12. // CHECK:STDOUT: --- tuple_as_element.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  16. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  17. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  18. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  19. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type) [template]
  20. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (%i32) [template]
  21. // CHECK:STDOUT: %.2: type = struct_type {.a: %i32, .b: %tuple.type.2} [template]
  22. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 1 [template]
  23. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 2 [template]
  24. // CHECK:STDOUT: %tuple.type.3: type = tuple_type (Core.IntLiteral) [template]
  25. // CHECK:STDOUT: %.6: type = struct_type {.a: Core.IntLiteral, .b: %tuple.type.3} [template]
  26. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  27. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  28. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  29. // CHECK:STDOUT: %.26: <witness> = interface_witness (%Convert.14) [template]
  30. // CHECK:STDOUT: %.27: <bound method> = bound_method %.4, %Convert.14 [template]
  31. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  32. // CHECK:STDOUT: %.29: %i32 = int_value 1 [template]
  33. // CHECK:STDOUT: %.30: <bound method> = bound_method %.5, %Convert.14 [template]
  34. // CHECK:STDOUT: %.31: <specific function> = specific_function %.30, @Convert.2(%.1) [template]
  35. // CHECK:STDOUT: %.32: %i32 = int_value 2 [template]
  36. // CHECK:STDOUT: %tuple: %tuple.type.2 = tuple_value (%.32) [template]
  37. // CHECK:STDOUT: %struct: %.2 = struct_value (%.29, %tuple) [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  42. // CHECK:STDOUT: .Int = %import_ref.1
  43. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  44. // CHECK:STDOUT: import Core//prelude
  45. // CHECK:STDOUT: import Core//prelude/...
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  51. // CHECK:STDOUT: .Core = imports.%Core
  52. // CHECK:STDOUT: .x = %x
  53. // CHECK:STDOUT: .y = %y
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core.import = import Core
  56. // CHECK:STDOUT: %.loc11_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  57. // CHECK:STDOUT: %int.make_type_signed.loc11_13: init type = call constants.%Int(%.loc11_13.1) [template = constants.%i32]
  58. // CHECK:STDOUT: %.loc11_13.2: type = value_of_initializer %int.make_type_signed.loc11_13 [template = constants.%i32]
  59. // CHECK:STDOUT: %.loc11_13.3: type = converted %int.make_type_signed.loc11_13, %.loc11_13.2 [template = constants.%i32]
  60. // CHECK:STDOUT: %.loc11_23: Core.IntLiteral = int_value 32 [template = constants.%.1]
  61. // CHECK:STDOUT: %int.make_type_signed.loc11_23: init type = call constants.%Int(%.loc11_23) [template = constants.%i32]
  62. // CHECK:STDOUT: %.loc11_27.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc11_23)
  63. // CHECK:STDOUT: %.loc11_27.2: type = value_of_initializer %int.make_type_signed.loc11_23 [template = constants.%i32]
  64. // CHECK:STDOUT: %.loc11_27.3: type = converted %int.make_type_signed.loc11_23, %.loc11_27.2 [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc11_27.4: type = converted %.loc11_27.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  66. // CHECK:STDOUT: %.loc11_28: type = struct_type {.a: %i32, .b: %tuple.type.2} [template = constants.%.2]
  67. // CHECK:STDOUT: %x.var: ref %.2 = var x
  68. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  69. // CHECK:STDOUT: %.loc12_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  70. // CHECK:STDOUT: %int.make_type_signed.loc12_13: init type = call constants.%Int(%.loc12_13.1) [template = constants.%i32]
  71. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %int.make_type_signed.loc12_13 [template = constants.%i32]
  72. // CHECK:STDOUT: %.loc12_13.3: type = converted %int.make_type_signed.loc12_13, %.loc12_13.2 [template = constants.%i32]
  73. // CHECK:STDOUT: %.loc12_23: Core.IntLiteral = int_value 32 [template = constants.%.1]
  74. // CHECK:STDOUT: %int.make_type_signed.loc12_23: init type = call constants.%Int(%.loc12_23) [template = constants.%i32]
  75. // CHECK:STDOUT: %.loc12_27.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc12_23)
  76. // CHECK:STDOUT: %.loc12_27.2: type = value_of_initializer %int.make_type_signed.loc12_23 [template = constants.%i32]
  77. // CHECK:STDOUT: %.loc12_27.3: type = converted %int.make_type_signed.loc12_23, %.loc12_27.2 [template = constants.%i32]
  78. // CHECK:STDOUT: %.loc12_27.4: type = converted %.loc12_27.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  79. // CHECK:STDOUT: %.loc12_28: type = struct_type {.a: %i32, .b: %tuple.type.2} [template = constants.%.2]
  80. // CHECK:STDOUT: %y.var: ref %.2 = var y
  81. // CHECK:STDOUT: %y: ref %.2 = bind_name y, %y.var
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @__global_init() {
  85. // CHECK:STDOUT: !entry:
  86. // CHECK:STDOUT: %.loc11_38: Core.IntLiteral = int_value 1 [template = constants.%.4]
  87. // CHECK:STDOUT: %.loc11_47: Core.IntLiteral = int_value 2 [template = constants.%.5]
  88. // CHECK:STDOUT: %.loc11_49.1: %tuple.type.3 = tuple_literal (%.loc11_47)
  89. // CHECK:STDOUT: %.loc11_50.1: %.6 = struct_literal (%.loc11_38, %.loc11_49.1)
  90. // CHECK:STDOUT: %.loc11_50.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  91. // CHECK:STDOUT: %.loc11_50.3: <bound method> = bound_method %.loc11_38, %.loc11_50.2 [template = constants.%.27]
  92. // CHECK:STDOUT: %.loc11_50.4: <specific function> = specific_function %.loc11_50.3, @Convert.2(constants.%.1) [template = constants.%.28]
  93. // CHECK:STDOUT: %int.convert_checked.loc11_50: init %i32 = call %.loc11_50.4(%.loc11_38) [template = constants.%.29]
  94. // CHECK:STDOUT: %.loc11_50.5: init %i32 = converted %.loc11_38, %int.convert_checked.loc11_50 [template = constants.%.29]
  95. // CHECK:STDOUT: %.loc11_50.6: ref %i32 = struct_access file.%x.var, element0
  96. // CHECK:STDOUT: %.loc11_50.7: init %i32 = initialize_from %.loc11_50.5 to %.loc11_50.6 [template = constants.%.29]
  97. // CHECK:STDOUT: %.loc11_49.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  98. // CHECK:STDOUT: %.loc11_49.3: <bound method> = bound_method %.loc11_47, %.loc11_49.2 [template = constants.%.30]
  99. // CHECK:STDOUT: %.loc11_49.4: <specific function> = specific_function %.loc11_49.3, @Convert.2(constants.%.1) [template = constants.%.31]
  100. // CHECK:STDOUT: %int.convert_checked.loc11_49: init %i32 = call %.loc11_49.4(%.loc11_47) [template = constants.%.32]
  101. // CHECK:STDOUT: %.loc11_49.5: init %i32 = converted %.loc11_47, %int.convert_checked.loc11_49 [template = constants.%.32]
  102. // CHECK:STDOUT: %.loc11_50.8: ref %tuple.type.2 = struct_access file.%x.var, element1
  103. // CHECK:STDOUT: %.loc11_49.6: init %tuple.type.2 = tuple_init (%.loc11_49.5) to %.loc11_50.8 [template = constants.%tuple]
  104. // CHECK:STDOUT: %.loc11_50.9: init %tuple.type.2 = converted %.loc11_49.1, %.loc11_49.6 [template = constants.%tuple]
  105. // CHECK:STDOUT: %.loc11_50.10: init %tuple.type.2 = initialize_from %.loc11_50.9 to %.loc11_50.8 [template = constants.%tuple]
  106. // CHECK:STDOUT: %.loc11_50.11: init %.2 = struct_init (%.loc11_50.7, %.loc11_50.10) to file.%x.var [template = constants.%struct]
  107. // CHECK:STDOUT: %.loc11_51: init %.2 = converted %.loc11_50.1, %.loc11_50.11 [template = constants.%struct]
  108. // CHECK:STDOUT: assign file.%x.var, %.loc11_51
  109. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  110. // CHECK:STDOUT: %.loc12_32.1: ref %i32 = struct_access %x.ref, element0
  111. // CHECK:STDOUT: %.loc12_32.2: %i32 = bind_value %.loc12_32.1
  112. // CHECK:STDOUT: %.loc12_32.3: ref %i32 = struct_access file.%y.var, element0
  113. // CHECK:STDOUT: %.loc12_32.4: init %i32 = initialize_from %.loc12_32.2 to %.loc12_32.3
  114. // CHECK:STDOUT: %.loc12_32.5: ref %tuple.type.2 = struct_access %x.ref, element1
  115. // CHECK:STDOUT: %.loc12_32.6: ref %i32 = tuple_access %.loc12_32.5, element0
  116. // CHECK:STDOUT: %.loc12_32.7: %i32 = bind_value %.loc12_32.6
  117. // CHECK:STDOUT: %.loc12_32.8: ref %tuple.type.2 = struct_access file.%y.var, element1
  118. // CHECK:STDOUT: %.loc12_32.9: init %tuple.type.2 = tuple_init (%.loc12_32.7) to %.loc12_32.8
  119. // CHECK:STDOUT: %.loc12_32.10: init %tuple.type.2 = converted %.loc12_32.5, %.loc12_32.9
  120. // CHECK:STDOUT: %.loc12_32.11: init %tuple.type.2 = initialize_from %.loc12_32.10 to %.loc12_32.8
  121. // CHECK:STDOUT: %.loc12_32.12: init %.2 = struct_init (%.loc12_32.4, %.loc12_32.11) to file.%y.var
  122. // CHECK:STDOUT: %.loc12_33: init %.2 = converted %x.ref, %.loc12_32.12
  123. // CHECK:STDOUT: assign file.%y.var, %.loc12_33
  124. // CHECK:STDOUT: return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: