moduleNameSlashes,
mkModuleName,
mkModuleNameFS,
+ stableModuleNameCmp,
-- * The PackageId type
PackageId,
packageIdFS,
stringToPackageId,
packageIdString,
+ stablePackageIdCmp,
-- * Wired-in PackageIds
primPackageId,
modulePackageId, moduleName,
pprModule,
mkModule,
+ stableModuleCmp,
-- * The ModuleLocation type
ModLocation(..),
import LazyUniqFM
import FastString
import Binary
+import Util
import System.FilePath
\end{code}
put_ bh (ModuleName fs) = put_ bh fs
get bh = do fs <- get bh; return (ModuleName fs)
+stableModuleNameCmp :: ModuleName -> ModuleName -> Ordering
+-- Compare lexically, not by unique
+stableModuleNameCmp n1 n2 = moduleNameFS n1 `compare` moduleNameFS n2
+
pprModuleName :: ModuleName -> SDoc
pprModuleName (ModuleName nm) =
getPprStyle $ \ sty ->
put_ bh (Module p n) = put_ bh p >> put_ bh n
get bh = do p <- get bh; n <- get bh; return (Module p n)
-instance Uniquable PackageId where
- getUnique pid = getUnique (packageIdFS pid)
+-- This gives a stable ordering, as opposed to the Ord instance which
+-- gives an ordering based on the Uniques of the components, which may
+-- not be stable from run to run of the compiler.
+stableModuleCmp :: Module -> Module -> Ordering
+stableModuleCmp (Module p1 n1) (Module p2 n2)
+ = (p1 `stablePackageIdCmp` p2) `thenCmp`
+ (n1 `stableModuleNameCmp` n2)
mkModule :: PackageId -> ModuleName -> Module
mkModule = Module
%************************************************************************
\begin{code}
-newtype PackageId = PId FastString deriving( Eq, Ord ) -- includes the version
+newtype PackageId = PId FastString deriving( Eq ) -- includes the version
-- here to avoid module loops with PackageConfig
+instance Uniquable PackageId where
+ getUnique pid = getUnique (packageIdFS pid)
+
+-- Note: *not* a stable lexicographic ordering, a faster unique-based
+-- ordering.
+instance Ord PackageId where
+ nm1 `compare` nm2 = getUnique nm1 `compare` getUnique nm2
+
+stablePackageIdCmp :: PackageId -> PackageId -> Ordering
+stablePackageIdCmp p1 p2 = packageIdFS p1 `compare` packageIdFS p2
+
instance Outputable PackageId where
ppr pid = text (packageIdString pid)