summaryrefslogtreecommitdiff
path: root/compiler/GHC/Utils
diff options
context:
space:
mode:
authorromes <rodrigo.m.mesquita@gmail.com>2022-06-29 15:36:43 +0200
committerromes <rodrigo.m.mesquita@gmail.com>2022-07-03 15:06:26 +0200
commitbae4d04456dc13f42eee2feae9d541836728ebbd (patch)
tree4a158e53deab52d58334230802990b30246e12c2 /compiler/GHC/Utils
parentc33787c7cada83c1284f1b3a4194ab8d03479f00 (diff)
downloadhaskell-wip/romes/ttg-module.tar.gz
Refactor ModuleName to L.H.S.Module.Namewip/romes/ttg-module
ModuleName used to live in GHC.Unit.Module.Name. In this commit, the definition of ModuleName and its associated functions are moved to Language.Haskell.Syntax.Module.Name according to the current plan towards making the AST GHC-independent. The instances for ModuleName for Outputable, Uniquable and Binary were moved to the module in which the class is defined because these instances depend on GHC. The instance of Eq for ModuleName is slightly changed to no longer depend on unique explicitly and instead uses FastString's instance of Eq.
Diffstat (limited to 'compiler/GHC/Utils')
-rw-r--r--compiler/GHC/Utils/Binary.hs6
-rw-r--r--compiler/GHC/Utils/Outputable.hs14
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/GHC/Utils/Binary.hs b/compiler/GHC/Utils/Binary.hs
index 15071c1b37..5e11489572 100644
--- a/compiler/GHC/Utils/Binary.hs
+++ b/compiler/GHC/Utils/Binary.hs
@@ -77,6 +77,8 @@ module GHC.Utils.Binary
import GHC.Prelude
+import Language.Haskell.Syntax.Module.Name (ModuleName(..))
+
import {-# SOURCE #-} GHC.Types.Name (Name)
import GHC.Data.FastString
import GHC.Utils.Panic.Plain
@@ -1103,6 +1105,10 @@ instance Binary Fingerprint where
put_ h (Fingerprint w1 w2) = do put_ h w1; put_ h w2
get h = do w1 <- get h; w2 <- get h; return (Fingerprint w1 w2)
+instance Binary ModuleName where
+ put_ bh (ModuleName fs) = put_ bh fs
+ get bh = do fs <- get bh; return (ModuleName fs)
+
-- instance Binary FunctionOrData where
-- put_ bh IsFunction = putByte bh 0
-- put_ bh IsData = putByte bh 1
diff --git a/compiler/GHC/Utils/Outputable.hs b/compiler/GHC/Utils/Outputable.hs
index b70dfc793d..5c47ad6f27 100644
--- a/compiler/GHC/Utils/Outputable.hs
+++ b/compiler/GHC/Utils/Outputable.hs
@@ -78,6 +78,8 @@ module GHC.Utils.Outputable (
pprFastFilePath, pprFilePathString,
+ pprModuleName,
+
-- * Controlling the style in which output is printed
BindingSite(..),
@@ -104,7 +106,7 @@ module GHC.Utils.Outputable (
) where
-import {-# SOURCE #-} Language.Haskell.Syntax.ImpExp ( ModuleName )
+import Language.Haskell.Syntax.Module.Name ( ModuleName(..) )
import GHC.Prelude
@@ -1039,6 +1041,16 @@ instance Outputable Serialized where
instance Outputable Extension where
ppr = text . show
+instance Outputable ModuleName where
+ ppr = pprModuleName
+
+pprModuleName :: ModuleName -> SDoc
+pprModuleName (ModuleName nm) =
+ getPprStyle $ \ sty ->
+ if codeStyle sty
+ then ztext (zEncodeFS nm)
+ else ftext nm
+
-----------------------------------------------------------------------
-- The @OutputableP@ class
-----------------------------------------------------------------------