Skip to content

Commit 5f96f69

Browse files
authored
[red-knot] Fix bug where module resolution would not be invalidated if an entire package was deleted (#12378)
1 parent ad19b3f commit 5f96f69

File tree

1 file changed

+10
-6
lines changed
  • crates/red_knot_module_resolver/src

1 file changed

+10
-6
lines changed

crates/red_knot_module_resolver/src/path.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,9 @@ impl<'a> ModuleResolutionPathRefInner<'a> {
369369

370370
#[must_use]
371371
fn is_regular_package(&self, search_path: Self, resolver: &ResolverState) -> bool {
372-
fn is_non_stdlib_pkg(state: &ResolverState, path: &SystemPath) -> bool {
373-
let file_system = state.system();
374-
file_system.path_exists(&path.join("__init__.py"))
375-
|| file_system.path_exists(&path.join("__init__.pyi"))
372+
fn is_non_stdlib_pkg(resolver: &ResolverState, path: &SystemPath) -> bool {
373+
system_path_to_file(resolver.db.upcast(), path.join("__init__.py")).is_some()
374+
|| system_path_to_file(resolver.db.upcast(), path.join("__init__.py")).is_some()
376375
}
377376

378377
match (self, search_path) {
@@ -387,8 +386,13 @@ impl<'a> ModuleResolutionPathRefInner<'a> {
387386
match Self::query_stdlib_version( path, search_path, &stdlib_root, resolver) {
388387
TypeshedVersionsQueryResult::DoesNotExist => false,
389388
TypeshedVersionsQueryResult::Exists | TypeshedVersionsQueryResult::MaybeExists => match path {
390-
FilePathRef::System(path) => resolver.db.system().path_exists(&path.join("__init__.pyi")),
391-
FilePathRef::Vendored(path) => resolver.db.vendored().exists(path.join("__init__.pyi")),
389+
FilePathRef::System(path) => system_path_to_file(resolver.db.upcast(),path.join("__init__.pyi")).is_some(),
390+
// No need to use `vendored_path_to_file` here:
391+
// (1) The vendored filesystem is immutable, so we don't need to worry about Salsa invalidation
392+
// (2) The caching Salsa provides probably won't speed us up that much
393+
// (TODO: check that assumption when we're able to run red-knot on larger code bases)
394+
// (3) We don't need the `File` object that `vendored_path_to_file` would return; we just need to know if the file exists
395+
FilePathRef::Vendored(path) => resolver.db.vendored().exists(path.join("__init__.pyi"))
392396
},
393397
}
394398
}

0 commit comments

Comments
 (0)