|
|
@@ -88,8 +88,7 @@ class MatchContext {
|
|
|
|
|
|
// Implementations of `EmitPatternMatch` for particular pattern inst kinds.
|
|
|
// The pattern argument is always equal to
|
|
|
- // `context.insts().Get(entry.pattern_id)`, and `pattern_loc_id` is always
|
|
|
- // equal to `context.insts().GetLocId(entry.pattern_id)`.
|
|
|
+ // `context.insts().Get(entry.pattern_id)`.
|
|
|
auto DoEmitPatternMatch(Context& context,
|
|
|
SemIR::AnyBindingPattern binding_pattern,
|
|
|
SemIR::InstId pattern_inst_id, WorkItem entry)
|
|
|
@@ -161,7 +160,6 @@ auto MatchContext::DoWork(Context& context) -> SemIR::InstBlockId {
|
|
|
static auto InsertHere(Context& context, SemIR::ExprRegionId region_id)
|
|
|
-> SemIR::InstId {
|
|
|
auto region = context.sem_ir().expr_regions().Get(region_id);
|
|
|
- auto loc_id = context.insts().GetLocId(region.result_id);
|
|
|
auto exit_block = context.inst_blocks().Get(region.block_ids.back());
|
|
|
if (region.block_ids.size() == 1) {
|
|
|
// TODO: Is it possible to avoid leaving an "orphan" block in the IR in the
|
|
|
@@ -174,13 +172,13 @@ static auto InsertHere(Context& context, SemIR::ExprRegionId region_id)
|
|
|
return region.result_id;
|
|
|
}
|
|
|
return AddInst<SemIR::SpliceBlock>(
|
|
|
- context, loc_id,
|
|
|
+ context, SemIR::LocId(region.result_id),
|
|
|
{.type_id = context.insts().Get(region.result_id).type_id(),
|
|
|
.block_id = region.block_ids.front(),
|
|
|
.result_id = region.result_id});
|
|
|
}
|
|
|
if (context.region_stack().empty()) {
|
|
|
- context.TODO(loc_id,
|
|
|
+ context.TODO(region.result_id,
|
|
|
"Control flow expressions are currently only supported inside "
|
|
|
"functions.");
|
|
|
return SemIR::ErrorInst::InstId;
|
|
|
@@ -195,7 +193,8 @@ static auto InsertHere(Context& context, SemIR::ExprRegionId region_id)
|
|
|
context.insts().GetAs<SemIR::Branch>(exit_block.back()).target_id;
|
|
|
CARBON_CHECK(context.inst_blocks().GetOrEmpty(resume_with_block_id).empty());
|
|
|
context.inst_block_stack().Push(resume_with_block_id);
|
|
|
- context.region_stack().AddToRegion(resume_with_block_id, loc_id);
|
|
|
+ context.region_stack().AddToRegion(resume_with_block_id,
|
|
|
+ SemIR::LocId(region.result_id));
|
|
|
return region.result_id;
|
|
|
}
|
|
|
|
|
|
@@ -221,8 +220,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
auto value_id = SemIR::InstId::None;
|
|
|
if (kind_ == MatchKind::Local) {
|
|
|
value_id =
|
|
|
- Convert(context, context.insts().GetLocId(entry.scrutinee_id),
|
|
|
- entry.scrutinee_id,
|
|
|
+ Convert(context, SemIR::LocId(entry.scrutinee_id), entry.scrutinee_id,
|
|
|
{.kind = bind_name_id.has_value() ? ConversionTarget::ValueOrRef
|
|
|
: ConversionTarget::Discarded,
|
|
|
.type_id = context.insts().Get(bind_name_id).type_id()});
|
|
|
@@ -264,7 +262,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
CARBON_DIAGNOSTIC(AddrSelfIsNonRef, Error,
|
|
|
"`addr self` method cannot be invoked on a value");
|
|
|
context.emitter().Emit(
|
|
|
- TokenOnly(context.insts().GetLocId(entry.scrutinee_id)),
|
|
|
+ context.insts().GetCanonicalLocId(entry.scrutinee_id).ToTokenOnly(),
|
|
|
AddrSelfIsNonRef);
|
|
|
// Add fake reference expression to preserve invariants.
|
|
|
auto scrutinee = context.insts().GetWithLocId(entry.scrutinee_id);
|
|
|
@@ -275,7 +273,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
auto scrutinee_ref_type_inst_id =
|
|
|
context.types().GetInstId(scrutinee_ref.type_id());
|
|
|
auto new_scrutinee = AddInst<SemIR::AddrOf>(
|
|
|
- context, context.insts().GetLocId(scrutinee_ref_id),
|
|
|
+ context, SemIR::LocId(scrutinee_ref_id),
|
|
|
{.type_id = GetPointerType(context, scrutinee_ref_type_inst_id),
|
|
|
.lvalue_id = scrutinee_ref_id});
|
|
|
AddWork({.pattern_id = addr_pattern.inner_id, .scrutinee_id = new_scrutinee});
|
|
|
@@ -296,8 +294,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
results_.push_back(SemIR::ErrorInst::InstId);
|
|
|
} else {
|
|
|
results_.push_back(ConvertToValueOfType(
|
|
|
- context, context.insts().GetLocId(entry.scrutinee_id),
|
|
|
- entry.scrutinee_id,
|
|
|
+ context, SemIR::LocId(entry.scrutinee_id), entry.scrutinee_id,
|
|
|
ExtractScrutineeType(
|
|
|
context.sem_ir(),
|
|
|
SemIR::GetTypeOfInstInSpecific(
|
|
|
@@ -312,7 +309,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
param_pattern.index = NextRuntimeIndex();
|
|
|
ReplaceInstBeforeConstantUse(context, entry.pattern_id, param_pattern);
|
|
|
auto param_id = AddInst<SemIR::ValueParam>(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id),
|
|
|
+ context, SemIR::LocId(pattern_inst_id),
|
|
|
{.type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), param_pattern.type_id),
|
|
|
.index = param_pattern.index,
|
|
|
@@ -354,7 +351,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
param_pattern.index = NextRuntimeIndex();
|
|
|
ReplaceInstBeforeConstantUse(context, entry.pattern_id, param_pattern);
|
|
|
auto param_id = AddInst<SemIR::RefParam>(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id),
|
|
|
+ context, SemIR::LocId(pattern_inst_id),
|
|
|
{.type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), param_pattern.type_id),
|
|
|
.index = param_pattern.index,
|
|
|
@@ -400,7 +397,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
param_pattern.index = NextRuntimeIndex();
|
|
|
ReplaceInstBeforeConstantUse(context, entry.pattern_id, param_pattern);
|
|
|
auto param_id = AddInst<SemIR::OutParam>(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id),
|
|
|
+ context, SemIR::LocId(pattern_inst_id),
|
|
|
{.type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), param_pattern.type_id),
|
|
|
.index = param_pattern.index,
|
|
|
@@ -424,7 +421,7 @@ auto MatchContext::DoEmitPatternMatch(
|
|
|
auto type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), return_slot_pattern.type_id);
|
|
|
auto return_slot_id = AddInst<SemIR::ReturnSlot>(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id),
|
|
|
+ context, SemIR::LocId(pattern_inst_id),
|
|
|
{.type_id = type_id,
|
|
|
.type_inst_id = context.types().GetInstId(type_id),
|
|
|
.storage_id = entry.scrutinee_id});
|
|
|
@@ -459,7 +456,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
}
|
|
|
case MatchKind::Caller: {
|
|
|
storage_id = AddInstWithCleanup<SemIR::TemporaryStorage>(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id),
|
|
|
+ context, SemIR::LocId(pattern_inst_id),
|
|
|
{.type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), var_pattern.type_id)});
|
|
|
CARBON_CHECK(entry.scrutinee_id.has_value());
|
|
|
@@ -473,11 +470,11 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
context.global_init().Resume();
|
|
|
}
|
|
|
if (entry.scrutinee_id.has_value()) {
|
|
|
- auto loc_id = context.insts().GetLocId(pattern_inst_id);
|
|
|
- auto init_id = Initialize(context, loc_id, storage_id, entry.scrutinee_id);
|
|
|
+ auto init_id = Initialize(context, SemIR::LocId(pattern_inst_id),
|
|
|
+ storage_id, entry.scrutinee_id);
|
|
|
// TODO: Consider using different instruction kinds for assignment
|
|
|
// versus initialization.
|
|
|
- AddInst<SemIR::Assign>(context, loc_id,
|
|
|
+ AddInst<SemIR::Assign>(context, SemIR::LocId(pattern_inst_id),
|
|
|
{.lhs_id = storage_id, .rhs_id = init_id});
|
|
|
}
|
|
|
AddWork(
|
|
|
@@ -529,9 +526,9 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
|
|
|
|
|
auto tuple_type_id =
|
|
|
ExtractScrutineeType(context.sem_ir(), tuple_pattern.type_id);
|
|
|
- auto converted_scrutinee = ConvertToValueOrRefOfType(
|
|
|
- context, context.insts().GetLocId(pattern_inst_id), entry.scrutinee_id,
|
|
|
- tuple_type_id);
|
|
|
+ auto converted_scrutinee =
|
|
|
+ ConvertToValueOrRefOfType(context, SemIR::LocId(pattern_inst_id),
|
|
|
+ entry.scrutinee_id, tuple_type_id);
|
|
|
if (auto scrutinee_value =
|
|
|
context.insts().TryGetAs<SemIR::TupleValue>(converted_scrutinee)) {
|
|
|
add_all_subscrutinees(
|