array_vs_tuple.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: %G: %G.type = struct_value () [template]
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %.1: i32 = int_value 3 [template]
  23. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(Core.IntLiteral) [template]
  24. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  25. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  26. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
  27. // CHECK:STDOUT: %.26: <bound method> = bound_method %.1, %Convert.15 [template]
  28. // CHECK:STDOUT: %.27: Core.IntLiteral = int_value 3 [template]
  29. // CHECK:STDOUT: %.28: type = array_type %.27, i32 [template]
  30. // CHECK:STDOUT: %.30: i32 = int_value 1 [template]
  31. // CHECK:STDOUT: %.31: i32 = int_value 2 [template]
  32. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (i32, i32, i32) [template]
  33. // CHECK:STDOUT: %.32: i32 = int_value 0 [template]
  34. // CHECK:STDOUT: %array: %.28 = tuple_value (%.30, %.31, %.1) [template]
  35. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (type, type, type) [template]
  36. // CHECK:STDOUT: %tuple: %tuple.type.1 = tuple_value (%.30, %.31, %.1) [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .Int32 = %import_ref.1
  42. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/...
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .G = %G.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: fn @G() {
  58. // CHECK:STDOUT: !entry:
  59. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %.loc13_16.1: i32 = int_value 3 [template = constants.%.1]
  61. // CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  62. // CHECK:STDOUT: %.loc13_11.2: type = converted %int.make_type_32.loc13, %.loc13_11.1 [template = i32]
  63. // CHECK:STDOUT: %.loc13_16.2: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  64. // CHECK:STDOUT: %.loc13_16.3: <bound method> = bound_method %.loc13_16.1, %.loc13_16.2 [template = constants.%.26]
  65. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %.loc13_16.3(%.loc13_16.1) [template = constants.%.27]
  66. // CHECK:STDOUT: %.loc13_16.4: Core.IntLiteral = value_of_initializer %int.convert_checked [template = constants.%.27]
  67. // CHECK:STDOUT: %.loc13_16.5: Core.IntLiteral = converted %.loc13_16.1, %.loc13_16.4 [template = constants.%.27]
  68. // CHECK:STDOUT: %.loc13_17: type = array_type %.loc13_16.5, i32 [template = constants.%.28]
  69. // CHECK:STDOUT: %a.var: ref %.28 = var a
  70. // CHECK:STDOUT: %a: ref %.28 = bind_name a, %a.var
  71. // CHECK:STDOUT: %.loc13_22: i32 = int_value 1 [template = constants.%.30]
  72. // CHECK:STDOUT: %.loc13_25: i32 = int_value 2 [template = constants.%.31]
  73. // CHECK:STDOUT: %.loc13_28: i32 = int_value 3 [template = constants.%.1]
  74. // CHECK:STDOUT: %.loc13_29.1: %tuple.type.1 = tuple_literal (%.loc13_22, %.loc13_25, %.loc13_28)
  75. // CHECK:STDOUT: %.loc13_29.2: i32 = int_value 0 [template = constants.%.32]
  76. // CHECK:STDOUT: %.loc13_29.3: ref i32 = array_index %a.var, %.loc13_29.2
  77. // CHECK:STDOUT: %.loc13_29.4: init i32 = initialize_from %.loc13_22 to %.loc13_29.3 [template = constants.%.30]
  78. // CHECK:STDOUT: %.loc13_29.5: i32 = int_value 1 [template = constants.%.30]
  79. // CHECK:STDOUT: %.loc13_29.6: ref i32 = array_index %a.var, %.loc13_29.5
  80. // CHECK:STDOUT: %.loc13_29.7: init i32 = initialize_from %.loc13_25 to %.loc13_29.6 [template = constants.%.31]
  81. // CHECK:STDOUT: %.loc13_29.8: i32 = int_value 2 [template = constants.%.31]
  82. // CHECK:STDOUT: %.loc13_29.9: ref i32 = array_index %a.var, %.loc13_29.8
  83. // CHECK:STDOUT: %.loc13_29.10: init i32 = initialize_from %.loc13_28 to %.loc13_29.9 [template = constants.%.1]
  84. // CHECK:STDOUT: %.loc13_29.11: init %.28 = array_init (%.loc13_29.4, %.loc13_29.7, %.loc13_29.10) to %a.var [template = constants.%array]
  85. // CHECK:STDOUT: %.loc13_30: init %.28 = converted %.loc13_29.1, %.loc13_29.11 [template = constants.%array]
  86. // CHECK:STDOUT: assign %a.var, %.loc13_30
  87. // CHECK:STDOUT: %int.make_type_32.loc14_11: init type = call constants.%Int32() [template = i32]
  88. // CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
  89. // CHECK:STDOUT: %int.make_type_32.loc14_21: init type = call constants.%Int32() [template = i32]
  90. // CHECK:STDOUT: %.loc14_24.1: %tuple.type.2 = tuple_literal (%int.make_type_32.loc14_11, %int.make_type_32.loc14_16, %int.make_type_32.loc14_21)
  91. // CHECK:STDOUT: %.loc14_24.2: type = value_of_initializer %int.make_type_32.loc14_11 [template = i32]
  92. // CHECK:STDOUT: %.loc14_24.3: type = converted %int.make_type_32.loc14_11, %.loc14_24.2 [template = i32]
  93. // CHECK:STDOUT: %.loc14_24.4: type = value_of_initializer %int.make_type_32.loc14_16 [template = i32]
  94. // CHECK:STDOUT: %.loc14_24.5: type = converted %int.make_type_32.loc14_16, %.loc14_24.4 [template = i32]
  95. // CHECK:STDOUT: %.loc14_24.6: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
  96. // CHECK:STDOUT: %.loc14_24.7: type = converted %int.make_type_32.loc14_21, %.loc14_24.6 [template = i32]
  97. // CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%tuple.type.1 [template = constants.%tuple.type.1]
  98. // CHECK:STDOUT: %b.var: ref %tuple.type.1 = var b
  99. // CHECK:STDOUT: %b: ref %tuple.type.1 = bind_name b, %b.var
  100. // CHECK:STDOUT: %.loc14_29: i32 = int_value 1 [template = constants.%.30]
  101. // CHECK:STDOUT: %.loc14_32: i32 = int_value 2 [template = constants.%.31]
  102. // CHECK:STDOUT: %.loc14_35: i32 = int_value 3 [template = constants.%.1]
  103. // CHECK:STDOUT: %.loc14_36.1: %tuple.type.1 = tuple_literal (%.loc14_29, %.loc14_32, %.loc14_35)
  104. // CHECK:STDOUT: %.loc14_36.2: ref i32 = tuple_access %b.var, element0
  105. // CHECK:STDOUT: %.loc14_36.3: init i32 = initialize_from %.loc14_29 to %.loc14_36.2 [template = constants.%.30]
  106. // CHECK:STDOUT: %.loc14_36.4: ref i32 = tuple_access %b.var, element1
  107. // CHECK:STDOUT: %.loc14_36.5: init i32 = initialize_from %.loc14_32 to %.loc14_36.4 [template = constants.%.31]
  108. // CHECK:STDOUT: %.loc14_36.6: ref i32 = tuple_access %b.var, element2
  109. // CHECK:STDOUT: %.loc14_36.7: init i32 = initialize_from %.loc14_35 to %.loc14_36.6 [template = constants.%.1]
  110. // CHECK:STDOUT: %.loc14_36.8: init %tuple.type.1 = tuple_init (%.loc14_36.3, %.loc14_36.5, %.loc14_36.7) to %b.var [template = constants.%tuple]
  111. // CHECK:STDOUT: %.loc14_37: init %tuple.type.1 = converted %.loc14_36.1, %.loc14_36.8 [template = constants.%tuple]
  112. // CHECK:STDOUT: assign %b.var, %.loc14_37
  113. // CHECK:STDOUT: return
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: