Skip to content

Commit 760c082

Browse files
Ask LH to tell ghc to collect timings
1 parent f72a084 commit 760c082

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

liquidhaskell-boot/src-ghc/Liquid/GHC/API.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ import GHC.Core.Opt.OccurAnal as Ghc
478478
( occurAnalysePgm )
479479
import GHC.Core.TyCo.FVs as Ghc (tyCoVarsOfCo, tyCoVarsOfType)
480480
import GHC.Driver.Backend as Ghc (interpreterBackend)
481+
import GHC.Driver.DynFlags as Ghc
482+
( DumpFlag(Opt_D_dump_timings)
483+
, dopt_set
484+
)
481485
import GHC.Driver.Env as Ghc
482486
( HscEnv(hsc_NC, hsc_unit_env, hsc_dflags, hsc_plugins)
483487
, Hsc
@@ -827,7 +831,13 @@ import GHC.Utils.Binary as Ghc
827831
, withBinBuffer
828832
)
829833
import GHC.Utils.Error as Ghc (pprLocMsgEnvelope, withTiming)
830-
import GHC.Utils.Logger as Ghc (Logger(logFlags), putLogMsg)
834+
import GHC.Utils.Logger as Ghc
835+
( LogFlags
836+
, Logger(logFlags)
837+
, putLogMsg
838+
, log_set_dopt
839+
, updateLogFlags
840+
)
831841
import GHC.Utils.Outputable as Ghc hiding ((<>))
832842
import GHC.Utils.Panic as Ghc (panic, throwGhcException, throwGhcExceptionIO)
833843
import GHC.Utils.Misc as Ghc (lengthAtLeast)

liquidhaskell-boot/src/Language/Haskell/Liquid/GHC/Plugin.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ plugin = GHC.defaultPlugin {
110110
, pluginRecompile = purePlugin
111111
}
112112
where
113-
liquidPlugin :: (MonadIO m) => [CommandLineOption] -> a -> (Config -> m a) -> m a
113+
liquidPlugin :: MonadIO m => [CommandLineOption] -> a -> (Config -> m a) -> m a
114114
liquidPlugin opts def go = do
115115
cfg <- liftIO $ LH.getOpts opts
116116
if skipModule cfg then return def else go cfg
@@ -130,12 +130,13 @@ plugin = GHC.defaultPlugin {
130130
-- See also: https://github.com/ucsd-progsys/liquidhaskell/issues/1727
131131
-- for a post-mortem.
132132
typecheckPluginGo cfg summary gblEnv = do
133-
logger <- getLogger
134-
dynFlags <- getDynFlags
133+
logger0 <- getLogger
134+
let logger = updateLogFlags logger0 (maybeDDumpTimings cfg)
135135
GHC.withTiming
136-
logger (text "LiquidHaskellCPU" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $
136+
logger (text "LiquidHaskellCPU" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $
137137
GHC.withTimingWallClock
138138
logger (text "LiquidHaskell" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $ do
139+
dynFlags <- getDynFlags
139140
if gopt Opt_Haddock dynFlags
140141
then do
141142
-- Warn the user
@@ -158,6 +159,13 @@ plugin = GHC.defaultPlugin {
158159
Right newGblEnv' ->
159160
pure newGblEnv'
160161

162+
-- We instruct LH to collect timings instead of doing it directly to GHC
163+
-- This helps work around https://github.com/haskell/cabal/issues/11116
164+
maybeDDumpTimings :: Config -> LogFlags -> LogFlags
165+
maybeDDumpTimings cfg =
166+
if ddumpTimings cfg then log_set_dopt Opt_D_dump_timings
167+
else id
168+
161169
--------------------------------------------------------------------------------
162170
-- | Inter-phase communication -------------------------------------------------
163171
--------------------------------------------------------------------------------

liquidhaskell-boot/src/Language/Haskell/Liquid/UX/CmdLine.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ defConfig = Config {
443443
= False &= help "Allow refining constructors with unsafe refinements"
444444
&= name "allow-unsafe-constructors"
445445
&= explicit
446+
, ddumpTimings
447+
= False &= help "Dump time measures of the Liquid Haskell plugin"
448+
&= name "ddump-timings"
449+
&= explicit
446450
} &= program "liquidhaskell"
447451
&= help "Refinement Types for Haskell"
448452
&= summary copyright

liquidhaskell-boot/src/Language/Haskell/Liquid/UX/Config.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ data Config = Config
118118
, dumpOpaqueReflections :: Bool -- Dumps all opaque reflections to the stdout
119119
, dumpPreNormalizedCore :: Bool -- Dumps the prenormalized core (before a-normalization)
120120
, allowUnsafeConstructors :: Bool -- ^ Allow refining constructors with unsafe refinements
121+
, ddumpTimings :: Bool -- ^ Dump time measures of the Liquid Haskell plugin
122+
-- Only needed to work around https://github.com/haskell/cabal/issues/11116
121123
} deriving (Generic, Data, Show, Eq)
122124

123125
allowPLE :: Config -> Bool

tests/tests.cabal

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ flag stack
2020
flag measure-timings
2121
default: False
2222
manual: True
23-
description: Enable when collecting timing information. It also enables
24-
-fforce-recomp since cabal sometimes tries to compile files more
25-
than once, and the second run discards the timings of the first.
23+
description: Enable when collecting timing information.
2624

2725
executable test-driver
2826
main-is: driver.hs
@@ -53,7 +51,10 @@ common common-ghc-options
5351
-O0
5452
-no-link
5553
if flag(measure-timings)
56-
ghc-options: -fforce-recomp -ddump-timings -ddump-to-file
54+
-- We collect timing measures from GHC whenever the plugin runs
55+
-- Doesn't run when linking in particular. See
56+
-- https://github.com/haskell/cabal/issues/11116
57+
ghc-options: -fplugin-opt=LiquidHaskell:--ddump-timings -ddump-to-file
5758
default-language: Haskell2010
5859

5960
flag benchmark-stitch-lh
@@ -851,8 +852,6 @@ executable reflect-pos
851852
, ReflString1
852853
, T2405
853854

854-
if flag(measure-timings)
855-
ghc-options: -fforce-recomp -ddump-timings -ddump-to-file
856855
build-depends: base
857856
, liquid-prelude
858857
, liquidhaskell

0 commit comments

Comments
 (0)