Refactor NodeStack APIs to better handle the increase of distinct ID types. (#2864)

I'm looking at adding CallableId, so figured I'd do this API refactoring which should reduce code duplication. This increases the amount of cross-calls between APIs because it may not be an issue for performance after optimizations, and should simplify reading of the API.

Also note the prior static_asserts on layout were missing a couple types, which is why I'm moving them into Entry where it's going to be more obvious when something's added.
This commit is contained in:
Jon Ross-Perkins
2023-06-01 16:39:02 -07:00
committed by GitHub
parent c83eea3ce2
commit a1a7251716
7 changed files with 166 additions and 259 deletions
@@ -18,8 +18,8 @@ auto SemanticsHandleFunctionDefinition(SemanticsContext& context,
ParseNodeKind::FunctionDefinitionStart) {
context.node_stack().PopAndIgnore();
}
auto decl_id =
context.node_stack().PopForNodeId(ParseNodeKind::FunctionDefinitionStart);
auto decl_id = context.node_stack().Pop<SemanticsNodeId>(
ParseNodeKind::FunctionDefinitionStart);
context.return_scope_stack().pop_back();
context.PopScope();
@@ -38,13 +38,13 @@ auto SemanticsHandleFunctionDefinitionStart(SemanticsContext& context,
if (context.parse_tree().node_kind(context.node_stack().PeekParseNode()) ==
ParseNodeKind::ReturnType) {
return_type_id =
context.node_stack().PopForTypeId(ParseNodeKind::ReturnType);
context.node_stack().Pop<SemanticsTypeId>(ParseNodeKind::ReturnType);
} else {
// Canonicalize the empty tuple for the implicit return.
context.CanonicalizeType(SemanticsNodeId::BuiltinEmptyTupleType);
}
auto param_refs_id =
context.node_stack().PopForNodeBlockId(ParseNodeKind::ParameterList);
auto param_refs_id = context.node_stack().Pop<SemanticsNodeBlockId>(
ParseNodeKind::ParameterList);
auto name_node =
context.node_stack().PopForSoloParseNode(ParseNodeKind::DeclaredName);
auto fn_node = context.node_stack().PopForSoloParseNode(