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:
Geoff Romer
2024-12-19 21:41:06 +00:00
committed by GitHub
co-authored by Richard Smith
parent 95c9634c60
commit a112cbde5c
504 changed files with 5699 additions and 8719 deletions
+7 -3
View File
@@ -25,7 +25,7 @@ auto HandleParseNode(Context& context, Parse::IfExprIfId node_id) -> bool {
// Start emitting the `then` block.
context.inst_block_stack().Pop();
context.inst_block_stack().Push(then_block_id);
context.AddCurrentCodeBlockToFunction(node_id);
context.AddToRegion(then_block_id, node_id);
context.node_stack().Push(if_node, else_block_id);
return true;
@@ -56,13 +56,18 @@ auto HandleParseNode(Context& context, Parse::IfExprThenId node_id) -> bool {
// Start emitting the `else` block.
context.inst_block_stack().Push(else_block_id);
context.AddCurrentCodeBlockToFunction(node_id);
context.AddToRegion(else_block_id, node_id);
context.node_stack().Push(node_id, then_value_id);
return true;
}
auto HandleParseNode(Context& context, Parse::IfExprElseId node_id) -> bool {
if (context.return_scope_stack().empty()) {
context.TODO(node_id,
"Control flow expressions are currently only supported inside "
"functions.");
}
// Alias node_id for if/then/else consistency.
auto& else_node = node_id;
@@ -84,7 +89,6 @@ auto HandleParseNode(Context& context, Parse::IfExprElseId node_id) -> bool {
if_node, {else_value_id, then_value_id});
context.SetBlockArgResultBeforeConstantUse(chosen_value_id, cond_value_id,
then_value_id, else_value_id);
context.AddCurrentCodeBlockToFunction(node_id);
// Push the result value.
context.node_stack().Push(else_node, chosen_value_id);