nested_struct_in_place.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/struct/nested_struct_in_place.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/nested_struct_in_place.carbon
  14. fn F() -> (i32, i32, i32);
  15. fn G() {
  16. var unused v: {.a: (i32, i32, i32), .b: (i32, i32, i32)} = {.a = F(), .b = F()};
  17. }
  18. // CHECK:STDOUT: --- nested_struct_in_place.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  22. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  23. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  24. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  26. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [concrete]
  27. // CHECK:STDOUT: %tuple: %tuple.type.ff9 = tuple_value (%i32, %i32, %i32) [concrete]
  28. // CHECK:STDOUT: %tuple.type.189: type = tuple_type (%i32, %i32, %i32) [concrete]
  29. // CHECK:STDOUT: %.594: Core.Form = init_form %tuple.type.189, call_param0 [concrete]
  30. // CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  32. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  33. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  34. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %struct_type.a.b.2f9: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete]
  36. // CHECK:STDOUT: %pattern_type.3c2: type = pattern_type %struct_type.a.b.2f9 [concrete]
  37. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  38. // CHECK:STDOUT: %DestroyOp.type: type = fn_type @DestroyOp [concrete]
  39. // CHECK:STDOUT: %DestroyOp: %DestroyOp.type = struct_value () [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  44. // CHECK:STDOUT: .Int = %Core.Int
  45. // CHECK:STDOUT: .Destroy = %Core.Destroy
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  50. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .F = %F.decl
  57. // CHECK:STDOUT: .G = %G.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  61. // CHECK:STDOUT: %return.patt: %pattern_type.b5a = return_slot_pattern [concrete]
  62. // CHECK:STDOUT: %return.param_patt: %pattern_type.b5a = out_param_pattern %return.patt, call_param0 [concrete]
  63. // CHECK:STDOUT: } {
  64. // CHECK:STDOUT: %int_32.loc15_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  65. // CHECK:STDOUT: %i32.loc15_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  66. // CHECK:STDOUT: %int_32.loc15_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  67. // CHECK:STDOUT: %i32.loc15_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  68. // CHECK:STDOUT: %int_32.loc15_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  69. // CHECK:STDOUT: %i32.loc15_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  70. // CHECK:STDOUT: %.loc15_25.1: %tuple.type.ff9 = tuple_literal (%i32.loc15_12, %i32.loc15_17, %i32.loc15_22) [concrete = constants.%tuple]
  71. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_25.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  72. // CHECK:STDOUT: %.loc15_25.3: Core.Form = init_form %.loc15_25.2, call_param0 [concrete = constants.%.594]
  73. // CHECK:STDOUT: %return.param: ref %tuple.type.189 = out_param call_param0
  74. // CHECK:STDOUT: %return: ref %tuple.type.189 = return_slot %return.param
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @F() -> out %return.param: %tuple.type.189;
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @G() {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: name_binding_decl {
  84. // CHECK:STDOUT: %v.patt: %pattern_type.3c2 = ref_binding_pattern v [concrete]
  85. // CHECK:STDOUT: %v.var_patt: %pattern_type.3c2 = var_pattern %v.patt [concrete]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %v.var: ref %struct_type.a.b.2f9 = var %v.var_patt
  88. // CHECK:STDOUT: %F.ref.loc18_68: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  89. // CHECK:STDOUT: %.loc18_81.1: ref %tuple.type.189 = struct_access %v.var, element0
  90. // CHECK:STDOUT: %F.call.loc18_70: init %tuple.type.189 to %.loc18_81.1 = call %F.ref.loc18_68()
  91. // CHECK:STDOUT: %F.ref.loc18_78: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  92. // CHECK:STDOUT: %.loc18_81.2: ref %tuple.type.189 = struct_access %v.var, element1
  93. // CHECK:STDOUT: %F.call.loc18_80: init %tuple.type.189 to %.loc18_81.2 = call %F.ref.loc18_78()
  94. // CHECK:STDOUT: %.loc18_81.3: %struct_type.a.b.2f9 = struct_literal (%F.call.loc18_70, %F.call.loc18_80)
  95. // CHECK:STDOUT: %.loc18_81.4: init %struct_type.a.b.2f9 to %v.var = struct_init (%F.call.loc18_70, %F.call.loc18_80)
  96. // CHECK:STDOUT: %.loc18_3: init %struct_type.a.b.2f9 = converted %.loc18_81.3, %.loc18_81.4
  97. // CHECK:STDOUT: assign %v.var, %.loc18_3
  98. // CHECK:STDOUT: %.loc18_58: type = splice_block %struct_type.a.b [concrete = constants.%struct_type.a.b.2f9] {
  99. // CHECK:STDOUT: %int_32.loc18_23: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  100. // CHECK:STDOUT: %i32.loc18_23: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  101. // CHECK:STDOUT: %int_32.loc18_28: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  102. // CHECK:STDOUT: %i32.loc18_28: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  103. // CHECK:STDOUT: %int_32.loc18_33: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  104. // CHECK:STDOUT: %i32.loc18_33: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  105. // CHECK:STDOUT: %.loc18_36.1: %tuple.type.ff9 = tuple_literal (%i32.loc18_23, %i32.loc18_28, %i32.loc18_33) [concrete = constants.%tuple]
  106. // CHECK:STDOUT: %.loc18_36.2: type = converted %.loc18_36.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  107. // CHECK:STDOUT: %int_32.loc18_44: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  108. // CHECK:STDOUT: %i32.loc18_44: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  109. // CHECK:STDOUT: %int_32.loc18_49: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  110. // CHECK:STDOUT: %i32.loc18_49: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  111. // CHECK:STDOUT: %int_32.loc18_54: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  112. // CHECK:STDOUT: %i32.loc18_54: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  113. // CHECK:STDOUT: %.loc18_57.1: %tuple.type.ff9 = tuple_literal (%i32.loc18_44, %i32.loc18_49, %i32.loc18_54) [concrete = constants.%tuple]
  114. // CHECK:STDOUT: %.loc18_57.2: type = converted %.loc18_57.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  115. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete = constants.%struct_type.a.b.2f9]
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %v: ref %struct_type.a.b.2f9 = ref_binding v, %v.var
  118. // CHECK:STDOUT: %DestroyOp.bound: <bound method> = bound_method %v.var, constants.%DestroyOp
  119. // CHECK:STDOUT: %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%v.var)
  120. // CHECK:STDOUT: return
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn @DestroyOp(%self.param: ref %struct_type.a.b.2f9) = "no_op";
  124. // CHECK:STDOUT: