mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Model type expressions as regions (#4698)
This is a precondition for enabling the new pattern-matching subsystem to support binding patterns that have `if` expressions in the type position. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
95c9634c60
commit
a112cbde5c
@@ -363,7 +363,7 @@ static auto HandleShortCircuitOperand(Context& context, Parse::NodeId node_id,
|
||||
context.inst_block_stack().Pop();
|
||||
context.inst_block_stack().Push(end_block_id);
|
||||
context.inst_block_stack().Push(rhs_block_id);
|
||||
context.AddCurrentCodeBlockToFunction(node_id);
|
||||
context.AddToRegion(rhs_block_id, node_id);
|
||||
|
||||
// HandleShortCircuitOperator will follow, and doesn't need the operand on the
|
||||
// node stack.
|
||||
@@ -384,6 +384,11 @@ auto HandleParseNode(Context& context, Parse::ShortCircuitOperandOrId node_id)
|
||||
// occurs during operand handling.
|
||||
static auto HandleShortCircuitOperator(Context& context, Parse::NodeId node_id)
|
||||
-> bool {
|
||||
if (context.return_scope_stack().empty()) {
|
||||
context.TODO(node_id,
|
||||
"Control flow expressions are currently only supported inside "
|
||||
"functions.");
|
||||
}
|
||||
auto [rhs_node, rhs_id] = context.node_stack().PopExprWithNodeId();
|
||||
auto short_circuit_result_id = context.node_stack().PopExpr();
|
||||
auto branch_value_id = context.node_stack().PopExpr();
|
||||
@@ -399,7 +404,7 @@ static auto HandleShortCircuitOperator(Context& context, Parse::NodeId node_id)
|
||||
context.AddInst<SemIR::BranchWithArg>(
|
||||
node_id, {.target_id = resume_block_id, .arg_id = rhs_id});
|
||||
context.inst_block_stack().Pop();
|
||||
context.AddCurrentCodeBlockToFunction(node_id);
|
||||
context.AddToRegion(context.inst_block_stack().PeekOrAdd(), node_id);
|
||||
|
||||
// Collect the result from either the first or second operand.
|
||||
auto result_id = context.AddInst<SemIR::BlockArg>(
|
||||
|
||||
Reference in New Issue
Block a user