mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-23 09:19:39 +00:00
We're seeing a lot of nondeterminism in the ecosystem tests at the moment, which started (or at least got worse) once `Callable` inference landed. This PR attempts to remove this nondeterminism. We recently (https://github.com/astral-sh/ruff/pull/21983) added a `source_order` field to BDD nodes, which tracks when their constraint was added to the BDD. Since we build up constraints based on the order that they appear in the underlying source, that gives us a stable ordering even though we use an arbitrary salsa-derived ordering for the BDD variables. The issue (at least for some of the flakiness) is that we add "derived" constraints when walking a BDD tree, and those derived constraints inherit or borrow the `source_order` of the "real" constraint that implied them. That means we can get multiple constraints in our specialization that all have the same `source_order`. If we're not careful, those "tied" constraints can be ordered arbitrarily. The fix requires ~three~ ~four~ several steps: - When starting to construct a sequent map (the data structure that stores the derived constraints), we first sort all of the "real" constraints by their `source_order`. That ensures that we insert things into the sequent map in a stable order. - During sequent map construction, derived facts are discovered by a deterministic process applied to constraints in a (now) stable order. So derived facts are now also inserted in a stable order. - We update the fields of `SequentMap` to use `FxOrderSet` instead of `FxHashSet`, so that we retain that stable insertion order. - When walking BDD paths when constructing a specialization, we were already sorting the constraints by their `source_order`. However, we were not considering that we might get derived constraints, and therefore constraints with "ties". Because of that, we need to make sure to use a _stable_ sort, that retains the insertion order for those ties. All together, this...should...fix the nondeterminism. (Unfortunately, I haven't been able to effectively test this, since I haven't been able to coerce local tests to flop into the other order that we sometimes see in CI.) |
||
|---|---|---|
| .. | ||
| resources | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| mdtest.py | ||
| mdtest.py.lock | ||