Implement #4864: Core is a keyword (#4909)

Change representation of package names from `IdentifierId` to
`PackageNameId`, and add a special value `PackageNameId::Core` for the
Core package. Add a `Core` expression to name the Core package, and
support for parsing the `Core` keyword in `package` and `import`
declarations.

For now, I've made no changes to instruction fingerprinting or name
mangling. This means that fingerprints and mangled names will collide
between names in the `Core` package and names in a `r#Core` package. See
#4908.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2025-02-11 21:33:57 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 50b3c825e4
commit 8eb4e24cb6
62 changed files with 935 additions and 487 deletions
+8 -4
View File
@@ -32,10 +32,14 @@ auto Mangler::MangleInverseQualifiedNameScope(llvm::raw_ostream& os,
os << prefix;
}
if (name_scope_id == SemIR::NameScopeId::Package) {
if (auto package_id = sem_ir().package_id(); package_id.has_value()) {
os << sem_ir().identifiers().Get(package_id);
auto package_id = sem_ir().package_id();
if (auto ident_id = package_id.AsIdentifierId(); ident_id.has_value()) {
os << sem_ir().identifiers().Get(ident_id);
} else {
os << "Main";
// TODO: Handle name conflicts between special package names and raw
// identifier package names. Note that any change here will also require
// a change to namespace mangling for imported packages.
os << package_id.AsSpecialName();
}
continue;
}
@@ -111,7 +115,7 @@ auto Mangler::MangleInverseQualifiedNameScope(llvm::raw_ostream& os,
break;
}
case SemIR::Namespace::Kind: {
os << names().GetAsStringIfIdentifier(name_scope.name_id());
os << names().GetIRBaseName(name_scope.name_id());
break;
}
default: