array_vs_tuple.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/array_vs_tuple.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/array_vs_tuple.carbon
  10. fn G() {
  11. // These should have two different constant values.
  12. var a: [i32; 3] = (1, 2, 3);
  13. var b: (i32, i32, i32) = (1, 2, 3);
  14. }
  15. // CHECK:STDOUT: --- array_vs_tuple.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  21. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: i32 = int_literal 3 [template]
  24. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  25. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  26. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  27. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  28. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  29. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  30. // CHECK:STDOUT: %array: %.3 = tuple_value (%.5, %.6, %.2) [template]
  31. // CHECK:STDOUT: %.9: type = tuple_type (type, type, type) [template]
  32. // CHECK:STDOUT: %.10: type = ptr_type %.7 [template]
  33. // CHECK:STDOUT: %tuple: %.7 = tuple_value (%.5, %.6, %.2) [template]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: file {
  37. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  38. // CHECK:STDOUT: .Core = %Core
  39. // CHECK:STDOUT: .G = %G.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  42. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {}
  43. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  44. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  45. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  46. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @G() {
  50. // CHECK:STDOUT: !entry:
  51. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  52. // CHECK:STDOUT: %.loc13_16: i32 = int_literal 3 [template = constants.%.2]
  53. // CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  54. // CHECK:STDOUT: %.loc13_11.2: type = converted %int.make_type_32.loc13, %.loc13_11.1 [template = i32]
  55. // CHECK:STDOUT: %.loc13_17: type = array_type %.loc13_16, i32 [template = constants.%.3]
  56. // CHECK:STDOUT: %a.var: ref %.3 = var a
  57. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  58. // CHECK:STDOUT: %.loc13_22: i32 = int_literal 1 [template = constants.%.5]
  59. // CHECK:STDOUT: %.loc13_25: i32 = int_literal 2 [template = constants.%.6]
  60. // CHECK:STDOUT: %.loc13_28: i32 = int_literal 3 [template = constants.%.2]
  61. // CHECK:STDOUT: %.loc13_29.1: %.7 = tuple_literal (%.loc13_22, %.loc13_25, %.loc13_28)
  62. // CHECK:STDOUT: %.loc13_29.2: i32 = int_literal 0 [template = constants.%.8]
  63. // CHECK:STDOUT: %.loc13_29.3: ref i32 = array_index %a.var, %.loc13_29.2
  64. // CHECK:STDOUT: %.loc13_29.4: init i32 = initialize_from %.loc13_22 to %.loc13_29.3 [template = constants.%.5]
  65. // CHECK:STDOUT: %.loc13_29.5: i32 = int_literal 1 [template = constants.%.5]
  66. // CHECK:STDOUT: %.loc13_29.6: ref i32 = array_index %a.var, %.loc13_29.5
  67. // CHECK:STDOUT: %.loc13_29.7: init i32 = initialize_from %.loc13_25 to %.loc13_29.6 [template = constants.%.6]
  68. // CHECK:STDOUT: %.loc13_29.8: i32 = int_literal 2 [template = constants.%.6]
  69. // CHECK:STDOUT: %.loc13_29.9: ref i32 = array_index %a.var, %.loc13_29.8
  70. // CHECK:STDOUT: %.loc13_29.10: init i32 = initialize_from %.loc13_28 to %.loc13_29.9 [template = constants.%.2]
  71. // CHECK:STDOUT: %.loc13_29.11: init %.3 = array_init (%.loc13_29.4, %.loc13_29.7, %.loc13_29.10) to %a.var [template = constants.%array]
  72. // CHECK:STDOUT: %.loc13_30: init %.3 = converted %.loc13_29.1, %.loc13_29.11 [template = constants.%array]
  73. // CHECK:STDOUT: assign %a.var, %.loc13_30
  74. // CHECK:STDOUT: %int.make_type_32.loc14_11: init type = call constants.%Int32() [template = i32]
  75. // CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
  76. // CHECK:STDOUT: %int.make_type_32.loc14_21: init type = call constants.%Int32() [template = i32]
  77. // CHECK:STDOUT: %.loc14_24.1: %.9 = tuple_literal (%int.make_type_32.loc14_11, %int.make_type_32.loc14_16, %int.make_type_32.loc14_21)
  78. // CHECK:STDOUT: %.loc14_24.2: type = value_of_initializer %int.make_type_32.loc14_11 [template = i32]
  79. // CHECK:STDOUT: %.loc14_24.3: type = converted %int.make_type_32.loc14_11, %.loc14_24.2 [template = i32]
  80. // CHECK:STDOUT: %.loc14_24.4: type = value_of_initializer %int.make_type_32.loc14_16 [template = i32]
  81. // CHECK:STDOUT: %.loc14_24.5: type = converted %int.make_type_32.loc14_16, %.loc14_24.4 [template = i32]
  82. // CHECK:STDOUT: %.loc14_24.6: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
  83. // CHECK:STDOUT: %.loc14_24.7: type = converted %int.make_type_32.loc14_21, %.loc14_24.6 [template = i32]
  84. // CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%.7 [template = constants.%.7]
  85. // CHECK:STDOUT: %b.var: ref %.7 = var b
  86. // CHECK:STDOUT: %b: ref %.7 = bind_name b, %b.var
  87. // CHECK:STDOUT: %.loc14_29: i32 = int_literal 1 [template = constants.%.5]
  88. // CHECK:STDOUT: %.loc14_32: i32 = int_literal 2 [template = constants.%.6]
  89. // CHECK:STDOUT: %.loc14_35: i32 = int_literal 3 [template = constants.%.2]
  90. // CHECK:STDOUT: %.loc14_36.1: %.7 = tuple_literal (%.loc14_29, %.loc14_32, %.loc14_35)
  91. // CHECK:STDOUT: %.loc14_36.2: ref i32 = tuple_access %b.var, element0
  92. // CHECK:STDOUT: %.loc14_36.3: init i32 = initialize_from %.loc14_29 to %.loc14_36.2 [template = constants.%.5]
  93. // CHECK:STDOUT: %.loc14_36.4: ref i32 = tuple_access %b.var, element1
  94. // CHECK:STDOUT: %.loc14_36.5: init i32 = initialize_from %.loc14_32 to %.loc14_36.4 [template = constants.%.6]
  95. // CHECK:STDOUT: %.loc14_36.6: ref i32 = tuple_access %b.var, element2
  96. // CHECK:STDOUT: %.loc14_36.7: init i32 = initialize_from %.loc14_35 to %.loc14_36.6 [template = constants.%.2]
  97. // CHECK:STDOUT: %.loc14_36.8: init %.7 = tuple_init (%.loc14_36.3, %.loc14_36.5, %.loc14_36.7) to %b.var [template = constants.%tuple]
  98. // CHECK:STDOUT: %.loc14_37: init %.7 = converted %.loc14_36.1, %.loc14_36.8 [template = constants.%tuple]
  99. // CHECK:STDOUT: assign %b.var, %.loc14_37
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  104. // CHECK:STDOUT: