mirror of https://github.com/astral-sh/ruff
[ty] Consistent ordering of constraint set specializations, take 2 (#21983)
In https://github.com/astral-sh/ruff/pull/21957, we tried to use `union_or_intersection_elements_ordering` to provide a stable ordering of the union and intersection elements that are created when determining which type a typevar should specialize to. @AlexWaygood [pointed out](https://github.com/astral-sh/ruff/pull/21551#discussion_r2616543762) that this won't work, since that provides a consistent ordering within a single process run, but does not provide a stable ordering across runs. This is an attempt to produce a proper stable ordering for constraint sets, so that we end up with consistent diagnostic and test output. We do this by maintaining a new `source_order` field on each interior BDD node, which records when that node's constraint was added to the set. Several of the BDD operators (`and`, `or`, etc) now have `_with_offset` variants, which update each `source_order` in the rhs to be larger than any of the `source_order`s in the lhs. This is what causes that field to be in line with (a) when you add each constraint to the set, and (b) the order of the parameters you provide to `and`, `or`, etc. Then we sort by that new field before constructing the union/intersection types when creating a specialization.
This commit is contained in:
parent
d6a5bbd91c
commit
7d3b7c5754
|
|
@ -689,20 +689,10 @@ impl<'db> IntersectionBuilder<'db> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn order_elements(mut self, val: bool) -> Self {
|
|
||||||
self.order_elements = val;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn add_positive(self, ty: Type<'db>) -> Self {
|
pub(crate) fn add_positive(self, ty: Type<'db>) -> Self {
|
||||||
self.add_positive_impl(ty, &mut vec![])
|
self.add_positive_impl(ty, &mut vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_positive_in_place(&mut self, ty: Type<'db>) {
|
|
||||||
let updated = std::mem::replace(self, Self::empty(self.db)).add_positive(ty);
|
|
||||||
*self = updated;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn add_positive_impl(
|
pub(crate) fn add_positive_impl(
|
||||||
mut self,
|
mut self,
|
||||||
ty: Type<'db>,
|
ty: Type<'db>,
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue