Sema: Refactor superfluous public import tracking.

In anticipation of reusing minimum access level information for diagnostics
related to the `MemberImportVisibility` feature, refactor the way the type
checker tracks the modules which must be imported publicly. Recording minimum
access levels is no longer restricted to modules that are already imported in a
source file since `MemberImportVisibility` diagnostics will need this
information when emitting fix-its for modules that are not already imported.

Unblocks rdar://126637855.
This commit is contained in:
Allan Shortlidge
2024-08-01 13:51:15 -07:00
parent 9906199d8e
commit 53a137b78f
5 changed files with 86 additions and 62 deletions

View File

@@ -2728,10 +2728,8 @@ SourceFile::getMaxAccessLevelUsingImport(
return known->second;
}
void SourceFile::registerAccessLevelUsingImport(
AttributedImport<ImportedModule> import,
AccessLevel accessLevel) {
auto mod = import.module.importedModule;
void SourceFile::registerRequiredAccessLevelForModule(ModuleDecl *mod,
AccessLevel accessLevel) {
auto known = ImportsUseAccessLevel.find(mod);
if (known == ImportsUseAccessLevel.end())
ImportsUseAccessLevel[mod] = accessLevel;
@@ -2754,7 +2752,7 @@ void SourceFile::registerAccessLevelUsingImport(
auto otherImportModName = otherImportMod->getName();
if (otherImportMod == declaringMod ||
llvm::find(bystanders, otherImportModName) != bystanders.end()) {
registerAccessLevelUsingImport(otherImport, accessLevel);
registerRequiredAccessLevelForModule(otherImportMod, accessLevel);
}
}
}