Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/ruff_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ mimalloc = { workspace = true }
tikv-jemallocator = { workspace = true }

[dev-dependencies]
rustc-hash = { workspace = true }
rayon = { workspace = true }
3 changes: 1 addition & 2 deletions crates/ruff_benchmark/benches/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::ops::Range;

use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use rayon::ThreadPoolBuilder;
use rustc_hash::FxHashSet;

use ruff_benchmark::TestFile;
use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity};
Expand All @@ -18,7 +17,7 @@ use ruff_python_ast::PythonVersion;
use ty_project::metadata::options::{EnvironmentOptions, Options};
use ty_project::metadata::value::{RangedValue, RelativePathBuf};
use ty_project::watch::{ChangeEvent, ChangedKind};
use ty_project::{CheckMode, Db, ProjectDatabase, ProjectMetadata};
use ty_project::{CheckMode, Db, FxHashSet, ProjectDatabase, ProjectMetadata};

struct Case {
db: ProjectDatabase,
Expand Down
2 changes: 1 addition & 1 deletion crates/ty/tests/file_watching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl TestCase {
let mut expected: HashSet<_> = expected.into_iter().collect();

let actual = self.db().project().files(self.db());
for file in &actual {
for file in actual.unstable_iter() {
assert!(
expected.remove(&file),
"Indexed project files contains '{}' which was not expected.",
Expand Down
1 change: 0 additions & 1 deletion crates/ty_ide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ get-size2 = { workspace = true }
itertools = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
salsa = { workspace = true, features = ["compact_str"] }
smallvec = { workspace = true }
tracing = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/ty_ide/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The main differences here are:
3. It doesn't have as many facilities as `ruff_linter`'s importer.
*/

use rustc_hash::FxHashMap;
use ty_python_semantic::FxHashMap;

use ruff_db::files::File;
use ruff_db::parsed::ParsedModuleRef;
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<'ast> MembersInScope<'ast> {
let model = SemanticModel::new(db, file);
let map = model
.members_in_scope_at(node)
.into_iter()
.unstable_into_iter()
.map(|(name, memberdef)| {
let def = memberdef.first_reachable_definition;
let kind = match *def.kind(db) {
Expand Down
4 changes: 2 additions & 2 deletions crates/ty_ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ use ruff_db::{
vendored::VendoredPath,
};
use ruff_text_size::{Ranged, TextRange};
use rustc_hash::FxHashSet;
use std::ops::{Deref, DerefMut};
use ty_project::Db;
use ty_python_semantic::FxHashSet;
use ty_python_semantic::types::{Type, TypeDefinition};

/// Information associated with a text range.
Expand Down Expand Up @@ -216,7 +216,7 @@ impl NavigationTargets {
if unique.is_empty() {
Self::empty()
} else {
let mut targets = unique.into_iter().collect::<Vec<_>>();
let mut targets = unique.unstable_into_iter().collect::<Vec<_>>();
targets.sort_by_key(|target| (target.file, target.focus_range.start()));
Self(targets.into())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_ide/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) fn references(
// Check if the symbol is potentially visible outside of this module
if search_across_files && is_symbol_externally_visible(goto_target) {
// Look for references in all other files within the workspace
for other_file in &db.project().files(db) {
for other_file in db.project().files(db).unstable_iter() {
// Skip the current file as we already processed it
if other_file == file {
continue;
Expand Down
6 changes: 3 additions & 3 deletions crates/ty_ide/src/workspace_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec<WorkspaceSymbolInfo> {

rayon::scope(move |s| {
// For each file, extract symbols and add them to results
for file in files.iter() {
for file in files.unstable_iter() {
let db = db.dyn_clone();
s.spawn(move |_| {
for (_, symbol) in symbols_for_file_global_only(&*db, *file).search(query) {
for (_, symbol) in symbols_for_file_global_only(&*db, file).search(query) {
// It seems like we could do better here than
// locking `results` for every single symbol,
// but this works pretty well as it is.
results.lock().unwrap().push(WorkspaceSymbolInfo {
symbol: symbol.to_owned(),
file: *file,
file,
});
}
});
Expand Down
1 change: 0 additions & 1 deletion crates/ty_project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ordermap = { workspace = true, features = ["serde"] }
rayon = { workspace = true }
regex = { workspace = true }
regex-automata = { workspace = true }
rustc-hash = { workspace = true }
salsa = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions crates/ty_project/src/db/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use ruff_db::Db as _;
use ruff_db::file_revision::FileRevision;
use ruff_db::files::{File, FileRootKind, Files};
use ruff_db::system::SystemPath;
use rustc_hash::FxHashSet;
use salsa::Setter;
use ty_python_semantic::FxHashSet;
use ty_python_semantic::Program;

/// Represents the result of applying changes to the project database.
Expand Down Expand Up @@ -317,7 +317,9 @@ impl ProjectDatabase {
}
}

let diagnostics = if let Some(walker) = ProjectFilesWalker::incremental(self, added_paths) {
let diagnostics = if let Some(walker) =
ProjectFilesWalker::incremental(self, added_paths.unstable_into_iter())
{
// Use directory walking to discover newly added files.
let (files, diagnostics) = walker.collect_vec(self);

Expand Down
23 changes: 8 additions & 15 deletions crates/ty_project/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::Arc;

use rustc_hash::FxHashSet;
use salsa::Setter;

use ruff_db::files::File;

use crate::db::Db;
use crate::{IOErrorDiagnostic, Project};
use ty_python_semantic::FxHashSet;

/// The indexed files of a project.
///
Expand Down Expand Up @@ -164,6 +164,10 @@ impl Indexed<'_> {
pub(super) fn len(&self) -> usize {
self.inner.files.len()
}

pub fn unstable_iter(&self) -> IndexedIter<'_> {
self.inner.files.unstable_iter().copied()
}
}

impl Deref for Indexed<'_> {
Expand All @@ -176,15 +180,6 @@ impl Deref for Indexed<'_> {

pub(super) type IndexedIter<'a> = std::iter::Copied<std::collections::hash_set::Iter<'a, File>>;

impl<'a> IntoIterator for &'a Indexed<'_> {
type Item = File;
type IntoIter = IndexedIter<'a>;

fn into_iter(self) -> Self::IntoIter {
self.inner.files.iter().copied()
}
}

/// A Mutable view of a project's indexed files.
///
/// Allows in-place mutation of the files without deep cloning the hash set.
Expand Down Expand Up @@ -251,12 +246,10 @@ impl Drop for IndexedMut<'_> {

#[cfg(test)]
mod tests {
use rustc_hash::FxHashSet;

use crate::ProjectMetadata;
use crate::db::Db;
use crate::db::tests::TestDb;
use crate::files::Index;
use crate::{FxHashSet, ProjectMetadata};
use ruff_db::files::system_path_to_file;
use ruff_db::system::{DbWithWritableSystem as _, SystemPathBuf};
use ruff_python_ast::name::Name;
Expand Down Expand Up @@ -288,8 +281,8 @@ mod tests {
}
Index::Indexed(files_2) => {
assert_eq!(
files_2.iter().collect::<Vec<_>>(),
files.iter().collect::<Vec<_>>()
files_2.unstable_iter().collect::<Vec<_>>(),
files.unstable_iter().collect::<Vec<_>>()
);
}
}
Expand Down
15 changes: 5 additions & 10 deletions crates/ty_project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use ruff_db::files::{File, FileRootKind};
use ruff_db::parsed::parsed_module;
use ruff_db::source::{SourceTextError, source_text};
use ruff_db::system::{SystemPath, SystemPathBuf};
use rustc_hash::FxHashSet;
use salsa::Durability;
use salsa::Setter;
use std::backtrace::BacktraceStatus;
Expand All @@ -31,6 +30,7 @@ use tracing::error;
use ty_python_semantic::add_inferred_python_version_hint_to_diagnostic;
use ty_python_semantic::lint::RuleSelection;
use ty_python_semantic::types::check_types;
pub use ty_python_semantic::{FxHashMap, FxHashSet};

mod db;
mod files;
Expand Down Expand Up @@ -286,7 +286,7 @@ impl Project {
let project_span = &project_span;

rayon::scope(move |scope| {
for file in &files {
for file in files.unstable_iter() {
let db = db.clone();
let reporter = &*reporter;
scope.spawn(move |_| {
Expand Down Expand Up @@ -612,16 +612,11 @@ impl<'a> ProjectFiles<'a> {
ProjectFiles::Indexed(files) => files.len(),
}
}
}

impl<'a> IntoIterator for &'a ProjectFiles<'a> {
type Item = File;
type IntoIter = ProjectFilesIter<'a>;

fn into_iter(self) -> Self::IntoIter {
fn unstable_iter(&self) -> ProjectFilesIter<'_> {
match self {
ProjectFiles::OpenFiles(files) => ProjectFilesIter::OpenFiles(files.iter()),
ProjectFiles::Indexed(files) => ProjectFilesIter::Indexed(files.into_iter()),
ProjectFiles::OpenFiles(files) => ProjectFilesIter::OpenFiles(files.unstable_iter()),
ProjectFiles::Indexed(files) => ProjectFilesIter::Indexed(files.unstable_iter()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_project/src/metadata/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use ruff_db::vendored::VendoredFileSystem;
use ruff_macros::{Combine, OptionsMetadata, RustDoc};
use ruff_options_metadata::{OptionSet, OptionsMetadata, Visit};
use ruff_python_ast::PythonVersion;
use rustc_hash::FxHasher;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt::{self, Debug, Display};
Expand All @@ -28,6 +27,7 @@ use std::ops::Deref;
use std::sync::Arc;
use thiserror::Error;
use ty_combine::Combine;
use ty_python_semantic::FxHasher;
use ty_python_semantic::lint::{Level, LintSource, RuleSelection};
use ty_python_semantic::{
ProgramSettings, PythonEnvironment, PythonPlatform, PythonVersionFileSource,
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_project/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use ruff_db::files::{File, system_path_to_file};
use ruff_db::system::walk_directory::{ErrorKind, WalkDirectoryBuilder, WalkState};
use ruff_db::system::{SystemPath, SystemPathBuf};
use ruff_python_ast::PySourceType;
use rustc_hash::FxHashSet;
use std::path::PathBuf;
use thiserror::Error;
use ty_python_semantic::FxHashSet;

/// Filter that decides which files are included in the project.
///
Expand Down
11 changes: 5 additions & 6 deletions crates/ty_python_semantic/src/dunder_all.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use rustc_hash::FxHashSet;

use ruff_db::files::File;
use ruff_db::parsed::parsed_module;
use ruff_python_ast::name::Name;
Expand All @@ -8,7 +6,7 @@ use ruff_python_ast::{self as ast};

use crate::semantic_index::{SemanticIndex, semantic_index};
use crate::types::{Truthiness, Type, TypeContext, infer_expression_types};
use crate::{Db, ModuleName, resolve_module};
use crate::{Db, FxHashSet, ModuleName, resolve_module};

fn dunder_all_names_cycle_initial(
_db: &dyn Db,
Expand Down Expand Up @@ -103,7 +101,8 @@ impl<'db> DunderAllNamesCollector<'db> {
// The module either does not have a `__all__` variable or it is invalid.
return false;
};
self.names.extend(module_dunder_all_names.iter().cloned());
self.names
.extend(module_dunder_all_names.unstable_iter().cloned());
true
}

Expand Down Expand Up @@ -240,7 +239,7 @@ impl<'db> StatementVisitor<'db> for DunderAllNamesCollector<'db> {

if all_names.contains(&Name::new_static("__all__")) {
self.update_origin(DunderAllOrigin::StarImport);
self.names.extend(all_names.iter().cloned());
self.names.extend(all_names.unstable_iter().cloned());
}
} else {
// `from module import __all__`
Expand Down Expand Up @@ -270,7 +269,7 @@ impl<'db> StatementVisitor<'db> for DunderAllNamesCollector<'db> {
};

self.update_origin(DunderAllOrigin::ExternalModule);
self.names.extend(all_names.iter().cloned());
self.names.extend(all_names.unstable_iter().cloned());
}
}
}
Expand Down
Loading