Separate binding insts for refs and values (#6235)

This resolves a TODO in `expr_info.cpp` by using the inst kind rather
than the bound value to track the binding's category.

Since we're churning all the `bind_name` insts in testdata anyway, I'm
also taking this opportunity to align the inst naming with the design's
terminology, by calling these insts "bindings" (this aspect of the PR is
dependent on #6231 resolving an ambiguity in that terminology). For
consistency we'll need to rename several other insts as well (see the
TODO on `RefBinding`); I'm deferring that to a separate PR to minimize
the review load, but I think those name changes are in-scope for this
review.
This commit is contained in:
Geoff Romer
2025-10-23 01:46:24 +00:00
committed by GitHub
parent c0879b2200
commit 09710d102f
435 changed files with 4380 additions and 4306 deletions
+8 -7
View File
@@ -1440,11 +1440,11 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id,
// TODO: Fix this once templates are supported.
bool is_template = false;
// TODO: Fix this once generics are supported.
bool is_generic = false;
// TODO: Model reference parameters as ref bindings.
SemIR::InstId pattern_id =
AddBindingPattern(context, param_loc_id, name_id, type_id,
type_expr_region_id, is_generic, is_template)
type_expr_region_id, SemIR::ValueBindingPattern::Kind,
is_template)
.pattern_id;
pattern_id = AddPatternInst(
context, {param_loc_id,
@@ -1872,12 +1872,13 @@ static auto ImportVarDecl(Context& context, SemIR::LocId loc_id,
context.cpp_global_names().Add({.key = {.entity_name_id = entity_name_id},
.clang_decl_id = clang_decl_id});
// Create `BindingPattern` and `VarPattern` in a `NameBindingDecl`.
// Create `RefBindingPattern` and `VarPattern` in a `NameBindingDecl`.
context.pattern_block_stack().Push();
SemIR::TypeId pattern_type_id = GetPatternType(context, var_type_id);
SemIR::InstId binding_pattern_inst_id = AddPatternInst<SemIR::BindingPattern>(
context, loc_id,
{.type_id = pattern_type_id, .entity_name_id = entity_name_id});
SemIR::InstId binding_pattern_inst_id =
AddPatternInst<SemIR::RefBindingPattern>(
context, loc_id,
{.type_id = pattern_type_id, .entity_name_id = entity_name_id});
var_storage.pattern_id = AddPatternInst<SemIR::VarPattern>(
context, Parse::VariablePatternId::None,
{.type_id = pattern_type_id, .subpattern_id = binding_pattern_inst_id});