tuple.carbon 7.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/return/tuple.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/return/tuple.carbon
  10. fn Main() -> (i32, i32) {
  11. return (15, 35);
  12. }
  13. // CHECK:STDOUT: --- tuple.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  17. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  18. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [template]
  19. // CHECK:STDOUT: %tuple.type.d07: type = tuple_type (%i32, %i32) [template]
  20. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  21. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  22. // CHECK:STDOUT: %int_15.447: Core.IntLiteral = int_value 15 [template]
  23. // CHECK:STDOUT: %int_35.c79: Core.IntLiteral = int_value 35 [template]
  24. // CHECK:STDOUT: %tuple.type.f94: type = tuple_type (Core.IntLiteral, Core.IntLiteral) [template]
  25. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  26. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  27. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  28. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  29. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  30. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  31. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  32. // CHECK:STDOUT: %Convert.bound.75f: <bound method> = bound_method %int_15.447, %Convert.956 [template]
  33. // CHECK:STDOUT: %Convert.specific_fn.c46: <specific function> = specific_function %Convert.bound.75f, @Convert.2(%int_32) [template]
  34. // CHECK:STDOUT: %int_15.7f7: %i32 = int_value 15 [template]
  35. // CHECK:STDOUT: %Convert.bound.76a: <bound method> = bound_method %int_35.c79, %Convert.956 [template]
  36. // CHECK:STDOUT: %Convert.specific_fn.9b5: <specific function> = specific_function %Convert.bound.76a, @Convert.2(%int_32) [template]
  37. // CHECK:STDOUT: %int_35.c78: %i32 = int_value 35 [template]
  38. // CHECK:STDOUT: %tuple: %tuple.type.d07 = tuple_value (%int_15.7f7, %int_35.c78) [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  43. // CHECK:STDOUT: .Int = %Core.Int
  44. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/...
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  52. // CHECK:STDOUT: .Core = imports.%Core
  53. // CHECK:STDOUT: .Main = %Main.decl
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core.import = import Core
  56. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {
  57. // CHECK:STDOUT: %return.patt: %tuple.type.d07 = return_slot_pattern
  58. // CHECK:STDOUT: %return.param_patt: %tuple.type.d07 = out_param_pattern %return.patt, runtime_param0
  59. // CHECK:STDOUT: } {
  60. // CHECK:STDOUT: %int_32.loc12_15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  61. // CHECK:STDOUT: %i32.loc12_15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  62. // CHECK:STDOUT: %int_32.loc12_20: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  63. // CHECK:STDOUT: %i32.loc12_20: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  64. // CHECK:STDOUT: %.loc12_23.1: %tuple.type.24b = tuple_literal (%i32.loc12_15, %i32.loc12_20)
  65. // CHECK:STDOUT: %.loc12_23.2: type = converted %.loc12_23.1, constants.%tuple.type.d07 [template = constants.%tuple.type.d07]
  66. // CHECK:STDOUT: %return.param: ref %tuple.type.d07 = out_param runtime_param0
  67. // CHECK:STDOUT: %return: ref %tuple.type.d07 = return_slot %return.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @Main() -> %return.param_patt: %tuple.type.d07 {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %int_15: Core.IntLiteral = int_value 15 [template = constants.%int_15.447]
  74. // CHECK:STDOUT: %int_35: Core.IntLiteral = int_value 35 [template = constants.%int_35.c79]
  75. // CHECK:STDOUT: %.loc13_17.1: %tuple.type.f94 = tuple_literal (%int_15, %int_35)
  76. // CHECK:STDOUT: %impl.elem0.loc13_17.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  77. // CHECK:STDOUT: %bound_method.loc13_17.1: <bound method> = bound_method %int_15, %impl.elem0.loc13_17.1 [template = constants.%Convert.bound.75f]
  78. // CHECK:STDOUT: %specific_fn.loc13_17.1: <specific function> = specific_function %bound_method.loc13_17.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.c46]
  79. // CHECK:STDOUT: %int.convert_checked.loc13_17.1: init %i32 = call %specific_fn.loc13_17.1(%int_15) [template = constants.%int_15.7f7]
  80. // CHECK:STDOUT: %.loc13_17.2: init %i32 = converted %int_15, %int.convert_checked.loc13_17.1 [template = constants.%int_15.7f7]
  81. // CHECK:STDOUT: %tuple.elem0: ref %i32 = tuple_access %return, element0
  82. // CHECK:STDOUT: %.loc13_17.3: init %i32 = initialize_from %.loc13_17.2 to %tuple.elem0 [template = constants.%int_15.7f7]
  83. // CHECK:STDOUT: %impl.elem0.loc13_17.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  84. // CHECK:STDOUT: %bound_method.loc13_17.2: <bound method> = bound_method %int_35, %impl.elem0.loc13_17.2 [template = constants.%Convert.bound.76a]
  85. // CHECK:STDOUT: %specific_fn.loc13_17.2: <specific function> = specific_function %bound_method.loc13_17.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.9b5]
  86. // CHECK:STDOUT: %int.convert_checked.loc13_17.2: init %i32 = call %specific_fn.loc13_17.2(%int_35) [template = constants.%int_35.c78]
  87. // CHECK:STDOUT: %.loc13_17.4: init %i32 = converted %int_35, %int.convert_checked.loc13_17.2 [template = constants.%int_35.c78]
  88. // CHECK:STDOUT: %tuple.elem1: ref %i32 = tuple_access %return, element1
  89. // CHECK:STDOUT: %.loc13_17.5: init %i32 = initialize_from %.loc13_17.4 to %tuple.elem1 [template = constants.%int_35.c78]
  90. // CHECK:STDOUT: %.loc13_17.6: init %tuple.type.d07 = tuple_init (%.loc13_17.3, %.loc13_17.5) to %return [template = constants.%tuple]
  91. // CHECK:STDOUT: %.loc13_18: init %tuple.type.d07 = converted %.loc13_17.1, %.loc13_17.6 [template = constants.%tuple]
  92. // CHECK:STDOUT: return %.loc13_18 to %return
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: