Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
-
fde9cb2c
by Luite Stegeman at 2026-05-28T05:42:39-04:00
-
f2725996
by Tom McLaughlin at 2026-05-28T05:42:51-04:00
-
8b0a4bc5
by Wolfgang Jeltsch at 2026-05-28T05:42:52-04:00
-
e9aef297
by Simon Jakobi at 2026-05-28T05:42:53-04:00
28 changed files:
- + changelog.d/fix-blackhole-handling
- + changelog.d/module-graph-reuse-in-downsweep
- + changelog.d/windows-rethrow-overlapped-exception
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/SysTools/Cpp.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Windows.hsc
- rts/Messages.c
- rts/ThreadPaused.c
- rts/Threads.c
- rts/Updates.h
- rts/include/rts/storage/ClosureMacros.h
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/A.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/B.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/C.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/D.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/X.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/Y.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.modules/Z.hs
- + testsuite/tests/ghc-api/downsweep/IncrementalDownsweep.stdout
- testsuite/tests/ghc-api/downsweep/OldModLocation.hs
- testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs
- testsuite/tests/ghc-api/downsweep/all.T
- testsuite/tests/ghc-api/fixed-nodes/InterfaceModuleGraph.hs
- + testsuite/tests/perf/should_run/T11226.hs
- + testsuite/tests/perf/should_run/T11226.stdout
- testsuite/tests/perf/should_run/all.T
Changes:
| 1 | +section: rts
|
|
| 2 | +synopsis: Fix several black hole handling bugs that could lead to deadlocks
|
|
| 3 | + or crashes in multithreaded programs. These could show up as the program
|
|
| 4 | + hanging or "END_TSO_QUEUE object entered" errors.
|
|
| 5 | +issues: #26922 #26936
|
|
| 6 | +mrs: !15640 |
| 1 | +section: compiler
|
|
| 2 | +synopsis: Allow `downsweep` to use nodes of an existing module graph
|
|
| 3 | +issues: #27054
|
|
| 4 | +mrs: !16028
|
|
| 5 | +description: {
|
|
| 6 | + This contribution enables `downsweep` to use the nodes of a module
|
|
| 7 | + graph obtained from a previous downsweeping round, which allows GHC
|
|
| 8 | + API applications to build module graphs somewhat incrementally.
|
|
| 9 | +} |
| 1 | +section: rts
|
|
| 2 | +synopsis: Rethrow exceptions in overlapped IO when using the WinIO IO manager.
|
|
| 3 | +issues: #27283
|
|
| 4 | +mrs: !15887
|
|
| 5 | + |
|
| 6 | +description: {
|
|
| 7 | + This change was made to support WinIO in the network library; see https://github.com/haskell/network/issues/602.
|
|
| 8 | +} |
| ... | ... | @@ -146,6 +146,10 @@ The result is having a uniform graph available for the whole compilation pipelin |
| 146 | 146 | -- an import of this module mean.
|
| 147 | 147 | type DownsweepCache = M.Map (UnitId, PkgQual, ModuleNameWithIsBoot) [Either DriverMessages ModuleNodeInfo]
|
| 148 | 148 | |
| 149 | +moduleGraphNodeMap :: ModuleGraph -> M.Map NodeKey ModuleGraphNode
|
|
| 150 | +moduleGraphNodeMap graph
|
|
| 151 | + = M.fromList [(mkNodeKey node, node) | node <- mgModSummaries' graph]
|
|
| 152 | + |
|
| 149 | 153 | -----------------------------------------------------------------------------
|
| 150 | 154 | --
|
| 151 | 155 | -- | Downsweep (dependency analysis) for --make mode
|
| ... | ... | @@ -158,6 +162,13 @@ type DownsweepCache = M.Map (UnitId, PkgQual, ModuleNameWithIsBoot) [Either Driv |
| 158 | 162 | -- cache to avoid recalculating a module summary if the source is
|
| 159 | 163 | -- unchanged.
|
| 160 | 164 | --
|
| 165 | +-- Downsweeping can start from scratch for from a given module graph. In the
|
|
| 166 | +-- latter case, the given graph is fully included in the resulting graph, even
|
|
| 167 | +-- if parts of it are not reachable from any of the given roots. When an import
|
|
| 168 | +-- is processed, the source of the imported module is not consulted if this
|
|
| 169 | +-- module is already mentioned in the given graph. The sources of the root
|
|
| 170 | +-- modules are always consulted, though.
|
|
| 171 | +--
|
|
| 161 | 172 | -- The returned ModuleGraph has one node for each home-package
|
| 162 | 173 | -- module, plus one for any hs-boot files. The imports of these nodes
|
| 163 | 174 | -- are all there, including the imports of non-home-package modules.
|
| ... | ... | @@ -172,6 +183,8 @@ downsweep :: HscEnv |
| 172 | 183 | -> Maybe Messager
|
| 173 | 184 | -> [ModSummary]
|
| 174 | 185 | -- ^ Old summaries
|
| 186 | + -> Maybe ModuleGraph
|
|
| 187 | + -- ^ Optionally a module graph to extend
|
|
| 175 | 188 | -> [ModuleName] -- Ignore dependencies on these; treat
|
| 176 | 189 | -- them as if they were package modules
|
| 177 | 190 | -> Bool -- True <=> allow multiple targets to have
|
| ... | ... | @@ -181,7 +194,7 @@ downsweep :: HscEnv |
| 181 | 194 | -- The non-error elements of the returned list all have distinct
|
| 182 | 195 | -- (Modules, IsBoot) identifiers, unless the Bool is true in
|
| 183 | 196 | -- which case there can be repeats
|
| 184 | -downsweep hsc_env diag_wrapper msg old_summaries excl_mods allow_dup_roots = do
|
|
| 197 | +downsweep hsc_env diag_wrapper msg old_summaries maybe_base_graph excl_mods allow_dup_roots = do
|
|
| 185 | 198 | n_jobs <- mkWorkerLimit (hsc_dflags hsc_env)
|
| 186 | 199 | (root_errs, root_summaries) <- rootSummariesParallel n_jobs hsc_env diag_wrapper msg summary
|
| 187 | 200 | let closure_errs = checkHomeUnitsClosed unit_env
|
| ... | ... | @@ -191,7 +204,7 @@ downsweep hsc_env diag_wrapper msg old_summaries excl_mods allow_dup_roots = do |
| 191 | 204 | |
| 192 | 205 | case all_errs of
|
| 193 | 206 | [] -> do
|
| 194 | - (downsweep_errs, downsweep_nodes) <- downsweepFromRootNodes hsc_env old_summary_map excl_mods allow_dup_roots DownsweepUseCompile (map ModuleNodeCompile root_summaries) []
|
|
| 207 | + (downsweep_errs, downsweep_nodes) <- downsweepFromRootNodes hsc_env old_summary_map maybe_base_graph excl_mods allow_dup_roots DownsweepUseCompile (map ModuleNodeCompile root_summaries) []
|
|
| 195 | 208 | |
| 196 | 209 | let (other_errs, unit_nodes) = partitionEithers $ HUG.unitEnv_foldWithKey (\nodes uid hue -> nodes ++ unitModuleNodes downsweep_nodes uid hue) [] (hsc_HUG hsc_env)
|
| 197 | 210 | |
| ... | ... | @@ -232,7 +245,7 @@ downsweep hsc_env diag_wrapper msg old_summaries excl_mods allow_dup_roots = do |
| 232 | 245 | downsweepThunk :: HscEnv -> ModSummary -> IO ModuleGraph
|
| 233 | 246 | downsweepThunk hsc_env mod_summary = unsafeInterleaveIO $ do
|
| 234 | 247 | debugTraceMsg (hsc_logger hsc_env) 3 $ text "Computing Module Graph thunk..."
|
| 235 | - ~(errs, mg) <- downsweepFromRootNodes hsc_env mempty [] True DownsweepUseFixed [ModuleNodeCompile mod_summary] []
|
|
| 248 | + ~(errs, mg) <- downsweepFromRootNodes hsc_env mempty Nothing [] True DownsweepUseFixed [ModuleNodeCompile mod_summary] []
|
|
| 236 | 249 | let dflags = hsc_dflags hsc_env
|
| 237 | 250 | liftIO $ printOrThrowDiagnostics (hsc_logger hsc_env)
|
| 238 | 251 | (initPrintConfig dflags)
|
| ... | ... | @@ -360,7 +373,7 @@ downsweepInstalledModules hsc_env mods = do |
| 360 | 373 | _ -> throwGhcException $ ProgramError $ showSDoc (hsc_dflags hsc_env) $ text "downsweepInstalledModules: Could not find installed module" <+> ppr i
|
| 361 | 374 | |
| 362 | 375 | nodes <- mapM process installed_mods
|
| 363 | - (errs, mg) <- downsweepFromRootNodes hsc_env mempty [] True DownsweepUseFixed nodes external_uids
|
|
| 376 | + (errs, mg) <- downsweepFromRootNodes hsc_env mempty Nothing [] True DownsweepUseFixed nodes external_uids
|
|
| 364 | 377 | |
| 365 | 378 | -- Similarly here, we should really not get any errors, but print them out if we do.
|
| 366 | 379 | let dflags = hsc_dflags hsc_env
|
| ... | ... | @@ -385,19 +398,21 @@ data DownsweepMode = DownsweepUseCompile | DownsweepUseFixed |
| 385 | 398 | -- all the dependencies, all the way to the leaf units.
|
| 386 | 399 | downsweepFromRootNodes :: HscEnv
|
| 387 | 400 | -> M.Map (UnitId, OsPath) ModSummary
|
| 401 | + -> Maybe ModuleGraph
|
|
| 388 | 402 | -> [ModuleName]
|
| 389 | 403 | -> Bool
|
| 390 | 404 | -> DownsweepMode -- ^ Whether to create fixed or compile nodes for dependencies
|
| 391 | 405 | -> [ModuleNodeInfo] -- ^ The starting ModuleNodeInfo
|
| 392 | 406 | -> [UnitId] -- ^ The starting units
|
| 393 | 407 | -> IO ([DriverMessages], [ModuleGraphNode])
|
| 394 | -downsweepFromRootNodes hsc_env old_summaries excl_mods allow_dup_roots mode root_nodes root_uids
|
|
| 408 | +downsweepFromRootNodes hsc_env old_summaries maybe_base_graph excl_mods allow_dup_roots mode root_nodes root_uids
|
|
| 395 | 409 | = do
|
| 396 | 410 | let root_map = mkRootMap root_nodes
|
| 397 | 411 | checkDuplicates root_map
|
| 398 | 412 | let env = DownsweepEnv hsc_env mode old_summaries excl_mods
|
| 399 | 413 | (deps', map0) <- runDownsweepM env $ do
|
| 400 | - (module_deps, map0) <- loopModuleNodeInfos root_nodes (M.empty, root_map)
|
|
| 414 | + let base_nodes = maybe M.empty moduleGraphNodeMap maybe_base_graph
|
|
| 415 | + (module_deps, map0) <- loopModuleNodeInfos root_nodes (base_nodes, root_map)
|
|
| 401 | 416 | let all_deps = loopUnit hsc_env module_deps root_uids
|
| 402 | 417 | let all_instantiations = getHomeUnitInstantiations hsc_env
|
| 403 | 418 | deps' <- loopInstantiations all_instantiations all_deps
|
| ... | ... | @@ -232,7 +232,7 @@ depanalPartial diag_wrapper msg excluded_mods allow_dup_roots = do |
| 232 | 232 | liftIO $ flushFinderCaches (hsc_FC hsc_env) (hsc_unit_env hsc_env)
|
| 233 | 233 | |
| 234 | 234 | (errs, mod_graph) <- liftIO $ downsweep
|
| 235 | - hsc_env diag_wrapper msg (mgModSummaries old_graph)
|
|
| 235 | + hsc_env diag_wrapper msg (mgModSummaries old_graph) Nothing
|
|
| 236 | 236 | excluded_mods allow_dup_roots
|
| 237 | 237 | return (unionManyMessages errs, mod_graph)
|
| 238 | 238 |
| ... | ... | @@ -148,7 +148,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do |
| 148 | 148 | -- and BUILD is the same as our HOST.
|
| 149 | 149 | |
| 150 | 150 | let io_manager_defs =
|
| 151 | - [ "-D__IO_MANAGER_WINIO__=1" | isWindows ] ++
|
|
| 151 | + [ "-D__IO_MANAGER_WINIO__=2" | isWindows ] ++
|
|
| 152 | 152 | [ "-D__IO_MANAGER_MIO__=1" ]
|
| 153 | 153 | |
| 154 | 154 | let sse_defs =
|
| ... | ... | @@ -690,7 +690,11 @@ withOverlappedEx mgr fname h async offset startCB completionCB = do |
| 690 | 690 | -- can go into an unbounded alertable wait.
|
| 691 | 691 | delay <- runExpiredTimeouts mgr
|
| 692 | 692 | registerAlertableWait delay
|
| 693 | - return $ IOFailed Nothing
|
|
| 693 | + -- Re-throw the original exception rather than
|
|
| 694 | + -- returning IOFailed. This ensures that async
|
|
| 695 | + -- exceptions (e.g. Timeout from System.Timeout)
|
|
| 696 | + -- propagate correctly to their handlers.
|
|
| 697 | + E.throw e
|
|
| 694 | 698 | let runner = do debugIO $ (dbgMsg ":: waiting ") ++ " | " ++ show lpol
|
| 695 | 699 | res <- readMVar signal `catch` cancel
|
| 696 | 700 | debugIO $ dbgMsg ":: signaled "
|
| ... | ... | @@ -188,10 +188,7 @@ uint32_t messageBlackHole(Capability *cap, MessageBlackHole *msg) |
| 188 | 188 | // BLACKHOLE has already been updated, and GC has shorted out the
|
| 189 | 189 | // indirection, so the pointer no longer points to a BLACKHOLE at
|
| 190 | 190 | // all.
|
| 191 | - if (bh_info != &stg_BLACKHOLE_info &&
|
|
| 192 | - bh_info != &stg_CAF_BLACKHOLE_info &&
|
|
| 193 | - bh_info != &__stg_EAGER_BLACKHOLE_info &&
|
|
| 194 | - bh_info != &stg_WHITEHOLE_info) {
|
|
| 191 | + if (!IS_BLACKHOLE_OR_WHITEHOLE_INFO(bh_info)) {
|
|
| 195 | 192 | return 0;
|
| 196 | 193 | }
|
| 197 | 194 | |
| ... | ... | @@ -350,10 +347,7 @@ StgTSO * blackHoleOwner (StgClosure *bh) |
| 350 | 347 | |
| 351 | 348 | info = RELAXED_LOAD(&bh->header.info);
|
| 352 | 349 | |
| 353 | - if (info != &stg_BLACKHOLE_info &&
|
|
| 354 | - info != &stg_CAF_BLACKHOLE_info &&
|
|
| 355 | - info != &__stg_EAGER_BLACKHOLE_info &&
|
|
| 356 | - info != &stg_WHITEHOLE_info) {
|
|
| 350 | + if (!IS_BLACKHOLE_OR_WHITEHOLE_INFO(info)) {
|
|
| 357 | 351 | return NULL;
|
| 358 | 352 | }
|
| 359 | 353 |
| ... | ... | @@ -183,6 +183,30 @@ stackSqueeze(Capability *cap, StgTSO *tso, StgPtr bottom) |
| 183 | 183 | }
|
| 184 | 184 | }
|
| 185 | 185 | |
| 186 | +/*
|
|
| 187 | + * Check whether tso is the owner of the black hole bh.
|
|
| 188 | + *
|
|
| 189 | + * We must call this from the capability that runs tso,
|
|
| 190 | + * since that guarantees that the writes to bh->indirectee
|
|
| 191 | + * by tso claiming ownership have been visible. If another
|
|
| 192 | + * tso has claimed it again afterwards we can safely suspend
|
|
| 193 | + * our work.
|
|
| 194 | + */
|
|
| 195 | +static bool
|
|
| 196 | +threadPausedBlackHoleOwner(StgTSO *tso, StgClosure *bh)
|
|
| 197 | +{
|
|
| 198 | + StgClosure *ind = RELAXED_LOAD(&((StgInd*)bh)->indirectee);
|
|
| 199 | + if (ind == (StgClosure*)tso) {
|
|
| 200 | + return true;
|
|
| 201 | + }
|
|
| 202 | + const StgInfoTable *ind_info = GET_INFO(UNTAG_CLOSURE(ind));
|
|
| 203 | + if (ind_info == &stg_BLOCKING_QUEUE_CLEAN_info
|
|
| 204 | + || ind_info == &stg_BLOCKING_QUEUE_DIRTY_info) {
|
|
| 205 | + return ((StgBlockingQueue*)UNTAG_CLOSURE(ind))->owner == tso;
|
|
| 206 | + }
|
|
| 207 | + return false;
|
|
| 208 | +}
|
|
| 209 | + |
|
| 186 | 210 | /* -----------------------------------------------------------------------------
|
| 187 | 211 | * Pausing a thread
|
| 188 | 212 | *
|
| ... | ... | @@ -255,11 +279,10 @@ threadPaused(Capability *cap, StgTSO *tso) |
| 255 | 279 | // Note [suspend duplicate work]
|
| 256 | 280 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 257 | 281 | // If the info table is a WHITEHOLE or a BLACKHOLE, then
|
| 258 | - // another thread has claimed it (via the SET_INFO()
|
|
| 259 | - // below), or is in the process of doing so. In that case
|
|
| 260 | - // we want to suspend the work that the current thread has
|
|
| 261 | - // done on this thunk and wait until the other thread has
|
|
| 262 | - // finished.
|
|
| 282 | + // some thread has claimed it, or is in the process of doing
|
|
| 283 | + // so. In that case we want to suspend the work that the
|
|
| 284 | + // current thread has done on this thunk and wait until the
|
|
| 285 | + // other thread has finished.
|
|
| 263 | 286 | //
|
| 264 | 287 | // If eager blackholing is taking place, it could be the
|
| 265 | 288 | // case that the blackhole points to the current
|
| ... | ... | @@ -287,8 +310,8 @@ threadPaused(Capability *cap, StgTSO *tso) |
| 287 | 310 | // Note that great care is required when entering computations
|
| 288 | 311 | // suspended by this mechanism. See Note [AP_STACKs must be eagerly
|
| 289 | 312 | // blackholed] for details.
|
| 290 | - if (((bh_info == &stg_BLACKHOLE_info)
|
|
| 291 | - && (RELAXED_LOAD(&((StgInd*)bh)->indirectee) != (StgClosure*)tso))
|
|
| 313 | + if ((IS_BLACKHOLE_INFO(bh_info)
|
|
| 314 | + && !threadPausedBlackHoleOwner(tso, bh))
|
|
| 292 | 315 | || (bh_info == &stg_WHITEHOLE_info))
|
| 293 | 316 | {
|
| 294 | 317 | debugTrace(DEBUG_squeeze,
|
| ... | ... | @@ -318,14 +341,13 @@ threadPaused(Capability *cap, StgTSO *tso) |
| 318 | 341 | // If we have a frame that is already eagerly blackholed, we
|
| 319 | 342 | // shouldn't overwrite its payload: There may already be a blocking
|
| 320 | 343 | // queue (see #26324).
|
| 321 | - if(frame_info == &stg_bh_upd_frame_info) {
|
|
| 322 | - // eager black hole: we do nothing
|
|
| 344 | + if(frame_info == &stg_bh_upd_frame_info
|
|
| 345 | + || IS_BLACKHOLE_INFO(bh_info)) {
|
|
| 346 | + // already a black hole: we do nothing
|
|
| 323 | 347 | |
| 324 | 348 | // it should be a black hole (but we may not own it, as another
|
| 325 | 349 | // thread could have raced us to claim it)
|
| 326 | - ASSERT(bh_info == &stg_BLACKHOLE_info ||
|
|
| 327 | - bh_info == &__stg_EAGER_BLACKHOLE_info ||
|
|
| 328 | - bh_info == &stg_CAF_BLACKHOLE_info);
|
|
| 350 | + ASSERT(IS_BLACKHOLE_INFO(bh_info));
|
|
| 329 | 351 | |
| 330 | 352 | } else {
|
| 331 | 353 | // lazy black hole
|
| ... | ... | @@ -474,7 +474,7 @@ checkBlockingQueues (Capability *cap, StgTSO *tso) |
| 474 | 474 | // thing the result would be the same in almost all cases. See #20093.
|
| 475 | 475 | p = UNTAG_CLOSURE(bq->bh);
|
| 476 | 476 | const StgInfoTable *pinfo = ACQUIRE_LOAD(&p->header.info);
|
| 477 | - if (pinfo != &stg_BLACKHOLE_info ||
|
|
| 477 | + if (!IS_BLACKHOLE_INFO(pinfo) ||
|
|
| 478 | 478 | (RELAXED_LOAD(&((StgInd *)p)->indirectee) != (StgClosure*)bq))
|
| 479 | 479 | {
|
| 480 | 480 | wakeBlockingQueue(cap,bq);
|
| ... | ... | @@ -498,10 +498,7 @@ updateThunk (Capability *cap, StgTSO *tso, StgClosure *thunk, StgClosure *val) |
| 498 | 498 | const StgInfoTable *i;
|
| 499 | 499 | |
| 500 | 500 | i = ACQUIRE_LOAD(&thunk->header.info);
|
| 501 | - if (i != &stg_BLACKHOLE_info &&
|
|
| 502 | - i != &stg_CAF_BLACKHOLE_info &&
|
|
| 503 | - i != &__stg_EAGER_BLACKHOLE_info &&
|
|
| 504 | - i != &stg_WHITEHOLE_info) {
|
|
| 501 | + if (!IS_BLACKHOLE_OR_WHITEHOLE_INFO(i)) {
|
|
| 505 | 502 | updateWithIndirection(cap, thunk, val);
|
| 506 | 503 | return;
|
| 507 | 504 | }
|
| ... | ... | @@ -190,9 +190,9 @@ |
| 190 | 190 | * frame is encountered, it checks the info table of the updatee and:
|
| 191 | 191 | *
|
| 192 | 192 | * - if it is `BLACKHOLE`, then the thunk has already been claimed for evaluation
|
| 193 | - * by another thread, and the yielding thread is instead added to the
|
|
| 194 | - * `BLACKHOLE`'s blocking queue (see Note [suspend duplicate work] in
|
|
| 195 | - * `ThreadPaused.c`).
|
|
| 193 | + * by some thread. If that's not the yielding thread itself, the yielding thread
|
|
| 194 | + * is added to the `BLACKHOLE`'s blocking queue (see Note [suspend duplicate
|
|
| 195 | + * work] in `ThreadPaused.c`).
|
|
| 196 | 196 | *
|
| 197 | 197 | * - if not, then it blackholes the thunk as done in eager blackholing (but
|
| 198 | 198 | * using the `BLACKHOLE_info` info table instead of `EAGER_BLACKHOLE_info`).
|
| ... | ... | @@ -382,6 +382,18 @@ EXTERN_INLINE StgOffset BLACKHOLE_sizeW ( void ); |
| 382 | 382 | EXTERN_INLINE StgOffset BLACKHOLE_sizeW ( void )
|
| 383 | 383 | { return sizeofW(StgInd); } // a BLACKHOLE is a kind of indirection
|
| 384 | 384 | |
| 385 | +/* -----------------------------------------------------------------------------
|
|
| 386 | + Blackhole predicates
|
|
| 387 | + -------------------------------------------------------------------------- */
|
|
| 388 | + |
|
| 389 | +#define IS_BLACKHOLE_INFO(info) \
|
|
| 390 | + ((info) == &stg_BLACKHOLE_info || \
|
|
| 391 | + (info) == &__stg_EAGER_BLACKHOLE_info || \
|
|
| 392 | + (info) == &stg_CAF_BLACKHOLE_info)
|
|
| 393 | + |
|
| 394 | +#define IS_BLACKHOLE_OR_WHITEHOLE_INFO(info) \
|
|
| 395 | + (IS_BLACKHOLE_INFO(info) || (info) == &stg_WHITEHOLE_info)
|
|
| 396 | + |
|
| 385 | 397 | /* --------------------------------------------------------------------------
|
| 386 | 398 | Sizes of closures
|
| 387 | 399 | ------------------------------------------------------------------------*/
|
| 1 | +{-# LANGUAGE Haskell2010 #-}
|
|
| 2 | + |
|
| 3 | +{-# OPTIONS_GHC -Wall -Werror #-}
|
|
| 4 | + |
|
| 5 | +import Control.Monad (unless)
|
|
| 6 | +import Control.Monad.IO.Class (liftIO)
|
|
| 7 | +import Control.Arrow ((>>>))
|
|
| 8 | +import Data.List (sort)
|
|
| 9 | +import System.Environment (getArgs)
|
|
| 10 | +import System.Exit (exitFailure)
|
|
| 11 | +import System.IO (stderr)
|
|
| 12 | +import System.Directory (removeFile)
|
|
| 13 | +import Language.Haskell.Syntax.Module.Name (moduleNameString)
|
|
| 14 | +import GHC.Utils.Ppr (Mode (PageMode))
|
|
| 15 | +import GHC.Utils.Outputable (vcat, defaultSDocContext, printSDocLn, ppr)
|
|
| 16 | +import GHC.Utils.Logger (getLogger)
|
|
| 17 | +import GHC.Types.SrcLoc (noLoc)
|
|
| 18 | +import GHC.Types.Error (mkUnknownDiagnostic)
|
|
| 19 | +import GHC.Unit.Types (moduleName)
|
|
| 20 | +import GHC.Unit.Module.ModSummary (ms_mod)
|
|
| 21 | +import GHC.Unit.Module.Graph (ModuleGraph, mgModSummaries)
|
|
| 22 | +import GHC.Driver.DynFlags (defaultFatalMessager, defaultFlushOut)
|
|
| 23 | +import GHC.Driver.Monad (Ghc, getSession, getSessionDynFlags)
|
|
| 24 | +import GHC.Driver.Make (downsweep)
|
|
| 25 | +import GHC.Driver.Errors.Types (DriverMessages)
|
|
| 26 | +import GHC
|
|
| 27 | + (
|
|
| 28 | + defaultErrorHandler,
|
|
| 29 | + guessTarget,
|
|
| 30 | + setTargets,
|
|
| 31 | + parseDynamicFlags,
|
|
| 32 | + setSessionDynFlags,
|
|
| 33 | + runGhc
|
|
| 34 | + )
|
|
| 35 | + |
|
| 36 | +sourceDirectory :: String
|
|
| 37 | +sourceDirectory = "IncrementalDownsweep.modules"
|
|
| 38 | + |
|
| 39 | +withSimpleErrorHandler :: Ghc a -> Ghc a
|
|
| 40 | +withSimpleErrorHandler = defaultErrorHandler defaultFatalMessager
|
|
| 41 | + defaultFlushOut
|
|
| 42 | + |
|
| 43 | +handleDriverMessages :: [DriverMessages] -> IO ()
|
|
| 44 | +handleDriverMessages driverMsgs
|
|
| 45 | + = unless (null driverMsgs) $
|
|
| 46 | + do
|
|
| 47 | + printSDocLn defaultSDocContext
|
|
| 48 | + (PageMode True)
|
|
| 49 | + stderr
|
|
| 50 | + (vcat (map ppr driverMsgs))
|
|
| 51 | + exitFailure
|
|
| 52 | + |
|
| 53 | +performDownsweepTurn :: Maybe ModuleGraph -> String -> Ghc ModuleGraph
|
|
| 54 | +performDownsweepTurn maybeGivenModuleGraph rootModuleName = do
|
|
| 55 | + target <- guessTarget rootModuleName Nothing Nothing
|
|
| 56 | + setTargets [target]
|
|
| 57 | + session <- getSession
|
|
| 58 | + (driverMsgs, resultingModuleGraph)
|
|
| 59 | + <- liftIO $ downsweep session
|
|
| 60 | + mkUnknownDiagnostic
|
|
| 61 | + Nothing
|
|
| 62 | + []
|
|
| 63 | + maybeGivenModuleGraph
|
|
| 64 | + []
|
|
| 65 | + False
|
|
| 66 | + liftIO $ handleDriverMessages driverMsgs
|
|
| 67 | + return resultingModuleGraph
|
|
| 68 | + |
|
| 69 | +outputModuleNamesInGraph :: ModuleGraph -> IO ()
|
|
| 70 | +outputModuleNamesInGraph = mgModSummaries >>>
|
|
| 71 | + map (ms_mod >>> moduleName >>> moduleNameString) >>>
|
|
| 72 | + sort >>>
|
|
| 73 | + print
|
|
| 74 | + |
|
| 75 | +main :: IO ()
|
|
| 76 | +main = do
|
|
| 77 | + libDir : otherArgs <- getArgs
|
|
| 78 | + runGhc (Just libDir) $ withSimpleErrorHandler $ do
|
|
| 79 | + |
|
| 80 | + -- Setup
|
|
| 81 | + logger <- getLogger
|
|
| 82 | + originalDynFlags <- getSessionDynFlags
|
|
| 83 | + (finalDynFlags, _, _)
|
|
| 84 | + <- parseDynamicFlags logger originalDynFlags $
|
|
| 85 | + map noLoc (["-i", "-i" ++ sourceDirectory] ++ otherArgs)
|
|
| 86 | + _ <- setSessionDynFlags finalDynFlags
|
|
| 87 | + |
|
| 88 | + -- Turn 1: From scratch, using 'A' as root
|
|
| 89 | + moduleGraph1 <- performDownsweepTurn Nothing "A"
|
|
| 90 | + liftIO $ outputModuleNamesInGraph moduleGraph1
|
|
| 91 | + |
|
| 92 | + -- Turn 2: From scratch, using 'X' as root
|
|
| 93 | + -- NOTE: 'A' is not included, because it is not reachable.
|
|
| 94 | + moduleGraph2 <- performDownsweepTurn Nothing "X"
|
|
| 95 | + liftIO $ outputModuleNamesInGraph moduleGraph2
|
|
| 96 | + |
|
| 97 | + -- Deletion of the source files used in turn 1
|
|
| 98 | + _ <- liftIO $
|
|
| 99 | + mapM_ (((sourceDirectory ++ "/") ++) >>> (++ ".hs") >>> removeFile)
|
|
| 100 | + ["A", "B", "C", "D"]
|
|
| 101 | + |
|
| 102 | + -- Turn 3: Based on the result of turn 1, using 'X' as root
|
|
| 103 | + -- NOTE: 'A' is included, because the result of turn 1 contains it.
|
|
| 104 | + moduleGraph3 <- performDownsweepTurn (Just moduleGraph1) "X"
|
|
| 105 | + liftIO $ outputModuleNamesInGraph moduleGraph3 |
| 1 | +module A where
|
|
| 2 | + |
|
| 3 | +import B
|
|
| 4 | +import C |
| 1 | +module B where
|
|
| 2 | + |
|
| 3 | +import D |
| 1 | +module C where
|
|
| 2 | + |
|
| 3 | +import D |
| 1 | +module D where |
| 1 | +module X where
|
|
| 2 | + |
|
| 3 | +import Y
|
|
| 4 | +import Z |
| 1 | +module Y where
|
|
| 2 | + |
|
| 3 | +import B |
| 1 | +module Z where
|
|
| 2 | + |
|
| 3 | +import C |
| 1 | +["A","B","C","D"]
|
|
| 2 | +["B","C","D","X","Y","Z"]
|
|
| 3 | +["A","B","C","D","X","Y","Z"] |
| ... | ... | @@ -48,13 +48,13 @@ main = do |
| 48 | 48 | |
| 49 | 49 | liftIO $ do
|
| 50 | 50 | |
| 51 | - _emss <- downsweep hsc_env mkUnknownDiagnostic Nothing [] [] False
|
|
| 51 | + _emss <- downsweep hsc_env mkUnknownDiagnostic Nothing [] Nothing [] False
|
|
| 52 | 52 | |
| 53 | 53 | flushFinderCaches (hsc_FC hsc_env) (hsc_unit_env hsc_env)
|
| 54 | 54 | createDirectoryIfMissing False "mydir"
|
| 55 | 55 | renameFile "B.hs" "mydir/B.hs"
|
| 56 | 56 | |
| 57 | - (_, nodes) <- downsweep hsc_env mkUnknownDiagnostic Nothing [] [] False
|
|
| 57 | + (_, nodes) <- downsweep hsc_env mkUnknownDiagnostic Nothing [] Nothing [] False
|
|
| 58 | 58 | |
| 59 | 59 | -- If 'checkSummaryTimestamp' were to call 'addHomeModuleToFinder' with
|
| 60 | 60 | -- (ms_location old_summary) like summariseFile used to instead of
|
| ... | ... | @@ -169,7 +169,7 @@ go label mods cnd = |
| 169 | 169 | setTargets [tgt]
|
| 170 | 170 | |
| 171 | 171 | hsc_env <- getSession
|
| 172 | - (_, nodes) <- liftIO $ downsweep hsc_env mkUnknownDiagnostic Nothing [] [] False
|
|
| 172 | + (_, nodes) <- liftIO $ downsweep hsc_env mkUnknownDiagnostic Nothing [] Nothing [] False
|
|
| 173 | 173 | |
| 174 | 174 | it label $ cnd (mgModSummaries nodes)
|
| 175 | 175 |
| ... | ... | @@ -14,3 +14,10 @@ test('OldModLocation', |
| 14 | 14 | ],
|
| 15 | 15 | compile_and_run,
|
| 16 | 16 | ['-package ghc'])
|
| 17 | + |
|
| 18 | +test('IncrementalDownsweep',
|
|
| 19 | + [ extra_files(['IncrementalDownsweep.modules/'])
|
|
| 20 | + , extra_run_opts('"' + config.libdir + '"')
|
|
| 21 | + ],
|
|
| 22 | + compile_and_run,
|
|
| 23 | + ['-package ghc']) |
| ... | ... | @@ -67,7 +67,7 @@ main = do |
| 67 | 67 | keyC = msKey msC
|
| 68 | 68 | |
| 69 | 69 | let mkGraph s = do
|
| 70 | - ([], nodes) <- downsweepFromRootNodes hsc_env mempty [] True DownsweepUseFixed s []
|
|
| 70 | + ([], nodes) <- downsweepFromRootNodes hsc_env mempty Nothing [] True DownsweepUseFixed s []
|
|
| 71 | 71 | return $ mkModuleGraph nodes
|
| 72 | 72 | |
| 73 | 73 | graph <- liftIO $ mkGraph [ModuleNodeCompile msC]
|
| 1 | +module Main where
|
|
| 2 | + |
|
| 3 | +main :: IO ()
|
|
| 4 | +main = print $ sum $ map bitcount [0, 4 .. 2 ^ (24 :: Int) - 1]
|
|
| 5 | + |
|
| 6 | +bitcount :: Int -> Int
|
|
| 7 | +bitcount x =
|
|
| 8 | + if x > 0
|
|
| 9 | + then let (d, m) = divMod x 2 in bitcount d + m
|
|
| 10 | + else 0 |
| 1 | +46137344 |
| ... | ... | @@ -30,6 +30,13 @@ test('T10359', |
| 30 | 30 | compile_and_run,
|
| 31 | 31 | ['-O'])
|
| 32 | 32 | |
| 33 | +test('T11226',
|
|
| 34 | + [collect_runtime_residency(10),
|
|
| 35 | + only_ways(['normal'])
|
|
| 36 | + ],
|
|
| 37 | + compile_and_run,
|
|
| 38 | + ['-O2'])
|
|
| 39 | + |
|
| 33 | 40 | test('T14955',
|
| 34 | 41 | [collect_stats('bytes allocated',5),
|
| 35 | 42 | only_ways(['normal'])
|