mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 13:01:05 +01:00
Initial support for binding patterns in SemIR (#4221)
Introduces the `BindingPattern` and `SymbolicBindingPattern` insts, and a separate stack of pattern blocks that they are emitted into. The intent is to generate the corresponding pattern-matching insts (like `BindName`) from them in a separate pass, but that is deferred to future PRs. See [here](https://docs.google.com/document/d/1U_vQH17V893J9aF1LJXUnFYBNSs2MjKl4bJPaWCB2zo/edit?usp=sharing&resourcekey=0-w0xGYZ0An31Kpz-wvzSXwQ) for the design this is based on, but note that during review we have chosen to deviate from that design by putting the patterns in separate blocks, and omitting the "forward references" from a `BindingPattern` to its corresponding `BindName`. This in turn necessitates having separate inst kinds for symbolic and non-symbolic binding patterns. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
87678cc374
commit
dc32aa2690
@@ -167,6 +167,20 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
|
||||
// TODO: Bindings should come into scope immediately in other contexts
|
||||
// too.
|
||||
context.AddNameToLookup(name_id, bind_id);
|
||||
auto entity_name_id =
|
||||
context.insts().GetAs<SemIR::AnyBindName>(bind_id).entity_name_id;
|
||||
if (is_generic) {
|
||||
context.AddPatternInst<SemIR::SymbolicBindingPattern>(
|
||||
name_node,
|
||||
{.type_id = cast_type_id, .entity_name_id = entity_name_id});
|
||||
} else {
|
||||
context.AddPatternInst<SemIR::BindingPattern>(
|
||||
name_node,
|
||||
{.type_id = cast_type_id, .entity_name_id = entity_name_id});
|
||||
}
|
||||
// TODO: use the pattern insts to generate the pattern-match insts
|
||||
// at the end of the full pattern, instead of eagerly generating them
|
||||
// here.
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user