assign_var.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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: [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 [template]
  16. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  17. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [template]
  18. // CHECK:STDOUT: %tuple.type.189: type = tuple_type (%i32, %i32, %i32) [template]
  19. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  20. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  21. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [template]
  22. // CHECK:STDOUT: %tuple.type.37f: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
  23. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  24. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  25. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  26. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  27. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  28. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  29. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  30. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  31. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  32. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  33. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  34. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  35. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  36. // CHECK:STDOUT: %Convert.bound.b30: <bound method> = bound_method %int_3.1ba, %Convert.956 [template]
  37. // CHECK:STDOUT: %Convert.specific_fn.b42: <specific function> = specific_function %Convert.bound.b30, @Convert.2(%int_32) [template]
  38. // CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [template]
  39. // CHECK:STDOUT: %tuple: %tuple.type.189 = tuple_value (%int_1.5d2, %int_2.ef8, %int_3.822) [template]
  40. // CHECK:STDOUT: %array_type: type = array_type %int_3.1ba, %i32 [template]
  41. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  46. // CHECK:STDOUT: .Int = %Core.Int
  47. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .a = %a
  57. // CHECK:STDOUT: .b = %b
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: name_binding_decl {
  61. // CHECK:STDOUT: %a.patt: %tuple.type.189 = binding_pattern a
  62. // CHECK:STDOUT: %.loc11_1: %tuple.type.189 = var_pattern %a.patt
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %a.var: ref %tuple.type.189 = var a
  65. // CHECK:STDOUT: %.loc11_22.1: type = splice_block %.loc11_22.3 [template = constants.%tuple.type.189] {
  66. // CHECK:STDOUT: %int_32.loc11_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  67. // CHECK:STDOUT: %i32.loc11_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  68. // CHECK:STDOUT: %int_32.loc11_14: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  69. // CHECK:STDOUT: %i32.loc11_14: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  70. // CHECK:STDOUT: %int_32.loc11_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  71. // CHECK:STDOUT: %i32.loc11_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  72. // CHECK:STDOUT: %.loc11_22.2: %tuple.type.ff9 = tuple_literal (%i32.loc11_9, %i32.loc11_14, %i32.loc11_19)
  73. // CHECK:STDOUT: %.loc11_22.3: type = converted %.loc11_22.2, constants.%tuple.type.189 [template = constants.%tuple.type.189]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %a: ref %tuple.type.189 = bind_name a, %a.var
  76. // CHECK:STDOUT: name_binding_decl {
  77. // CHECK:STDOUT: %b.patt: %array_type = binding_pattern b
  78. // CHECK:STDOUT: %.loc12_1: %array_type = var_pattern %b.patt
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %b.var: ref %array_type = var b
  81. // CHECK:STDOUT: %.loc12_15: type = splice_block %array_type [template = constants.%array_type] {
  82. // CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  83. // CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  84. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3.1ba]
  85. // CHECK:STDOUT: %array_type: type = array_type %int_3, %i32 [template = constants.%array_type]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %b: ref %array_type = bind_name b, %b.var
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @__global_init() {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %int_1.loc11: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  93. // CHECK:STDOUT: %int_2.loc11: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  94. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3.1ba]
  95. // CHECK:STDOUT: %.loc11_34.1: %tuple.type.37f = tuple_literal (%int_1.loc11, %int_2.loc11, %int_3)
  96. // CHECK:STDOUT: %impl.elem0.loc11_34.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  97. // CHECK:STDOUT: %bound_method.loc11_34.1: <bound method> = bound_method %int_1.loc11, %impl.elem0.loc11_34.1 [template = constants.%Convert.bound.ab5]
  98. // CHECK:STDOUT: %specific_fn.loc11_34.1: <specific function> = specific_function %bound_method.loc11_34.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  99. // CHECK:STDOUT: %int.convert_checked.loc11_34.1: init %i32 = call %specific_fn.loc11_34.1(%int_1.loc11) [template = constants.%int_1.5d2]
  100. // CHECK:STDOUT: %.loc11_34.2: init %i32 = converted %int_1.loc11, %int.convert_checked.loc11_34.1 [template = constants.%int_1.5d2]
  101. // CHECK:STDOUT: %tuple.elem0.loc11: ref %i32 = tuple_access file.%a.var, element0
  102. // CHECK:STDOUT: %.loc11_34.3: init %i32 = initialize_from %.loc11_34.2 to %tuple.elem0.loc11 [template = constants.%int_1.5d2]
  103. // CHECK:STDOUT: %impl.elem0.loc11_34.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  104. // CHECK:STDOUT: %bound_method.loc11_34.2: <bound method> = bound_method %int_2.loc11, %impl.elem0.loc11_34.2 [template = constants.%Convert.bound.ef9]
  105. // CHECK:STDOUT: %specific_fn.loc11_34.2: <specific function> = specific_function %bound_method.loc11_34.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  106. // CHECK:STDOUT: %int.convert_checked.loc11_34.2: init %i32 = call %specific_fn.loc11_34.2(%int_2.loc11) [template = constants.%int_2.ef8]
  107. // CHECK:STDOUT: %.loc11_34.4: init %i32 = converted %int_2.loc11, %int.convert_checked.loc11_34.2 [template = constants.%int_2.ef8]
  108. // CHECK:STDOUT: %tuple.elem1.loc11: ref %i32 = tuple_access file.%a.var, element1
  109. // CHECK:STDOUT: %.loc11_34.5: init %i32 = initialize_from %.loc11_34.4 to %tuple.elem1.loc11 [template = constants.%int_2.ef8]
  110. // CHECK:STDOUT: %impl.elem0.loc11_34.3: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  111. // CHECK:STDOUT: %bound_method.loc11_34.3: <bound method> = bound_method %int_3, %impl.elem0.loc11_34.3 [template = constants.%Convert.bound.b30]
  112. // CHECK:STDOUT: %specific_fn.loc11_34.3: <specific function> = specific_function %bound_method.loc11_34.3, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.b42]
  113. // CHECK:STDOUT: %int.convert_checked.loc11_34.3: init %i32 = call %specific_fn.loc11_34.3(%int_3) [template = constants.%int_3.822]
  114. // CHECK:STDOUT: %.loc11_34.6: init %i32 = converted %int_3, %int.convert_checked.loc11_34.3 [template = constants.%int_3.822]
  115. // CHECK:STDOUT: %tuple.elem2.loc11: ref %i32 = tuple_access file.%a.var, element2
  116. // CHECK:STDOUT: %.loc11_34.7: init %i32 = initialize_from %.loc11_34.6 to %tuple.elem2.loc11 [template = constants.%int_3.822]
  117. // CHECK:STDOUT: %.loc11_34.8: init %tuple.type.189 = tuple_init (%.loc11_34.3, %.loc11_34.5, %.loc11_34.7) to file.%a.var [template = constants.%tuple]
  118. // CHECK:STDOUT: %.loc11_1: init %tuple.type.189 = converted %.loc11_34.1, %.loc11_34.8 [template = constants.%tuple]
  119. // CHECK:STDOUT: assign file.%a.var, %.loc11_1
  120. // CHECK:STDOUT: %a.ref: ref %tuple.type.189 = name_ref a, file.%a
  121. // CHECK:STDOUT: %tuple.elem0.loc12: ref %i32 = tuple_access %a.ref, element0
  122. // CHECK:STDOUT: %.loc12_19.1: %i32 = bind_value %tuple.elem0.loc12
  123. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  124. // CHECK:STDOUT: %.loc12_19.2: ref %i32 = array_index file.%b.var, %int_0
  125. // CHECK:STDOUT: %.loc12_19.3: init %i32 = initialize_from %.loc12_19.1 to %.loc12_19.2
  126. // CHECK:STDOUT: %tuple.elem1.loc12: ref %i32 = tuple_access %a.ref, element1
  127. // CHECK:STDOUT: %.loc12_19.4: %i32 = bind_value %tuple.elem1.loc12
  128. // CHECK:STDOUT: %int_1.loc12: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  129. // CHECK:STDOUT: %.loc12_19.5: ref %i32 = array_index file.%b.var, %int_1.loc12
  130. // CHECK:STDOUT: %.loc12_19.6: init %i32 = initialize_from %.loc12_19.4 to %.loc12_19.5
  131. // CHECK:STDOUT: %tuple.elem2.loc12: ref %i32 = tuple_access %a.ref, element2
  132. // CHECK:STDOUT: %.loc12_19.7: %i32 = bind_value %tuple.elem2.loc12
  133. // CHECK:STDOUT: %int_2.loc12: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  134. // CHECK:STDOUT: %.loc12_19.8: ref %i32 = array_index file.%b.var, %int_2.loc12
  135. // CHECK:STDOUT: %.loc12_19.9: init %i32 = initialize_from %.loc12_19.7 to %.loc12_19.8
  136. // CHECK:STDOUT: %.loc12_19.10: init %array_type = array_init (%.loc12_19.3, %.loc12_19.6, %.loc12_19.9) to file.%b.var
  137. // CHECK:STDOUT: %.loc12_1: init %array_type = converted %a.ref, %.loc12_19.10
  138. // CHECK:STDOUT: assign file.%b.var, %.loc12_1
  139. // CHECK:STDOUT: return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: