Note [Deterministic simplifyInstanceContexts]
Canonicalisation uses nonDetCmpType which is nondeterministic. Sorting with nonDetCmpType puts the returned lists in a nondeterministic order. If we were to return them, we'd get class constraints in nondeterministic order. Consider: data ADT a b = Z a b deriving Eq The generated code could be either: instance (Eq a, Eq b) => Eq (Z a b) where Or: instance (Eq b, Eq a) => Eq (Z a b) where To prevent the order from being nondeterministic we only canonicalize when comparing and return them in the same order as simplifyDeriv returned them. See also Note [nonDetCmpType nondeterminism]
References 1
- nonDetCmpType nondeterminism GHC.Core.TyCo.Compare
Referenced by 1
- GHC.Tc.Deriv.Infer call site