Skip to content

Commit c5eb932

Browse files
committed
switch from IndexMap to OrderMap everywhere
1 parent e548ce1 commit c5eb932

File tree

17 files changed

+79
-82
lines changed

17 files changed

+79
-82
lines changed

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ etcetera = { version = "0.11.0" }
8888
fern = { version = "0.7.0" }
8989
filetime = { version = "0.2.23" }
9090
getrandom = { version = "0.3.1" }
91-
get-size2 = { version = "0.7.0", features = [
91+
get-size2 = { version = "0.7.3", features = [
9292
"derive",
9393
"smallvec",
9494
"hashbrown",
@@ -129,7 +129,7 @@ memchr = { version = "2.7.1" }
129129
mimalloc = { version = "0.1.39" }
130130
natord = { version = "1.0.9" }
131131
notify = { version = "8.0.0" }
132-
ordermap = { version = "0.5.0" }
132+
ordermap = { version = "1.0.0" }
133133
path-absolutize = { version = "3.1.1" }
134134
path-slash = { version = "0.2.1" }
135135
pathdiff = { version = "0.2.1" }
@@ -146,7 +146,7 @@ regex-automata = { version = "0.4.9" }
146146
rustc-hash = { version = "2.0.0" }
147147
rustc-stable-hash = { version = "0.1.2" }
148148
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
149-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "59aa1075e837f5deb0d6ffb24b68fedc0f4bc5e0", default-features = false, features = [
149+
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "55e5e7d32fa3fc189276f35bb04c9438f9aedbd1", default-features = false, features = [
150150
"compact_str",
151151
"macros",
152152
"salsa_unstable",

crates/ty_python_semantic/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ camino = { workspace = true }
3333
colored = { workspace = true }
3434
compact_str = { workspace = true }
3535
drop_bomb = { workspace = true }
36-
get-size2 = { workspace = true, features = ["indexmap"]}
37-
indexmap = { workspace = true }
36+
get-size2 = { workspace = true, features = ["ordermap"] }
3837
itertools = { workspace = true }
3938
ordermap = { workspace = true }
40-
salsa = { workspace = true, features = ["compact_str"] }
39+
salsa = { workspace = true, features = ["compact_str", "ordermap"] }
4140
thiserror = { workspace = true }
4241
tracing = { workspace = true }
4342
rustc-hash = { workspace = true }

crates/ty_python_semantic/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ pub mod pull_types;
6060

6161
type FxOrderMap<K, V> = ordermap::map::OrderMap<K, V, BuildHasherDefault<FxHasher>>;
6262
type FxOrderSet<V> = ordermap::set::OrderSet<V, BuildHasherDefault<FxHasher>>;
63-
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
64-
type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
6563

6664
/// Returns the default registry with all known semantic lints.
6765
pub fn default_lint_registry() -> &'static LintRegistry {

crates/ty_python_semantic/src/module_resolver/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl SearchPaths {
549549
// (Paths may, however, *overlap* -- e.g. you could have both `src/`
550550
// and `src/foo` as module resolution paths simultaneously.)
551551
//
552-
// This code doesn't use an `IndexSet` because the key is the system
552+
// This code doesn't use an `OrdersetSet` because the key is the system
553553
// path and not the search root.
554554
//
555555
// [`sys.path` at runtime]: https://docs.python.org/3/library/site.html#module-site

crates/ty_python_semantic/src/place.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,13 @@ pub(crate) fn place_from_declarations<'db>(
480480

481481
type DeclaredTypeAndConflictingTypes<'db> = (
482482
TypeAndQualifiers<'db>,
483-
Option<Box<indexmap::set::Slice<Type<'db>>>>,
483+
Option<Box<ordermap::set::Slice<Type<'db>>>>,
484484
);
485485

486486
/// The result of looking up a declared type from declarations; see [`place_from_declarations`].
487487
pub(crate) struct PlaceFromDeclarationsResult<'db> {
488488
place_and_quals: PlaceAndQualifiers<'db>,
489-
conflicting_types: Option<Box<indexmap::set::Slice<Type<'db>>>>,
489+
conflicting_types: Option<Box<ordermap::set::Slice<Type<'db>>>>,
490490
/// Contains the first reachable declaration for this place, if any.
491491
/// This field is used for backreferences in diagnostics.
492492
pub(crate) first_declaration: Option<Definition<'db>>,
@@ -495,7 +495,7 @@ pub(crate) struct PlaceFromDeclarationsResult<'db> {
495495
impl<'db> PlaceFromDeclarationsResult<'db> {
496496
fn conflict(
497497
place_and_quals: PlaceAndQualifiers<'db>,
498-
conflicting_types: Box<indexmap::set::Slice<Type<'db>>>,
498+
conflicting_types: Box<ordermap::set::Slice<Type<'db>>>,
499499
first_declaration: Option<Definition<'db>>,
500500
) -> Self {
501501
PlaceFromDeclarationsResult {
@@ -513,7 +513,7 @@ impl<'db> PlaceFromDeclarationsResult<'db> {
513513
self,
514514
) -> (
515515
PlaceAndQualifiers<'db>,
516-
Option<Box<indexmap::set::Slice<Type<'db>>>>,
516+
Option<Box<ordermap::set::Slice<Type<'db>>>>,
517517
) {
518518
(self.place_and_quals, self.conflicting_types)
519519
}

crates/ty_python_semantic/src/site_packages.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{fmt, sync::Arc};
1616

1717
use crate::{PythonVersionFileSource, PythonVersionSource, PythonVersionWithSource};
1818
use camino::Utf8Component;
19-
use indexmap::IndexSet;
19+
use ordermap::OrderSet;
2020
use ruff_annotate_snippets::{Level, Renderer, Snippet};
2121
use ruff_db::system::{System, SystemPath, SystemPathBuf};
2222
use ruff_python_ast::PythonVersion;
@@ -39,15 +39,15 @@ type StdlibDiscoveryResult<T> = Result<T, StdlibDiscoveryError>;
3939
/// (which could be another virtual environment or a system installation,
4040
/// and which could itself have multiple `site-packages` directories).
4141
///
42-
/// We use an `IndexSet` here to guard against the (very remote)
42+
/// We use an `OrderSet` here to guard against the (very remote)
4343
/// possibility that an environment might somehow be marked as being
4444
/// both a `--system-site-packages` virtual environment *and* an
4545
/// ephemeral environment that extends the system environment. If this
4646
/// were the case, the system environment's `site-packages` directory
4747
/// *might* be added to the `SitePackagesPaths` twice, but we wouldn't
4848
/// want duplicates to appear in this set.
4949
#[derive(Debug, PartialEq, Eq, Default)]
50-
pub struct SitePackagesPaths(IndexSet<SystemPathBuf>);
50+
pub struct SitePackagesPaths(OrderSet<SystemPathBuf>);
5151

5252
impl SitePackagesPaths {
5353
fn is_empty(&self) -> bool {
@@ -128,13 +128,13 @@ impl fmt::Display for SitePackagesPaths {
128128

129129
impl<const N: usize> From<[SystemPathBuf; N]> for SitePackagesPaths {
130130
fn from(paths: [SystemPathBuf; N]) -> Self {
131-
Self(IndexSet::from(paths))
131+
Self(OrderSet::from(paths))
132132
}
133133
}
134134

135135
impl IntoIterator for SitePackagesPaths {
136136
type Item = SystemPathBuf;
137-
type IntoIter = indexmap::set::IntoIter<SystemPathBuf>;
137+
type IntoIter = ordermap::set::IntoIter<SystemPathBuf>;
138138

139139
fn into_iter(self) -> Self::IntoIter {
140140
self.0.into_iter()

crates/ty_python_semantic/src/types/class.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::types::{
4141
determine_upper_bound,
4242
};
4343
use crate::{
44-
Db, FxIndexMap, FxIndexSet, FxOrderSet, Program,
44+
Db, FxOrderMap, FxOrderSet, Program,
4545
module_resolver::file_to_module,
4646
place::{
4747
Definedness, LookupError, LookupResult, Place, PlaceAndQualifiers, known_module_symbol,
@@ -59,8 +59,8 @@ use crate::{
5959
definition_expression_type,
6060
},
6161
};
62-
use indexmap::IndexSet;
6362
use itertools::Itertools as _;
63+
use ordermap::OrderSet;
6464
use ruff_db::diagnostic::Span;
6565
use ruff_db::files::File;
6666
use ruff_db::parsed::{ParsedModuleRef, parsed_module};
@@ -158,8 +158,8 @@ fn fields_cycle_initial<'db>(
158158
_self: ClassLiteral<'db>,
159159
_specialization: Option<Specialization<'db>>,
160160
_field_policy: CodeGeneratorKind<'db>,
161-
) -> FxIndexMap<Name, Field<'db>> {
162-
FxIndexMap::default()
161+
) -> FxOrderMap<Name, Field<'db>> {
162+
FxOrderMap::default()
163163
}
164164

165165
/// A category of classes with code generation capabilities (with synthesized methods).
@@ -875,8 +875,8 @@ impl<'db> ClassType<'db> {
875875
specialization
876876
.and_then(|spec| spec.tuple(db))
877877
.map(|tuple| {
878-
let mut element_type_to_indices: FxIndexMap<Type<'db>, Vec<i64>> =
879-
FxIndexMap::default();
878+
let mut element_type_to_indices: FxOrderMap<Type<'db>, Vec<i64>> =
879+
FxOrderMap::default();
880880

881881
match tuple {
882882
// E.g. for `tuple[int, str]`, we will generate the following overloads:
@@ -1578,10 +1578,10 @@ impl<'db> ClassLiteral<'db> {
15781578
pub(crate) fn typevars_referenced_in_definition(
15791579
self,
15801580
db: &'db dyn Db,
1581-
) -> FxIndexSet<BoundTypeVarInstance<'db>> {
1581+
) -> FxOrderSet<BoundTypeVarInstance<'db>> {
15821582
#[derive(Default)]
15831583
struct CollectTypeVars<'db> {
1584-
typevars: RefCell<FxIndexSet<BoundTypeVarInstance<'db>>>,
1584+
typevars: RefCell<FxOrderSet<BoundTypeVarInstance<'db>>>,
15851585
recursion_guard: TypeCollector<'db>,
15861586
}
15871587

@@ -3004,7 +3004,7 @@ impl<'db> ClassLiteral<'db> {
30043004
db: &'db dyn Db,
30053005
specialization: Option<Specialization<'db>>,
30063006
field_policy: CodeGeneratorKind<'db>,
3007-
) -> FxIndexMap<Name, Field<'db>> {
3007+
) -> FxOrderMap<Name, Field<'db>> {
30083008
if field_policy == CodeGeneratorKind::NamedTuple {
30093009
// NamedTuples do not allow multiple inheritance, so it is sufficient to enumerate the
30103010
// fields of this class only.
@@ -3052,8 +3052,8 @@ impl<'db> ClassLiteral<'db> {
30523052
db: &'db dyn Db,
30533053
specialization: Option<Specialization<'db>>,
30543054
field_policy: CodeGeneratorKind,
3055-
) -> FxIndexMap<Name, Field<'db>> {
3056-
let mut attributes = FxIndexMap::default();
3055+
) -> FxOrderMap<Name, Field<'db>> {
3056+
let mut attributes = FxOrderMap::default();
30573057

30583058
let class_body_scope = self.body_scope(db);
30593059
let table = place_table(db, class_body_scope);
@@ -3748,8 +3748,8 @@ impl<'db> ClassLiteral<'db> {
37483748
fn is_cyclically_defined_recursive<'db>(
37493749
db: &'db dyn Db,
37503750
class: ClassLiteral<'db>,
3751-
classes_on_stack: &mut IndexSet<ClassLiteral<'db>>,
3752-
visited_classes: &mut IndexSet<ClassLiteral<'db>>,
3751+
classes_on_stack: &mut OrderSet<ClassLiteral<'db>>,
3752+
visited_classes: &mut OrderSet<ClassLiteral<'db>>,
37533753
) -> bool {
37543754
let mut result = false;
37553755
for explicit_base in class.explicit_bases(db) {
@@ -3778,8 +3778,8 @@ impl<'db> ClassLiteral<'db> {
37783778

37793779
tracing::trace!("Class::inheritance_cycle: {}", self.name(db));
37803780

3781-
let visited_classes = &mut IndexSet::new();
3782-
if !is_cyclically_defined_recursive(db, self, &mut IndexSet::new(), visited_classes) {
3781+
let visited_classes = &mut OrderSet::new();
3782+
if !is_cyclically_defined_recursive(db, self, &mut OrderSet::new(), visited_classes) {
37833783
None
37843784
} else if visited_classes.contains(&self) {
37853785
Some(InheritanceCycle::Participant)

crates/ty_python_semantic/src/types/cyclic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::marker::PhantomData;
2626

2727
use rustc_hash::FxHashMap;
2828

29-
use crate::FxIndexSet;
29+
use crate::FxOrderSet;
3030
use crate::types::Type;
3131

3232
pub(crate) type TypeTransformer<'db, Tag> = CycleDetector<Tag, Type<'db>, Type<'db>>;
@@ -48,7 +48,7 @@ pub struct CycleDetector<Tag, T, R> {
4848
/// If the type we're visiting is present in `seen`, it indicates that we've hit a cycle (due
4949
/// to a recursive type); we need to immediately short circuit the whole operation and return
5050
/// the fallback value. That's why we pop items off the end of `seen` after we've visited them.
51-
seen: RefCell<FxIndexSet<T>>,
51+
seen: RefCell<FxOrderSet<T>>,
5252

5353
/// Unlike `seen`, this field is a pure performance optimisation (and an essential one). If the
5454
/// type we're trying to normalize is present in `cache`, it doesn't necessarily mean we've hit
@@ -66,7 +66,7 @@ pub struct CycleDetector<Tag, T, R> {
6666
impl<Tag, T: Hash + Eq + Clone, R: Clone> CycleDetector<Tag, T, R> {
6767
pub fn new(fallback: R) -> Self {
6868
CycleDetector {
69-
seen: RefCell::new(FxIndexSet::default()),
69+
seen: RefCell::new(FxOrderSet::default()),
7070
cache: RefCell::new(FxHashMap::default()),
7171
fallback,
7272
_tag: PhantomData,

0 commit comments

Comments
 (0)