Skip to content

Commit e2eb8c8

Browse files
committed
[Dependency Scanner] Do not re-use prior source dependencies in successive scans
If a scanner instance is used for multiple scans, the `SwiftDependencyScanningService` will have collected prior scans' main source modules' dependency info. Suppose the scanner first scans a source module `A` and records its dependencies. If a successive scan of some source module `B` finds that it depends on `A`, it would get a cache hit on the source module from a prior scan and re-use dependency information. This change no longer allows such re-use of the prior source module scan dependencies. Said prior scan may have had an entirely different context and therefore different set of dependencies on `A` than may be visible otherwise. Instead, all scanning actions must rely on such modules being re-discovered on the filesystem.
1 parent eecde02 commit e2eb8c8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/AST/ModuleDependencies.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,19 @@ ModuleDependenciesCache::ModuleDependenciesCache(
422422
Optional<const ModuleDependencyInfo*>
423423
ModuleDependenciesCache::findDependency(
424424
StringRef moduleName, Optional<ModuleDependencyKind> kind) const {
425-
return globalScanningService.findDependency(moduleName, kind);
425+
auto optionalDep = globalScanningService.findDependency(moduleName, kind);
426+
// During a scan, only produce the cached source module info for the current module
427+
// under scan.
428+
if (optionalDep.hasValue()) {
429+
auto dep = optionalDep.getValue();
430+
if (dep->getAsSwiftSourceModule() &&
431+
moduleName != mainScanModuleName &&
432+
moduleName != "DummyMainModuleForResolvingCrossImportOverlays") {
433+
return None;
434+
}
435+
}
436+
437+
return optionalDep;
426438
}
427439

428440
bool ModuleDependenciesCache::hasDependency(

0 commit comments

Comments
 (0)