nested_struct_in_place.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 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.type.189: type = tuple_type (%i32, %i32, %i32) [concrete]
  28. // CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
  29. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  31. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  32. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  33. // CHECK:STDOUT: %struct_type.a.b.2f9: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete]
  34. // CHECK:STDOUT: %ptr.7ae: type = ptr_type %tuple.type.189 [concrete]
  35. // CHECK:STDOUT: %pattern_type.3c2: type = pattern_type %struct_type.a.b.2f9 [concrete]
  36. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  37. // CHECK:STDOUT: %Op.type.19f: type = fn_type @Op.3, @Destroy.impl(%tuple.type.189) [concrete]
  38. // CHECK:STDOUT: %Op.672: %Op.type.19f = struct_value () [concrete]
  39. // CHECK:STDOUT: %Op.specific_fn.cf9: <specific function> = specific_function %Op.672, @Op.3(%tuple.type.189) [concrete]
  40. // CHECK:STDOUT: %Op.type.840: type = fn_type @Op.3, @Destroy.impl(%struct_type.a.b.2f9) [concrete]
  41. // CHECK:STDOUT: %Op.52b: %Op.type.840 = struct_value () [concrete]
  42. // CHECK:STDOUT: %ptr.c95: type = ptr_type %struct_type.a.b.2f9 [concrete]
  43. // CHECK:STDOUT: %Op.specific_fn.c7e: <specific function> = specific_function %Op.52b, @Op.3(%struct_type.a.b.2f9) [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  48. // CHECK:STDOUT: .Int = %Core.Int
  49. // CHECK:STDOUT: .Destroy = %Core.Destroy
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  54. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  59. // CHECK:STDOUT: .Core = imports.%Core
  60. // CHECK:STDOUT: .F = %F.decl
  61. // CHECK:STDOUT: .G = %G.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  65. // CHECK:STDOUT: %return.patt: %pattern_type.b5a = return_slot_pattern [concrete]
  66. // CHECK:STDOUT: %return.param_patt: %pattern_type.b5a = out_param_pattern %return.patt, call_param0 [concrete]
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %int_32.loc15_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  69. // CHECK:STDOUT: %i32.loc15_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  70. // CHECK:STDOUT: %int_32.loc15_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  71. // CHECK:STDOUT: %i32.loc15_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  72. // CHECK:STDOUT: %int_32.loc15_22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  73. // CHECK:STDOUT: %i32.loc15_22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  74. // CHECK:STDOUT: %.loc15_25.1: %tuple.type.ff9 = tuple_literal (%i32.loc15_12, %i32.loc15_17, %i32.loc15_22)
  75. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_25.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  76. // CHECK:STDOUT: %return.param: ref %tuple.type.189 = out_param call_param0
  77. // CHECK:STDOUT: %return: ref %tuple.type.189 = return_slot %return.param
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @F() -> %return.param: %tuple.type.189;
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @G() {
  85. // CHECK:STDOUT: !entry:
  86. // CHECK:STDOUT: name_binding_decl {
  87. // CHECK:STDOUT: %v.patt: %pattern_type.3c2 = binding_pattern v [concrete]
  88. // CHECK:STDOUT: %v.var_patt: %pattern_type.3c2 = var_pattern %v.patt [concrete]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %v.var: ref %struct_type.a.b.2f9 = var %v.var_patt
  91. // CHECK:STDOUT: %F.ref.loc18_61: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  92. // CHECK:STDOUT: %.loc18_74.1: ref %tuple.type.189 = struct_access %v.var, element0
  93. // CHECK:STDOUT: %F.call.loc18_63: init %tuple.type.189 = call %F.ref.loc18_61() to %.loc18_74.1
  94. // CHECK:STDOUT: %F.ref.loc18_71: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  95. // CHECK:STDOUT: %.loc18_74.2: ref %tuple.type.189 = struct_access %v.var, element1
  96. // CHECK:STDOUT: %F.call.loc18_73: init %tuple.type.189 = call %F.ref.loc18_71() to %.loc18_74.2
  97. // CHECK:STDOUT: %.loc18_74.3: %struct_type.a.b.2f9 = struct_literal (%F.call.loc18_63, %F.call.loc18_73)
  98. // CHECK:STDOUT: %.loc18_74.4: init %struct_type.a.b.2f9 = struct_init (%F.call.loc18_63, %F.call.loc18_73) to %v.var
  99. // CHECK:STDOUT: %.loc18_3: init %struct_type.a.b.2f9 = converted %.loc18_74.3, %.loc18_74.4
  100. // CHECK:STDOUT: assign %v.var, %.loc18_3
  101. // CHECK:STDOUT: %.loc18_51: type = splice_block %struct_type.a.b [concrete = constants.%struct_type.a.b.2f9] {
  102. // CHECK:STDOUT: %int_32.loc18_16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  103. // CHECK:STDOUT: %i32.loc18_16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  104. // CHECK:STDOUT: %int_32.loc18_21: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32.loc18_21: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: %int_32.loc18_26: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  107. // CHECK:STDOUT: %i32.loc18_26: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  108. // CHECK:STDOUT: %.loc18_29.1: %tuple.type.ff9 = tuple_literal (%i32.loc18_16, %i32.loc18_21, %i32.loc18_26)
  109. // CHECK:STDOUT: %.loc18_29.2: type = converted %.loc18_29.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  110. // CHECK:STDOUT: %int_32.loc18_37: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  111. // CHECK:STDOUT: %i32.loc18_37: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  112. // CHECK:STDOUT: %int_32.loc18_42: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  113. // CHECK:STDOUT: %i32.loc18_42: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  114. // CHECK:STDOUT: %int_32.loc18_47: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  115. // CHECK:STDOUT: %i32.loc18_47: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  116. // CHECK:STDOUT: %.loc18_50.1: %tuple.type.ff9 = tuple_literal (%i32.loc18_37, %i32.loc18_42, %i32.loc18_47)
  117. // CHECK:STDOUT: %.loc18_50.2: type = converted %.loc18_50.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  118. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %tuple.type.189, .b: %tuple.type.189} [concrete = constants.%struct_type.a.b.2f9]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %v: ref %struct_type.a.b.2f9 = bind_name v, %v.var
  121. // CHECK:STDOUT: %Op.bound.loc18_74.1: <bound method> = bound_method %.loc18_74.2, constants.%Op.672
  122. // CHECK:STDOUT: %Op.specific_fn.1: <specific function> = specific_function constants.%Op.672, @Op.3(constants.%tuple.type.189) [concrete = constants.%Op.specific_fn.cf9]
  123. // CHECK:STDOUT: %bound_method.loc18_74.1: <bound method> = bound_method %.loc18_74.2, %Op.specific_fn.1
  124. // CHECK:STDOUT: %addr.loc18_74.1: %ptr.7ae = addr_of %.loc18_74.2
  125. // CHECK:STDOUT: %no_op.loc18_74.1: init %empty_tuple.type = call %bound_method.loc18_74.1(%addr.loc18_74.1)
  126. // CHECK:STDOUT: %Op.bound.loc18_74.2: <bound method> = bound_method %.loc18_74.1, constants.%Op.672
  127. // CHECK:STDOUT: %Op.specific_fn.2: <specific function> = specific_function constants.%Op.672, @Op.3(constants.%tuple.type.189) [concrete = constants.%Op.specific_fn.cf9]
  128. // CHECK:STDOUT: %bound_method.loc18_74.2: <bound method> = bound_method %.loc18_74.1, %Op.specific_fn.2
  129. // CHECK:STDOUT: %addr.loc18_74.2: %ptr.7ae = addr_of %.loc18_74.1
  130. // CHECK:STDOUT: %no_op.loc18_74.2: init %empty_tuple.type = call %bound_method.loc18_74.2(%addr.loc18_74.2)
  131. // CHECK:STDOUT: %Op.bound.loc18_3: <bound method> = bound_method %v.var, constants.%Op.52b
  132. // CHECK:STDOUT: %Op.specific_fn.3: <specific function> = specific_function constants.%Op.52b, @Op.3(constants.%struct_type.a.b.2f9) [concrete = constants.%Op.specific_fn.c7e]
  133. // CHECK:STDOUT: %bound_method.loc18_3: <bound method> = bound_method %v.var, %Op.specific_fn.3
  134. // CHECK:STDOUT: %addr.loc18_3: %ptr.c95 = addr_of %v.var
  135. // CHECK:STDOUT: %no_op.loc18_3: init %empty_tuple.type = call %bound_method.loc18_3(%addr.loc18_3)
  136. // CHECK:STDOUT: return
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: