summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-07-02 20:36:19 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-07-25 00:45:07 -0400
commite443846ba05c943877e193a9518d5817e15560f3 (patch)
tree733d36b60ddd2bb69810466a118825b7e67f8840
parent02133353e712e98bfbbc6ed32305b137bb3654eb (diff)
downloadhaskell-e443846ba05c943877e193a9518d5817e15560f3.tar.gz
DynFlags: store printer in TraceBinIfaceReading
We don't need to pass the whole DynFlags, just pass the logging function, if any.
-rw-r--r--compiler/GHC/Iface/Binary.hs55
-rw-r--r--compiler/GHC/Iface/Load.hs14
2 files changed, 36 insertions, 33 deletions
diff --git a/compiler/GHC/Iface/Binary.hs b/compiler/GHC/Iface/Binary.hs
index 1e2f7060f1..5c533cbd9c 100644
--- a/compiler/GHC/Iface/Binary.hs
+++ b/compiler/GHC/Iface/Binary.hs
@@ -17,7 +17,7 @@ module GHC.Iface.Binary (
getSymtabName,
getDictFastString,
CheckHiWay(..),
- TraceBinIFaceReading(..),
+ TraceBinIFace(..),
getWithUserData,
putWithUserData,
@@ -49,7 +49,6 @@ import GHC.Types.Unique.Supply
import GHC.Utils.Panic
import GHC.Utils.Binary as Binary
import GHC.Types.SrcLoc
-import GHC.Utils.Error
import GHC.Data.FastMutInt
import GHC.Types.Unique
import GHC.Utils.Outputable
@@ -80,11 +79,12 @@ import qualified Control.Monad.Trans.State.Strict as State
data CheckHiWay = CheckHiWay | IgnoreHiWay
deriving Eq
-data TraceBinIFaceReading = TraceBinIFaceReading | QuietBinIFaceReading
- deriving Eq
+data TraceBinIFace
+ = TraceBinIFace (SDoc -> IO ())
+ | QuietBinIFace
-- | Read an interface file
-readBinIface :: CheckHiWay -> TraceBinIFaceReading -> FilePath
+readBinIface :: CheckHiWay -> TraceBinIFace -> FilePath
-> TcRnIf a b ModIface
readBinIface checkHiWay traceBinIFaceReading hi_path = do
ncu <- mkNameCacheUpdater
@@ -92,27 +92,20 @@ readBinIface checkHiWay traceBinIFaceReading hi_path = do
liftIO $ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path ncu
-- | Read an interface file in 'IO'.
-readBinIface_ :: DynFlags -> CheckHiWay -> TraceBinIFaceReading -> FilePath
+readBinIface_ :: DynFlags -> CheckHiWay -> TraceBinIFace -> FilePath
-> NameCacheUpdater
-> IO ModIface
-readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path ncu = do
+readBinIface_ dflags checkHiWay traceBinIFace hi_path ncu = do
let platform = targetPlatform dflags
- printer :: SDoc -> IO ()
- printer = case traceBinIFaceReading of
- TraceBinIFaceReading -> \sd ->
- putLogMsg dflags
- NoReason
- SevOutput
- noSrcSpan
- $ withPprStyle defaultDumpStyle sd
- QuietBinIFaceReading -> \_ -> return ()
-
wantedGot :: String -> a -> a -> (a -> SDoc) -> IO ()
wantedGot what wanted got ppr' =
- printer (text what <> text ": " <>
+ case traceBinIFace of
+ QuietBinIFace -> return ()
+ TraceBinIFace printer -> printer $
+ text what <> text ": " <>
vcat [text "Wanted " <> ppr' wanted <> text ",",
- text "got " <> ppr' got])
+ text "got " <> ppr' got]
errorOnMismatch :: (Eq a, Show a) => String -> a -> a -> IO ()
errorOnMismatch what wanted got =
@@ -185,8 +178,8 @@ getWithUserData ncu bh = do
get bh
-- | Write an interface file
-writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
-writeBinIface dflags hi_path mod_iface = do
+writeBinIface :: DynFlags -> TraceBinIFace -> FilePath -> ModIface -> IO ()
+writeBinIface dflags traceBinIface hi_path mod_iface = do
bh <- openBinMem initBinMemSize
let platform = targetPlatform dflags
put_ bh (binaryInterfaceMagic platform)
@@ -199,7 +192,7 @@ writeBinIface dflags hi_path mod_iface = do
extFields_p_p <- tellBin bh
put_ bh extFields_p_p
- putWithUserData (debugTraceMsg dflags 3) bh mod_iface
+ putWithUserData traceBinIface bh mod_iface
extFields_p <- tellBin bh
putAt bh extFields_p_p extFields_p
@@ -213,8 +206,8 @@ writeBinIface dflags hi_path mod_iface = do
-- is necessary if you want to serialise Names or FastStrings.
-- It also writes a symbol table and the dictionary.
-- This segment should be read using `getWithUserData`.
-putWithUserData :: Binary a => (SDoc -> IO ()) -> BinHandle -> a -> IO ()
-putWithUserData log_action bh payload = do
+putWithUserData :: Binary a => TraceBinIFace -> BinHandle -> a -> IO ()
+putWithUserData traceBinIface bh payload = do
-- Remember where the dictionary pointer will go
dict_p_p <- tellBin bh
-- Placeholder for ptr to dictionary
@@ -252,8 +245,11 @@ putWithUserData log_action bh payload = do
symtab_next <- readFastMutInt symtab_next
symtab_map <- readIORef symtab_map
putSymbolTable bh symtab_next symtab_map
- log_action (text "writeBinIface:" <+> int symtab_next
- <+> text "Names")
+ case traceBinIface of
+ QuietBinIFace -> return ()
+ TraceBinIFace printer ->
+ printer (text "writeBinIface:" <+> int symtab_next
+ <+> text "Names")
-- NB. write the dictionary after the symbol table, because
-- writing the symbol table may create more dictionary entries.
@@ -267,8 +263,11 @@ putWithUserData log_action bh payload = do
dict_next <- readFastMutInt dict_next_ref
dict_map <- readIORef dict_map_ref
putDictionary bh dict_next dict_map
- log_action (text "writeBinIface:" <+> int dict_next
- <+> text "dict entries")
+ case traceBinIface of
+ QuietBinIFace -> return ()
+ TraceBinIFace printer ->
+ printer (text "writeBinIface:" <+> int dict_next
+ <+> text "dict entries")
diff --git a/compiler/GHC/Iface/Load.hs b/compiler/GHC/Iface/Load.hs
index 3d8a1f47ef..fa148dc954 100644
--- a/compiler/GHC/Iface/Load.hs
+++ b/compiler/GHC/Iface/Load.hs
@@ -983,7 +983,8 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
writeIface :: DynFlags -> FilePath -> ModIface -> IO ()
writeIface dflags hi_file_path new_iface
= do createDirectoryIfMissing True (takeDirectory hi_file_path)
- writeBinIface dflags hi_file_path new_iface
+ let printer = TraceBinIFace (debugTraceMsg dflags 3)
+ writeBinIface dflags printer hi_file_path new_iface
-- @readIface@ tries just the one file.
readIface :: Module -> FilePath
@@ -993,7 +994,7 @@ readIface :: Module -> FilePath
readIface wanted_mod file_path
= do { res <- tryMostM $
- readBinIface CheckHiWay QuietBinIFaceReading file_path
+ readBinIface CheckHiWay QuietBinIFace file_path
; case res of
Right iface
-- NB: This check is NOT just a sanity check, it is
@@ -1112,12 +1113,15 @@ For some background on this choice see trac #15269.
-- | Read binary interface, and print it out
showIface :: HscEnv -> FilePath -> IO ()
showIface hsc_env filename = do
+ let dflags = hsc_dflags hsc_env
+ printer = putLogMsg dflags NoReason SevOutput noSrcSpan . withPprStyle defaultDumpStyle
+
-- skip the hi way check; we don't want to worry about profiled vs.
-- non-profiled interfaces, for example.
iface <- initTcRnIf 's' hsc_env () () $
- readBinIface IgnoreHiWay TraceBinIFaceReading filename
- let dflags = hsc_dflags hsc_env
- -- See Note [Name qualification with --show-iface]
+ readBinIface IgnoreHiWay (TraceBinIFace printer) filename
+
+ let -- See Note [Name qualification with --show-iface]
qualifyImportedNames mod _
| mod == mi_module iface = NameUnqual
| otherwise = NameNotInScope1