[ty] Remove some nondeterminism in constraint set tests#22064
Conversation
| /// - `C → D`: This indicates that `C` on its own is enough to imply `D`. Any path that assumes `C` | ||
| /// holds but `D` does _not_ is impossible and can be pruned. | ||
| #[derive(Debug, Default, Eq, PartialEq, get_size2::GetSize, salsa::Update)] | ||
| struct SequentMap<'db> { |
There was a problem hiding this comment.
There are other FxHashMaps in here, but they're only used for existence checks; we never iterate over them. The ones changed below are the only ones we iterate over, and where insertion order is therefore important.
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
It's hard to tell if this fixes the issue, because if it doesn't, or if it does but it "solidifies" an ordering that doesn't match what we happen to get on the "pre" run, the results will look the same 😆 |
carljm
left a comment
There was a problem hiding this comment.
Seems reasonable, if potentially expensive?
Guess there's no way to see if it worked other than land it?
|
And (regarding #22064 (comment)) we we already non-deterministic before the |
I hope (and codspeed CI seems to agree) that it won't be too bad — the biggest change is sorting before starting sequent map construction, and my intuition is that we're doing enough work finding all of the sequents that the extra sorting step won't be a bottleneck. |
To be fair, where we are now is really quite non-deterministic 😅 |
We're seeing a lot of nondeterminism in the ecosystem tests at the moment, which started (or at least got worse) once
Callableinference landed.This PR attempts to remove this nondeterminism. We recently (#21983) added a
source_orderfield 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_orderof the "real" constraint that implied them. That means we can get multiple constraints in our specialization that all have the samesource_order. If we're not careful, those "tied" constraints can be ordered arbitrarily.The fix requires
threefourseveral steps:source_order. That ensures that we insert things into the sequent map in a stable order.SequentMapto useFxOrderSetinstead ofFxHashSet, so that we retain that stable insertion order.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.)