convert.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int32 = %import_ref
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/operators
  38. // CHECK:STDOUT: import Core//prelude/types
  39. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  40. // CHECK:STDOUT: import Core//prelude/operators/as
  41. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  42. // CHECK:STDOUT: import Core//prelude/operators/comparison
  43. // CHECK:STDOUT: import Core//prelude/types/bool
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  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: .F = %F.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {
  55. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  57. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32.loc11, %.loc11_11.1 [template = i32]
  58. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @F() -> i32 {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: %int.make_type_32.loc12_11: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %int.make_type_32.loc12_16: init type = call constants.%Int32() [template = i32]
  68. // CHECK:STDOUT: %int.make_type_32.loc12_21: init type = call constants.%Int32() [template = i32]
  69. // 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)
  70. // CHECK:STDOUT: %.loc12_24.2: type = value_of_initializer %int.make_type_32.loc12_11 [template = i32]
  71. // CHECK:STDOUT: %.loc12_24.3: type = converted %int.make_type_32.loc12_11, %.loc12_24.2 [template = i32]
  72. // CHECK:STDOUT: %.loc12_24.4: type = value_of_initializer %int.make_type_32.loc12_16 [template = i32]
  73. // CHECK:STDOUT: %.loc12_24.5: type = converted %int.make_type_32.loc12_16, %.loc12_24.4 [template = i32]
  74. // CHECK:STDOUT: %.loc12_24.6: type = value_of_initializer %int.make_type_32.loc12_21 [template = i32]
  75. // CHECK:STDOUT: %.loc12_24.7: type = converted %int.make_type_32.loc12_21, %.loc12_24.6 [template = i32]
  76. // CHECK:STDOUT: %.loc12_24.8: type = converted %.loc12_24.1, constants.%.3 [template = constants.%.3]
  77. // CHECK:STDOUT: %v.var: ref %.3 = var v
  78. // CHECK:STDOUT: %v: ref %.3 = bind_name v, %v.var
  79. // CHECK:STDOUT: %.loc12_29: i32 = int_literal 1 [template = constants.%.5]
  80. // CHECK:STDOUT: %.loc12_32: i32 = int_literal 2 [template = constants.%.6]
  81. // CHECK:STDOUT: %.loc12_35: i32 = int_literal 3 [template = constants.%.7]
  82. // CHECK:STDOUT: %.loc12_36.1: %.3 = tuple_literal (%.loc12_29, %.loc12_32, %.loc12_35)
  83. // CHECK:STDOUT: %.loc12_36.2: ref i32 = tuple_access %v.var, element0
  84. // CHECK:STDOUT: %.loc12_36.3: init i32 = initialize_from %.loc12_29 to %.loc12_36.2 [template = constants.%.5]
  85. // CHECK:STDOUT: %.loc12_36.4: ref i32 = tuple_access %v.var, element1
  86. // CHECK:STDOUT: %.loc12_36.5: init i32 = initialize_from %.loc12_32 to %.loc12_36.4 [template = constants.%.6]
  87. // CHECK:STDOUT: %.loc12_36.6: ref i32 = tuple_access %v.var, element2
  88. // CHECK:STDOUT: %.loc12_36.7: init i32 = initialize_from %.loc12_35 to %.loc12_36.6 [template = constants.%.7]
  89. // CHECK:STDOUT: %.loc12_36.8: init %.3 = tuple_init (%.loc12_36.3, %.loc12_36.5, %.loc12_36.7) to %v.var [template = constants.%tuple]
  90. // CHECK:STDOUT: %.loc12_37: init %.3 = converted %.loc12_36.1, %.loc12_36.8 [template = constants.%tuple]
  91. // CHECK:STDOUT: assign %v.var, %.loc12_37
  92. // CHECK:STDOUT: %int.make_type_32.loc14_11: init type = call constants.%Int32() [template = i32]
  93. // CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
  94. // CHECK:STDOUT: %int.make_type_32.loc14_21: init type = call constants.%Int32() [template = i32]
  95. // 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)
  96. // CHECK:STDOUT: %.loc14_24.2: type = value_of_initializer %int.make_type_32.loc14_11 [template = i32]
  97. // CHECK:STDOUT: %.loc14_24.3: type = converted %int.make_type_32.loc14_11, %.loc14_24.2 [template = i32]
  98. // CHECK:STDOUT: %.loc14_24.4: type = value_of_initializer %int.make_type_32.loc14_16 [template = i32]
  99. // CHECK:STDOUT: %.loc14_24.5: type = converted %int.make_type_32.loc14_16, %.loc14_24.4 [template = i32]
  100. // CHECK:STDOUT: %.loc14_24.6: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
  101. // CHECK:STDOUT: %.loc14_24.7: type = converted %int.make_type_32.loc14_21, %.loc14_24.6 [template = i32]
  102. // CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%.3 [template = constants.%.3]
  103. // CHECK:STDOUT: %v.ref: ref %.3 = name_ref v, %v
  104. // CHECK:STDOUT: %.loc14_28.1: ref i32 = tuple_access %v.ref, element0
  105. // CHECK:STDOUT: %.loc14_28.2: i32 = bind_value %.loc14_28.1
  106. // CHECK:STDOUT: %.loc14_28.3: ref i32 = tuple_access %v.ref, element1
  107. // CHECK:STDOUT: %.loc14_28.4: i32 = bind_value %.loc14_28.3
  108. // CHECK:STDOUT: %.loc14_28.5: ref i32 = tuple_access %v.ref, element2
  109. // CHECK:STDOUT: %.loc14_28.6: i32 = bind_value %.loc14_28.5
  110. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.loc14_28.2, %.loc14_28.4, %.loc14_28.6)
  111. // CHECK:STDOUT: %.loc14_29: %.3 = converted %v.ref, %tuple
  112. // CHECK:STDOUT: %w: %.3 = bind_name w, %.loc14_29
  113. // CHECK:STDOUT: %w.ref: %.3 = name_ref w, %w
  114. // CHECK:STDOUT: %.loc15_12: i32 = int_literal 1 [template = constants.%.5]
  115. // CHECK:STDOUT: %.loc15_11: i32 = tuple_access %w.ref, element1
  116. // CHECK:STDOUT: return %.loc15_11
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: