two_entries.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/two_entries.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/two_entries.carbon
  10. let v: {.a: i32, .b: i32} = {.a = 1, .b = 2};
  11. let w: {.a: i32, .b: i32} = v;
  12. var x: {.a: i32, .b: i32} = {.a = 1, .b = 2};
  13. var y: {.a: i32, .b: i32} = x;
  14. // CHECK:STDOUT: --- two_entries.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  19. // CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [concrete]
  20. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  21. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  22. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [concrete]
  23. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  24. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  25. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  26. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  27. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  29. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  30. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  31. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  32. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  33. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  34. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
  35. // CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
  36. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  37. // CHECK:STDOUT: %struct: %struct_type.a.b.501 = struct_value (%int_1.5d2, %int_2.ef8) [concrete]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  42. // CHECK:STDOUT: .Int = %Core.Int
  43. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  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 [concrete] {
  51. // CHECK:STDOUT: .Core = imports.%Core
  52. // CHECK:STDOUT: .v = %v
  53. // CHECK:STDOUT: .w = %w
  54. // CHECK:STDOUT: .x = %x
  55. // CHECK:STDOUT: .y = %y
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: name_binding_decl {
  59. // CHECK:STDOUT: %v.patt: %struct_type.a.b.501 = binding_pattern v
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %.loc11_25: type = splice_block %struct_type.a.b.loc11 [concrete = constants.%struct_type.a.b.501] {
  62. // CHECK:STDOUT: %int_32.loc11_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  63. // CHECK:STDOUT: %i32.loc11_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  64. // CHECK:STDOUT: %int_32.loc11_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  65. // CHECK:STDOUT: %i32.loc11_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  66. // CHECK:STDOUT: %struct_type.a.b.loc11: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %impl.elem0.loc11_44.1: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  69. // CHECK:STDOUT: %bound_method.loc11_44.1: <bound method> = bound_method @__global_init.%int_1.loc11, %impl.elem0.loc11_44.1 [concrete = constants.%Convert.bound.ab5]
  70. // CHECK:STDOUT: %specific_fn.loc11_44.1: <specific function> = specific_function %impl.elem0.loc11_44.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  71. // CHECK:STDOUT: %bound_method.loc11_44.2: <bound method> = bound_method @__global_init.%int_1.loc11, %specific_fn.loc11_44.1 [concrete = constants.%bound_method.9a1]
  72. // CHECK:STDOUT: %int.convert_checked.loc11_44.1: init %i32 = call %bound_method.loc11_44.2(@__global_init.%int_1.loc11) [concrete = constants.%int_1.5d2]
  73. // CHECK:STDOUT: %.loc11_44.1: %i32 = value_of_initializer %int.convert_checked.loc11_44.1 [concrete = constants.%int_1.5d2]
  74. // CHECK:STDOUT: %.loc11_44.2: %i32 = converted @__global_init.%int_1.loc11, %.loc11_44.1 [concrete = constants.%int_1.5d2]
  75. // CHECK:STDOUT: %impl.elem0.loc11_44.2: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  76. // CHECK:STDOUT: %bound_method.loc11_44.3: <bound method> = bound_method @__global_init.%int_2.loc11, %impl.elem0.loc11_44.2 [concrete = constants.%Convert.bound.ef9]
  77. // CHECK:STDOUT: %specific_fn.loc11_44.2: <specific function> = specific_function %impl.elem0.loc11_44.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  78. // CHECK:STDOUT: %bound_method.loc11_44.4: <bound method> = bound_method @__global_init.%int_2.loc11, %specific_fn.loc11_44.2 [concrete = constants.%bound_method.b92]
  79. // CHECK:STDOUT: %int.convert_checked.loc11_44.2: init %i32 = call %bound_method.loc11_44.4(@__global_init.%int_2.loc11) [concrete = constants.%int_2.ef8]
  80. // CHECK:STDOUT: %.loc11_44.3: %i32 = value_of_initializer %int.convert_checked.loc11_44.2 [concrete = constants.%int_2.ef8]
  81. // CHECK:STDOUT: %.loc11_44.4: %i32 = converted @__global_init.%int_2.loc11, %.loc11_44.3 [concrete = constants.%int_2.ef8]
  82. // CHECK:STDOUT: %struct: %struct_type.a.b.501 = struct_value (%.loc11_44.2, %.loc11_44.4) [concrete = constants.%struct]
  83. // CHECK:STDOUT: %.loc11_44.5: %struct_type.a.b.501 = converted @__global_init.%.loc11, %struct [concrete = constants.%struct]
  84. // CHECK:STDOUT: %v: %struct_type.a.b.501 = bind_name v, %.loc11_44.5
  85. // CHECK:STDOUT: name_binding_decl {
  86. // CHECK:STDOUT: %w.patt: %struct_type.a.b.501 = binding_pattern w
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %.loc12: type = splice_block %struct_type.a.b.loc12 [concrete = constants.%struct_type.a.b.501] {
  89. // CHECK:STDOUT: %int_32.loc12_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  90. // CHECK:STDOUT: %i32.loc12_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  91. // CHECK:STDOUT: %int_32.loc12_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  92. // CHECK:STDOUT: %i32.loc12_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  93. // CHECK:STDOUT: %struct_type.a.b.loc12: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %w: %struct_type.a.b.501 = bind_name w, @__global_init.%v.ref
  96. // CHECK:STDOUT: name_binding_decl {
  97. // CHECK:STDOUT: %x.patt: %struct_type.a.b.501 = binding_pattern x
  98. // CHECK:STDOUT: %.loc14_1: %struct_type.a.b.501 = var_pattern %x.patt
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %x.var: ref %struct_type.a.b.501 = var x
  101. // CHECK:STDOUT: %.loc14_25: type = splice_block %struct_type.a.b.loc14 [concrete = constants.%struct_type.a.b.501] {
  102. // CHECK:STDOUT: %int_32.loc14_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  103. // CHECK:STDOUT: %i32.loc14_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  104. // CHECK:STDOUT: %int_32.loc14_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32.loc14_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: %struct_type.a.b.loc14: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %x: ref %struct_type.a.b.501 = bind_name x, %x.var
  109. // CHECK:STDOUT: name_binding_decl {
  110. // CHECK:STDOUT: %y.patt: %struct_type.a.b.501 = binding_pattern y
  111. // CHECK:STDOUT: %.loc15_1: %struct_type.a.b.501 = var_pattern %y.patt
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %y.var: ref %struct_type.a.b.501 = var y
  114. // CHECK:STDOUT: %.loc15_25: type = splice_block %struct_type.a.b.loc15 [concrete = constants.%struct_type.a.b.501] {
  115. // CHECK:STDOUT: %int_32.loc15_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  116. // CHECK:STDOUT: %i32.loc15_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  117. // CHECK:STDOUT: %int_32.loc15_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  118. // CHECK:STDOUT: %i32.loc15_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  119. // CHECK:STDOUT: %struct_type.a.b.loc15: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %y: ref %struct_type.a.b.501 = bind_name y, %y.var
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @__global_init() {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %int_1.loc11: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  127. // CHECK:STDOUT: %int_2.loc11: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  128. // CHECK:STDOUT: %.loc11: %struct_type.a.b.cfd = struct_literal (%int_1.loc11, %int_2.loc11)
  129. // CHECK:STDOUT: %v.ref: %struct_type.a.b.501 = name_ref v, file.%v
  130. // CHECK:STDOUT: %int_1.loc14: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  131. // CHECK:STDOUT: %int_2.loc14: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  132. // CHECK:STDOUT: %.loc14_44.1: %struct_type.a.b.cfd = struct_literal (%int_1.loc14, %int_2.loc14)
  133. // CHECK:STDOUT: %impl.elem0.loc14_44.1: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  134. // CHECK:STDOUT: %bound_method.loc14_44.1: <bound method> = bound_method %int_1.loc14, %impl.elem0.loc14_44.1 [concrete = constants.%Convert.bound.ab5]
  135. // CHECK:STDOUT: %specific_fn.loc14_44.1: <specific function> = specific_function %impl.elem0.loc14_44.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  136. // CHECK:STDOUT: %bound_method.loc14_44.2: <bound method> = bound_method %int_1.loc14, %specific_fn.loc14_44.1 [concrete = constants.%bound_method.9a1]
  137. // CHECK:STDOUT: %int.convert_checked.loc14_44.1: init %i32 = call %bound_method.loc14_44.2(%int_1.loc14) [concrete = constants.%int_1.5d2]
  138. // CHECK:STDOUT: %.loc14_44.2: init %i32 = converted %int_1.loc14, %int.convert_checked.loc14_44.1 [concrete = constants.%int_1.5d2]
  139. // CHECK:STDOUT: %.loc14_44.3: ref %i32 = struct_access file.%x.var, element0
  140. // CHECK:STDOUT: %.loc14_44.4: init %i32 = initialize_from %.loc14_44.2 to %.loc14_44.3 [concrete = constants.%int_1.5d2]
  141. // CHECK:STDOUT: %impl.elem0.loc14_44.2: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  142. // CHECK:STDOUT: %bound_method.loc14_44.3: <bound method> = bound_method %int_2.loc14, %impl.elem0.loc14_44.2 [concrete = constants.%Convert.bound.ef9]
  143. // CHECK:STDOUT: %specific_fn.loc14_44.2: <specific function> = specific_function %impl.elem0.loc14_44.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  144. // CHECK:STDOUT: %bound_method.loc14_44.4: <bound method> = bound_method %int_2.loc14, %specific_fn.loc14_44.2 [concrete = constants.%bound_method.b92]
  145. // CHECK:STDOUT: %int.convert_checked.loc14_44.2: init %i32 = call %bound_method.loc14_44.4(%int_2.loc14) [concrete = constants.%int_2.ef8]
  146. // CHECK:STDOUT: %.loc14_44.5: init %i32 = converted %int_2.loc14, %int.convert_checked.loc14_44.2 [concrete = constants.%int_2.ef8]
  147. // CHECK:STDOUT: %.loc14_44.6: ref %i32 = struct_access file.%x.var, element1
  148. // CHECK:STDOUT: %.loc14_44.7: init %i32 = initialize_from %.loc14_44.5 to %.loc14_44.6 [concrete = constants.%int_2.ef8]
  149. // CHECK:STDOUT: %.loc14_44.8: init %struct_type.a.b.501 = struct_init (%.loc14_44.4, %.loc14_44.7) to file.%x.var [concrete = constants.%struct]
  150. // CHECK:STDOUT: %.loc14_1: init %struct_type.a.b.501 = converted %.loc14_44.1, %.loc14_44.8 [concrete = constants.%struct]
  151. // CHECK:STDOUT: assign file.%x.var, %.loc14_1
  152. // CHECK:STDOUT: %x.ref: ref %struct_type.a.b.501 = name_ref x, file.%x
  153. // CHECK:STDOUT: %.loc15_29.1: ref %i32 = struct_access %x.ref, element0
  154. // CHECK:STDOUT: %.loc15_29.2: %i32 = bind_value %.loc15_29.1
  155. // CHECK:STDOUT: %.loc15_29.3: ref %i32 = struct_access file.%y.var, element0
  156. // CHECK:STDOUT: %.loc15_29.4: init %i32 = initialize_from %.loc15_29.2 to %.loc15_29.3
  157. // CHECK:STDOUT: %.loc15_29.5: ref %i32 = struct_access %x.ref, element1
  158. // CHECK:STDOUT: %.loc15_29.6: %i32 = bind_value %.loc15_29.5
  159. // CHECK:STDOUT: %.loc15_29.7: ref %i32 = struct_access file.%y.var, element1
  160. // CHECK:STDOUT: %.loc15_29.8: init %i32 = initialize_from %.loc15_29.6 to %.loc15_29.7
  161. // CHECK:STDOUT: %.loc15_29.9: init %struct_type.a.b.501 = struct_init (%.loc15_29.4, %.loc15_29.8) to file.%y.var
  162. // CHECK:STDOUT: %.loc15_1: init %struct_type.a.b.501 = converted %x.ref, %.loc15_29.9
  163. // CHECK:STDOUT: assign file.%y.var, %.loc15_1
  164. // CHECK:STDOUT: return
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: