Skip to content

Commit 3e8166e

Browse files
authored
Merge pull request #32633 from nkcsgexi/build-forward-module-from-command-line
Dependencies Scanner: report compiled Swift module paths if they are available
2 parents 3da8595 + 84dd4db commit 3e8166e

File tree

13 files changed

+248
-192
lines changed

13 files changed

+248
-192
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,11 @@ class ASTContext final {
716716
/// compiler.
717717
/// \param isDWARF \c true if this module loader can load Clang modules
718718
/// from DWARF.
719+
/// \param IsInterface \c true if this module loader can load Swift textual
720+
/// interface.
719721
void addModuleLoader(std::unique_ptr<ModuleLoader> loader,
720-
bool isClang = false, bool isDWARF = false);
722+
bool isClang = false, bool isDWARF = false,
723+
bool IsInterface = false);
721724

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

797+
/// Retrieve the module interface loader for this ASTContext.
798+
ModuleLoader *getModuleInterfaceLoader() const;
794799
public:
795800
namelookup::ImportCache &getImportCache() const;
796801

include/swift/AST/ModuleDependencies.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ class ModuleDependencies {
180180
/// Describe the module dependencies for a Swift module that can be
181181
/// built from a Swift interface file (\c .swiftinterface).
182182
static ModuleDependencies forSwiftInterface(
183-
const std::string &compiledModulePath,
184183
const std::string &swiftInterfaceFile,
185184
ArrayRef<StringRef> buildCommands,
186185
ArrayRef<StringRef> extraPCMArgs,
187186
StringRef contextHash) {
187+
std::string compiledModulePath;
188188
return ModuleDependencies(
189189
std::make_unique<SwiftModuleDependenciesStorage>(
190190
compiledModulePath, swiftInterfaceFile, buildCommands,
@@ -201,9 +201,8 @@ class ModuleDependencies {
201201
}
202202

203203
/// Describe the main Swift module.
204-
static ModuleDependencies forMainSwiftModule(
205-
const std::string &compiledModulePath,
206-
ArrayRef<StringRef> extraPCMArgs) {
204+
static ModuleDependencies forMainSwiftModule(ArrayRef<StringRef> extraPCMArgs) {
205+
std::string compiledModulePath;
207206
return ModuleDependencies(
208207
std::make_unique<SwiftModuleDependenciesStorage>(
209208
compiledModulePath, None, ArrayRef<StringRef>(), extraPCMArgs,

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
202202
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) override;
203203

204204
bool isCached(StringRef DepPath) override;
205-
206205
public:
207206
static std::unique_ptr<ModuleInterfaceLoader>
208207
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
@@ -235,6 +234,9 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
235234
StringRef ModuleName, StringRef InPath, StringRef OutPath,
236235
bool SerializeDependencyHashes, bool TrackSystemDependencies,
237236
ModuleInterfaceLoaderOptions Opts);
237+
238+
std::string getUpToDateCompiledModuleForInterface(StringRef moduleName,
239+
StringRef interfacePath) override;
238240
};
239241

240242
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class SerializedModuleLoaderBase : public ModuleLoader {
200200
virtual Optional<ModuleDependencies> getModuleDependencies(
201201
StringRef moduleName, ModuleDependenciesCache &cache,
202202
InterfaceSubContextDelegate &delegate) override;
203+
204+
virtual std::string getUpToDateCompiledModuleForInterface(StringRef moduleName,
205+
StringRef interfacePath) {
206+
return std::string();
207+
}
203208
};
204209

205210
/// Imports serialized Swift modules into an ASTContext.
@@ -445,12 +450,7 @@ class SerializedASTFile final : public LoadedFile {
445450
}
446451
};
447452

448-
Optional<StringRef>
449-
computePrebuiltModulePath(ASTContext &ctx,
450-
StringRef interfacePath,
451-
StringRef prebuiltCacheDir,
452-
StringRef moduleName,
453-
llvm::SmallString<256> &scratch);
453+
454454
} // end namespace swift
455455

456456
#endif

lib/AST/ASTContext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ struct ASTContext::Implementation {
263263
/// The module loader used to load Clang modules from DWARF.
264264
ClangModuleLoader *TheDWARFModuleLoader = nullptr;
265265

266+
/// The module loader used to load Swift textual interface.
267+
ModuleLoader *TheModuleInterfaceLoader = nullptr;
268+
266269
/// Map from Swift declarations to raw comments.
267270
llvm::DenseMap<const Decl *, RawComment> RawComments;
268271

@@ -1450,14 +1453,15 @@ void ASTContext::addSearchPath(StringRef searchPath, bool isFramework,
14501453
}
14511454

14521455
void ASTContext::addModuleLoader(std::unique_ptr<ModuleLoader> loader,
1453-
bool IsClang, bool IsDwarf) {
1456+
bool IsClang, bool IsDwarf, bool IsInterface) {
14541457
if (IsClang && !IsDwarf && !getImpl().TheClangModuleLoader)
14551458
getImpl().TheClangModuleLoader =
14561459
static_cast<ClangModuleLoader *>(loader.get());
14571460
if (IsClang && IsDwarf && !getImpl().TheDWARFModuleLoader)
14581461
getImpl().TheDWARFModuleLoader =
14591462
static_cast<ClangModuleLoader *>(loader.get());
1460-
1463+
if (IsInterface && !getImpl().TheModuleInterfaceLoader)
1464+
getImpl().TheModuleInterfaceLoader = loader.get();
14611465
getImpl().ModuleLoaders.push_back(std::move(loader));
14621466
}
14631467

@@ -1532,6 +1536,10 @@ ClangModuleLoader *ASTContext::getDWARFModuleLoader() const {
15321536
return getImpl().TheDWARFModuleLoader;
15331537
}
15341538

1539+
ModuleLoader *ASTContext::getModuleInterfaceLoader() const {
1540+
return getImpl().TheModuleInterfaceLoader;
1541+
}
1542+
15351543
ModuleDecl *ASTContext::getLoadedModule(
15361544
ArrayRef<Located<Identifier>> ModulePath) const {
15371545
assert(!ModulePath.empty());

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool CompilerInstance::setUpModuleLoaders() {
504504
getDependencyTracker(), MLM, FEOpts.PreferInterfaceForModules,
505505
LoaderOpts,
506506
IgnoreSourceInfoFile);
507-
Context->addModuleLoader(std::move(PIML));
507+
Context->addModuleLoader(std::move(PIML), false, false, true);
508508
}
509509

510510
std::unique_ptr<SerializedModuleLoader> SML =

0 commit comments

Comments
 (0)