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
This commit is contained in:
Brent Westbrook 2025-07-31 08:52:19 -04:00 committed by GitHub
parent d2d4b115e3
commit a71513bae1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View file

@ -38,7 +38,7 @@ mod tests {
impl CursorTest { impl CursorTest {
fn references(&self) -> String { fn references(&self) -> String {
let Some(reference_results) = let Some(mut reference_results) =
goto_references(&self.db, self.cursor.file, self.cursor.offset, true) goto_references(&self.db, self.cursor.file, self.cursor.offset, true)
else { else {
return "No references found".to_string(); return "No references found".to_string();
@ -48,6 +48,8 @@ mod tests {
return "No references found".to_string(); return "No references found".to_string();
} }
reference_results.sort_by_key(ReferenceTarget::file);
self.render_diagnostics(reference_results.into_iter().enumerate().map( self.render_diagnostics(reference_results.into_iter().enumerate().map(
|(i, ref_item)| -> ReferenceResult { |(i, ref_item)| -> ReferenceResult {
ReferenceResult { ReferenceResult {

View file

@ -75,7 +75,7 @@ def f(h4: HeterogeneousSubclass4, i: int):
class MixedSubclass(tuple[I0, *tuple[I1, ...], I2, I3, I2, I5]): ... 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__) reveal_type(MixedSubclass.__getitem__)
def g(m: MixedSubclass, i: int): def g(m: MixedSubclass, i: int):
@ -105,7 +105,7 @@ def g(m: MixedSubclass, i: int):
class MixedSubclass2(tuple[I0, I1, *tuple[I2, ...], I3]): ... 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__) reveal_type(MixedSubclass2.__getitem__)
def g(m: MixedSubclass2, i: int): def g(m: MixedSubclass2, i: int):

View file

@ -27,7 +27,7 @@ use crate::types::{
infer_definition_types, infer_definition_types,
}; };
use crate::{ use crate::{
Db, FxOrderSet, KnownModule, Program, Db, FxIndexMap, FxOrderSet, KnownModule, Program,
module_resolver::file_to_module, module_resolver::file_to_module,
place::{ place::{
Boundness, LookupError, LookupResult, Place, PlaceAndQualifiers, class_symbol, 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::name::Name;
use ruff_python_ast::{self as ast, PythonVersion}; use ruff_python_ast::{self as ast, PythonVersion};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};
use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; use rustc_hash::{FxHashSet, FxHasher};
type FxOrderMap<K, V> = ordermap::map::OrderMap<K, V, BuildHasherDefault<FxHasher>>; type FxOrderMap<K, V> = ordermap::map::OrderMap<K, V, BuildHasherDefault<FxHasher>>;
@ -628,8 +628,8 @@ impl<'db> ClassType<'db> {
.map(|spec| { .map(|spec| {
let tuple = spec.tuple(db); let tuple = spec.tuple(db);
let mut element_type_to_indices: FxHashMap<Type<'db>, Vec<i64>> = let mut element_type_to_indices: FxIndexMap<Type<'db>, Vec<i64>> =
FxHashMap::default(); FxIndexMap::default();
match tuple { match tuple {
// E.g. for `tuple[int, str]`, we will generate the following overloads: // E.g. for `tuple[int, str]`, we will generate the following overloads: