From a71513bae1ab1d24310af761dedbb606911db808 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 31 Jul 2025 08:52:19 -0400 Subject: [PATCH] Fix tests on 32-bit architectures (#19652) Summary -- Fixes #19640. I'm not sure these are the exact fixes we really want, but I reproduced the issue in a 32-bit Docker container and tracked down the causes, so I figured I'd open a PR. As I commented on the issue, the `goto_references` test depends on the iteration order of the files in an `FxHashSet` in `Indexed`. In this case, we can just sort the output in test code. Similarly, the tuple case depended on the order of overloads inserted in an `FxHashMap`. `FxIndexMap` seemed like a convenient drop-in replacement, but I don't know if that will have other detrimental effects. I did have to change the assertion for the tuple test, but I think it should now be stable across architectures. Test Plan -- Running the tests in the aforementioned Docker container --- crates/ty_ide/src/goto_references.rs | 4 +++- .../resources/mdtest/subscript/tuple.md | 4 ++-- crates/ty_python_semantic/src/types/class.rs | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/ty_ide/src/goto_references.rs b/crates/ty_ide/src/goto_references.rs index 1f6d5063f5..40d5ea8de9 100644 --- a/crates/ty_ide/src/goto_references.rs +++ b/crates/ty_ide/src/goto_references.rs @@ -38,7 +38,7 @@ mod tests { impl CursorTest { fn references(&self) -> String { - let Some(reference_results) = + let Some(mut reference_results) = goto_references(&self.db, self.cursor.file, self.cursor.offset, true) else { return "No references found".to_string(); @@ -48,6 +48,8 @@ mod tests { return "No references found".to_string(); } + reference_results.sort_by_key(ReferenceTarget::file); + self.render_diagnostics(reference_results.into_iter().enumerate().map( |(i, ref_item)| -> ReferenceResult { ReferenceResult { diff --git a/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md b/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md index a5be45f5cb..b85065fb06 100644 --- a/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md @@ -75,7 +75,7 @@ def f(h4: HeterogeneousSubclass4, i: int): class MixedSubclass(tuple[I0, *tuple[I1, ...], I2, I3, I2, I5]): ... -# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[2, 3], /) -> I1 | I2 | I3, (self, index: Literal[-1], /) -> I5, (self, index: Literal[1], /) -> I1 | I2, (self, index: Literal[-3], /) -> I3, (self, index: Literal[-5], /) -> I1 | I0, (self, index: Literal[-4, -2], /) -> I2, (self, index: Literal[4], /) -> I1 | I2 | I3 | I5, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3 | I5, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3 | I5, ...]] +# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[-5], /) -> I1 | I0, (self, index: Literal[-1], /) -> I5, (self, index: Literal[1], /) -> I1 | I2, (self, index: Literal[-4, -2], /) -> I2, (self, index: Literal[2, 3], /) -> I1 | I2 | I3, (self, index: Literal[-3], /) -> I3, (self, index: Literal[4], /) -> I1 | I2 | I3 | I5, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3 | I5, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3 | I5, ...]] reveal_type(MixedSubclass.__getitem__) def g(m: MixedSubclass, i: int): @@ -105,7 +105,7 @@ def g(m: MixedSubclass, i: int): class MixedSubclass2(tuple[I0, I1, *tuple[I2, ...], I3]): ... -# revealed: Overload[(self, index: Literal[-1], /) -> I3, (self, index: Literal[0], /) -> I0, (self, index: Literal[-2], /) -> I2 | I1, (self, index: Literal[2], /) -> I2 | I3, (self, index: Literal[1], /) -> I1, (self, index: Literal[-3], /) -> I2 | I1 | I0, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3, ...]] +# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[-2], /) -> I2 | I1, (self, index: Literal[1], /) -> I1, (self, index: Literal[-3], /) -> I2 | I1 | I0, (self, index: Literal[-1], /) -> I3, (self, index: Literal[2], /) -> I2 | I3, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3, ...]] reveal_type(MixedSubclass2.__getitem__) def g(m: MixedSubclass2, i: int): diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 5e3bbc7029..65af4b9880 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -27,7 +27,7 @@ use crate::types::{ infer_definition_types, }; use crate::{ - Db, FxOrderSet, KnownModule, Program, + Db, FxIndexMap, FxOrderSet, KnownModule, Program, module_resolver::file_to_module, place::{ Boundness, LookupError, LookupResult, Place, PlaceAndQualifiers, class_symbol, @@ -53,7 +53,7 @@ use ruff_db::parsed::{ParsedModuleRef, parsed_module}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, PythonVersion}; use ruff_text_size::{Ranged, TextRange}; -use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; +use rustc_hash::{FxHashSet, FxHasher}; type FxOrderMap = ordermap::map::OrderMap>; @@ -628,8 +628,8 @@ impl<'db> ClassType<'db> { .map(|spec| { let tuple = spec.tuple(db); - let mut element_type_to_indices: FxHashMap, Vec> = - FxHashMap::default(); + let mut element_type_to_indices: FxIndexMap, Vec> = + FxIndexMap::default(); match tuple { // E.g. for `tuple[int, str]`, we will generate the following overloads: