mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Clarify SourceFile's existing missing imports record.
In anticipation of adding a new kind of missing import record to `SourceFile`, clarify the purpose of the existing "missing imports" record with more specific naming and documentation.
This commit is contained in:
@@ -273,8 +273,8 @@ public:
|
||||
ModuleDecl::ImportFilter filter) const {}
|
||||
|
||||
/// Lists modules that are not imported from this file and used in API.
|
||||
virtual void
|
||||
getMissingImportedModules(SmallVectorImpl<ImportedModule> &imports) const {}
|
||||
virtual void getImplicitImportsForModuleInterface(
|
||||
SmallVectorImpl<ImportedModule> &imports) const {}
|
||||
|
||||
/// \see ModuleDecl::getImportedModulesForLookup
|
||||
virtual void getImportedModulesForLookup(
|
||||
|
||||
@@ -1034,8 +1034,8 @@ public:
|
||||
ImportFilter filter = ImportFilterKind::Exported) const;
|
||||
|
||||
/// Lists modules that are not imported from a file and used in API.
|
||||
void
|
||||
getMissingImportedModules(SmallVectorImpl<ImportedModule> &imports) const;
|
||||
void getImplicitImportsForModuleInterface(
|
||||
SmallVectorImpl<ImportedModule> &imports) const;
|
||||
|
||||
/// Looks up which modules are imported by this module, ignoring any that
|
||||
/// won't contain top-level decls.
|
||||
|
||||
@@ -159,6 +159,10 @@ private:
|
||||
/// The highest access level of declarations referencing each import.
|
||||
llvm::DenseMap<const ModuleDecl *, AccessLevel> ImportsUseAccessLevel;
|
||||
|
||||
/// Imports that should be printed in the module interface even though they
|
||||
/// were not written in the source file.
|
||||
llvm::SmallDenseSet<ImportedModule> ImplicitImportsForModuleInterface;
|
||||
|
||||
/// A unique identifier representing this file; used to mark private decls
|
||||
/// within the file to keep them from conflicting with other files in the
|
||||
/// same module.
|
||||
@@ -510,12 +514,20 @@ public:
|
||||
|
||||
SWIFT_DEBUG_DUMPER(dumpSeparatelyImportedOverlays());
|
||||
|
||||
llvm::SmallDenseSet<ImportedModule> MissingImportedModules;
|
||||
|
||||
void addMissingImportedModule(ImportedModule module) const {
|
||||
const_cast<SourceFile *>(this)->MissingImportedModules.insert(module);
|
||||
/// Record an import that should be printed in the module interface even
|
||||
/// though it was not written in the source file. These imports are needed in
|
||||
/// Swift 5 mode to preserve the integrity of swiftinterface files when code
|
||||
/// publicly use declarations from modules that were \c `@_implementationOnly`
|
||||
/// imported in other source files.
|
||||
void addImplicitImportForModuleInterface(ImportedModule module) {
|
||||
ImplicitImportsForModuleInterface.insert(module);
|
||||
}
|
||||
|
||||
/// Gather implicit imports that should printed in swiftinterfaces for
|
||||
/// compatibility with code in some Swift 5 modules.
|
||||
void getImplicitImportsForModuleInterface(
|
||||
SmallVectorImpl<ImportedModule> &imports) const override;
|
||||
|
||||
/// Record the source range info for a parsed \c #if clause.
|
||||
void recordIfConfigClauseRangeInfo(const IfConfigClauseRangeInfo &range);
|
||||
|
||||
@@ -527,10 +539,10 @@ public:
|
||||
ArrayRef<IfConfigClauseRangeInfo>
|
||||
getIfConfigClausesWithin(SourceRange outer) const;
|
||||
|
||||
void getMissingImportedModules(
|
||||
SmallVectorImpl<ImportedModule> &imports) const override;
|
||||
|
||||
/// Record visible declarations for use in code completion and refactoring.
|
||||
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
|
||||
|
||||
/// Retrieve visible declarations for use in code completion and refactoring.
|
||||
const SmallVectorImpl<ValueDecl *> &getCachedVisibleDecls() const;
|
||||
|
||||
virtual void lookupValue(DeclName name, NLKind lookupKind,
|
||||
|
||||
@@ -1720,9 +1720,9 @@ void ModuleDecl::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
|
||||
FORWARD(getImportedModules, (modules, filter));
|
||||
}
|
||||
|
||||
void ModuleDecl::getMissingImportedModules(
|
||||
void ModuleDecl::getImplicitImportsForModuleInterface(
|
||||
SmallVectorImpl<ImportedModule> &imports) const {
|
||||
FORWARD(getMissingImportedModules, (imports));
|
||||
FORWARD(getImplicitImportsForModuleInterface, (imports));
|
||||
}
|
||||
|
||||
const llvm::DenseMap<const clang::Module *, ModuleDecl *> &
|
||||
@@ -1811,9 +1811,9 @@ SourceFile::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
|
||||
}
|
||||
}
|
||||
|
||||
void SourceFile::getMissingImportedModules(
|
||||
void SourceFile::getImplicitImportsForModuleInterface(
|
||||
SmallVectorImpl<ImportedModule> &modules) const {
|
||||
for (auto module : MissingImportedModules)
|
||||
for (auto module : ImplicitImportsForModuleInterface)
|
||||
modules.push_back(module);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
|
||||
SmallVector<ImportedModule> imports;
|
||||
M->getImportedModules(imports, filter);
|
||||
M->getMissingImportedModules(imports);
|
||||
M->getImplicitImportsForModuleInterface(imports);
|
||||
|
||||
for (ImportedModule import: imports) {
|
||||
StringRef importedName = import.importedModule->getNameStr();
|
||||
@@ -337,7 +337,7 @@ static void printImports(raw_ostream &out,
|
||||
M->getImportedModules(allImports, allImportFilter);
|
||||
|
||||
if (Opts.PrintMissingImports)
|
||||
M->getMissingImportedModules(allImports);
|
||||
M->getImplicitImportsForModuleInterface(allImports);
|
||||
|
||||
ImportedModule::removeDuplicates(allImports);
|
||||
diagnoseScopedImports(ctx.Diags, allImports);
|
||||
|
||||
@@ -45,7 +45,7 @@ static bool addMissingImport(SourceLoc loc, const Decl *D,
|
||||
// API.
|
||||
auto missingImport = ImportedModule(ImportPath::Access(),
|
||||
const_cast<ModuleDecl *>(M));
|
||||
SF->addMissingImportedModule(missingImport);
|
||||
SF->addImplicitImportForModuleInterface(missingImport);
|
||||
ctx.Diags.diagnose(loc, diag::missing_import_inserted, M->getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user