assign_var.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/array/assign_var.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/assign_var.carbon
  10. var a: (i32, i32, i32) = (1, 2, 3);
  11. var b: array(i32, 3) = a;
  12. // CHECK:STDOUT: --- assign_var.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  16. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  17. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  19. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [concrete]
  20. // CHECK:STDOUT: %tuple.type.189: type = tuple_type (%i32, %i32, %i32) [concrete]
  21. // CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
  22. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  23. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  24. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [concrete]
  25. // CHECK:STDOUT: %tuple.type.37f: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [concrete]
  26. // CHECK:STDOUT: %tuple.elem0: ref %i32 = tuple_access file.%a.var, element0 [concrete]
  27. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  29. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  30. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  31. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  32. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To.c80) [symbolic]
  33. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  34. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  35. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  36. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  37. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  38. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  39. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  40. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  41. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  42. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  43. // CHECK:STDOUT: %tuple.elem1: ref %i32 = tuple_access file.%a.var, element1 [concrete]
  44. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
  45. // CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
  46. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  47. // CHECK:STDOUT: %tuple.elem2: ref %i32 = tuple_access file.%a.var, element2 [concrete]
  48. // CHECK:STDOUT: %Convert.bound.b30: <bound method> = bound_method %int_3.1ba, %Convert.956 [concrete]
  49. // CHECK:STDOUT: %bound_method.047: <bound method> = bound_method %int_3.1ba, %Convert.specific_fn [concrete]
  50. // CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [concrete]
  51. // CHECK:STDOUT: %tuple: %tuple.type.189 = tuple_value (%int_1.5d2, %int_2.ef8, %int_3.822) [concrete]
  52. // CHECK:STDOUT: %array_type: type = array_type %int_3.1ba, %i32 [concrete]
  53. // CHECK:STDOUT: %pattern_type.5d8: type = pattern_type %array_type [concrete]
  54. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: imports {
  58. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  59. // CHECK:STDOUT: .Int = %Core.Int
  60. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  61. // CHECK:STDOUT: import Core//prelude
  62. // CHECK:STDOUT: import Core//prelude/...
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  65. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  66. // 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)]
  67. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  72. // CHECK:STDOUT: .Core = imports.%Core
  73. // CHECK:STDOUT: .a = %a
  74. // CHECK:STDOUT: .b = %b
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: name_binding_decl {
  78. // CHECK:STDOUT: %a.patt: %pattern_type.b5a = binding_pattern a [concrete]
  79. // CHECK:STDOUT: %a.var_patt: %pattern_type.b5a = var_pattern %a.patt [concrete]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %a.var: ref %tuple.type.189 = var %a.var_patt [concrete]
  82. // CHECK:STDOUT: %.loc11_22.1: type = splice_block %.loc11_22.3 [concrete = constants.%tuple.type.189] {
  83. // CHECK:STDOUT: %int_32.loc11_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  84. // CHECK:STDOUT: %i32.loc11_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  85. // CHECK:STDOUT: %int_32.loc11_14: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  86. // CHECK:STDOUT: %i32.loc11_14: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  87. // CHECK:STDOUT: %int_32.loc11_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  88. // CHECK:STDOUT: %i32.loc11_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  89. // CHECK:STDOUT: %.loc11_22.2: %tuple.type.ff9 = tuple_literal (%i32.loc11_9, %i32.loc11_14, %i32.loc11_19)
  90. // CHECK:STDOUT: %.loc11_22.3: type = converted %.loc11_22.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %a: ref %tuple.type.189 = bind_name a, %a.var
  93. // CHECK:STDOUT: name_binding_decl {
  94. // CHECK:STDOUT: %b.patt: %pattern_type.5d8 = binding_pattern b [concrete]
  95. // CHECK:STDOUT: %b.var_patt: %pattern_type.5d8 = var_pattern %b.patt [concrete]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %b.var: ref %array_type = var %b.var_patt [concrete]
  98. // CHECK:STDOUT: %.loc12: type = splice_block %array_type [concrete = constants.%array_type] {
  99. // CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  100. // CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  101. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
  102. // CHECK:STDOUT: %array_type: type = array_type %int_3, %i32.loc12 [concrete = constants.%array_type]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %b: ref %array_type = bind_name b, %b.var
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @__global_init() {
  108. // CHECK:STDOUT: !entry:
  109. // CHECK:STDOUT: %int_1.loc11: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  110. // CHECK:STDOUT: %int_2.loc11: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  111. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
  112. // CHECK:STDOUT: %.loc11_34.1: %tuple.type.37f = tuple_literal (%int_1.loc11, %int_2.loc11, %int_3)
  113. // CHECK:STDOUT: %impl.elem0.loc11_34.1: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  114. // CHECK:STDOUT: %bound_method.loc11_34.1: <bound method> = bound_method %int_1.loc11, %impl.elem0.loc11_34.1 [concrete = constants.%Convert.bound.ab5]
  115. // CHECK:STDOUT: %specific_fn.loc11_34.1: <specific function> = specific_function %impl.elem0.loc11_34.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  116. // CHECK:STDOUT: %bound_method.loc11_34.2: <bound method> = bound_method %int_1.loc11, %specific_fn.loc11_34.1 [concrete = constants.%bound_method.9a1]
  117. // CHECK:STDOUT: %int.convert_checked.loc11_34.1: init %i32 = call %bound_method.loc11_34.2(%int_1.loc11) [concrete = constants.%int_1.5d2]
  118. // CHECK:STDOUT: %.loc11_34.2: init %i32 = converted %int_1.loc11, %int.convert_checked.loc11_34.1 [concrete = constants.%int_1.5d2]
  119. // CHECK:STDOUT: %tuple.elem0.loc11: ref %i32 = tuple_access file.%a.var, element0 [concrete = constants.%tuple.elem0]
  120. // CHECK:STDOUT: %.loc11_34.3: init %i32 = initialize_from %.loc11_34.2 to %tuple.elem0.loc11 [concrete = constants.%int_1.5d2]
  121. // CHECK:STDOUT: %impl.elem0.loc11_34.2: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  122. // CHECK:STDOUT: %bound_method.loc11_34.3: <bound method> = bound_method %int_2.loc11, %impl.elem0.loc11_34.2 [concrete = constants.%Convert.bound.ef9]
  123. // CHECK:STDOUT: %specific_fn.loc11_34.2: <specific function> = specific_function %impl.elem0.loc11_34.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  124. // CHECK:STDOUT: %bound_method.loc11_34.4: <bound method> = bound_method %int_2.loc11, %specific_fn.loc11_34.2 [concrete = constants.%bound_method.b92]
  125. // CHECK:STDOUT: %int.convert_checked.loc11_34.2: init %i32 = call %bound_method.loc11_34.4(%int_2.loc11) [concrete = constants.%int_2.ef8]
  126. // CHECK:STDOUT: %.loc11_34.4: init %i32 = converted %int_2.loc11, %int.convert_checked.loc11_34.2 [concrete = constants.%int_2.ef8]
  127. // CHECK:STDOUT: %tuple.elem1.loc11: ref %i32 = tuple_access file.%a.var, element1 [concrete = constants.%tuple.elem1]
  128. // CHECK:STDOUT: %.loc11_34.5: init %i32 = initialize_from %.loc11_34.4 to %tuple.elem1.loc11 [concrete = constants.%int_2.ef8]
  129. // CHECK:STDOUT: %impl.elem0.loc11_34.3: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  130. // CHECK:STDOUT: %bound_method.loc11_34.5: <bound method> = bound_method %int_3, %impl.elem0.loc11_34.3 [concrete = constants.%Convert.bound.b30]
  131. // CHECK:STDOUT: %specific_fn.loc11_34.3: <specific function> = specific_function %impl.elem0.loc11_34.3, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  132. // CHECK:STDOUT: %bound_method.loc11_34.6: <bound method> = bound_method %int_3, %specific_fn.loc11_34.3 [concrete = constants.%bound_method.047]
  133. // CHECK:STDOUT: %int.convert_checked.loc11_34.3: init %i32 = call %bound_method.loc11_34.6(%int_3) [concrete = constants.%int_3.822]
  134. // CHECK:STDOUT: %.loc11_34.6: init %i32 = converted %int_3, %int.convert_checked.loc11_34.3 [concrete = constants.%int_3.822]
  135. // CHECK:STDOUT: %tuple.elem2.loc11: ref %i32 = tuple_access file.%a.var, element2 [concrete = constants.%tuple.elem2]
  136. // CHECK:STDOUT: %.loc11_34.7: init %i32 = initialize_from %.loc11_34.6 to %tuple.elem2.loc11 [concrete = constants.%int_3.822]
  137. // CHECK:STDOUT: %.loc11_34.8: init %tuple.type.189 = tuple_init (%.loc11_34.3, %.loc11_34.5, %.loc11_34.7) to file.%a.var [concrete = constants.%tuple]
  138. // CHECK:STDOUT: %.loc11_1: init %tuple.type.189 = converted %.loc11_34.1, %.loc11_34.8 [concrete = constants.%tuple]
  139. // CHECK:STDOUT: assign file.%a.var, %.loc11_1
  140. // CHECK:STDOUT: %a.ref: ref %tuple.type.189 = name_ref a, file.%a
  141. // CHECK:STDOUT: %tuple.elem0.loc12: ref %i32 = tuple_access %a.ref, element0
  142. // CHECK:STDOUT: %.loc12_24.1: %i32 = bind_value %tuple.elem0.loc12
  143. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  144. // CHECK:STDOUT: %.loc12_24.2: ref %i32 = array_index file.%b.var, %int_0
  145. // CHECK:STDOUT: %.loc12_24.3: init %i32 = initialize_from %.loc12_24.1 to %.loc12_24.2
  146. // CHECK:STDOUT: %tuple.elem1.loc12: ref %i32 = tuple_access %a.ref, element1
  147. // CHECK:STDOUT: %.loc12_24.4: %i32 = bind_value %tuple.elem1.loc12
  148. // CHECK:STDOUT: %int_1.loc12: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  149. // CHECK:STDOUT: %.loc12_24.5: ref %i32 = array_index file.%b.var, %int_1.loc12
  150. // CHECK:STDOUT: %.loc12_24.6: init %i32 = initialize_from %.loc12_24.4 to %.loc12_24.5
  151. // CHECK:STDOUT: %tuple.elem2.loc12: ref %i32 = tuple_access %a.ref, element2
  152. // CHECK:STDOUT: %.loc12_24.7: %i32 = bind_value %tuple.elem2.loc12
  153. // CHECK:STDOUT: %int_2.loc12: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  154. // CHECK:STDOUT: %.loc12_24.8: ref %i32 = array_index file.%b.var, %int_2.loc12
  155. // CHECK:STDOUT: %.loc12_24.9: init %i32 = initialize_from %.loc12_24.7 to %.loc12_24.8
  156. // CHECK:STDOUT: %.loc12_24.10: init %array_type = array_init (%.loc12_24.3, %.loc12_24.6, %.loc12_24.9) to file.%b.var
  157. // CHECK:STDOUT: %.loc12_1: init %array_type = converted %a.ref, %.loc12_24.10
  158. // CHECK:STDOUT: assign file.%b.var, %.loc12_1
  159. // CHECK:STDOUT: return
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: