Refactor BindName to support tracking the enclosing scope. (#3566)

This is a step towards adding enclosing scopes for imports. It creates
an indirection for all bind names.

We discussed specializing for bindings that are in function scope (i.e.,
not a useful enclosing scope for imports or diagnostics). However, the
thought is to go ahead with this singular approach for now, and only
change structure if it's a performance issues so that we have
incrementally fewer instructions to handle.
This commit is contained in:
Jon Ross-Perkins
2024-01-05 02:56:03 +00:00
committed by GitHub
parent dfb27ded9c
commit 0205645e7d
18 changed files with 82 additions and 16 deletions
+4 -4
View File
@@ -57,10 +57,10 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
if (auto bind_name = context.insts().Get(value_id).TryAs<SemIR::BindName>()) {
// Form a corresponding name in the current context, and bind the name to
// the variable.
context.decl_name_stack().AddNameToLookup(
context.decl_name_stack().MakeUnqualifiedName(bind_name->parse_node,
bind_name->name_id),
value_id);
auto name_context = context.decl_name_stack().MakeUnqualifiedName(
bind_name->parse_node,
context.bind_names().Get(bind_name->bind_name_id).name_id);
context.decl_name_stack().AddNameToLookup(name_context, value_id);
value_id = bind_name->value_id;
}