[Git][ghc/ghc][wip/romes/origin-global-break-action] 2 commits: Global break action which uses a per-thread context map
by Rodrigo Mesquita (@alt-romes) 30 Nov '26
by Rodrigo Mesquita (@alt-romes) 30 Nov '26
30 Nov '26
Rodrigo Mesquita pushed to branch wip/romes/origin-global-break-action at Glasgow Haskell Compiler / GHC
Commits:
b6308b7b by Rodrigo Mesquita at 2026-11-30T11:36:42+00:00
Global break action which uses a per-thread context map
Previously, everytime an expression was run in the interpreter (`sandboxIO`):
1) the RTS global variable `rts_breakpoint_io_action`, which is run
anytime any thread hits a breakpoint, got set to a new action that:
a) Wrote the breakpoint hit by the thread to the `statusMVar`
b) Blocked waiting on a newly created MVar `breakMVar` for a `resumeStmt` to
signal it.
2) Start the expression evaluation on a new "sandbox" thread
3) Block waiting on `statusMVar` for a breakpoint to be hit, and we'd
return the read `EvalBreak`
4) Set the `rts_breakpoint_io_action` to a no-op which prints "Ignored breakpoint..."
At some later point, we could `resumeStmt` with the `EvalBreak` context
by signaling the `breakMVar` on which the thread that hit the breakpoint
is blocked.
However, if you consider an expression which forks off threads which hit
breakpoints, surprising things may happen:
main = do
-- the `worker` code has a breakpoint
mapM (forkIO . worker) [1..10]
forever $ threadDelay 10000000
Interpreting this program, we'll do (1,2,3), and all workers will hit
their breakpoint and run `rts_breakpoint_io_action`. Here's a first
issue:
1. The first worker succeeds in `putMVar statusMVar`
2. The interpreter will read `takeMVar statusMVar` (3) and then (4)
3. The remaining workers are hitting the breakpoint concurrently:
- Some may block trying to `putMVar statusMVar`
- Some may run the no-op action which discards the breakpoint
Depending on whether the remaining workers hit the breakpoint or (4)
happens first, some workers will skip their breakpoint.
Now, let's pretend all workers can block on `putMVar statusMVar`. Since
the interpreter will take the breakpoints one by one, and resume them
one by one, it seemingly works. However, that's only fine when we assume
only one expression is evaluated at once. As soon as multiple
expressions can be evaluated at once (a desireable property of a
debugger, as well as something that can already happen today in some
scenarios (see `break049`)), it becomes madness:
The second issue comes the global break action being swapped by a second
evaluation and threads from the first evaluation running the "wrong" action.
Consider:
1. eval `expr_A` installs a break action that puts on `statusMVar_A`
2. `expr_A` forks off a few threads, they're running in the background
3. eval `expr_B` sets the break action to put on `statusMVar_B`
4. the `expr_A` forked threads hit a breakpoint and put `statusMVar_B`
5. `expr_B` returns with a breakpoint of `expr_A`, `resume expr_B` would
resume `expr_A`, etc...
A third issue with having a single MVar for all threads of an execution
is that there is no way to have fine-grained control over which threads
are resumed and which are stopped. This is often necessary to debug
multi-threaded programs too.
Therefore, it is imperative that the global break action does not
capture a global single MVar when many expressions with many
corresponding threads can be running in the interpreter/debugger at
once, if we want to support debugging multi-threaded programs at all.
---
This commit fixes these foundational issues by making the global break
action truly global (i.e. never modified and never capturing any locals).
The global break action is installed once in `sandboxIO` and never
removed (`withBreakAciton` and `noBreakAction` were killed). Subsequent
runs of `sandboxIO` re-rewrite the same break action (a no-op).
When any thread hits the global break action, it looks its `ThreadId` up
in the global per-thread context mapping, returning a `ResumeContext`
which contains that thread's `breakMVar` (now `resumeBreakVar`) and
`statusMVar` (now `resumeEvalStatus`). Each thread blocks on its own
MVar and replies on its own TVar. There is no longer one global status
nor break MVar.
To resume a thread by its `ThreadId`, we can simply fetch its
`ResumeContext` and signal the corresponding `resumeBreakMVar`
To wait for a result or for a breakpoint in a specific thread, we do
`readThreadEvalStatus`. To wait for any breakpoint hit in any thread at
all, we have `readAnyThreadEvalBreak`.
Some evaluations will only care to look at their own result and breaks
(so they run with `readAllBreaks` `= False`); and the main thread of an
evaluation should not be read by other evaluations. In short, only
threads forked off by the main thread of evaluations get read with
`readAnyThreadEvalBreak`. If two evaluations fork off threads in the
background, `readAnyThreadEvalBreak` may return threads from any of
them. There is no just way to distinguish their "parents" at runtime.
For instance, `compileParsedExprRemote` should run an expression until
completion without any existing threads interfering with its execution,
so it runs with `readAllBreaks = False`. Otherwise, by default, running
`main` on the REPL, we'll want to stop at any break any forked thread
hits, just like we did before.
P.S. Currently, we need to keep track of the "main expression thread"
being currently evaluated to fetch its result, but, when `evalStmt`
becomes asynchronous by returning the `ThreadId` of the "sandbox"
thread, the whole `evaluationMainThreadGlobalVar` hack can be deleted.
---
New tests observing behavior that we don't want to break (which I broke
at some point while developing this patch):
- break032: we don't stop at breakpoints in TH
- break033: :continue after -fbreak-on-exception doesn't hit exception breakpoint
- break034: test :abandon doesn't hang with -fbreak-on-error
- conc033: also run with the external interpreter
- ForceInterrupt(Ext): ^C during :force interrupts the forced expression
- break043: :continue of a forked thread reads main thread breaks/results too
- break046: evaluating expr while stopped doesn't change what :continue resumes
- break048: evaluating expr while forked thread is stopped doesn't hit again current breakpoint
New tests that failed before this commit:
- T3171(ext)nosandbox: T3171 with -fno-ghci-sandbox (T3171extnosandbox still fails)
- break050(ext): ^C during :continue of a forked thread interrupts that thread
Fixed ext-interp bc. resumeStmt now does unsafeUnmask, just like
sandboxIO, so the UserInterrupt reaches the resume.
- break049: breakpoints in forked threads don't get mixed up with other evaluations
This test demonstrates one way multi-threaded debugging can go wrong
bc the global break action used to capture a break MVar for a
specific thread that is shared by all threads (described above as
"the second issue"). Here is the annotated execution of the test
*before this commit*:
```haskell
ghci> main
Stopped in Main.inMain, break049.hs:30:12-18
_result :: IO () = _
[break049.hs:30:12-18] ghci> :force slow
-- ANN: the breakpoint we're ignoring on :force is the worker's
-- breakpoint, and it's just discarded
*** Ignoring breakpoint [break049.hs:27:14-20]
slow = 5
[break049.hs:30:12-18] ghci> :cmd return ""
-- ANN: we :continue `main`, but the worker should still be blocked
-- so `main` should block.
[break049.hs:30:12-18] ghci> :continue
-- ANN: however, it completes; recall the worker break was ignored
-- instead of stopping there
main done
-- ANN: after this commit, the worker break wouldn't have been read
-- by `:force`, and we'd see it when resuming `:main`, and
-- `:continue` here would resume the worker and only then main would
-- complete.
ghci> :continue
-- ANN: bc this is ghci before the commit, we see:
not stopped at a breakpoint
ghci>
```
- break042: main forks workers and all workers hit a breakpoint
This test witnesses "the first issue" described above, where the
workers hit breaks after the global break action was already removed
and so are lost.
Fixes #28124
- - - - -
31f4f82e by Rodrigo Mesquita at 2026-11-30T11:36:42+00:00
ci: unset CI_COMMIT_MESSAGE to avoid Windows environment length limits
The previous commit consistently made the Windows runner fail with:
> find: The environment is too large for exec().
GitLab sets these environment variables by default, but we never read
them. Just unset them at the start.
- - - - -
53 changed files:
- .gitlab/ci.sh
- + changelog.d/28124
- compiler/GHC/Driver/Config.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Runtime/Eval/Types.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Tc/Gen/Splice.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Run.hs
- + libraries/ghci/GHCi/Run/Breakpoints.hs
- libraries/ghci/ghci.cabal.in
- rts/Interpreter.c
- testsuite/tests/concurrent/should_run/all.T
- testsuite/tests/ghci.debugger/scripts/Makefile
- testsuite/tests/ghci.debugger/scripts/T14690.stdout
- testsuite/tests/ghci.debugger/scripts/all.T
- testsuite/tests/ghci.debugger/scripts/break024.stdout
- + testsuite/tests/ghci.debugger/scripts/break032.hs
- + testsuite/tests/ghci.debugger/scripts/break032.script
- + testsuite/tests/ghci.debugger/scripts/break032.stdout
- + testsuite/tests/ghci.debugger/scripts/break033.hs
- + testsuite/tests/ghci.debugger/scripts/break033.script
- + testsuite/tests/ghci.debugger/scripts/break033.stdout
- + testsuite/tests/ghci.debugger/scripts/break034.hs
- + testsuite/tests/ghci.debugger/scripts/break034.script
- + testsuite/tests/ghci.debugger/scripts/break034.stdout
- + testsuite/tests/ghci.debugger/scripts/break042.hs
- + testsuite/tests/ghci.debugger/scripts/break042.script
- + testsuite/tests/ghci.debugger/scripts/break042.stderr
- + testsuite/tests/ghci.debugger/scripts/break042.stdout
- + testsuite/tests/ghci.debugger/scripts/break043.hs
- + testsuite/tests/ghci.debugger/scripts/break043.script
- + testsuite/tests/ghci.debugger/scripts/break043.stdout
- + testsuite/tests/ghci.debugger/scripts/break046.hs
- + testsuite/tests/ghci.debugger/scripts/break046.script
- + testsuite/tests/ghci.debugger/scripts/break046.stdout
- + testsuite/tests/ghci.debugger/scripts/break048.hs
- + testsuite/tests/ghci.debugger/scripts/break048.script
- + testsuite/tests/ghci.debugger/scripts/break048.stdout
- + testsuite/tests/ghci.debugger/scripts/break049.hs
- + testsuite/tests/ghci.debugger/scripts/break049.script
- + testsuite/tests/ghci.debugger/scripts/break049.stdout
- + testsuite/tests/ghci.debugger/scripts/break050.hs
- + testsuite/tests/ghci.debugger/scripts/break050.script
- + testsuite/tests/ghci.debugger/scripts/break050.stdout
- + testsuite/tests/ghci.debugger/scripts/break050ext.stdout
- + testsuite/tests/ghci/should_run/ForceInterrupt.script
- + testsuite/tests/ghci/should_run/ForceInterrupt.stdout
- + testsuite/tests/ghci/should_run/ForceInterruptExt.stdout
- testsuite/tests/ghci/should_run/Makefile
- + testsuite/tests/ghci/should_run/T3171extnosandbox.stdout
- + testsuite/tests/ghci/should_run/T3171nosandbox.stdout
- testsuite/tests/ghci/should_run/all.T
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/04b20eca3f17529a0cdb2814053aa0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/04b20eca3f17529a0cdb2814053aa0…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/fendor/one-shot-no-eps] Experiment with separate table types for inOneShot mode
by Hannes Siebenhandl (@fendor) 30 Nov '26
by Hannes Siebenhandl (@fendor) 30 Nov '26
30 Nov '26
Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC
Commits:
232bc7bf by Hannes Siebenhandl at 2026-11-30T12:32:50+01:00
Experiment with separate table types for inOneShot mode
- - - - -
9 changed files:
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main/Hsc.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Unit/Home/PackageTable.hs
- ghc/GHCi/Leak.hs
Changes:
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -102,7 +102,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
logger = hsc_logger hsc_env
unit_env = hsc_unit_env hsc_env
extra_vars = interactiveInScope (hsc_IC hsc_env)
- home_pkg_rules = hugRulesBelow hsc_env (moduleUnitId mod)
+ home_pkg_rules = hugRulesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) (moduleUnitId mod)
(GWIB { gwib_mod = moduleName mod, gwib_isBoot = NotBoot })
name_ppr_ctx = mkNamePprCtx ptc unit_env rdr_env
ptc = initPromotionTickContext dflags
=====================================
compiler/GHC/Driver/Env.hs
=====================================
@@ -99,6 +99,7 @@ import Data.IORef
import qualified Data.Set as Set
import GHC.Types.Name.Reader (ExactRdrName(..))
import qualified GHC.Unit.Home.PackageTable as HomePackageTable
+import qualified GHC.Unit.Home.PackageTable as HPT
runHsc :: HscEnv -> Hsc a -> IO a
runHsc hsc_env hsc = do
@@ -259,26 +260,26 @@ hscUIC hsc_env = ue_uic (hsc_unit_env hsc_env)
-- | Find all rules in modules that are in the transitive closure of the given
-- module.
-hugRulesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
-hugRulesBelow hsc_env uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
- hugSomeThingsBelowUs (md_rules . hm_details) False hsc_env uid mn
+hugRulesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
+hugRulesBelow mg hug uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
+ hugSomeThingsBelowUs (md_rules . hm_details) False mg hug uid mn
-- | Get annotations from all modules "below" this one (in the dependency
-- sense) within the home units. If the module is @Nothing@, returns /all/
-- annotations in the home units.
-hugAnnsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
-hugAnnsBelow hsc_env uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
- hugSomeThingsBelowUs (md_anns . hm_details) False hsc_env uid mn
+hugAnnsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
+hugAnnsBelow mg hug uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
+ hugSomeThingsBelowUs (md_anns . hm_details) False mg hug uid mn
-- | Find all COMPLETE pragmas in modules that are in the transitive closure of the
-- given module.
-hugCompleteSigsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
-hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$>
- hugSomeThingsBelowUs (md_complete_matches . hm_details) False hsc uid mn
+hugCompleteSigsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
+hugCompleteSigsBelow mg hug uid mn = foldr (++) [] <$>
+ hugSomeThingsBelowUs (md_complete_matches . hm_details) False mg hug uid mn
-- | Find instances visible from the given set of imports
-hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
-hugInstancesBelow hsc_env uid mnwib = do
+hugInstancesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
+hugInstancesBelow mg hug uid mnwib = do
let mn = mkModule uid (gwib_mod mnwib)
(insts, famInsts) <-
unzip . concat <$>
@@ -289,7 +290,8 @@ hugInstancesBelow hsc_env uid mnwib = do
then []
else [(md_insts details, md_fam_insts details)])
True -- Include -hi-boot
- hsc_env
+ mg
+ hug
uid
mnwib
return (foldl' unionInstEnv emptyInstEnv insts, concat famInsts)
@@ -297,17 +299,18 @@ hugInstancesBelow hsc_env uid mnwib = do
-- | Get things from modules in the transitive closure of the given module.
--
-- Note: Don't expose this function. This is a footgun if exposed!
-hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
+hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
-- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk
-- These things are currently stored in the EPS for home packages. (See #25795 for
-- progress in removing these kind of checks; and making these functions of
-- `UnitEnv` rather than `HscEnv`)
-- See Note [The ModuleGraph]
-hugSomeThingsBelowUs _ _ hsc_env _ _ | isOneShot (ghcMode (hsc_dflags hsc_env)) = return []
-hugSomeThingsBelowUs extract include_hi_boot hsc_env uid mn
- = let hug = hsc_HUG hsc_env
- mg = hsc_mod_graph hsc_env
- in
+hugSomeThingsBelowUs extract include_hi_boot mg hug uid mn =
+ -- If the first hpt is a one-shot table, we don't recurse into it.
+ -- TODO @fendor: I guess that's nonsense to a certain degree
+ if HPT.isOneShotMode $ homeUnitEnv_hpt $ unitEnv_lookup uid hug
+ then pure []
+ else
sequence
[ things
-- "Finding each non-hi-boot module below me" maybe could be cached (well,
@@ -347,7 +350,7 @@ prepareAnnotations hsc_env mb_guts = do
-- entries regardless of dependency ordering.
get_mod mg = (moduleUnitId (mg_module mg), GWIB (moduleName (mg_module mg)) NotBoot)
home_pkg_anns <- fromMaybe (hugAllAnns (hsc_unit_env hsc_env))
- $ uncurry (hugAnnsBelow hsc_env)
+ $ uncurry (hugAnnsBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env))
. get_mod <$> mb_guts
more_home_pkg_anns <- HomePackageTable.hptLoadedAnnEnv $ hsc_HPT hsc_env
let
=====================================
compiler/GHC/Driver/Main/Hsc.hs
=====================================
@@ -107,7 +107,10 @@ import System.IO
newHscEnv :: FilePath -> DynFlags -> IO HscEnv
newHscEnv top_dir dflags = do
- hpt <- emptyHomePackageTable
+ hpt <- case ghcMode dflags of
+ OneShot -> emptyOnDemandHomePackageTable
+ CompManager -> emptyHomePackageTable
+ MkDepend -> emptyHomePackageTable
newHscEnvWithHUG top_dir dflags (homeUnitId_ dflags) (home_unit_graph hpt)
where
home_unit_graph hpt = HUG.unitEnv_singleton
=====================================
compiler/GHC/Iface/Load.hs
=====================================
@@ -100,66 +100,65 @@ import GHC.Builtin.PrimOps.Ids
import GHC.Builtin.WiredIn.Prim
import GHC.Builtin.WiredIn.Ids( seqId )
+import GHC.Core (CoreRule)
+import GHC.Core.FamInstEnv
+import GHC.Core.InstEnv
import GHC.Core.Rules
import GHC.Core.TyCon
-import GHC.Core.InstEnv
-import GHC.Core.FamInstEnv
-import GHC.Parser.Annotation( noLocA, noAnn )
+import GHC.Parser.Annotation (noAnn, noLocA)
import GHC.Types.Annotations
+import GHC.Types.Avail
+import GHC.Types.DefaultEnv (DefaultEnv)
+import GHC.Types.Fixity
+import GHC.Types.Fixity.Env
import GHC.Types.Id
import GHC.Types.Name
import GHC.Types.Name.Cache
import GHC.Types.Name.Env
import GHC.Types.Name.Reader
-import GHC.Types.Avail
-import GHC.Types.Fixity
-import GHC.Types.Fixity.Env
+import GHC.Types.PkgQual
+import GHC.Types.SafeHaskell
import GHC.Types.SourceError
import GHC.Types.SourceFile
-import GHC.Types.SafeHaskell
-import GHC.Types.TypeEnv
-import GHC.Types.Unique.DSet
-import GHC.Types.Unique.Map( listToUniqMap )
-import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM, elemUFM )
+import GHC.Types.SourceText
import GHC.Types.SrcLoc
import GHC.Types.TyThing
-import GHC.Types.PkgQual
-import GHC.Types.SourceText
+import GHC.Types.TypeEnv
+import GHC.Types.Unique.DSet
+import GHC.Types.Unique.FM (UniqFM, elemUFM, listToUFM, lookupUFM)
+import GHC.Types.Unique.Map (listToUniqMap)
+import GHC.Unit.Env
import GHC.Unit.External
+import GHC.Unit.Finder
+import GHC.Unit.Home
+import GHC.Unit.Home.Graph qualified as HUG
+import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable)
+import GHC.Unit.Home.PackageTable
+import GHC.Unit.Home.PackageTable qualified as HomePackageTable
import GHC.Unit.Module
+import GHC.Unit.Module.Deps
import GHC.Unit.Module.Graph
-import GHC.Unit.Module.Warnings
+import GHC.Unit.Module.ModDetails (ModDetails (..))
import GHC.Unit.Module.ModIface
-import GHC.Unit.Module.Deps
+import GHC.Unit.Module.Warnings
import GHC.Unit.State
-import GHC.Unit.Home
-import qualified GHC.Unit.Home.Graph as HUG
-import GHC.Unit.Home.PackageTable
-import GHC.Unit.Finder
-import GHC.Unit.Env
import GHC.Stack( callStack )
import GHC.Data.Maybe
import Language.Haskell.Syntax.Lit (StringLiteral(..))
+import Control.Applicative ((<|>))
import Control.Monad
-import qualified Data.Foldable as Foldable
+import Data.Foldable qualified as Foldable
import Data.Function ((&))
-import Data.Map ( toList )
-import qualified Data.Set as Set
-import System.FilePath
+import Data.Map (toList)
+import Data.Set qualified as Set
import System.Directory
-import GHC.Types.DefaultEnv (DefaultEnv)
-import GHC.Core (CoreRule)
-import GHC.Unit.Module.ModDetails (ModDetails(..))
-import GHC.Unit.Home.ModInfo (HomeModInfo(..), emptyHomeModInfoLinkable)
-import qualified Data.Set as Set
-import qualified GHC.Unit.Home.PackageTable as HomePackageTable
-import Control.Applicative ((<|>))
+import System.FilePath
{- *********************************************************************
@@ -799,8 +798,8 @@ loadInterface doc_str mod from
-- READ THE MODULE IN
; hpt <- getHpt
- ; hls <- liftIO (hptLoaderState hpt)
- ; read_result <- case wantHiBootFile mhome_unit hls mod from of
+ ; is_boot_map <- liftIO (hptLoadedIsBoot hpt)
+ ; read_result <- case wantHiBootFile mhome_unit is_boot_map mod from of
Failed err -> return (Failed err)
Succeeded hi_boot_file -> do
hsc_env <- getTopEnv
@@ -836,7 +835,7 @@ loadInterface doc_str mod from
massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
(text "Attempting to non-home package interface into the Home Loader State" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
tcParts <- tcPartsOfTheIface mod iface
- addModIfacePartsToHpt gbl_env mod loc iface tcParts
+ addModIfacePartsToHpt gbl_env mod iface tcParts
else dontLeakTheHUG $ do
-- Load the new ModIface into the External Package State
--
@@ -868,37 +867,36 @@ loadInterface doc_str mod from
tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches)
tcPartsOfTheIface mod iface = do
- ignore_prags <- goptM Opt_IgnoreInterfacePragmas
- new_eps_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
- new_eps_insts <- mapM tcIfaceInst (mi_insts iface)
- new_eps_defaults <- tcIfaceDefaults mod (mi_defaults iface)
- new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
- new_eps_rules <- tcIfaceRules ignore_prags (mi_rules iface)
- new_eps_anns <- tcIfaceAnnotations (mi_anns iface)
- new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
+ ignore_prags <- goptM Opt_IgnoreInterfacePragmas
+ new_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
+ new_insts <- mapM tcIfaceInst (mi_insts iface)
+ new_defaults <- tcIfaceDefaults mod (mi_defaults iface)
+ new_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
+ new_rules <- tcIfaceRules ignore_prags (mi_rules iface)
+ new_anns <- tcIfaceAnnotations (mi_anns iface)
+ new_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
pure
- ( new_eps_decls
- , new_eps_insts
- , new_eps_defaults
- , new_eps_fam_insts
- , new_eps_rules
- , new_eps_anns
- , new_eps_complete_matches
+ ( new_decls
+ , new_insts
+ , new_defaults
+ , new_fam_insts
+ , new_rules
+ , new_anns
+ , new_complete_matches
)
-addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
-addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
- hsc_env <- getTopEnv
+addModIfacePartsToHpt :: IfGblEnv -> Module -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
+addModIfacePartsToHpt gbl_env mod iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
let
details = ModDetails
- { md_types = mkNameEnv new_eps_decls
+ { md_types = mkNameEnv new_decls
, md_exports = mi_exports iface
- , md_defaults = new_eps_defaults
- , md_insts = mkInstEnv new_eps_insts
- , md_fam_insts = new_eps_fam_insts
- , md_rules = new_eps_rules
- , md_anns = new_eps_anns
- , md_complete_matches = new_eps_complete_matches
+ , md_defaults = new_defaults
+ , md_insts = mkInstEnv new_insts
+ , md_fam_insts = new_fam_insts
+ , md_rules = new_rules
+ , md_anns = new_anns
+ , md_complete_matches = new_complete_matches
}
bad_boot = mi_boot iface == IsBoot
@@ -909,16 +907,11 @@ addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e
warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
hpt <- getHpt
- -- Create an IO action that loads and compiles bytecode from Core
- -- bindings.
- --
- -- See Note [Interface Files with Core Definitions]
- let lazy_bytecode = loadIfaceByteCode hsc_env iface loc (mkNameEnv new_eps_decls)
liftIO $ addHomeModInfoToHpt (HomeModInfo iface details emptyHomeModInfoLinkable) hpt
- liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) lazy_bytecode
+ liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches)
addModIfacePartsToEps :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
-addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
+addModIfacePartsToEps gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
purged_hsc_env <- getTopEnv
let
@@ -942,7 +935,7 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e
--
-- See Note [Interface Files with Core Definitions]
add_bytecode old
- | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
+ | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_decls)
= extendModuleEnv old mod action
-- Don't add an entry if the iface doesn't have 'extra_decls'
-- so 'get_link_deps' knows that it should load object code.
@@ -956,36 +949,36 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e
then eps
else if bad_boot
-- See Note [Loading your own hi-boot file]
- then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
+ then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_decls }
else
eps {
eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
- eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
+ eps_PTE = addDeclsToPTE (eps_PTE eps) new_decls,
eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
eps_rule_base = extendRuleBaseList (eps_rule_base eps)
- new_eps_rules,
+ new_rules,
eps_complete_matches
- = eps_complete_matches eps ++ new_eps_complete_matches,
+ = eps_complete_matches eps ++ new_complete_matches,
eps_inst_env = extendInstEnvList (eps_inst_env eps)
- new_eps_insts,
+ new_insts,
eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
- new_eps_fam_insts,
+ new_fam_insts,
eps_ann_env = extendAnnEnvList (eps_ann_env eps)
- new_eps_anns,
+ new_anns,
eps_mod_fam_inst_env
= let
fam_inst_env =
extendFamInstEnvList emptyFamInstEnv
- new_eps_fam_insts
+ new_fam_insts
in
extendModuleEnv (eps_mod_fam_inst_env eps)
mod
fam_inst_env,
eps_stats = addEpsInStats (eps_stats eps)
- (length new_eps_decls)
- (length new_eps_insts)
- (length new_eps_rules),
- eps_defaults = extendModuleEnv (eps_defaults eps) mod new_eps_defaults
+ (length new_decls)
+ (length new_insts)
+ (length new_rules),
+ eps_defaults = extendModuleEnv (eps_defaults eps) mod new_defaults
}
@@ -1204,10 +1197,10 @@ moduleFreeHolesPrecise doc_str mod
return (Succeeded (renameFreeHoles ifhs insts))
Failed err -> return (Failed err)
-wantHiBootFile :: Maybe HomeUnit -> HomeLoaderState -> Module -> WhereFrom
+wantHiBootFile :: Maybe HomeUnit -> InstalledModuleEnv ModuleNameWithIsBoot -> Module -> WhereFrom
-> MaybeErr MissingInterfaceError IsBootInterface
-- Figure out whether we want Foo.hi or Foo.hi-boot
-wantHiBootFile mhome_unit hls mod from
+wantHiBootFile mhome_unit is_boot_map mod from
= case from of
ImportByUser usr_boot
| usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
@@ -1226,9 +1219,9 @@ wantHiBootFile mhome_unit hls mod from
-- We never import boot modules from other packages!
| otherwise
- -> case hlsIsBoot hls (toUnitId <$> mod) of
- Just is_boot ->
- Succeeded is_boot
+ -> case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
+ Just mnib ->
+ Succeeded $ gwib_isBoot mnib
Nothing ->
Succeeded NotBoot
-- The boot-ness of the requested interface,
=====================================
compiler/GHC/Iface/Recomp.hs
=====================================
@@ -427,10 +427,9 @@ checkVersions hsc_env mod_summary iface self_recomp
-- (in which case we are done with this module) or it'll fail (in which
-- case we'll compile the module from scratch anyhow).
- when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
- ; hpt <- getHpt
- ; liftIO $ hlsSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
- }
+ ; hpt <- getHpt
+ ; liftIO $ hptSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
+
; recomp <- checkList [checkModUsage (hsc_FC hsc_env) u
| u <- mi_sr_usages self_recomp]
; case recomp of (NeedsRecompile reason) -> return $ OutOfDateItem reason (Just iface) ; _ -> do {
=====================================
compiler/GHC/IfaceToCore.hs
=====================================
@@ -633,12 +633,12 @@ tcHiBootIface hsc_src mod
-- a SOURCE import) or that our hi-boot file has mysteriously
-- disappeared.
do { hpt <- getHpt
- ; hls <- liftIO $ hptLoaderState hpt
- ; case hlsIsBoot hls (toUnitId <$> mod) of
+ ; is_boot_map <- liftIO $ hptLoadedIsBoot hpt
+ ; case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
-- The typical case
Nothing -> return NoSelfBoot
-- error cases
- Just is_boot -> case is_boot of
+ Just mnib -> case gwib_isBoot mnib of
IsBoot ->
let diag = Can'tFindInterface err
(LookingForHiBoot mod)
=====================================
compiler/GHC/Tc/Module.hs
=====================================
@@ -191,7 +191,7 @@ import qualified Data.Map as M
import Data.Foldable ( for_ )
import Data.Traversable ( for )
import Data.IORef( newIORef )
-import GHC.Unit.Home.PackageTable (hlsSetBootInfo)
+import GHC.Unit.Home.PackageTable (hptSetBootInfo)
{-
************************************************************************
@@ -501,21 +501,19 @@ tcRnImports hsc_env import_decls
-- modules batch (@--make@) compiled before this one, but
-- which are not below this one.
; (home_insts, home_fam_insts) <- liftIO $
- hugInstancesBelow hsc_env unitId mnwib
+ hugInstancesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib
-- We use 'unsafeInterleaveIO' to avoid redundant memory allocations
-- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad
-- and see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14274#note_620545
; completeSigsBelow <- liftIO $ unsafeInterleaveIO $
- hugCompleteSigsBelow hsc_env unitId mnwib
+ hugCompleteSigsBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib
- -- Record boot-file info in the EPS, so that it's
+ -- Record boot-file info in the HPT, so that it's
-- visible to loadHiBootInterface in tcRnSrcDecls,
-- and any other incrementally-performed imports
- ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
- ; hpt <- getHpt
- ; liftIO $ hlsSetBootInfo hpt (imp_boot_mods imports)
- }
+ ; hpt <- getHpt
+ ; liftIO $ hptSetBootInfo hpt (imp_boot_mods imports)
-- Update the gbl env
; updGblEnv ( \ gbl ->
=====================================
compiler/GHC/Unit/Home/PackageTable.hs
=====================================
@@ -21,13 +21,17 @@
-- Or, do you really need a function to traverse all modules in the HPT? It is
-- often better to keep the computation internal to this module, such as in
-- 'hptCollectObjects'...
+{-# OPTIONS_GHC -Wall -Wincomplete-record-selectors #-}
module GHC.Unit.Home.PackageTable
(
HomePackageTable(..)
, emptyHomePackageTable
+ , emptyOnDemandHomePackageTable
- , HomeLoaderState -- TODO: should this be opaque? Probably
- , emptyHomeLoaderState
+ , isOneShotMode
+
+ -- , HomeLoaderState -- TODO: should this be opaque? Probably
+ -- , emptyHomeLoaderState
-- * Lookups in the HPT
, lookupHpt
@@ -42,13 +46,14 @@ module GHC.Unit.Home.PackageTable
, restrictHpt
-- * Queries about home modules
+ , listHptIfaces
, hptCompleteSigs
, hptAllInstances
, hptAllFamInstances
, hptAllAnnotations
, hlsIsModuleNameWithBoot
, hlsIsBoot
- , hlsSetBootInfo
+ , hptSetBootInfo
, hptLoadedIsBoot
, hptLoadedTypeEnv
, hptLoadedInstEnv
@@ -78,9 +83,8 @@ module GHC.Unit.Home.PackageTable
--
-- In GHC itself these should be avoided, and other uses should justify why
-- it is not sufficient to go through the intended insert-only API.
- , hptInternalTableRef
+ -- , hptInternalTableRef
, hptInternalTableFromRef
- , hptLoaderState
-- * Legacy API
--
-- | This API is deprecated and meant to be removed.
@@ -98,7 +102,6 @@ import GHC.Core.FamInstEnv
import GHC.Core.InstEnv
import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase)
import GHC.Data.Word64Set qualified as W64
-import GHC.Linker.Types (Linkable)
import GHC.Types.Annotations
import GHC.Types.CompleteMatch
import GHC.Types.TypeEnv
@@ -117,24 +120,14 @@ import GHC.Types.DefaultEnv (DefaultEnv)
import GHC.Core
-- | Helps us find information about modules in the home package
-data HomePackageTable = HPT {
+data HomePackageTable
+ = HPT_Make { table :: {-# UNPACK #-} !(IORef (DModuleNameEnv HomeModInfo)) }
+ | HPT_OneShot { loader :: {-# UNPACK #-} !(IORef HomeLoaderState) }
- table :: IORef (DModuleNameEnv HomeModInfo),
- -- ^ Domain = modules in this home unit
- --
- -- This is an IORef because we want to avoid leaking HPTs (see the particularly bad #25511).
- -- Moreover, the HPT invariant allows mutability in this table without compromising thread safety or soundness.
- -- To recall:
- -- A query to the HPT should depend only on data relevant to that query, such that
- -- there being more or less unrelated entries in the HPT does not influence the result in any way.
- --
- -- Note that the HPT increases monotonically, except at certain barrier
- -- points like when 'restrictHpt' is called. At these barriers, it is safe
- -- to temporarily violate the HPT monotonicity.
- --
- -- The elements of this table may be updated (e.g. on rehydration).
- loader :: IORef HomeLoaderState
- }
+isOneShotMode :: HomePackageTable -> Bool
+isOneShotMode = \ case
+ HPT_OneShot{} -> True
+ HPT_Make{} -> False
-- | Create a new 'HomePackageTable'.
--
@@ -145,14 +138,19 @@ emptyHomePackageTable :: IO HomePackageTable
-- romes:todo: use a MutableArray directly?
emptyHomePackageTable = do
table <- newIORef emptyUDFM
+ return HPT_Make{table}
+
+emptyOnDemandHomePackageTable :: IO HomePackageTable
+emptyOnDemandHomePackageTable = do
loader <- newIORef emptyHomeLoaderState
- return HPT{table, loader}
+ return HPT_OneShot{loader}
data HomeLoaderState = HomeLoaderState
- { hls_modules :: ModuleEnv ()
+ { hls_table :: DModuleNameEnv HomeModInfo
+ , hls_modules :: ModuleEnv ()
, hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
, hls_type_env :: !TypeEnv
- , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
+ -- , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
, hls_inst_env :: !InstEnv
, hls_fam_inst_env :: !FamInstEnv
, hls_mod_fam_inst_env :: !(ModuleEnv FamInstEnv)
@@ -165,10 +163,11 @@ data HomeLoaderState = HomeLoaderState
emptyHomeLoaderState :: HomeLoaderState
emptyHomeLoaderState =
HomeLoaderState
- { hls_modules = emptyModuleEnv
+ { hls_table = emptyUDFM
+ , hls_modules = emptyModuleEnv
, hls_is_boot = emptyInstalledModuleEnv
, hls_type_env = emptyTypeEnv
- , hls_iface_bytecode = emptyModuleEnv
+ -- , hls_iface_bytecode = emptyModuleEnv
, hls_inst_env = emptyInstEnv
, hls_fam_inst_env = emptyFamInstEnv
, hls_mod_fam_inst_env = emptyModuleEnv
@@ -184,7 +183,8 @@ emptyHomeLoaderState =
-- | Lookup the 'HomeModInfo' of a module in the HPT, given its name.
lookupHpt :: HomePackageTable -> ModuleName -> IO (Maybe HomeModInfo)
-lookupHpt HPT{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
+lookupHpt HPT_Make{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
+lookupHpt HPT_OneShot{loader=hpt} mn = (`lookupUDFM` mn) . hls_table <$!> readIORef hpt
-- | Lookup the 'HomeModInfo' of a 'Module' in the HPT.
lookupHptByModule :: HomePackageTable -> Module -> IO (Maybe HomeModInfo)
@@ -195,35 +195,45 @@ lookupHptByModule hpt mod
Just hm | mi_module (hm_iface hm) == mod -> Just hm
_otherwise -> Nothing
-hptLoaderState :: HomePackageTable -> IO HomeLoaderState
-hptLoaderState = readIORef . loader
+queryOnDemandHpt :: a -> (HomeLoaderState -> a) -> HomePackageTable -> IO a
+queryOnDemandHpt a f hpt =
+ case hpt of
+ HPT_Make{} ->
+ pure a
+ HPT_OneShot{loader} ->
+ f <$> readIORef loader
hptLoadedIsBoot :: HomePackageTable -> IO (InstalledModuleEnv ModuleNameWithIsBoot)
-hptLoadedIsBoot hpt = hls_is_boot <$> readIORef (loader hpt)
+hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot
hptLoadedTypeEnv :: HomePackageTable -> IO TypeEnv
-hptLoadedTypeEnv hpt = hls_type_env <$> readIORef (loader hpt)
+hptLoadedTypeEnv = queryOnDemandHpt emptyTypeEnv hls_type_env
hptLoadedInstEnv :: HomePackageTable -> IO InstEnv
-hptLoadedInstEnv hpt = hls_inst_env <$> readIORef (loader hpt)
+hptLoadedInstEnv = queryOnDemandHpt emptyInstEnv hls_inst_env
hptLoadedFamInstEnv :: HomePackageTable -> IO FamInstEnv
-hptLoadedFamInstEnv hpt = hls_fam_inst_env <$> readIORef (loader hpt)
+hptLoadedFamInstEnv = queryOnDemandHpt emptyFamInstEnv hls_fam_inst_env
hptLoadedModFamInstEnv :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
-hptLoadedModFamInstEnv hpt = hls_mod_fam_inst_env <$> readIORef (loader hpt)
+hptLoadedModFamInstEnv = queryOnDemandHpt emptyModuleEnv hls_mod_fam_inst_env
hptLoadedRuleBase :: HomePackageTable -> IO RuleBase
-hptLoadedRuleBase hpt = hls_rule_base <$> readIORef (loader hpt)
+hptLoadedRuleBase = queryOnDemandHpt emptyRuleBase hls_rule_base
hptLoadedAnnEnv :: HomePackageTable -> IO AnnEnv
-hptLoadedAnnEnv hpt = hls_ann_env <$> readIORef (loader hpt)
+hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv hls_ann_env
hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
-hptLoadedCompleteMatches hpt = hls_complete_matches <$> readIORef (loader hpt)
+hptLoadedCompleteMatches = queryOnDemandHpt [] hls_complete_matches
hptLoadedDefaults :: HomePackageTable -> IO (ModuleEnv DefaultEnv)
-hptLoadedDefaults hpt = hls_defaults <$> readIORef (loader hpt)
+hptLoadedDefaults = queryOnDemandHpt emptyModuleEnv hls_defaults
+
+listHptIfaces :: HomePackageTable -> IO (DModuleNameEnv HomeModInfo)
+listHptIfaces = \ case
+ HPT_Make{table} -> readIORef table
+ HPT_OneShot{loader} -> hls_table <$> readIORef loader
--------------------------------------------------------------------------------
-- * Extending the HPT
@@ -244,10 +254,12 @@ addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi)
{-# DEPRECATED addToHpt "Deprecated in favour of 'addHomeModInfoToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
-- After deprecation cycle, move `addToHpt` to a `where` clause inside `addHomeModInfoToHpt`.
addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO ()
-addToHpt HPT{table=hptr} mn hmi = do
+addToHpt HPT_Make{table=hptr} mn hmi = do
atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
-- If the key already existed in the map, this insertion is overwriting
-- the HMI of a previously loaded module (likely in rehydration).
+addToHpt HPT_OneShot{loader=hptr} mn hmi = do
+ atomicModifyIORef' hptr (\hpt -> (hpt { hls_table = addToUDFM (hls_table hpt) mn hmi }, ()))
-- | 'addHomeModInfoToHpt' for multiple module infos.
addHomeModInfosToHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
@@ -262,19 +274,21 @@ addHomeModInfosToHpt hpt = mapM_ (flip addHomeModInfoToHpt hpt)
-- called at barrier points, such as the end of upsweep, when all threads are
-- done and we want to clean up failed entries.
restrictHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
-restrictHpt HPT{table=hptr} hmis =
+restrictHpt HPT_Make{table=hptr} hmis =
let key_set = map (getKey . getUnique . hmi_mod) hmis
hmi_mod hmi = moduleName (mi_module (hm_iface hmi))
in atomicModifyIORef' hptr (\hpt -> (udfmRestrictKeysSet hpt (W64.fromList key_set), ()))
+restrictHpt HPT_OneShot{} _ = pure ()
{-# DEPRECATED addListToHpt "Deprecated in favour of 'addHomeModInfosToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
-- After deprecation cycle, remove.
addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
-addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> Maybe (IO Linkable) -> IO ()
-addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_defaults, new_hls_fam_insts, new_hls_rules, new_hls_anns, new_hls_complete_matches) bytecode = do
- atomicModifyIORef (loader hpt) $ \hls ->
+addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IO ()
+addOnDemandHomeModule HPT_Make{} _ _ _ = pure ()
+addOnDemandHomeModule HPT_OneShot{loader} mn bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
+ atomicModifyIORef loader $ \hls ->
( if mn `elemModuleEnv` hls_modules hls
then hls -- If already loaded, don't add twice
else
@@ -285,41 +299,39 @@ addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_def
)
where
addHomeModTypeEnv hls = hls
- { hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls
+ { hls_type_env = extendNameEnvList (hls_type_env hls) new_decls
}
addHomeModData hls = hls {
- hls_modules = extendModuleEnv (hls_modules hls) mn (),
- hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls,
- hls_iface_bytecode = case bytecode of
- Nothing -> hls_iface_bytecode hls
- Just bc -> extendModuleEnv (hls_iface_bytecode hls) mn bc,
+ hls_modules = extendModuleEnv (hls_modules hls) mn (),
+ hls_type_env = extendNameEnvList (hls_type_env hls) new_decls,
hls_rule_base = extendRuleBaseList (hls_rule_base hls)
- new_hls_rules,
+ new_rules,
hls_complete_matches
- = hls_complete_matches hls ++ new_hls_complete_matches,
+ = hls_complete_matches hls ++ new_complete_matches,
hls_inst_env = extendInstEnvList (hls_inst_env hls)
- new_hls_insts,
+ new_insts,
hls_fam_inst_env = extendFamInstEnvList (hls_fam_inst_env hls)
- new_hls_fam_insts,
+ new_fam_insts,
hls_ann_env = extendAnnEnvList (hls_ann_env hls)
- new_hls_anns,
+ new_anns,
hls_mod_fam_inst_env
=
let
fam_inst_env =
extendFamInstEnvList emptyFamInstEnv
- new_hls_fam_insts
+ new_fam_insts
in
extendModuleEnv (hls_mod_fam_inst_env hls)
mn
fam_inst_env,
- hls_defaults = extendModuleEnv (hls_defaults hls) mn new_hls_defaults
+ hls_defaults = extendModuleEnv (hls_defaults hls) mn new_defaults
}
-hlsSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
-hlsSetBootInfo hpt is_boot_env =
- atomicModifyIORef' (loader hpt) $ \ hls ->
+hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
+hptSetBootInfo HPT_Make{} _ = pure ()
+hptSetBootInfo HPT_OneShot{loader} is_boot_env =
+ atomicModifyIORef' loader $ \ hls ->
(hls { hls_is_boot = is_boot_env }, ())
----------------------------------------------------------------------------------
@@ -370,7 +382,11 @@ hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn
-- currently takes all dependencies only to then filter them with an ad-hoc transitive closure check.
-- See #25639
hptCollectDependencies :: HomePackageTable -> IO (Set.Set (IfaceImportLevel, UnitId))
-hptCollectDependencies HPT{table} = do
+hptCollectDependencies HPT_OneShot{loader} = do
+ hpt <- readIORef loader
+ return $
+ foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty (hls_table hpt)
+hptCollectDependencies HPT_Make{table} = do
hpt <- readIORef table
return $
foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty hpt
@@ -380,7 +396,11 @@ hptCollectDependencies HPT{table} = do
--
-- $O(n)$ in the number of modules in the HPT.
hptCollectHomeModInfo :: HomePackageTable -> IO [HomeModInfo]
-hptCollectHomeModInfo HPT{table} = do
+hptCollectHomeModInfo HPT_OneShot{loader} = do
+ hpt <- readIORef loader
+ return $
+ foldr (:) [] (hls_table hpt)
+hptCollectHomeModInfo HPT_Make{table} = do
hpt <- readIORef table
return $
foldr (:) [] hpt
@@ -398,7 +418,13 @@ hptCollectHomeModInfo HPT{table} = do
-- unit map in failed lookups.
pprHPT :: HomePackageTable -> IO SDoc
-- A bit arbitrary for now
-pprHPT HPT{table=hptr} = do
+pprHPT HPT_OneShot{loader=hptr} = do
+ hpt <- readIORef hptr
+ return $!
+ pprUDFM (hls_table hpt) $ \hms ->
+ vcat [ ppr (mi_module (hm_iface hm))
+ | hm <- hms ]
+pprHPT HPT_Make{table=hptr} = do
hpt <- readIORef hptr
return $!
pprUDFM hpt $ \hms ->
@@ -437,7 +463,12 @@ pprHPT HPT{table=hptr} = do
-- If this function is ever exposed from the HPT module, make sure the
-- argument function doesn't introduce leaks.
concatHpt :: (HomeModInfo -> [a]) -> HomePackageTable -> IO [a]
-concatHpt f HPT{table} = do
+concatHpt f HPT_OneShot{loader} = do
+ hpt <- readIORef loader
+ return $ concat . eltsUDFM . mapMaybeUDFM g $ hls_table hpt
+ where
+ g hmi = case f hmi of { [] -> Nothing; as -> Just as }
+concatHpt f HPT_Make{table} = do
hpt <- readIORef table
return $ concat . eltsUDFM . mapMaybeUDFM g $ hpt
where
@@ -449,15 +480,15 @@ concatHpt f HPT{table} = do
-- | Gets the internal 'IORef' which holds the 'HomeModInfo's of this HPT.
-- Use with care.
-hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
-hptInternalTableRef = table
+-- hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
+-- hptInternalTableRef = \ case
+-- HPT_Make{table} -> table
+-- HPT_OneShot{} -> -- TODO: @fendor how does this make sense?
-- | Construct a HomePackageTable from the IORef.
-- Use with care, only if you can really justify going around the intended insert-only API.
hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
hptInternalTableFromRef ref = do
- loader <- newIORef emptyHomeLoaderState
- return HPT {
- table = ref,
- loader
+ return HPT_Make {
+ table = ref
}
=====================================
ghc/GHCi/Leak.hs
=====================================
@@ -7,7 +7,6 @@ module GHCi.Leak
import Control.Monad
import Data.Bits
-import Data.IORef
import Foreign.Ptr (ptrToIntPtr, intPtrToPtr)
import GHC
import GHC.Ptr (Ptr (..))
@@ -43,7 +42,7 @@ data LeakModIndicators = LeakModIndicators
getLeakIndicators :: HscEnv -> IO LeakIndicators
getLeakIndicators hsc_env =
fmap LeakIndicators $ do
- hpt <- readIORef $ hptInternalTableRef $ hsc_HPT hsc_env
+ hpt <- listHptIfaces $ hsc_HPT hsc_env
forM (eltsUDFM hpt) $ \hmi@HomeModInfo{..} -> do
leakMod <- mkWeakPtr hmi Nothing
leakIface <- mkWeakPtr hm_iface Nothing
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/232bc7bf148c0c24a5c1779b355a0c0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/232bc7bf148c0c24a5c1779b355a0c0…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
Teo Camarasu pushed new branch wip/T28210 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T28210
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/mangoiv/clone-shallow-default] ci: make shallow cloning the default
by Magnus (@MangoIV) 30 Nov '26
by Magnus (@MangoIV) 30 Nov '26
30 Nov '26
Magnus pushed to branch wip/mangoiv/clone-shallow-default at Glasgow Haskell Compiler / GHC
Commits:
fed3796d by mangoiv at 2026-11-30T11:35:11+01:00
ci: make shallow cloning the default
We disabled shallow cloning because linters sometimes need deep clones.
We now clone shallowly and just enable deep cloning on lint jobs that we
know need them (see b2f106f5544e4c71bb07df4acb9d2b5ed184a7e3)
Fixes #28157
- - - - -
2 changed files:
- .gitlab-ci.yml
- testsuite/driver/perf_notes.py
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -17,8 +17,7 @@ variables:
# Bump to invalidate GitLab CI cache.
CACHE_REV: 12
- # Disable shallow clones; they break our linting rules
- GIT_DEPTH: 0
+ GIT_DEPTH: 1
# Always start with a fresh clone to avoid non-hermetic builds
GIT_STRATEGY: clone
@@ -267,6 +266,7 @@ ghc-linters:
extends: .lint-params
variables:
BUILD_FLAVOUR: default
+ GIT_DEPTH: 0
script:
- .gitlab/ci.sh configure
- timeout 10m .gitlab/ci.sh run_hadrian test --test-root-dirs="testsuite/tests/linters"
@@ -282,7 +282,6 @@ lint-changelog:
extends: .lint-ghc-toolchain
variables:
CHANGELOG_EXPECT_MR: "$CI_MERGE_REQUEST_IID"
- GIT_DEPTH: 1
GIT_SUBMODULE_STRATEGY: none
script:
- .gitlab/ci.sh lint_changelog
@@ -297,7 +296,6 @@ lint-changelog:
lint-linters:
extends: .lint-python
variables:
- GIT_DEPTH: 1
GIT_SUBMODULE_STRATEGY: none
script:
- mypy testsuite/tests/linters/regex-linters/*.py
@@ -307,7 +305,6 @@ lint-linters:
lint-testsuite:
extends: .lint-ghc-toolchain
variables:
- GIT_DEPTH: 1
GIT_SUBMODULE_STRATEGY: none
script:
- make -Ctestsuite list_broken TEST_HC=$(which ghc)
@@ -317,7 +314,6 @@ lint-testsuite:
typecheck-testsuite:
extends: .lint-python
variables:
- GIT_DEPTH: 1
GIT_SUBMODULE_STRATEGY: none
script:
- mypy testsuite/driver/runtests.py
@@ -330,6 +326,7 @@ typecheck-testsuite:
extends: .lint-params
variables:
BUILD_FLAVOUR: default
+ GIT_DEPTH: 0
GIT_SUBMODULE_DEPTH: 0 # full history
script:
- .gitlab/ci.sh configure
@@ -346,6 +343,7 @@ typecheck-testsuite:
lint-author:
extends: .lint-python
variables:
+ GIT_DEPTH: 0
GIT_SUBMODULE_STRATEGY: none
script:
- git fetch "$CI_MERGE_REQUEST_PROJECT_URL" $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
@@ -362,7 +360,6 @@ lint-ci-config:
extends: .lint
# We don't need history/submodules in this job
variables:
- GIT_DEPTH: 1
GIT_SUBMODULE_STRATEGY: none
before_script:
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
=====================================
testsuite/driver/perf_notes.py
=====================================
@@ -433,6 +433,12 @@ def baseline_commit_log(commit: Union[GitHash,GitRef]) -> List[GitHash]:
# including the input commit. The output commits are all commit hashes.
# str -> [str]
def commit_log(commitOrRange, n=None):
+ # default gitlab git cloning is shallow: for git perf notes we still need to be able
+ # to catch up on history. This unshallows the repository and fetches a blobless tree.
+ is_shallow = subprocess.check_output( ['git', 'rev-parse', '--is-shallow-repository']).decode().strip() == 'true'
+ if is_shallow:
+ subprocess.check_call(['git', 'fetch', '--unshallow', '--filter=blob:none', 'origin', '+refs/heads/*:refs/remotes/origin/*'])
+
nArgs = ['-n' + str(n)] if n != None else []
output = subprocess.check_output(['git', 'log', '--format=%H'] + nArgs + [commitOrRange]).decode()
hashes = list(filter(is_commit_hash, output.split('\n')))
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fed3796d60ebd9ca3d364dd7e86d5f2…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fed3796d60ebd9ca3d364dd7e86d5f2…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/unload-strategy] 40 commits: NCG: List each destination of a jump table once
by Zubin (@wz1000) 30 Nov '26
by Zubin (@wz1000) 30 Nov '26
30 Nov '26
Zubin pushed to branch wip/unload-strategy at Glasgow Haskell Compiler / GHC
Commits:
01a5b0ac by Sylvain Henry at 2026-11-22T16:35:34-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
e4498112 by Andreas Klebinger at 2026-11-22T16:35:34-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
f59fb957 by Sylvain Henry at 2026-11-22T16:35:34-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
2091b89a by fendor at 2026-11-22T16:36:17-05:00
`ghc -M`: Add support for link nodes to json output
`LinkNode`s are part of the module graph and indicate that a certain
linking artefact is to be produced from other module graph nodes.
We expose `LinkNode`s in the output of `ghc -M -dep-json`, allowing
consumers to see when a linking artefact is to be produced.
Only the JSON output format of `ghc -M` supports `LinkNode` as it is
unclear how the Makefile output should be retrofitted to express the
dependencies, and whether it would require a feature guard.
Closes #28007
- - - - -
cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
06e71ddf by Simon Peyton Jones at 2026-11-22T16:37:40-05:00
Better desugaring for bang patterns
Ticket #27862 showed that we were desugaring bang patterns in a
silly way, which led to bad code. This small fix makes it much
better.
I ended up refactoring `decomposeFirstPat` to be of type
(LPat -> LPat) instead of (Pat -> Pat)
which made it much easier to keep the locations correct.
On the way I also fixed #28137, a missing warning.
See Note [Tidying patterns] which has new (TP1) and (TP2)
and Note [Grouping equations] especially (GE1)
- - - - -
cd6c2a96 by Simon Jakobi at 2026-11-22T16:38:23-05:00
Cmm: drop eliminated blocks from the graph in CBE
Previously, common block elimination only made the eliminated blocks
unreachable. They stayed in the graph until stack layout discarded
them.
Removing these blocks right away reduces the potential for confusion
(e.g. #27368). It does not appear to make any significant difference
to compiler allocations.
Assisted-by: Claude Opus 5.5
- - - - -
c0764c69 by Hannes Siebenhandl at 2026-11-22T16:39:04-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
242f8daf by Alan Zimmerman at 2026-11-22T16:39:46-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
1e568190 by David Eichmann at 2026-11-22T16:40:28-05:00
Fix race condition in IOManager test
- - - - -
64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00
Fix a zonking bug
As #28135 showed, we were failing to zonk some type-variable
binders before doing scoped-sort dependency analysis, resulting
in chaos.
The fix is easy.
- - - - -
ed5124b3 by mangoiv at 2026-11-22T16:41:50-05:00
ci: nightly push can run on any arch
- - - - -
1340d255 by ARATA Mizuki at 2026-11-23T20:13:03-05:00
rts: Fix unwinding information for StgRun
The unwinding rule for rsp updated in a5ec467ee3d4e77c026437a545981269acde3434
was wrong. It gave the value of rsp _after_ the call instruction (i.e.
on entry to StgRun), whereas it should give the value _before_ the call
instruction (i.e. the caller's rsp).
Fixes #27637
- - - - -
56bb91d9 by Alan Zimmerman at 2026-11-23T20:13:44-05:00
EPA: Replace AnnListLayout / AnnListBrackets with EpLayout
We have harmonised the use of `AnnListLayout` and `AnnListBrackets` to
be equivalent to `EpLayout`.
We now take the final step, and remove them completely in favour of
`EpLayout`.
The change looks bigger than it is, because a lot of golden test
output gets updated.
- - - - -
2349dd26 by Simon Peyton Jones at 2026-11-26T21:19:27-05:00
Use a different herald for -ddump-simpl-trace
... so that we can more easily skip the high-volume ones
- - - - -
03b1faab by Simon Peyton Jones at 2026-11-26T21:19:27-05:00
Update comments and user manual
This commit addresses the comment-related suggestions in #27973
- - - - -
24055252 by Simon Peyton Jones at 2026-11-26T21:19:27-05:00
Document and refactor eta-reduction documentation
Triggered by #27212, this patch does several related things.
* #27212 suggested that `findRhsArity` should ask for eta-expansion
whenever the RHS's `manifestArity` is less than the arity it finds.
That is a misconception: it deliberately compares with `exprArity`,
which counts PAPs, so that we do not eta-expand PAPs (#9020).
Switching to `manifestArity` makes compile time worse in T13960
and T13056.
So this patch changes no code here; we continue to expand only to
increase `exprArity` not `manifestArity`. Instead it documents the
design in `findRhsArity`, `tryEtaExpandRhs`, `wantEtaExpansion` and
Note [Do not eta-expand PAPs] (which now records the #27212
experiment).
* Refactor GHC.Core.Opt.Arity.tryEtaReduce, which was hard to
understand:
- Accumulate an MCoercion rather than a Coercion, so the common
no-cast case builds no coercions at all.
- Separate equations of `go` for type and value arguments. For
value arguments, the new `getTrivialHead_maybe` looks through any
nesting of casts and floatable ticks, and `mkEtaReduceFunCo` builds
the coercion.
- Make the FunCo with `mkFunCo2` and compute its right-hand
FunTyFlag from the coercion kinds. The cast can turn a Type-kinded
argument into a Constraint-kinded one. New test T27212 covers this.
- `mkEtaReduceForAllMCo` builds the ForAllCo for type arguments. It
is tiresomely similar to `mkEtaForAllMCo`, but with the visibilities
the other way round (#24014). It will go away again once !17006
lands.
- New helper `mCoToCo` in GHC.Core.TyCo.Make.
* Drop the checks on multiplicity in `tryEtaReduce`, which sometimes
disabled eta-reduction. For example, (\x. K x) has type Int -> T,
but the data constructor has type K :: Int %1 -> T, so we used to
refuse to eta-reduce it to K.
But Note [Linting linearity] in GHC.Core.Lint (EXAMPLE 4) already
says that we do not preserve linearity under eta-reduction, so this
change just puts that claim into practice. See (EtaMult) in
Note [Eta reduction soundness].
Consequences in the testsuite:
- T18052a: the pattern-synonym builder (\x y. (x,y)) is now just (,).
- T21888a: the NOINLINE function (f x = Just x) becomes (f = Just),
so f loses its CPR signature. The test is about demands, not CPR.
* Tidy up the documentation of eta-reduction:
- Relabel the criteria in Note [Eta reduction soundness] as (EtaA),
(EtaS), (EtaR), (EtaE), (EtaT), (EtaJ), (EtaB) and (EtaW), and
update all references to them. Also fix references to point (2) of
Note [Eta reduction makes sense], which no longer exists.
- Replace the confused "never reduce arity" bullet with an example in
(EtaA), cross-referenced from Note [Arity robustness].
- Add historical notes (EtaMult) and (EtaBot).
- Label the equations in Note [Eta reduction with casted arguments]
(ECA1-4), and point to the code that implements them.
LLM disclosure: I interacted with Claude a lot for this MR, but I
wrote all the code and docs myself.
- - - - -
e02a40c5 by Zubin Duggal at 2026-11-26T21:20:10-05:00
linker: Remove DotA and DotDLL constructors of LinkablePart
As far as I can, we have never actually used these constructors,
and they have never appeared in a positive position, ever since they
were introduced a long time ago.
Foreign libraries aren't loaded through these either, that happens either
through `loadPackages` which uses `LibrarySpec` or through 'loadCmdLineLibs'
Also, a Linkable defines the build product of a single home module. DotA/DotDLL
are library like things, so they don't fit into a Linkable anyway.
- - - - -
56ae5186 by Zubin Duggal at 2026-11-26T21:20:10-05:00
Identify Linkable with fingerprints of their contents rather than modtimes
- - - - -
3b1fe950 by Zubin Duggal at 2026-11-26T21:20:10-05:00
Linker cleanup
delete a bunch of unused functions
- - - - -
8f2d4513 by Zubin Duggal at 2026-11-26T21:20:10-05:00
Record constituent hashes for bytecode libraries
A bytecode library now records the combined hash of its constituents,
so relinking can be skipped when they haven't changed.
- - - - -
bd43176e by Zubin Duggal at 2026-11-26T21:20:10-05:00
bytecode: Give persistent bytecode files a fixed-size header with a hash
The header of .gbc and .bytecodelib files now consists of the magic word,
the compiler version and a hash, all with fixed-length encodings. The hash
is the gbc_hash of a bytecode file, or the inputs hash of a bytecode
library.
readBinByteCodeHash and readBytecodeLibInputsHash now read only the header
rather than the whole file. The version is written as its four numeric
components instead of as a string.
- - - - -
c62000f2 by Zubin Duggal at 2026-11-26T21:20:10-05:00
driver: Refresh ms_bytecode_date when reusing a ModSummary
- - - - -
f979f719 by Zubin Duggal at 2026-11-26T21:20:10-05:00
bytecode: Treat persistent bytecode files with a bad header as stale
- - - - -
cf85181f by Zubin Duggal at 2026-11-26T21:20:10-05:00
bytecode: Record the inputs hash in BytecodeLib
-------------------------
Metric Increase:
MultiLayerModulesRecomp
MultiLayerModulesTH_Make
MultiLayerModulesTH_OneShot
-------------------------
- - - - -
2948aea2 by Simon Jakobi at 2026-11-26T21:20:52-05:00
X86 NCG: use bt for single-bit tests
Previously the Cmm patterns
(x & (1 << i)) != 0
(x & (1 << i)) == 0
compiled to a mov/shl/and/test sequence. Now they compile to a single
bt, followed directly by a jc/jae or setc/setae.
As with btr/bts/btc, a literal single-bit mask that doesn't fit in an
imm32, such as x & 0x10000000000, is now also tested with bt instead of
being loaded into a register first.
Data.Bits.testBit doesn't benefit yet when the bit index is variable:
its bounds-checked shiftL wraps the shift in a mask that blocks this
optimization.
See Note [Bit-test instructions] in GHC.CmmToAsm.X86.CodeGen.
Fixes #27688.
Assisted-by: Claude Fable 5.1
- - - - -
d7206efa by Simon Jakobi at 2026-11-26T21:21:33-05:00
ci: Anchor the release branch pattern
Branches with `ghc-X.Y` anywhere in their name, such as
wip/ghc-9.16-backports, were treated as release branches. Each push
started a full-ci branch pipeline next to the merge request pipeline,
and its jobs pushed perf notes.
Fixes #28172.
Assisted-by: Claude Fable 5.2
- - - - -
c3e21ac0 by Simon Jakobi at 2026-11-26T21:21:33-05:00
ci: Fix the release branch pattern of lint-submods-branch
The pattern had `[0.9]` for `[0-9]`, so the job didn't run on ghc-10.0.
Also anchor the pattern (#28172).
Assisted-by: Claude Fable 5.2
- - - - -
03036aef by Simon Jakobi at 2026-11-26T21:22:15-05:00
ci: Retry some failed jobs automatically
Let GitLab retry a job up to twice when it fails with one of these
reasons:
- runner_system_failure: the runner could not run the job. This is
nearly always an image pull that fails before the job starts.
- stuck_or_timeout_failure: GitLab dropped the job, either because
its runner stopped reporting for an hour or because no runner
picked it up within a day.
Assisted-by: Claude Fable 5.2
- - - - -
e8139c28 by Simon Jakobi at 2026-11-26T21:22:56-05:00
Correct some comments about unreachable Cmm blocks
* ContFlowOpt claimed that maybe_concat drops every block that has no
predecessors left. But a block that loses its predecessors to
shortcutting stays in the graph.
* The linear register allocator claimed that the Cmm pipeline keeps
unreachable blocks away from it. But the NCG's own Cmm optimisations
can make more blocks unreachable after the Cmm pipeline has run. It
is sccBlocks that discards unreachable code before register
allocation (#7574).
Also:
* Remove a commented-out trace in the linear allocator that predates
#7574.
* Say in Note [unreachable blocks] that any pass in cpsTop can encounter
unreachable blocks. Rename it to Note [Unreachable blocks in the Cmm
pipeline], so its title no longer differs only in case from an
unrelated Note in GHC.Cmm.Dataflow.
Context: #27368
Assisted-by: Claude Fable 5.2
- - - - -
21abda33 by Teo Camarasu at 2026-11-26T21:23:37-05:00
Skip tests that excercise forkProcess when using non-moving GC
The non-moving GC creates a persistent marker thread. This causes issues
when users use forkProcess, since the child process ends up in a strange
state.
forkProcess is documented to not work well with the threaded Haskell
runtime. So, it's not surprising that it doesn't work with the
non-moving GC which is inherently threaded.
We should one day add support for forkProcess, but, for now, we just
disable these tests when using the non-moving GC.
The underlying issue is tracked by #27547.
- - - - -
79efb4a7 by Wolfgang Jeltsch at 2026-11-26T21:24:20-05:00
Switch fingerprint caches to `FastString` keys
Resolves #28139.
- - - - -
feacb69d by mangoiv at 2026-11-26T21:25:01-05:00
ci: fix a bug where there's no runner that can pick up nightly push jobs
- - - - -
1d5c87ce by Alan Zimmerman at 2026-11-26T21:25:43-05:00
EPA: Move setLayoutBoth inside markAnnListA
The current refactoring aims to capture layout only in the `AnnList`
exact print annotation. A consequence of this is that exact printing
should only process layout when printing in the context of `AnnList`.
To achieve this, this commit moves the layout printing enabler
`setlayoutboth` into the `AnnList` processing. Future commits will
remove the other occurrences.
It also adds some tests to confirm it still works as intended, and cleans
up some other unused functions.
- - - - -
b2f76fc1 by Zubin Duggal at 2026-11-29T09:36:39+05:30
linker: refactor loader so that object suffixes get passed through in a sane way
- - - - -
d201361f by Zubin Duggal at 2026-11-30T13:01:12+05:30
linker: Automatically reload stale linkables
Linked BCOs contain direct references to closures, so replacing only a
changed module can leave stale references in other modules. Take
-- A.hs
f = 1
-- B.hs
import A
g = f + 1
After loading A and B, change A so that f = 2 and recompile it. B does
not need to be recompiled, but its loaded BCO still refers to the old
closure for f. The next splice should see f = 2 and g = 3. To get the
correct result, we have to *reload* B, even though we didn't need to
recompile it.
The GHC driver calls unload before each upsweep, which unloads
everything, so this does not arise during an ordinary GHCi reload. API
clients such as HLS may instead want to keep the loader state while
recompiling individual modules. Forcing them to unload everything or
carefully keep track of what to unload is not ideal.
Now we automatically reload stale linkables, so that if we are asked
to link a module whose code has changed, the old code, and everything
that refers to it, is dropped and reloaded. See
Note [Automatically reloading stale linkables].
Dropped objects are now purged, not unloaded, so values built by the
old code and computations still using it keep working. The object
stays in memory, but new code will not be able to link against it.
This is a change in behaviour, objects were previously only ever
unloaded, all at once, in unload. See
Note [Unloading vs purging objects]
Fixes #27606
- - - - -
c3e3409e by Zubin Duggal at 2026-11-30T13:01:39+05:30
linker: Add unloadModules
Drop the given modules and every loaded module that transitively
refers to them. Reloading stale code does not need this, it happens
automatically. This is for API clients dropping modules they no
longer need. Interactive modules are ignored.
See Note [Automatically reloading stale linkables] in GHC.Linker.Loader
See Note [Unloading vs purging objects] in GHC.Runtime.Interpreter
- - - - -
1012eccc by Zubin Duggal at 2026-11-30T13:01:40+05:30
iserv: Add a PurgeObj message
purgeObj no longer falls back to unloading on external interpreters.
See Note [Unloading vs purging objects] in GHC.Runtime.Interpreter.
- - - - -
72ad53f3 by Zubin Duggal at 2026-11-30T13:01:46+05:30
linker: Remove static pointer table entries when dropping modules
Entries were added by bytecode modules, but never removed. This meant
that every reload of a module with static forms leaked its old entries
and kept the old code alive, including in GHCi with :reload.
loaded_spt_keys now records the keys each loaded bytecode module
inserted. dropModules and unload remove them. We also add a new
RemoveSptEntry message to support this operation with the external
interpreter.
The key of an entry added by sptAddEntry is now allocated in the same
block as the entry, so it is freed when the entry is removed.
Object code manages its own entries with initialisers and finalisers,
so it was not changed.
Fixes #27740
- - - - -
a975fbe3 by Zubin Duggal at 2026-11-30T14:47:30+05:30
Introduce -funload-strategy
When unloading object code, we have a choice to make. Do we call
purgeObj or unloadObj?
purgeObj clears the symbol tables associated with an object, so that
future objects can't link against it, but the object stays in memory
unloadObj does the above, but it also marks the object as needing to be
unloaded, so at some point in a future GC, the RTS may notice that it is
no longer used, and if so, unload it entirely, freeing up the memory.
Ideally we would always unload, but a number of bugs with the
implementation of unloadObj mean that it is fragile on many platforms.
This is documented in Note [Unloading vs purging objects]. So on these
platforms we purge instead.
We introduce the -funload-strategy flag, so that users can opt into
purging/unloading on platforms where we make the other choice by
default.
The distinction is moot when we are using the dynamic RTS, we don't do
either then.
Fixes #27741
- - - - -
218 changed files:
- .gitlab-ci.yml
- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- + changelog.d/27694
- + changelog.d/T27137
- + changelog.d/T27212
- + changelog.d/T27637
- + changelog.d/T27862
- + changelog.d/T28135
- + changelog.d/fingerprint-caches-with-fast-string-keys
- + changelog.d/make-depends-link-nodes
- changelog.d/ncg-x86-bit-test-instructions
- + changelog.d/unload-strategy
- compiler/GHC.hs
- compiler/GHC/ByteCode/Binary.hs
- compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/Cmm.hs
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/Cmm/ContFlowOpt.hs
- compiler/GHC/Cmm/Pipeline.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Inline.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/TyCo/Make.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
- compiler/GHC/Driver/Config/Interpreter.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Usage.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Linker/ByteCode.hs
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Linker/Types.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/Init.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- + distrib/configure.ac
- docs/users_guide/debug-info.rst
- docs/users_guide/ghci.rst
- docs/users_guide/make-depends-json-schema-1_0.json
- docs/users_guide/using-optimisation.rst
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/ObjLink.hs
- libraries/ghci/GHCi/Run.hs
- libraries/ghci/GHCi/StaticPtrTable.hs
- rts/StgCRun.c
- testsuite/tests/ado/T22483.stderr
- + testsuite/tests/codeGen/should_compile/T27694.hs
- + testsuite/tests/codeGen/should_compile/T27694c.hs
- + testsuite/tests/codeGen/should_compile/T27694d.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_gen_asm/T27688.asm
- + testsuite/tests/codeGen/should_gen_asm/T27688.hs
- + testsuite/tests/codeGen/should_gen_asm/T27688b.asm
- + testsuite/tests/codeGen/should_gen_asm/T27688b.cmm
- testsuite/tests/codeGen/should_gen_asm/all.T
- + testsuite/tests/codeGen/should_run/T27694b.hs
- + testsuite/tests/codeGen/should_run/T27694b.stdout
- + testsuite/tests/codeGen/should_run/T27915.hs
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-32
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-64
- testsuite/tests/codeGen/should_run/all.T
- + testsuite/tests/deSugar/should_compile/T27862.hs
- + testsuite/tests/deSugar/should_compile/T27862.stderr
- + testsuite/tests/deSugar/should_compile/T27862a.hs
- + testsuite/tests/deSugar/should_compile/T27862a.stderr
- + testsuite/tests/deSugar/should_compile/T27862b.hs
- + testsuite/tests/deSugar/should_compile/T27862b.stderr
- + testsuite/tests/deSugar/should_compile/T27862c.hs
- + testsuite/tests/deSugar/should_compile/T27862c.stderr
- + testsuite/tests/deSugar/should_compile/T27862d.hs
- + testsuite/tests/deSugar/should_compile/T27862d.stderr
- + testsuite/tests/deSugar/should_compile/T28137.hs
- + testsuite/tests/deSugar/should_compile/T28137.stderr
- testsuite/tests/deSugar/should_compile/all.T
- testsuite/tests/deSugar/should_run/dsrun008.stderr
- testsuite/tests/dmdanal/sigs/T21888a.stderr
- testsuite/tests/driver/bytecode-object/Makefile
- testsuite/tests/driver/bytecode-object/all.T
- + testsuite/tests/driver/bytecode-object/bytecode_object27.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object28.script
- + testsuite/tests/driver/bytecode-object/bytecode_object28.stdout
- + testsuite/tests/driver/bytecode-object/bytecode_object29.stdout
- testsuite/tests/driver/mkdepend/all.T
- + testsuite/tests/driver/mkdepend/mhu04/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu04/app/Utils.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu04/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu04/unitApp
- + testsuite/tests/driver/mkdepend/mhu04/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/app/Main.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib.hs
- + testsuite/tests/driver/mkdepend/mhu05/lib/Lib/Internal.hs
- + testsuite/tests/driver/mkdepend/mhu05/test/Spec.hs
- + testsuite/tests/driver/mkdepend/mhu05/unitApp
- + testsuite/tests/driver/mkdepend/mhu05/unitLib
- + testsuite/tests/driver/mkdepend/mhu05/unitTest
- + testsuite/tests/driver/mkdepend/mkdepend02.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend02/Main.hs
- + testsuite/tests/driver/mkdepend/mkdepend_bkp_01/bkp01.bkp
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu04.dep-makefile
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-json
- + testsuite/tests/driver/mkdepend/mkdepend_mhu05.dep-makefile
- + testsuite/tests/driver/recomp023/M.hs
- + testsuite/tests/driver/recomp023/M2.hs
- + testsuite/tests/driver/recomp023/Makefile
- + testsuite/tests/driver/recomp023/all.T
- + testsuite/tests/driver/recomp023/recomp023.stdout
- + testsuite/tests/ghc-api/T27606/B.hs
- + testsuite/tests/ghc-api/T27606/Common.hs
- + testsuite/tests/ghc-api/T27606/T27606a.hs
- + testsuite/tests/ghc-api/T27606/T27606a.stdout
- + testsuite/tests/ghc-api/T27606/T27606b.hs
- + testsuite/tests/ghc-api/T27606/T27606b.stdout
- + testsuite/tests/ghc-api/T27606/T27606c.hs
- + testsuite/tests/ghc-api/T27606/T27606c.stdout
- + testsuite/tests/ghc-api/T27606/T27606c_purge.stdout
- + testsuite/tests/ghc-api/T27606/T27606d.hs
- + testsuite/tests/ghc-api/T27606/T27606d.stdout
- + testsuite/tests/ghc-api/T27606/T27606e.hs
- + testsuite/tests/ghc-api/T27606/T27606e.stdout
- + testsuite/tests/ghc-api/T27606/all.T
- + testsuite/tests/ghc-api/T27740.hs
- + testsuite/tests/ghc-api/T27740.stdout
- testsuite/tests/ghc-api/all.T
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/Test20239.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T24221.stderr
- testsuite/tests/hpc/fork/test.T
- testsuite/tests/lib/base/all.T
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.hs
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T14189.stderr
- testsuite/tests/parser/should_compile/T15279.stderr
- testsuite/tests/parser/should_compile/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/pmcheck/should_compile/T24234.stderr
- + testsuite/tests/printer/Layout.hs
- testsuite/tests/printer/Makefile
- testsuite/tests/printer/T18052a.stderr
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/printer/all.T
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/all.T
- testsuite/tests/simplCore/should_compile/T24726.stderr
- + testsuite/tests/simplCore/should_compile/T27212.hs
- testsuite/tests/simplCore/should_compile/all.T
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/tcfail203a.stderr
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/718ea6f3781546de7d149e43ea1ec0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/718ea6f3781546de7d149e43ea1ec0…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][master] testsuite: Do not pass $(WAY_FLAGS) to GHCi in Makefile tests (#28166)
by Marge Bot (@marge-bot) 30 Nov '26
by Marge Bot (@marge-bot) 30 Nov '26
30 Nov '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
ef652c33 by Sylvain Henry at 2026-11-30T04:14:36-05:00
testsuite: Do not pass $(WAY_FLAGS) to GHCi in Makefile tests (#28166)
Since 543c108e6a9 the driver sets WAY_FLAGS for Makefile tests. Some
GHCi tests passed $(WAY_FLAGS) to ghc --interactive, where it was empty
before. In the optasm and optllvm ways it now contains -O, and the
byte-code backend ignores -O with a -Winconsistent-flags warning. This
warning made the tests fail.
Pass $(WAY_FLAGS) to the compilation steps only. GHCi reuses the object
files that these steps make with -O, thus the tests stay useful in the
optimised ways.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
6 changed files:
- testsuite/tests/ghci/prog-mhu005/Makefile
- testsuite/tests/ghci/prog-mhu006/Makefile
- testsuite/tests/ghci/prog-mhu007/Makefile
- testsuite/tests/ghci/prog020/Makefile
- testsuite/tests/ghci/prog022/Makefile
- testsuite/tests/ghci/prog025/Makefile
Changes:
=====================================
testsuite/tests/ghci/prog-mhu005/Makefile
=====================================
@@ -4,28 +4,28 @@ include $(TOP)/mk/test.mk
.PHONY: prog-mhu005a
prog-mhu005a:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -unit @unitA -unit @unitB < prog-mhu005a.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -unit @unitA -unit @unitB < prog-mhu005a.script
.PHONY: prog-mhu005b
prog-mhu005b:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005b.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005b.script
.PHONY: prog-mhu005c
prog-mhu005c:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-import-loaded-targets -unit @unitA -unit @unitB < prog-mhu005c.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-import-loaded-targets -unit @unitA -unit @unitB < prog-mhu005c.script
.PHONY: prog-mhu005d
prog-mhu005d:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -fno-import-loaded-targets -unit @unitA -unit @unitB < prog-mhu005d.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -fno-import-loaded-targets -unit @unitA -unit @unitB < prog-mhu005d.script
.PHONY: prog-mhu005e
prog-mhu005e:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005e.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005e.script
.PHONY: prog-mhu005f
prog-mhu005f:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -unit @unitA -unit @unitB < prog-mhu005f.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -unit @unitA -unit @unitB < prog-mhu005f.script
.PHONY: prog-mhu005g
prog-mhu005g:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005g.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -unit @unitA -unit @unitB < prog-mhu005g.script
=====================================
testsuite/tests/ghci/prog-mhu006/Makefile
=====================================
@@ -4,6 +4,6 @@ include $(TOP)/mk/test.mk
.PHONY: prog-mhu006a
prog-mhu006a:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) \
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) \
-no-user-package-db \
-unit @unitA -unit @unitB < prog-mhu006a.script
=====================================
testsuite/tests/ghci/prog-mhu007/Makefile
=====================================
@@ -29,5 +29,5 @@ prog-mhu007:
$(LOCAL_GHC_PKG_BAR) hide testpkg-bar
$(LOCAL_GHC_PKG_BAR) list
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) \
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) \
-no-user-package-db -fno-code -unit @unitA -unit @unitB < prog-mhu007.script
=====================================
testsuite/tests/ghci/prog020/Makefile
=====================================
@@ -5,9 +5,9 @@ include $(TOP)/mk/test.mk
.PHONY: ghci.prog020a
ghci.prog020a:
'$(TEST_HC)' $(TEST_HC_OPTS) $(WAY_FLAGS) $(ghciWayFlags) -v0 A.hs B.hs
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -i -i. A B < ghci.prog020a.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -i -i. A B < ghci.prog020a.script
.PHONY: ghci.prog020b
ghci.prog020b:
'$(TEST_HC)' $(TEST_HC_OPTS) $(WAY_FLAGS) $(ghciWayFlags) -v0 A.hs B.hs
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -i -i. A B < ghci.prog020b.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -i -i. A B < ghci.prog020b.script
=====================================
testsuite/tests/ghci/prog022/Makefile
=====================================
@@ -4,24 +4,24 @@ include $(TOP)/mk/test.mk
.PHONY: ghci.prog022a
ghci.prog022a:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -i -i. A B < ghci.prog022a.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -i -i. A B < ghci.prog022a.script
.PHONY: ghci.prog022b
ghci.prog022b:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -i -i. A B < ghci.prog022b.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -i -i. A B < ghci.prog022b.script
.PHONY: ghci.prog022c
ghci.prog022c:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fimport-loaded-targets -i -i. A B < ghci.prog022c.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fimport-loaded-targets -i -i. A B < ghci.prog022c.script
.PHONY: ghci.prog022d
ghci.prog022d:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -i -i. A B < ghci.prog022d.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -i -i. A B < ghci.prog022d.script
.PHONY: ghci.prog022e
ghci.prog022e:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fimport-loaded-targets -i -i. A B < ghci.prog022e.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fimport-loaded-targets -i -i. A B < ghci.prog022e.script
.PHONY: ghci.prog022f
ghci.prog022f:
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -i -i. A B < ghci.prog022f.script
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) -v0 -fno-load-initial-targets -fimport-loaded-targets -i -i. A B < ghci.prog022f.script
=====================================
testsuite/tests/ghci/prog025/Makefile
=====================================
@@ -26,7 +26,7 @@ prog025a:
$(LOCAL_GHC_PKG01) hide testpkg-0.2.0.0
$(LOCAL_GHC_PKG01) list
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) \
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) \
-no-user-package-db -fno-code -unit @unitA < prog025a.script
# Same as prog025a, but the home unit arguments are not provided using a response file
@@ -49,6 +49,6 @@ prog025b:
$(LOCAL_GHC_PKG01) list
# Uses response file for argument, doesn't use it as a -unit argument
- '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(WAY_FLAGS) $(ghciWayFlags) \
+ '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) $(ghciWayFlags) \
-no-user-package-db -fno-code \
@unitA < prog025b.script
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ef652c33e77f61e93dedb7ca15607d1…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ef652c33e77f61e93dedb7ca15607d1…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][master] 2 commits: testsuite: fix framework failure on window for tests using all_available_io_managers_except()
by Marge Bot (@marge-bot) 30 Nov '26
by Marge Bot (@marge-bot) 30 Nov '26
30 Nov '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
8aca9c73 by David Eichmann at 2026-11-30T04:13:46-05:00
testsuite: fix framework failure on window for tests using all_available_io_managers_except()
- - - - -
2858a265 by David Eichmann at 2026-11-30T04:13:46-05:00
testsuite: use `all_available_io_managers` for various tests
Affected tests:
* T10590
* T21969
* T21969a
* T21969b
* T21969c
* T21969d
* T21969e
* T21969f
- - - - -
3 changed files:
- testsuite/driver/testutil.py
- testsuite/tests/concurrent/should_run/all.T
- testsuite/tests/rts/all.T
Changes:
=====================================
testsuite/driver/testutil.py
=====================================
@@ -184,8 +184,10 @@ def shorten_metric_name(name: str) -> str:
# I/O manager discovery for a haskell binary. Returns the set of IO Manager
# strings supported by the binary
def discover_io_managers(hs_exe: Union[str, Path], cwd: Union[str, Path]) -> Set[str]:
+ # We must use an absolute path for the executable. Relative paths break on windows.
+ hs_exe_path = Path(cwd).joinpath(hs_exe)
rp = subprocess.run(
- [str(hs_exe), '+RTS', '--info', '-RTS'],
+ [hs_exe_path, '+RTS', '--info', '-RTS'],
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
=====================================
testsuite/tests/concurrent/should_run/all.T
=====================================
@@ -271,7 +271,8 @@ test('T21969',
extra_run_opts('50000'),
run_timeout_multiplier(0.3), # default timeout seems to be 300, but lockups happen quickly
req_target_smp,
- req_ghc_smp
+ req_ghc_smp,
+ all_available_io_managers,
],
compile_and_run, [''])
@@ -289,24 +290,28 @@ test('T21969',
test('T21969a',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969b',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969c',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969d',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
@@ -314,12 +319,14 @@ test('T21969e',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
run_timeout_multiplier(0.3),
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969f',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -408,6 +408,7 @@ test('T10590', [ ignore_stderr
, when(opsys('mingw32'), skip)
, js_skip # JS backend doesn't support pipes
, req_process
+ , all_available_io_managers
], compile_and_run, [''])
# Run with stdin and stdout closed -- that is what leaves those descriptors
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/51e1429855049a9e77720ed6d5cf96…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/51e1429855049a9e77720ed6d5cf96…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][master] EPA: Introduce LayoutFrame stacks in ExactPrint state
by Marge Bot (@marge-bot) 30 Nov '26
by Marge Bot (@marge-bot) 30 Nov '26
30 Nov '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
56abdcf4 by Alan Zimmerman at 2026-11-30T04:15:17-05:00
EPA: Introduce LayoutFrame stacks in ExactPrint state
The exact print process keeps the current layout offset in its state,
for use in printing and updating for makeDelta.
Update it to use a stack rather than a single value, so it properly
handles nested layout, in particular when the layout is introduced but
the printing is empty.
Also simplify the exact print repl test runner to use a relative path
to the GHC libdir.
- - - - -
2 changed files:
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
Changes:
=====================================
utils/check-exact/ExactPrint.hs
=====================================
@@ -78,7 +78,7 @@ import Data.Functor.Const
import Data.Typeable
import Data.List ( partition, sort )
import qualified Data.List.NonEmpty as NE
-import Data.Maybe ( isJust )
+import Data.Maybe ( isJust, isNothing, fromMaybe )
import Data.Void
import Utils
@@ -122,13 +122,11 @@ defaultEPState = EPState
, uExtraDPReturn = Nothing
, pAcceptSpan = False
- , epPos = (1,1)
- , pMarkLayout = False
- , pLHS = LayoutStartCol 1
+ , pPos = (1,1)
+ , pLayout = [LayoutFrame (LayoutStartCol 1) (Just (LayoutStartCol 1))]
, dPriorEndPosition = (1,1)
- , dMarkLayout = False
- , dLHS = LayoutStartCol 1
+ , dLayout = [LayoutFrame (LayoutStartCol 1) (Just (LayoutStartCol 1))]
, epComments = []
, epCommentsApplied = []
@@ -172,6 +170,13 @@ instance Monoid w => Semigroup (EPWriter w) where
instance Monoid w => Monoid (EPWriter w) where
mempty = EPWriter mempty
+-- ---------------------------------------------------------------------
+
+data LayoutFrame = LayoutFrame
+ { lfSaved :: !LayoutStartCol -- ^ effective offset at scope entry
+ , lfResolved :: !(Maybe LayoutStartCol) -- ^ column of the first token printed in this scope
+ }
+
data EPState = EPState
{ uAnchorSpan :: !RealSrcSpan -- ^ in pre-changed AST
-- reference frame, from
@@ -189,16 +194,14 @@ data EPState = EPState
-- end of the span.
-- Print phase
- , epPos :: !Pos -- ^ Current output position
- , pMarkLayout :: !Bool
- , pLHS :: !LayoutStartCol
+ , pPos :: !Pos -- ^ Current output position
+ , pLayout :: [LayoutFrame]
-- Delta phase
, dPriorEndPosition :: !Pos -- ^ End of Position reached
-- when processing the
-- preceding element
- , dMarkLayout :: !Bool
- , dLHS :: !LayoutStartCol
+ , dLayout :: [LayoutFrame]
-- Shared
, epComments :: ![Comment]
@@ -2644,7 +2647,7 @@ instance ExactPrint (HsIPBinds GhcPs) where
getAnnotationEntry = const NoEntryVal
setAnnotationAnchor a _ _ _ = a
- exact (IPBinds x binds) = setLayoutBoth $ do
+ exact (IPBinds x binds) = do
binds' <- mapM markAnnotated binds
return (IPBinds x binds')
@@ -3018,7 +3021,7 @@ instance ExactPrint (HsExpr GhcPs) where
an0 <- markLensFun an lhsCaseAnnCase markEpToken
e' <- markAnnotated e
an1 <- markLensFun an0 lhsCaseAnnOf markEpToken
- alts' <- setLayoutBoth $ markAnnotated alts
+ alts' <- markAnnotated alts
return (HsCase an1 e' alts')
exact (HsIf an e1 e2 e3) = do
@@ -3040,7 +3043,7 @@ instance ExactPrint (HsExpr GhcPs) where
exact (HsLet (tkLet, tkIn) binds e) = do
setLayoutBoth $ do -- Make sure the 'in' gets indented too
tkLet' <- markEpToken tkLet
- binds' <- setLayoutBoth $ markAnnotated binds
+ binds' <- markAnnotated binds
tkIn' <- markEpToken tkIn
e' <- markAnnotated e
return (HsLet (tkLet',tkIn') binds' e')
@@ -3302,7 +3305,7 @@ instance ExactPrint (HsUntypedSplice GhcPs) where
-- the colOffset for now.
-- TODO: use local?
oldOffset <- getLayoutOffsetP
- EPState{pMarkLayout} <- get
+ pMarkLayout <- queryLayoutStack <$> gets pLayout
unless pMarkLayout $ setLayoutOffsetP 0
printStringAdvance
-- Note: Lexer.x does not provide unicode alternative. 2017-02-26
@@ -3525,7 +3528,7 @@ instance ExactPrint (HsCmd GhcPs) where
exact (HsCmdLet (tkLet, tkIn) binds e) = do
setLayoutBoth $ do -- Make sure the 'in' gets indented too
tkLet' <- markEpToken tkLet
- binds' <- setLayoutBoth $ markAnnotated binds
+ binds' <- markAnnotated binds
tkIn' <- markEpToken tkIn
e' <- markAnnotated e
return (HsCmdLet (tkLet', tkIn') binds' e')
@@ -5026,30 +5029,51 @@ printQueuedComment Comment{commentContents} dp = do
------------------------------------------------------------------------
+effectiveLayout :: [LayoutFrame] -> LayoutStartCol
+effectiveLayout (f:_) = fromMaybe (lfSaved f) (lfResolved f)
+effectiveLayout [] = LayoutStartCol 1
+
+popLayoutStack :: [LayoutFrame] -> [LayoutFrame]
+popLayoutStack (_:rest) = rest
+popLayoutStack [] = []
+
+queryLayoutStack :: [LayoutFrame] -> Bool
+queryLayoutStack (f:_) = isNothing (lfResolved f)
+queryLayoutStack [] = False
+
+
+-- | Work down the stack filling in the resolved layout column for all
+-- so-far-unresolved ones. These can only be in the prefix of the
+-- list.
+resolveLayoutStack :: [LayoutFrame] -> LayoutStartCol -> [LayoutFrame]
+resolveLayoutStack (f:rest) c =
+ case lfResolved f of
+ Nothing -> f { lfResolved = Just c } : resolveLayoutStack rest c
+ Just _ -> f:rest
+resolveLayoutStack [] _ = []
+
setLayoutBoth :: (Monad m, Monoid w) => EP w m a -> EP w m a
-setLayoutBoth k = do
+setLayoutBoth action = do
oldLHS <- getLayoutOffsetD
oldAnchorOffset <- getLayoutOffsetP
debugM $ "setLayoutBoth: (oldLHS,oldAnchorOffset)=" ++ show (oldLHS,oldAnchorOffset)
- modify (\a -> a { dMarkLayout = True
- , pMarkLayout = True } )
+ modify (\a -> a { dLayout = (LayoutFrame (effectiveLayout (dLayout a)) Nothing:dLayout a)
+ , pLayout = (LayoutFrame (effectiveLayout (pLayout a)) Nothing:pLayout a)} )
let reset = do
- debugM $ "setLayoutBoth:reset: (oldLHS,oldAnchorOffset)=" ++ show (oldLHS,oldAnchorOffset)
- modify (\a -> a { dMarkLayout = False
- , dLHS = oldLHS
- , pMarkLayout = False
- , pLHS = oldAnchorOffset} )
- k <* reset
+ debugM $ "pushLayout:reset: (oldLHS,oldAnchorOffset)=" ++ show (oldLHS,oldAnchorOffset)
+ modify (\a -> a { dLayout = popLayoutStack (dLayout a)
+ , pLayout = popLayoutStack (pLayout a) })
+ action <* reset
------------------------------------------------------------------------
getPosP :: (Monad m, Monoid w) => EP w m Pos
-getPosP = gets epPos
+getPosP = gets pPos
setPosP :: (Monad m, Monoid w) => Pos -> EP w m ()
setPosP l = do
debugM $ "setPosP:" ++ show l
- modify (\s -> s {epPos = l})
+ modify (\s -> s {pPos = l})
getExtraDP :: (Monad m, Monoid w) => EP w m (Maybe EpaLocation)
getExtraDP = gets uExtraDP
@@ -5100,14 +5124,13 @@ setPriorEndASTPD pe@(fm,to) = do
setLayoutStartD :: (Monad m, Monoid w) => Int -> EP w m ()
setLayoutStartD p = do
- EPState{dMarkLayout} <- get
+ dMarkLayout <- queryLayoutStack <$> gets dLayout
when dMarkLayout $ do
debugM $ "setLayoutStartD: setting dLHS=" ++ show p
- modify (\s -> s { dMarkLayout = False
- , dLHS = LayoutStartCol p})
+ modify (\s -> s { dLayout = resolveLayoutStack (dLayout s) (LayoutStartCol p)})
getLayoutOffsetD :: (Monad m, Monoid w) => EP w m LayoutStartCol
-getLayoutOffsetD = gets dLHS
+getLayoutOffsetD = effectiveLayout <$> gets dLayout
setAnchorU :: (Monad m, Monoid w) => RealSrcSpan -> EP w m ()
setAnchorU rss = do
@@ -5168,12 +5191,12 @@ applyComment c = do
(h:t) -> modify (\s -> s { epCommentsApplied = (c:h):t } )
getLayoutOffsetP :: (Monad m, Monoid w) => EP w m LayoutStartCol
-getLayoutOffsetP = gets pLHS
+getLayoutOffsetP = effectiveLayout <$> gets pLayout
setLayoutOffsetP :: (Monad m, Monoid w) => LayoutStartCol -> EP w m ()
setLayoutOffsetP c = do
debugM $ "setLayoutOffsetP:" ++ show c
- modify (\s -> s { pLHS = c })
+ modify (\s -> s { pLayout = resolveLayoutStack (pLayout s) c})
-- ---------------------------------------------------------------------
@@ -5208,11 +5231,12 @@ adjustDeltaForOffsetM dp = do
printString :: (Monad m, Monoid w) => Bool -> String -> EP w m ()
printString layout str = do
- EPState{epPos = (_,c), pMarkLayout} <- get
+ pMarkLayout <- queryLayoutStack <$> gets pLayout
+ EPState{pPos = (_,c) } <- get
EPOptions{epTokenPrint, epWhitespacePrint} <- ask
when (pMarkLayout && layout) $ do
debugM $ "printString: setting pLHS to " ++ show c
- modify (\s -> s { pLHS = LayoutStartCol c, pMarkLayout = False } )
+ setLayoutOffsetP (LayoutStartCol c)
-- Advance position, taking care of any newlines in the string
let strDP = dpFromString str
=====================================
utils/check-exact/Main.hs
=====================================
@@ -36,10 +36,7 @@ import GHC.Data.FastString
-- ---------------------------------------------------------------------
_tt :: IO ()
--- _tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/worktree/master/_build/stage1/lib/"
-_tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/ghc/_build/stage1/lib/"
--- _tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/worktree/exactprint/_build/stage1/lib"
--- _tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/worktree/epw/_build/stage1/lib"
+_tt = testOneFile changers "../../_build/stage1/lib/"
-- "../../testsuite/tests/ghc-api/exactprint/RenameCase1.hs" (Just changeRenameCase1)
-- "../../testsuite/tests/ghc-api/exactprint/LayoutLet2.hs" (Just changeLayoutLet2)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/56abdcf4b1134ff1017a6d6248c0d72…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/56abdcf4b1134ff1017a6d6248c0d72…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][master] 27 commits: Move idle GC tracking to its own file, step 1 of 2
by Marge Bot (@marge-bot) 30 Nov '26
by Marge Bot (@marge-bot) 30 Nov '26
30 Nov '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
aff1b84b by Duncan Coutts at 2026-11-30T04:10:39-05:00
Move idle GC tracking to its own file, step 1 of 2
Add a new IdleGC.{c,h} module. Move the RecentActivity type,
recent_activity variable and {get,set}RecentActivity wrappers.
- - - - -
1d0d3378 by Duncan Coutts at 2026-11-30T04:10:39-05:00
Move idle GC functionality to its own file, step 2 of 2
We can now fully encapsulate the recent_activity state, exposing just
three hooks, and one query used in the scheduler and timer tick.
This is a prelude to making changes to the implementation of tracking
when to perform an idle gc.
- - - - -
a691243d by Duncan Coutts at 2026-11-30T04:10:39-05:00
Correct comments in idle GC code
The comments still referred to stopTimer/startTimer. These were
replaced recently by pauseTimer/unpauseTimer, but the comment was not
updated.
- - - - -
fb5fde91 by Duncan Coutts at 2026-11-30T04:10:39-05:00
Make signal handling be a responsibility of the I/O manager(s)
Previously it was scattered between I/O managers and the scheduler, and
especially the scheduler's deadlock detection.
Previously the scheduler would poll for pending signals each iteration
of the scheduler loop. The scheduler also had some hairy signal
functionality in the deadlock detection: in the non-threaded RTS (only)
if there were still no threads running after deadlock detection then it
would block waiting for signals.
But signals can and (in my opinion) should be thought of as just a funny
kind of I/O, and thus should be a responsibility of the I/O manager.
So now we have the I/O managers poll for signals when they are polling
for I/O completion (and removing the separate poll in the scheduler).
And when I/O managers block waiting for I/O then they now also start
signal handlers if they get interrupted by a signal. Crucially, if there
is no pending I/O or timers, the awaitCompletedTimeoutsOrIO will still
block waiting for signals.
This patch puts us into an intermediate state: it temporarily breaks
deadlock detection in the non-threaded RTS. The waiting on I/O currently
happens before deadlock detection. This means we'll now wait forever on
signals before doing deadlock detection. We need to move waiting after
deadlock detection. We'll do that in a later patch.
- - - - -
6737f45e by Duncan Coutts at 2026-11-30T04:10:39-05:00
Clean up the RTS internal signal handling API
Now that the I/O manager is responsible for signals, we can simplify the
API we present for signal handling.
We now just need startPendingSignalHandlers, which is called from the
I/O managers. We can get rid of awaitUserSignals. We also don't need
RtsSignals.h to re-export the platform-specific posix/Signals.h or
win32/ConsoleHandler.h
We can also hide more of the implementation of signals. Less has to be
exposed in posix/Signals.h or win32/ConsoleHandler.h. Indeed,
posix/Signals.h becomes empty and we remove it. Partly this is because
we don't need inline functions (or macros) in the interface.
Also remove signal_handlers from RTS ABI exported symbols list. It does
not appear to have any users in the core libs, and its really an
internal implementation detail. It should not be exposed unless it's
really necessary.
- - - - -
bd9d3d53 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Remove variable n_haskell_handlers which has become write-only
The previous commit removed the last read of this variable.
- - - - -
de8455fe by Duncan Coutts at 2026-11-30T04:10:40-05:00
Narrow the window in which signals might be missed before poll/select
Any signals delivered just before poll/select block will be missed until
they are woken later by unrelated events. This arbitrarily delays the
delivery of signals.
This is not a complete solution. It is a cheap way to narrow but not
close the window. A full solution will have to come later. This issue
existed already, and is documented in issue #27540.
- - - - -
73381f34 by Duncan Coutts at 2026-11-30T04:10:40-05:00
In the scheduler, move I/O blocking after deadlock detection
To make deadlock detection effective in the non-threaded RTS when there
are deadlocked threads and other unrelated threads waiting on I/O, we
need to arrange to do deadlock detection before we block in scheduler
to wait on I/O.
The solution is to:
1. adjust scheduleFindWork, which runs before deadlock detection, to
only poll for I/O and not block; and
2. add a step after deadlock detection to wait on I/O if there are
still no threads to run (and there's any I/O or timeouts outstanding)
The scheduleCheckBlockedThreads is now so simple that it made more sense
to inline it into scheduleFindWork.
- - - - -
b206520f by Duncan Coutts at 2026-11-30T04:10:40-05:00
Remove bogus anyPendingTimeoutsOrIO guard from scheduleDetectDeadlock
The deadlock detection was only invoked if both of these conditions
hold:
1. the run queue is empty
2. there is no pending I/O or timeouts
The second condition is unnecessary. The deadlock detection mechanism
can find deadlocks even if there are other threads waiting on I/O or
timers. Having this extra condition means that we fail to detect
blocked threads if there are any threads waiting on I/O or timers.
Part of fixing issue #26408
- - - - -
49a75a4c by Duncan Coutts at 2026-11-30T04:10:40-05:00
Don't consider pending I/O for early context switch optimisation
Context switches are normally initiated by the timer signal. If however
the user specifies "context switch as often as possible", with +RTS -C0
then the scheduler arranges for an early context switch (when it's just
about to run a Haskell thread).
Context switching very often is expensive, so as an optimisation there
cases where we do not arrange an early context switch:
1. if there's no other threads to run
2. if there is no pending I/O or timers
This patch eliminates case 2, leaving only case 1.
The rationale is as follows. The use of this was inconsistent across
platforms and threaded/non-threaded RTS ways. It only worked on the
non-threaded RTS and on Windows only worked for the win32-legacy I/O
manager. On all other combinations anyPendingTimeoutsOrIO would always
return false. The fact that nobody noticed and complained about this
inconsistency suggests that the feature is not relied upon.
If however it turns out that applications do rely on this, then the
proper thing to do is not to restore this check, but to add a new I/O
manager hint function that returns if there is any pending events that
are likely to happen *soon*: for example timeouts expiring within one
timeslice, or I/O waits on things likely to complete soon like disk I/O,
but not for example socket/pipe I/O.
The motivation to avoid this use of anyPendingTimeoutsOrIO is to
allow us to eliminate anyPendingTimeoutsOrIO entirely. All other uses
of this are just guards on {await,poll}CompletedTimeoutsOrIO and
the guards can safely be folded into those functions. This will better
cope with some I/O managers having no proper implementation of
anyPendingTimeoutsOrIO.
Ultimately this will let us simplify the scheduler which currently has
to have special #ifdef mingw32_HOST_OS cases to cope with the lack of a
working anyPendingTimeoutsOrIO for some Windows I/O managers
- - - - -
cf8f2888 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Remove anyPendingTimeoutsOrIO guarding {poll,await}CompletedTimeoutsOrIO
Previously the API of the I/O manager used a two step process: check
anyPendingTimeoutsOrIO and then call {poll,await}CompletedTimeoutsOrIO.
This was primarily there as a performance thing, to cheaply check if we
need to do anything.
And then because anyPendingTimeoutsOrIO existed, it was used for other
things too. We have now eliminated the other uses, and are just left
with the performance pattern.
But this was problematic because not all I/O managers correctly
implement anyPendingTimeoutsOrIO (specifically the win32 ones), and now
that we also make I/O managers responsible for signals then we need to
poll/await even if there is no pending I/O or timeouts. If there is no
pending I/O or timeouts then await needs to degenerate to just waiting
forever for any signals.
- - - - -
a1d2e786 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Remove anyPendingTimeoutsOrIO, it is no longer used
And this avoids the problems arising from the win32 I/O managers having
had a bogus implementation.
- - - - -
61769cec by Duncan Coutts at 2026-11-30T04:10:40-05:00
Remove second scheduler call to awaitCompletedTimeoutsOrIO
Previously awaitCompletedTimeoutsOrIO was called both before and after
deadlock detection in the scheduler. The reason for that was that the
win32 I/O managers had a bogus implementation of anyPendingTimeoutsOrIO
and this was used to guard the call of awaitCompletedTimeoutsOrIO prior
to deadlock detection. This meant the first call site was never actually
called when using the win32 I/O managers. This was the reason for the
second call: the first one was never used. What a mess.
So now we have a simple design in the scheduler:
1. poll for completed I/O, timers or signals
2. if no runnable threads: do deadlock detection
3. if still no runnable threads: block waiting for I/O, timers or
signals.
- - - - -
c4de27e0 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Lift emptyRunQueue guard out of scheduleDetectDeadlock
this improved the clarity of the logic when reading the scheduler code.
And improve the comment about scheduleDoGC that was rather unclear.
- - - - -
b53a9113 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Make interruptIOManager work for WinIO (non-threaded)
Fixes #27403
The idle GC scheme now fundamentally relies on interruptIOManager
working, so it's no longer acceptable for it to be missing for WinIO.
Not having it would cause lock ups.
- - - - -
7eb3b4bd by Duncan Coutts at 2026-11-30T04:10:40-05:00
Make non-threaded deadlock detection also rely on idle GC
Only do deadlock detection GC when idle GC kicks in. This also relies on
using wakeUpRts, so now do this unconditionally. Previously wakeUpRts
was for the threaded rts only.
- - - - -
b32b1f2a by Duncan Coutts at 2026-11-30T04:10:40-05:00
Enable idle GC by default on non-threaded RTS
The behaviour is now uniform between the threaded and non-threaded RTS
ways. The deadlock detection now relies on idle GC for both threaded
and non-threaded ways. Previously deadlock detection did not rely on
idle GC for the non-threaded way.
Also tweak test T7275 to account for idle GC. This test's output is
sensitive to the number of major GCs run. Since this commit enables idle
GC for the non-threaded RTS, for this test that increases the number of
major GCs, since the test program is frequently idle for more than 300ms.
- - - - -
a1939765 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Fix state of idle GC control vars with +RTS -V0
Currently when the user uses +RTS -I0, then doIdleGC is set to false.
But if the master tick interval -V is set to 0 then the idleGCDelayTime
was being set to 0 but doIdleGC was not being set to false, which is
inconsistent, and almost certainly buggy.
- - - - -
90285b5c by Duncan Coutts at 2026-11-30T04:10:40-05:00
Add a long Note [Deadlock detection]
It describes the historical and modern designs and their trade-offs.
The point is we've now unified the code for deadlock detection between
the threaded and non-threaded ways, by changing the non-threaded to
follow the same design as the threaded.
- - - - -
3747864c by Duncan Coutts at 2026-11-30T04:10:40-05:00
Refactor the utils providing the I/O timeout for different system APIs
We have to provide a timeout in three different time formats (int
milliseconds, struct timeval *, and struct timespec *). These are for
platform APIs including poll, select, ppoll, pselect, epoll_wait,
epoll_wait2 and in future kevent and io_uring.
Previously we had one util for each format that both worked out what
the timeout should be and converted it into the particular format. This
duplicates some logic and it also makes it awkward to modify the timeout
value (since there's no common format).
Modifying the timeout value is exactly what we want to do, in a
subsequent commit, where we want to adjust the timeout to take account
of idle GC.
- - - - -
a65d0b02 by Duncan Coutts at 2026-11-30T04:10:40-05:00
Update the old select I/O manager to use the new timeout utils
This will make it much easier to adjust the timeout to take account of
idle GC.
- - - - -
46ae539f by Duncan Coutts at 2026-11-30T04:10:40-05:00
Add opportunistic deadlock detection without idle GC
Our general design is now that comprehensive deadlock detection relies
on idle GC. This allows us to detect partial deadlocks that are not
system deadlocks. But it's not prompt.
It's a nice to have feature to be able to promptly detect the cases that
are system deadlocks. There's no hope to do this in the threaded RTS
with -N > 1, but it can be done for the non-threaded RTS and _could_ be
done for the threaded RTS with -N1.
We can integrate this feature into the general design without too many
contortions. We just need the I/O managers to check before sleeping if
they would be about to sleep indefinately with no I/O and no registered
signal handlers. If so, they can notify the idle GC that we're
deadlocked and we schedule and idle GC.
- - - - -
9f964bcf by Duncan Coutts at 2026-11-30T04:10:41-05:00
Add idle GC mode for !HAVE_PREEMPTION
We have to do idle GC (and thus deadlock detection) differently when we
do not have the ticker and the ability to interrupt the I/O manager
when it's blocking.
- - - - -
257f8e57 by Duncan Coutts at 2026-11-30T04:10:41-05:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
5d077511 by Duncan Coutts at 2026-11-30T04:10:41-05:00
Add performDeadlockDetection and export via ghc-experimental
When documenting the idle GC and deadlock detection behaviour in the
user guide, it becomes obiovus that in some cases one would want manual
control over deadlock detection.
In particular, for applications that disable idle GC, for debugging or
robustness, they may want to invoke deadlock detecting GC manually.
Bind it in ghc-internal GHC.Internal.System.Mem and re-export via
ghc-experimental in System.Mem.Experimental. It is clearly
implementation specific behaviour, especially since in GHC the deadlock
detection is tied to doing a major GC.
- - - - -
7dc34c0f by Duncan Coutts at 2026-11-30T04:10:41-05:00
Add tests for deadlock detection, issue #26408
We have three tests:
T26408a: make sure that we can detect a /partial deadlock/ that is not
also a /system deadlock/
T26408b: make sure that we can detect a /system deadlock/ promptly
without relying on idle GC
T26408c: make sure that we do not falsely detect a deadlock when there is
nothing to do except wait on signals
T26408d: test that performDeadlockDetection works
T26408e: make sure that we can detect a system deadlock with idle GC
disabled, after the idle GC timeout has elapsed.
T26408f: same as e but with manually invoked major GC
- - - - -
ed9cc1f5 by Duncan Coutts at 2026-11-30T04:10:41-05:00
Update the user guide with the revised idle GC behaviour
It's now not just for the threaded RTS, but general.
Add a new section in the RTS chapter: Idle GC and deadlock detection.
Provide general documentation on both topics. In particular, document
the behaviour of deadlock detection and how it depends on idle GC.
Move the existing entries for -I and -Iw to this section.
Add a changelog entry.
- - - - -
56 changed files:
- + changelog.d/idle-gc-and-deadlock-detection
- docs/users_guide/profiling.rst
- docs/users_guide/runtime_control.rst
- libraries/ghc-experimental/src/System/Mem/Experimental.hs
- libraries/ghc-internal/src/GHC/Internal/System/Mem.hs
- rts/Capability.c
- rts/IOManager.c
- rts/IOManager.h
- + rts/IdleGC.c
- + rts/IdleGC.h
- rts/Linker.c
- rts/RtsFlags.c
- rts/RtsSignals.h
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/Schedule.c
- rts/Schedule.h
- rts/Timer.c
- rts/include/rts/OSThreads.h
- rts/include/rts/storage/GC.h
- rts/js/environment.js
- rts/posix/Poll.c
- rts/posix/Poll.h
- rts/posix/Select.c
- rts/posix/SelectBis.c
- rts/posix/SelectBis.h
- rts/posix/Signals.c
- − rts/posix/Signals.h
- rts/posix/Timeout.c
- rts/posix/Timeout.h
- rts/rts.cabal
- rts/win32/AsyncMIO.c
- rts/win32/AsyncMIO.h
- rts/win32/AsyncWinIO.c
- rts/win32/AsyncWinIO.h
- rts/win32/AwaitEvent.c
- rts/win32/ConsoleHandler.c
- rts/win32/ConsoleHandler.h
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- testsuite/tests/profiling/should_run/Makefile
- testsuite/tests/rts/Makefile
- + testsuite/tests/rts/T26408a.hs
- + testsuite/tests/rts/T26408a.stderr
- + testsuite/tests/rts/T26408b.hs
- + testsuite/tests/rts/T26408b.stderr
- + testsuite/tests/rts/T26408c.hs
- + testsuite/tests/rts/T26408c.stdout
- + testsuite/tests/rts/T26408d.hs
- + testsuite/tests/rts/T26408d.stderr
- + testsuite/tests/rts/T26408e.hs
- + testsuite/tests/rts/T26408e.stderr
- + testsuite/tests/rts/T26408f.hs
- + testsuite/tests/rts/T26408f.stderr
- testsuite/tests/rts/all.T
- testsuite/tests/rts/symbols/rts-check-symbols.stdout
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1d5c87ce0834e7142ce3881ac4ed33…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1d5c87ce0834e7142ce3881ac4ed33…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][master] x86-64 NCG: check that address displacements fit in 32 bits (#28105)
by Marge Bot (@marge-bot) 30 Nov '26
by Marge Bot (@marge-bot) 30 Nov '26
30 Nov '26
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
51e14298 by Sylvain Henry at 2026-11-30T04:13:04-05:00
x86-64 NCG: check that address displacements fit in 32 bits (#28105)
Three clauses of getAmode put a constant in the displacement of an
address without a valid check that it fits in a signed 32-bit integer,
so the assembler rejected the module:
- x + ((y << shift) + offset): the guard checked the offset only for
shift 3, because && binds tighter than ||.
- CmmRegOff x offset + (y << shift): no check.
- x - lit: the guard checked lit, but the displacement is -lit, which
does not fit for lit = -2^31.
Each clause now checks the constant that goes in the displacement and
narrows it to the target word width, as litToImm does: the Integer of
a CmmInt can be out of the range of its width, and truncation with the
host Int is wrong for a 64-bit host that compiles for a 32-bit target.
When the constant does not fit, the clause does not match and a later
clause computes it in a register.
See Note [Displacements fit in 32 bits].
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
5 changed files:
- + changelog.d/28105
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- + testsuite/tests/codeGen/should_compile/T28105.cmm
- + testsuite/tests/codeGen/should_compile/T28105b.hs
- testsuite/tests/codeGen/should_compile/all.T
Changes:
=====================================
changelog.d/28105
=====================================
@@ -0,0 +1,10 @@
+section: codegen
+synopsis: x86-64 NCG: never emit an address displacement that does not fit in 32 bits
+issues: #28105
+mrs: !17002
+description: {
+ Three address forms in the x86-64 native code generator put a constant into
+ the displacement of an address without checking that it fits in a signed
+ 32-bit integer, so the assembler rejected the module. The constant is now
+ computed in a register when it does not fit.
+}
=====================================
compiler/GHC/CmmToAsm/X86/CodeGen.hs
=====================================
@@ -3466,6 +3466,8 @@ getAmode :: CmmExpr -> NatM Amode
getAmode e = do
platform <- getPlatform
let is32Bit = target32Bit platform
+ -- See Note [Displacements fit in 32 bits]
+ fits_disp n = is32BitInteger (narrowS (wordWidth platform) n)
case e of
CmmRegOff r n
@@ -3477,12 +3479,14 @@ getAmode e = do
-- This is all just ridiculous, since it carefully undoes
-- what mangleIndexTree has just done.
- CmmMachOp (MO_Sub _rep) [x, CmmLit lit@(CmmInt i _)]
- | is32BitLit platform lit
+ -- The displacement is -i: check that it fits, not i. See
+ -- Note [Displacements fit in 32 bits].
+ CmmMachOp (MO_Sub _rep) [x, CmmLit (CmmInt i _)]
+ | fits_disp (negate i)
-- assert (rep == II32)???
-> do
(x_reg, x_code) <- getSomeReg x
- let off = ImmInt (-(fromInteger i))
+ let off = litToImm (CmmInt (negate i) (wordWidth platform))
return (Amode (AddrBaseIndex (EABaseReg x_reg) EAIndexNone off) x_code)
CmmMachOp (MO_Add _rep) [x, CmmLit lit]
@@ -3499,18 +3503,21 @@ getAmode e = do
-> getAmode (CmmMachOp (MO_Add rep) [b,a])
-- Matches: (x + offset) + (y << shift)
+ -- See Note [Displacements fit in 32 bits].
CmmMachOp (MO_Add _) [CmmRegOff x offset, CmmMachOp (MO_Shl _) [y, CmmLit (CmmInt shift _)]]
- | shift == 0 || shift == 1 || shift == 2 || shift == 3
+ | is_scale shift
+ , fits_disp (fromIntegral offset)
-> x86_complex_amode (CmmReg x) y shift (fromIntegral offset)
CmmMachOp (MO_Add _) [x, CmmMachOp (MO_Shl _) [y, CmmLit (CmmInt shift _)]]
- | shift == 0 || shift == 1 || shift == 2 || shift == 3
+ | is_scale shift
-> x86_complex_amode x y shift 0
+ -- See Note [Displacements fit in 32 bits].
CmmMachOp (MO_Add _) [x, CmmMachOp (MO_Add _) [CmmMachOp (MO_Shl _)
[y, CmmLit (CmmInt shift _)], CmmLit (CmmInt offset _)]]
- | shift == 0 || shift == 1 || shift == 2 || shift == 3
- && is32BitInteger offset
+ | is_scale shift
+ , fits_disp offset
-> x86_complex_amode x y shift offset
CmmMachOp (MO_Add _) [x,y]
@@ -3556,6 +3563,36 @@ getAmode e = do
is_label (CmmLabelDiffOff{}) = True
is_label _ = False
+ -- the scales an index register can have: 1, 2, 4, 8
+ is_scale shift = shift >= 0 && shift <= 3
+
+{- Note [Displacements fit in 32 bits]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+An x86-64 address with a base or an index register has a 32-bit sign-extended
+displacement. The assembler rejects a larger one:
+
+ movq 4294967296(%rbx,%r14,4),%rbx
+ Error: 0x100000000 out of range of signed 32bit displacement
+
+So each clause of getAmode that puts a constant in the displacement must check
+that it fits (fits_disp). When the check fails, the clause does not match and
+a later clause computes the constant in a register instead (#15570, #28105).
+This is independent of the code model: the constant is added to a pointer in
+a register, which can point anywhere. Labels are the concern of is32BitLit,
+see Note [%rip-relative addressing on x86-64].
+
+Two details:
+
+- For x - lit the displacement is -lit, so the check is on -lit: lit = -2^31
+ fits but -lit does not.
+
+- The Integer of a CmmInt can be out of the range of its width (see CmmLit).
+ So the check and the emitted immediate both narrow the constant to the
+ word width of the target, as litToImm does. On a 32-bit target every
+ narrowed constant fits. Narrowing with the host Int (fromInteger) is not
+ enough: a 64-bit host that compiles for a 32-bit target would emit the
+ constant unchanged.
+-}
-- | Like 'getAmode', but the amode stays valid across the code of other
-- expressions: if a register of the amode could be clobbered, the
@@ -3600,7 +3637,8 @@ getSimpleAmode addr = is32BitPlatform >>= \case
x86_complex_amode :: CmmExpr -> CmmExpr -> Integer -> Integer -> NatM Amode
x86_complex_amode base index shift offset
- = do (x_reg, x_code) <- getNonClobberedReg base
+ = do platform <- getPlatform
+ (x_reg, x_code) <- getNonClobberedReg base
-- x must be in a temp, because it has to stay live over y_code
-- we could compare x_reg and y_reg and do something better here...
(y_reg, y_code) <- getSomeReg index
@@ -3608,7 +3646,10 @@ x86_complex_amode base index shift offset
code = x_code `appOL` y_code
base = case shift of 0 -> 1; 1 -> 2; 2 -> 4; 3 -> 8;
n -> panic $ "x86_complex_amode: unhandled shift! (" ++ show n ++ ")"
- return (Amode (AddrBaseIndex (EABaseReg x_reg) (EAIndex y_reg base) (ImmInt (fromIntegral offset)))
+ -- narrow the offset to the word width, like litToImm: a CmmInt
+ -- can be out of range. See Note [Displacements fit in 32 bits].
+ off = ImmInteger (narrowS (wordWidth platform) offset)
+ return (Amode (AddrBaseIndex (EABaseReg x_reg) (EAIndex y_reg base) off)
code)
=====================================
testsuite/tests/codeGen/should_compile/T28105.cmm
=====================================
@@ -0,0 +1,19 @@
+#include "Cmm.h"
+
+// Each procedure exercises a clause of getAmode in the x86-64 NCG that put
+// a constant outside the signed 32-bit range in the address displacement.
+
+// x + ((y << shift) + offset), shift below 3
+shifted (W_ p, W_ i) {
+ return (I64[((p - 4294967296) + (i << 2)) + 4294967296]);
+}
+
+// CmmRegOff x offset + (y << shift)
+regoff (W_ p, W_ i) {
+ return (I64[(p + 4294967296) + (i << 2)]);
+}
+
+// x - lit, with -lit outside the range
+subneg (W_ p) {
+ return (I64[I64[p] - (-2147483648)]);
+}
=====================================
testsuite/tests/codeGen/should_compile/T28105b.hs
=====================================
@@ -0,0 +1,12 @@
+{-# LANGUAGE MagicHash #-}
+module T28105b where
+
+import GHC.Exts
+
+-- I8[R2 + ((R3 << 2) + 4294967296)]
+f :: Addr# -> Int# -> Word8#
+f a i = indexWord8OffAddr# a (i *# 4# +# 4294967296#)
+
+-- I8[(R2 + 4294967296) + (R3 << 2)]
+g :: Addr# -> Int# -> Word8#
+g a i = indexWord8OffAddr# (plusAddr# a 4294967296#) (i *# 4#)
=====================================
testsuite/tests/codeGen/should_compile/all.T
=====================================
@@ -156,3 +156,6 @@ test('T27979', [req_cmm, check_errmsg('stg_ap_0_fast')], compile, ['-O -ddump-cm
test('T27694', normal, compile, ['-dasm-lint'])
test('T27694c', normal, compile, ['-O -dasm-lint'])
test('T27694d', normal, compile, ['-O2 -dasm-lint'])
+
+test('T28105', [cmm_src, when(unregisterised(), skip), when(wordsize(32), skip)], compile, ['-no-hs-main'])
+test('T28105b', [when(unregisterised(), skip), when(wordsize(32), skip)], compile, ['-O -Wno-overflowed-literals'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51e1429855049a9e77720ed6d5cf964…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51e1429855049a9e77720ed6d5cf964…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0