Skip to content

Commit 285f15a

Browse files
committed
Fix lowering of dependent copies.
1 parent 08e56df commit 285f15a

File tree

17 files changed

+134
-91
lines changed

17 files changed

+134
-91
lines changed

toolchain/check/call.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static auto PerformCallToFunction(Context& context, SemIR::LocId loc_id,
228228
SemIR::InstId return_slot_arg_id = SemIR::InstId::None;
229229
switch (return_info.init_repr.kind) {
230230
case SemIR::InitRepr::InPlace:
231+
case SemIR::InitRepr::Dependent:
231232
// Tentatively put storage for a temporary in the function's return slot.
232233
// This will be replaced if necessary when we perform initialization.
233234
return_slot_arg_id = AddInst<SemIR::TemporaryStorage>(

toolchain/check/convert.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ namespace Carbon::Check {
4242

4343
// Marks the initializer `init_id` as initializing `target_id`.
4444
static auto MarkInitializerFor(SemIR::File& sem_ir, SemIR::InstId init_id,
45-
SemIR::InstId target_id,
46-
PendingBlock& target_block) -> void {
45+
ConversionTarget& target) -> void {
46+
CARBON_CHECK(target.is_initializer());
4747
auto return_slot_arg_id = FindReturnSlotArgForInitializer(sem_ir, init_id);
4848
if (return_slot_arg_id.has_value()) {
4949
// Replace the temporary in the return slot with a reference to our target.
@@ -52,7 +52,8 @@ static auto MarkInitializerFor(SemIR::File& sem_ir, SemIR::InstId init_id,
5252
"Return slot for initializer does not contain a temporary; "
5353
"initialized multiple times? Have {0}",
5454
sem_ir.insts().Get(return_slot_arg_id));
55-
target_block.MergeReplacing(return_slot_arg_id, target_id);
55+
target.init_id =
56+
target.init_block->MergeReplacing(return_slot_arg_id, target.init_id);
5657
}
5758
}
5859

@@ -343,8 +344,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
343344
bool is_init = target.is_initializer();
344345
ConversionTarget::Kind inner_kind =
345346
!is_init ? ConversionTarget::Value
346-
: SemIR::InitRepr::ForType(sem_ir, target.type_id).kind ==
347-
SemIR::InitRepr::InPlace
347+
: SemIR::InitRepr::ForType(sem_ir, target.type_id).MightBeInPlace()
348348
? ConversionTarget::FullInitializer
349349
: ConversionTarget::Initializer;
350350

@@ -454,8 +454,7 @@ static auto ConvertStructToStructOrClass(
454454
bool is_init = target.is_initializer();
455455
ConversionTarget::Kind inner_kind =
456456
!is_init ? ConversionTarget::Value
457-
: SemIR::InitRepr::ForType(sem_ir, target.type_id).kind ==
458-
SemIR::InitRepr::InPlace
457+
: SemIR::InitRepr::ForType(sem_ir, target.type_id).MightBeInPlace()
459458
? ConversionTarget::FullInitializer
460459
: ConversionTarget::Initializer;
461460

@@ -1284,8 +1283,7 @@ static auto IsCppEnum(Context& context, SemIR::TypeId type_id) -> bool {
12841283
// Given a value expression, form a corresponding initializer that copies from
12851284
// that value to the specified target, if it is possible to do so.
12861285
static auto PerformCopy(Context& context, SemIR::InstId expr_id,
1287-
SemIR::InstId target_id, PendingBlock& target_block,
1288-
bool diagnose) -> SemIR::InstId {
1286+
ConversionTarget& target) -> SemIR::InstId {
12891287
// TODO: We don't have a mechanism yet to generate `Copy` impls for each enum
12901288
// type imported from C++. For now we fake it by providing a direct copy.
12911289
auto type_id = context.insts().Get(expr_id).type_id();
@@ -1295,21 +1293,21 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id,
12951293

12961294
auto copy_id = BuildUnaryOperator(
12971295
context, SemIR::LocId(expr_id), {"Copy"}, expr_id, [&] {
1298-
if (!diagnose) {
1296+
if (!target.diagnose) {
12991297
return context.emitter().BuildSuppressed();
13001298
}
13011299
CARBON_DIAGNOSTIC(CopyOfUncopyableType, Error,
13021300
"cannot copy value of type {0}", TypeOfInstId);
13031301
return context.emitter().Build(expr_id, CopyOfUncopyableType, expr_id);
13041302
});
1305-
MarkInitializerFor(context.sem_ir(), copy_id, target_id, target_block);
1303+
MarkInitializerFor(context.sem_ir(), copy_id, target);
13061304
return copy_id;
13071305
}
13081306

13091307
// Convert a value expression so that it can be used to initialize a C++ thunk
13101308
// parameter.
1311-
static auto ConvertValueForCppThunkRef(Context& context, SemIR::InstId expr_id,
1312-
bool diagnose) -> SemIR::InstId {
1309+
static auto ConvertValueForCppThunkRef(Context& context, SemIR::InstId expr_id)
1310+
-> SemIR::InstId {
13131311
auto expr = context.insts().Get(expr_id);
13141312

13151313
// If the expression has a pointer value representation, extract that and use
@@ -1325,8 +1323,7 @@ static auto ConvertValueForCppThunkRef(Context& context, SemIR::InstId expr_id,
13251323
// and initialize a temporary from it.
13261324
auto temporary_id = AddInst<SemIR::TemporaryStorage>(
13271325
context, SemIR::LocId(expr_id), {.type_id = expr.type_id()});
1328-
PendingBlock target_block(&context);
1329-
expr_id = PerformCopy(context, expr_id, temporary_id, target_block, diagnose);
1326+
expr_id = Initialize(context, SemIR::LocId(expr_id), temporary_id, expr_id);
13301327
return AddInstWithCleanup<SemIR::Temporary>(context, SemIR::LocId(expr_id),
13311328
{.type_id = expr.type_id(),
13321329
.storage_id = temporary_id,
@@ -1534,8 +1531,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
15341531
// a conversion. In that case, we will have created it with the
15351532
// target already set.
15361533
// TODO: Find a better way to track whether we need to do this.
1537-
MarkInitializerFor(sem_ir, expr_id, target.init_id,
1538-
*target.init_block);
1534+
MarkInitializerFor(sem_ir, expr_id, target);
15391535
}
15401536
break;
15411537
}
@@ -1587,14 +1583,13 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
15871583

15881584
// When initializing from a value, perform a copy.
15891585
if (target.is_initializer()) {
1590-
expr_id = PerformCopy(context, expr_id, target.init_id,
1591-
*target.init_block, target.diagnose);
1586+
expr_id = PerformCopy(context, expr_id, target);
15921587
}
15931588

15941589
// When initializing a C++ thunk parameter, form a reference, creating a
15951590
// temporary if needed.
15961591
if (target.kind == ConversionTarget::CppThunkRef) {
1597-
expr_id = ConvertValueForCppThunkRef(context, expr_id, target.diagnose);
1592+
expr_id = ConvertValueForCppThunkRef(context, expr_id);
15981593
}
15991594

16001595
break;
@@ -1603,7 +1598,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
16031598
// Perform a final destination store, if necessary.
16041599
if (target.kind == ConversionTarget::FullInitializer) {
16051600
if (auto init_rep = SemIR::InitRepr::ForType(sem_ir, target.type_id);
1606-
init_rep.kind == SemIR::InitRepr::ByCopy) {
1601+
init_rep.MightBeByCopy()) {
16071602
target.init_block->InsertHere();
16081603
expr_id = AddInst<SemIR::InitializeFrom>(context, loc_id,
16091604
{.type_id = target.type_id,

toolchain/check/pending_block.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ class PendingBlock {
6868
}
6969

7070
// Replace the instruction at target_id with the instructions in this block.
71-
// The new value for target_id should be value_id.
72-
auto MergeReplacing(SemIR::InstId target_id, SemIR::InstId value_id) -> void {
71+
// The new value for target_id should be value_id. Returns the InstId that
72+
// should be used to refer to the result from now on.
73+
auto MergeReplacing(SemIR::InstId target_id, SemIR::InstId value_id)
74+
-> SemIR::InstId {
7375
SemIR::LocIdAndInst value = context_->insts().GetWithLocId(value_id);
7476

77+
auto result_id = value_id;
7578
if (insts_.size() == 1 && insts_[0] == value_id) {
7679
// The block is {value_id}. Replace `target_id` with the instruction
7780
// referred to by `value_id`. This is intended to be the common case.
81+
result_id = target_id;
7882
} else {
7983
// Anything else: splice it into the IR, replacing `target_id`. This
8084
// includes empty blocks, which `Add` handles.
@@ -88,6 +92,7 @@ class PendingBlock {
8892

8993
// Prepare to stash more pending instructions.
9094
insts_.clear();
95+
return result_id;
9196
}
9297

9398
private:

toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -165,63 +165,63 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
165165
// CHECK:STDOUT: import_ir_inst134: {ir_id: ir4, inst_id: inst449}
166166
// CHECK:STDOUT: import_ir_inst135: {ir_id: ir4, inst_id: inst450}
167167
// CHECK:STDOUT: import_ir_inst136: {ir_id: ir4, inst_id: inst455}
168-
// CHECK:STDOUT: import_ir_inst137: {ir_id: ir4, inst_id: inst510}
169-
// CHECK:STDOUT: import_ir_inst138: {ir_id: ir4, inst_id: inst508}
170-
// CHECK:STDOUT: import_ir_inst139: {ir_id: ir4, inst_id: inst484}
171-
// CHECK:STDOUT: import_ir_inst140: {ir_id: ir4, inst_id: inst478}
172-
// CHECK:STDOUT: import_ir_inst141: {ir_id: ir4, inst_id: inst473}
173-
// CHECK:STDOUT: import_ir_inst142: {ir_id: ir4, inst_id: inst471}
174-
// CHECK:STDOUT: import_ir_inst143: {ir_id: ir4, inst_id: inst476}
175-
// CHECK:STDOUT: import_ir_inst144: {ir_id: ir4, inst_id: inst481}
176-
// CHECK:STDOUT: import_ir_inst145: {ir_id: ir4, inst_id: inst502}
177-
// CHECK:STDOUT: import_ir_inst146: {ir_id: ir4, inst_id: inst504}
178-
// CHECK:STDOUT: import_ir_inst147: {ir_id: ir4, inst_id: inst535}
179-
// CHECK:STDOUT: import_ir_inst148: {ir_id: ir4, inst_id: inst509}
180-
// CHECK:STDOUT: import_ir_inst149: {ir_id: ir4, inst_id: inst472}
181-
// CHECK:STDOUT: import_ir_inst150: {ir_id: ir4, inst_id: inst477}
182-
// CHECK:STDOUT: import_ir_inst151: {ir_id: ir4, inst_id: inst483}
183-
// CHECK:STDOUT: import_ir_inst152: {ir_id: ir4, inst_id: inst492}
184-
// CHECK:STDOUT: import_ir_inst153: {ir_id: ir4, inst_id: inst495}
185-
// CHECK:STDOUT: import_ir_inst154: {ir_id: ir4, inst_id: inst499}
186-
// CHECK:STDOUT: import_ir_inst155: {ir_id: ir4, inst_id: inst503}
187-
// CHECK:STDOUT: import_ir_inst156: {ir_id: ir4, inst_id: inst512}
188-
// CHECK:STDOUT: import_ir_inst157: {ir_id: ir4, inst_id: inst535}
189-
// CHECK:STDOUT: import_ir_inst158: {ir_id: ir4, inst_id: inst530}
190-
// CHECK:STDOUT: import_ir_inst159: {ir_id: ir4, inst_id: inst531}
191-
// CHECK:STDOUT: import_ir_inst160: {ir_id: ir4, inst_id: inst526}
192-
// CHECK:STDOUT: import_ir_inst161: {ir_id: ir4, inst_id: inst528}
193-
// CHECK:STDOUT: import_ir_inst162: {ir_id: ir4, inst_id: inst471}
194-
// CHECK:STDOUT: import_ir_inst163: {ir_id: ir4, inst_id: inst476}
195-
// CHECK:STDOUT: import_ir_inst164: {ir_id: ir4, inst_id: inst481}
196-
// CHECK:STDOUT: import_ir_inst165: {ir_id: ir4, inst_id: inst538}
197-
// CHECK:STDOUT: import_ir_inst166: {ir_id: ir4, inst_id: inst539}
198-
// CHECK:STDOUT: import_ir_inst167: {ir_id: ir4, inst_id: inst517}
199-
// CHECK:STDOUT: import_ir_inst168: {ir_id: ir4, inst_id: inst518}
200-
// CHECK:STDOUT: import_ir_inst169: {ir_id: ir4, inst_id: inst519}
201-
// CHECK:STDOUT: import_ir_inst170: {ir_id: ir4, inst_id: inst520}
202-
// CHECK:STDOUT: import_ir_inst171: {ir_id: ir4, inst_id: inst521}
203-
// CHECK:STDOUT: import_ir_inst172: {ir_id: ir4, inst_id: inst522}
204-
// CHECK:STDOUT: import_ir_inst173: {ir_id: ir4, inst_id: inst523}
205-
// CHECK:STDOUT: import_ir_inst174: {ir_id: ir4, inst_id: inst527}
206-
// CHECK:STDOUT: import_ir_inst175: {ir_id: ir4, inst_id: inst544}
207-
// CHECK:STDOUT: import_ir_inst176: {ir_id: ir4, inst_id: inst551}
208-
// CHECK:STDOUT: import_ir_inst177: {ir_id: ir4, inst_id: inst557}
209-
// CHECK:STDOUT: import_ir_inst178: {ir_id: ir4, inst_id: inst559}
210-
// CHECK:STDOUT: import_ir_inst179: {ir_id: ir4, inst_id: inst560}
211-
// CHECK:STDOUT: import_ir_inst180: {ir_id: ir4, inst_id: inst561}
212-
// CHECK:STDOUT: import_ir_inst181: {ir_id: ir4, inst_id: inst564}
213-
// CHECK:STDOUT: import_ir_inst182: {ir_id: ir4, inst_id: inst574}
214-
// CHECK:STDOUT: import_ir_inst183: {ir_id: ir4, inst_id: inst580}
215-
// CHECK:STDOUT: import_ir_inst184: {ir_id: ir4, inst_id: inst582}
216-
// CHECK:STDOUT: import_ir_inst185: {ir_id: ir4, inst_id: inst583}
217-
// CHECK:STDOUT: import_ir_inst186: {ir_id: ir4, inst_id: inst584}
218-
// CHECK:STDOUT: import_ir_inst187: {ir_id: ir4, inst_id: inst587}
219-
// CHECK:STDOUT: import_ir_inst188: {ir_id: ir4, inst_id: inst599}
220-
// CHECK:STDOUT: import_ir_inst189: {ir_id: ir4, inst_id: inst606}
221-
// CHECK:STDOUT: import_ir_inst190: {ir_id: ir4, inst_id: inst611}
222-
// CHECK:STDOUT: import_ir_inst191: {ir_id: ir4, inst_id: inst612}
223-
// CHECK:STDOUT: import_ir_inst192: {ir_id: ir4, inst_id: inst613}
224-
// CHECK:STDOUT: import_ir_inst193: {ir_id: ir4, inst_id: inst618}
168+
// CHECK:STDOUT: import_ir_inst137: {ir_id: ir4, inst_id: inst512}
169+
// CHECK:STDOUT: import_ir_inst138: {ir_id: ir4, inst_id: inst510}
170+
// CHECK:STDOUT: import_ir_inst139: {ir_id: ir4, inst_id: inst486}
171+
// CHECK:STDOUT: import_ir_inst140: {ir_id: ir4, inst_id: inst480}
172+
// CHECK:STDOUT: import_ir_inst141: {ir_id: ir4, inst_id: inst475}
173+
// CHECK:STDOUT: import_ir_inst142: {ir_id: ir4, inst_id: inst473}
174+
// CHECK:STDOUT: import_ir_inst143: {ir_id: ir4, inst_id: inst478}
175+
// CHECK:STDOUT: import_ir_inst144: {ir_id: ir4, inst_id: inst483}
176+
// CHECK:STDOUT: import_ir_inst145: {ir_id: ir4, inst_id: inst504}
177+
// CHECK:STDOUT: import_ir_inst146: {ir_id: ir4, inst_id: inst506}
178+
// CHECK:STDOUT: import_ir_inst147: {ir_id: ir4, inst_id: inst537}
179+
// CHECK:STDOUT: import_ir_inst148: {ir_id: ir4, inst_id: inst511}
180+
// CHECK:STDOUT: import_ir_inst149: {ir_id: ir4, inst_id: inst474}
181+
// CHECK:STDOUT: import_ir_inst150: {ir_id: ir4, inst_id: inst479}
182+
// CHECK:STDOUT: import_ir_inst151: {ir_id: ir4, inst_id: inst485}
183+
// CHECK:STDOUT: import_ir_inst152: {ir_id: ir4, inst_id: inst494}
184+
// CHECK:STDOUT: import_ir_inst153: {ir_id: ir4, inst_id: inst497}
185+
// CHECK:STDOUT: import_ir_inst154: {ir_id: ir4, inst_id: inst501}
186+
// CHECK:STDOUT: import_ir_inst155: {ir_id: ir4, inst_id: inst505}
187+
// CHECK:STDOUT: import_ir_inst156: {ir_id: ir4, inst_id: inst514}
188+
// CHECK:STDOUT: import_ir_inst157: {ir_id: ir4, inst_id: inst537}
189+
// CHECK:STDOUT: import_ir_inst158: {ir_id: ir4, inst_id: inst532}
190+
// CHECK:STDOUT: import_ir_inst159: {ir_id: ir4, inst_id: inst533}
191+
// CHECK:STDOUT: import_ir_inst160: {ir_id: ir4, inst_id: inst528}
192+
// CHECK:STDOUT: import_ir_inst161: {ir_id: ir4, inst_id: inst530}
193+
// CHECK:STDOUT: import_ir_inst162: {ir_id: ir4, inst_id: inst473}
194+
// CHECK:STDOUT: import_ir_inst163: {ir_id: ir4, inst_id: inst478}
195+
// CHECK:STDOUT: import_ir_inst164: {ir_id: ir4, inst_id: inst483}
196+
// CHECK:STDOUT: import_ir_inst165: {ir_id: ir4, inst_id: inst540}
197+
// CHECK:STDOUT: import_ir_inst166: {ir_id: ir4, inst_id: inst541}
198+
// CHECK:STDOUT: import_ir_inst167: {ir_id: ir4, inst_id: inst519}
199+
// CHECK:STDOUT: import_ir_inst168: {ir_id: ir4, inst_id: inst520}
200+
// CHECK:STDOUT: import_ir_inst169: {ir_id: ir4, inst_id: inst521}
201+
// CHECK:STDOUT: import_ir_inst170: {ir_id: ir4, inst_id: inst522}
202+
// CHECK:STDOUT: import_ir_inst171: {ir_id: ir4, inst_id: inst523}
203+
// CHECK:STDOUT: import_ir_inst172: {ir_id: ir4, inst_id: inst524}
204+
// CHECK:STDOUT: import_ir_inst173: {ir_id: ir4, inst_id: inst525}
205+
// CHECK:STDOUT: import_ir_inst174: {ir_id: ir4, inst_id: inst529}
206+
// CHECK:STDOUT: import_ir_inst175: {ir_id: ir4, inst_id: inst546}
207+
// CHECK:STDOUT: import_ir_inst176: {ir_id: ir4, inst_id: inst553}
208+
// CHECK:STDOUT: import_ir_inst177: {ir_id: ir4, inst_id: inst559}
209+
// CHECK:STDOUT: import_ir_inst178: {ir_id: ir4, inst_id: inst561}
210+
// CHECK:STDOUT: import_ir_inst179: {ir_id: ir4, inst_id: inst562}
211+
// CHECK:STDOUT: import_ir_inst180: {ir_id: ir4, inst_id: inst563}
212+
// CHECK:STDOUT: import_ir_inst181: {ir_id: ir4, inst_id: inst566}
213+
// CHECK:STDOUT: import_ir_inst182: {ir_id: ir4, inst_id: inst576}
214+
// CHECK:STDOUT: import_ir_inst183: {ir_id: ir4, inst_id: inst582}
215+
// CHECK:STDOUT: import_ir_inst184: {ir_id: ir4, inst_id: inst584}
216+
// CHECK:STDOUT: import_ir_inst185: {ir_id: ir4, inst_id: inst585}
217+
// CHECK:STDOUT: import_ir_inst186: {ir_id: ir4, inst_id: inst586}
218+
// CHECK:STDOUT: import_ir_inst187: {ir_id: ir4, inst_id: inst589}
219+
// CHECK:STDOUT: import_ir_inst188: {ir_id: ir4, inst_id: inst601}
220+
// CHECK:STDOUT: import_ir_inst189: {ir_id: ir4, inst_id: inst608}
221+
// CHECK:STDOUT: import_ir_inst190: {ir_id: ir4, inst_id: inst613}
222+
// CHECK:STDOUT: import_ir_inst191: {ir_id: ir4, inst_id: inst614}
223+
// CHECK:STDOUT: import_ir_inst192: {ir_id: ir4, inst_id: inst615}
224+
// CHECK:STDOUT: import_ir_inst193: {ir_id: ir4, inst_id: inst620}
225225
// CHECK:STDOUT: name_scopes:
226226
// CHECK:STDOUT: name_scope0: {inst: inst14, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name(Core): inst16, name0: inst53}}
227227
// CHECK:STDOUT: name_scope1: {inst: inst16, parent_scope: name_scope0, has_error: false, extended_scopes: [], names: {name3: inst69}}

toolchain/check/testdata/class/generic/init.carbon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ fn InitFromAdaptedSpecific(x: i32) -> i32 {
210210
// CHECK:STDOUT: %bound_method.loc10_27.2: <bound method> = bound_method %x.ref, %specific_impl_fn.loc10_27.1
211211
// CHECK:STDOUT: %.loc10_28.2: ref @InitFromStructGeneric.%T.as_type.loc9_44.1 (%T.as_type) = class_element_access %v.var, element0
212212
// CHECK:STDOUT: %.loc10_27.1: init @InitFromStructGeneric.%T.as_type.loc9_44.1 (%T.as_type) = call %bound_method.loc10_27.2(%x.ref) to %.loc10_28.2
213-
// CHECK:STDOUT: %.loc10_28.3: init @InitFromStructGeneric.%Class.loc10_17.2 (%Class.b1d) = class_init (%.loc10_27.1), %v.var
214-
// CHECK:STDOUT: %.loc10_3.1: init @InitFromStructGeneric.%Class.loc10_17.2 (%Class.b1d) = converted %.loc10_28.1, %.loc10_28.3
213+
// CHECK:STDOUT: %.loc10_28.3: init @InitFromStructGeneric.%T.as_type.loc9_44.1 (%T.as_type) = initialize_from %.loc10_27.1 to %.loc10_28.2
214+
// CHECK:STDOUT: %.loc10_28.4: init @InitFromStructGeneric.%Class.loc10_17.2 (%Class.b1d) = class_init (%.loc10_28.3), %v.var
215+
// CHECK:STDOUT: %.loc10_3.1: init @InitFromStructGeneric.%Class.loc10_17.2 (%Class.b1d) = converted %.loc10_28.1, %.loc10_28.4
215216
// CHECK:STDOUT: assign %v.var, %.loc10_3.1
216217
// CHECK:STDOUT: %.loc10_17.1: type = splice_block %Class.loc10_17.1 [symbolic = %Class.loc10_17.2 (constants.%Class.b1d)] {
217218
// CHECK:STDOUT: %Class.ref: %Class.type = name_ref Class, file.%Class.decl [concrete = constants.%Class.generic]

toolchain/check/testdata/class/generic/member_type.carbon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ fn Test() -> i32 {
370370
// CHECK:STDOUT: %bound_method.loc9_38.2: <bound method> = bound_method %n.ref, %specific_impl_fn.loc9_38.1
371371
// CHECK:STDOUT: %.loc9_39.2: ref @Outer.F.%T.as_type.loc9_11.1 (%T.as_type) = class_element_access %return, element0
372372
// CHECK:STDOUT: %.loc9_38.1: init @Outer.F.%T.as_type.loc9_11.1 (%T.as_type) = call %bound_method.loc9_38.2(%n.ref) to %.loc9_39.2
373-
// CHECK:STDOUT: %.loc9_39.3: init @Outer.F.%Inner (%Inner.2a5) = class_init (%.loc9_38.1), %return
374-
// CHECK:STDOUT: %.loc9_40: init @Outer.F.%Inner (%Inner.2a5) = converted %.loc9_39.1, %.loc9_39.3
373+
// CHECK:STDOUT: %.loc9_39.3: init @Outer.F.%T.as_type.loc9_11.1 (%T.as_type) = initialize_from %.loc9_38.1 to %.loc9_39.2
374+
// CHECK:STDOUT: %.loc9_39.4: init @Outer.F.%Inner (%Inner.2a5) = class_init (%.loc9_39.3), %return
375+
// CHECK:STDOUT: %.loc9_40: init @Outer.F.%Inner (%Inner.2a5) = converted %.loc9_39.1, %.loc9_39.4
375376
// CHECK:STDOUT: return %.loc9_40 to %return
376377
// CHECK:STDOUT: }
377378
// CHECK:STDOUT: }

toolchain/lower/function_context.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ auto FunctionContext::FinishInit(TypeInFile type, SemIR::InstId dest_id,
285285
case SemIR::InitRepr::Incomplete:
286286
CARBON_FATAL("Lowering aggregate initialization of incomplete type {0}",
287287
type.file->types().GetAsInst(type.type_id));
288+
case SemIR::InitRepr::Dependent:
289+
CARBON_FATAL("Lowering aggregate initialization of dependent type {0}",
290+
type.file->types().GetAsInst(type.type_id));
288291
}
289292
}
290293

toolchain/lower/handle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ auto HandleInst(FunctionContext& context, SemIR::InstId /*inst_id*/,
259259
case SemIR::InitRepr::Incomplete:
260260
CARBON_FATAL("Lowering return of incomplete type {0}",
261261
result_type.file->types().GetAsInst(result_type.type_id));
262+
case SemIR::InitRepr::Dependent:
263+
CARBON_FATAL("Lowering return of dependent type {0}",
264+
result_type.file->types().GetAsInst(result_type.type_id));
262265
}
263266
}
264267

0 commit comments

Comments
 (0)