two_entries.carbon 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: %Int.type: type = generic_class_type @Int [concrete]
  19. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  21. // CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [concrete]
  22. // CHECK:STDOUT: %pattern_type.851: type = pattern_type %struct_type.a.b.501 [concrete]
  23. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  24. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  25. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [concrete]
  26. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  27. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  29. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  30. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  31. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To.c80) [symbolic]
  32. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  33. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  34. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  35. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  36. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  37. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  38. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  39. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  40. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  41. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  42. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
  43. // CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
  44. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  45. // CHECK:STDOUT: %struct: %struct_type.a.b.501 = struct_value (%int_1.5d2, %int_2.ef8) [concrete]
  46. // CHECK:STDOUT: %.22f: ref %i32 = struct_access file.%x.var, element0 [concrete]
  47. // CHECK:STDOUT: %.5fc: ref %i32 = struct_access file.%x.var, element1 [concrete]
  48. // CHECK:STDOUT: %.4ca: ref %i32 = struct_access file.%y.var, element0 [concrete]
  49. // CHECK:STDOUT: %.86e: ref %i32 = struct_access file.%y.var, element1 [concrete]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: imports {
  53. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  54. // CHECK:STDOUT: .Int = %Core.Int
  55. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/...
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  60. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  61. // CHECK:STDOUT: %Core.import_ref.a5b: @impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/types/int, loc19_39, loaded [symbolic = @impl.4f9.%Convert (constants.%Convert.f06)]
  62. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .v = %v
  69. // CHECK:STDOUT: .w = %w
  70. // CHECK:STDOUT: .x = %x
  71. // CHECK:STDOUT: .y = %y
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Core.import = import Core
  74. // CHECK:STDOUT: name_binding_decl {
  75. // CHECK:STDOUT: %v.patt: %pattern_type.851 = binding_pattern v [concrete]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %.loc11_25: type = splice_block %struct_type.a.b.loc11 [concrete = constants.%struct_type.a.b.501] {
  78. // CHECK:STDOUT: %int_32.loc11_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  79. // CHECK:STDOUT: %i32.loc11_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  80. // CHECK:STDOUT: %int_32.loc11_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  81. // CHECK:STDOUT: %i32.loc11_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  82. // CHECK:STDOUT: %struct_type.a.b.loc11: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %impl.elem0.loc11_44.1: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  85. // 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]
  86. // 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]
  87. // 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]
  88. // 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]
  89. // CHECK:STDOUT: %.loc11_44.1: %i32 = value_of_initializer %int.convert_checked.loc11_44.1 [concrete = constants.%int_1.5d2]
  90. // CHECK:STDOUT: %.loc11_44.2: %i32 = converted @__global_init.%int_1.loc11, %.loc11_44.1 [concrete = constants.%int_1.5d2]
  91. // CHECK:STDOUT: %impl.elem0.loc11_44.2: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  92. // 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]
  93. // 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]
  94. // 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]
  95. // 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]
  96. // CHECK:STDOUT: %.loc11_44.3: %i32 = value_of_initializer %int.convert_checked.loc11_44.2 [concrete = constants.%int_2.ef8]
  97. // CHECK:STDOUT: %.loc11_44.4: %i32 = converted @__global_init.%int_2.loc11, %.loc11_44.3 [concrete = constants.%int_2.ef8]
  98. // CHECK:STDOUT: %struct: %struct_type.a.b.501 = struct_value (%.loc11_44.2, %.loc11_44.4) [concrete = constants.%struct]
  99. // CHECK:STDOUT: %.loc11_44.5: %struct_type.a.b.501 = converted @__global_init.%.loc11, %struct [concrete = constants.%struct]
  100. // CHECK:STDOUT: %v: %struct_type.a.b.501 = bind_name v, %.loc11_44.5
  101. // CHECK:STDOUT: name_binding_decl {
  102. // CHECK:STDOUT: %w.patt: %pattern_type.851 = binding_pattern w [concrete]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %.loc12: type = splice_block %struct_type.a.b.loc12 [concrete = constants.%struct_type.a.b.501] {
  105. // CHECK:STDOUT: %int_32.loc12_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc12_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  107. // CHECK:STDOUT: %int_32.loc12_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  108. // CHECK:STDOUT: %i32.loc12_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  109. // CHECK:STDOUT: %struct_type.a.b.loc12: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %w: %struct_type.a.b.501 = bind_name w, @__global_init.%v.ref
  112. // CHECK:STDOUT: name_binding_decl {
  113. // CHECK:STDOUT: %x.patt: %pattern_type.851 = binding_pattern x [concrete]
  114. // CHECK:STDOUT: %x.var_patt: %pattern_type.851 = var_pattern %x.patt [concrete]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %x.var: ref %struct_type.a.b.501 = var %x.var_patt [concrete]
  117. // CHECK:STDOUT: %.loc14: type = splice_block %struct_type.a.b.loc14 [concrete = constants.%struct_type.a.b.501] {
  118. // CHECK:STDOUT: %int_32.loc14_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  119. // CHECK:STDOUT: %i32.loc14_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  120. // CHECK:STDOUT: %int_32.loc14_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  121. // CHECK:STDOUT: %i32.loc14_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  122. // CHECK:STDOUT: %struct_type.a.b.loc14: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %x: ref %struct_type.a.b.501 = bind_name x, %x.var
  125. // CHECK:STDOUT: name_binding_decl {
  126. // CHECK:STDOUT: %y.patt: %pattern_type.851 = binding_pattern y [concrete]
  127. // CHECK:STDOUT: %y.var_patt: %pattern_type.851 = var_pattern %y.patt [concrete]
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %y.var: ref %struct_type.a.b.501 = var %y.var_patt [concrete]
  130. // CHECK:STDOUT: %.loc15: type = splice_block %struct_type.a.b.loc15 [concrete = constants.%struct_type.a.b.501] {
  131. // CHECK:STDOUT: %int_32.loc15_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  132. // CHECK:STDOUT: %i32.loc15_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  133. // CHECK:STDOUT: %int_32.loc15_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  134. // CHECK:STDOUT: %i32.loc15_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  135. // CHECK:STDOUT: %struct_type.a.b.loc15: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: %y: ref %struct_type.a.b.501 = bind_name y, %y.var
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: fn @__global_init() {
  141. // CHECK:STDOUT: !entry:
  142. // CHECK:STDOUT: %int_1.loc11: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  143. // CHECK:STDOUT: %int_2.loc11: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  144. // CHECK:STDOUT: %.loc11: %struct_type.a.b.cfd = struct_literal (%int_1.loc11, %int_2.loc11)
  145. // CHECK:STDOUT: %v.ref: %struct_type.a.b.501 = name_ref v, file.%v
  146. // CHECK:STDOUT: %int_1.loc14: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  147. // CHECK:STDOUT: %int_2.loc14: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  148. // CHECK:STDOUT: %.loc14_44.1: %struct_type.a.b.cfd = struct_literal (%int_1.loc14, %int_2.loc14)
  149. // CHECK:STDOUT: %impl.elem0.loc14_44.1: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  150. // CHECK:STDOUT: %bound_method.loc14_44.1: <bound method> = bound_method %int_1.loc14, %impl.elem0.loc14_44.1 [concrete = constants.%Convert.bound.ab5]
  151. // 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]
  152. // CHECK:STDOUT: %bound_method.loc14_44.2: <bound method> = bound_method %int_1.loc14, %specific_fn.loc14_44.1 [concrete = constants.%bound_method.9a1]
  153. // CHECK:STDOUT: %int.convert_checked.loc14_44.1: init %i32 = call %bound_method.loc14_44.2(%int_1.loc14) [concrete = constants.%int_1.5d2]
  154. // CHECK:STDOUT: %.loc14_44.2: init %i32 = converted %int_1.loc14, %int.convert_checked.loc14_44.1 [concrete = constants.%int_1.5d2]
  155. // CHECK:STDOUT: %.loc14_44.3: ref %i32 = struct_access file.%x.var, element0 [concrete = constants.%.22f]
  156. // CHECK:STDOUT: %.loc14_44.4: init %i32 = initialize_from %.loc14_44.2 to %.loc14_44.3 [concrete = constants.%int_1.5d2]
  157. // CHECK:STDOUT: %impl.elem0.loc14_44.2: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  158. // CHECK:STDOUT: %bound_method.loc14_44.3: <bound method> = bound_method %int_2.loc14, %impl.elem0.loc14_44.2 [concrete = constants.%Convert.bound.ef9]
  159. // 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]
  160. // CHECK:STDOUT: %bound_method.loc14_44.4: <bound method> = bound_method %int_2.loc14, %specific_fn.loc14_44.2 [concrete = constants.%bound_method.b92]
  161. // CHECK:STDOUT: %int.convert_checked.loc14_44.2: init %i32 = call %bound_method.loc14_44.4(%int_2.loc14) [concrete = constants.%int_2.ef8]
  162. // CHECK:STDOUT: %.loc14_44.5: init %i32 = converted %int_2.loc14, %int.convert_checked.loc14_44.2 [concrete = constants.%int_2.ef8]
  163. // CHECK:STDOUT: %.loc14_44.6: ref %i32 = struct_access file.%x.var, element1 [concrete = constants.%.5fc]
  164. // CHECK:STDOUT: %.loc14_44.7: init %i32 = initialize_from %.loc14_44.5 to %.loc14_44.6 [concrete = constants.%int_2.ef8]
  165. // 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]
  166. // CHECK:STDOUT: %.loc14_1: init %struct_type.a.b.501 = converted %.loc14_44.1, %.loc14_44.8 [concrete = constants.%struct]
  167. // CHECK:STDOUT: assign file.%x.var, %.loc14_1
  168. // CHECK:STDOUT: %x.ref: ref %struct_type.a.b.501 = name_ref x, file.%x
  169. // CHECK:STDOUT: %.loc15_29.1: ref %i32 = struct_access %x.ref, element0
  170. // CHECK:STDOUT: %.loc15_29.2: %i32 = bind_value %.loc15_29.1
  171. // CHECK:STDOUT: %.loc15_29.3: ref %i32 = struct_access file.%y.var, element0 [concrete = constants.%.4ca]
  172. // CHECK:STDOUT: %.loc15_29.4: init %i32 = initialize_from %.loc15_29.2 to %.loc15_29.3
  173. // CHECK:STDOUT: %.loc15_29.5: ref %i32 = struct_access %x.ref, element1
  174. // CHECK:STDOUT: %.loc15_29.6: %i32 = bind_value %.loc15_29.5
  175. // CHECK:STDOUT: %.loc15_29.7: ref %i32 = struct_access file.%y.var, element1 [concrete = constants.%.86e]
  176. // CHECK:STDOUT: %.loc15_29.8: init %i32 = initialize_from %.loc15_29.6 to %.loc15_29.7
  177. // CHECK:STDOUT: %.loc15_29.9: init %struct_type.a.b.501 = struct_init (%.loc15_29.4, %.loc15_29.8) to file.%y.var
  178. // CHECK:STDOUT: %.loc15_1: init %struct_type.a.b.501 = converted %x.ref, %.loc15_29.9
  179. // CHECK:STDOUT: assign file.%y.var, %.loc15_1
  180. // CHECK:STDOUT: return
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: