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
@@ -50,6 +50,7 @@ Context::Context(const Lex::TokenizedBuffer& tokens, DiagnosticEmitter& emitter,
|
||||
vlog_stream_(vlog_stream),
|
||||
node_stack_(parse_tree, vlog_stream),
|
||||
inst_block_stack_("inst_block_stack_", sem_ir, vlog_stream),
|
||||
pattern_block_stack_("pattern_block_stack_", sem_ir, vlog_stream),
|
||||
param_and_arg_refs_stack_(sem_ir, vlog_stream, node_stack_),
|
||||
args_type_info_stack_("args_type_info_stack_", sem_ir, vlog_stream),
|
||||
decl_name_stack_(this),
|
||||
@@ -82,6 +83,7 @@ auto Context::VerifyOnFinish() -> void {
|
||||
// node_stack_ will still contain top-level entities.
|
||||
scope_stack_.VerifyOnFinish();
|
||||
inst_block_stack_.VerifyOnFinish();
|
||||
pattern_block_stack_.VerifyOnFinish();
|
||||
param_and_arg_refs_stack_.VerifyOnFinish();
|
||||
}
|
||||
|
||||
@@ -177,6 +179,13 @@ auto Context::AddPlaceholderInst(SemIR::LocIdAndInst loc_id_and_inst)
|
||||
return inst_id;
|
||||
}
|
||||
|
||||
auto Context::AddPatternInst(SemIR::LocIdAndInst loc_id_and_inst)
|
||||
-> SemIR::InstId {
|
||||
auto inst_id = AddInstInNoBlock(loc_id_and_inst);
|
||||
pattern_block_stack_.AddInstId(inst_id);
|
||||
return inst_id;
|
||||
}
|
||||
|
||||
auto Context::AddConstant(SemIR::Inst inst, bool is_symbolic)
|
||||
-> SemIR::ConstantId {
|
||||
auto const_id = constants().GetOrAdd(inst, is_symbolic);
|
||||
@@ -1285,6 +1294,7 @@ auto Context::PrintForStackDump(llvm::raw_ostream& output) const -> void {
|
||||
SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_);
|
||||
node_stack_.PrintForStackDump(formatter, Indent, output);
|
||||
inst_block_stack_.PrintForStackDump(formatter, Indent, output);
|
||||
pattern_block_stack_.PrintForStackDump(formatter, Indent, output);
|
||||
param_and_arg_refs_stack_.PrintForStackDump(formatter, Indent, output);
|
||||
args_type_info_stack_.PrintForStackDump(formatter, Indent, output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user