Reduce explicit SemIR::LocIdAndInst construction (#5153)

Building on #5151 reducing `UncheckedLoc` use, further remove uses of
the `SemIR::LocIdAndInst` constructor where we typically have overloads
that don't need it. Add parallel convenience wrappers for placeholder
insts.

Also refactors `MergeReplacing`. I don't think it makes sense to add an
overload for `ReplaceLocIdAndInstBeforeConstantUse`, but we can still
reduce the `LocIdAndInst` construction there.
This commit is contained in:
Jon Ross-Perkins
2025-03-21 21:45:53 +00:00
committed by GitHub
parent 402dc2c064
commit 832c6398d6
12 changed files with 78 additions and 94 deletions
+11 -15
View File
@@ -63,18 +63,16 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
is_template);
if (is_generic) {
bind_id = AddInstInNoBlock(
context, SemIR::LocIdAndInst(name_node,
SemIR::BindSymbolicName{
.type_id = cast_type_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::None}));
context, name_node,
SemIR::BindSymbolicName{.type_id = cast_type_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::None});
} else {
bind_id = AddInstInNoBlock(
context,
SemIR::LocIdAndInst(
name_node, SemIR::BindName{.type_id = cast_type_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::None}));
bind_id =
AddInstInNoBlock(context, name_node,
SemIR::BindName{.type_id = cast_type_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::None});
}
}
@@ -195,10 +193,8 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
.decl_block_id = SemIR::InstBlockId::None};
auto decl_id = AddPlaceholderInstInNoBlock(
context,
SemIR::LocIdAndInst(
context.parse_tree().As<Parse::CompileTimeBindingPatternId>(
node_id),
assoc_const_decl));
context.parse_tree().As<Parse::CompileTimeBindingPatternId>(node_id),
assoc_const_decl);
assoc_const_decl.assoc_const_id = context.associated_constants().Add(
{.name_id = name_id,
.parent_scope_id = context.scope_stack().PeekNameScopeId(),