Skip to content

Commit

Permalink
[red-knot] Fix bug where module resolution would not be invalidated i…
Browse files Browse the repository at this point in the history
…f an entire package was deleted (#12378)
  • Loading branch information
AlexWaygood committed Jul 19, 2024
1 parent ad19b3f commit 5f96f69
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/red_knot_module_resolver/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,9 @@ impl<'a> ModuleResolutionPathRefInner<'a> {

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

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

0 comments on commit 5f96f69

Please sign in to comment.