From fdf6c02f72fbcbad9982bf78473916c40dcaa5ec Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Wed, 10 Jan 2007 12:43:27 +0000 Subject: [PATCH] Sort rules and instances lexicographically in interface files We should sort rules and instances lexicographically, not by Unique, in interface files, else we get unnecessary "rules changed" and hence unnecessary recompilation. This bug has been there since the interface-file upheaval that put Names into IfaceSyn. --- compiler/basicTypes/OccName.lhs | 5 +++-- compiler/iface/MkIface.lhs | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/basicTypes/OccName.lhs b/compiler/basicTypes/OccName.lhs index 48aa6db..0810d73 100644 --- a/compiler/basicTypes/OccName.lhs +++ b/compiler/basicTypes/OccName.lhs @@ -176,8 +176,9 @@ instance Eq OccName where (OccName sp1 s1) == (OccName sp2 s2) = s1 == s2 && sp1 == sp2 instance Ord OccName where - compare (OccName sp1 s1) (OccName sp2 s2) = (s1 `compare` s2) `thenCmp` - (sp1 `compare` sp2) + -- Compares lexicographically, *not* by Unique of the string + compare (OccName sp1 s1) (OccName sp2 s2) + = (s1 `compare` s2) `thenCmp` (sp1 `compare` sp2) \end{code} diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs index 7518111..0fc3972 100644 --- a/compiler/iface/MkIface.lhs +++ b/compiler/iface/MkIface.lhs @@ -188,7 +188,6 @@ import TyCon import DataCon import Type import TcType -import TysPrim import InstEnv import FamInstEnv import TcRnMonad @@ -276,9 +275,13 @@ mkIface hsc_env maybe_old_iface mi_deps = deps, mi_usages = usages, mi_exports = mkIfaceExports exports, + + -- Sort these lexicographically, so that + -- the result is stable across compilations mi_insts = sortLe le_inst iface_insts, mi_fam_insts= sortLe le_fam_inst iface_fam_insts, mi_rules = sortLe le_rule iface_rules, + mi_fixities = fixities, mi_deprecs = deprecs, mi_globals = Just rdr_env, @@ -314,13 +317,18 @@ mkIface hsc_env maybe_old_iface ; return (new_iface, no_change_at_all) } where - r1 `le_rule` r2 = ifRuleName r1 <= ifRuleName r2 - i1 `le_inst` i2 = ifDFun i1 <= ifDFun i2 - i1 `le_fam_inst` i2 = ifFamInstTyConOcc i1 <= ifFamInstTyConOcc i2 + r1 `le_rule` r2 = ifRuleName r1 <= ifRuleName r2 + i1 `le_inst` i2 = ifDFun i1 `le_occ` ifDFun i2 + i1 `le_fam_inst` i2 = ifFamInstTcName i1 `le_occ` ifFamInstTcName i2 + + le_occ :: Name -> Name -> Bool + -- Compare lexicographically by OccName, *not* by unique, because + -- the latter is not stable across compilations + le_occ n1 n2 = nameOccName n1 <= nameOccName n2 dflags = hsc_dflags hsc_env deliberatelyOmitted x = panic ("Deliberately omitted: " ++ x) - ifFamInstTyConOcc = nameOccName . ifaceTyConName . ifFamInstTyCon + ifFamInstTcName = ifaceTyConName . ifFamInstTyCon ----------------------------- -- 1.7.10.4