[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 Brickner
2024-12-06 21:50:50 +00:00
committed by GitHub
co-authored by jonmeow
parent e7a86b03c6
commit daba2c72cf
19 changed files with 526 additions and 140 deletions
+2 -2
View File
@@ -198,7 +198,7 @@ static auto ImportCurrentPackage(Context& context, UnitInfo& unit_info,
unit_info.package_imports[import_map_lookup.value()];
if (self_import.has_load_error) {
context.name_scopes().Get(SemIR::NameScopeId::Package).has_error = true;
context.name_scopes().Get(SemIR::NameScopeId::Package).set_has_error();
}
ImportLibrariesFromCurrentPackage(
@@ -208,7 +208,7 @@ static auto ImportCurrentPackage(Context& context, UnitInfo& unit_info,
context.scope_stack().Push(
package_inst_id, SemIR::NameScopeId::Package, SemIR::SpecificId::Invalid,
context.name_scopes().Get(SemIR::NameScopeId::Package).has_error);
context.name_scopes().Get(SemIR::NameScopeId::Package).has_error());
}
// Imports all other packages (excluding the current package).