Skip to content

Dependencies Scanner: report compiled Swift module paths if they are available #32633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,11 @@ class ASTContext final {
/// compiler.
/// \param isDWARF \c true if this module loader can load Clang modules
/// from DWARF.
/// \param IsInterface \c true if this module loader can load Swift textual
/// interface.
void addModuleLoader(std::unique_ptr<ModuleLoader> loader,
bool isClang = false, bool isDWARF = false);
bool isClang = false, bool isDWARF = false,
bool IsInterface = false);

/// Retrieve the module dependencies for the module with the given name.
///
Expand Down Expand Up @@ -791,6 +794,8 @@ class ASTContext final {
/// The loader is owned by the AST context.
ClangModuleLoader *getDWARFModuleLoader() const;

/// Retrieve the module interface loader for this ASTContext.
ModuleLoader *getModuleInterfaceLoader() const;
public:
namelookup::ImportCache &getImportCache() const;

Expand Down
7 changes: 3 additions & 4 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ class ModuleDependencies {
/// Describe the module dependencies for a Swift module that can be
/// built from a Swift interface file (\c .swiftinterface).
static ModuleDependencies forSwiftInterface(
const std::string &compiledModulePath,
const std::string &swiftInterfaceFile,
ArrayRef<StringRef> buildCommands,
ArrayRef<StringRef> extraPCMArgs,
StringRef contextHash) {
std::string compiledModulePath;
return ModuleDependencies(
std::make_unique<SwiftModuleDependenciesStorage>(
compiledModulePath, swiftInterfaceFile, buildCommands,
Expand All @@ -201,9 +201,8 @@ class ModuleDependencies {
}

/// Describe the main Swift module.
static ModuleDependencies forMainSwiftModule(
const std::string &compiledModulePath,
ArrayRef<StringRef> extraPCMArgs) {
static ModuleDependencies forMainSwiftModule(ArrayRef<StringRef> extraPCMArgs) {
std::string compiledModulePath;
return ModuleDependencies(
std::make_unique<SwiftModuleDependenciesStorage>(
compiledModulePath, None, ArrayRef<StringRef>(), extraPCMArgs,
Expand Down
4 changes: 3 additions & 1 deletion include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) override;

bool isCached(StringRef DepPath) override;

public:
static std::unique_ptr<ModuleInterfaceLoader>
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
Expand Down Expand Up @@ -235,6 +234,9 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
StringRef ModuleName, StringRef InPath, StringRef OutPath,
bool SerializeDependencyHashes, bool TrackSystemDependencies,
ModuleInterfaceLoaderOptions Opts);

std::string getUpToDateCompiledModuleForInterface(StringRef moduleName,
StringRef interfacePath) override;
};

struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
Expand Down
12 changes: 6 additions & 6 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class SerializedModuleLoaderBase : public ModuleLoader {
virtual Optional<ModuleDependencies> getModuleDependencies(
StringRef moduleName, ModuleDependenciesCache &cache,
InterfaceSubContextDelegate &delegate) override;

virtual std::string getUpToDateCompiledModuleForInterface(StringRef moduleName,
StringRef interfacePath) {
return std::string();
}
};

/// Imports serialized Swift modules into an ASTContext.
Expand Down Expand Up @@ -445,12 +450,7 @@ class SerializedASTFile final : public LoadedFile {
}
};

Optional<StringRef>
computePrebuiltModulePath(ASTContext &ctx,
StringRef interfacePath,
StringRef prebuiltCacheDir,
StringRef moduleName,
llvm::SmallString<256> &scratch);

} // end namespace swift

#endif
12 changes: 10 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ struct ASTContext::Implementation {
/// The module loader used to load Clang modules from DWARF.
ClangModuleLoader *TheDWARFModuleLoader = nullptr;

/// The module loader used to load Swift textual interface.
ModuleLoader *TheModuleInterfaceLoader = nullptr;

/// Map from Swift declarations to raw comments.
llvm::DenseMap<const Decl *, RawComment> RawComments;

Expand Down Expand Up @@ -1450,14 +1453,15 @@ void ASTContext::addSearchPath(StringRef searchPath, bool isFramework,
}

void ASTContext::addModuleLoader(std::unique_ptr<ModuleLoader> loader,
bool IsClang, bool IsDwarf) {
bool IsClang, bool IsDwarf, bool IsInterface) {
if (IsClang && !IsDwarf && !getImpl().TheClangModuleLoader)
getImpl().TheClangModuleLoader =
static_cast<ClangModuleLoader *>(loader.get());
if (IsClang && IsDwarf && !getImpl().TheDWARFModuleLoader)
getImpl().TheDWARFModuleLoader =
static_cast<ClangModuleLoader *>(loader.get());

if (IsInterface && !getImpl().TheModuleInterfaceLoader)
getImpl().TheModuleInterfaceLoader = loader.get();
getImpl().ModuleLoaders.push_back(std::move(loader));
}

Expand Down Expand Up @@ -1532,6 +1536,10 @@ ClangModuleLoader *ASTContext::getDWARFModuleLoader() const {
return getImpl().TheDWARFModuleLoader;
}

ModuleLoader *ASTContext::getModuleInterfaceLoader() const {
return getImpl().TheModuleInterfaceLoader;
}

ModuleDecl *ASTContext::getLoadedModule(
ArrayRef<Located<Identifier>> ModulePath) const {
assert(!ModulePath.empty());
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ bool CompilerInstance::setUpModuleLoaders() {
getDependencyTracker(), MLM, FEOpts.PreferInterfaceForModules,
LoaderOpts,
IgnoreSourceInfoFile);
Context->addModuleLoader(std::move(PIML));
Context->addModuleLoader(std::move(PIML), false, false, true);
}

std::unique_ptr<SerializedModuleLoader> SML =
Expand Down
Loading