Skip to content

Commit c36ae0d

Browse files
authored
Merge pull request swiftlang#79818 from artemcm/SeparateSDKExplicitModules
[Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
2 parents 0aeba05 + 1c0caa6 commit c36ae0d

20 files changed

+170
-52
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,10 @@ class ModuleDependenciesCache {
11491149
std::string mainScanModuleName;
11501150
/// The context hash of the current scanning invocation
11511151
std::string scannerContextHash;
1152-
/// The location of where the built modules will be output to
1152+
/// The location of where the explicitly-built modules will be output to
11531153
std::string moduleOutputPath;
1154+
/// The location of where the explicitly-built SDK modules will be output to
1155+
std::string sdkModuleOutputPath;
11541156
/// The timestamp of the beginning of the scanning query action
11551157
/// using this cache
11561158
const llvm::sys::TimePoint<> scanInitializationTime;
@@ -1164,9 +1166,10 @@ class ModuleDependenciesCache {
11641166

11651167
public:
11661168
ModuleDependenciesCache(SwiftDependencyScanningService &globalScanningService,
1167-
std::string mainScanModuleName,
1168-
std::string moduleOutputPath,
1169-
std::string scanningContextHash);
1169+
const std::string &mainScanModuleName,
1170+
const std::string &moduleOutputPath,
1171+
const std::string &sdkModuleOutputPath,
1172+
const std::string &scanningContextHash);
11701173
ModuleDependenciesCache(const ModuleDependenciesCache &) = delete;
11711174
ModuleDependenciesCache &operator=(const ModuleDependenciesCache &) = delete;
11721175

@@ -1199,7 +1202,8 @@ class ModuleDependenciesCache {
11991202
void addSeenClangModule(clang::tooling::dependencies::ModuleID newModule) {
12001203
alreadySeenClangModules.insert(newModule);
12011204
}
1202-
std::string getModuleOutputPath() const { return moduleOutputPath; }
1205+
StringRef getModuleOutputPath() const { return moduleOutputPath; }
1206+
StringRef getSDKModuleOutputPath() const { return sdkModuleOutputPath; }
12031207

12041208
/// Query all dependencies
12051209
ModuleDependencyIDSetVector

include/swift/AST/ModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ModuleLoader {
372372
/// if no such module exists.
373373
virtual llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
374374
getModuleDependencies(Identifier moduleName,
375-
StringRef moduleOutputPath,
375+
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
376376
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
377377
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
378378
InterfaceSubContextDelegate &delegate,

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,11 @@ class ClangImporter final : public ClangModuleLoader {
485485
bridgeClangModuleDependencies(
486486
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
487487
clang::tooling::dependencies::ModuleDepsGraph &clangDependencies,
488-
StringRef moduleOutputPath, RemapPathCallback remapPath = nullptr);
488+
StringRef moduleOutputPath, StringRef stableModuleOutputPath,
489+
RemapPathCallback remapPath = nullptr);
489490

490491
llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
491-
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath,
492+
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
492493
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
493494
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
494495
InterfaceSubContextDelegate &delegate,

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ class ModuleDependencyScanningWorker {
3737

3838
private:
3939
/// Retrieve the module dependencies for the Clang module with the given name.
40-
ModuleDependencyVector
41-
scanFilesystemForClangModuleDependency(Identifier moduleName,
42-
StringRef moduleOutputPath,
43-
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenModules,
44-
llvm::PrefixMapper *prefixMapper);
40+
ModuleDependencyVector scanFilesystemForClangModuleDependency(
41+
Identifier moduleName, StringRef moduleOutputPath,
42+
StringRef sdkModuleOutputPath,
43+
const llvm::DenseSet<clang::tooling::dependencies::ModuleID>
44+
&alreadySeenModules,
45+
llvm::PrefixMapper *prefixMapper);
4546

4647
/// Retrieve the module dependencies for the Swift module with the given name.
47-
ModuleDependencyVector
48-
scanFilesystemForSwiftModuleDependency(Identifier moduleName, StringRef moduleOutputPath,
49-
llvm::PrefixMapper *prefixMapper,
50-
bool isTestableImport = false);
48+
ModuleDependencyVector scanFilesystemForSwiftModuleDependency(
49+
Identifier moduleName, StringRef moduleOutputPath,
50+
StringRef sdkModuleOutputPath, llvm::PrefixMapper *prefixMapper,
51+
bool isTestableImport = false);
5152

5253
/// Store cache entry for include tree.
5354
llvm::Error

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class FrontendOptions {
103103
/// dependency scanning.
104104
std::string ExplicitModulesOutputPath;
105105

106+
/// The path to output explicitly-built SDK module dependencies. Only relevant during
107+
/// dependency scanning.
108+
std::string ExplicitSDKModulesOutputPath;
109+
106110
/// The path to look in to find backup .swiftinterface files if those found
107111
/// from SDKs are failing.
108112
std::string BackupModuleInterfaceDir;

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,10 @@ def clang_scanner_module_cache_path : Separate<["-"], "clang-scanner-module-cach
21762176
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
21772177
HelpText<"Specifies the Clang dependency scanner module cache path">;
21782178

2179+
def sdk_module_cache_path : Separate<["-"], "sdk-module-cache-path">,
2180+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
2181+
HelpText<"Specifies the module cache path for explicitly-built SDK modules">;
2182+
21792183
def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">,
21802184
Flags<[FrontendOption, NewDriverOnlyOption]>,
21812185
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix=replacement>">;

include/swift/Sema/SourceLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class SourceLoader : public ModuleLoader {
9999
}
100100

101101
llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
102-
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath,
102+
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
103103
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
104104
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
105105
InterfaceSubContextDelegate &delegate,

include/swift/Serialization/ScanningLoaders.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
3939

4040
InterfaceSubContextDelegate &astDelegate;
4141

42-
/// Location where pre-built moduels are to be built into.
42+
/// Location where pre-built modules are to be built into.
4343
std::string moduleOutputPath;
44+
/// Location where pre-built SDK modules are to be built into.
45+
std::string sdkModuleOutputPath;
4446

4547
public:
4648
std::optional<ModuleDependencyInfo> dependencies;
4749

4850
SwiftModuleScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
4951
Identifier moduleName,
5052
InterfaceSubContextDelegate &astDelegate,
51-
StringRef moduleOutputPath, ScannerKind kind = MDS_plain)
53+
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
54+
ScannerKind kind = MDS_plain)
5255
: SerializedModuleLoaderBase(ctx, nullptr, LoadMode,
5356
/*IgnoreSwiftSourceInfoFile=*/true),
5457
kind(kind), moduleName(moduleName), astDelegate(astDelegate),
55-
moduleOutputPath(moduleOutputPath) {}
58+
moduleOutputPath(moduleOutputPath),
59+
sdkModuleOutputPath(sdkModuleOutputPath) {}
5660

5761
std::error_code findModuleFilesInDirectory(
5862
ImportPath::Element ModuleID, const SerializedModuleBaseName &BaseName,
@@ -93,9 +97,11 @@ class PlaceholderSwiftModuleScanner : public SwiftModuleScanner {
9397
Identifier moduleName,
9498
StringRef PlaceholderDependencyModuleMap,
9599
InterfaceSubContextDelegate &astDelegate,
96-
StringRef moduleOutputPath)
100+
StringRef moduleOutputPath,
101+
StringRef sdkModuleOutputPath)
97102
: SwiftModuleScanner(ctx, LoadMode, moduleName, astDelegate,
98-
moduleOutputPath, MDS_placeholder) {
103+
moduleOutputPath, sdkModuleOutputPath,
104+
MDS_placeholder) {
99105

100106
// FIXME: Find a better place for this map to live, to avoid
101107
// doing the parsing on every module.

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
264264
virtual void verifyAllModules() override;
265265

266266
virtual llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
267-
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath,
267+
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
268268
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
269269
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
270270
InterfaceSubContextDelegate &delegate,

lib/AST/ModuleDependencies.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,13 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
765765

766766
ModuleDependenciesCache::ModuleDependenciesCache(
767767
SwiftDependencyScanningService &globalScanningService,
768-
std::string mainScanModuleName, std::string moduleOutputPath,
769-
std::string scannerContextHash)
768+
const std::string &mainScanModuleName, const std::string &moduleOutputPath,
769+
const std::string &sdkModuleOutputPath, const std::string &scannerContextHash)
770770
: globalScanningService(globalScanningService),
771771
mainScanModuleName(mainScanModuleName),
772772
scannerContextHash(scannerContextHash),
773773
moduleOutputPath(moduleOutputPath),
774+
sdkModuleOutputPath(sdkModuleOutputPath),
774775
scanInitializationTime(std::chrono::system_clock::now()) {
775776
for (auto kind = ModuleDependencyKind::FirstKind;
776777
kind != ModuleDependencyKind::LastKind; ++kind)

0 commit comments

Comments
 (0)