From bae4d04456dc13f42eee2feae9d541836728ebbd Mon Sep 17 00:00:00 2001 From: romes Date: Wed, 29 Jun 2022 15:36:43 +0200 Subject: Refactor ModuleName to L.H.S.Module.Name 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. --- compiler/GHC/Utils/Binary.hs | 6 ++++++ compiler/GHC/Utils/Outputable.hs | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'compiler/GHC/Utils') 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 ----------------------------------------------------------------------- -- cgit v1.2.1