@@ -179,19 +179,28 @@ findFixity iface ifaceMap instIfaceMap = \name ->
179
179
-- Collecting and sorting instances
180
180
--------------------------------------------------------------------------------
181
181
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
182
191
183
192
-- | Simplified type for sorting types, ignoring qualification (not visible
184
193
-- in Haddock output) and unifying special tycons with normal ones.
185
194
-- For the benefit of the user (looks nice and predictable) and the
186
195
-- tests (which prefer output to be deterministic).
187
- data SimpleType = SimpleType Name [SimpleType ]
196
+ data SimpleType = SimpleType SName [SimpleType ]
188
197
| SimpleTyLit TyLit
189
198
deriving (Eq ,Ord )
190
199
191
200
192
- instHead :: ([TyVar ], [PredType ], Class , [Type ]) -> ([Int ], Name , [SimpleType ])
201
+ instHead :: ([TyVar ], [PredType ], Class , [Type ]) -> ([Int ], SName , [SimpleType ])
193
202
instHead (_, _, cls, args)
194
- = (map argCount args, className cls, map simplify args)
203
+ = (map argCount args, SName ( className cls) , map simplify args)
195
204
196
205
argCount :: Type -> Int
197
206
argCount (AppTy t _) = argCount t + 1
@@ -202,12 +211,12 @@ argCount (CastTy t _) = argCount t
202
211
argCount _ = 0
203
212
204
213
simplify :: 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]
206
215
simplify (ForAllTy _ t) = simplify t
207
216
simplify (AppTy t1 t2) = SimpleType s (ts ++ maybeToList (simplify_maybe t2))
208
217
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) )
211
220
(mapMaybe simplify_maybe ts)
212
221
simplify (LitTy l) = SimpleTyLit l
213
222
simplify (CastTy ty _) = simplify ty
@@ -218,9 +227,9 @@ simplify_maybe (CoercionTy {}) = Nothing
218
227
simplify_maybe ty = Just (simplify ty)
219
228
220
229
-- Used for sorting
221
- instFam :: FamInst -> ([Int ], Name , [SimpleType ], Int , SimpleType )
230
+ instFam :: FamInst -> ([Int ], SName , [SimpleType ], Int , SimpleType )
222
231
instFam 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)
224
233
225
234
226
235
--------------------------------------------------------------------------------
0 commit comments