Skip to content

Commit e69fe8e

Browse files
[ScanDependency] Move binary module validation into scanner
Improve swift dependency scanner by validating and selecting dependency module into scanner. This provides benefits that: * Build system does not need to schedule interface compilation task if the candidate module is picked, it can just use the candidate module directly. * There is no need for forwarding module in the explicit module build. Since the build system is coordinating the build, there is no need for the forwarding module in the module cache to avoid duplicated work, * This also correctly supports all the module loading modes in the dependency scanner. This is achieved by only adding validate and up-to-date binary module as the candidate module for swift interface module dependency. This allows caching build to construct the correct dependency in the CAS. If there is a candidate module for the interface module, dependency scanner will return a binary module dependency in the dependency graph. rdar://123711823
1 parent 315a763 commit e69fe8e

File tree

12 files changed

+219
-167
lines changed

12 files changed

+219
-167
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,12 @@ class ModuleDependenciesCache {
11151115
std::optional<const ModuleDependencyInfo *>
11161116
findDependency(StringRef moduleName) const;
11171117

1118+
/// Look for known existing dependencies.
1119+
///
1120+
/// \returns the cached result.
1121+
const ModuleDependencyInfo &
1122+
findKnownDependency(const ModuleDependencyID &moduleID) const;
1123+
11181124
/// Record dependencies for the given module.
11191125
void recordDependency(StringRef moduleName,
11201126
ModuleDependencyInfo dependencies);

include/swift/AST/SearchPathOptions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ enum class ModuleSearchPathKind {
3838
RuntimeLibrary,
3939
};
4040

41+
/// Specifies how to load modules when both a module interface and serialized
42+
/// AST are present, or whether to disallow one format or the other altogether.
43+
enum class ModuleLoadingMode {
44+
PreferInterface,
45+
PreferSerialized,
46+
OnlyInterface,
47+
OnlySerialized
48+
};
49+
4150
/// A single module search path that can come from different sources, e.g.
4251
/// framework search paths, import search path etc.
4352
class ModuleSearchPath : public llvm::RefCountedBase<ModuleSearchPath> {
@@ -499,6 +508,9 @@ class SearchPathOptions {
499508
/// original form.
500509
PathObfuscator DeserializedPathRecoverer;
501510

511+
/// Specify the module loading behavior of the compilation.
512+
ModuleLoadingMode ModuleLoadMode = ModuleLoadingMode::PreferSerialized;
513+
502514
/// Return all module search paths that (non-recursively) contain a file whose
503515
/// name is in \p Filenames.
504516
SmallVector<const ModuleSearchPath *, 4>

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/FileUnit.h"
1717
#include "swift/AST/Module.h"
1818
#include "swift/AST/ModuleLoader.h"
19+
#include "swift/AST/SearchPathOptions.h"
1920
#include "llvm/Support/MemoryBuffer.h"
2021
#include "llvm/Support/PrefixMapper.h"
2122
#include "llvm/TargetParser/Triple.h"
@@ -28,15 +29,6 @@ namespace file_types {
2829
enum ID : uint8_t;
2930
}
3031

31-
/// Specifies how to load modules when both a module interface and serialized
32-
/// AST are present, or whether to disallow one format or the other altogether.
33-
enum class ModuleLoadingMode {
34-
PreferInterface,
35-
PreferSerialized,
36-
OnlyInterface,
37-
OnlySerialized
38-
};
39-
4032
/// How a dependency should be loaded.
4133
///
4234
/// \sa getTransitiveLoadingBehavior

lib/AST/ModuleDependencies.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,13 @@ ModuleDependenciesCache::findDependency(StringRef moduleName) const {
736736
return std::nullopt;
737737
}
738738

739+
const ModuleDependencyInfo &ModuleDependenciesCache::findKnownDependency(
740+
const ModuleDependencyID &moduleID) const {
741+
auto dep = findDependency(moduleID);
742+
assert(dep && "dependency unknown");
743+
return **dep;
744+
}
745+
739746
bool ModuleDependenciesCache::hasDependency(const ModuleDependencyID &moduleID) const {
740747
return hasDependency(moduleID.ModuleName, moduleID.Kind);
741748
}

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/ADT/SetOperations.h"
3030
#include "llvm/CAS/CachingOnDiskFileSystem.h"
3131
#include "llvm/Support/Error.h"
32+
#include "llvm/Support/Process.h"
3233
#include "llvm/Support/Threading.h"
3334
#include "llvm/Support/VirtualFileSystem.h"
3435
#include <algorithm>
@@ -175,7 +176,8 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
175176
ScanASTContext,
176177
*static_cast<ModuleInterfaceCheckerImpl *>(
177178
ScanASTContext.getModuleInterfaceChecker()),
178-
&DependencyTracker, ModuleLoadingMode::OnlyInterface);
179+
&DependencyTracker,
180+
ScanCompilerInvocation.getSearchPathOptions().ModuleLoadMode);
179181
}
180182

181183
ModuleDependencyVector

0 commit comments

Comments
 (0)