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
+3 -1
View File
@@ -144,9 +144,11 @@ auto Context::AddPackageImports(Parse::NodeId import_node,
// Add a name for formatted output. This isn't used in name lookup in order
// to reduce indirection, but it's separate from the Import because it
// otherwise fits in an Inst.
auto bind_name_id = bind_names().Add(
{.name_id = name_id, .enclosing_scope_id = SemIR::NameScopeId::Package});
AddInst(SemIR::BindName{.parse_node = import_node,
.type_id = type_id,
.name_id = name_id,
.bind_name_id = bind_name_id,
.value_id = inst_id});
}