Skip to content

Commit c91cbe3

Browse files
Merge pull request #2564 from ucsd-progsys/fd/cores-default
Make using a single core the default
2 parents 3b06d81 + 5b15ef1 commit c91cbe3

File tree

14 files changed

+155
-302
lines changed

14 files changed

+155
-302
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Next
44

5+
- Change `--cores` default to 1 [#2564](https://github.com/ucsd-progsys/liquidhaskell/pull/2564)
6+
57
## 0.9.12.2 (2025-03-22)
68

79
- Simplify kvar solutions in fqout files [liquid-fixpoint#741](https://github.com/ucsd-progsys/liquid-fixpoint/pull/741).

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ Then a csv report can be generated from this json files with
148148
```
149149
cabal v2-run benchmark-timings -- tmp/*.json --phase LiquidHaskell -o summary.csv
150150
```
151-
On each line, the report will contain the time taken by each test.
151+
On each line, the report will contain the the wall-clock time taken by each test.
152+
Use `--phase LiquidHaskellCPU` to get the CPU time instead.
152153

153154
Comparison charts in `svg` format can be generated by invoking
154155

benchmark-timings/app/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Data.Traversable (for)
1717
import Data.Maybe (catMaybes)
1818

1919
import Data.ByteString.Lazy.Char8 (writeFile)
20-
import Data.List (foldl', intersperse, isSuffixOf)
20+
import Data.List (intersperse, isSuffixOf)
2121
import qualified Text.ParserCombinators.ReadP as ReadP
2222

2323
data Phase = Phase

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ module Liquid.GHC.API.Extra (
2424
, thisPackage
2525
, tyConRealArity
2626
, untick
27+
, withTimingWallClock
2728
) where
2829

30+
import Control.Monad
31+
import Control.Monad.IO.Class
32+
import GHC.Conc (getAllocationCounter)
33+
import Debug.Trace
34+
import GHC.Clock (getMonotonicTimeNSec)
2935
import Liquid.GHC.API.StableModule as StableModule
3036
import GHC hiding (modInfoLookupName)
3137
import Data.Data (Data, gmapQr, gmapT)
@@ -51,7 +57,10 @@ import GHC.Types.Name.Reader (nameRdrName)
5157
import GHC.Types.SrcLoc as Ghc
5258
import GHC.Types.Unique (getUnique, hasKey)
5359

60+
import GHC.Utils.Error as Ghc
61+
import GHC.Utils.Logger as Ghc
5462
import GHC.Utils.Outputable as Ghc hiding ((<>))
63+
import qualified GHC.Utils.Outputable as Ghc
5564

5665
import GHC.Unit.Module
5766

@@ -263,3 +272,72 @@ untick e = e
263272

264273
minus_RDR :: RdrName
265274
minus_RDR = nameRdrName minusName
275+
276+
-- | A version of 'withTiming' that uses wall clock time instead of CPU time.
277+
--
278+
-- This version is copied and modified from GHC's 'GHC.Utils.Error.withTiming'
279+
withTimingWallClock :: MonadIO m
280+
=> Logger
281+
-> SDoc -- ^ The name of the phase
282+
-> (a -> ()) -- ^ A function to force the result
283+
-- (often either @const ()@ or 'rnf')
284+
-> m a -- ^ The body of the phase to be timed
285+
-> m a
286+
withTimingWallClock logger what force_result action =
287+
if logVerbAtLeast logger 2 || logHasDumpFlag logger Opt_D_dump_timings
288+
then do when printTimingsNotDumpToFile $ liftIO $
289+
logInfo logger $ withPprStyle defaultUserStyle $
290+
text "***" <+> what Ghc.<> colon
291+
let ctx = log_default_user_context (logFlags logger)
292+
alloc0 <- liftIO getAllocationCounter
293+
!start <- liftIO getMonotonicTimeNSec
294+
eventBegins ctx what
295+
recordAllocs alloc0
296+
!r <- action
297+
() <- pure $ force_result r
298+
eventEnds ctx what
299+
!end <- liftIO getMonotonicTimeNSec
300+
alloc1 <- liftIO getAllocationCounter
301+
recordAllocs alloc1
302+
-- recall that allocation counter counts down
303+
let alloc = alloc0 - alloc1
304+
time = (end - start) `div` 1000000
305+
306+
when (logVerbAtLeast logger 2 && printTimingsNotDumpToFile)
307+
$ liftIO $ logInfo logger $ withPprStyle defaultUserStyle
308+
(text "!!!" <+> what Ghc.<> colon <+> text "finished in"
309+
<+> word64 time
310+
<+> text "milliseconds"
311+
Ghc.<> comma
312+
<+> text "allocated"
313+
<+> doublePrec 3 (realToFrac alloc / 1024 / 1024)
314+
<+> text "megabytes")
315+
316+
liftIO $ putDumpFileMaybe logger Opt_D_dump_timings "" FormatText
317+
$ text $ showSDocOneLine ctx
318+
$ hsep [ what Ghc.<> colon
319+
, text "alloc=" Ghc.<> ppr alloc
320+
, text "time=" Ghc.<> word64 time
321+
]
322+
pure r
323+
else action
324+
325+
where -- Avoid both printing to console and dumping to a file (#20316).
326+
printTimingsNotDumpToFile =
327+
not (log_dump_to_file (logFlags logger))
328+
329+
recordAllocs alloc =
330+
liftIO $ traceMarkerIO $ "GHC:allocs:" ++ show alloc
331+
332+
eventBegins ctx w = do
333+
let doc = eventBeginsDoc ctx w
334+
liftIO $ traceMarkerIO doc
335+
liftIO $ traceEventIO doc
336+
337+
eventEnds ctx w = do
338+
let doc = eventEndsDoc ctx w
339+
liftIO $ traceMarkerIO doc
340+
liftIO $ traceEventIO doc
341+
342+
eventBeginsDoc ctx w = showSDocOneLine ctx $ text "GHC:started:" <+> w
343+
eventEndsDoc ctx w = showSDocOneLine ctx $ text "GHC:finished:" <+> w

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module Language.Haskell.Liquid.GHC.Interface (
3333
, modSummaryHsFile
3434
, makeFamInstEnv
3535
, clearSpec
36-
, checkFilePragmas
3736
, lookupTyThing
3837
, updLiftedSpec
3938
) where
@@ -50,7 +49,6 @@ import Liquid.GHC.API as Ghc hiding ( text
5049
)
5150
import qualified Liquid.GHC.API as Ghc
5251

53-
import Control.Exception
5452
import Control.Monad
5553
import Control.Monad.Trans.Maybe
5654

@@ -61,7 +59,6 @@ import qualified Data.HashSet as S
6159

6260
import Text.PrettyPrint.HughesPJ hiding (first, (<>))
6361
import Language.Fixpoint.Types hiding (err, panic, Error, Result, Expr)
64-
import qualified Language.Fixpoint.Misc as Misc
6562
import Language.Haskell.Liquid.GHC.Misc
6663
import Language.Haskell.Liquid.GHC.Types (MGIModGuts(..))
6764
import Language.Haskell.Liquid.GHC.Play
@@ -152,19 +149,6 @@ modSummaryHsFile modSummary =
152149
showPpr (ms_mod modSummary))
153150
(ml_hs_file $ ms_location modSummary)
154151

155-
checkFilePragmas :: [Located String] -> IO ()
156-
checkFilePragmas = Misc.applyNonNull (return ()) throw . mapMaybe err
157-
where
158-
err pragma
159-
| check (val pragma) = Just (ErrFilePragma $ fSrcSpan pragma :: Error)
160-
| otherwise = Nothing
161-
check pragma = any (`isPrefixOf` pragma) bad
162-
bad =
163-
[ "-i", "--idirs"
164-
, "-g", "--ghc-option"
165-
, "--c-files", "--cfiles"
166-
]
167-
168152
--------------------------------------------------------------------------------
169153
-- | Family instance information
170154
--------------------------------------------------------------------------------

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ plugin = GHC.defaultPlugin {
132132
typecheckPluginGo cfg summary gblEnv = do
133133
logger <- getLogger
134134
dynFlags <- getDynFlags
135-
withTiming logger (text "LiquidHaskell" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $ do
135+
GHC.withTiming
136+
logger (text "LiquidHaskellCPU" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $
137+
GHC.withTimingWallClock
138+
logger (text "LiquidHaskell" <+> brackets (ppr $ ms_mod_name summary)) (const ()) $ do
136139
if gopt Opt_Haddock dynFlags
137140
then do
138141
-- Warn the user
@@ -300,15 +303,14 @@ typecheckHook' cfg ms tcGblEnv specComments = do
300303

301304
liquidCheckModule :: Config -> ModSummary -> TcGblEnv -> [BPspec] -> TcM (Either LiquidCheckException TcGblEnv)
302305
liquidCheckModule cfg0 ms tcg specs = do
303-
withPragmas cfg0 thisFile pragmas $ \cfg -> do
306+
withPragmas cfg0 pragmas $ \cfg -> do
304307
pipelineData <- do
305308
env <- getTopEnv
306309
session <- Session <$> liftIO (newIORef env)
307310
liftIO $ flip reflectGhc session $ mkPipelineData ms tcg specs
308311
liquidLib <- setGblEnv tcg $ liquidHaskellCheckWithConfig cfg pipelineData ms
309312
traverse (serialiseSpec tcg) liquidLib
310313
where
311-
thisFile = LH.modSummaryHsFile ms
312314
pragmas = [ s | Pragma s <- specs ]
313315

314316
mkPipelineData :: (GhcMonad m) => ModSummary -> TcGblEnv -> [BPspec] -> m PipelineData
@@ -412,10 +414,10 @@ checkLiquidHaskellContext lhContext = do
412414
out <- liftIO $ LH.checkTargetInfo pmrTargetInfo
413415

414416
let bareSpec = lhInputSpec lhContext
415-
file = LH.modSummaryHsFile $ lhModuleSummary lhContext
416417

417-
withPragmas (lhGlobalCfg lhContext) file (Ms.pragmas bareSpec) $ \moduleCfg -> do
418+
withPragmas (lhGlobalCfg lhContext) (Ms.pragmas bareSpec) $ \moduleCfg -> do
418419
let filters = getFilters moduleCfg
420+
file = LH.modSummaryHsFile $ lhModuleSummary lhContext
419421
-- Report the outcome of the checking
420422
LH.reportResult (errorLogger file filters) moduleCfg [giTarget (giSrc pmrTargetInfo)] out
421423
-- If there are unmatched filters or errors, and we are not reporting with
@@ -500,14 +502,8 @@ processModule LiquidHaskellContext{..} = do
500502
debugLog ("Module ==> " ++ renderModule thisModule)
501503

502504
let bareSpec0 = lhInputSpec
503-
-- /NOTE/: For the Plugin to work correctly, we shouldn't call 'canonicalizePath', because otherwise
504-
-- this won't trigger the \"external name resolution\" as part of 'Language.Haskell.Liquid.Bare.Resolve'
505-
-- (cfr. 'allowExtResolution').
506-
let file = LH.modSummaryHsFile lhModuleSummary
507-
508-
_ <- liftIO $ LH.checkFilePragmas $ Ms.pragmas bareSpec0
509505

510-
withPragmas lhGlobalCfg file (Ms.pragmas bareSpec0) $ \moduleCfg -> do
506+
withPragmas lhGlobalCfg (Ms.pragmas bareSpec0) $ \moduleCfg -> do
511507
dependencies <- loadDependencies moduleCfg lhRelevantModules
512508

513509
debugLog $ "Found " <> show (HM.size $ getDependencies dependencies) <> " dependencies:"
@@ -520,6 +516,7 @@ processModule LiquidHaskellContext{..} = do
520516
hscEnv <- getTopEnv
521517
let preNormalizedCore = preNormalizeCore moduleCfg modGuts0
522518
modGuts = modGuts0 { mg_binds = preNormalizedCore }
519+
file = LH.modSummaryHsFile lhModuleSummary
523520
targetSrc <- liftIO $ makeTargetSrc moduleCfg file modGuts hscEnv
524521
logger <- getLogger
525522

0 commit comments

Comments
 (0)