@@ -179,19 +179,28 @@ findFixity iface ifaceMap instIfaceMap = \name ->
179179-- Collecting and sorting instances
180180--------------------------------------------------------------------------------
181181
182+ -- | Stable name for stable comparisons. GHC's `Name` uses unstable
183+ -- ordering based on their `Unique`'s.
184+ newtype SName = SName Name
185+
186+ instance Eq SName where
187+ SName n1 == SName n2 = n1 `stableNameCmp` n2 == EQ
188+
189+ instance Ord SName where
190+ SName n1 `compare` SName n2 = n1 `stableNameCmp` n2
182191
183192-- | Simplified type for sorting types, ignoring qualification (not visible
184193-- in Haddock output) and unifying special tycons with normal ones.
185194-- For the benefit of the user (looks nice and predictable) and the
186195-- tests (which prefer output to be deterministic).
187- data SimpleType = SimpleType Name [SimpleType ]
196+ data SimpleType = SimpleType SName [SimpleType ]
188197 | SimpleTyLit TyLit
189198 deriving (Eq ,Ord )
190199
191200
192- instHead :: ([TyVar ], [PredType ], Class , [Type ]) -> ([Int ], Name , [SimpleType ])
201+ instHead :: ([TyVar ], [PredType ], Class , [Type ]) -> ([Int ], SName , [SimpleType ])
193202instHead (_, _, cls, args)
194- = (map argCount args, className cls, map simplify args)
203+ = (map argCount args, SName ( className cls) , map simplify args)
195204
196205argCount :: Type -> Int
197206argCount (AppTy t _) = argCount t + 1
@@ -202,12 +211,12 @@ argCount (CastTy t _) = argCount t
202211argCount _ = 0
203212
204213simplify :: Type -> SimpleType
205- simplify (FunTy _ _ t1 t2) = SimpleType funTyConName [simplify t1, simplify t2]
214+ simplify (FunTy _ _ t1 t2) = SimpleType ( SName funTyConName) [simplify t1, simplify t2]
206215simplify (ForAllTy _ t) = simplify t
207216simplify (AppTy t1 t2) = SimpleType s (ts ++ maybeToList (simplify_maybe t2))
208217 where (SimpleType s ts) = simplify t1
209- simplify (TyVarTy v) = SimpleType (tyVarName v) []
210- simplify (TyConApp tc ts) = SimpleType (tyConName tc)
218+ simplify (TyVarTy v) = SimpleType (SName ( tyVarName v) ) []
219+ simplify (TyConApp tc ts) = SimpleType (SName ( tyConName tc) )
211220 (mapMaybe simplify_maybe ts)
212221simplify (LitTy l) = SimpleTyLit l
213222simplify (CastTy ty _) = simplify ty
@@ -218,9 +227,9 @@ simplify_maybe (CoercionTy {}) = Nothing
218227simplify_maybe ty = Just (simplify ty)
219228
220229-- Used for sorting
221- instFam :: FamInst -> ([Int ], Name , [SimpleType ], Int , SimpleType )
230+ instFam :: FamInst -> ([Int ], SName , [SimpleType ], Int , SimpleType )
222231instFam FamInst { fi_fam = n, fi_tys = ts, fi_rhs = t }
223- = (map argCount ts, n, map simplify ts, argCount t, simplify t)
232+ = (map argCount ts, SName n, map simplify ts, argCount t, simplify t)
224233
225234
226235--------------------------------------------------------------------------------
0 commit comments