-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vendored_typeshed_versions
should use db.vendored
#13434
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
use rustc_hash::{FxBuildHasher, FxHashSet}; | ||
use std::borrow::Cow; | ||
use std::iter::FusedIterator; | ||
use std::ops::Deref; | ||
|
||
use rustc_hash::{FxBuildHasher, FxHashSet}; | ||
|
||
use ruff_db::files::{File, FilePath, FileRootKind}; | ||
use ruff_db::system::{DirectoryEntry, System, SystemPath, SystemPathBuf}; | ||
use ruff_db::vendored::{VendoredFileSystem, VendoredPath}; | ||
|
||
use super::module::{Module, ModuleKind}; | ||
use super::path::{ModulePath, SearchPath, SearchPathValidationError}; | ||
use crate::db::Db; | ||
use crate::module_name::ModuleName; | ||
use crate::module_resolver::typeshed::{vendored_typeshed_versions, TypeshedVersions}; | ||
use crate::site_packages::VirtualEnvironment; | ||
use crate::{Program, PythonVersion, SearchPathSettings, SitePackages}; | ||
|
||
use super::module::{Module, ModuleKind}; | ||
use super::path::{ModulePath, SearchPath, SearchPathValidationError}; | ||
|
||
/// Resolves a module name to a module. | ||
pub fn resolve_module(db: &dyn Db, module_name: ModuleName) -> Option<Module> { | ||
let interned_name = ModuleNameIngredient::new(db, module_name); | ||
|
@@ -136,7 +137,7 @@ pub(crate) struct SearchPaths { | |
/// for the first `site-packages` path | ||
site_packages: Vec<SearchPath>, | ||
|
||
typeshed_versions: ResolvedTypeshedVersions, | ||
typeshed_versions: TypeshedVersions, | ||
} | ||
|
||
impl SearchPaths { | ||
|
@@ -202,11 +203,11 @@ impl SearchPaths { | |
|
||
let search_path = SearchPath::custom_stdlib(db, &custom_typeshed)?; | ||
|
||
(ResolvedTypeshedVersions::Custom(parsed), search_path) | ||
(parsed, search_path) | ||
} else { | ||
tracing::debug!("Using vendored stdlib"); | ||
( | ||
ResolvedTypeshedVersions::Vendored(vendored_typeshed_versions()), | ||
vendored_typeshed_versions(db), | ||
SearchPath::vendored_stdlib(), | ||
) | ||
}; | ||
|
@@ -279,23 +280,6 @@ impl SearchPaths { | |
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
enum ResolvedTypeshedVersions { | ||
Vendored(&'static TypeshedVersions), | ||
Custom(TypeshedVersions), | ||
} | ||
|
||
Comment on lines
-283
to
-286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why I didn't use |
||
impl Deref for ResolvedTypeshedVersions { | ||
type Target = TypeshedVersions; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
match self { | ||
ResolvedTypeshedVersions::Vendored(versions) => versions, | ||
ResolvedTypeshedVersions::Custom(versions) => versions, | ||
} | ||
} | ||
} | ||
|
||
/// Collect all dynamic search paths. For each `site-packages` path: | ||
/// - Collect that `site-packages` path | ||
/// - Collect any search paths listed in `.pth` files in that `site-packages` directory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to defer validating the vendored typeshed versions. They should be valid and whether we panic here or when trying to resolve the first module doesn't make a real difference. It results in a panic.
The only downside is that getting the versions is now a salsa lookup rather than a static field access. Let's see if this hurts performance in a meaningful way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, there's a 1% performance drop. That doesn't seem worth it.
I'm just gonna make
vendored_typeshed_versions
always parse the file without caching. This is an overall simplification and shouldn't hurt performance except in the case when we reconstruct theSearchPathSettings
because the project configuration has changed.... but that's a very slow path anyway and parsing the VERSIONS file should be rather fast