@@ -147,6 +147,29 @@ static auto MakeElementAccessInst(Context& context, SemIR::LocId loc_id,
147
147
}
148
148
}
149
149
150
+ // Get the conversion target kind to use when initializing an element of an
151
+ // aggregate.
152
+ static auto GetAggregateElementConversionTargetKind (SemIR::File& sem_ir,
153
+ ConversionTarget target)
154
+ -> ConversionTarget::Kind {
155
+ // If we're forming an initializer, then we want an initializer for each
156
+ // element.
157
+ if (target.is_initializer ()) {
158
+ // Perform a final destination store if we're performing an in-place
159
+ // initialization.
160
+ auto init_repr = SemIR::InitRepr::ForType (sem_ir, target.type_id );
161
+ CARBON_CHECK (init_repr.kind != SemIR::InitRepr::Dependent,
162
+ " Aggregate should not have dependent init kind" );
163
+ if (init_repr.kind == SemIR::InitRepr::InPlace) {
164
+ return ConversionTarget::FullInitializer;
165
+ }
166
+ return ConversionTarget::Initializer;
167
+ }
168
+
169
+ // Otherwise, we want a value representation for each element.
170
+ return ConversionTarget::Value;
171
+ }
172
+
150
173
// Converts an element of one aggregate so that it can be used as an element of
151
174
// another aggregate.
152
175
//
@@ -337,16 +360,8 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
337
360
return SemIR::ErrorInst::InstId;
338
361
}
339
362
340
- // If we're forming an initializer, then we want an initializer for each
341
- // element. Otherwise, we want a value representation for each element.
342
- // Perform a final destination store if we're performing an in-place
343
- // initialization.
344
- bool is_init = target.is_initializer ();
345
363
ConversionTarget::Kind inner_kind =
346
- !is_init ? ConversionTarget::Value
347
- : SemIR::InitRepr::ForType (sem_ir, target.type_id ).MightBeInPlace ()
348
- ? ConversionTarget::FullInitializer
349
- : ConversionTarget::Initializer;
364
+ GetAggregateElementConversionTargetKind (sem_ir, target);
350
365
351
366
// Initialize each element of the destination from the corresponding element
352
367
// of the source.
@@ -373,7 +388,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
373
388
new_block.Set (i, init_id);
374
389
}
375
390
376
- if (is_init ) {
391
+ if (target. is_initializer () ) {
377
392
target.init_block ->InsertHere ();
378
393
return AddInst<SemIR::TupleInit>(context, value_loc_id,
379
394
{.type_id = target.type_id ,
@@ -447,16 +462,8 @@ static auto ConvertStructToStructOrClass(
447
462
}
448
463
}
449
464
450
- // If we're forming an initializer, then we want an initializer for each
451
- // element. Otherwise, we want a value representation for each element.
452
- // Perform a final destination store if we're performing an in-place
453
- // initialization.
454
- bool is_init = target.is_initializer ();
455
465
ConversionTarget::Kind inner_kind =
456
- !is_init ? ConversionTarget::Value
457
- : SemIR::InitRepr::ForType (sem_ir, target.type_id ).MightBeInPlace ()
458
- ? ConversionTarget::FullInitializer
459
- : ConversionTarget::Initializer;
466
+ GetAggregateElementConversionTargetKind (sem_ir, target);
460
467
461
468
// Initialize each element of the destination from the corresponding element
462
469
// of the source.
@@ -544,6 +551,7 @@ static auto ConvertStructToStructOrClass(
544
551
new_block.Set (i, init_id);
545
552
}
546
553
554
+ bool is_init = target.is_initializer ();
547
555
if (ToClass) {
548
556
target.init_block ->InsertHere ();
549
557
CARBON_CHECK (is_init,
0 commit comments