convert.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/let/convert.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/convert.carbon
  10. fn F() -> i32 {
  11. var v: (i32, i32, i32) = (1, 2, 3);
  12. // Convert from object representation to value representation.
  13. let w: (i32, i32, i32) = v;
  14. return w[1];
  15. }
  16. // CHECK:STDOUT: --- convert.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  23. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  24. // CHECK:STDOUT: %.2: type = tuple_type (type, type, type) [template]
  25. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32, i32) [template]
  26. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  27. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  28. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  29. // CHECK:STDOUT: %.7: i32 = int_literal 3 [template]
  30. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5, %.6, %.7) [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  35. // CHECK:STDOUT: .Core = %Core
  36. // CHECK:STDOUT: .F = %F.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  39. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  40. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  41. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  42. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  43. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32, %.loc11_11.1 [template = i32]
  44. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  47. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  48. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  49. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: fn @F() -> i32 {
  57. // CHECK:STDOUT: !entry:
  58. // CHECK:STDOUT: %int.make_type_32.loc12_11: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %int.make_type_32.loc12_16: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %int.make_type_32.loc12_21: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc12_24.1: %.2 = tuple_literal (%int.make_type_32.loc12_11, %int.make_type_32.loc12_16, %int.make_type_32.loc12_21)
  62. // CHECK:STDOUT: %.loc12_24.2: type = value_of_initializer %int.make_type_32.loc12_11 [template = i32]
  63. // CHECK:STDOUT: %.loc12_24.3: type = converted %int.make_type_32.loc12_11, %.loc12_24.2 [template = i32]
  64. // CHECK:STDOUT: %.loc12_24.4: type = value_of_initializer %int.make_type_32.loc12_16 [template = i32]
  65. // CHECK:STDOUT: %.loc12_24.5: type = converted %int.make_type_32.loc12_16, %.loc12_24.4 [template = i32]
  66. // CHECK:STDOUT: %.loc12_24.6: type = value_of_initializer %int.make_type_32.loc12_21 [template = i32]
  67. // CHECK:STDOUT: %.loc12_24.7: type = converted %int.make_type_32.loc12_21, %.loc12_24.6 [template = i32]
  68. // CHECK:STDOUT: %.loc12_24.8: type = converted %.loc12_24.1, constants.%.3 [template = constants.%.3]
  69. // CHECK:STDOUT: %v.var: ref %.3 = var v
  70. // CHECK:STDOUT: %v: ref %.3 = bind_name v, %v.var
  71. // CHECK:STDOUT: %.loc12_29: i32 = int_literal 1 [template = constants.%.5]
  72. // CHECK:STDOUT: %.loc12_32: i32 = int_literal 2 [template = constants.%.6]
  73. // CHECK:STDOUT: %.loc12_35: i32 = int_literal 3 [template = constants.%.7]
  74. // CHECK:STDOUT: %.loc12_36.1: %.3 = tuple_literal (%.loc12_29, %.loc12_32, %.loc12_35)
  75. // CHECK:STDOUT: %.loc12_36.2: ref i32 = tuple_access %v.var, element0
  76. // CHECK:STDOUT: %.loc12_36.3: init i32 = initialize_from %.loc12_29 to %.loc12_36.2 [template = constants.%.5]
  77. // CHECK:STDOUT: %.loc12_36.4: ref i32 = tuple_access %v.var, element1
  78. // CHECK:STDOUT: %.loc12_36.5: init i32 = initialize_from %.loc12_32 to %.loc12_36.4 [template = constants.%.6]
  79. // CHECK:STDOUT: %.loc12_36.6: ref i32 = tuple_access %v.var, element2
  80. // CHECK:STDOUT: %.loc12_36.7: init i32 = initialize_from %.loc12_35 to %.loc12_36.6 [template = constants.%.7]
  81. // CHECK:STDOUT: %.loc12_36.8: init %.3 = tuple_init (%.loc12_36.3, %.loc12_36.5, %.loc12_36.7) to %v.var [template = constants.%tuple]
  82. // CHECK:STDOUT: %.loc12_37: init %.3 = converted %.loc12_36.1, %.loc12_36.8 [template = constants.%tuple]
  83. // CHECK:STDOUT: assign %v.var, %.loc12_37
  84. // CHECK:STDOUT: %int.make_type_32.loc14_11: init type = call constants.%Int32() [template = i32]
  85. // CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
  86. // CHECK:STDOUT: %int.make_type_32.loc14_21: init type = call constants.%Int32() [template = i32]
  87. // CHECK:STDOUT: %.loc14_24.1: %.2 = tuple_literal (%int.make_type_32.loc14_11, %int.make_type_32.loc14_16, %int.make_type_32.loc14_21)
  88. // CHECK:STDOUT: %.loc14_24.2: type = value_of_initializer %int.make_type_32.loc14_11 [template = i32]
  89. // CHECK:STDOUT: %.loc14_24.3: type = converted %int.make_type_32.loc14_11, %.loc14_24.2 [template = i32]
  90. // CHECK:STDOUT: %.loc14_24.4: type = value_of_initializer %int.make_type_32.loc14_16 [template = i32]
  91. // CHECK:STDOUT: %.loc14_24.5: type = converted %int.make_type_32.loc14_16, %.loc14_24.4 [template = i32]
  92. // CHECK:STDOUT: %.loc14_24.6: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
  93. // CHECK:STDOUT: %.loc14_24.7: type = converted %int.make_type_32.loc14_21, %.loc14_24.6 [template = i32]
  94. // CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%.3 [template = constants.%.3]
  95. // CHECK:STDOUT: %v.ref: ref %.3 = name_ref v, %v
  96. // CHECK:STDOUT: %.loc14_28.1: ref i32 = tuple_access %v.ref, element0
  97. // CHECK:STDOUT: %.loc14_28.2: i32 = bind_value %.loc14_28.1
  98. // CHECK:STDOUT: %.loc14_28.3: ref i32 = tuple_access %v.ref, element1
  99. // CHECK:STDOUT: %.loc14_28.4: i32 = bind_value %.loc14_28.3
  100. // CHECK:STDOUT: %.loc14_28.5: ref i32 = tuple_access %v.ref, element2
  101. // CHECK:STDOUT: %.loc14_28.6: i32 = bind_value %.loc14_28.5
  102. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.loc14_28.2, %.loc14_28.4, %.loc14_28.6)
  103. // CHECK:STDOUT: %.loc14_29: %.3 = converted %v.ref, %tuple
  104. // CHECK:STDOUT: %w: %.3 = bind_name w, %.loc14_29
  105. // CHECK:STDOUT: %w.ref: %.3 = name_ref w, %w
  106. // CHECK:STDOUT: %.loc15_12: i32 = int_literal 1 [template = constants.%.5]
  107. // CHECK:STDOUT: %.loc15_13: i32 = tuple_index %w.ref, %.loc15_12
  108. // CHECK:STDOUT: return %.loc15_13
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: