two_entries.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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: %.1: Core.IntLiteral = int_value 32 [template]
  18. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  19. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  20. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  21. // CHECK:STDOUT: %.2: type = struct_type {.a: %i32, .b: %i32} [template]
  22. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 1 [template]
  23. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 2 [template]
  24. // CHECK:STDOUT: %.6: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  25. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  26. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  27. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  28. // CHECK:STDOUT: %.30: <witness> = interface_witness (%Convert.14) [template]
  29. // CHECK:STDOUT: %.31: <bound method> = bound_method %.4, %Convert.14 [template]
  30. // CHECK:STDOUT: %.32: <specific function> = specific_function %.31, @Convert.2(%.1) [template]
  31. // CHECK:STDOUT: %.33: %i32 = int_value 1 [template]
  32. // CHECK:STDOUT: %.34: <bound method> = bound_method %.5, %Convert.14 [template]
  33. // CHECK:STDOUT: %.35: <specific function> = specific_function %.34, @Convert.2(%.1) [template]
  34. // CHECK:STDOUT: %.36: %i32 = int_value 2 [template]
  35. // CHECK:STDOUT: %struct: %.2 = struct_value (%.33, %.36) [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  40. // CHECK:STDOUT: .Int = %import_ref.1
  41. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/...
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = imports.%Core
  50. // CHECK:STDOUT: .v = @__global_init.%v
  51. // CHECK:STDOUT: .w = @__global_init.%w
  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_22.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  61. // CHECK:STDOUT: %int.make_type_signed.loc11_22: init type = call constants.%Int(%.loc11_22.1) [template = constants.%i32]
  62. // CHECK:STDOUT: %.loc11_22.2: type = value_of_initializer %int.make_type_signed.loc11_22 [template = constants.%i32]
  63. // CHECK:STDOUT: %.loc11_22.3: type = converted %int.make_type_signed.loc11_22, %.loc11_22.2 [template = constants.%i32]
  64. // CHECK:STDOUT: %.loc11_25: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.2]
  65. // CHECK:STDOUT: %.loc12_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  66. // CHECK:STDOUT: %int.make_type_signed.loc12_13: init type = call constants.%Int(%.loc12_13.1) [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %int.make_type_signed.loc12_13 [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc12_13.3: type = converted %int.make_type_signed.loc12_13, %.loc12_13.2 [template = constants.%i32]
  69. // CHECK:STDOUT: %.loc12_22.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  70. // CHECK:STDOUT: %int.make_type_signed.loc12_22: init type = call constants.%Int(%.loc12_22.1) [template = constants.%i32]
  71. // CHECK:STDOUT: %.loc12_22.2: type = value_of_initializer %int.make_type_signed.loc12_22 [template = constants.%i32]
  72. // CHECK:STDOUT: %.loc12_22.3: type = converted %int.make_type_signed.loc12_22, %.loc12_22.2 [template = constants.%i32]
  73. // CHECK:STDOUT: %.loc12_25: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.2]
  74. // CHECK:STDOUT: %.loc14_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  75. // CHECK:STDOUT: %int.make_type_signed.loc14_13: init type = call constants.%Int(%.loc14_13.1) [template = constants.%i32]
  76. // CHECK:STDOUT: %.loc14_13.2: type = value_of_initializer %int.make_type_signed.loc14_13 [template = constants.%i32]
  77. // CHECK:STDOUT: %.loc14_13.3: type = converted %int.make_type_signed.loc14_13, %.loc14_13.2 [template = constants.%i32]
  78. // CHECK:STDOUT: %.loc14_22.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  79. // CHECK:STDOUT: %int.make_type_signed.loc14_22: init type = call constants.%Int(%.loc14_22.1) [template = constants.%i32]
  80. // CHECK:STDOUT: %.loc14_22.2: type = value_of_initializer %int.make_type_signed.loc14_22 [template = constants.%i32]
  81. // CHECK:STDOUT: %.loc14_22.3: type = converted %int.make_type_signed.loc14_22, %.loc14_22.2 [template = constants.%i32]
  82. // CHECK:STDOUT: %.loc14_25: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.2]
  83. // CHECK:STDOUT: %x.var: ref %.2 = var x
  84. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  85. // CHECK:STDOUT: %.loc15_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  86. // CHECK:STDOUT: %int.make_type_signed.loc15_13: init type = call constants.%Int(%.loc15_13.1) [template = constants.%i32]
  87. // CHECK:STDOUT: %.loc15_13.2: type = value_of_initializer %int.make_type_signed.loc15_13 [template = constants.%i32]
  88. // CHECK:STDOUT: %.loc15_13.3: type = converted %int.make_type_signed.loc15_13, %.loc15_13.2 [template = constants.%i32]
  89. // CHECK:STDOUT: %.loc15_22.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  90. // CHECK:STDOUT: %int.make_type_signed.loc15_22: init type = call constants.%Int(%.loc15_22.1) [template = constants.%i32]
  91. // CHECK:STDOUT: %.loc15_22.2: type = value_of_initializer %int.make_type_signed.loc15_22 [template = constants.%i32]
  92. // CHECK:STDOUT: %.loc15_22.3: type = converted %int.make_type_signed.loc15_22, %.loc15_22.2 [template = constants.%i32]
  93. // CHECK:STDOUT: %.loc15_25: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.2]
  94. // CHECK:STDOUT: %y.var: ref %.2 = var y
  95. // CHECK:STDOUT: %y: ref %.2 = bind_name y, %y.var
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @__global_init() {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: %.loc11_35: Core.IntLiteral = int_value 1 [template = constants.%.4]
  101. // CHECK:STDOUT: %.loc11_43: Core.IntLiteral = int_value 2 [template = constants.%.5]
  102. // CHECK:STDOUT: %.loc11_44.1: %.6 = struct_literal (%.loc11_35, %.loc11_43)
  103. // CHECK:STDOUT: %.loc11_44.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  104. // CHECK:STDOUT: %.loc11_44.3: <bound method> = bound_method %.loc11_35, %.loc11_44.2 [template = constants.%.31]
  105. // CHECK:STDOUT: %.loc11_44.4: <specific function> = specific_function %.loc11_44.3, @Convert.2(constants.%.1) [template = constants.%.32]
  106. // CHECK:STDOUT: %int.convert_checked.loc11_44.1: init %i32 = call %.loc11_44.4(%.loc11_35) [template = constants.%.33]
  107. // CHECK:STDOUT: %.loc11_44.5: %i32 = value_of_initializer %int.convert_checked.loc11_44.1 [template = constants.%.33]
  108. // CHECK:STDOUT: %.loc11_44.6: %i32 = converted %.loc11_35, %.loc11_44.5 [template = constants.%.33]
  109. // CHECK:STDOUT: %.loc11_44.7: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  110. // CHECK:STDOUT: %.loc11_44.8: <bound method> = bound_method %.loc11_43, %.loc11_44.7 [template = constants.%.34]
  111. // CHECK:STDOUT: %.loc11_44.9: <specific function> = specific_function %.loc11_44.8, @Convert.2(constants.%.1) [template = constants.%.35]
  112. // CHECK:STDOUT: %int.convert_checked.loc11_44.2: init %i32 = call %.loc11_44.9(%.loc11_43) [template = constants.%.36]
  113. // CHECK:STDOUT: %.loc11_44.10: %i32 = value_of_initializer %int.convert_checked.loc11_44.2 [template = constants.%.36]
  114. // CHECK:STDOUT: %.loc11_44.11: %i32 = converted %.loc11_43, %.loc11_44.10 [template = constants.%.36]
  115. // CHECK:STDOUT: %struct: %.2 = struct_value (%.loc11_44.6, %.loc11_44.11) [template = constants.%struct]
  116. // CHECK:STDOUT: %.loc11_45: %.2 = converted %.loc11_44.1, %struct [template = constants.%struct]
  117. // CHECK:STDOUT: %v: %.2 = bind_name v, %.loc11_45
  118. // CHECK:STDOUT: %v.ref: %.2 = name_ref v, %v
  119. // CHECK:STDOUT: %w: %.2 = bind_name w, %v.ref
  120. // CHECK:STDOUT: %.loc14_35: Core.IntLiteral = int_value 1 [template = constants.%.4]
  121. // CHECK:STDOUT: %.loc14_43: Core.IntLiteral = int_value 2 [template = constants.%.5]
  122. // CHECK:STDOUT: %.loc14_44.1: %.6 = struct_literal (%.loc14_35, %.loc14_43)
  123. // CHECK:STDOUT: %.loc14_44.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  124. // CHECK:STDOUT: %.loc14_44.3: <bound method> = bound_method %.loc14_35, %.loc14_44.2 [template = constants.%.31]
  125. // CHECK:STDOUT: %.loc14_44.4: <specific function> = specific_function %.loc14_44.3, @Convert.2(constants.%.1) [template = constants.%.32]
  126. // CHECK:STDOUT: %int.convert_checked.loc14_44.1: init %i32 = call %.loc14_44.4(%.loc14_35) [template = constants.%.33]
  127. // CHECK:STDOUT: %.loc14_44.5: init %i32 = converted %.loc14_35, %int.convert_checked.loc14_44.1 [template = constants.%.33]
  128. // CHECK:STDOUT: %.loc14_44.6: ref %i32 = struct_access file.%x.var, element0
  129. // CHECK:STDOUT: %.loc14_44.7: init %i32 = initialize_from %.loc14_44.5 to %.loc14_44.6 [template = constants.%.33]
  130. // CHECK:STDOUT: %.loc14_44.8: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  131. // CHECK:STDOUT: %.loc14_44.9: <bound method> = bound_method %.loc14_43, %.loc14_44.8 [template = constants.%.34]
  132. // CHECK:STDOUT: %.loc14_44.10: <specific function> = specific_function %.loc14_44.9, @Convert.2(constants.%.1) [template = constants.%.35]
  133. // CHECK:STDOUT: %int.convert_checked.loc14_44.2: init %i32 = call %.loc14_44.10(%.loc14_43) [template = constants.%.36]
  134. // CHECK:STDOUT: %.loc14_44.11: init %i32 = converted %.loc14_43, %int.convert_checked.loc14_44.2 [template = constants.%.36]
  135. // CHECK:STDOUT: %.loc14_44.12: ref %i32 = struct_access file.%x.var, element1
  136. // CHECK:STDOUT: %.loc14_44.13: init %i32 = initialize_from %.loc14_44.11 to %.loc14_44.12 [template = constants.%.36]
  137. // CHECK:STDOUT: %.loc14_44.14: init %.2 = struct_init (%.loc14_44.7, %.loc14_44.13) to file.%x.var [template = constants.%struct]
  138. // CHECK:STDOUT: %.loc14_45: init %.2 = converted %.loc14_44.1, %.loc14_44.14 [template = constants.%struct]
  139. // CHECK:STDOUT: assign file.%x.var, %.loc14_45
  140. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  141. // CHECK:STDOUT: %.loc15_29.1: ref %i32 = struct_access %x.ref, element0
  142. // CHECK:STDOUT: %.loc15_29.2: %i32 = bind_value %.loc15_29.1
  143. // CHECK:STDOUT: %.loc15_29.3: ref %i32 = struct_access file.%y.var, element0
  144. // CHECK:STDOUT: %.loc15_29.4: init %i32 = initialize_from %.loc15_29.2 to %.loc15_29.3
  145. // CHECK:STDOUT: %.loc15_29.5: ref %i32 = struct_access %x.ref, element1
  146. // CHECK:STDOUT: %.loc15_29.6: %i32 = bind_value %.loc15_29.5
  147. // CHECK:STDOUT: %.loc15_29.7: ref %i32 = struct_access file.%y.var, element1
  148. // CHECK:STDOUT: %.loc15_29.8: init %i32 = initialize_from %.loc15_29.6 to %.loc15_29.7
  149. // CHECK:STDOUT: %.loc15_29.9: init %.2 = struct_init (%.loc15_29.4, %.loc15_29.8) to file.%y.var
  150. // CHECK:STDOUT: %.loc15_30: init %.2 = converted %x.ref, %.loc15_29.9
  151. // CHECK:STDOUT: assign file.%y.var, %.loc15_30
  152. // CHECK:STDOUT: return
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: