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
@@ -27,11 +27,13 @@ auto SemanticsHandleStructFieldDesignator(SemanticsContext& context,
auto SemanticsHandleStructFieldType(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto [type_node, type_id] = context.node_stack().PopForParseNodeAndNodeId();
auto [type_node, type_id] =
context.node_stack().PopWithParseNode<SemanticsNodeId>();
SemanticsTypeId cast_type_id = context.ExpressionAsType(type_node, type_id);
auto [name_node, name_id] = context.node_stack().PopForParseNodeAndNameId(
ParseNodeKind::DesignatedName);
auto [name_node, name_id] =
context.node_stack().PopWithParseNode<SemanticsStringId>(
ParseNodeKind::DesignatedName);
context.AddNode(
SemanticsNode::StructTypeField::Make(name_node, cast_type_id, name_id));
@@ -47,8 +49,8 @@ auto SemanticsHandleStructFieldUnknown(SemanticsContext& context,
auto SemanticsHandleStructFieldValue(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto [value_parse_node, value_node_id] =
context.node_stack().PopForParseNodeAndNodeId();
auto [_, name_id] = context.node_stack().PopForParseNodeAndNameId(
context.node_stack().PopWithParseNode<SemanticsNodeId>();
auto name_id = context.node_stack().Pop<SemanticsStringId>(
ParseNodeKind::DesignatedName);
// Store the name for the type.