Sorting out how bindings are added to name lookup. (#2869)

This shifts logic so that bindings are added to name lookup only after the scope is complete, removing logic around adding/removing/re-adding names in certain scopes.

This does mean that things like a function's forward declaration will need to go through an extra hoop for name conflict checks, because under this approach a function definition does conflict checking when it adds names for the body's use. But, that seems easy to address, and better than the current hoops.
This commit is contained in:
Jon Ross-Perkins
2023-06-01 16:50:34 -07:00
committed by GitHub
parent a1a7251716
commit 39f7aae98d
76 changed files with 484 additions and 620 deletions
@@ -139,6 +139,8 @@ class SemanticsNodeStack {
explicit Entry(ParseTree::Node parse_node,
SemanticsNodeBlockId node_block_id)
: parse_node(parse_node), node_block_id(node_block_id) {}
explicit Entry(ParseTree::Node parse_node, SemanticsFunctionId function_id)
: parse_node(parse_node), function_id(function_id) {}
explicit Entry(ParseTree::Node parse_node, SemanticsStringId name_id)
: parse_node(parse_node), name_id(name_id) {}
explicit Entry(ParseTree::Node parse_node, SemanticsTypeId type_id)
@@ -153,6 +155,9 @@ class SemanticsNodeStack {
if constexpr (std::is_same<T, SemanticsNodeBlockId>()) {
return node_block_id;
}
if constexpr (std::is_same<T, SemanticsFunctionId>()) {
return function_id;
}
if constexpr (std::is_same<T, SemanticsStringId>()) {
return name_id;
}
@@ -172,6 +177,7 @@ class SemanticsNodeStack {
union {
SemanticsNodeId node_id;
SemanticsNodeBlockId node_block_id;
SemanticsFunctionId function_id;
SemanticsStringId name_id;
SemanticsTypeId type_id;
};
@@ -184,6 +190,8 @@ class SemanticsNodeStack {
"Need standard layout for type punning");
static_assert(std::is_standard_layout_v<SemanticsNodeBlockId>,
"Need standard layout for type punning");
static_assert(std::is_standard_layout_v<SemanticsFunctionId>,
"Need standard layout for type punning");
static_assert(std::is_standard_layout_v<SemanticsStringId>,
"Need standard layout for type punning");
static_assert(std::is_standard_layout_v<SemanticsTypeId>,