struct.carbon 6.7 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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/return/struct.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/return/struct.carbon
  14. fn Main() -> {.a: i32} {
  15. return {.a = 3};
  16. }
  17. // CHECK:STDOUT: --- struct.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  21. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  22. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  23. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  24. // CHECK:STDOUT: %struct_type.a.ba9: type = struct_type {.a: %i32} [concrete]
  25. // CHECK:STDOUT: %pattern_type.268: type = pattern_type %struct_type.a.ba9 [concrete]
  26. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  27. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [concrete]
  29. // CHECK:STDOUT: %struct_type.a.a6c: type = struct_type {.a: Core.IntLiteral} [concrete]
  30. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  32. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  33. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  34. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  35. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @ImplicitAs.impl.4f9(%To) [symbolic]
  36. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  37. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @ImplicitAs.impl.4f9(%int_32) [concrete]
  38. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @ImplicitAs.impl.4f9(%int_32) [concrete]
  39. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  40. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  41. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  42. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_3.1ba, %Convert.956 [concrete]
  43. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  44. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_3.1ba, %Convert.specific_fn [concrete]
  45. // CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [concrete]
  46. // CHECK:STDOUT: %struct: %struct_type.a.ba9 = struct_value (%int_3.822) [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  51. // CHECK:STDOUT: .Int = %Core.Int
  52. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  53. // CHECK:STDOUT: import Core//prelude
  54. // CHECK:STDOUT: import Core//prelude/...
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  57. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  58. // CHECK:STDOUT: %Core.import_ref.a5b: @ImplicitAs.impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/parts/int, loc16_39, loaded [symbolic = @ImplicitAs.impl.4f9.%Convert (constants.%Convert.f06)]
  59. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @ImplicitAs.impl.4f9 [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .Main = %Main.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {
  69. // CHECK:STDOUT: %return.patt: %pattern_type.268 = return_slot_pattern [concrete]
  70. // CHECK:STDOUT: %return.param_patt: %pattern_type.268 = out_param_pattern %return.patt, call_param0 [concrete]
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  73. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  74. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete = constants.%struct_type.a.ba9]
  75. // CHECK:STDOUT: %return.param: ref %struct_type.a.ba9 = out_param call_param0
  76. // CHECK:STDOUT: %return: ref %struct_type.a.ba9 = return_slot %return.param
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @Main() -> %struct_type.a.ba9 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
  83. // CHECK:STDOUT: %.loc16_17.1: %struct_type.a.a6c = struct_literal (%int_3)
  84. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  85. // CHECK:STDOUT: %bound_method.loc16_17.1: <bound method> = bound_method %int_3, %impl.elem0 [concrete = constants.%Convert.bound]
  86. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  87. // CHECK:STDOUT: %bound_method.loc16_17.2: <bound method> = bound_method %int_3, %specific_fn [concrete = constants.%bound_method]
  88. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc16_17.2(%int_3) [concrete = constants.%int_3.822]
  89. // CHECK:STDOUT: %.loc16_17.2: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_3.822]
  90. // CHECK:STDOUT: %.loc16_17.3: %i32 = converted %int_3, %.loc16_17.2 [concrete = constants.%int_3.822]
  91. // CHECK:STDOUT: %struct: %struct_type.a.ba9 = struct_value (%.loc16_17.3) [concrete = constants.%struct]
  92. // CHECK:STDOUT: %.loc16_18: %struct_type.a.ba9 = converted %.loc16_17.1, %struct [concrete = constants.%struct]
  93. // CHECK:STDOUT: return %.loc16_18
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: