mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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
@@ -30,6 +30,12 @@ auto HandleParseNode(Context& context, Parse::ImplIntroducerId node_id)
|
||||
// consistent to imagine that it does. This also gives us a scope for implicit
|
||||
// parameters.
|
||||
context.decl_name_stack().PushScopeAndStartName();
|
||||
|
||||
// Push a pattern block for the signature of the `forall` (if any).
|
||||
// TODO: Instead use a separate parse node kinds for `impl` and `impl forall`,
|
||||
// and only push a pattern block in `forall` case.
|
||||
context.pattern_block_stack().Push();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,6 +219,8 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
|
||||
// TODO: Does lookup in an impl file need to look for a prior impl declaration
|
||||
// in the api file?
|
||||
auto impl_id = context.impls().LookupOrAdd(self_type_id, constraint_type_id);
|
||||
context.impls().Get(impl_id).pattern_block_id =
|
||||
context.pattern_block_stack().Pop();
|
||||
SemIR::ImplDecl impl_decl = {.impl_id = impl_id,
|
||||
.decl_block_id = decl_block_id};
|
||||
auto impl_decl_id = context.AddInst(node_id, impl_decl);
|
||||
|
||||
Reference in New Issue
Block a user