[DependencyScanner] Change the scanner order to resolve placeholders first.

This is meant to address a problem that arises on incremental package builds:

A re-scan on an already-built package instead of a placeholder dependency produces a graph that contains a dependency consisting solely of the previously-built swiftmodule.
This is not the behaviour we would like. Instead, we should respect that this is a placeholder dependency and ensure that the dependency graph for that dependency itself captures the fact that a previously-built module exists using compiledModuleCandidates field of the dependency graph.
This commit is contained in:
Artem Chikin
2020-08-28 13:39:55 -07:00
parent c48a676a1c
commit 67eca9b794
4 changed files with 32 additions and 25 deletions

View File

@@ -176,13 +176,19 @@ Optional<ModuleDependencies> SerializedModuleLoaderBase::getModuleDependencies(
auto moduleId = Ctx.getIdentifier(moduleName);
// Instantiate dependency scanning "loaders".
SmallVector<std::unique_ptr<ModuleDependencyScanner>, 2> scanners;
scanners.push_back(std::make_unique<ModuleDependencyScanner>(
Ctx, LoadMode, moduleId, delegate));
// Placeholder dependencies must be resolved first, to prevent the ModuleDependencyScanner
// from first discovering artifacts of a previous build. Such artifacts are captured
// as compiledModuleCandidates in the dependency graph of the placeholder dependency module
// itself.
scanners.push_back(std::make_unique<PlaceholderSwiftModuleScanner>(
Ctx, LoadMode, moduleId, Ctx.SearchPathOpts.PlaceholderDependencyModuleMap,
delegate));
scanners.push_back(std::make_unique<ModuleDependencyScanner>(
Ctx, LoadMode, moduleId, delegate));
// Check whether there is a module with this name that we can import.
assert(isa<PlaceholderSwiftModuleScanner>(scanners[0].get()) &&
"Expected PlaceholderSwiftModuleScanner as the first dependency scanner loader.");
for (auto &scanner : scanners) {
if (scanner->canImportModule({moduleId, SourceLoc()})) {
// Record the dependencies.