Build VarStorage insts more efficiently. (#7422)

Instead of traversing the entire pattern block looking for
`VarPattern`s, we keep track of them on creation, and then build
`VarStorage`s directly from that list.

This also gets rid of the global `var_storage_map`, and instead keep
that information narrowly scoped to each full-pattern, and consume it in
a single linear traversal instead of with random-access lookups. To
enable that, this fixes a parse bug where nested `var` patterns were
getting diagnosed but not marked as errors.
This commit is contained in:
Geoff Romer
2026-06-26 22:26:13 +00:00
committed by GitHub
parent cfd1ed8484
commit 1a3966d2c4
14 changed files with 176 additions and 188 deletions
+2 -3
View File
@@ -674,9 +674,8 @@ auto MatchContext::DoVarPreWorkImpl(State state,
// In a `var`/`let` declaration, the `VarStorage` inst is created before
// we start pattern matching.
auto lookup_result = context_.var_storage_map().Lookup(entry.pattern_id);
CARBON_CHECK(lookup_result);
auto storage_id = lookup_result.value();
auto storage_id =
context_.full_pattern_stack().GetLocalVarStorage(entry.pattern_id);
if (scrutinee_id.has_value()) {
auto init_id =
InitializeExisting(context_, SemIR::LocId(entry.pattern_id),