Skip to content

Commit fcbf14f

Browse files
[DependencyScan] Prevent command-line flags added again on re-scan
Add a flag `finalized` to indicate that a module entry in the dependency cache is finalized and no longer needs to be updated. This prevents the command-line flags from dependency inputs get added multiple times on re-scan with the same service. While during normal compilation, adding the same command-line flags multiple times are fine, it is bad for caching builds as a new compilation cache key needs to be computed every time.
1 parent 6e5a300 commit fcbf14f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ModuleDependencyInfoStorageBase {
116116
const std::vector<std::string> &moduleImports,
117117
StringRef moduleCacheKey = "")
118118
: dependencyKind(dependencyKind), moduleImports(moduleImports),
119-
moduleCacheKey(moduleCacheKey.str()), resolved(false) {}
119+
moduleCacheKey(moduleCacheKey.str()), resolved(false), finalized(false) {}
120120

121121
virtual ModuleDependencyInfoStorageBase *clone() const = 0;
122122

@@ -138,6 +138,7 @@ class ModuleDependencyInfoStorageBase {
138138
std::string moduleCacheKey;
139139

140140
bool resolved;
141+
bool finalized;
141142
};
142143

143144
struct CommonSwiftTextualModuleDependencyDetails {
@@ -604,6 +605,13 @@ class ModuleDependencyInfo {
604605
storage->resolved = isResolved;
605606
}
606607

608+
bool isFinalized() const {
609+
return storage->finalized;
610+
}
611+
void setIsFinalized(bool isFinalized) {
612+
storage->finalized = isFinalized;
613+
}
614+
607615
/// For a Source dependency, register a `Testable` import
608616
void addTestableImport(ImportPath::Module module);
609617

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ static llvm::Error resolveExplicitModuleInputs(
302302
if (moduleID.second == ModuleDependencyKind::SwiftPlaceholder)
303303
return llvm::Error::success();
304304

305+
// If the dependency is already finalized, nothing needs to be done.
306+
if (resolvingDepInfo.isFinalized())
307+
return llvm::Error::success();
308+
305309
std::vector<std::string> rootIDs;
306310
if (auto ID = resolvingDepInfo.getCASFSRootID())
307311
rootIDs.push_back(*ID);
@@ -505,6 +509,7 @@ static llvm::Error resolveExplicitModuleInputs(
505509
return E;
506510
}
507511
}
512+
dependencyInfoCopy.setIsFinalized(true);
508513
cache.updateDependency(moduleID, dependencyInfoCopy);
509514

510515
return llvm::Error::success();

0 commit comments

Comments
 (0)