[Dependency Scanning] Have the scanner cache answer queries relevant to current search paths only.

The dependency scanner's cache persists across different queries and answering a subsequent query's module lookup with a module not in the query's search path is not correct.

For example, suppose we are looking for a Swift module `Foo` with a set of search paths `SP`.
And dependency scanner cache already contains a module `Foo`, for which we found an interface file at location `L`. If `L`∉`SP`, then we cannot re-use the cached entry because we’d be resolving the scanning query to a filesystem location that the current scanning context is not aware of.

Resolves rdar://81175942
This commit is contained in:
Artem Chikin
2021-07-29 10:46:48 -07:00
parent 77cb4b639c
commit 6a12dc0070
11 changed files with 480 additions and 141 deletions

View File

@@ -165,15 +165,19 @@ ErrorOr<ModuleDependencies> ModuleDependencyScanner::scanInterfaceFile(
Optional<ModuleDependencies> SerializedModuleLoaderBase::getModuleDependencies(
StringRef moduleName, ModuleDependenciesCache &cache,
InterfaceSubContextDelegate &delegate) {
auto currentSearchPathSet = Ctx.getAllModuleSearchPathsSet();
// Check whether we've cached this result.
if (auto found = cache.findDependencies(
moduleName, ModuleDependenciesKind::SwiftTextual))
moduleName,
{ModuleDependenciesKind::SwiftTextual, currentSearchPathSet}))
return found;
if (auto found = cache.findDependencies(
moduleName, ModuleDependenciesKind::SwiftBinary))
moduleName,
{ModuleDependenciesKind::SwiftBinary, currentSearchPathSet}))
return found;
if (auto found = cache.findDependencies(
moduleName, ModuleDependenciesKind::SwiftPlaceholder))
moduleName,
{ModuleDependenciesKind::SwiftPlaceholder, currentSearchPathSet}))
return found;
auto moduleId = Ctx.getIdentifier(moduleName);