Factor out pushing / popping of names plus parameters. (#4005)

Previously we did some of this in decl_name_stack and some of it in the
callers of decl_name_stack. Factor out a single place to pop a name and
its optional following parameters.

Part of making this behavior consistent is that we now track whether an
implicit parameter list was present or absent rather than mapping an
absent list to `InstBlockId::Empty`. This improves our redeclaration
checking and the precision of some diagnostics.
This commit is contained in:
Richard Smith
2024-05-30 16:05:35 +00:00
committed by GitHub
parent cda5f66d22
commit 28cefe98df
24 changed files with 249 additions and 138 deletions
+5 -10
View File
@@ -9,6 +9,7 @@
#include "toolchain/check/eval.h"
#include "toolchain/check/merge.h"
#include "toolchain/check/modifiers.h"
#include "toolchain/check/name_component.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/typed_insts.h"
@@ -176,14 +177,8 @@ static auto MergeOrAddName(Context& context, Parse::AnyClassDeclId node_id,
static auto BuildClassDecl(Context& context, Parse::AnyClassDeclId node_id,
bool is_definition)
-> std::tuple<SemIR::ClassId, SemIR::InstId> {
auto param_refs_id =
context.node_stack().PopIf<Parse::NodeKind::TuplePattern>().value_or(
SemIR::InstBlockId::Invalid);
auto implicit_param_refs_id =
context.node_stack().PopIf<Parse::NodeKind::ImplicitParamList>().value_or(
SemIR::InstBlockId::Invalid);
auto name_context = context.decl_name_stack().FinishName();
auto name = PopNameComponent(context);
auto name_context = context.decl_name_stack().FinishName(name);
context.node_stack()
.PopAndDiscardSoloNodeId<Parse::NodeKind::ClassIntroducer>();
@@ -222,8 +217,8 @@ static auto BuildClassDecl(Context& context, Parse::AnyClassDeclId node_id,
SemIR::Class class_info = {
.name_id = name_context.name_id_for_new_inst(),
.enclosing_scope_id = name_context.enclosing_scope_id_for_new_inst(),
.implicit_param_refs_id = implicit_param_refs_id,
.param_refs_id = param_refs_id,
.implicit_param_refs_id = name.implicit_params_id,
.param_refs_id = name.params_id,
// `.self_type_id` depends on the ClassType, so is set below.
.self_type_id = SemIR::TypeId::Invalid,
.decl_id = class_decl_id,