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
@@ -167,7 +167,7 @@ static auto HandleAnyBindingPattern(
self_type_inst_id);
SemIR::ExprRegionId type_expr_region_id =
ConsumeSubpatternExpr(context, type_expr.inst_id);
ConsumeExprRegionForPattern(context, type_expr.inst_id);
// The name in a generic binding may be wrapped in `template`.
bool is_generic = node_kind == Parse::NodeKind::CompileTimeBindingPattern;
@@ -502,7 +502,7 @@ auto HandleParseNode(Context& context,
auto [cast_type_inst_id, cast_type_id] =
ExprAsType(context, type_node, parsed_type_id);
auto region_id = ConsumeSubpatternExpr(context, cast_type_inst_id);
auto region_id = ConsumeExprRegionForPattern(context, cast_type_inst_id);
// TODO: Should we be tracking this somewhere?
(void)region_id;