Restructure handling of expressions in patterns (#7445)

Instead of maintaining a stack of pending subpatterns which might or
might not contain expressions, we mark non-nesting regions during
pattern handling that might contain an expression. The implementation
remains largely the same; the difference is that callers are expected to
end a pending expression region as soon as possible, rather than wait
for the end of the subpattern. This makes it possible to emit
non-pattern insts during pattern handling, without the risk that they
will get caught in a pending expression region further up the stack.
This commit is contained in:
Geoff Romer
2026-07-01 19:15:34 +00:00
committed by GitHub
parent e7771c2f6d
commit 11eaeeda7d
10 changed files with 99 additions and 71 deletions
+2 -2
View File
@@ -117,14 +117,14 @@ auto HandleParseNode(Context& context, Parse::ForHeaderStartId node_id)
context.decl_introducer_state_stack().Push<Lex::TokenKind::Let>();
context.pattern_block_stack().Push();
context.full_pattern_stack().PushNameBindingDecl();
BeginSubpattern(context);
BeginExprRegionForPattern(context);
context.node_stack().Push(node_id);
return true;
}
auto HandleParseNode(Context& context, Parse::ForInId node_id) -> bool {
EndSubpattern(context, context.node_stack());
EndExprRegionForPattern(context, context.node_stack());
auto pattern_block_id = context.pattern_block_stack().Pop();
AddInst<SemIR::NameBindingDecl>(context, node_id,
{.pattern_block_id = pattern_block_id});