tuple.carbon 6.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.471: 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: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  26. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  27. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  28. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  29. // CHECK:STDOUT: %Convert.bound.bc3: <bound method> = bound_method %int_15.447, %Convert.925 [template]
  30. // CHECK:STDOUT: %Convert.specific_fn.098: <specific function> = specific_function %Convert.bound.bc3, @Convert.2(%int_32) [template]
  31. // CHECK:STDOUT: %int_15.761: %i32 = int_value 15 [template]
  32. // CHECK:STDOUT: %Convert.bound.9e7: <bound method> = bound_method %int_35.c79, %Convert.925 [template]
  33. // CHECK:STDOUT: %Convert.specific_fn.dba: <specific function> = specific_function %Convert.bound.9e7, @Convert.2(%int_32) [template]
  34. // CHECK:STDOUT: %int_35.545: %i32 = int_value 35 [template]
  35. // CHECK:STDOUT: %tuple: %tuple.type.471 = tuple_value (%int_15.761, %int_35.545) [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  40. // CHECK:STDOUT: .Int = %import_ref.187
  41. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/...
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = imports.%Core
  50. // CHECK:STDOUT: .Main = %Main.decl
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {
  54. // CHECK:STDOUT: %return.patt: %tuple.type.471 = return_slot_pattern
  55. // CHECK:STDOUT: %return.param_patt: %tuple.type.471 = out_param_pattern %return.patt, runtime_param0
  56. // CHECK:STDOUT: } {
  57. // CHECK:STDOUT: %int_32.loc12_15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc12_15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  59. // CHECK:STDOUT: %int_32.loc12_20: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc12_20: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  61. // CHECK:STDOUT: %.loc12_23.1: %tuple.type.24b = tuple_literal (%i32.loc12_15, %i32.loc12_20)
  62. // CHECK:STDOUT: %.loc12_23.2: type = converted %.loc12_23.1, constants.%tuple.type.471 [template = constants.%tuple.type.471]
  63. // CHECK:STDOUT: %return.param: ref %tuple.type.471 = out_param runtime_param0
  64. // CHECK:STDOUT: %return: ref %tuple.type.471 = return_slot %return.param
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @Main() -> %return.param_patt: %tuple.type.471 {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: %int_15: Core.IntLiteral = int_value 15 [template = constants.%int_15.447]
  71. // CHECK:STDOUT: %int_35: Core.IntLiteral = int_value 35 [template = constants.%int_35.c79]
  72. // CHECK:STDOUT: %.loc13_17.1: %tuple.type.f94 = tuple_literal (%int_15, %int_35)
  73. // CHECK:STDOUT: %impl.elem0.loc13_17.1: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  74. // CHECK:STDOUT: %Convert.bound.loc13_17.1: <bound method> = bound_method %int_15, %impl.elem0.loc13_17.1 [template = constants.%Convert.bound.bc3]
  75. // CHECK:STDOUT: %Convert.specific_fn.loc13_17.1: <specific function> = specific_function %Convert.bound.loc13_17.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.098]
  76. // CHECK:STDOUT: %int.convert_checked.loc13_17.1: init %i32 = call %Convert.specific_fn.loc13_17.1(%int_15) [template = constants.%int_15.761]
  77. // CHECK:STDOUT: %.loc13_17.2: init %i32 = converted %int_15, %int.convert_checked.loc13_17.1 [template = constants.%int_15.761]
  78. // CHECK:STDOUT: %tuple.elem0: ref %i32 = tuple_access %return, element0
  79. // CHECK:STDOUT: %.loc13_17.3: init %i32 = initialize_from %.loc13_17.2 to %tuple.elem0 [template = constants.%int_15.761]
  80. // CHECK:STDOUT: %impl.elem0.loc13_17.2: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  81. // CHECK:STDOUT: %Convert.bound.loc13_17.2: <bound method> = bound_method %int_35, %impl.elem0.loc13_17.2 [template = constants.%Convert.bound.9e7]
  82. // CHECK:STDOUT: %Convert.specific_fn.loc13_17.2: <specific function> = specific_function %Convert.bound.loc13_17.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.dba]
  83. // CHECK:STDOUT: %int.convert_checked.loc13_17.2: init %i32 = call %Convert.specific_fn.loc13_17.2(%int_35) [template = constants.%int_35.545]
  84. // CHECK:STDOUT: %.loc13_17.4: init %i32 = converted %int_35, %int.convert_checked.loc13_17.2 [template = constants.%int_35.545]
  85. // CHECK:STDOUT: %tuple.elem1: ref %i32 = tuple_access %return, element1
  86. // CHECK:STDOUT: %.loc13_17.5: init %i32 = initialize_from %.loc13_17.4 to %tuple.elem1 [template = constants.%int_35.545]
  87. // CHECK:STDOUT: %.loc13_17.6: init %tuple.type.471 = tuple_init (%.loc13_17.3, %.loc13_17.5) to %return [template = constants.%tuple]
  88. // CHECK:STDOUT: %.loc13_18: init %tuple.type.471 = converted %.loc13_17.1, %.loc13_17.6 [template = constants.%tuple]
  89. // CHECK:STDOUT: return %.loc13_18 to %return
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: