nested_struct_in_place.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/struct/nested_struct_in_place.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/nested_struct_in_place.carbon
  10. fn F() -> (i32, i32, i32);
  11. fn G() {
  12. var v: {.a: (i32, i32, i32), .b: (i32, i32, i32)} = {.a = F(), .b = F()};
  13. }
  14. // CHECK:STDOUT: --- nested_struct_in_place.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  18. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  19. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  21. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [concrete]
  22. // CHECK:STDOUT: %tuple.type.189: type = tuple_type (%i32, %i32, %i32) [concrete]
  23. // CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  27. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %struct_type.a.b.2f9: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete]
  29. // CHECK:STDOUT: %pattern_type.3c2: type = pattern_type %struct_type.a.b.2f9 [concrete]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  34. // CHECK:STDOUT: .Int = %Core.Int
  35. // CHECK:STDOUT: import Core//prelude
  36. // CHECK:STDOUT: import Core//prelude/...
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .F = %F.decl
  45. // CHECK:STDOUT: .G = %G.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  49. // CHECK:STDOUT: %return.patt: %pattern_type.b5a = return_slot_pattern [concrete]
  50. // CHECK:STDOUT: %return.param_patt: %pattern_type.b5a = out_param_pattern %return.patt, call_param0 [concrete]
  51. // CHECK:STDOUT: } {
  52. // CHECK:STDOUT: %int_32.loc11_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  53. // CHECK:STDOUT: %i32.loc11_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  54. // CHECK:STDOUT: %int_32.loc11_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  55. // CHECK:STDOUT: %i32.loc11_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  56. // CHECK:STDOUT: %int_32.loc11_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  57. // CHECK:STDOUT: %i32.loc11_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  58. // CHECK:STDOUT: %.loc11_25.1: %tuple.type.ff9 = tuple_literal (%i32.loc11_12, %i32.loc11_17, %i32.loc11_22)
  59. // CHECK:STDOUT: %.loc11_25.2: type = converted %.loc11_25.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  60. // CHECK:STDOUT: %return.param: ref %tuple.type.189 = out_param call_param0
  61. // CHECK:STDOUT: %return: ref %tuple.type.189 = return_slot %return.param
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @F() -> %return.param: %tuple.type.189;
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @G() {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: name_binding_decl {
  71. // CHECK:STDOUT: %v.patt: %pattern_type.3c2 = binding_pattern v [concrete]
  72. // CHECK:STDOUT: %v.var_patt: %pattern_type.3c2 = var_pattern %v.patt [concrete]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %v.var: ref %struct_type.a.b.2f9 = var %v.var_patt
  75. // CHECK:STDOUT: %F.ref.loc14_61: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  76. // CHECK:STDOUT: %.loc14_74.1: ref %tuple.type.189 = struct_access %v.var, element0
  77. // CHECK:STDOUT: %F.call.loc14_63: init %tuple.type.189 = call %F.ref.loc14_61() to %.loc14_74.1
  78. // CHECK:STDOUT: %F.ref.loc14_71: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  79. // CHECK:STDOUT: %.loc14_74.2: ref %tuple.type.189 = struct_access %v.var, element1
  80. // CHECK:STDOUT: %F.call.loc14_73: init %tuple.type.189 = call %F.ref.loc14_71() to %.loc14_74.2
  81. // CHECK:STDOUT: %.loc14_74.3: %struct_type.a.b.2f9 = struct_literal (%F.call.loc14_63, %F.call.loc14_73)
  82. // CHECK:STDOUT: %.loc14_74.4: init %struct_type.a.b.2f9 = struct_init (%F.call.loc14_63, %F.call.loc14_73) to %v.var
  83. // CHECK:STDOUT: %.loc14_3: init %struct_type.a.b.2f9 = converted %.loc14_74.3, %.loc14_74.4
  84. // CHECK:STDOUT: assign %v.var, %.loc14_3
  85. // CHECK:STDOUT: %.loc14_51: type = splice_block %struct_type.a.b [concrete = constants.%struct_type.a.b.2f9] {
  86. // CHECK:STDOUT: %int_32.loc14_16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  87. // CHECK:STDOUT: %i32.loc14_16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  88. // CHECK:STDOUT: %int_32.loc14_21: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  89. // CHECK:STDOUT: %i32.loc14_21: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  90. // CHECK:STDOUT: %int_32.loc14_26: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  91. // CHECK:STDOUT: %i32.loc14_26: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  92. // CHECK:STDOUT: %.loc14_29.1: %tuple.type.ff9 = tuple_literal (%i32.loc14_16, %i32.loc14_21, %i32.loc14_26)
  93. // CHECK:STDOUT: %.loc14_29.2: type = converted %.loc14_29.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  94. // CHECK:STDOUT: %int_32.loc14_37: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  95. // CHECK:STDOUT: %i32.loc14_37: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  96. // CHECK:STDOUT: %int_32.loc14_42: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  97. // CHECK:STDOUT: %i32.loc14_42: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  98. // CHECK:STDOUT: %int_32.loc14_47: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc14_47: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  100. // CHECK:STDOUT: %.loc14_50.1: %tuple.type.ff9 = tuple_literal (%i32.loc14_37, %i32.loc14_42, %i32.loc14_47)
  101. // CHECK:STDOUT: %.loc14_50.2: type = converted %.loc14_50.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  102. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete = constants.%struct_type.a.b.2f9]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %v: ref %struct_type.a.b.2f9 = bind_name v, %v.var
  105. // CHECK:STDOUT: return
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: