[NFC] Convert NameScope from struct to class (#4623)

This is a preparation change for adding name poisoning support
(https://github.com/carbon-language/carbon-lang/issues/4622), which is
expected to require more elaborate logic around NameScope since a name
can be not defined yet, defined, or poisoned.

The API separates looking up a name from getting the full entry since we
have cases where the entries are invalidated between the time we're
looking for the name and when we access (and sometimes modify) the
entry.

This change has the following benefits:
* `names` and `name_map` are internal to `NameScope` and are guaranteed
to match.
* `extended_scopes` and `import_ir_scopes` can not be manipulated (only
new scopes can be added).
* `inst_id`, `name_id` and `parent_scope_id` are constants.
* `has_error` can only be mutated from false to true.

---------

Co-authored-by: jonmeow <jperkins@google.com>
This commit is contained in:
Boaz Bricknerandjonmeow authored and GitHub committed 2024-12-06 21:50:50 +00:00
1 parent e7a86b03c6
commit daba2c72cf
19 files changed
+526 -140

No files matched your search

+2 -2
View File
@@ -81,8 +81,8 @@ auto HandleParseNode(Context& context, Parse::ExportDeclId node_id) -> bool {
// diagnostic and so that cross-package imports can find it easily.
auto entity_name = context.entity_names().Get(import_ref->entity_name_id);
auto& parent_scope = context.name_scopes().Get(entity_name.parent_scope_id);
auto lookup = parent_scope.name_map.Lookup(entity_name.name_id);
auto& scope_inst_id = parent_scope.names[lookup.value()].inst_id;
auto& scope_inst_id =
parent_scope.GetEntry(*parent_scope.Lookup(entity_name.name_id)).inst_id;
CARBON_CHECK(scope_inst_id == inst_id);
scope_inst_id = export_id;