[Git][ghc/ghc] Pushed new branch wip/supersven/riscv-ncg-mul2
by Sven Tennie (@supersven) 28 Nov '26
by Sven Tennie (@supersven) 28 Nov '26
28 Nov '26
Sven Tennie pushed new branch wip/supersven/riscv-ncg-mul2 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/supersven/riscv-ncg-mul2
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/marge_bot_batch_merge_job] 43 commits: Move idle GC tracking to its own file, step 1 of 2
by Marge Bot (@marge-bot) 28 Nov '26
by Marge Bot (@marge-bot) 28 Nov '26
28 Nov '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
cfa5e489 by Duncan Coutts at 2026-11-28T11:14:40-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.
- - - - -
04d5046b by Duncan Coutts at 2026-11-28T11:14:40-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.
- - - - -
32a539b4 by Duncan Coutts at 2026-11-28T11:14:40-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.
- - - - -
df5d9667 by Duncan Coutts at 2026-11-28T11:14:40-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.
- - - - -
1c69e202 by Duncan Coutts at 2026-11-28T11:14:40-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.
- - - - -
6c3310f0 by Duncan Coutts at 2026-11-28T11:14:40-05:00
Remove variable n_haskell_handlers which has become write-only
The previous commit removed the last read of this variable.
- - - - -
faaadfcf by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
06144e7a by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
6cdc7d5d by Duncan Coutts at 2026-11-28T11:14: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
- - - - -
082fef37 by Duncan Coutts at 2026-11-28T11:14: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
- - - - -
aa0ed321 by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
82c6358a by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
a135990c by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
69999ea5 by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
8c78737e by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
2e46f07e by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
f196abe8 by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
50f5f83d by Duncan Coutts at 2026-11-28T11:14:41-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.
- - - - -
01c6d780 by Duncan Coutts at 2026-11-28T11:14:41-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.
- - - - -
fc7872d1 by Duncan Coutts at 2026-11-28T11:14:41-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.
- - - - -
463d9a99 by Duncan Coutts at 2026-11-28T11:14:41-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.
- - - - -
9433de9f by Duncan Coutts at 2026-11-28T11:14:41-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.
- - - - -
5c1ad733 by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
9fe96277 by Duncan Coutts at 2026-11-28T11:14:41-05:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
5981641d by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
c2bf7468 by Duncan Coutts at 2026-11-28T11:14: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
- - - - -
fc627960 by Duncan Coutts at 2026-11-28T11:14: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.
- - - - -
b245f840 by Wolfgang Jeltsch at 2026-11-28T11:14:42-05:00
Clean up the language specification in `GHCi.ResolvedBCO`
- - - - -
44a8a1c6 by Wolfgang Jeltsch at 2026-11-28T11:14:42-05:00
Make the `BCOByteArray` serialization format platform-independent
- - - - -
dd20ac95 by Simon Peyton Jones at 2026-11-28T11:14:43-05:00
Make pushCast pure, and move it to Simplify.Utils
pushCast and pushCastMCo were in the SimplM monad, but no longer do
anything monadic. (Historically, pushing a coercion into an argument
used to simplify that argument; but now the coercion is recorded in
the sc_cast field of ApplyToVal.)
This patch makes them pure functions, and moves them, together with
addCastMCo, optOutCoercion and Note [The sc_cast field of ApplyToVal],
from GHC.Core.Opt.Simplify.Iteration to GHC.Core.Opt.Simplify.Utils,
alongside the SimplCont type they manipulate.
No change in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
7df69f79 by Simon Peyton Jones at 2026-11-28T11:14:43-05:00
Lambda and case binders have vanilla IdInfo (#27965)
Lambda binders, case binders, and case-alternative binders should never
have RULES, a (non-default) inline pragma, or a stable unfolding.
See new Note [Core binder IdInfo invariants] in GHC.Core, which
lays out the invariants.
This patch
* Makes Core Lint check the invariant, using the new predicate
GHC.Types.Id.lamBndrInfoOK.
* Fixes the desugarer, which violated it. For a strict binding
let !x = rhs in body
we generate
let x = rhs in case x of x { DEFAULT -> body }
re-using x (shadowed) as the case binder; see Note [Desugar Strict binds].
But the case binder inherited x's IdInfo, including, say, a NOINLINE
pragma (e.g. `res1` in GHC.Internal.Control.Monad.ST.Lazy.Imp). Now
GHC.HsToCore.Utils.seqVar gives the case binder vanilla IdInfo.
This was not just a matter of taste. For example
h fm s = let {-# NOINLINE res1 #-}
!res1 = fm s
!(f, s') = res1
in (f+1, s')
The NOINLINE case binder becomes a NOINLINE alias `let res3 = res2`,
which is never inlined, and survives (as a silly join point) into the
final code.
* Fixes the Simplifier, which could violate it when duplicating a
StrictBind continuation, which makes a join point
let x = <> in b ==> join j x = b in j <>
If x has any IdInfo that isn't allowed in a lambda-binder, we now zap the
IdInfo in the join point:
let x = <> in b ==> join j x' = b in j <>
where x' is like x (definitely the same unique) but with zapped IdInfo.
See (SB3) in Note [StrictBind].
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
fbe7d2e3 by Simon Peyton Jones at 2026-11-28T11:14:43-05:00
Add varIsHNF, and use it in move_transit_vars
`varIsHNF v` is the same as `exprIsHNF (Var v)`, but avoids building the
Var only to take it apart. The (Var v) case of exprIsHNFlike now uses
the shared varIsHNFlike, so the two cannot drift apart.
In GHC.Core.Opt.WorkWrap.Utils.move_transit_vars we had the guard
isUnliftedType var_ty || exprIsHNF (Var var)
but exprIsHNF is already True of variables of (definitely) unlifted type,
so the isUnliftedType test was redundant. Now it is just (varIsHNF var).
Also make `exprIsHNFlike` treat an application with no value arguments, such as
`f @Int`, exactly like the bare variable `f`, by going through varIsHNFlike.
Otherwise no change in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
6ff53399 by Simon Peyton Jones at 2026-11-28T11:14:44-05:00
Use SimplClo for the argument of ApplyToVal
This patch renames SimplSR to SimplClo (a "closure"), and uses it not
only as the range of the Simplifier's substitution, but also as the
argument of an ApplyToVal continuation. ApplyToVal used to have three
fields
sc_env :: StaticEnv
sc_arg :: CoreExpr
sc_cast :: MOutCoercion
but now has just
sc_dup :: DupFlag
sc_arg :: SimplClo
An un-simplified argument is (ContEx env arg mco), and an already-simplified
one is (DoneEx arg _). See Note [The argument of ApplyToVal] in
GHC.Core.Opt.Simplify.Utils.
The main payoff is that, since the substitution maps an Id to a SimplClo,
beta-reduction can substitute the argument for the lambda binder without
further ado. Accordingly, preInlineUnconditionally is split into
* preInlineLetUnconditionally, for let-bindings
* preInlineBetaUnconditionally, for beta-redexes, which takes a SimplClo
The latter omits some checks that cannot fire for lambda binders.
Other notes
* The new (ContEx env arg mco) form makes it easy to push a cast into an
argument (mkCloCastMCo), whether or not it has been simplified.
See Note [The MOutCoercion field of ContEx].
* `preInlineUnconditionally` gets split into two variants, one for
let-bindings and one for beta-reduction (which takes a `SimplClo`).
There is a little bit of duplication here, but not much.
* Fixes #27962. The simplifier was previously dropping a cast when dealing
with runRW#. The new `SimplClo` makes that bug much harder to allow.
* Fixes #27963. contOutArgs, which supplies the arguments for Plan (BEFORE)
rule matching, ignored the sc_cast field of ApplyToVal. So in
(f |> co) n ==> f (n |> co1) -- co1 in sc_cast
a rule for `f` saw `f n` rather than `f (n |> co1)`, and failed to match
(the rule matcher checks the types of template variables). If f's
unfolding is active, f may then be inlined, and the rule is lost for
good. Now contOutArgs uses simplCloExpr, which includes the pending cast.
Almost no change in behaviour, except for the #27963 bug-fix.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
34c2eec3 by Simon Peyton Jones at 2026-11-28T11:14:44-05:00
Add splitThunkCpr
This commit adds GHC.Core.Opt.WorkWrap.splitThunkCpr, which adds a form
of "thunk splitting" for strict bindings that have CPR information.
See Note [Thunk splitting] in WorkWrap.hs for the details.
It catches a previously-unrecognised optimisation opportunity
(see #28158) but it only helps in fairly obscure cases, so
I don't expect a big impact in practice.
As usually I did lots of refactoring along the way.
LLM disclosure: lots of interaction with Claude, but I wrote all the
code and comments.
- - - - -
9f940522 by sheaf at 2026-11-28T11:14:51-05:00
Make FunDepEqns a non-empty list
This avoids creating a 'FunDepEqns' with no equations. This means that
consumers dealing with [FunDepEqns] can reliably use "null fun_dep_eqns"
to decide whether there are any equations.
- - - - -
dcdcff09 by sheaf at 2026-11-28T11:14:52-05:00
tryFamEqFunDeps: (CF1) only for closed tyfams
This commit makes (CF1) in Note [Exploiting closed type families] only
apply to *closed* type families, not *open* type families.
This allows the program reported in #28082 to continue to be accepted,
fixing a regression.
Fixes #28082
- - - - -
57cc1d3c by Rodrigo Mesquita at 2026-11-28T11:14:53-05:00
test: make T3171 not fragile and add version for ext interp too
- actually test the sleep of the user-given expression gets interrupted
- the ext interp version tests two things:
- Requests can be cancelled without terminating the ext interp (#18852)
- The stmt being evaluated gets interrupted in the ext interp (that
is, ^C gets sent to the thread running the user-given expression
and doesn't affect the ext interp main thread)
- testing ext interp requires sending ^C to whole process group
Fixes #15383
- - - - -
8aa931da by Rodrigo Mesquita at 2026-11-28T11:14:53-05: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
- - - - -
605a9b04 by Rodrigo Mesquita at 2026-11-28T11:14:53-05: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.
- - - - -
43b6e742 by Sylvain Henry at 2026-11-28T11:15:00-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>
- - - - -
63d1d19e by David Eichmann at 2026-11-28T11:15:02-05:00
testsuite: fix framework failure on window for tests using all_available_io_managers_except()
- - - - -
f6cfc4a8 by David Eichmann at 2026-11-28T11:15:02-05:00
testsuite: use `all_available_io_managers` for various tests
Affected tests:
* T10590
* T21969
* T21969a
* T21969b
* T21969c
* T21969d
* T21969e
* T21969f
- - - - -
774c721a by Sylvain Henry at 2026-11-28T11:15:08-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>
- - - - -
162 changed files:
- .gitlab/ci.sh
- + changelog.d/28105
- + changelog.d/28124
- + changelog.d/T27962
- + changelog.d/T27963
- + changelog.d/T28082
- + changelog.d/idle-gc-and-deadlock-detection
- compiler/GHC/Builtin/WiredIn/Ids.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/Core.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Make/Box.hs
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/Simplify/Env.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/WorkWrap.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Core/Ppr.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Config.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Runtime/Eval/Types.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Tc/Instance/FunDeps.hs
- compiler/GHC/Tc/Solver/FunDeps.hs
- compiler/GHC/Types/Cpr.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Utils/Monad.hs
- 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
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/ResolvedBCO.hs
- libraries/ghci/GHCi/Run.hs
- + libraries/ghci/GHCi/Run/Breakpoints.hs
- libraries/ghci/ghci.cabal.in
- rts/Capability.c
- rts/IOManager.c
- rts/IOManager.h
- + rts/IdleGC.c
- + rts/IdleGC.h
- rts/Interpreter.c
- 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/driver/testutil.py
- + testsuite/tests/codeGen/should_compile/T28105.cmm
- + testsuite/tests/codeGen/should_compile/T28105b.hs
- testsuite/tests/codeGen/should_compile/all.T
- 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/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
- + 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/T3171.stdout
- + testsuite/tests/ghci/should_run/T3171ext.stdout
- + testsuite/tests/ghci/should_run/T3171extnosandbox.stdout
- + testsuite/tests/ghci/should_run/T3171nosandbox.stdout
- testsuite/tests/ghci/should_run/all.T
- + testsuite/tests/indexed-types/should_compile/T28082.hs
- testsuite/tests/indexed-types/should_compile/all.T
- 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
- testsuite/tests/simplCore/should_compile/T15445.stderr
- + testsuite/tests/simplCore/should_compile/T27962.hs
- + testsuite/tests/simplCore/should_compile/T27963.hs
- + testsuite/tests/simplCore/should_compile/T27963.stderr
- + testsuite/tests/simplCore/should_compile/T27965.hs
- + testsuite/tests/simplCore/should_compile/T27965a.hs
- + testsuite/tests/simplCore/should_compile/T27965b.hs
- + testsuite/tests/simplCore/should_compile/T28158.hs
- + testsuite/tests/simplCore/should_compile/T28158.stderr
- testsuite/tests/simplCore/should_compile/all.T
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ea95d108583659c20d1fe3012cd36a…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ea95d108583659c20d1fe3012cd36a…
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/az/exactprint-annotation-rationalisation] 64 commits: Use a different herald for -ddump-simpl-trace
by Alan Zimmerman (@alanz) 28 Nov '26
by Alan Zimmerman (@alanz) 28 Nov '26
28 Nov '26
Alan Zimmerman pushed to branch wip/az/exactprint-annotation-rationalisation at Glasgow Haskell Compiler / GHC
Commits:
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.
- - - - -
8870d3e2 by Alan Zimmerman at 2026-11-28T13:12:16+00: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.
- - - - -
ddc9ccb8 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:EPA: Make EpVirtualBraces noSpanAnchor if no contents
Otherwise the vocurly is emitted at the start of the next
item parsed
Check: is this needed, or just a check for empty contents?
- - - - -
22c5d138 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:Align with ghc-exactprint
- - - - -
4ff724fa by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:EPA: Fix AnnList leading semis when layout
When there is layout, anything printed triggers it, including leading
semis.
Add some test case examples too
- - - - -
7f9947e6 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
MOVE EPA: Plan for Fixing AnnList Layout Properly
Also Exactprint layout scope plan
- - - - -
5c194a07 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:Exactprint: tidy up layout capturing
- - - - -
b7bca6d1 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F:MD:EPA: add makeDelta test for Test20297
The original #20297 related to comment placement for exact printing
after running ExactPrint.makeDelta on ParsedSource. Add an additional
test that explicitly tests this.
- - - - -
12a2c29d by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make ValBinds LocatedA in HsLocalBindsLR
If we have items with an AnnList Annotation, as part of another, which
has different content, it must be LocatedA. This is a technical requirement
due to the way comment allocation happens during the makeDelta processing.
Comments are queued for printing, and as soon as any non-comment is to
be printed, the pending comments before that position are printed, and
in makeDelta processing these attached as preceding comments to the thing
just printed.
The means they end up captured inside the layout region of the AnnList item.
So for
foo = x
where -- comment
x = 3
the comment ends up as a preceding comment of `x = 3`, inside the
layout, and prints as
foo = x
where
-- comment
x = 3
- - - - -
2b7a6eb6 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make IPBinds LocatedA
- - - - -
52bd87dd by Alan Zimmerman at 2026-11-28T13:14:52+00:00
[WIP] EPA: adding some notes to ExactPrint
- - - - -
a5ac5b23 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make ClsInstDecl decls LocatedA
- - - - -
38069bab by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:EPA: Make ClassDecls decls LocatedA
- - - - -
5cab4688 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make ClosedTypeFamily equations Located
For FamilyDecl/ClosedTypeFamily
- - - - -
fb88afd3 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Perf ok:EPA: Make dd_cons located
- - - - -
d37944e3 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make HsMultiIf options located
- - - - -
c96fa5b3 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make DecBrl contents LocatedA
- - - - -
d3ac741b by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Located do statements
- - - - -
d6b48038 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Print RecStmt located
- - - - -
f53ecc3e by Alan Zimmerman at 2026-11-28T13:14:52+00:00
P:EPA: HsCmdDo Located
- - - - -
b24d6ed4 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Extend Test20297 for additional occurrences
- - - - -
dacf1bb7 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Tweak PatSynBind location for comments
- - - - -
eed883b9 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: WIP, add test for where ;; ValBinds
- - - - -
51ef8d2c by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Make EpVirtualBraces noSpanAnchor if no contents
Otherwise the vocurly is emitted at the start of the next
item parsed
Check: is this needed, or just a check for empty contents?
- - - - -
5778b800 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Perf ok:EPA: Use EpNoLayout in AnnList with empty contents and no explicit braces
TODO: get rid of unused first arg to epVirtualBraces
- - - - -
7b51d959 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Perf ok:TODO: XClassDecl: remove additional EpLayout
- - - - -
ce92f682 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Perf ok:EPA: Remove CanUpdateAnchorOnly
- - - - -
bfd7f1bd by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Perf:decrese:EPA: Sync with ghc-exactprint after EPWriter -> CPS
- - - - -
69e1b4db by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Fix EpVirtualBraces for HsDo
The start of layout must include the leading semi, so we comb3 to
ensure it is included if the initial stmts are empty
- - - - -
8070cf32 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: ClsInstDecl where clause span
- - - - -
0aec7131 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: GADT parens printing, fix
- - - - -
ee3d1c65 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Plan update DO NOT COMMIT
- - - - -
93c166f5 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F1:EPA: fix AnnList opening span for some cases
F1 as per ANNLIST-LAYOUT-FINDINGS.md
- - - - -
234c60e8 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F2:EPA fix vocurly start
F2
- - - - -
b847460c by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F3:EPA multi way if
- - - - -
ecf762e7 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F4:EPA: Parse leading semis for gadt_contrs
- - - - -
99c86698 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA:F5: Leading semicolons dropped in closed-type-family bodies
- - - - -
6b028e9a by Alan Zimmerman at 2026-11-28T13:14:52+00:00
F6: ALR: skip, the feature is deprecated
- - - - -
4c51979b by Alan Zimmerman at 2026-11-28T13:14:52+00:00
[WIP]:F7 leading semi differences
- - - - -
eea83643 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: First pass implementation of HsList, for ClassDecls
Just as a straight list replacement to start with, no payload.
This shows the scope and invasiveness of the initial change
- - - - -
1ec33c64 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: HsList attempt WIP
- - - - -
c6aeaeaf by Alan Zimmerman at 2026-11-28T13:14:52+00:00
Enable ppr test for Haddock1. It currently fails
- - - - -
1b9f4098 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
WIP on removing NoEpAnn. Likely abandon
- - - - -
3bb2db61 by Alan Zimmerman at 2026-11-28T13:14:52+00:00
EPA: Add an overview doc for exact printing
- - - - -
7abe6442 by Simon Peyton Jones at 2026-11-28T13:14:52+00:00
Added an intro section
- - - - -
152 changed files:
- .gitlab-ci.yml
- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- + ANNLIST-LAYOUT-FINDINGS.md
- + ANNLIST-LAYOUT-PLAN.md
- + ExactPrint.md
- + LAYOUT-SCOPE-PLAN.md
- + changelog.d/T27212
- + changelog.d/fingerprint-caches-with-fast-string-keys
- changelog.d/ncg-x86-bit-test-instructions
- compiler/GHC/ByteCode/Binary.hs
- compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/Cmm.hs
- compiler/GHC/Cmm/ContFlowOpt.hs
- compiler/GHC/Cmm/Pipeline.hs
- compiler/GHC/CmmToAsm/Reg/Linear.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/Backpack.hs
- compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Main/Interactive.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Hs.hs
- compiler/GHC/Hs/Binds.hs
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/DocString.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/ImpExp.hs
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Stats.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Docs.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/HsToCore/Usage.hs
- compiler/GHC/Iface/Ext/Ast.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/PostProcess.hs
- compiler/GHC/Parser/PostProcess/Haddock.hs
- compiler/GHC/Rename/Bind.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Splice.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Tc/Zonk/Type.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax.hs
- compiler/Language/Haskell/Syntax/Basic.hs
- compiler/Language/Haskell/Syntax/Binds.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- compiler/Language/Haskell/Syntax/Decls.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- docs/users_guide/debug-info.rst
- docs/users_guide/using-optimisation.rst
- ghc/GHCi/UI.hs
- + 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/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/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/exactprint/Test20239.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/parser/should_compile/DumpParsedAst.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/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/perf/compiler/hard_hole_fits.stderr
- + testsuite/tests/printer/Layout.hs
- testsuite/tests/printer/Makefile
- testsuite/tests/printer/Ppr003.hs
- testsuite/tests/printer/T18052a.stderr
- testsuite/tests/printer/T18791.stderr
- + testsuite/tests/printer/Test20297.expected.hs
- testsuite/tests/printer/Test20297.hs
- testsuite/tests/printer/Test20297.stdout
- + testsuite/tests/printer/Test20297MD.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/printer/all.T
- 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
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Parsers.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hoogle.hs
- utils/haddock/haddock-api/src/Haddock/Backends/LaTeX.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/GhcUtils.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Create.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9def32b8d5e0e41919feae1fd45f76…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9def32b8d5e0e41919feae1fd45f76…
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/az/epa-tidy-locatedxxx-39] EPA: Introduce LayoutFrame stacks in ExactPrint state
by Alan Zimmerman (@alanz) 28 Nov '26
by Alan Zimmerman (@alanz) 28 Nov '26
28 Nov '26
Alan Zimmerman pushed to branch wip/az/epa-tidy-locatedxxx-39 at Glasgow Haskell Compiler / GHC
Commits:
8870d3e2 by Alan Zimmerman at 2026-11-28T13:12:16+00: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/8870d3e2a3ed95e91afc834cba673bc…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8870d3e2a3ed95e91afc834cba673bc…
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] Pushed new branch wip/az/epa-tidy-locatedxxx-39
by Alan Zimmerman (@alanz) 28 Nov '26
by Alan Zimmerman (@alanz) 28 Nov '26
28 Nov '26
Alan Zimmerman pushed new branch wip/az/epa-tidy-locatedxxx-39 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/az/epa-tidy-locatedxxx-39
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/ncg-notes] 31 commits: CoreMap: look up a non-recursive let with the key order of the store
by Mikolaj Konarski (@Mikolaj) 28 Nov '26
by Mikolaj Konarski (@Mikolaj) 28 Nov '26
28 Nov '26
Mikolaj Konarski pushed to branch wip/ncg-notes at Glasgow Haskell Compiler / GHC
Commits:
38d421fb by Sylvain Henry at 2026-11-16T16:02:22-05:00
CoreMap: look up a non-recursive let with the key order of the store
xtE stored a `Let (NonRec b r) e` with the body e as the first key and
the right-hand side r as the second key. lkE used the opposite order.
When a trie level holds one entry, GenMap compares the full keys with
(==), and the difference has no effect. When a trie level holds two
entries, a lookup of an expression with a non-recursive let fails. A
later insert of an equal expression then overwrites the first entry.
Now xtE stores the key in the order that lkE uses.
Effects of the bug: CSE did not share identical bindings when a module
had two different bindings that hold a non-recursive let or join point
(#27892). The pattern-match checker gave different representatives to
equal guard or view expressions, and thus reported spurious
non-exhaustive matches.
Fixes #27892.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
fa5bc4c0 by Sylvain Henry at 2026-11-16T16:02:22-05:00
CoreMap: ignore the multiplicities of binders
BndrMap keyed a binder on its type and on its multiplicity, and
eqDeBruijnExpr compared the multiplicities of lambda binders. But the
multiplicity of a let binder has no meaning (Note [Multiplicity of let
binders] in GHC.Types.Var), and Core-to-core passes do not keep the
multiplicities of lambda binders correct (Note [Linting linearity] in
GHC.Core.Lint). Thus the trie separated terms that are equal.
The key-order bug fixed in the previous commit hid this bug. With that
fix, the pattern-match checker gave different representatives to two
equal view expressions when one let came from the source and the other
let came from the beta-reduction of a linear lambda.
Now BndrMap is TypeMapG again, as before the linear types commit, and
eqDeBruijnExpr ignores the multiplicities of lambda binders. The
haddocks of CoreMap and eqCoreExpr state this contract.
Fixes #28095.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
fa6b8c9e by Simon Peyton Jones at 2026-11-16T16:03:04-05:00
Swap visibilities in mkSymCo
As #28123 showed, `mkSymCo` was failing to swap visibility flags
in `ForAllCo`.
Fixing that in turn showed that the change to `mkEtaForAllMCo` that
allegedly fixed #27557 was utterly wrong, and should simply be un-done.
I have added some comments to document the invariants.
- - - - -
cbe0a6bf by fendor at 2026-11-17T09:25:55-05:00
Add support for streaming `ghc -M` to stdout
Adds the flags `-dep-json-stdout` and `-dep-makefile-stdout` which
streams dependency information line-by-line to stdout.
Each dependency generation can be redirected to separate outputs.
Providing any extra `-dep-{json,makefile}[-stdout]` disables the default
generation of the `Makefile` file.
Allows consumers to start processing the dependency information as it
comes in and not waiting for the dependency generation to finish.
`DepStream` abstracts over the possible output handles, which is either
a file or the stdout handle.
Writing to a file requires temporary file paths, thus `DepStream` must
provide a way to perform clean up when dependency processing finished or
when an error is thrown for any reason.
We further decouple the rendering and writing of the result from the
dependency generation, localising side effects and making the code
slightly more readable.
The testsuite now also handles `ghc -M` writing to stdout.
We add a test for each combination of writing to stdout and file,
except for writing both makefile and json.
While it probably works, is really undefined behaviour.
Closes #27937
- - - - -
fbd49db2 by Sylvain Henry at 2026-11-17T09:27:09-05:00
Link the on-demand iserv without --gc-sections
GHC links an iserv program each time a session needs the external
interpreter. The link is static, against the ghci library and the boot
libraries. Like all executable links, it passed -Wl,--gc-sections to a
GNU linker. On libraries built with -split-sections (the release
bindists), the section garbage collection of ld.bfd is the largest part
of that link: with binutils 2.45, the link takes 3 times longer with
--gc-sections than without. The program is temporary and its size is
not important. Thus the iserv link does not use --gc-sections. Other
executable links do not change.
In CI, each ext-interp or ghci-ext test takes 12 to 18 times longer in
the x86_64-linux-fedora43-release test job (split sections) than in the
x86_64-linux-deb13-validate test job (no split sections) on the same
runner, while a normal-way test takes the same time in both. This link
is most of that difference.
See Note [No --gc-sections for the on-demand iserv] in
GHC.Runtime.Interpreter.C.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
09c965e2 by mangoiv at 2026-11-17T09:27:51-05:00
ci: make tests-primops run on marge CI
test primops dispatch was disabled on the *full-ci
group label to avoid dispatching for some of its configs
but wasn't reenabled for marge ci runs which it ought to
run
Fixes #27765
- - - - -
83038fbe by David Eichmann at 2026-11-17T09:28:32-05:00
test driver refactor: replace `.format(**locals())` with f-string
- - - - -
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.
- - - - -
55e17806 by Mikolaj Konarski at 2026-11-28T10:21:01+01:00
Fix stale and false comments in the NCG
Of what anyone working with the NCG needs, this commit serves "Comments
and Notes that are true of the code they describe."
Comments and documentation only: the generated code is the same. Each
item names a comment, says what it said, and says what holds instead.
- The comment above genMachCode in GHC.CmmToAsm named stix code
and the UniqSM monad. The code is Cmm, and genMachCode switches
from the UniqDSM monad to NatM.
- The comment on NcgImpl's extractUnwindPoints, in GHC.CmmToAsm.Monad,
placed Note [Unwinding information in the NCG] in that module.
The Note is in GHC.CmmToAsm.
- The header of GHC.CmmToAsm.PIC named the modules CLabel, Cmm,
AsmCodeGen and MachCodeGen. It now names the modules and functions
that do what it lists, and which labels each converts. Two comments
further down named MachCodeGen. One named it as calling
cmmMakeDynamicReference for static data, which the instruction
selectors do for some labels, such as those of floating point literals
on i386 and PowerPC. The other named it as calling the initialization
of the PIC base register for every procedure that accessed it, which
cmmTopCodeGen does on i386 and on 32-bit PowerPC but not AIX. They now
say so. The first also said that cmmToCmm calls
cmmMakeDynamicReference for every CmmLabel in the Cmm code, where
it does so only in procedures' code, and the second
that the initialization adds its instructions to the top
of the procedure, where on ELF it also adds them to the top of each
block with an info table. They now say that too. The header also said
that for Win32 only SRTs might contain addresses of __imp_ symbol
pointers, with a TODO that this might be bitrotted. Only
cmmMakeDynamicReference makes such a pointer's label, so none
is in data, and an SRT holds its closures' own labels, also
under -fexternal-dynamic-refs for closures in other packages.
The sentence and its TODO are deleted.
- The header of GHC.CmmToAsm.Reg.Target said that the module keeps
the NCG from emitting code for an architecture other than the host's.
Each of its functions dispatches on the target platform's
architecture, and the sentence is deleted. Its TODO, to make arch
specific versions of RegAlloc.Graph.TrivColorable, named a module now
called GHC.CmmToAsm.Reg.Graph.TrivColorable, and dates from 2009, when
that module chose its counts of registers by the host's architecture.
trivColorable now takes the target platform, by which it chooses each
architecture's count, and the squeeze functions of the target's Regs
module, which this module's targetVirtualRegSqueeze
and targetRealRegSqueeze choose. The TODO is deleted.
- Note [CFG based code layout] in GHC.CmmToAsm.BlockLayout placed
optimizeCFG right after instruction selection. cmmNativeGen runs it,
where it keeps the CFG (x86 and x86-64, not under -finfo-table-map),
after register allocation and shortcutting. The Note presented
the next two steps, loopInfo's loop analysis and mkGlobalWeights'
refinement of the edge weights, as unconditional. optimizeCFG takes
them only under -fcmm-static-pred, which -O implies, and the Note now
says so. The Note said that the refined weights are normalized
relative to the most often visited node. They are relative
to the entry node, to which calcFreqs gives frequency 1. The Note also
said that sequenceChain and addPreentryBlock recognise call edges
by their CmmCall source. addPreentryBlock, through isCallEdge, also
takes a CmmForeignCall source, and the Note now says so.
- The haddock of the Ord instance of CfgEdge, in GHC.CmmToAsm.CFG, said
that edges are sorted ascending pointwise by weight, source
and destination. The instance orders them lexicographically,
and "pointwise" is deleted.
- Note [Updating the CFG during shortcutting] in GHC.CmmToAsm.CFG said
that its author knew of a jump target that is an immediate value only
without tables next to code. With tables next to code a tail call's
jump to a label has one, which x86's canShortcut accepts,
and the sentence is deleted.
- Note [CFG Edge Weights] in GHC.CmmToAsm.CFG gave the default weight
as 20k; defaultWeights has 1000. It said that likely branches
are taken more than 80% of the time and unlikely ones less than 20%;
the default weights give 75% and 25%. It said that the false side
of a regular branch is preferred; getCfg gives both sides the same
weight. On x86 and x86-64 the x86 instruction selector adds 3
to the false side of a floating-point comparison, and, where
the weights stay equal, as they do not after that 3, optHsPatterns'
favourFewerPreds may weight one side above the other by their
predecessors. It said that calls are ignored completely; the layout
leaves a call's edge out while it builds chains and while it combines
neighbouring chains, and divides its weight by 64 when it merges
the chains.
- Note [Layout relevant edge weights] in GHC.CmmToAsm.BlockLayout said
that edges constituted by a call are ignored. The layout ignores them
while it builds the chains and while it combines neighbouring chains,
and counts a 64th of their weight when it merges the chains.
- Note [Static Branch Prediction] in GHC.CmmToAsm.CFG named two
heuristics. staticBranchPrediction applies three, ohPredicts being
the third.
- In staticBranchPrediction, in GHC.CmmToAsm.CFG, a comment said that s1
is the branch in the true case; s1 is the successor with the smaller
label. The guard commented "Only backedges" is also reached by a back
edge beside a heap or stack check's edge, and its comment now says so.
- The comment above findBackEdges, in GHC.CmmToAsm.CFG, said that back
edges are found by BFS. findBackEdges finds them by a depth-first
search (classifyEdges in GHC.Data.Graph.Directed).
- A comment in the Instruction class said that regUsageOfInstr
is to state precisely the registers an instruction reads and writes.
x86's regUsageOfInstr returns them as the register allocators
are to use them. The comment now says so, with examples of where
that departs from what the hardware does.
- The comment at the last arm of regUsageOfInstr's MOV case,
in GHC.CmmToAsm.X86.Instr, said that the MOV instructions reaching
it zero any remaining upper part of the destination. Some do, such
as a 32-bit MOV into a general register and, up to bit 127, a load
at FF32 or FF64. Others keep it, such as a MOV between registers
at FF32 or FF64, printed movss or movsd, and an 8-bit or 16-bit MOV
into a general register. The comment now also says that the usage
of the other MOV instructions has a register destination written,
not read. The comment at the MOVD arm said that MOVD and MOVQ always
zero any remaining upper part of the destination. The legacy forms GHC
prints zero it only up to bit 127, keeping bits 128 and above of a ymm
register, and the comment now says up to bit 127.
- Comments in GHC.CmmToAsm.Reg.Liveness, in both register allocators
and at the Ord instances of CmmTickScope, LocalReg and VirtualReg said
that deterministic code generation is not supported, which
-fobject-determinism provides for a Haskell module compiled without
-fcmm-thread-sanitizer, in its object's code, data and relocations;
under -g, with other values of -dinitial-unique
and -dunique-increment, the object's DWARF lexical blocks come
in another order, and under -fllvm the object's FILE symbol names
a temporary .ll file whose name depends, among other things, on what
else the build compiles. In GHC.CmmToAsm.Reg.Liveness
and the allocators, each now says whether the order at hand matters
and, where it does, what it decides. At the Ord instances, each now
says that the order compares uniques and so is deterministic
if the uniques are.
- In GHC.CmmToAsm.Reg.Graph.SpillCost, a comment said that there
are no loops in the code, so that the block frequencies can be 1.
Given a CFG, slurpSpillCostInfo scales the uses and definitions
it counts by the CFG's block frequencies. The sentence is deleted.
- linearRegAlloc's haddock and the comment over process said
that a block of an SCC is allocated before a jump into it only
if it is the first block (the haddock) or the procedure's entry block
(the comment). Any of the procedure's entry blocks is. The comment
over process also said that process loops where a block's assignment
never gets set. process stops after a round that allocates no block,
and so drops such a block.
- findPrefRealReg's comment said that the preferred register
is the first one the variable was assigned to. It is the variable's
register in the first entry assignment, in allocation order, that maps
it to a register. A block's entry assignment is recorded at the first
jump into it.
- Two comments in GHC.CmmToAsm.Reg.Graph named the flag -fasm-lint,
which is -dasm-lint. The one in a round that spills also said
that the graph is then validated, which it is not: nothing evaluates
the validated graph that round stores, and that comment is deleted.
- Two comments in GHC.CmmToAsm.Reg.Linear.Base named the stats flag
-ddrop-asm-stats, which is -ddump-asm-stats.
- The executable specification of FreeRegs,
in GHC.CmmToAsm.Reg.Linear.FreeRegs, handed out the most recently
released registers first. It now gives noFreeRegs as [] and has
getFreeRegs hand out the registers in each instance's fixed order.
Its allocateReg took the set first and its getFreeRegs classed
registers by regClass, which GHC does not have; both now follow
the instances (the register first, targetClassOfRealReg). It made
releasing a free register and allocating an allocated one no-ops
and now says that the AArch64, RISC-V and LoongArch instances panic
there.
- The header of GHC.CmmToAsm.Reg.Linear.StackMap said that a slot stays
associated with its register to the end of the procedure. A register
that outgrows its slot moves to new ones. What holds is that no other
register gets the old slot.
- The comment at handleComponent's case for a cycle of moves,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that all the cycle's
source registers are spilled. handleComponent spills one.
- makeRegMovementGraph's comment said that cyclic components seem
to occur only very rarely. They are frequent in some code:
in the benchmark of an unreleased version of orthotope, a Haskell
array library, the fixup code breaks register cycles through a stack
slot in $w$s$wequalT1 and in $w$s$w$ccompare1. The sentence
is deleted.
- A comment at expandNode's case for a move from InBoth to InMem,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that the source's slot
is guaranteed to be the destination's. They can differ where
the virtual register has more than one slot, and the value
is then stored from its register. The comment now says that the guard
fails only there.
- A comment in GHC.CmmToAsm.X86.Ppr's pprNatCmmDecl cited Note [Internal
proc labels] in GHC.Cmm.Label, across two lines. The Note
is in GHC.Cmm.CLabel, and the citation is now on one line.
- A comment in GHC.CmmToAsm.Reg.Linear.AArch64 said that getFreeRegs
scans the integer registers from 28 down. getFreeRegs starts from x18,
and the comment now also says that it starts from v31 among the v
registers.
- The comment at classOfRealReg in GHC.CmmToAsm.X86.Regs said "On x86"
of what holds on i386 alone. It numbered the registers with 8-bit
versions 1-4, and the allocatable ones among them 1, 3 and 4. It now
says "On i386", and they are 0-3, and 0, 2 and 3.
- The haddock of RegArch's Separate, in GHC.Platform.Reg.Class, gave
RISC-V as an example. registerArch gives RISC-V NoVectors
and no architecture Separate.
- A comment in the stmtToInstrs of each of X86, AArch64, LA64 and RV64
said that the condition of a conditional branch can be assumed likely
false, because GHC.Cmm.ContFlowOpt arranges for the likely side
to fall through. ContFlowOpt also inverts a condition whatever
its likelihood where the condition can be inverted, the true target
has one predecessor and the false target more than one,
so the condition may be likely true. None of the four genCondBranch
functions uses the likelihood.
- A comment in mkCmmIfThenElse', in GHC.StgToCmm.Monad, said
that the NCG does not know about likely annotations. The PowerPC code
generator has printed them as branch hints since 2017. Since 2018
getCfg has weighted the CFG's edges by them, and on x86 and x86-64
without -finfo-table-map the block layout
(not under -fblock-layout-weightless without -fblock-layout-cfg)
and the order of some conditional branches' jumps (invertCondBranches)
follow these weights. The comment's clause on a fallthrough
is replaced by what the swap does: where the test can be inverted
it becomes a likely-true test of the inverse, and GHC.Cmm.ContFlowOpt
swaps the branches back where the true target, after shortcutting, has
one predecessor.
- Note [Updating the CFG during CodeGen], in GHC.CmmToAsm.Monad, said
that cmmNativeGen removes the unreachable blocks before it builds
the CFG and generates code. cmmNativeGen removes none there. The CFG
lacks them, instruction selection still covers them, and no pass drops
them before it. So the combinators that split a block panic
in getSuccessorEdges when called in an unreachable block (ISSUE
28088). The Note now says so.
- Note [Updating the CFG during CodeGen] also said that a store emits
the code of its address before the code of its value and takes
the address from getNonClobberedAmode. The assignMem_* functions
of GHC.CmmToAsm.X86.CodeGen generate and emit the code of the value
first and take the address from getAmode. getNonClobberedAmode
is for code that must come between an amode and its use. The Note now
says so.
- Note [Updating the CFG during CodeGen] also said that sanityCheckCfg
checks the CFG against the final instruction stream when -dasm-lint
is on. sanityCheckCfg checks it against the code before block layout,
also in a DEBUG compiler, and in either case only where
ncgEnableDeadCodeElimination holds: on x86 and x86-64, without
-finfo-table-map. The Note now says so. ISSUE 28179 reports three
sentences of the Note: the one on sanityCheckCfg and those that said
that cmmNativeGen removes the unreachable blocks before it builds
the CFG and that a store emits the code of its address before
that of its value.
- A comment at makeImportsDoc, in GHC.CmmToAsm, put a hack
for .subsections_via_symbols in PprMach.pprNatCmmDecl. A comment above
initializePicBase_x86, in GHC.CmmToAsm.PIC, cited PprMach.hs for how
FETCHGOT is printed. A comment above pprWordArray, in GHC.CmmToC,
cited codeGen/ClosureInfo and nativeGen/PprMach for info tables
as arrays of words. No module PprMach or ClosureInfo is left.
The first comment now cites the printers' pprNatCmmDecl and Note
[Subsections Via Symbols] in GHC.CmmToAsm.X86.Ppr, the second cites
GHC.CmmToAsm.X86.Ppr, and the third cites mkInfoTable in GHC.Cmm.Info,
which lays the info tables out, and pprNatCmmDecl in each
GHC.CmmToAsm.*.Ppr, which prints them.
- A comment in raInsn, in GHC.CmmToAsm.Reg.Linear, said that a real
source register must be allocatable, since it would otherwise
not be in r_dying, a name raInsn does not have. The guard looks
the register up in liveDieRead, which the comment now names.
- A comment in genRaInsn, in GHC.CmmToAsm.Reg.Linear, said that using
nub on the registers read is no problem. The code uses nubOrdOn,
and the clause is deleted.
- The comment at initBlock's case for a block without an entry
assignment, in GHC.CmmToAsm.Reg.Linear, took the block to be part
of a loop that the allocator iterates over again. No block
is allocated twice. The case is reached by an entry block, or
by a block that no allocated jump reaches. The comment now says so,
and what the case does.
- The haddock of lookupFirstUsed, in GHC.CmmToAsm.Reg.Linear.Base, said
that it gives the register a virtual register was first assigned to.
lookupFirstUsed gives the variable's register in the first entry
assignment, in allocation order, that maps it to a register,
as findPrefRealReg's comment now says. The haddock now says so too.
- The haddock of minusCoveredRegs, in GHC.CmmToAsm.Reg.Regs, said
that it removes a register only where its format in the second
argument is at least as large as in the first. minusCoveredRegs
removes a register at a scalar format in the first whatever its format
in the second, and compares a vector format by Format's derived Ord;
the haddock now says so.
- The haddock of shrinkingRegs, in GHC.CmmToAsm.Reg.Regs, said
that it computes the registers in both arguments whose size is smaller
in the second. shrinkingRegs also keeps every register of the first
argument that is not in the second, and compares the formats
by Format's derived Ord; the haddock now says so.
- The comment "A Rule of the Game (tm) for Amodes" and the haddock
of getNonClobberedAmode, in GHC.CmmToAsm.X86.CodeGen, said
that getNonClobberedAmode's amode stays valid across other code.
getNonClobberedAmode computes the address into a new temporary only
where getAmode's amode names a real register that freeReg hands out;
otherwise code that writes a virtual register the amode names breaks
it. Both now except such code.
- A comment in getAmode, in GHC.CmmToAsm.X86.CodeGen, said that a clause
turns lit1 << n + lit2 into lit2 + lit1 << n for the next clause.
The shifted operand is any expression. The clause is reached only
for a literal that the clause for x + lit does not take. The swapped
sum goes to the clause for x + (y << shift) or to the one for x + y.
The comment now says so.
- Note [Sinking and inlining] and the comment at shouldDiscard,
in GHC.Cmm.Sink, compared sinking's deletion of dead assignments
with removeDeadAssignments, which no longer exists. They now say only
that sinking does not delete every dead assignment, without master's
reason, that it would need multiple passes: no number of passes
deletes a local that only its own assignment in a loop reads,
or a dead store to a global register.
- The haddock of FrontierMap, in GHC.CmmToAsm.BlockLayout, said
that it maps the blocks near the end of a chain, and gave the front
blocks [A,B] of [A,B,C,D,E] as the end region. combineNeighbourhood
keeps one such map for the ends of the chains and one for their
fronts. The haddock now says so, with an entry of each.
- Note [When does an assignment conflict?], in GHC.Cmm.Sink, swapped
'A' and 'N' in its conditions (C1) and (C2). Its own (C1a) and (C1b),
and the labels in conflicts, have (C1) where N assigns to a register
A mentions, and (C2) where N reads the register A assigns.
The conditions now say so.
- The users' guide's entry of -fcmm-static-pred said that the prediction
is made on the final Cmm code and used by the register allocation
and code layout passes. The prediction is made only in the NCG for x86
and x86-64, on the NCG's CFG after register allocation
and shortcutting. It is used, without -finfo-table-map, for the layout
(not under -fblock-layout-weightless without -fblock-layout-cfg)
and for the order of some conditional branches' jumps
(invertCondBranches). The entry now also says that the graph colouring
allocators (-fregs-graph, -fregs-iterative) choose what to spill
by live range length alone (chooseSpill, spillCost_length),
so that the flag does not change their allocation. Its short
description, "Enable static control flow prediction.", named neither
limit; it now names the native code generator for x86 and x86-64
and excludes -finfo-table-map.
- The users' guide's entry of -fcmm-sink said that the sinking pass
attempts to find identical Cmm blocks and eliminate the duplicates.
Those are words of the -fcmm-elim-common-blocks entry, run
into this entry's sentence since the two entries were written.
The sentence now says only that the pass attempts to move variable
bindings closer to their usage sites.
- The users' guide's entries of -fblock-layout-cfg
and -fblock-layout-weightless did not say that the flags act only
where the CFG is kept. sequenceTop uses the chain algorithm,
and the old algorithm uses the edge weights, only on x86 and x86-64
and without -finfo-table-map. Both entries now say so, and so does
the short description of -fblock-layout-cfg, "Use the new cfg based
block layout algorithm.", which named neither limit. The short
description of -fblock-layout-weights said that the flag sets edge
weights used by the new code layout algorithm; the old algorithm uses
them too, without -fblock-layout-weightless, and invertCondBranches
orders the jumps of some conditional branches by them. It now names
both uses and the limits. The -fblock-layout-cfg entry also said
that the flag builds a control flow graph, which cmmNativeGen builds
whatever the flag says, and set the chain algorithm against the last
jump of each block, which the old algorithm follows there only
under -fblock-layout-weightless; it now sets it against at most one
edge per block. The -fblock-layout-weightless entry said that without
the flag the old algorithm also uses the heaviest outgoing edge;
it uses that edge instead of the last jump, or none where that edge's
weight is not positive or the block has more than two successors.
The entry of -fasm-shortcutting and its short description, "Enable
shortcutting on assembly.", did not say that the flag acts only on x86
and x86-64: the canShortcut of PowerPC, AArch64, RISC-V and LoongArch
returns Nothing for every instruction, so that shortcutBranches
removes no block there. Both now say so.
- A comment above initializePicBase_x86, in GHC.CmmToAsm.PIC,
and the one on FETCHGOT, in GHC.CmmToAsm.X86.Instr, said that FETCHGOT
prints its last line as addl __GLOBAL_OFFSET_TABLE__+.-1b
and the register. GHC.CmmToAsm.X86.Ppr prints addl
$_GLOBAL_OFFSET_TABLE_+(.-1b), with one underscore at each end
of the symbol, and the comments now show that line.
- The short description of -fblock-layout-weightless in the users' guide
said that the flag ignores the CFG's weights for code layout. The flag
acts only on the old layout algorithm, as the entry's own text says,
and at -O it changes nothing: on x86 and x86-64 without
-finfo-table-map, -fblock-layout-cfg replaces that algorithm,
and elsewhere that algorithm is given no CFG. The short description
now names the old algorithm.
- Note [When does an assignment conflict?], in GHC.Cmm.Sink, said
that (C1) includes two situations, and lists three, (C1a) to (C1c).
It now says three.
- Note [Internal proc labels], in GHC.Cmm.CLabel, named the flag
-fexpose-all-symbols and said that it is enabled by default,
and the haddock of ppInternalProcLabel named Opt_ExposeAllSymbols.
The flag is -fexpose-internal-symbols, whose GeneralFlag
is Opt_ExposeInternalSymbols, and it is off by default. Both now say
so.
- The haddock of FrontierMap, in GHC.CmmToAsm.BlockLayout, said "cheaper
then" where it means "cheaper than", which it now says.
- Note [Sinking and inlining], in GHC.Cmm.Sink, said that an assignment
is cheap where its right-hand side is a local register, the comment
above isTrivial counted registers, both local and global, as trivial,
and Note [Inline GlobalRegs?] said that GlobalRegs are treated
as trivial and inlined everywhere. isTrivial, which decides it,
accepts a local register, a literal, and a global register only where
it is held in a machine register or, on ARM, any global register.
The three now say so. Sinking does not inline such a register
everywhere: an unsafe foreign call that returns defines the global
registers held in machine registers that callerSaves names, okToInline
returns False for an expression reading one and the call,
and conflicts returns True for an assignment from one and the call,
so the assignment is neither inlined into the call nor carried past
it. On x86-64 Linux, where R3 is held in rsi, an assignment of R3
to a local register stays before an unsafe foreign call that takes
the local, which on AArch64, where R3 is held in x24, takes R3 itself.
The Note no longer says everywhere. The comment above okToInline said
that nothing referring to global registers is inlined into an unsafe
foreign call, where R1 is inlined into one on x86-64 Linux; it now
names the global registers the call defines.
- The users' guide's entries of -g and -fexpose-internal-symbols said
that -g2 implies -fexpose-internal-symbols. setDebugLevel,
in GHC.Driver.Session, sets the flag only above level 2, so -g3
implies it, and -g, which is level 2, does not. Both entries now say
level 3.
- A comment at CmmUnsafeForeignCall, in GHC.Cmm.Node, named
GHC.Platform.callerSaves, which GHC.Platform does not export.
The function is GHC.Platform.Regs.callerSaves, which the comment now
names.
- Note [Internal proc labels], in GHC.Cmm.CLabel, and the users' guide's
entry of -fexpose-internal-symbols said that the flag makes GHC
produce symbols for procedures internal to a module, and the haddock
of ppInternalProcLabel made the function's label conditional
on the flag. Only the code generator for x86 and x86-64 tests
the flag, in pprExposedInternalProcLabel, before it calls
ppInternalProcLabel, which tests none. The three now say so.
The entry's short description, "Produce symbols for all functions,
including internal functions.", named no target; it now names
the native code generator for x86 and x86-64. The entry also said
that -fno-expose-internal-symbols suppresses all non-global symbol
table entries; it suppresses only the labels that the flag adds,
and the sentence is deleted.
- Note [Chain based CFG serialization], in GHC.CmmToAsm.BlockLayout,
said that the chains are built ignoring calls and edges into a block
prefixed by an info table, and its example of a block that ends up
in a chain of its own was reached by such a jump. sequenceChain
ignores only call edges there and keeps an edge into an info table's
block at an eighth of its weight. The Note now names only calls,
and its example reaches the block by a call. Its step 2 said
that an edge (A -> B) fuses two chains where A ends one and B starts
the other, and that the edge is skipped where no such chains
are found. mergeChains fuses the chains holding A and B, that
of A first, wherever A and B are in them, and skips the edge only
where A and B are in one chain. Step 2 also said that it combines
the chains resulting from the step above it, and came before step 3,
which places neighbouring chains next to each other. sequenceChain
runs combineNeighbourhood, step 3, before mergeChains, step 2, which
takes its result. The Note now says so, and places and numbers
the neighbour step before the fusing step.
- The comment on cmmMakeDynamicReference above ReferenceKind,
in GHC.CmmToAsm.PIC, said that a function for recording an imported
symbol must be passed in, addImportCmmOpt or addImportNat.
cmmMakeDynamicReference takes no such argument: it runs in an instance
of CmmMakeDynamicReferenceM, whose addImport is addImportCmmOpt
for CmmOptM and addImportNat for NatM. The comment now says so.
- The users' guide's chapter on debugging compiled programs gave -g's
levels as 0, 1 or 2 in the flag's short description,
and its walkthrough said that there are three levels, -g2 emitting
everything GHC knows, and that the GHC-specific annotations
are emitted with -g2. The entry's list of levels said that -g2 adds
unwinding records for inner blocks, allowing more precise backtraces
than -g1, and that -g3 produces GHC-specific DWARF information,
its section on GHC's DIEs gave the tag of DW_TAG_ghc_src_note
as 0x5b01, and its implementor's notes said that under -g the DIEs
in .debug_info can identify all relevant source locations. The entry's
levels are 0 to 3, and it said that those are accepted, where -g9
and -g-1 compile too: GHC tests debugLevel only by > 0, < 2 and > 2,
so a higher level acts as 3 and a negative one as 0, as the entry now
says. Below level 2, dwarfGen, in GHC.CmmToAsm.Dwarf, strips
the blocks (ncgDwarfStripBlockInfo, in GHC.Driver.Config.CmmToAsm)
only from the DIEs and gives debugFrame the unstripped procedures,
so -g1, -g2 and -g3 emit the same unwinding records, as objdump
--dwarf=frames of objects compiled at the three levels shows, and -g2
adds DW_TAG_lexical_block DIEs. -g2 also emits GHC's own attribute
DW_AT_ghc_tick_parent; what needs -g3 is the source-note DIEs:
ncgDwarfSourceNotes holds only above level 2.
GHC.CmmToAsm.Dwarf.Constants gives dW_TAG_ghc_src_note as 0x5b00.
Below level 3 no DIE carries a source location: the subprogram
and block abbreviations in GHC.CmmToAsm.Dwarf.Types hold none,
and the spans are attributes of the source-note DIEs. The short
description, the walkthrough and the annotations' sentence now name
level 3, the walkthrough and the list give -g2 the block DIEs and -g3
the source notes, the section gives 0x5b00, and the notes give
the source locations to the source-note DIEs that -g3 adds. The notes
said that GHC produces DWARF v4, where GHC emits version 3 headers
in .debug_info (compileUnitHeader, in GHC.CmmToAsm.Dwarf)
and in .debug_frame (its CIE, in pprDwarfFrame
in GHC.CmmToAsm.Dwarf.Types), and they now say v3. They said
that the DIEs in .debug_info describe all of the basic blocks
in the compiled program, where below level 2 they describe no block
inside a procedure, and at no level a procedure that cmmDebugLink
drops (the next item); they now say that its DIEs describe
the functions and, from -g2, the blocks inside them. They named
the sections .debug_frames and .debug_arange, which
GHC.CmmToAsm.Dwarf.Constants names .debug_frame and .debug_aranges,
as the notes now do. Note [Info Offset], in GHC.CmmToAsm.Dwarf.Types,
named the frame section .debug_frames too, and now names
it .debug_frame.
- The users' guide's entry of -g said that only DWARF debug information
is supported on x86-64 and i386, its short description said
that the flag produces DWARF debug information in compiled object
files, and a tip of its chapter on debugging compiled programs said
how to extract the debug information on Mac OS X with dsymutil. Only
the native code generator emits DWARF, and ncgDwarfEnabled,
in GHC.Driver.Config.CmmToAsm, holds only for ELF targets other
than AArch64: Mac OS X gets none, and x86, x86-64, 64-bit PowerPC
with the ELFv2 ABI, RISC-V and LoongArch can get it, with unwinding
records that follow the Haskell stack pointer only on x86 and x86-64,
where extractUnwindPoints returns unwinding points, and there at most
through a procedure's first block: the frame description entry ends
at the end label that X86's pprBasicBlock prints after the procedure's
entry block (procToFrame in GHC.CmmToAsm.Dwarf, pprFrameProc
in GHC.CmmToAsm.Dwarf.Types), and the row added around a C call,
naming the C stack pointer alone, gets the Haskell stack pointer's
rule at the procedure's entry from addDefaultUnwindings
in GHC.CmmToAsm.Dwarf. objdump --dwarf=frames shows both for an object
compiled at -O1 -g1 by a compiler of master's code, on x86-64
from Haskell, where a procedure of 0x92 bytes by nm -S gets a frame
description entry of 10 bytes and a row setting the frame address's
offset to 0 at a C call made where Sp is 8 bytes below its value
at entry, and given an i386 target description through -B, from Cmm.
The entry now says so, its short description names the native code
generator and some ELF targets, and the tip is deleted. A comment
in cmmDebugLabels, in GHC.Cmm.DebugBlock, said that declaring a block
that holds only meta instructions missing skips debug data generation
without messing up the block hierarchy. cmmDebugLink drops a missing
block's DebugBlock with every block and procedure nested under it,
so where a procedure's entry block holds only meta instructions,
as at -O0 -g on x86-64 for an entry block that only moves
the arguments and jumps to the heap check, that procedure
and those nested under it get no DIEs from GHC and no unwinding
records. The comment now says that cmmDebugLink skips the nested
blocks and procedures too.
- The haddock of mkGlobalWeights, Note [Static Branch Prediction]
and the comment above calcFreqs, in GHC.CmmToAsm.CFG, gave the title
of Wu and Larus's paper as "Static Branch Prediction and Program
Profile Analysis". The paper, at MICRO-27 in 1994, is "Static Branch
Frequency and Program Profile Analysis", which the three now give.
- The users' guide's chapter on debugging compiled programs said
that the debugging information does not affect the optimizations GHC
performs. Under -g the native code generator can keep a block
that holds only a jump, which -fasm-shortcutting removes without -g,
as in the testsuite's T5149_cmm.cmm at -O2 on x86-64: compiled
by a compiler of master's code, it jumps to g5149 directly without -g
and through a kept block with it. The sentence is deleted.
- Comments named modules and files by names that no longer exist,
or never did. The header of GHC.Platform.Reg named NCGMonad, now
GHC.CmmToAsm.Monad, which it now names. The header
of GHC.CmmToAsm.Format had a TODO, from 2009, saying that the module
is shared by all architectures because NCGMonad needs it to make
a virtual register, and that architecture specific formats would
be better, as SPARC does not use FF80. The SPARC code generator
and FF80 have since been removed, and since 2024 the register
allocators use Format too, for RegWithFormat; the TODO is deleted.
Note [GHC's data format representations], in the same module, named
Format.Format, now GHC.CmmToAsm.Format.Format. The header
of GHC.CmmToAsm.Reg.Graph.Base placed the hand written versions
of its functions in MachRegs*.hs, and the comment on its RegClass
placed the allocatable register classes in MachRegs.hs; the header
of GHC.CmmToAsm.Reg.Graph.X86 placed the reference in RegArchBase.hs
and trivColorable in MachRegs.hs, and the haddock of that module's
worst named RegColorBase; and the commented-out specification
in GHC.CmmToAsm.Reg.Graph.TrivColorable compared its worst
with RegArchX86 and said that the trivColorable function of each
architecture should implement it, where one trivColorable takes each
architecture's squeeze functions. The comments now name the squeeze
functions of each architecture's Regs module, which trivColorable
takes, GHC.Platform.Reg.Class, GHC.CmmToAsm.Reg.Graph.Base,
GHC.CmmToAsm.Reg.Graph.TrivColorable and GHC.CmmToAsm.Reg.Graph.X86.
The specification calls regClass and applies Reg's constructor
RealReg, both removed in 2009, and its header now says that it
is a sketch. The header of GHC.CmmToAsm.Reg.Graph.TrivColorable said
that there is an allocatableRegsInClass :: RegClass -> Int,
but that the unboxing is too slow there, with a TODO asking whether
that is still true and whether allocatableRegsInClass could be used.
allocatableRegsInClass is defined only in that specification, since
2009, and trivColorable uses the counts that allocatableRegs :: Arch
-> RegClass -> Int hard-codes. The sentence and its TODO are deleted.
The comment on the PowerPC calling conventions
in GHC.CmmToAsm.PPC.CodeGen pointed to MachRegs.hs for the argument
and nonvolatile registers, and now points to GHC.CmmToAsm.PPC.Regs.
The haddock of PicBaseReg, in GHC.Cmm.Reg, named the module
PositionIndependentCode, and comments in the AArch64, RISC-V
and LoongArch instruction selectors named Cmm.CmmToAsm.PIC; both now
name GHC.CmmToAsm.PIC. The same comments placed cmmExprNative,
the second of the two callsites they gave cmmMakeDynamicReference,
in GHC.CmmToAsm; it is in GHC.Cmm.GenericOpt, and each selector calls
cmmMakeDynamicReference in genSwitch too, LoongArch's in genPrimCCall
and genLibCCall rather than in genCCall, as the comments now say.
A comment in GHC.CmmToAsm.Reg.Liveness named Digraph, now
GHC.Data.Graph.Directed. Comments in GHC.Cmm.CLabel and GHC.Cmm.Sink
named PprC, now GHC.CmmToC, and comments in GHC.Cmm.DebugBlock
and GHC.Cmm.Utils named CmmSink, and one
in compiler/CodeGen.Platform.h CmmSink.hs, now GHC.Cmm.Sink. A comment
in GHC.CmmToC named nativeGen/AsmCodeGen as reordering blocks, which
GHC.CmmToAsm.BlockLayout does and the comment now names. The comment
on isTrivial's case for ARM, in GHC.Cmm.Sink, said
that CodeGen.Platform.ARM does not have globalRegMaybe. When the case
was added, in 2014, globalRegMaybe panicked on ARM; GHC.Platform.ARM's
globalRegMaybe does not, and the comment now says so. A comment
in GHC.Cmm.Parser said that OldCmm does not support a first class else
statement. OldCmm was removed in 2012, and the comment is deleted.
GHC.Cmm.Info named rts/include/rts/storage/InfoTable.h, and Note [No
static object resurrection], in GHC.Cmm.Info.Build, named smStorage.h;
the files are rts/include/rts/storage/InfoTables.h
and rts/sm/Storage.h.
Assisted-by: Claude Opus 5.5
- - - - -
81f6cb78 by Mikolaj Konarski at 2026-11-28T10:21:01+01:00
Define the labels of the NCG's comments
Of what anyone working with the NCG needs, this commit serves "The kind
of each statement in the NCG's comments, shown at the statement: a bug,
half-done work, a likely change or code meant to stay.", "What a comment
that does not show the kind of its statements does and does not claim.",
"How the statements on bugs, half-done work and likely changes are kept
true as the code changes." and "Each known bug's tracker issue, named
at the code it concerns."
Comments only; the generated code is the same.
Note [Labels in NCG comments], added to GHC.CmmToAsm, defines the labels
that comments added to the native code generator since then put
at the head of a statement. The commits that follow label each statement
they add, and are read under this Note:
BUG wrong behaviour, a missing check or misleading code;
the statement says in short what it leads to and,
where the code shows it, where it is reached
WIP half-done work
TODO what is likely to change, correct or buggy; a bug marked
TODO alone is accepted for now and worked around
BUG TODO both, where both are to be stressed
no label what is meant to stay, but a statement citing a labelled
one is of its kind; a kept trade-off says why
A BUG statement names its consequence: wrong code, wrong debugging
information, a panic or another failed compilation, assembly
the assembler rejects, only slower or larger code, only a warning
from the assembler, only more C stack space, or only a misled reader.
The Note does not reach back to older comments: their TODO, ToDo, FIXME
and XXX predate its meanings, and an older comment's lack of a label
makes no claim that the code is meant to stay.
The Note also says how the labels are kept true. A change to what
a labelled statement describes removes or rewrites the statement,
and each statement that cites it, in the same change; BUG, TODO and BUG
TODO gain the issue's number when the issue is filed; and a git grep
given in the Note lists the labelled lines.
Assisted-by: Claude Opus 5.5
- - - - -
435efda0 by Mikolaj Konarski at 2026-11-28T10:21:01+01:00
Document bugs and TODOs in the NCG's CFG and block layout
Of what anyone working with the NCG needs, this commit serves "Where
the code does something other than what reading it suggests.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached.", "Each known
bug's tracker issue, named at the code it concerns." and "Where the code
is likely to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments]: BUG
for wrong behaviour, BUG TODO for a bug that is also likely to change,
TODO for what is likely to change, none for what is meant to stay.
What each BUG leads to, where it is reached and what that rests on:
- build_mapping in shortcutBranches, GHC.CmmToAsm (BUG: under -g a block
that holds only its jump can also hold the location and unwinding
information that -g adds, and is then kept where without -g
it is shorted). The code under -g jumps through the kept block,
and on x86 and x86-64 static prediction and block layout get another
CFG than without -g. This costs only speed and code size, under -g
and -fasm-shortcutting, on x86 and x86-64, not on Darwin. This rests
on master's code read: split matches a block of exactly one
instruction, and under -g on ELF targets other than AArch64
the instruction selectors put a LOCATION at the head of a block
with a source note, and under -g x86's gives a CmmUnwind an UNWIND,
neither of which emits code. On a development branch whose block
layout differed from master's, this changed the code of a probe
under -g.
- Note [Updating the CFG during shortcutting] in GHC.CmmToAsm.CFG (BUG:
with tables next to code, a block that is only a tail call's jump
to a label is shortcut away, and with it the edge A -> B). A's branch
has one target fewer in the CFG than in the code, and a loop whose
only exit was the lost edge has no exit in the CFG, so calcFreqs caps
its cycle probability. This costs only speed. It is reached on x86
and x86-64, the targets with a CFG after register allocation,
under -fasm-shortcutting, not on Darwin, not under -finfo-table-map,
not for a jump through a symbol pointer, and under -g only
for a jump-only block to which -g adds nothing. This rests on master's
code read: the removed block ends in a tail call and has no edges out
in the CFG; it leaves the code and the CFG together, and no block
becomes unreachable; and the readers of the CFG after
shortcutWeightMap do not panic on a missing edge: optimizeCFG's
lookups take their blocks and edges from the CFG itself;
sanityCheckCfg compares the jumps to blocks with the edges,
and the jump that loses its edge, now to a label, is not among
those jumps; sequenceTop looks up only the blocks the CFG's edges
name, all of them blocks of the code; and invertCondBranches takes
an edge's information as a Maybe and leaves a jump without it alone.
- Note [Updating the CFG during shortcutting] in GHC.CmmToAsm.CFG,
its BUG TODO (where a redirected edge A -> C coincides with an edge
A -> C already there, or with another redirected edge, only one
EdgeInfo is kept, chosen by the order of the fold over A's targets
in update_from_edge). The weights are not summed. This costs only
speed, on x86 and x86-64 under -fasm-shortcutting, not on Darwin,
not under -finfo-table-map, and under -g only for a jump-only block
to which -g adds nothing. This rests on master's code read and
on a run of master's compiler at -O0 -fasm-shortcutting, where
in the Cmm procedure f (W_ x, W_ y, W_ z) { W_ t; if (x > y) (likely:
True) { goto b; } else { goto c; } b: t = y; goto c; c: R1 = z + 1;
jump g [R1]; } the two edges into c become one with the weight of one
of them.
- getCfg in GHC.CmmToAsm.CFG (BUG, ISSUE 28088: the CFG gets only
the blocks reachable from the entry, while instruction selection still
covers the blocks that cmmToCmm makes unreachable when, after the Cmm
pipeline has removed the unreachable blocks, it turns a branch
on a constant into a jump). Where the selector splits such a block
in the CFG (addImmediateSuccessor), as X86's cmpxchg loop
for an atomic and, or, xor or nand does, the compiler panics
with "getSuccessorEdges: Block does not exist". This is reached on x86
and x86-64, at any optimisation level: cmmToCmm turns a branch
on a literal into a jump under every flag, and the literal comes
at -O0 from cmmToCmm's own constant folding and at -O from sinking's.
For x86-64 this rests on master's code read and on runs of master's
compiler under -dcmm-lint. A procedure whose if (1 != 0) leaves
a block with a fetch-and-and unreachable panics with that message
at -O0 and at -O, and also at both with -finfo-table-map added,
under which no CFG is kept after instruction selection. Where
the branch tests a local set to 1 instead, the procedure panics at -O
and compiles at -O0. For i386 it rests on runs of a compiler
of master's code given an i386 target description through -B,
with -dcmm-lint, where f (bits32 p) { bits32 r; if (1 != 0) { return
(1); } (r) = prim %fetch_and32(p, 18::bits32); return (r); } panics
with that message at -O0 and at -O, with -finfo-table-map too,
and compiles where it tests p != 0 instead, and on master's code read:
getCfgProc builds the CFG for every target the NCG compiles
but wasm32; i386 runs the same selector (ncgX86 = ncgX86_64),
and updateCfgNat forces each update, so addImmediateSuccessor's call
of getSuccessorEdges panics during instruction selection whether
or not a CFG is kept after it. It rests also on ISSUE 28088's record.
- parseWeights in GHC.CmmToAsm.CFG.Weight (BUG: a setting without "="
or of an unknown name panics, and a value is read lazily).
-fblock-layout-weights=1 then makes the compiler panic, "Invalid CFG
weight parameters." followed by the example parameters, and foo=1 "foo
is not a CFG weight parameter.", each with the request for a bug
report, where the flag's HasArg in GHC.Driver.Session could report
a usage error; a non-numeric value, uncondWeight=x, is accepted where
the compilation uses no weight it sets and otherwise makes
the compiler panic later, "Prelude.read: no parse". This is a failed
compilation reported as a panic, from the command line, on any module,
at -O0 and -O, under the native code generator; under -fllvm the value
is not used. This rests on master's code read (parseWeights
and its local assignment and update; the flag's entry
in GHC.Driver.Session) and on a compiler of master's code on x86-64
and given an AArch64 target description through -B: on a module of one
function, -fblock-layout-weights=1 panicked so at -O0 on x86-64,
and at -O0 and -O for AArch64, and foo=1 at -O0 on x86-64;
uncondWeight=x compiled it at -O0 and -O,
and uncondWeight=x,condBranchWeight=y panicked with no parse at -O0
and -O on a function with a conditional; with -fllvm,
-fblock-layout-weights=1 compiled it.
- Note [Layout relevant edge weights] in GHC.CmmToAsm.BlockLayout (BUG
TODO, ISSUE 27799: where buildChains skips one edge of a conditional
branch because it would close a cycle, as it can skip a loop latch's
back edge, not fusing the branch's other edge leaves an unconditional
jump as well, and the modifier on the edges of a conditional branch
then under-prices that other edge). An unconditional edge of nearly
equal weight from another predecessor can be fused with the target
first. Where the latch's CmmCondBranch has the exit as its true
target, the loop then ends in a conditional jump to the exit
and an unconditional one back, one jump more on every iteration,
as in the issue's program; where it has the body, the loop ends
in a conditional jump back and an unconditional one to the exit, which
runs once, as the loop exits. This costs only speed, on x86 and x86-64
under -fblock-layout-cfg, not under -finfo-table-map. This rests
on master's code read (directEdges' relevantWeight in sequenceChain),
on ISSUE 27799's record and on a run of master's compiler at -O2
on the issue's program: under -fobject-determinism its latch ends
in jge and jmp, and without it in jl alone; and on runs of master's
compiler at -O1 on a Cmm loop of each form, whose latch ends in jae
to the exit and jmp, or in jb to the body and jmp.
Two TODOs for ISSUE 28170, at livenessCfg in cmmNativeGen
and at ncgEnableDeadCodeElimination in initNCGConfig, say that since
55a6377a5d, a workaround for ISSUE 20428, -finfo-table-map turns dead
code elimination off, and with it, from the liveness pass on, every use
of the CFG that can change the code. No CFG is then kept after register
allocation, so the layout has neither static prediction nor the chains
of -fblock-layout-cfg, and lays the blocks out without weights.
Note [CFG Edge Weights] now says what -fcmm-static-pred changes:
that under it, where the CFG is kept (x86 and x86-64,
not under -finfo-table-map), the weights become estimated frequencies
before the layout uses them.
At getCfg's case for a switch, master's comment says that the weight -1
given to every target of a switch with more than ten entries (its case
values and its default), a compiler performance hack, keeps the layout
from considering them. A TODO there now says that, where the CFG
is kept, the layout considers them nonetheless under -fblock-layout-cfg,
and under -fcmm-static-pred where they go to at most two blocks, both
flags on at -O1 and -O2, and that what the hack saves has
not been measured.
Other TODOs say:
- at the Ord instance of CfgEdge, that edges of equal weight are ordered
by their labels, which carry no meaning for the layout;
- at allEdges' relevantWeight in sequenceChain, that it differs
from directEdges';
- at dropJumps, that a block that only jumps to the next one is left
as an empty label and a jump over it is kept.
In X86's genCondBranch', a comment says that the 3 added to the weight
of a floating-point comparison's false edge breaks layout ties toward
the false target.
Assisted-by: Claude Opus 5.5
- - - - -
8531201d by Mikolaj Konarski at 2026-11-28T10:21:01+01:00
Document bugs and TODOs in static branch prediction and loop analysis
Of what anyone working with the NCG needs, this commit serves "The paper
or earlier design each part of the NCG is based on, where there is one,
and which code is no longer used and since which change.", "Which
designs were tried and given up, and the measurement or the bug
that decided each.", "Where the code does something other than what
reading it suggests.", "Where the code is known to behave wrongly
or is half done.", "What each known bug leads to, such as wrong code,
a compiler panic or only slower code, and under which flags and on which
targets it is reached.", "Each known bug's tracker issue, named
at the code it concerns." and "Where the code is likely to change,
and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments]: BUG
for wrong behaviour, BUG TODO for a bug that is also likely to change,
WIP for half-done work, TODO for what is likely to change, none for what
is meant to stay.
What each BUG leads to, where it is reached and what that rests on:
- getCfg in GHC.CmmToAsm.CFG (BUG: after fixStgRegisters, a test of any
global register with no machine register on the target, CurrentTSO
or CurrentNursery among them, reads BaseReg and is tagged
HeapStackCheck, as is any test that reads BaseReg itself).
The exemptions of Note [Static Branch Prediction] for heap and stack
checks then apply to such a test, so its weights are left unpredicted.
This costs only speed, on x86 and x86-64 under -fcmm-static-pred,
not under -finfo-table-map. This rests on master's code read. The tag
decides the code only through isHeapOrStackCheck, all of whose callers
are in staticBranchPrediction, which runs inside mkGlobalWeights.
mkGlobalWeights reaches the code through staticPredCfg, only
under -fcmm-static-pred, and otherwise only through the graph
allocator's spill costs, on whose frequencies no spill choice depends.
optimizeCFG, which calls staticPredCfg, runs only where the CFG
is kept, and so not under -finfo-table-map.
- Note [Back edges in loopInfo], added to GHC.CmmToAsm.CFG, its BUG
citing ISSUE 28083 (an edge into the entry block is never a back edge,
as mkDomMap leaves the root out of every dominator set). A loop whose
head is the entry block is not found. This costs only speed, on x86
and x86-64 under -fcmm-static-pred, not under -finfo-table-map.
This rests on master's code read and ISSUE 28083's record. loopInfo's
result reaches the code only through static prediction and block
layout: of its two callers, loopLevels is never called,
and mkGlobalWeights serves staticPredCfg, under -fcmm-static-pred,
and otherwise only the graph allocator's spill costs, on whose
frequencies no spill choice depends.
- Note [Back edges in loopInfo] in GHC.CmmToAsm.CFG, its BUG citing
ISSUE 28093 (a self loop is a back edge only where its block dominates
no other block). A block that jumps to itself and to an exit
it dominates, as cmpxchg_code's retry loop in GHC.CmmToAsm.X86.CodeGen
does where the linear allocator puts no fixup block on its retry edge,
is not a loop. calcFreqs then counts the block as irreducible and,
unless the block heads a loop that loopInfo finds, gives it frequency
0, and so 0 to the edges out of it. This costs only speed, on x86
and x86-64 under -fcmm-static-pred, not under -finfo-table-map,
by the same path as the BUG of ISSUE 28083. For static prediction,
loopInfo runs on the CFG after register allocation, so a fixup block
that the linear allocator puts on the retry edge makes the retry loop
a cycle of two blocks, which loopInfo finds. This rests on master's
code read, on the record of ISSUE 28093, and on -ddump-cfg-weights
by the compiler of master 37ad471050: of MR 16269's test T28093.cmm,
a self loop whose block dominates the exit, which weighs the self edge
and the exit edge 0, and of a loop calling fetchOrIntArray#, which
weighs the retry block's edges and the loop's back edge 0;
and on -ddump-cfg-weights at -O by a compiler of master's code,
of .cmm procedures: for x86-64, of one applying %fetch_or64, whose
retry block keeps its self loop, both of its edges weighing 0,
and of the same with fourteen locals live across the operation, whose
retry edge gets a fixup block, the exit edge weighing 1; given an i386
target description through -B, of one applying %fetch_or32, whose
retry edge gets a fixup block, the exit edge weighing 1, and which
under -fregs-graph keeps its self loop, both of its edges weighing 0;
and, for i386, of a hand-written self loop whose block dominates
the exit, both of whose edges weigh 0, and 799 and 801
under -fno-cmm-static-pred.
- Note [Static Branch Prediction] in GHC.CmmToAsm.CFG (BUG: the back
edge rule supersedes a likely annotation in the Cmm as well). A branch
with both a back edge and another edge is predicted to take the back
edge, whatever its annotation says, unless an edge of it is tagged
HeapStackCheck (a heap or stack check). This costs only speed, on x86
and x86-64 under -fcmm-static-pred, not under -finfo-table-map.
This rests on master's code read: staticBranchPrediction's case
for a mix of back edges and other edges tests no annotation.
- ohPredicts in staticBranchPrediction, GHC.CmmToAsm.CFG (BUG TODO:
a constructor-tag test is predicted like any other comparison).
The prediction is wrong for the trees of Data.Map and Data.Set, which
declare Bin first, where the test is left spelt as an equality,
as in a client's copy of Data.Map's lookup specialised at Int keys:
the side that stays in the loop is predicted unlikely. This costs only
speed, on x86 and x86-64 under -fcmm-static-pred,
not under -finfo-table-map. It is accepted until the knowledge
of the likely side reaches the CFG, hence TODO as well. This rests
on master's code read and on a compiler of master's code at -O1
and -O2, which left an equality in a client's copy of lookup
specialised at Int keys, and inverted the test in that client's copies
of Data.Map's and Data.Set's member and in Data.Map.Internal's own
lookup and member.
- ohPredicts in staticBranchPrediction, GHC.CmmToAsm.CFG, its BUG
(ohPredicts treats s1 as the true side only where it is ltrue,
the label the branch was made with, which an edge no longer ends
at once the linear allocator's fixup block, by addNodesBetween,
the block that allocMoreStack moves the entry block's code to,
by addPreentryBlock, or shortcutting, by shortcutWeightMap, has
redirected it). Where the redirected true edge's new target has
the smaller label of the two, each side gets the other's prediction.
This costs only speed, on x86 and x86-64 under -fcmm-static-pred,
not under -finfo-table-map. This rests on master's code read, and
on a compiler of master 37ad471050's code with a counter added, which
found over nofib's modules 7 of the 4874 unannotated equality tests
with a literal predicted inverted at -O2 and none of the 4401 at -O1.
- calcFreqs in GHC.CmmToAsm.CFG (BUG: mkGlobalWeights passes the loops
in the order of loopInfo's back edges, descending by label, and
not by nesting). An enclosing loop's pass can come before an inner
loop's and use the branch probability of an inner back edge where
its cycle probability belongs, which gives nested loops wrong cycle
probabilities. This costs only speed, on x86 and x86-64
under -fcmm-static-pred, not under -finfo-table-map. This rests
on master's code read and on -ddump-cfg-weights by a compiler
of master's code at -O1 and -O2: of a .cmm procedure of a loop
counting down to 0 nested in another, each loop testing its counter
at its head and the outer one jumping out where an equality test
of its counter with 0 holds, the outer loop's latch having the larger
label, which weighs the outer back edge 448, and of the same nest
with the inner loop's test inverted, giving the inner latch the larger
label, which weighs the outer back edge 7.
A WIP in Note [Static Branch Prediction] says that the paper's other
heuristics are stubs.
calcFreqs' comment on an irreducible block, "Rare we don't care", now
says what frequency such a block keeps and, as a TODO, where such blocks
arise and how few procedures of a sample hold one, that the layout
then ranks edges by frequencies that do not add up, with a loop calling
fetchOrIntArray#, compiled for x86-64 by the compiler of master
37ad471050, for a case, and that summing their inflow was tried
on a development branch and kept there. In the CFGs
that -ddump-cfg-weights gives as final, from a compiler of master's
code, of containers at -O1 and of 49 nofib programs at -O2, 4 procedures
of 11410 hold a block that at least 0.01 enters and nothing leaves,
and a replication of calcFreqs' test takes those 4 blocks as irreducible
and no other, none of them on a self loop: in compress2 and in scs, each
on a cycle that is entered at two of its blocks and runs through
a call's continuation. Of two Cmm procedures compiled by that compiler
at -O1, one gives 0 to a block whose only loop is on itself, though 0.5
enters it, and the other gives 1 to the head of a loop that also loops
on itself, though 0.00098 enters the loop, which 0.088 then leaves.
Other TODOs say:
- in Note [Back edges in loopInfo], that findBackEdges, which
optHsPatterns uses for the back edge bonus, and loopInfo differ
on edges into the entry block, on back edges of irreducible cycles
and on a self loop only where its block dominates no other block;
- at ohPredicts, that it matches only MO_Eq, so the spelling
GHC.Cmm.ContFlowOpt leaves decides whether a test is predicted,
and that predicting a pointer-tag test spelt with MO_Ne as its MO_Eq
spelling is predicted was tried on a development branch and cost nofib
0.36% more instructions at -O2;
- at lehPredicts, that where a heap or stack check's call to the garbage
collector returns into the procedure, loopInfo counts the cycle
through that call as a loop: lehPredicts then returns Nothing
for a branch into the checking block where that block is the loop's
head, and counts a branch towards a case alternative without such
a check as a loop exit where the head is the block choosing
the alternative;
- at calcFreqs, that nothing checks its result, and that a check could
compare each block's frequency with the sum of the frequencies
on its in-edges, which the propagation departs from at some blocks,
among them an irreducible block, a loop head whose cycle probability
is capped, and the entry block;
- at loopMembers, that neither it nor loopLevels has a caller in GHC:
loopMembers since the graph allocator's spill costs, for which
it was added early in 2019, began that year to weight by block
frequencies instead, and loopLevels since it came with the loop
analysis that year.
A comment at optimizeCFG says that static prediction starts
from the weights optHsPatterns leaves, so that their adjustments carry
into the predicted probabilities, except where the back edge rule
replaces them.
Assisted-by: Claude Opus 5.5
- - - - -
0bbada46 by Mikolaj Konarski at 2026-11-28T10:41:01+01:00
Document bugs and TODOs in liveness and the register allocators
Of what anyone working with the NCG needs, this commit serves "Which
designs were tried and given up, and the measurement or the bug
that decided each.", "The invariants the code depends on.", "Where
the code does something other than what reading it suggests.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached.", "Each known
bug's tracker issue, named at the code it concerns." and "Where the code
is likely to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments].
What each BUG leads to, where it is reached and what that rests on:
- regAlloc in GHC.CmmToAsm.Reg.Graph (BUG: once regSpill has grown
the pool of slots, it returns slotsCount', the pool's highest slot
number, which counts the preallocated slots and every slot
of the pool, used or not, as the stack needed, and the driver passes
it to ncgAllocMoreStack, where the linear allocator's regAlloc returns
only the slots from maxSpillSlots on): the preallocated slots
are reserved a second time, and with them the slots that no spill
uses, as the pool starts with maxSpillSlots+1 slots and regSpill
in GHC.CmmToAsm.Reg.Graph.Spill grows it 512 slots at a time when
a round of spilling needs more than are free. This costs C stack
space, under -fregs-graph or -fregs-iterative, on every target the NCG
compiles but wasm32, and where a target's mkStackAllocInstr returns
more instructions for a larger amount, code at entry and exit:
on AArch64 one instruction more for each 4095 bytes, on RISC-V,
LoongArch and PowerPC more past the range of an immediate,
and on Windows x86-64 a call of ___chkstk_ms past 4 KB. This rests
on master's code read and on a compile by a compiler of master's code,
at -O0 on x86-64, of a procedure whose live locals took 2042 spill
slots: under -fregs-graph its code reserved 2551 slots (subq
$20416,%rsp), and under the linear allocator 32 bytes. The graph
allocator can be chosen for any target the NCG compiles but wasm32,
and trivColorable covers x86, x86-64, PowerPC, AArch64, RISC-V
and LoongArch.
- regAlloc_spin in GHC.CmmToAsm.Reg.Graph, its branch for a round
that spills (BUG: nothing evaluates the graph it validates
under -dasm-lint, which goes only into the lazy raGraph field
of a RegAllocStatsSpill, while only a RegAllocStatsStart's raGraph
is ever accessed). So -dasm-lint validates no graph of a round
that spills, only that of the round that colours every node,
and checks less than it appears to. The code is the same: this only
misleads a reader, under -fregs-graph or -fregs-iterative, on every
target the NCG compiles but wasm32. This rests on master's code read
(the accesses to raGraph in GHC.CmmToAsm.Reg.Graph.Stats
and GHC.CmmToAsm, all of a RegAllocStatsStart, raGraph being a lazy
field) and on a program built against the ghc package of a compiler
of master's code, which passed a RegAllocStatsSpill whose raGraph
is an error through the printing of -ddump-asm-regalloc-stages
and -ddump-asm-stats without forcing it. The stages dump's printing
of that graph, which forced the check, was commented out
and then deleted in e174477111 (2010).
- buildGraph in GHC.CmmToAsm.Reg.Graph (BUG: slurpConflicts returns
the set of registers live after each instruction,
and graphAddConflictSet adds each set whole). addConflicts
in GHC.Data.Graph.Ops unions the whole set into the conflict set
of each member, so for N values live together over some N instructions
building the graph makes on the order of N^3 set insertions,
for a graph of N^2/2 edges; regAlloc_spin builds the graph afresh
in each round, under -fregs-iterative as under -fregs-graph.
This costs compile time and memory, up to a compilation that runs out
of memory, under -fregs-graph and -fregs-iterative, from Haskell
at -O1 and from Cmm at -O0, on every target the graph allocators
serve; at -O1 Cmm sinking moves a load to its single use, which keeps
such values from being live together. This rests on master's code read
(slurpConflicts, buildGraph, graphAddConflictSet, addConflicts,
regAlloc_spin) and on a compiler of master's code on x86-64. A Haskell
function that reads 1000 Ints from a MutableByteArray# and returns
the sum of their squares, each value used twice so that sinking leaves
it in place, took at -O1 -c 70 s and 2.0 GB under -fregs-graph
and under -fregs-iterative alike, and 1.5 s and 170 MB
under the linear allocator; with 2100 Ints it ran out of memory
under -fregs-graph within an 8 GB address-space limit. A .cmm
procedure that loads 2100 words into locals and then sums them took
at -O0 -S 8 minutes and 5.3 GB under -fregs-graph, against 0.14 s
and 105 MB under the linear allocator.
- pprSpillCostRecord in GHC.CmmToAsm.Reg.Graph.SpillCost (BUG: it binds
a SpillCostRecord as (reg, uses, defs, life), where the type's
comments give its fields as the writes, the reads and the lifetime).
Only the names are wrong: it prints the two counts in the record's
order, under no names, and their sum divided by the register's node
degree, and nothing in GHC calls it. This rests on master's code read:
slurpSpillCostInfo's incDefs fills the second field and incUses
the third.
- regAlloc in GHC.CmmToAsm.Reg.Linear, at extra_stack (BUG: stack_use
counts the slots used, while the C stack area that the RTS reserves
holds slots 0 to maxSpillSlots): at maxSpillSlots+1 slots regAlloc
returns 1 as the extra stack needed, where none is, and beyond
that one slot more than is needed. This costs C stack space, 16 bytes
at most, as each target's allocMoreStack rounds the amount up
to a multiple of 16 bytes, and at maxSpillSlots+1 slots the blocks
and stack adjustments that ncgAllocMoreStack adds at entry and exit,
under the linear allocator, on every target the NCG compiles
but wasm32. This rests on master's code read: getStackUse returns
the stack map's next free slot, counted from 0 (emptyStackMap); each
target's maxSpillSlots is the number of slots the area holds less 1,
and its spillSlotToOffset puts slot maxSpillSlots inside the area;
and cmmNativeGen gives the graph allocator the free slots 0
to maxSpillSlots.
- saveClobberedTemps in GHC.CmmToAsm.Reg.Linear (BUG TODO, ISSUE 26631:
my_reg is the first free register of the class that the instruction
does not clobber, chosen without regard to what the instructions
before the value's next read do to it). Where they write it too,
as the moves of a C call's arguments into their registers do,
the value is moved from register to register, and where the call
clobbers every register of the value's class, as on x86-64 a C call
clobbers every floating-point register except on Windows, the call
then spills it all the same. This costs only speed, under the linear
allocator, on every target the NCG compiles but wasm32. This rests
on master's code read, on ISSUE 26631's record and on a run
of master's compiler at -O on x86-64 of f x y z = c_hypot z x + y * z
on Doubles, f marked NOINLINE and c_hypot an unsafe foreign import
of hypot, which moved z from xmm3 to xmm0 to xmm4 and then spilled
it before the call of hypot.
- joinToTargets in GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG: on x86
and x86-64 a floating-point == or /= test's block ends in three jumps,
two of which name one target, genCondBranch's parity jump
and a conditional or unconditional one, and each is joined
on its own). Where that target needs a fixup block, each of the two
jumps gets one, with the same moves, and both are reachable, while
only one can fall into the target. This costs only speed and code
size, on x86 and x86-64 under the linear allocator: where one
of the two falls into the target, the path through the other ends
in a jump to it. Under -fblock-layout-cfg, on by default at -O
and -O2, the edges into the two weigh the same, and sequenceChain
in GHC.CmmToAsm.BlockLayout hands buildChains edges of one weight
in the descending order of CfgEdge's Ord, by label; in the runs below,
this lets the twin of the second of the two jumps fall
into the target, so that a /= test whose true target needs the blocks
ends in a jump to the target on the path taken when the operands
are ordered and differ, and an == test whose false target needs them
on the path taken when an operand is NaN. Without -fblock-layout-cfg,
at -O0 or under -fno-block-layout-cfg, the block has three successors,
and mkNode in GHC.CmmToAsm.BlockLayout gives no preferred successor
to a block with more than two successors in the CFG, so the block's
false target can be placed away from it and reached by a jump.
This rests on master's code read and on constructed Cmm compiled
by a compiler of master's code for x86-64 and, given an i386 target
description through -B, for i386: at -O and at -O2, a /= test whose
true target needs the blocks ends in jne and jp, the jne's twin ending
in a jump to the target, where a > test's one fixup block falls
into it, and an == test whose false target needs them falls through
its unconditional jump's twin into the target, its parity jump's twin
ending in a jump to it; under -fno-block-layout-cfg, at -O, the /=
test also ends in a jump to its false target, which the > test falls
into. No module of the compile benchmarks, compiled by master's
compiler, was found to show it. A fix that shares the block where
the two jumps' stack deltas agree, the target's vregs have the same
locations at both and no value moves between two slots was written
on a development branch and is left out.
- Note [The first jump into a block fixes its entry assignment], added
to GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG TODO, ISSUE 27800:
a return continuation is an entry block, and the allocator, going
in SCC order, processes one that jumps into a loop from outside
it before that loop). Where the procedure's entry and such
a continuation enter one loop at two different blocks, the two can
record incompatible assignments, and the loop's own edges then get
fixup code that runs on every iteration. This costs only speed,
under the linear allocator, on every target the NCG compiles
but wasm32. MR 16673 proposes a fix. This rests on master's code read
and on ISSUE 27800's record, whose Cmm procedure gets two fixup blocks
inside its loop on x86-64.
- joinToTargets_first in GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG
TODO, ISSUE 27981: to_free holds only registers that hold virtual
registers, so a real register still allocated at the jump, such as R1
on x86-64 where it is read after a conditional branch, stays allocated
in the free registers recorded for the block, even when it is not live
into it). The block's code then cannot use that register, and a jump
from it into a block whose entry assignment holds a value there gets
fixup moves, which on a loop's back edge run on every iteration.
This costs only speed, under the linear allocator, where an STG
register's machine register is handed out between its uses: x86-64,
PowerPC and, for XMM1 to XMM4, i386. This rests on master's code read,
on ISSUE 27981's record and on a run of master's compiler at -O
on the issue's program on x86-64, in which a loop's return
continuation falls into a fixup block of two moves before the loop
head on every iteration.
- makeRegMovementGraph, handleComponent and makeMove
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, and the header
of GHC.CmmToAsm.Reg.Linear.StackMap (BUG, ISSUE 27638: since ISSUE
26668 a virtual register whose format has outgrown its slot gets new
slots, so a jump can need a move between two slots of one register):
such a move ends in makeMove's panic, "makeMove: we don't handle
mem->mem moves". And where handleComponent's cyclic case moves
to an InBoth destination (BUG, a statement of its own, ISSUE 27638
reporting only the panic), the destination's slot is written only
if it is the slot spillR picks; otherwise it can keep a stale value,
which is wrong code where the slot is reloaded. Both can be reached
only under the linear allocator, where a virtual register's format
grows past 8 bytes, which only a vector format does, and so only
on i386, x86-64 and AArch64, the targets whose regUsageOfInstr can
give a register a vector format: those of PowerPC, RV64 and LA64 give
every register the format of its class, of 8 bytes at most (regFormat
in their Instr modules), and RV64's and LA64's stop with sorry
on a vector register. The first is reached on x86-64 at -O0, -O1
and -O2: master's compiler panics so at all three on a function
in which a Double# is passed to an unsafe foreign call of type Double#
-> Double#, then broadcast to a DoubleX2# whose lane goes to a second
such call in one arm of a case whose other arm returns the first
call's result, and used again after the case, whose result a strict
let binds. No program leaving a stale slot is known. The first can
be reached two ways, by expandNode, both from a jump at which
the virtual register is in one of its slots only: into a block
that holds it in another of its slots only, and into a block
that holds it in a register and another slot, where makeMove loads
the register first. A fix cannot count on a spare register: nothing
keeps one free at a jump, and the block's entry assignment can hold
every allocatable register, on x86-64 the eleven integer registers
(rax, rbx, rcx, rdx, rsi, rdi, r8 to r11 and r14) and the sixteen
vector registers, the others being the stack pointer and
those of STG's Base, Sp, Hp and SpLim (freeReg
in compiler/CodeGen.Platform.h). This rests on master's code read,
ISSUE 27638's record, a run of master's compiler and a compiler
of master's code given 64-bit PowerPC ELFv2 and ELFv1, RISC-V
and LoongArch target descriptions through -B: at -O a function adding
two DoubleX2# arguments went through PowerPC's register allocator,
as -ddump-asm-regalloc shows, to a panic in pprInstr on a VecFormat
load, and stopped on a W128 load in RV64's and LA64's getRegister,
and a broadcast or a pack gave the sorry of checkVecCompatibility.
The cyclic case drops the InMem half of an InBoth destination
(expandNode lists InReg first) and writes only spillR's slot, which
is getStackSlotFor's newest slot of the virtual register and differs
from the destination's only after the register grew.
And allocateRegsAndSpill frees the register of an InBoth virtual
register without a store, so that its next use reloads the slot.
- handleComponent and makeMove in GHC.CmmToAsm.Reg.Linear.JoinToTargets
(BUG: handleComponent's cyclic case spills the first move's source
at the source's format and reloads it at the destination's,
and makeMove loads from a slot at the destination's format too). Where
the destination's format is a vector one and the slot was written
at a narrower one, the load reads past what was written,
into the bytes after the slot, which can be another virtual register's
slot, against Note [Use spilled format when reloading]
in GHC.CmmToAsm.Reg.Linear, which says that a register is reloaded
at the format it was spilled at. That is wrong code where a value
is computed from a lane so loaded; no program is known to compute one.
The formats differ so where X86's broadcast of a Double# or a Float#
writes the scalar's own register at the vector's format on the path
of the first jump into a block, which fixes the block's entry
assignment (Note [The first jump into a block fixes its entry
assignment]), and another jump into the block holds the scalar
at its own format, in a register in a cycle of moves or in its slot.
That is reached on x86-64 and i386 at -O0, -O1 and -O2. This rests
on master's code read (spillR, whose slot getStackSlotFor sizes
by the format given, and loadR; expandNode and makeRegMovementGraph,
which keep each end's format; makeMove's case for a move from a slot
to a register; vector_float_broadcast_sse
and vector_float_broadcast_avx in GHC.CmmToAsm.X86.CodeGen, which take
their operand's register from getSomeReg and write it) and
on a compiler of master's code. On x86-64, for a function in which
a Double# x, passed to a C call, is broadcast to a DoubleX2# in one
arm of a case and read as a Double# by a join point both arms jump to,
the cyclic case's fixup block spilled x with movsd and reloaded
it with movupd at -O1 under -msse4.2 and with no -m flag and at -O2
-msse4.2, and with vmovupd at -O1 -mavx, the upper lane coming
from the next slot, which the same block had just written with another
variable's value; with a Float# broadcast to a FloatX4# it reloaded
with movups, and with a DoubleX4# under -mavx2 with vmovupd into a ymm
register. In a variant whose other arm does not read x, which
then stays in its slot at that arm's jump, makeMove's load of x
was movupd too, at -O0, -O1 and -O2, on x86-64 and on i386. Both
programs gave at -O1 the results they gave at -O0. In variants
in which a DoubleX2#, FloatX4# or Int64X2# variable or a broadcast
scalar enters such a join point, at -O0 and -O1 under -msse4.2
and at -O2 -mavx2, no block both spilled a slot and reloaded it wider.
Given an AArch64 target description through -B, at -O1, the first
function's broadcast wrote a register of its own, and its cyclic fixup
spilled and reloaded at 8 bytes.
- expandNode in GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG TODO: where
the destination is InBoth with the source's slot, as when a virtual
register is InBoth at both ends of the jump, it stores the value
into a slot that already holds it). This costs only speed and code
size, under the linear allocator, on every target the NCG compiles
but wasm32. This rests on master's code read: the case of an InBoth
source drops the source's slot and expands the node as from an InReg
source, whose cases for an InBoth destination keep the store
to its slot.
- livenessSCCs in GHC.CmmToAsm.Reg.Liveness (BUG, ISSUE 27619: Regs' Eq
compares the registers and not their formats, so the fixpoint can stop
before the formats recorded for a cycle's blocks converge): a vector
register can be recorded live at a format narrower than the value
it holds, and a write at that format then kills
it in minusCoveredRegs, which is wrong code where a later instruction
reads a part of the register that the write leaves alone. On x86 such
a write is one that regUsageOfInstr declares written, not modified,
and that keeps the rest of the register, as a MOV between registers
at FF32 or FF64 (movss, movsd) does. No program is known to give
a wrong result: the insert of a Double# into lane 0 of a DoubleX2#,
a MOV between registers at the vector's format, is declared read
and modified, and so leaves the register live. ISSUE 27619's record
gives the consequence as spills and reloads narrower than the value;
the formats so recorded set no spill or reload width. The linear
allocator spills and reloads at the format of a variable's Loc, which
comes from an instruction's operand: a write's, for a reload
the spill's, or, for a move from a real register that raInsn
eliminates, the move's read in liveDieRead, which at an instruction
that is not a branch holds the instruction's own reads; the graph
allocator spills and reloads at the formats regUsageOfInstr gives
the instruction's operands. This rests on master's code read, on ISSUE
27619's record, whose program shows a register recorded so, and
on a compiler of master's code: a variant of that program
with an unsafe C call in its loop, whose counter rises so
that it ends, compiled at -O -fno-cse, records the DoubleX2# at FF64
on entry to the loop's head, and it is spilled and reloaded at 16
bytes, by movupd or, under -mavx, vmovupd, under both allocators,
the graph allocator also reloading 8 bytes for the instructions
that read lane 0 alone; the program gives the result it gives at -O0.
- getSlotMap in slurpReloadCoalesce, GHC.CmmToAsm.Reg.Liveness (BUG:
it folds the slot maps of a block's predecessors from the empty map
with mergeSlotMaps, which keeps only the slots both maps hold).
The slot map on entry to a block is always empty, so a reload
is coalesced with a spill only inside one block. This costs only speed
and code size, under -fregs-graph or -fregs-iterative, on every target
the NCG compiles but wasm32. This rests on master's code read;
buildGraph in GHC.CmmToAsm.Reg.Graph is the only caller
of slurpReloadCoalesce.
- maxRegWithFormat in GHC.CmmToAsm.Reg.Regs (BUG, ISSUE 27619: Format's
derived Ord compares a VecFormat's number of elements before their
format, ranking VecFormat 16 FmtInt8, 128 bits, above VecFormat 4
FmtDouble, 256 bits): it can keep the narrower of two formats.
Were one register read at both, a write at the narrower would kill
it in minusCoveredRegs, which is wrong code where a later instruction
reads a part of the register that the write leaves alone; whether any
register is read so is not known. This rests on master's code read
and ISSUE 27619's record. The haddocks of minusCoveredRegs
and shrinkingRegs, which compare formats by the same Ord, point to it.
The other statements, by part.
The linear allocator:
- Note [The first jump into a block fixes its entry assignment],
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, says that the first jump
into a block that the allocator processes records the block's entry
assignment, spilled values included, and that every later jump
conforms to it by fixup code. Its two TODOs, and its BUG TODO
for ISSUE 27800 above, are what follows from that: a loop head
recorded from a preheader that spilled a loop-carried value has
the value reloaded on every iteration, and stored again by every back
edge once the body has written it; and the block that a failed heap
or stack check returns to from the garbage collector can be allocated
before the hot path's jump into the checking block and record
that block's entry assignment, as the order of allocation depends
on no frequency. process' comment cites the Note.
- Note [Unique order in the linear allocator], added
to GHC.CmmToAsm.Reg.Linear, first lists the tags that the vregs'
uniques carry, in their order, and says which of them
-fobject-determinism renames. It then says, as a TODO, which decisions
take the order of the vregs' uniques as a ranking: the spill victim,
and the order in which saveClobberedTemps moves values out
of clobbered registers. It also says that the order decides,
of joinToTargets' fixup moves, the order of those that their
dependencies leave free and which move of a cycle goes through
the stack. The comments at those three folds cite it.
- Issues get labels where the code behaves as they report: BUG TODO
for ISSUE 26631, ISSUE 27800 and ISSUE 27981 above, and BUG for ISSUE
27638 at handleComponent, makeMove, makeRegMovementGraph
and StackMap's header, whose comments ruled out a move between two
stack slots, which ISSUE 26668 made possible.
- TODOs without an issue: raInsn's elimination of a move gives
the destination the source's register, whatever register an entry
assignment recorded for a block it is live into; and findPrefRealReg's
preference is keyed by virtual register, while a Cmm local is one
virtual register over all its live ranges.
- The header of GHC.CmmToAsm.Reg.Linear.StackMap says that a stack slot
belongs to one virtual register for the whole procedure,
as getStackSlotFor takes new slots only at the next free one, which
only grows, and a register that outgrows its slot gets another,
keeping the first; that the fixups at a jump rely on this; and
that it costs stack, the slots of a procedure adding up over every
register spilled in it.
- Step (j) of the outline at the top of GHC.CmmToAsm.Reg.Linear,
re-adding a dead spilled register's stack slot to the free list,
is marked WIP: it is not done, as a StackMap never frees a slot.
- A comment at clobberRegs' filter says that on AArch64, RISC-V
and LoongArch frAllocateReg panics on a register that is not free.
- Three designs tried on a development branch are recorded, with what
each trial measured, beside the code they would change: handing out
the floating-point registers in descending order (at the BUG TODO
for ISSUE 26631 in saveClobberedTemps), taking the entry block first
and then, after each SCC, an SCC holding a block whose entry
assignment is recorded, a cyclic one first (at the BUG TODO for ISSUE
27800), and putting fixup moves before an unconditional jump rather
than in a block of their own (in joinToTargets_again).
Liveness, in GHC.CmmToAsm.Reg.Liveness and GHC.CmmToAsm.Reg.Regs:
- The comment at the fixpoint of livenessSCCs says that its test
compares the whole map, where only the SCC's blocks can change (TODO,
ISSUE 27437), and that its steps are monotone, so that a test
comparing the formats too would reach a result independent
of the order in which the blocks are walked. The comment at Regs' Eq
says that Eq ignores formats and that ISSUE 27619 proposes one
that compares them (TODO, ISSUE 27619), and points to the BUG
at livenessSCCs for what ignoring them leads to.
- The comment on the SCCs' order says that no block may fall through,
and liveDieRead's haddock that at a branch it also holds the registers
live into its targets only.
- A comment at computeLiveness' panic on SCCs out of reverse dependent
order says that, where sccBlocks has a CFG, a jump to a block missing
from the CFG reaches it too.
The graph allocator: in GHC.CmmToAsm.Reg.Graph.SpillCost, a WIP comment
says that the block frequencies scale only the counts of uses
and definitions, on which no spill choice depends, as spillCost_chaitin,
which would use them, is commented out.
Both allocators: a TODO at patchRegsOfInstr says that, as it maps
a register to a register, both allocators reload a spilled value
into a register for an instruction that reads it, even at its last read,
where an x86 instruction could read the stack slot.
Assisted-by: Claude Opus 5.5
- - - - -
1e1c5215 by Mikolaj Konarski at 2026-11-28T10:49:33+01:00
Document bugs and TODOs in code generators, DWARF and an unused module
Of what anyone working with the NCG needs, this commit serves "The paper
or earlier design each part of the NCG is based on, where there is one,
and which code is no longer used and since which change.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached.", "Each known
bug's tracker issue, named at the code it concerns.", "Where the code
is likely to change, and how." and "What the NCG leaves to the assembler
and the linker: which operand ranges a code generator checks and which
only the assembler rejects, which branches the NCG lengthens, and which
assemblers its output is written for."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments].
What each BUG leads to, where it is reached and what that rests on:
- getRegister' in GHC.CmmToAsm.AArch64.CodeGen (BUG, ISSUE 28126:
isNbitEncodeable 12 admits label offsets from -2048 to 2047, while
check_off in GHC.CmmToAsm.AArch64.Ppr accepts only 0 to 4095):
on AArch64, compiling a label at an offset from -2048 to -1 stops
with check_off's error, a pgmError,
"GHC.CmmToAsm.AArch64.Ppr.check_off : -8 is out of 12 bit"
for an offset of -8. Below -2048 the guard fails, and the next clause
adds the offset through a register. This rests on master's code read
(litToImm', ImmIndex, check_off), ISSUE 28126's record and a run
of master's x86-64 compiler given an AArch64 target description,
in which a Cmm load from a label less 8, at -O0 and at -O,
and plusAddr# of a string literal and -1#, at -O, stop
with check_off's error; nothing was run on AArch64.
- lower_CmmRegOff in GHC.CmmToAsm.Wasm.FromCmm and the cases
for CmmRegOff of getRegister' in GHC.CmmToAsm.RV64.CodeGen
and GHC.CmmToAsm.LA64.CodeGen, one BUG at each (the sum
is not truncated to a sub-word register's width, as each target's
general lowering of a sub-word MO_Add truncates its result,
and cmmMachOpFoldM in GHC.Cmm.Opt folds a sub-word register plus
or minus a literal into a CmmRegOff at any width validOffsetRep
allows). Where an operation reads the bits above the width,
this is wrong code: on wasm32 a widening MO_UU_Conv of a sub-word
value masks nothing, and on RV64 Note [Signed arithmetic on RISCV64]
keeps a sub-word value zero-extended between operations. On LA64
the first case breaks the same invariant, stated under "Signed
arithmetic on LoongArch64", harmlessly, each reader of a sub-word
register there that the printer accepts extending or masking it first,
or reading its low bits alone; but MO_Add's case for a literal of 12
bits, at 8 and 16 bits, sign-extends its operand in the operand's own
register, and where that operand is also the first operand
of an unsigned comparison in genCondJump, whose ubcond zero-extends
that register ahead of the second operand's code, the extension undoes
the zero extension and the branch compares the sign-extended value.
This is wrong code on LoongArch, from Haskell at -O and -O2, where
sinking puts the sum into the comparison: the code for x < x + 5
on a Word8 gives False for x from 128 to 250, and on a Word16 for x
from 32768 to 65530. At -O -fno-cmm-sink the comparison goes through
getRegister''s case for MO_U_Lt, which extends after both operands'
code, and at -O0 through Word8's Ord and Num methods, and both
are right. Most other cases of an operation of 8 or 16 bits extend
or mask its operand in place too, among them those of the shifts,
of MO_And, MO_Or and MO_Xor and of MO_Mul, MO_S_Quot, MO_S_Rem,
MO_U_Quot and MO_U_Rem, all but the shifts' at 32 bits too: a zero
extension there undoes the sign extension that genCondJump's sbcond
makes for a signed comparison, and a sign extension the zero extension
of ubcond. Haskell reaches each of those named at -O and -O2, where
sinking puts the operation into the comparison and its operand
is the comparison's first operand: the code for x < x * 3 gives False
on a Word8 for x from 129 to 170, on a Word16 from 32769 to 43690
and on a Word32 from 2147483649 to 2863311530; and the primops
on sub-word values reach the shifts and the logical operations,
as in ltInt8# of x and of x masked with 127 by andWord8#, whose code
gives False for x from -128 to -1. The methods of Bits tried on Word8
and Int8 shift or mask a conversion of the operand into a register
of its own, and their code is right. LA64's second case is,
for a register of 8 or 16 bits, a compiler panic, "LA64.ppr: ADD
error": its ADD of two registers at the register's width is one
that GHC.CmmToAsm.LA64.Ppr prints at 32 and 64 bits alone. An 8-bit
register reaches it where the folds add literals one at a time
to a CmmRegOff, summing the offsets unnarrowed. This rests on master's
code read, ISSUE 28133's record and runs of a compiler of master's
code given RISC-V and LoongArch target descriptions through -B, on Cmm
with -dcmm-lint: a bits8 local plus 1, compared with 0 at -O
-fno-cmm-sink, under which the NCG folds nothing into a CmmRegOff,
became on RV64 an add with no truncation before the comparison;
a bits16 local plus 5000, and a bits8 local plus 100 added 21 times
in one expression, each local also stored, at -O0 and at -O,
were returned through %zx64 with no truncation on RV64 and made
the compiler panic so on LA64; and on LA64 a bits8 local plus 1
was extended or masked wherever it was shifted, multiplied, negated,
divided, compared, switched on, converted or passed to a C call.
On LA64, for a Haskell function f x = if x < x + 5 then 1 else 0
on Word8, at -O and -O2, it printed bstrpick.d $a0,$a0,7,0, ext.w.b
$a0,$a0, addi.d $a1,$a0,5, bstrpick.d $a1,$a1,7,0 and bgeu $a0,$a1,
the branch taken to return 0, and likewise ext.w.h and bstrpick.d
to 15 bits on Word16 and addi.d $a1,$a0,-5 for x - 5; for x < x * 3
on Word8, at -O and -O2, it printed bstrpick.d $a0,$a0,7,0 and ext.w.b
$a0,$a0 before mul.d $a1,$a0,$a1 and bgeu $a0,$a1,
and the instructions from each such function's entry to its branch,
run in a simulator over every 8- and 16-bit input and over a sample
of 32-bit ones, were wrong at those inputs alone, and at -O
-fno-cmm-sink, on Word8 and Int8, at none; on Cmm with -dcmm-lint,
at -O0 and -O, x < x + 5::bits8 on a bits8 x gave the same sequence
before a bltu, and %lt(x, x >> 1), %lt(x, x & 0x7f::bits8) and %ltu(x,
x << 1) gave an extension of x in place between the comparison's own
extension of x and the branch, as did %lt(x, x & 0x7f::bits32)
on a bits32 x, at -O. Nothing was run on these targets, and nothing
was compiled for wasm32. On RV64 and LA64 an offset that fits in 12
bits goes to the case of MO_Add for such a literal, or on RV64
for an offset from -2047 to -1 to that of MO_Sub, which does
not truncate either; on RV64 an offset of -2048 goes to MO_Sub's
general case, which truncates. RV64's BUG cites ISSUE 28133, which
reports the cases of MO_Add, MO_Sub and MO_Or for a register
and a 12-bit literal, the first two of which RV64's first case
reaches; its other case has no issue.
- makeFarBranches in GHC.CmmToAsm.AArch64.CodeGen (BUG: instr_pos counts
an LDR of a label as one instruction, where it prints as two, or three
with an offset, and the meta instructions DELTA, PUSH_STACK_FRAME,
POP_STACK_FRAME and, in a DEBUG compiler, MULTILINE_COMMENT as one
each, where replace_jump counts them as none). The estimate
of a branch's distance can fall short, that of a backward branch
by at least one for each of these meta instructions before its target,
and a conditional branch beyond its reach is then left as it is,
on AArch64. LLVM's assembler (clang 18) and GNU as 2.42 reject such
a module. This rests on master's code read (instr_pos, replace_jump,
isMetaInstr, and the printing of LDR in GHC.CmmToAsm.AArch64.Ppr)
and on a compiler of master's code given an AArch64 target description
through -B: of a Cmm procedure that branches over 42000 stores
of a label plus an offset to addresses 8 bytes apart, it printed
at -O0 a cbz whose target lay past its reach of 1 MiB, which LLVM's
assembler rejected ("fixup value out of range"), as GNU as did
("conditional branch out of range"); with 70000 stores the estimate
passed the threshold and the branch was rewritten. Of a procedure f
(W_ x, W_ p) of 2000 C calls, each with a PUSH_STACK_FRAME, printed
as two instructions, a POP_STACK_FRAME and two DELTA, then a loop
of 263000 stores W_[p] = x, printed as one str each, that tests x != 0
and leaves x unchanged, it printed at -O0 a cbnz whose target lay
263002 instructions back, past its reach, which both assemblers
rejected likewise; without the calls the branch was rewritten,
and where the loop also decremented x the cbnz went instead to a fixup
block within its reach, which the linear allocator put on the loop's
back edge.
- makeFarBranches in GHC.CmmToAsm.RV64.CodeGen (BUG: max_jump_dist
is 2^11-1 instructions, where a BCOND, printed as a B-type branch,
reaches 4 KiB each way, 1024 instructions back and 1023 forward where
none is compressed; and instr_size counts a MOV that prints as li
as two instructions, where the assembler expands li of a 64-bit
constant to up to eight). A conditional branch whose target lies more
than 4 KiB away, but fewer than 2^11-1 instructions by the estimate,
is left beyond its reach, on RISC-V, and only an assembler
that lengthens such a branch assembles the module as meant: LLVM's
(clang 18) and GNU as 2.42 lengthen such a beq, with and without
-mno-relax. This rests on master's code read and on a compiler
of master's code given a RISC-V target description through -B, which
printed such a beq past its reach, not rewritten, that both assemblers
turned into a bne over a j. The second cause leaves a branch
that a corrected max_jump_dist would also leave: at -O, for a .cmm
procedure whose branch skips 300 stores of distinct 64-bit constants,
it printed a beq over 300 li and 300 sd, counted near 900
instructions, under 1023, which GNU as 2.42 placed 11 KiB, 0x2c28
bytes, before its target, each li expanded to eight instructions,
and lengthened to a bne over a j without a message, as clang 18 did.
No Haskell program was shown to reach it.
- makeFarBranches in GHC.CmmToAsm.LA64.CodeGen (BUG: replace_jump
rewrites BCOND1 alone, never BEQZ or BNEZ, which genCondJump also
emits and which reach 4 MiB each way; instr_size counts a MOV
that prints as li.d as one instruction, where the assembler expands
li.d to up to four; and replace_jump advances its position by two
for each BCOND1 it rewrites, where instr_size counted one).
The estimate of a forward branch's distance falls short by one
for each BCOND1 rewritten before its target, through the advance where
the BCOND1 comes before the branch and through instr_size's count
where it comes between the two. A conditional branch beyond its reach
can be left as it is, on LoongArch, and LLVM's assembler (clang 18)
then rejects the module, where GNU as 2.42 lengthens the branch.
This rests on master's code read and on a compiler of master's code
given a LoongArch target description through -B, which left as they
were a beqz past its reach; in a procedure of 9000 li.d and 9000
stores that the estimate put below its threshold, a bltu past BCOND1's
128 KiB; at -O0, after 40 BCOND1 that it rewrote, a bltu with 32780
instructions between it and its target, which it rewrote without
the 40; and, at -O0 too, a bltu with 40 BCOND1 that it rewrote
and 32700 stores between it and its target: LLVM's assembler rejected
all four ("fixup value out of range"), and expanded two of the second
procedure's li.d, assembled alone, to three and four instructions; GNU
as 2.42 assembled each of the four as the inverted branch over a b.
- do_mul_may_oflo in GHC.CmmToAsm.LA64.CodeGen, local to getRegister',
its case for W32 (BUG: MULW is given operands of 64 bits, which
GHC.CmmToAsm.LA64.Ppr prints at 32 bits alone). MO_S_MulMayOflo at 32
bits is then a compiler panic, "LA64.ppr: MULW error", on LoongArch,
at -O0 and -O, from hand-written Cmm alone: StgToCmm emits
MO_S_MulMayOflo for IntMulMayOfloOp at the word's width, and the cases
for 8, 16 and 64 bits compile. The testsuite's MulMayOflo_full.cmm
panics so, and its all.T marks it expect_broken(23742) on every
architecture but AArch64, x86-64, i386 and RISC-V; ISSUE 23742 reports
that the other backends compute the MachOp wrongly for sub-word inputs
and names no panic. This rests on master's code read
(do_mul_may_oflo's cases, and MULW's printing) and on a compiler
of master's code given a LoongArch target description through -B,
which panicked so at -O0 and -O on r = %mulmayoflo(a, b)
of a procedure's two bits32 arguments, which -dcmm-lint passes,
and at -O on MulMayOflo_full.cmm; at bits8, bits16 and bits64
it compiled.
- makeFarBranches in GHC.CmmToAsm.PPC.Instr (BUG: blockLen counts each
instruction as one, where MFOV, LDFAR, STFAR and FETCHPC print as two,
as does a BCC that makeFar turns into a BCCFAR). The estimate
of a branch's distance can fall short by more than the margin
that nearLimit, 7000 instructions less maxRetInfoTableSizeW for each
info table, keeps below bc's reach of 8192 instructions back and 8191
forward, and a conditional branch beyond its reach is then left
as it is, on PowerPC. LLVM's assembler (clang 18) encodes such
a branch without a message, with a wrapped displacement, which
is wrong code, and GNU as 2.42 rejects the module. This rests
on master's code read (blockLen, nearLimit, makeFar, and the printing
of these instructions in GHC.CmmToAsm.PPC.Ppr) and on a compiler
of master's code given a 64-bit PowerPC target description
with the ELFv2 ABI through -B: of a Cmm procedure that branches
over 2300 stores of %mulmayoflo, it printed at -O0 a beq with 9205
instructions between it and its target, past its reach of 32 KiB,
which LLVM's assembler encoded as a branch backwards and GNU as 2.42
rejected ("operand out of range").
- iselExpr64 in GHC.CmmToAsm.PPC.CodeGen (BUG: it has no case
for a conversion to 64 bits from fewer than 32, or for a 64-bit
multiply, shift or logical operation). Each such expression panics
("iselExpr64(powerpc)"), a failed compilation, on 32-bit PowerPC,
at -O0 as at -O1. On this target StgToCmm emits the Int64# and Word64#
primops for these operations as callish MachOps, such as MO_x64_Mul,
which genCCall compiles to a call of hs_mul64, as stgToCmmAllowArith64
in GHC.Driver.Config.StgToCmm is off for the NCG of a 32-bit target
other than i386 and wasm32, and an Int8# reaches 64 bits through
the word; so only hand-written Cmm is known to reach these cases,
though ISSUE 26828, closed, showed GHC's own source reaching
iselExpr64 with a 64-bit subtraction of a literal, which has a case
on master. This rests on master's code read (iselExpr64's cases;
stgToCmmAllowArith64, and opTranslate64 in GHC.StgToCmm.Prim) and
on a compiler of master's code given a 32-bit PowerPC target
description through -B. At -O0 and -O1 it panicked so on bits64[p] =
%zx64(x) for a bits8 or a bits16 x, on %sx64 of a bits8 and
on the product of two bits64 loads, and at -O1 on %sx64 of a bits16,
a 64-bit shift and a 64-bit and; it compiled %zx64 of a bits32
and the sum of two bits64 loads at -O0 and -O1, and %sx64 of a bits32
at -O1. Haskell was not compiled for this target, and nothing
was assembled.
- getRegister''s case for CmmRegOff in GHC.CmmToAsm.X86.CodeGen (BUG:
neither mangleIndexTree nor add_int narrows the offset
to the register's width, and cmmMachOpFoldM's folds of literals
into a CmmRegOff sum them unnarrowed). For a 16-bit register whose
offset lies outside 16 bits, add_int's LEA, printed as an ADD
of an immediate where the result takes the operand's register, makes
the assembler shorten the immediate, with a warning where
its magnitude reaches 2^16 (addw $90000,%ax for a 16-bit register plus
three times 30000); the shortened immediate gives the value meant,
so this costs at most the warning, on x86 and x86-64. An 8-bit
register's sum takes an ADD whose immediate litToImm narrows, an LEA
printed as an LEA takes the offset as a 32-bit displacement without
a warning, and a wider register holds any offset add_int is given.
This rests on master's code read (mangleIndexTree, add_code, add_int
and the printing of an LEA as an ADD in GHC.CmmToAsm.X86.Ppr),
on master's compiler, whose assembly for such a sum in Cmm made
the assembler warn so, and on GNU as given addw and leaw with such
an immediate and displacement, with and without --32: it warned
of the addw alone and assembled both.
- getRegister''s case for MO_V_Broadcast in GHC.CmmToAsm.X86.CodeGen,
above its first alternative, with a pointer at its case
for MO_V_Insert 2 W64 (BUG: on i386, vector_int64x2_broadcast
and vector_int_broadcast_avx2 for 64-bit lanes,
and vector_int64x2_insert_sse2 and vector_int_insert_pinsr
for MO_V_Insert 2 W64, compile the 64-bit integer
by getNonClobberedReg, into one 32-bit register, and move it by MOVD
or PINSR at II64). On i386 a 64-bit integer takes two registers, which
iselExpr64 gives; getRegister' instead panics on a 64-bit load
("getRegister(x86) CmmLoad"), gives for a 64-bit Cmm local the virtual
register of its low half, VirtualRegI of its unique, and compiles
a 64-bit literal to a MOV at II64, printed movq. MOVD and PINSR
at II64 are printed movq and pinsrq of that 32-bit register, neither
of which exists in 32-bit mode. So, from Haskell, each
broadcastInt64X2# and broadcastWord64X2#, under -mavx2 each
broadcastInt64X4# and broadcastWord64X4#, and each insertInt64X2#,
insertWord64X2#, packInt64X2# and packWord64X2# that reaches the code
generator fails to compile, under -msse4.2, -mavx2 or neither: at -O0,
where the operand is a Cmm local or a literal, the assembler rejects
the module (GNU as: "operand type mismatch
for `movq'", and for an insert under SSE4.1 "`pinsrq' is only
supported in 64-bit mode"); at -O1 and -O2 the compiler panics where
the operand is a load, as a function's argument is, and at -O1
the assembler rejects the module where the operand is a literal
or an unsafe foreign call's result, and an operand computed
by intToInt64# stops the compiler with a sorry error ("Invalid
conversion operation from W32 to W64"). A lane unpacked
from an Int64X2# or a Word64X2# stops the compiler first at -O0,
by the BUG at iselExpr64's last clause, and at -O1 and -O2, where Cmm
sinking puts the lane's extraction into the operand, the extraction
is printed movq or pextrq of a 32-bit register too. getRegister''s
case for CmmLit compiles a vector literal whose lanes are equal
and not zero by MO_V_Broadcast of a lane, so an Int64X2# or Word64X2#
constant of equal lanes that getRegister' compiles fails too,
as a pack of two equal literals does at -O1, where one of zero lanes
or of unequal lanes compiles. A comment on ISSUE 25498, an issue
on SIMD tests that fail on i386 under the LLVM backend, says
that packInt64X2# and unpackInt64X2# are not implemented in the i386
NCG, explaining why the test T25030, which the Makefile compiles
without -fllvm, fails there; that issue reports the test's failure
in the LLVM ways, which the comment proposes to fix by passing -fllvm,
and no issue reports the NCG's failure, so the statement cites none.
This rests on master's code read (getRegister''s cases
for MO_V_Broadcast and MO_V_Insert and its cases for CmmLoad, CmmReg
and CmmLit, getLocalRegReg, mkVirtualReg in GHC.CmmToAsm.X86.RegInfo,
localReg64 in GHC.CmmToAsm.Monad, the four functions, and pprMovdOpOp
and pprPinsr in GHC.CmmToAsm.X86.Ppr) and on a compiler of master's
code given an i386 target description through -B, at -S, its assembly
given to GNU as 2.42 with --32: for f a = broadcastInt64X2#
a the assembler rejected movq %eax,%xmm0 at -O0, and the compiler
panicked at -O1 and -O2, under -msse4.2, -mavx2 or neither; so did
broadcastWord64X2#, packInt64X2#, packWord64X2#, insertInt64X2#,
insertWord64X2#, plusInt64X2# of two broadcasts and timesWord64X2#
of a broadcast and an argument, the assembler rejecting the pinsrq
of the packs and the inserts under -msse4.2 and -mavx2;
broadcastInt64X4# and broadcastWord64X4# did so under -mavx2,
and stopped otherwise with "256-bit wide integer SIMD vector
instructions require at least -mavx2"; at -O1 the broadcast
of a literal and of an unsafe foreign call's result, the insert
of a literal and the pack of two equal literals compiled to assembly
the assembler rejected, and the packs of two unequal literals
and of two zeros compiled to assembly it accepted; clang 18, given
-target i386-linux-gnu, rejected the assembly of broadcastInt64X2#
at -O0, of broadcastInt64X4# at -O0 under -mavx2, of insertInt64X2#
at -O0 under -msse4.2 and of the two broadcasts at -O1; plusInt64X2#
of two arguments, broadcastInt32X4#, broadcastInt8X16#
and broadcastDoubleX2# compiled and assembled at -O0 and -O1. Nothing
was linked or run.
- iselExpr64 in GHC.CmmToAsm.X86.CodeGen, above its last clause,
with a pointer at getRegister''s case for MO_V_Extract 2 W64 (BUG:
it has no case for MO_V_Extract). On i386 a 64-bit integer takes two
registers, which iselExpr64 gives: stmtToInstrs passes each assignment
of a 64-bit value to a local or to memory to assignReg_I64Code
or assignMem_I64Code, which compile the value by iselExpr64,
as condIntCode' does a 64-bit comparison's operands, genCCall32
a foreign call's 64-bit arguments and getRegister' the operand
of its narrowings from 64 bits. StgToCmm emits MO_V_Extract
for the unpack primops alone (doVecUnpackOp), as one assignment
of each lane to a local, so each extraction of a 64-bit lane
that reaches iselExpr64 panics in its last clause
("iselExpr64(i386)"), a failed compilation, on i386, from Haskell,
under -msse4.2, -mavx2 or neither: at -O0, where an unpack any
of whose lanes is used extracts every lane, that of each such
unpackInt64X2# and unpackWord64X2#, under -mavx2 of each such
unpackInt64X4# and unpackWord64X4#, and under -mavx512f of each such
unpackInt64X8# and unpackWord64X8#, the 256-bit and 512-bit ones
stopping instead on x86-64 with the sorry error asking for -fllvm
that getRegister''s case for MO_V_Extract gives for them; at -O1
and -O2, that of each such unpack whose lane is returned, stored,
compared, narrowed, added or passed to an unsafe foreign call. At -O1
and -O2 cmmMachOpFoldM folds an extraction to the lane's value where
the Cmm gives it, as for an unpack of a pack or of an insert
at that lane, leaving none to compile, and the extraction of a 128-bit
vector's lane that Cmm sinking puts into the operand of a broadcast
or an insert, packs included, reaches getRegister''s case
for MO_V_Extract 2 W64 instead, through the BUG at its case
for MO_V_Broadcast: there vector_int64x2_extract_sse2, or under SSE4.1
vector_int_extract_pextr, moves the lane by MOVD or PEXTR at II64
into one 32-bit register, printed movq or pextrq, and the assembler
rejects the module; for a 256-bit vector's lane under -mavx2,
getRegister''s case for MO_V_Extract stops with the sorry error
instead. A comment on ISSUE 25498, an issue on SIMD tests that fail
on i386 under the LLVM backend, says that packInt64X2#
and unpackInt64X2# are not implemented in the i386 NCG, to explain
a test's failure in the LLVM ways, which that issue reports, and ISSUE
23537, open, reports iselExpr64's panic on i386 for a 64-bit
subtraction of a literal and a 64-bit shift, for which iselExpr64 has
cases on master; no issue reports the panic on an extraction,
so the statement cites none. This rests on master's code read
(iselExpr64's cases, stmtToInstrs, assignReg_I64Code,
assignMem_I64Code, condIntCode', genCCall32's push_arg, getRegister''s
cases for narrowings from 64 bits and for MO_V_Extract,
vector_int64x2_extract_sse2, vector_int_extract_pextr, doVecUnpackOp
in GHC.StgToCmm.Prim and cmmMachOpFoldM's case for MO_V_Extract
in GHC.Cmm.Opt) and on a compiler of master's code given an i386
target description through -B, at -S, its assembly given to GNU
as 2.42 with --32: for f v = unpackInt64X2# v it panicked so at -O0,
-O1 and -O2, under -msse4.2, -mavx2 or neither, and so did
unpackWord64X2#, an unpack whose lane 0 or lane 1 alone is returned,
and one whose lane is narrowed by int64ToInt#, added, compared,
written to a byte array or passed to an unsafe foreign call;
unpackInt64X4# and unpackWord64X4# did so at -O0, -O1 and -O2
under -mavx2 and stopped otherwise with "256-bit wide integer SIMD
vector instructions require at least -mavx2", and unpackInt64X8#
and unpackWord64X8# did so at -O0, -O1 and -O2 under -mavx512f, while
a compiler of master's code on x86-64 stopped with "Please use -fllvm"
for unpackInt64X4# under -mavx2 and unpackInt64X8# under -mavx512f
and compiled unpackInt64X2#; at -O1 and -O2 a broadcast, an insert
and a pack of unpacked lanes compiled to a movq from an xmm register
to a 32-bit one, or with -msse4.2 or -mavx2 to a pextrq, which
the assembler rejected, as clang 18, given -target i386-linux-gnu, did
for the broadcast's and the pack's at -O1; a broadcast of lane 0
of an unpackInt64X4# under -mavx2 stopped with that sorry error at -O1
and -O2, and an unpack of a pack of two arguments and one of an insert
at the lane used compiled at -O1 and -O2 to assembly the assembler
accepted, their -O1 Cmm holding no extraction; unpackDoubleX2#
and unpackInt32X4# compiled and assembled at -O0, -O1 and -O2,
and so did, at -O0 and -O1, a .cmm procedure computing a 64-bit shift
and a 64-bit subtraction of a literal. Nothing was linked or run.
- getRegister''s case for MO_V_Broadcast in GHC.CmmToAsm.X86.CodeGen,
its last alternative (BUG: every 512-bit integer broadcast reaches
its panic, the alternative for vector_int_broadcast_avx2 taking 128
and 256 bits alone). Under -mavx512f each 512-bit integer broadcast
panics ("Unsupported integer vector broadcast operation"), a failed
compilation, on x86-64, from Haskell, where under -mavx2 the compiler
rejects 512-bit integer vectors as an unimplemented feature
that requires -mavx512f. This rests on master's code read and
on a compiler of master's code on x86-64: for a function returning
broadcastInt8X64#, broadcastInt16X32#, broadcastInt32X16#,
broadcastInt64X8#, broadcastWord8X64#, broadcastWord16X32#,
broadcastWord32X16# or broadcastWord64X8# of its argument, at -O0
and -O1, it panicked so under -mavx512f and stopped with "512-bit wide
integer SIMD vector instructions require at least -mavx512f"
under -mavx2; broadcastInt64X4#, broadcastWord32X8#
and broadcastInt32X4# compiled under both.
- vector_float_broadcast_avx in GHC.CmmToAsm.X86.CodeGen, local
to getRegister' (BUG, ISSUE 27767: VSHUF with immediate 0, printed
vshufpd or vshufps, copies within each 128 bits of the register
the first element of those 128 bits). For a 256-bit or 512-bit vector
only the low 128 bits then hold the scalar, and each higher 128 bits
hold copies of their own first element, whatever the register held
there. This is wrong code, under -mavx2 for broadcastDoubleX4#
and broadcastFloatX8#, and under -mavx512f for the 512-bit broadcasts;
a 128-bit broadcast is right, and under -mavx alone a 256-bit vector
is rejected. ISSUE 27767's program, an fmaddDoubleX4#
of a broadcastDoubleX4#, is wrong in its two high lanes by this alone.
This rests on master's code read (getRegister''s case
for MO_VF_Broadcast, which takes vector_float_broadcast_avx
under -mavx, and VSHUF's printing as vshufpd and vshufps), ISSUE
27767's record and a compiler of master's code on x86-64 under -mavx2.
At -O0 and -O1, broadcastDoubleX4# of a Double# computed by scalar
code gave (2.5, 2.5, 0.0, 0.0) and broadcastFloatX8# 2.5 in the four
low lanes and 0.0 in the four high ones; at -O1, broadcastDoubleX4#
of lane 0 of a DoubleX4# loaded as (1.0, 2.0, 3.0, 4.0) gave (1.0,
1.0, 3.0, 3.0), and broadcastFloatX8# of lane 0 of 1.0 to 8.0 gave 1.0
in the four low lanes and 5.0 in the four high ones;
broadcastDoubleX2# and broadcastFloatX4# gave the scalar in every
lane. ISSUE 27767's program gave (12.0,24.0,30.0,40.0) at -O0 and -O1,
and (12.0,24.0,36.0,48.0) with the broadcast replaced by four stores
and a 256-bit load, as under -fllvm. Under -mavx512f the 512-bit
broadcasts compiled to vshufpd and vshufps on zmm registers, which
were not run. Nothing was run on i386.
- vector_int_broadcast_avx2 in GHC.CmmToAsm.X86.CodeGen, local
to getRegister' (BUG: for a 256-bit vector, MOVD's destination
and VPBROADCAST's source take the vector's format, so both are printed
as a ymm register). On x86-64, and on i386 for lanes of 8 to 32 bits,
the assembler rejects the module for every 256-bit integer broadcast
under -mavx2, which -mavx512f implies, and a 128-bit broadcast takes
xmm registers and assembles; on i386 a broadcast of 64-bit lanes
of either width fails by the BUG at getRegister''s case
for MO_V_Broadcast above its first alternative, and a 512-bit
broadcast does not reach this function. This rests on master's code
read (getRegister''s cases for MO_V_Broadcast, and pprMovdOpOp
and pprBroadcast in GHC.CmmToAsm.X86.Ppr, which print each operand
at the format given) and on a compiler of master's code on x86-64:
for a module defining f (I32# a) = (# broadcastInt32X8# a #),
it printed movd %eax,%ymm1 and vpbroadcastd %ymm1,%ymm1 at -O1 -mavx2,
which GNU as 2.42 ("operand type mismatch for `movd'") and clang 18
rejected; ghc -c failed so for each 256-bit Int and Word broadcast
at -O0 and -O1, under -mavx2 and under -mavx512f, and compiled
the 128-bit ones tried; for i386, given its target description through
-B, GNU as 2.42 with --32 rejected so the assembly
of broadcastInt32X8#, broadcastInt16X16# and broadcastWord8X32# at -O0
and -O1 under -mavx2, and assembled that of broadcastInt32X4#
and broadcastInt8X16#. Nothing was run on i386.
- vector_op_sse_reg in GHC.CmmToAsm.X86.CodeGen and the second PALIGNR
fallback of vector_shuffle_int128_common there, taken by the 128-bit
integer shuffles without SSSE3, both local to getRegister', one
at each (BUG, ISSUE 28179: the first operand's code is generated
before the second's but emitted after it). On i386, where both
operands' code splits a block, as the code of a 64-bit shift does
(iselExpr64's shifts end the block and call addCondBlock), the CFG has
the splits the other way round. Where the CFG is kept, the compiler
then panics in addNodesBetween ("Can't find weight for edge
that should have one") if the linear allocator puts a fixup block
on an edge the CFG lacks, and otherwise in sanityCheckCfg ("Block list
and cfg nodes don't match") under -dasm-lint or in a DEBUG compiler.
On x86-64 no expression's code splits a block, so the reversal
is harmless there. This rests on master's code read
(vector_op_sse_reg's two cases, iselExpr64's shifts, addCondBlock,
and cmmNativeGen, where sanityCheckCfg forces the CFG
that addNodesBetween returns), ISSUE 28179's record and runs
of an x86-64 stage-1 compiler built from this branch, whose code
is master's, given an i386 target description through -B. At -S -O
-dasm-lint, sanityCheckCfg panicked on plusInt32X4# of two broadcasts
of 64-bit shift results and, without -mssse3, on shuffleInt32X4#
of two such broadcasts with indices (# 6#, 7#, 0#, 1# #), whose
assembly without -dasm-lint has psrldq, pslldq and por and no palignr;
addNodesBetween panicked on a loop of such additions at -O,
with -dasm-lint or without, and sanityCheckCfg did instead
under -fregs-graph -dasm-lint. These compiled: the addition with one
operand shifted, at -O0, without -dasm-lint and for x86-64;
the shuffle with indices (# 2#, 3#, 4#, 5# #); the shuffle
and the loop under -finfo-table-map -dasm-lint; and the loop
under -fregs-graph without -dasm-lint. Nothing was assembled, linked
or run, and nothing was run on i386.
- vector_float_extract in GHC.CmmToAsm.X86.CodeGen, local
to getRegister', its case for 32-bit lanes under AVX (BUG, ISSUE
27422: VPSHUFD with the lane as its immediate selects,
by the immediate's two low bits, a lane of the vector's low 128 bits).
Lane k of a FloatX8# or a FloatX16# then gives lane k mod 4, which
is wrong code for lanes 4 to 7 of a FloatX8# under -mavx2
and for lanes 4 to 15 of a FloatX16# under -mavx512f, on x86-64,
from Haskell; a FloatX4# is right. ISSUE 27422's program,
an unpackFloatX8# of a sum, is wrong by this alone. This rests
on master's code read (getRegister''s case for MO_VF_Extract,
and VPSHUFD's printing as vpshufd), ISSUE 27422's record
and a compiler of master's code on x86-64 under -mavx2. A program
unpacking a FloatX8# loaded from (1.0, ..., 8.0) printed
[1.0,2.0,3.0,4.0,1.0,2.0,3.0,4.0] at -O0, -O1 and -O2, its assembly
vpshufd $1 to vpshufd $7 on ymm registers, and one unpacking
a FloatX4# so printed [1.0,2.0,3.0,4.0]. ISSUE 27422's program printed
11.0, 22.0, 33.0 and 44.0 twice at -O1 and -O2, as the issue reports,
and was refused at -O0 ("FloatX8# insert operations require -fllvm");
with its sum stored to memory and read back lane by lane in place
of the unpack, it printed 11.0 to 88.0. Under -mavx512f, lane 9
of a FloatX16# compiled to vpshufd $9 on zmm registers, which
was not run. Nothing was run on i386.
- vector_float_extract in GHC.CmmToAsm.X86.CodeGen, local
to getRegister', its case for 64-bit lanes (BUG: it takes the offsets
0 and 1 alone). Extracting lane 2 or above of a DoubleX4#
or a DoubleX8# panics ("Unsupported AVX floating-point vector extract
offset"), a failed compilation, on x86-64 under -mavx2 and -mavx512f,
and at -O1 and -O2 under -mavx, from Haskell; at -O0, where an unpack
extracts every lane, so does every unpackDoubleX4# and unpackDoubleX8#
any of whose lanes the program uses. This rests on master's code read
(getRegister''s case for MO_VF_Extract, which takes this case
for 64-bit lanes at every length and under every SIMD flag) and
on a compiler of master's code on x86-64. For functions returning one
lane of an unpackDoubleX4# of their argument, at -O1 and -O2
under -mavx, -mavx2 and -mavx512f, it compiled lanes 0 and 1
and panicked so on lanes 2 and 3, and at -O0 under -mavx2
and -mavx512f it panicked so on each lane; for an unpackDoubleX8#
under -mavx512f, it compiled lane 1 and panicked on lanes 2 and 7
at -O1, and panicked on lane 1 at -O0.
- getHiVirtualRegFromLo in GHC.Platform.Reg, pointed to from localReg64
and getNewReg64 in GHC.CmmToAsm.Monad and from genByteSwap
in GHC.CmmToAsm.X86.CodeGen (BUG, ISSUE 28125: the high half keeps
the number of the low half's unique): a 64-bit Cmm local and a 64-bit
NCG temporary with the same number share their high half, and where
both are live, writing one overwrites the other's high 32 bits.
This is wrong code on i386 and 32-bit PowerPC. Equal numbers occur,
as the NCG's uniques count from 0 in each Haskell module
(initDUniqSupply in GHC.Driver.Main.Compile) and, in a .cmm file,
continue the supply its Cmm pipeline used: in a .cmm file that a ghc
process compiles first, whose parser numbers its locals from 1 on;
in a Haskell module under -fobject-determinism, which renumbers
its Cmm locals from 54 on (emptyDetUFM in GHC.Cmm.UniqueRenamer);
and in any other Haskell module or .cmm file once the NCG's count
reaches the numbers that the global unique counter gave its Cmm
locals. In genByteSwap, equal high halves with different low halves
can arise so, and the branch for that case swaps correctly. This rests
on master's code read, ISSUE 28125's record, whose runs show all
three, and runs of a compiler of master's code given i386 and 32-bit
PowerPC target descriptions through -B, with -dcmm-lint, at -O, each
of the procedures f and g below compiled by a ghc process of its own.
For i386 the .cmm procedure f (bits64 x, bits64 y, gcptr p) {
bits64[p] = (x * y) + x; return (); } gave its 64-bit local x,
numbered 1, and the NCG temporary that loads its second argument, y,
one high half, and the final assembly loaded y's high half (movl
12(%ebp),%ecx) into the register holding x's (movl 4(%ebp),%ecx)
before reading it as x's; for 32-bit PowerPC, iselExpr64, which has
no case for a 64-bit shift or multiply, panicked on that procedure's
x * y. For both, the procedure g (gcptr p, gcptr q) { bits64 x; x =
bits64[p]; bits64[q] = bits64[q + 8]; bits64[q + 16] = bits64[q + 24];
bits64[q + 32] = bits64[q + 40]; bits64[q + 48] = x; return (); },
whose 64-bit local x, numbered 3, is live across three later 64-bit
loads, gave x and the NCG temporary that loads the third of them one
high half, and the final assembly stored that value's high word
as x's. For i386, a procedure like g whose x is live across eight
later 64-bit loads, in a .cmm file that a ghc process compiled after
f's file, numbered x 7 and gave it and the NCG temporary that loads
the seventh of them one high half, and the final assembly stored
that value's high word as x's. Nothing was assembled, linked or run,
and nothing was run on either target.
- callerSaves in compiler/CodeGen.Platform.h (BUG: no clause names
XmmReg, YmmReg or ZmmReg, though rts/include/stg/MachRegs/x86.h
defines CALLER_SAVES_XMM1 and up for x86-64, and arm64.h
CALLER_SAVES_XMM1 and XMM2; for i386, x86.h puts XMM1 to XMM4 in xmm0
to xmm3 and defines none for them). The Cmm passes treat a vector STG
register as surviving an unsafe foreign call, which clobbers
its machine register, and Cmm lint accepts one among such a call's
arguments. Where Cmm copies a vector STG register to a local before
such a call, or a callish MachOp compiled to one such as MO_F64_Sin,
and uses the local after it, as StgToCmm does with a function's vector
argument, sinking, on at -O1 and -O2, can move the copy past the call;
and under -fcmm-thread-sanitizer, at any -O level, around each call
that GHC.Cmm.ThreadSanitizer inserts, saveRestoreCallerRegs saves only
the STG registers that callerSaves names. Either is wrong code
on AArch64 and i386, each reached on both from Haskell that uses
vector primops. On x86-64, each of XMM1 to XMM6 that x86.h makes
caller-saves, XMM6 not on Windows, shares its machine register
with an F and a D register that callerSaves names, so sinking keeps
the copy before the call, but saveRestoreCallerRegs saves and restores
only the low 64 bits of that machine register. This rests on master's
code read (activeCallerSavesRegs in GHC.Cmm.Node, from which sinking
takes a call's clobbers, mayNotMentionCallerSavedRegs in GHC.Cmm.Lint,
and saveRestoreCallerRegs) and on a compiler of master's code given
AArch64 and i386 target descriptions through -B, which at -O
-dcmm-lint moved v = XMM1 past foreign "C" foo(x) in a procedure
that then sets XMM2 = v; given the AArch64 one, at -O and -O2,
it compiled Haskell functions that add a DoubleX2# argument to itself
after an unsafe foreign call, or after sinDouble#, to a bl foo or bl
sin followed by an fadd of v4, XMM1's machine register, which the call
clobbers, where at -O0, for x86-64 at -O, and for the sinDouble# one
at -O with -fno-cmm-sink, the vector was kept on the stack across
the call. Given the i386 one, at -O1 and -O2, it compiled the same
functions to a call followed by an addpd of xmm0, XMM1's machine
register, which the call clobbers, where at -O0, and at -O1
with -fno-cmm-sink, the vector was kept on the stack across the call.
Under -fcmm-thread-sanitizer, at -O0, -O1 and -O2, it compiled
the function with the unsafe foreign call, for AArch64 and i386,
to code that keeps the sum in v4 or xmm0 across the call
to __tsan_read8 or __tsan_read4 that the pass inserts for the load
of the return address, and for x86-64 to code that saves xmm1 around
that call by movsd alone. Nothing compiled
under -fcmm-thread-sanitizer was run.
- callClobberedRegs in GHC.CmmToAsm.X86.Regs, its case for x86-64
Windows (BUG: a callee saves only the low 128 bits of xmm6 to xmm15,
and the case names those registers at no width). The register
allocators can then keep a 256-bit or 512-bit value in ymm6 to ymm15
or zmm6 to zmm15 across a C call, of an unsafe foreign call or
of a callish MachOp such as MO_F64_Sin, and the callee can destroy
the value's bits above 127. This is wrong code on x86-64 Windows,
under -mavx2 for 256-bit values and under -mavx512f for 512-bit ones,
from Haskell and from hand-written Cmm; a value of 128 bits or fewer
survives the call. This rests on master's code read
(callClobberedRegs; clobbered in GHC.CmmToAsm.X86.Instr, which writes
the registers it names; padStackArgs in GHC.CmmToAsm.X86.CodeGen,
which rejects only 256-bit and 512-bit arguments of a Windows C call),
on the x64 ABI document that the case's comment cites, whose table
makes the upper half of ymm6 to ymm15 volatile, and on a compiler
of master's code given an x86-64 Windows target description through
-B. For a Haskell function adding a DoubleX4# argument to itself after
an unsafe foreign call, at -O0, -O1 and -O2 under -mavx2 and at -O1
under -fregs-graph, it printed vmovupd %ymm1,%ymm6 before the call
and vaddpd %ymm6,%ymm6 after it, where for x86-64 Linux the vector
was spilled across the call; it did likewise for sinDouble# in place
of the foreign call, for a DoubleX8# under -mavx512f at -O0 and -O1
with zmm6, and for a .cmm procedure keeping two vec256 locals across
foreign "C" foo(), at -O0 and -O1, with ymm6 and ymm7. clang 18,
for x86_64-w64-windows-gnu, compiled a function clobbering ymm6
to a save and restore of xmm6 alone, and that code, run on x86-64
Linux after the compiler's sequence for a DoubleX4# of (1, 2, 3, 4),
left (1, 2, 0, 0). Nothing was run on Windows, and nothing compiled
under -mavx512f was run.
- verifyBasicBlock in GHC.CmmToAsm.X86.CodeGen (BUG: a block of native
code whose last jump is missing is caught only where that jump alone
would cover one of the block's edges in the CFG: sanityCheckCfg, where
the CFG is kept and under -dasm-lint or in a DEBUG compiler, checks
that the block's jumps and its edges, a call's aside, agree,
so a block with no such edge, as one meant to end in a tail call
or a return, goes unchecked; this checks, in a DEBUG compiler, only
that nothing but jumps follows a jump). A block that did not end
in one would run on into whichever block the layout puts after it,
which is wrong code; no instruction selector is known to make such
a block. This rests on master's code read.
- getAmode in GHC.CmmToAsm.X86.CodeGen, three clauses (BUG, ISSUE 28105:
each can emit a displacement outside the signed 32-bit range: -i where
i = -2^31; an offset left unchecked; and an offset checked only
at shift 3, as && binds tighter than ||): where the displacement does
not fit, the x86-64 assembler rejects the module. This rests
on master's code read, ISSUE 28105's record and a compiler of master's
code on x86-64, which printed, for hand-written Cmm at -O0 and -O,
movq 2147483648(%rax) for bits64[bits64[p] - (-2147483648)], and movq
4294967296(%rbx,%r14,4) for bits64[(p + 4294967296) + (i << 2)]
and for bits64[p + ((i << 2) + 4294967296)], and at -O movb
4294967296(%r14,%rsi,4) for indexWord8OffAddr# (plusAddr#
a 4294967296#) (i *# 4#) and for indexWord8OffAddr# a (i *# 4# +#
4294967296#), each of which GNU as 2.42 and clang 18 rejected.
- getAmode in GHC.CmmToAsm.X86.CodeGen, its clause for a register offset
plus a shift and, at shift 0 to 2, its clause for x + ((y << shift) +
offset), one at each (BUG: nor is the offset narrowed
to the register's width). On i386 an offset outside 32 bits reaches
the assembler, which shortens it modulo 2^32, to the address meant,
warning only where its magnitude reaches 2^32, so this costs at most
the warning; on x86-64 such an offset is the BUG of ISSUE 28105
at each clause. It is reached from hand-written Cmm at the second
clause; at the first, cmmMachOpFoldM in GHC.Cmm.Opt narrows a single
literal added to a register to its width. This rests on master's code
read, on GNU as given such displacements with --32, which
it shortened, warning from a magnitude of 2^32 on, and assembled,
and on a compiler of master's code given an i386 target description
through -B. For bits32[p + ((i << 2) + 4294967296)] on bits32 p and i,
in a .cmm procedure that -dcmm-lint passes, it printed movl
4294967296(%ecx,%eax,4),%eax at -O0 and its like on %esi at -O, which
i686-linux-gnu-as --32 assembled with the warning "0x100000000
shortened to 0x0"; for bits32[(p + 4294967296) + (i << 2)] it printed
movl (%esi,%eax,4), the offset folded to 0, and at shift 3, whose
guard refuses the offset, the clause for x + y took it, and the offset
was added by addl $0.
- addAlignmentCheck in GHC.CmmToAsm.X86.CodeGen (BUG: the check's
conditional jump names mkBadAlignmentLabel bare, where under -dynamic
an ordinary jump to the RTS goes through the GOT). On i386
under -dynamic, which implies -fPIC, with -falignment-sanitisation,
the assembler relocates the jump as R_386_PC32 against
stg_badAlignment_entry, a symbol of the RTS's shared object,
so a shared object linked from the code carries a text relocation: GNU
ld warns that it creates DT_TEXTREL, and fails under -z text.
Hand-written Cmm reaches it, and so does Haskell, as StgToCmm emits
the same check (wordAligned in GHC.Cmm.Info). On x86-64 the assembler
relocates the same jump as R_X86_64_PLT32, and the object links.
This rests on master's code read (addAlignmentCheck's JXX_GBL;
wordAligned) and on a compiler of master's code given an i386 target
description through -B, with GNU as and ld 2.42. For a .cmm procedure
loading the info pointer of a gcptr, at -O0 -fPIC -dynamic
-falignment-sanitisation, it printed jne stg_badAlignment_entry, which
as --32 relocated as R_386_PC32, while an ordinary jump
to stg_gc_noregs became jmp *stg_gc_noregs@got(%eax); ld -m elf_i386
-shared, given a stub shared object defining the symbol, warned
"relocation against
`stg_badAlignment_entry' in read-only section `.text'" and "creating
DT_TEXTREL in a shared object", and with -z text failed
with "read-only segment has dynamic relocations". On x86-64 a Haskell
module under -fPIC -falignment-sanitisation held the same jne at -O0
and -O1. Haskell was not compiled for i386, and nothing was run.
- genXchg and the cmpxchg_code of genAtomicRMW
in GHC.CmmToAsm.X86.CodeGen, one at each (BUG: where dst_r
is a register that the amode names, as in (x) = prim %xchg64(x, y)
or (x) = prim %fetch_and64(x, y) in a loop of hand-written Cmm where x
is the address after Cmm sinking (-fcmm-sink, on at -O1 and -O2),
a MOV into dst_r from another register overwrites the address before
the XCHG, or the loop's CMPXCHG, uses it). On x86-64, where
getSimpleAmode is getNonClobberedAmode, which returns an amode
of virtual registers as it is, this is wrong code: at every width
for And, Nand, Or and Xor among the atomic operations, as Add and Sub
write dst_r after their XADD, and at 64 bits for the exchange, whose
XCHG the assembler rejects at 8, 16 and 32 bits whatever its operands
(the BUG at pprInstr's case for XCHG in GHC.CmmToAsm.X86.Ppr); on i386
getSimpleAmode computes the address into a fresh register. StgToCmm's
result local is never the address's, and the RTS's Cmm has no such
line, so only other hand-written Cmm reaches it. This rests
on master's code read and on a compiler of master's code at -O:
in a loop, (x) = prim %fetch_and64(x, y) assembled to a lock cmpxchgq
through the overwritten register, and a program calling (x) = prim
%xchg64(x, y) in a loop, whose code holds xchgq (%rbx),%rbx, crashed
with a segmentation fault, where with a fresh result local it printed
the old and new values. In the loop, (x) = prim %fetch_and8(x, y)
assembled to movb %al,%bl before lock cmpxchgb %dl,(%rbx),
and its 16-bit and 32-bit forms likewise, while (x) = prim %xchg8(x,
y) printed xchgb (%rax),%rax, which the assembler rejected. At -O0
the line's arguments are copied to fresh locals first, and the code
is right. Cmm sinking replaces x's copy by x, or by the right-hand
side of x's one assignment where it moves that assignment
into the line: with one assignment from a load followed by a store,
the code held xchgq (%rsi),%rsi; with one from a load and a test of x
before the line, it was wrong also at -O0 -fcmm-sink and right at -O
-fno-cmm-sink; and two assignments that -O merges into one gave right
code.
- pprInstr's case for XCHG in GHC.CmmToAsm.X86.Ppr (BUG: pprFormatOpReg
prints the register operand at the word's format, not
at the exchange's). At 8 and 16 bits, and on x86-64 at 32,
the register's name then does not match the instruction's suffix,
and the assembler rejects the module whatever the operands, at -O0
as at -O1. StgToCmm emits MO_Xchg at the word's width alone,
and no Cmm in the tree calls a narrower %xchg, so only other
hand-written Cmm reaches it. This rests on master's code read
(pprFormatOpReg, which prints its register at archWordFormat; genXchg,
which gives XCHG the exchange's format; StgToCmm's MO_Xchg) and
on a compiler of master's code on x86-64 and, given an i386 target
description through -B, for i386. For (r) = prim %xchg8(p, y)
and its wider forms in hand-written Cmm, at -O0 and -O1 on x86-64,
it printed xchgb (%rax),%r14, xchgw (%rax),%r14 and xchgl (%rax),%r14,
which GNU as 2.42 and llvm-mc 18 rejected, and xchgq (%rax),%r14,
which they assembled; at -O1 for i386, xchgb (%eax),%ecx and xchgw
(%eax),%ecx, rejected, and xchgl (%eax),%ecx, assembled.
- takeRegRegMoveInstr in GHC.CmmToAsm.X86.Instr, its case for MOV (BUG:
the guard tests the move's format alone, so a MOV of a scalar format
from a vector register, which vector_float_extract emits to extract
lane 0, is returned as a register-to-register move). In buildGraph
in GHC.CmmToAsm.Reg.Graph, slurpConflicts adds a coalescing edge
for every such move, usable where the vector dies,
and slurpReloadCoalesce one between each reload of a spill slot
and the register last spilled to it, so a vector's virtual registers
before and after its spills join one class with the scalar's;
the graph allocators' coalescing renames the class to the scalar's
register, and the vector's reloads then load 8 bytes, by movsd, which
zeroes the upper lane that a later movhlps reads. This is wrong code
on x86-64 under -fregs-graph and -fregs-iterative, at -O1 and -O2,
from Haskell that extracts lane 0 of a vector that is spilled
and reads its other lane later. The linear allocator is spared: raInsn
in GHC.CmmToAsm.Reg.Linear gives the move's destination the source's
location only where the source dies, and renames no reload
of the vector. This is not GHC #27993, 16-byte spills into 8-byte
slots, and GHC #27619, on formats in the liveness fixpoint, is another
mechanism. This rests on master's code read (takeRegRegMoveInstr;
vector_float_extract's MOV FF32 and MOV FF64 for lane 0; buildGraph,
slurpConflicts and slurpReloadCoalesce; raInsn) and on a compiler
of master's code on x86-64. A program whose function unpacks the sum
of a DoubleX2# of (a, b) and a broadcast of a, calls ldexp through
an unsafe foreign call and then uses both lanes printed (8.0,-6.0,0.0)
at -O1 and -O2 under -fregs-graph and -fregs-iterative, where
it printed (8.0,-6.0,26.0) at -O2 under the linear allocator
and at -O0 under both graph allocators. Its -fregs-graph assembly
at -O2 spilled the sum by movupd and reloaded it by movsd before
movhlps, and -ddump-asm-regalloc-stages listed as coalesced
into the Double's virtual register the sum's registers before
and after its spills, the one moved by movsd and the one read
by movhlps among them.
- shortcutJump's case for JMP_TBL in GHC.CmmToAsm.X86.Instr (BUG:
updateBlock applies the mapping once, where the case for JXX follows
the chain of shortcuts, as shortBlockId does for the table's entries
and shortcutWeightMap in GHC.CmmToAsm.CFG does for the CFG's edges).
Where a block that a jump table targets is shortcut to a block
that is shortcut in turn, the JMP_TBL's block list keeps a removed
block while the CFG has the edge to the chain's end,
and sanityCheckCfg panics ("Block list and cfg nodes don't match"),
a failed compilation, under -dasm-lint or in a DEBUG compiler, on x86
and x86-64 under -fasm-shortcutting, not on Darwin; the emitted table
follows the whole chain, so the code is right. Only hand-written Cmm
is known to reach it. The comment at apply_mapping in GHC.CmmToAsm,
"shortcutJump should apply the mapping repeatedly", does not hold
of a table's block list. This rests on master's code read
(shortcutJump, shortcutStatic and shortBlockId, shortcutWeightMap,
and the case for JMP_TBL of jumpDestsOfInstr, whose result
sanityCheckCfg compares with the CFG) and on a compiler of master's
code on x86-64: a .cmm procedure of eight switch cases, some of which
reach their target through two blocks that end up a single jump each,
panicked so ("missing edges") at -O2 -dasm-lint, at -O0 and -O1
with -fasm-shortcutting -dasm-lint and at -O2 -fregs-graph -dasm-lint,
and compiled at -O2, at -O2 -fno-asm-shortcutting -dasm-lint
and at -O0 -dasm-lint; at -O2 the table's entries went to the chains'
ends.
- shortcutStatic in GHC.CmmToAsm.X86.Instr (BUG, ISSUE 28138:
it retargets the first label of a CmmLabelDiffOff and keeps
the second, which its comment says works for jump tables; since
84a087d5d5 (ISSUE 24016) a position-independent table's entries
are relative to the label of the block that jumps through the table,
in the procedure's section, and no longer to the table's label).
An entry retargeted to a label in another section, an imported
procedure's or, under -fsplit-sections, another procedure's,
is a difference the assembler cannot resolve, and it rejects
the module. This is reached under -fasm-shortcutting with -fPIC
or -fPIE, on x86 and x86-64, not on Darwin, where shortcutting is off,
and under -g only for a jump-only block to which -g adds nothing.
Under -dynamic, which implies -fPIC and -fexternal-dynamic-refs,
a jump to an imported procedure or to a procedure of a .cmm file goes
through the GOT outside Windows, and canShortcut skips such a jump,
so there it is reached only by a jump to another procedure of the same
Haskell module under -fsplit-sections. The statement stands
at shortcutStatic rather than at build_mapping in GHC.CmmToAsm, which
maps a block to its jump's target in any section, as a jump may go
to any label. This rests on master's code read (genSwitch,
generateJumpTableForInstr, shortcutStatic, canShortcut, labelDynamic
in GHC.Cmm.CLabel and wayGeneralFlags in GHC.Platform.Ways,
and cmmNativeGen, which runs generateJumpTables before
shortcutBranches), ISSUE 28138's record and a compiler of master's
code: on x86-64, ISSUE 28138's T.hs, whose case tail-calls three
procedures of another module, made GNU as 2.42 reject the module
("can't resolve U_a4_info - .Ln1") at -O2 -fPIC, -O2 -fPIE and -O1
-fPIC -fasm-shortcutting, and assembled at -O2, -O1 -fPIC, -O2 -fPIC
-fno-asm-shortcutting and -O2 -fPIC -g; a .cmm procedure whose switch
jumps to three procedures of its own file made the assembler reject
it so ("can't resolve a1 - .Lc7") at -O2 -fPIC -fsplit-sections,
for x86-64 and, given an i386 target description through -B
and assembled with --32, for i386, and assembled without
-fsplit-sections or with -fno-asm-shortcutting. -dynamic itself
was tried on .cmm files alone, a Haskell module failing to compile
under it, the compiler having no dynamic libraries; with the two flags
it implies, at -O2 -fPIC -fexternal-dynamic-refs on x86-64, ISSUE
28138's T.hs assembled, with and without -fsplit-sections, its jumps
to the other module's procedures going through the GOT; a module whose
case tail-calls three procedures of its own made the assembler reject
it ("can't resolve .text..LrGK_info - .Ln4") under -fsplit-sections,
and assembled without it or with -fno-asm-shortcutting; and the .cmm
procedure assembled under -fsplit-sections, for x86-64 and for i386,
its jumps going through the GOT, as it did at -O2 -dynamic,
with and without -fsplit-sections. Windows was not tried.
- procToDwarf in GHC.CmmToAsm.Dwarf, its fallback for dwName (BUG: show
of a Label gives its unique as a number, where ppr gave the block's
name). Under -g, the DIE of a procedure with no source note
is then named by a number, such as L7133701809754871424, that no label
of the assembly carries, where its DW_AT_low_pc names the block's
label, such as .Lc1uU, and its linkage name is _blk_c1uU. This is only
a misled reader of the debugging information, at -O0 and -O,
from Haskell, on every target that emits DWARF; no effect on gdb
was shown. 05550a5abc ("Avoid roundtrip through SDoc", 2020) put show
where ppr of the label had given the c1uU form. This rests on master's
code read (procToDwarf) and on a compiler of master's code on x86-64:
for a module of three functions, a main and their local procedures,
at -g -O, 9 of the 16 subprogram DIEs that readelf printed were named
so, and at -g -O0, 3 of 19.
- procToFrame in GHC.CmmToAsm.Dwarf (BUG: dwFdeProc is the label
of the procedure's entry block, and pprFrameProc
in GHC.CmmToAsm.Dwarf.Types ends the frame description entry
at that label's procedure end label, which X86's, PowerPC's, RV64's
and LA64's pprBasicBlock print after the block itself, as for a block
that may end up a procedure of its own). Under -g the entry then ends
after the procedure's first block and leaves out the code and the rows
of the procedure's other blocks, so that a debugger finds no frame
description entry for a pc in them; a procedure of one block
is spared. procToDwarf's subprogram DIE takes the same end,
and so does mkDwarfARange's address range, which -fsplit-sections
emits for each procedure; the compile unit's DW_AT_high_pc and,
without -fsplit-sections, its one address range end after its last
procedure's first block. This is wrong debugging information, reached
under -g, -g1 included, at -O0 and -O1 alike, on the targets for which
the compiler emits DWARF: x86, x86-64, 64-bit PowerPC with the ELFv2
ABI, RISC-V and LoongArch. This rests on master's code read
(cmmDebugGen in GHC.Cmm.DebugBlock, which sets each DebugBlock's
dblCLabel to its block's label; procToFrame, procToDwarf,
mkDwarfARange and dwarfGen; pprFrameProc and pprDwarfInfoOpen;
the four pprBasicBlock) and on a compiler of master's code on x86-64
and given 64-bit PowerPC ELFv2, RISC-V, LoongArch and i386 target
descriptions through -B, with GNU as and readelf 2.42. On a Haskell
module whose functions call C functions, for all but i386, and
on a .cmm file of a procedure of four blocks and one of one block,
for all five, at -O0 and -O1 under -g1 and -g, every frame description
entry of a procedure of more than one block ended at the end
of the procedure's first block, and every other one covered
its procedure. On x86-64 at -O1 -g, readelf gave the entry
of the module's first procedure the range 0x17 to 0x21, where
the procedure's code runs from 0x18 to 0x7f, and its rows set_loc
0x30, 0x58, 0x66 and 0x71; it gave the procedure's DIE the same range
and, under -fsplit-sections, its address range a length of 9 bytes;
at -O0 -g, the compile unit's DW_AT_high_pc was 0x849, inside the last
procedure, which runs from 0x840 to 0x88f. Linked and run under gdb,
a trap in a C function called from a later block of a procedure gave
a backtrace whose frame for that procedure lies at a pc no frame
description entry covers, followed by a frame at pc 0; assembled
from the same assembly with each entry's length rewritten to end
at its procedure's end label, the backtrace ended at the procedure's
frame.
- pprFrameBlock in GHC.CmmToAsm.Dwarf.Types (BUG: a point whose table
differs from the one before gets a DW_CFA_set_loc even where it
is the procedure's first). The state starts from the CIE's table,
initUw in pprFrameProc, and the first point's set_loc names its label,
minus 1 for a block with an info table, which is the frame description
entry's own initial location; where the first point's table differs
from the CIE's, as for a procedure entered with its arguments
on the stack, whose Sp offset on entry is not 0, the entry opens
with a set_loc to its own start. The DWARF standard says
of DW_CFA_set_loc that the new location is always greater
than the current one. This is wrong debugging information under -g,
on x86-64 and i386, at -O0 and -O, from Haskell and Cmm:
llvm-dwarfdump 18 refuses to decode such an entry into rows, where GNU
readelf 2.42 prints its opcodes without a message; gdb was not tried.
The BUG at procToFrame, on the entries' ranges, is another fault
of the same entries. This rests on master's code read (pprFrameBlock
and pprFrameProc) and on a compiler of master's code on x86-64
and given an i386 target description through -B. For a Haskell
function of ten Int# arguments, at -g -O0 and -g -O, the function's
entry, pc 0 to 0x1a, opened with DW_CFA_set_loc 0
and DW_CFA_def_cfa_offset 80, and llvm-dwarfdump --debug-frame stopped
on it: "DW_CFA_set_loc with adrress 0x0 which must be greater
than the current row address 0x0"; a module of functions entered
with no arguments on the stack decoded without error. For a .cmm
procedure of eight bits64 arguments, two of them on the stack,
on x86-64, and one of two word arguments, both on the stack, for i386,
assembled by i686-linux-gnu-as --32, at -g -O0 and -g -O,
llvm-dwarfdump stopped the same way.
- addDefaultUnwindings in GHC.CmmToAsm.Dwarf (BUG: it gives every
unwinding table that does not name Sp the rule Sp has
at the procedure's entry, and the table that X86's addSpUnwindings
adds where the C stack pointer moves, as around a C call, names MachSp
alone). Up to the next table that names Sp, DWARF gives the canonical
frame address by Sp's rule at entry: rbp+0 on x86-64, where before
a call it can be another offset, such as rbp+16. A debugger unwinding
from there finds the wrong frame. Where such a row lies past
a procedure's first block, the procedure's frame description entry
leaves it out (the BUG at procToFrame), and no debugger consults it:
in the x86-64 objects of a Haskell module at -O0 -g and -O1 -g, every
row that sets the canonical frame address's offset back to 0 lay past
its entry's range. This is reached under -g on ELF targets, on x86
and x86-64, as ncgDwarfUnwindings holds on ELF targets under -g
and addSpUnwindings is X86's. This rests on master's code read
and on readelf's reading of the frame table of an object that master's
compiler made under -g.
- dwarfReturnRegNo in GHC.CmmToAsm.Dwarf.Constants (BUG, ISSUE 11261:
no case for 32-bit PowerPC or for 64-bit PowerPC with the ELFv1 ABI;
dwarfRegNo has none for 32-bit PowerPC either). ncgDwarfEnabled holds
under -g on ELF targets other than AArch64, so on these two
the compiler can panic under -g on a module with code,
with "dwarfReturnRegNo: Unsupported platform!", as ISSUE 11261 reports
for 64-bit PowerPC. This rests on master's code read (initNCGConfig's
ncgDwarfEnabled, and pprDwarfFrame, which prints the return register's
number before any other register's) and on a compiler of master's code
given a 64-bit PowerPC ELFv1 target description through -B, which
panicked so on a Haskell module and on a .cmm file at -O -g,
and on the module at -O0 -g, -O -g1 and -O0 -g1, and compiled
the module at -O and, at -O -g, a module whose one binding is x = 5 ::
Int, which has no code; given an ELFv2 one, it emitted .debug_info
at -O -g, and given a 32-bit PowerPC one, it panicked so on a .cmm
file at -O -g.
- cmmDebugGen in GHC.Cmm.DebugBlock (BUG: blockCtxs and scopeMap
are maps keyed by CmmTickScope, whose Ord compares the scopes'
uniques, and detRenameCmmTick in GHC.Cmm.UniqueRenamer leaves
those uniques as they are under -fobject-determinism). The order
of the top scopes and of each scope's nested scopes, and with
it the order of the lexical-block DIEs that dwarfGen emits under -g,
follows the unique supply, so under -g -fobject-determinism
an object's .debug_info and its relocations differ between values
of -dinitial-unique and -dunique-increment, against Note [Norms
of the NCG] in GHC.CmmToAsm; the object's code, data and other
sections, and the set of its DIEs' names, are the same.
This is reached from Haskell at -O0, -O1 and -O2. This rests
on master's code read (cmmDebugGen, blockContexts, the Ord instance
of CmmTickScope in GHC.Cmm.Node, detRenameCmmTick, and procToDwarf
and blockToDwarf in GHC.CmmToAsm.Dwarf, which keep the DebugBlocks'
order) and on a compiler of master's code on x86-64
under -fobject-determinism, with -dinitial-unique=16777215
-dunique-increment=-1, as GHC's determinism test check-standalone.sh
uses, against the default. For a module of a data type and a Data.Map
fold, at -O0, -O1 and -O2 with -g, the objects differed in .debug_info
and .rela.debug_info alone of ten sections compared; at -O1 readelf
gave both the same DW_AT_name values in another order, each moved name
a lexical block's; -ddump-debug showed the blocks in another order
and nesting; and -ddump-cmm-raw showed the blocks under the same
labels and their tick scopes under different uniques. Without -g
the objects were identical. A --make build of seven modules at -O1 -g
gave seven objects differing in .debug_info alone of six sections
compared. Hand-written Cmm was not tried, and no target but x86-64.
- cmmDebugLink in GHC.Cmm.DebugBlock (BUG: it drops a block missing
from its labels with every block and procedure nested under it,
and cmmDebugLabels declares missing a block that holds only meta
instructions). Where such a block is a procedure's entry block,
under -g dwarfGen emits no DIEs and no unwinding records
for that procedure and those nested under it, and no section at all
for a module whose procedures are all dropped so: the module's object
then keeps only the debugging sections that the assembler makes
from the .loc lines, and has no .debug_frame. Where such a block
is the first of a tick scope inside a procedure, as for a local loop
at -O0 on x86-64, dwarfGen emits none for the blocks of that scope.
The first case is reached for an entry block that holds no more
than moves of the arguments and a jump, which dropJumps
in GHC.CmmToAsm.BlockLayout drops where block layout places the jump's
target next. With -fcmm-control-flow off, the target can be the heap
check: on x86-64 and 64-bit PowerPC at -O0, where the register
allocator eliminates the moves, and on these and on i386, RISC-V
and LoongArch at -O1 -fno-cmm-control-flow, where the Cmm sinking pass
leaves the entry block only its jump. With the flag on or off, it can
be the header of the procedure's loop, which has two predecessors,
so that cmmCfgOpts does not merge it into the entry block: at -O1
and -O2 on 64-bit PowerPC, and on x86-64 under -fno-block-layout-cfg,
where the register allocator eliminates the moves and sequenceBlocks
places the header next. On x86-64 the default layout, sequenceChain,
kept that jump in the runs below, and on i386, RISC-V and LoongArch
such a procedure's entry block kept loads or copies of the arguments.
Since eebe1658cc (ISSUE 22792) cmmDebugLink drops a missing block;
before, it kept the block with no position. This rests on master's
code read (cmmDebugLabels; cmmDebugLink's mapMaybe link; cmmDebugGen,
which nests the other blocks of a tick scope and the blocks
of its nested scopes, other procedures' among them, under the scope's
first block; and dwarfGen, which emits nothing for no blocks) and
on a compiler of master's code on x86-64 and given 64-bit PowerPC
ELFv2 and ELFv1, i386, RISC-V and LoongArch target descriptions
through -B. For a module whose one binding is mk n m = Just n, at -O0
-g it emitted no DWARF section for x86-64 and ELFv2, ghc -c leaving
in the x86-64 object the .debug_info, .debug_line, .debug_aranges,
.debug_abbrev and .debug_str of GNU as 2.42 and no .debug_frame,
and five for RISC-V and LoongArch, where the entry block keeps two
copies into temporaries; with -fcmm-control-flow it emitted five
for x86-64 and ELFv2; and for x86-64 it emitted five at -O1 -g
and none at -O1 -g -fno-cmm-control-flow. With two lambdas in mk,
whose four procedures -ddump-debug at -O0 -g -fcmm-control-flow shows
nested under mk's, it emitted none at -O0 -g for x86-64 and ELFv2,
though each of the four keeps its stack check in its entry block;
with a second binding whose entry block keeps its stack check, only
that binding's DIEs and frame description entry, and for a binding
whose local loop's first block holds only meta instructions, no DIE
for the loop's blocks, for x86-64 at -O0 -g. For mk's module
it emitted none at -O1 -g -fno-cmm-control-flow for ELFv2, ELFv1,
RISC-V and LoongArch too, and none at -O0 -g for ELFv1; for i386,
for a copy of the module that declares its own constructor, it emitted
the DIE and frame description entry of one of its three procedures
at -O1 -g -fno-cmm-control-flow and of all three at -O0 -g and at -O1
-g -fno-cmm-control-flow -fno-cmm-sink. For a module of three
self-recursive Int loops, at -O1 -g it emitted them for its seven
procedures for x86-64, RISC-V and LoongArch, and for four, the three
workers' missing, for ELFv2, at -O2 -g and with -fno-cmm-control-flow
too, and for x86-64 under -fno-block-layout-cfg; given the ELFv1
description it panicked in dwarfReturnRegNo (BUG #11261)
on that module and emitted no DWARF section for a module of two Int#
loops, at -O1 -g and -O2 -g; for i386 that module's two procedures
kept theirs under -fno-block-layout-cfg too.
- emitPrimOp in GHC.StgToCmm.Prim, its cases for the vector arithmetic,
bitwise and FMA primops, VecAddOp to VecFNMSub (BUG: they call
no checkVecCompatibility, which the cases of VecBroadcastOp,
VecPackOp, VecUnpackOp, VecInsertOp, the vector loads, stores
and indexing primops and VecShuffleOp call). backendSimdValidity
in GHC.Driver.Backend is IsValid for the native code generator
on every target, so on a target whose code generator cannot compile
a vector, VecAddOp, VecSubOp, VecMulOp, VecDivOp, VecQuotOp, VecRemOp,
VecNegOp, VecAbsOp, VecSqrtOp, VecMinOp, VecMaxOp, VecAndOp, VecOrOp,
VecXorOp, VecFMAdd, VecFMSub, VecFNMAdd and VecFNMSub reach it,
and it panics where the check gives a sorry error, "SIMD vector
instructions are not supported on this architecture" or, on AArch64,
"256-bit wide SIMD vector instructions are not supported". This
is a panic, a failed compilation, from Haskell, at -O0 and -O,
on RISC-V ("Width too big! Cannot load: W128"), LoongArch ("Unknown
width to load: W128") and 64-bit PowerPC with the ELFv1 and ELFv2 ABIs
("PPC pprInstr: VecFormat") for any vector, and on AArch64
("floatVecOp: invalid vector format") for a vector of 256 bits.
Pointers at the four panics cite the BUG. This rests on master's code
read (emitPrimOp's cases and checkVecCompatibility) and on a compiler
of master's code given RISC-V, LoongArch, 64-bit PowerPC ELFv1
and ELFv2 and AArch64 target descriptions through -B: f a b =
plusDoubleX2# a b panicked so at -O0 and -O on the first four, where f
a = broadcastDoubleX2# a stopped with the sorry error; for AArch64,
plusDoubleX4# panicked so at -O0 and -O, where broadcastDoubleX4#
stopped with the sorry error. On x86-64 without -mavx, plusDoubleX4#
stopped with a sorry error of GHC.CmmToAsm.X86.Instr's, "256-bit wide
vectors require -mavx2".
- initNCGConfig in GHC.Driver.Config.CmmToAsm, its field
ncgProcAlignment (BUG: the value of -fproc-alignment is not checked,
and only X86's, RV64's and LA64's printers use it). A value
that is not a power of 2 or is over 512 makes mkAlignment
in GHC.Types.Basic, which their pprProcAlignment calls, panic
("mkAlignment: received either a non power of 2 argument or > 512"),
a failed compilation, on x86, x86-64, RISC-V and LoongArch,
from Haskell and Cmm, where the flag's parser could reject it;
on AArch64, whose printer has its calls of pprProcAlignment commented
out, and on PowerPC, whose printer has none, the flag has no effect,
which its entry in the users' guide does not say. This rests
on master's code read (the flag's intSuffix in GHC.Driver.Session,
initNCGConfig, the three pprProcAlignment, AArch64's printer
and PowerPC's) and on a compiler of master's code on x86-64 and given
i386, RISC-V, LoongArch, AArch64, 64-bit PowerPC ELFv1 and ELFv2
and 32-bit PowerPC target descriptions through -B. On x86-64,
-fproc-alignment=0, 3, 1024 and -4 each made it panic so on a .cmm
procedure and a Haskell module at -O1, and 3 on the module at -O0
and -O2 too, while 1, 16 and 512 compiled; for a .cmm procedure
at -O1, 0 made it panic so for i386, RISC-V and LoongArch and compiled
for AArch64 and the three PowerPC targets, whose assembly at 64
was that without the flag, where i386 added .align 64 and RISC-V
and LoongArch .balign 64.
The other statements:
- The comment at mkRegRegMoveInstr, in GHC.CmmToAsm.X86.Instr, says
that its move clears the upper part of the register. A TODO says
that for a float or a double it is MOV FF64, printed movsd, which
keeps the destination's upper half.
- invertCondBranches inverts a jump only after an integer comparison.
A TODO says that maybeInvertCond's complement on the flags is as sound
after a floating-point one.
- pprBasicBlock in GHC.CmmToAsm.X86.Ppr aligns, past a procedure's
start, only a block with an info table (TODO, ISSUE 27668).
- condIntCode' tests a value against zero even on a path where
the instruction computing it has set ZF and SF from it, as on the back
edge of a loop that counts down: it gets only the comparison,
and another path into the test, such as the loop's entry, may set
no flags. Only a condition that reads ZF and SF alone could use
the flags of a dec, which writes OF and leaves CF where TEST clears
both (TODO, ISSUE 27738).
- The header of GHC.CmmToAsm.Reg.Graph.Coalesce says, as a TODO,
that no module imports it, and that its pass, which ran before graph
allocation (-fregs-graph), has had no caller since 2007, when
it was taken out of the pipeline in favour of the coalescing
that GHC.Data.Graph.Color.colorGraph does.
- Note [Unsafe foreign calls clobber caller-save registers]
in GHC.Cmm.Node points to the BUG at callerSaves.
- Note [Updating the CFG during CodeGen] in GHC.CmmToAsm.Monad, on what
a caller of getNonClobberedAmode must guard against, cites the BUGs
at genXchg and at genAtomicRMW's cmpxchg_code.
- The comment in cmmDebugLabels, in GHC.Cmm.DebugBlock, on the blocks
it declares missing, points to the BUG at cmmDebugLink.
- The panics on a vector's width or format in the CmmLoad cases
of getRegister' in GHC.CmmToAsm.RV64.CodeGen
and GHC.CmmToAsm.LA64.CodeGen, in pprInstr's case for LD
in GHC.CmmToAsm.PPC.Ppr and in floatVecOp
in GHC.CmmToAsm.AArch64.CodeGen point to the BUG at emitPrimOp's
vector arithmetic primops.
- The comment at getRegister''s case for MO_V_Insert 2 W64,
in GHC.CmmToAsm.X86.CodeGen, points to the BUG at its case
for MO_V_Broadcast.
- The comment at getRegister''s case for MO_V_Extract 2 W64,
in GHC.CmmToAsm.X86.CodeGen, points to the BUG at iselExpr64's last
clause there.
Assisted-by: Claude Opus 5.5
- - - - -
ee55bc52 by Mikolaj Konarski at 2026-11-28T10:49:33+01:00
State the NCG's norms and where a branch's likely side is known
Of what anyone working with the NCG needs, this commit serves "The norms
and principles that apply to the NCG, whether each is agreed or only
proposed, and which trade-offs are acceptable." and "How to write a test
for a change to the NCG: where such tests live, what hand-written Cmm
may contain, and how a test is confined to a target or a way or marked
as a known failure."
Comments only; the generated code is the same.
Note [Norms of the NCG], in GHC.CmmToAsm, states two norms that GHC's
own documents and testsuite hold the native code generator to, and what
each means for a change. Under -fobject-determinism the output is
to be bit-for-bit the same for the same inputs, so an order taken
from uniques is a question for review. The testsuite passes -dcmm-lint
by default, so a .cmm file that a test compiles with the ghc program
must be one that Cmm lint accepts, unless the test turns the lints off.
Note [Where a branch's likely side is known], in GHC.CmmToAsm.CFG, says
where it is known which side of a conditional branch is likely: where
the branch is made, as for heap and stack checks; upstream,
and not carried down, for constructor-tag tests; and nowhere,
for the rest, to which static prediction applies its heuristics on loop
exits and equality tests where the branch is two-way and has no back
edge, and its back edge rule where the branch has both a back edge
and another edge. It also states the trade-offs kept
with that knowledge, each with its reason: conditions inverted
so that the true side falls through where it has one predecessor, even
where the false side is likely if that side has more than one, and edges
across calls left out when chains are built and when neighbouring chains
are combined.
Note [Norms of the NCG] points to it.
Assisted-by: Claude Opus 5.5
- - - - -
cb14f824 by Mikolaj Konarski at 2026-11-28T10:49:33+01:00
Rewrite the NCG's overview Note
Of what anyone working with the NCG needs, this commit serves "Comments
and Notes that are true of the code they describe.", "Which targets go
through the NCG, which of its parts each target uses, and what the NCG
takes from the Cmm pipeline, StgToCmm and the RTS.", "The NCG's passes
in the order they run, and what each requires of the one before.",
"Which dump flag shows the output of which pass, and how to read each
dump.", "The invariants the code depends on.", "What each MachOp
and each Cmm construct means, precisely enough to write a code generator
from: a shift by the width or more, the upper bits of a value narrower
than its register, what a foreign call may clobber.", "What the NCG
leaves to the assembler and the linker: which operand ranges a code
generator checks and which only the assembler rejects, which branches
the NCG lengthens, and which assemblers its output is written for.",
"How to build and test a change to the NCG: which stage's compiler runs
the changed code, which builds check the compiler's assertions,
and which test directories and testsuite ways exercise the NCG.", "Which
flags and build settings change what the NCG emits, such as `-g`,
`-fPIC`, `-dynamic` and `-fproc-alignment`, and which of them the tests
run with.", "What the tests cover and what they do not: which targets CI
runs natively, which paths have few or no tests, and which performance
test exercises which pass." and "How to measure a change to the NCG:
which benchmarks exercise which parts of the NCG and which barely
exercise it; which tools run them and compare two compilers' results,
how to set them up and where to get them; how noisy each benchmark is;
which counter to trust; and what besides the compiler moves a result,
such as the host, the environment and how the baseline was built."
Comments only; the generated code is the same.
Note [Native code generator], the module header of GHC.CmmToAsm, named
CmmStmts, cmmCodeGen, targetDoubleSize and smStablePtrTable, which
nothing defines, and machine-independent optimisations "defined below",
which are in GHC.Cmm.GenericOpt. This commit rewrites it. The Note now
says:
- which targets go through cmmNativeGen, that wasm32 has a generator
of its own, and which back end the other targets get by default;
- what the Cmm pipeline returns, and what the NCG takes from StgToCmm
and the RTS;
- the interfaces through which the machine-independent parts access
a target, and what only some targets have;
- the passes, in the order cmmNativeGen runs them, with the flags
that turn them on and the dump flags that show their output, and,
at step 4, what instruction selection must ensure;
- where the NCG's uniques come from;
- what the assembler and the linker do after it;
- the flags, testsuite directories and benchmarks for working
on the NCG.
For detail it cites the Notes and labelled statements of the preceding
commits.
Assisted-by: Claude Opus 5.5
- - - - -
a9784ddb by Mikolaj Konarski at 2026-11-28T10:49:33+01:00
Propose two principles for the NCG
Of what anyone working with the NCG needs, this commit serves "The norms
and principles that apply to the NCG, whether each is agreed or only
proposed, and which trade-offs are acceptable."
Comments only; the generated code is the same.
Note [Proposed principles of the NCG], in GHC.CmmToAsm, puts two
principles to GHC's developers, of which it says that the native code
generator does not keep the second:
- correctness first: semantic correctness is not traded for a measured
gain that an incorrect form gives by accident, until a form with both
has been looked for and the trade agreed in review;
- one TODO set: a departure from correctness that is left in place
is marked TODO, as a member of one set that is accepted for now
and re-investigated together.
No other commit cites the Note, so this commit can be dropped
on its own.
Assisted-by: Claude Opus 5.5
- - - - -
4d67151e by Mikolaj Konarski at 2026-11-28T10:49:33+01:00
Add a README to the NCG's directory
Of what anyone working with the NCG needs, this commit serves "An order
in which to read the NCG's Notes.", "One place where the terms the NCG's
comments use are defined.", "One small function followed through
the NCG's dumps, in the order of its passes.", "Which dump flag shows
the output of which pass, and how to read each dump.", "Which parts
of the NCG were examined for bugs, half-done work and likely changes,
and which were not.", "What to ask of a merge request that changes
the NCG, by the kind of change: which invariants it must keep, and which
tests and measurements should come with it.", "The invariants the code
depends on.", "How to find the pass at fault for a miscompilation
or a compiler panic, and how to reduce the case to a Cmm test.", "What
else must change when a MachOp, an instruction, a register
or a relocation is added or changed." and "How to write a test
for a change to the NCG: where such tests live, what hand-written Cmm
may contain, and how a test is confined to a target or a way or marked
as a known failure."
Documentation only; the generated code is the same.
compiler/GHC/CmmToAsm/README.md is a way in for anyone working
with the native code generator, whether reading its output and dumps,
tracking a fault to its pass, reviewing or making a change,
or maintaining it. It says what to read and what to do. Its sections:
- Where to start reading: three Notes of GHC.CmmToAsm, then Notes
on the passes, each with its module, in the overview's order.
- Vocabulary: the terms the NCG's comments use, each with where
it is defined or used.
- Finding the pass at fault: for a wrong result or a panic, the oracles
to compare with, the flags that switch a pass off or swap it,
the lints, and how to cut a case down to a Cmm test.
- One function through the dumps: a small loop compiled at -O on x86-64,
with an excerpt for each dump flag in the overview's list of passes
but -ddump-asm-regalloc-stages and -ddump-asm-conflicts, which print
nothing under the linear allocator.
- Reviewing a change: questions to ask of a change by its kind, each
citing the Note or comment it rests on.
- What the labelled statements cover: which parts of the NCG they
were first written from, and which were left out.
The excerpts are cut from the dumps of one compilation by a compiler
built from master at 37ad471050: each of their lines but "..." is a line
of a dump, in the dump's order, with tabs replaced by spaces. Every
Note, function, module, flag and path the README names exists
at this commit. The overview, Note [Native code generator], now ends
by pointing to the README.
Assisted-by: Claude Opus 5.5
- - - - -
200 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/27892
- + changelog.d/T27137
- + changelog.d/T27637
- + changelog.d/T27862
- + changelog.d/T28123
- + changelog.d/T28135
- + changelog.d/iserv-no-gc-sections.md
- + changelog.d/make-depends-link-nodes
- + changelog.d/make-depends-streaming-output
- compiler/CodeGen.Platform.h
- compiler/GHC/Cmm/CLabel.hs
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/Cmm/DebugBlock.hs
- compiler/GHC/Cmm/Info.hs
- compiler/GHC/Cmm/Info/Build.hs
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/Cmm/Parser.y
- compiler/GHC/Cmm/Reg.hs
- compiler/GHC/Cmm/Sink.hs
- compiler/GHC/Cmm/Utils.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/CFG/Weight.hs
- compiler/GHC/CmmToAsm/Dwarf.hs
- compiler/GHC/CmmToAsm/Dwarf/Constants.hs
- compiler/GHC/CmmToAsm/Dwarf/Types.hs
- compiler/GHC/CmmToAsm/Format.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/CodeGen.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PIC.hs
- compiler/GHC/CmmToAsm/PPC/CodeGen.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/PPC/Ppr.hs
- + compiler/GHC/CmmToAsm/README.md
- compiler/GHC/CmmToAsm/RV64/CodeGen.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Graph.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Base.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Coalesce.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Spill.hs
- compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs
- compiler/GHC/CmmToAsm/Reg/Graph/TrivColorable.hs
- compiler/GHC/CmmToAsm/Reg/Graph/X86.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Linear/AArch64.hs
- compiler/GHC/CmmToAsm/Reg/Linear/Base.hs
- compiler/GHC/CmmToAsm/Reg/Linear/FreeRegs.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/Reg/Linear/StackMap.hs
- compiler/GHC/CmmToAsm/Reg/Liveness.hs
- compiler/GHC/CmmToAsm/Reg/Regs.hs
- compiler/GHC/CmmToAsm/Reg/Target.hs
- compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/CmmToAsm/X86/Regs.hs
- compiler/GHC/CmmToC.hs
- compiler/GHC/Core/Map/Expr.hs
- compiler/GHC/Core/Map/Type.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/TyCo/Make.hs
- compiler/GHC/Driver/Config/CmmToAsm.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.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/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Linker/Executable.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Platform/Reg.hs
- compiler/GHC/Platform/Reg/Class.hs
- compiler/GHC/Runtime/Interpreter/C.hs
- compiler/GHC/StgToCmm/Monad.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- + distrib/configure.ac
- docs/users_guide/debug-info.rst
- docs/users_guide/make-depends-json-schema-1_0.json
- docs/users_guide/phases.rst
- docs/users_guide/separate_compilation.rst
- docs/users_guide/using-optimisation.rst
- rts/StgCRun.c
- testsuite/driver/my_typing.py
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- 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_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/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_mhu01.dep-json → testsuite/tests/driver/mkdepend/mkdepend_mhu01a.dep-json
- testsuite/tests/driver/mkdepend/mkdepend_mhu01.dep-makefile → testsuite/tests/driver/mkdepend/mkdepend_mhu01a.dep-makefile
- + testsuite/tests/driver/mkdepend/mkdepend_mhu01b.stderr
- + testsuite/tests/driver/mkdepend/mkdepend_mhu01c.stderr
- + testsuite/tests/driver/mkdepend/mkdepend_mhu01d.dep-makefile
- + testsuite/tests/driver/mkdepend/mkdepend_mhu01d.stderr
- + 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/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/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.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/pmcheck/should_compile/T27892a.hs
- + testsuite/tests/pmcheck/should_compile/T28095.hs
- testsuite/tests/pmcheck/should_compile/all.T
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/all.T
- + testsuite/tests/simplCore/should_compile/T27892.hs
- + testsuite/tests/simplCore/should_compile/T27892.stderr
- + testsuite/tests/simplCore/should_compile/T28095a.hs
- + testsuite/tests/simplCore/should_compile/T28095a.stderr
- 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
- + testsuite/tests/vdq-rta/should_compile/T28123.hs
- testsuite/tests/vdq-rta/should_compile/all.T
- 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/273bc4b2bc96880e03124ae4abe964…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/273bc4b2bc96880e03124ae4abe964…
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/marge_bot_batch_merge_job] 10 commits: RTS: static check to disallow nested Begin/EndPrivate.h
by Marge Bot (@marge-bot) 28 Nov '26
by Marge Bot (@marge-bot) 28 Nov '26
28 Nov '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
e70d0f5e by David Eichmann at 2026-11-27T19:41:24-05:00
RTS: static check to disallow nested Begin/EndPrivate.h
- - - - -
53ad660d by David Eichmann at 2026-11-27T19:41:24-05:00
RTS: add RTS_PUBLIC macro and protect against use in Begin/EndPrivate.h group
- - - - -
46f46bae by David Eichmann at 2026-11-27T19:41:24-05:00
RTS: tag all exported symbols with RTS_PUBLIC
- - - - -
4ec15fb2 by David Eichmann at 2026-11-27T19:41:24-05:00
RTS: Remove Begin/EndPrivate.h
Also remove PrivateIncludeLinter from the testsuite as it is nolonger
needed.
- - - - -
60aeb593 by sheaf at 2026-11-27T19:41:40-05:00
Make FunDepEqns a non-empty list
This avoids creating a 'FunDepEqns' with no equations. This means that
consumers dealing with [FunDepEqns] can reliably use "null fun_dep_eqns"
to decide whether there are any equations.
- - - - -
63d14d45 by sheaf at 2026-11-27T19:41:40-05:00
tryFamEqFunDeps: (CF1) only for closed tyfams
This commit makes (CF1) in Note [Exploiting closed type families] only
apply to *closed* type families, not *open* type families.
This allows the program reported in #28082 to continue to be accepted,
fixing a regression.
Fixes #28082
- - - - -
5f2d2045 by Sylvain Henry at 2026-11-27T19:42:07-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>
- - - - -
b29c2a11 by David Eichmann at 2026-11-27T19:42:09-05:00
testsuite: fix framework failure on window for tests using all_available_io_managers_except()
- - - - -
c3dda971 by David Eichmann at 2026-11-27T19:42:09-05:00
testsuite: use `all_available_io_managers` for various tests
Affected tests:
* T10590
* T21969
* T21969a
* T21969b
* T21969c
* T21969d
* T21969e
* T21969f
- - - - -
ea95d108 by Sylvain Henry at 2026-11-27T19:42:14-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>
- - - - -
244 changed files:
- + changelog.d/28105
- + changelog.d/T28082
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/Tc/Instance/FunDeps.hs
- compiler/GHC/Tc/Solver/FunDeps.hs
- rts/ARMOutlineAtomicsSymbols.h
- rts/Adjustor.h
- rts/AllocArray.h
- rts/Arena.h
- − rts/BeginPrivate.h
- rts/BuiltinClosures.h
- rts/Capability.h
- rts/CheckUnload.h
- rts/CheckVectorSupport.h
- rts/CloneStack.h
- rts/ClosureTable.h
- rts/Continuation.h
- − rts/EndPrivate.h
- rts/ForeignExports.h
- rts/GetEnv.h
- rts/GetTime.h
- rts/Globals.c
- rts/Hash.h
- rts/Hpc.c
- rts/IOManager.h
- rts/IOManagerInternals.h
- rts/IPE.h
- rts/Interpreter.c
- rts/Interpreter.h
- rts/Libdw.h
- rts/LibdwPool.h
- rts/Linker.c
- rts/LinkerInternals.h
- rts/Messages.h
- rts/PathUtils.h
- rts/Pool.h
- rts/Printer.c
- rts/Printer.h
- rts/ProfHeap.c
- rts/ProfHeap.h
- rts/ProfHeapInternal.h
- rts/ProfilerReport.h
- rts/ProfilerReportJson.h
- rts/Profiling.h
- rts/Proftimer.c
- rts/Proftimer.h
- rts/RaiseAsync.h
- rts/ReportMemoryMap.h
- rts/RetainerProfile.h
- rts/RetainerSet.h
- rts/RtsAPI.c
- rts/RtsFlags.c
- rts/RtsFlags.h
- rts/RtsMessages.c
- rts/RtsSignals.h
- rts/RtsSymbolInfo.h
- rts/RtsSymbols.c
- rts/RtsSymbols.h
- rts/RtsUtils.h
- rts/SMPClosureOps.h
- rts/STM.c
- rts/STM.h
- rts/Schedule.c
- rts/Schedule.h
- rts/Sparks.h
- rts/StableName.h
- rts/StablePtr.h
- rts/StaticPtrTable.h
- rts/Stats.c
- rts/Stats.h
- rts/StgPrimFloat.h
- rts/Task.c
- rts/Task.h
- rts/ThreadLabels.h
- rts/ThreadPaused.h
- rts/Threads.h
- rts/Ticker.h
- rts/Ticky.c
- rts/Ticky.h
- rts/TimeoutQueue.c
- rts/TimeoutQueue.h
- rts/Timer.h
- rts/TopHandler.h
- rts/Trace.h
- rts/TraverseHeap.c
- rts/TraverseHeap.h
- rts/TraverseHeapTest.c
- rts/Updates.h
- rts/WSDeque.h
- rts/Weak.h
- rts/adjustor/AdjustorPool.h
- rts/adjustor/NativeAmd64.c
- rts/eventlog/EventLog.c
- rts/eventlog/EventLog.h
- rts/gen_event_types.py
- rts/hooks/Hooks.h
- rts/include/HsFFI.h
- rts/include/Rts.h
- rts/include/RtsAPI.h
- + rts/include/RtsPublic.h
- rts/include/Stg.h
- rts/include/rts/Adjustor.h
- rts/include/rts/BlockSignals.h
- rts/include/rts/EventLogWriter.h
- rts/include/rts/ExecPage.h
- rts/include/rts/FileLock.h
- rts/include/rts/Flags.h
- rts/include/rts/ForeignExports.h
- rts/include/rts/GetTime.h
- rts/include/rts/Globals.h
- rts/include/rts/Hpc.h
- rts/include/rts/IOInterface.h
- rts/include/rts/IPE.h
- rts/include/rts/Libdw.h
- rts/include/rts/LibdwPool.h
- rts/include/rts/Linker.h
- rts/include/rts/Main.h
- rts/include/rts/Messages.h
- rts/include/rts/NonMoving.h
- rts/include/rts/OSThreads.h
- rts/include/rts/Parallel.h
- rts/include/rts/PrimFloat.h
- rts/include/rts/Profiling.h
- rts/include/rts/RtsSymbols.h
- rts/include/rts/RtsToHsIface.h
- rts/include/rts/SpinLock.h
- rts/include/rts/StableName.h
- rts/include/rts/StablePtr.h
- rts/include/rts/StaticPtrTable.h
- rts/include/rts/TTY.h
- rts/include/rts/Threads.h
- rts/include/rts/Ticky.h
- rts/include/rts/Time.h
- rts/include/rts/Timer.h
- rts/include/rts/Utils.h
- rts/include/rts/prof/CCS.h
- rts/include/rts/prof/Heap.h
- rts/include/rts/storage/Block.h
- rts/include/rts/storage/ClosureMacros.h
- rts/include/rts/storage/GC.h
- rts/include/rts/storage/Heap.h
- rts/include/rts/storage/HeapAlloc.h
- rts/include/rts/storage/InfoTables.h
- rts/include/rts/storage/MBlock.h
- rts/include/rts/storage/TSO.h
- rts/include/stg/MiscClosures.h
- rts/include/stg/Prim.h
- rts/include/stg/Regs.h
- rts/include/stg/SMP.h
- rts/include/stg/Ticky.h
- rts/linker/CacheFlush.h
- rts/linker/Elf.h
- rts/linker/InitFini.h
- rts/linker/LoadNativeObjPosix.h
- rts/linker/M32Alloc.c
- rts/linker/M32Alloc.h
- rts/linker/MMap.h
- rts/linker/MachO.h
- rts/linker/PEi386.h
- rts/linker/ProddableBlocks.h
- rts/linker/SymbolExtras.h
- rts/linker/elf_got.h
- rts/linker/elf_plt.h
- rts/linker/elf_plt_aarch64.c
- rts/linker/elf_plt_aarch64.h
- rts/linker/elf_plt_riscv64.c
- rts/linker/elf_plt_riscv64.h
- rts/linker/elf_reloc.h
- rts/linker/elf_reloc_aarch64.c
- rts/linker/elf_reloc_aarch64.h
- rts/linker/elf_reloc_riscv64.c
- rts/linker/elf_reloc_riscv64.h
- rts/linker/elf_util.h
- rts/linker/macho/plt.h
- rts/linker/macho/plt_aarch64.c
- rts/linker/macho/plt_aarch64.h
- rts/posix/FdWakeup.h
- rts/posix/MIO.h
- rts/posix/Poll.h
- rts/posix/Select.h
- rts/posix/SelectBis.h
- rts/posix/Signals.c
- rts/posix/Signals.h
- rts/posix/Timeout.h
- rts/rts.cabal
- rts/sm/BlockAlloc.c
- rts/sm/BlockAlloc.h
- rts/sm/CNF.h
- rts/sm/Compact.h
- rts/sm/Evac.h
- rts/sm/GC.h
- rts/sm/GCTDecl.h
- rts/sm/GCThread.h
- rts/sm/GCUtils.h
- rts/sm/MBlock.c
- rts/sm/MarkStack.h
- rts/sm/MarkWeak.h
- rts/sm/NonMoving.c
- rts/sm/NonMoving.h
- rts/sm/NonMovingAllocate.h
- rts/sm/NonMovingCensus.h
- rts/sm/NonMovingMark.h
- rts/sm/NonMovingScav.h
- rts/sm/NonMovingShortcut.h
- rts/sm/NonMovingSweep.h
- rts/sm/OSMem.h
- rts/sm/Sanity.c
- rts/sm/Sanity.h
- rts/sm/Scav.h
- rts/sm/ShouldCompact.h
- rts/sm/Storage.c
- rts/sm/Storage.h
- rts/wasm/JSFFI.c
- rts/wasm/JSFFIGlobals.c
- rts/wasm/StgRun.c
- rts/win32/AsyncMIO.h
- rts/win32/AsyncWinIO.h
- rts/win32/AwaitEvent.h
- rts/win32/ConsoleHandler.h
- rts/win32/MIOManager.h
- rts/win32/ThrIOManager.h
- rts/win32/WorkQueue.h
- rts/win32/veh_excn.h
- testsuite/driver/testutil.py
- + testsuite/tests/codeGen/should_compile/T28105.cmm
- + testsuite/tests/codeGen/should_compile/T28105b.hs
- testsuite/tests/codeGen/should_compile/all.T
- testsuite/tests/concurrent/should_run/all.T
- testsuite/tests/ghci/linking/dyn/A.c
- testsuite/tests/ghci/linking/dyn/B.c
- 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
- + testsuite/tests/indexed-types/should_compile/T28082.hs
- testsuite/tests/indexed-types/should_compile/all.T
- testsuite/tests/linters/regex-linters/check-rts-includes.py
- testsuite/tests/rts/T12771/foo_dll.c
- testsuite/tests/rts/T13082/foo_dll.c
- testsuite/tests/rts/T14611/foo_dll.c
- testsuite/tests/rts/all.T
- utils/fs/fs.h
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/629428949ecbe5fbbfc3c6d3451d41…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/629428949ecbe5fbbfc3c6d3451d41…
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/T28187] Make -fcpr-anal control CPR analysis directly
by Simon Peyton Jones (@simonpj) 28 Nov '26
by Simon Peyton Jones (@simonpj) 28 Nov '26
28 Nov '26
Simon Peyton Jones pushed to branch wip/T28187 at Glasgow Haskell Compiler / GHC
Commits:
51c9f96c by Simon Peyton Jones at 2026-11-27T23:59:34+00:00
Make -fcpr-anal control CPR analysis directly
Fixes #28187, just a tidy up refactoring.
Previously `-fcpr-anal` did not control whether CPR analysis ran: the
analysis ran whenever worker/wrapper was enabled, and the flag only
stopped worker/wrapper from exploiting its results, via the
`wo_cpr_anal` field of `WwOpts`.
This patch makes `dmd_cpr_ww` in GHC.Core.Opt.Pipeline decide on each
pass separately:
* Demand analysis runs if -fstrictness is on; it does boxity analysis
only if worker/wrapper follows.
* CPR analysis runs if -fcpr-anal is on, but only if worker/wrapper
follows. See Note [Don't change boxity without worker/wrapper].
* Worker/wrapper runs if -fworker-wrapper is on and at least one of
the analyses has run.
* The simplifier runs afterwards if at least one of the analyses has
run.
We can now drop `wo_cpr_anal` altogether: without CPR analysis, no
local binder has a constructed CPR signature, so worker/wrapper never
does CPR splitting anyway. (The simplifier gives bottoming bindings
`botCpr`, but `canUnboxResult` does not unbox for that.)
Consequences:
* A module compiled with -fno-cpr-anal has no CPR information in its
interface file.
* -O -fno-strictness -fworker-wrapper now runs CPR analysis and
worker/wrapper, where previously it ran neither.
* -flate-dmd-anal runs the same demand/CPR/worker-wrapper round a
second time, late in the pipeline, each pass under its own flag; the
user guide now says so.
* The final demand-analysis run is now guarded by -fstrictness alone;
previously -flate-dmd-anal also triggered it, even when no other
demand analysis had run.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
6 changed files:
- + changelog.d/T28187
- compiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Driver/Config/Core/Opt/WorkWrap.hs
- docs/users_guide/using-optimisation.rst
Changes:
=====================================
changelog.d/T28187
=====================================
@@ -0,0 +1,21 @@
+section: compiler
+synopsis:
+ ``-fno-cpr-anal`` now switches off CPR analysis itself, rather than just
+ stopping worker/wrapper from using its results.
+issues: #28187
+mrs: !17063
+description: {
+ Previously CPR analysis ran whenever worker/wrapper was enabled, regardless
+ of ``-fcpr-anal``. Now each of the demand analyser, CPR analyser and
+ worker/wrapper passes is controlled by its own flag:
+
+ - Demand analysis runs if ``-fstrictness`` is on.
+ - CPR analysis runs if both ``-fcpr-anal`` and ``-fworker-wrapper`` are on.
+ - Worker/wrapper runs if ``-fworker-wrapper`` is on and at least one of
+ the two analyses has run.
+
+ One consequence is that a module compiled with ``-fno-cpr-anal`` has no
+ CPR information in its interface file, so CPR analysis in importing
+ modules sees less. Also, ``-fno-strictness -fworker-wrapper`` now runs CPR
+ analysis and worker/wrapper, where previously it ran neither.
+}
=====================================
compiler/GHC/Core/Opt/DmdAnal.hs
=====================================
@@ -195,7 +195,8 @@ to transfer over the previous boxity to the new demand signature, in
`setIdDmdAndBoxSig`.
Why isn't CprAnal configured with a similar flag? Because if we aren't going to
-do worker/wrapper we don't run CPR analysis at all. (see GHC.Core.Opt.Pipeline)
+do worker/wrapper we don't run CPR analysis at all. (see `dmd_cpr_ww` in
+GHC.Core.Opt.Pipeline)
It might be surprising that we only try to preserve *arg* boxity, not boxity on
FVs. But FV demands won't make it into interface files anyway, so it's a waste
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -132,6 +132,7 @@ getCoreToDo dflags hpt_rule_base extra_vars
call_arity = gopt Opt_CallArity dflags
exitification = gopt Opt_Exitification dflags
strictness = gopt Opt_Strictness dflags
+ cpr_anal = gopt Opt_CprAnal dflags
full_laziness = gopt Opt_FullLaziness dflags
do_specialise = gopt Opt_Specialise dflags
do_float_in = gopt Opt_FloatIn dflags
@@ -172,14 +173,30 @@ getCoreToDo dflags hpt_rule_base extra_vars
simpl_gently = CoreDoSimplify $ initSimplifyOpts dflags extra_vars max_iter
(initGentleSimplMode dflags) hpt_rule_base
- dmd_cpr_ww = if ww_on then [CoreDoDemand True,CoreDoCpr,CoreDoWorkerWrapper]
- else [CoreDoDemand False] -- NB: No CPR! See Note [Don't change boxity without worker/wrapper]
-
-
- demand_analyser = (CoreDoPasses (
- dmd_cpr_ww ++
- [simplify "post-worker-wrapper"]
- ))
+ -- Demand analysis, CPR analysis, worker/wrapper, and a simplifier run
+ -- to clean up. Each is controlled by its own flag, as follows
+ --
+ -- * Demand analysis runs if -fstrictness is on; it does boxity
+ -- analysis only if worker/wrapper follows, hence (CoreDoDemand ww_on)
+ --
+ -- * CPR analysis runs if -fcpr-anal is on, but only if worker/wrapper
+ -- follows. See Note [Don't change boxity without worker/wrapper]
+ -- in GHC.Core.Opt.DmdAnal
+ --
+ -- * Worker/wrapper runs if -fworker-wrapper is on, and at
+ -- least one of the analyses has run.
+ --
+ -- * The simplifier runs if at least one of the analyses has run,
+ -- regardless of worker/wrapper
+ dmd_cpr_ww simpl_name
+ = CoreDoPasses
+ [ runWhen strictness (CoreDoDemand ww_on)
+ , runWhen do_cpr CoreDoCpr
+ , runWhen do_ww CoreDoWorkerWrapper
+ , runWhen (strictness || do_cpr) (simplify simpl_name) ]
+ where
+ do_cpr = ww_on && cpr_anal
+ do_ww = ww_on && (strictness || do_cpr)
add_caller_ccs =
runWhen (profiling && not (null $ callerCcFilters dflags)) CoreAddCallerCcs
@@ -259,7 +276,7 @@ getCoreToDo dflags hpt_rule_base extra_vars
],
-- Strictness analysis
- runWhen strictness demand_analyser,
+ dmd_cpr_ww "post-worker-wrapper",
runWhen exitification CoreDoExitify,
-- See Note [Placement of the exitification pass]
@@ -319,16 +336,14 @@ getCoreToDo dflags hpt_rule_base extra_vars
--------- End of -O2 passes --------------
- runWhen late_dmd_anal $ CoreDoPasses (
- dmd_cpr_ww ++ [simplify "post-late-ww"]
- ),
+ runWhen late_dmd_anal $ dmd_cpr_ww "post-late-ww",
-- Final run of the demand_analyser, ensures that one-shot thunks are
-- really really one-shot thunks. Only needed if the demand analyser
-- has run at all. See Note [Final Demand Analyser run] in GHC.Core.Opt.DmdAnal
-- It is EXTREMELY IMPORTANT to run this pass, otherwise execution
-- can become /exponentially/ more expensive. See #11731, #12996.
- runWhen (strictness || late_dmd_anal) (CoreDoDemand False),
+ runWhen strictness (CoreDoDemand False),
maybe_rule_check FinalPhase,
=====================================
compiler/GHC/Core/Opt/WorkWrap/Utils.hs
=====================================
@@ -141,9 +141,6 @@ data WwOpts
wo_fam_envs :: !FamInstEnvs
, -- | Options for the "Simple optimiser"
wo_simple_opts :: !SimpleOpts
- , -- | Whether to enable "Constructed Product Result" analysis.
- -- (Originally from DOI: 10.1017/S0956796803004751)
- wo_cpr_anal :: !Bool
, -- | Used for absent argument error message
wo_module :: !Module
, -- | Generate workers even if the only effect is some args get passed
@@ -1603,9 +1600,7 @@ mkWWcpr_entry
CoreExpr -> CoreExpr, -- New wrapper. 'nop_fn' if not useful
CoreExpr -> CoreExpr) -- New worker. 'nop_fn' if not useful
-- ^ Entrypoint to CPR W/W. See Note [Worker/wrapper for CPR] for an overview.
-mkWWcpr_entry opts body_ty body_cpr
- | not (wo_cpr_anal opts) = return (boringSplit, nop_fn, nop_fn)
- | otherwise = do
+mkWWcpr_entry opts body_ty body_cpr = do
-- Part (1)
res_bndr <- mk_res_bndr body_ty
let bind_res_bndr body scope = mkDefaultCase body res_bndr scope
=====================================
compiler/GHC/Driver/Config/Core/Opt/WorkWrap.hs
=====================================
@@ -15,7 +15,6 @@ initWorkWrapOpts :: Module -> DynFlags -> FamInstEnvs -> WwOpts
initWorkWrapOpts this_mod dflags fam_envs = MkWwOpts
{ wo_fam_envs = fam_envs
, wo_simple_opts = initSimpleOpts dflags
- , wo_cpr_anal = gopt Opt_CprAnal dflags
, wo_module = this_mod
, wo_unlift_strict = gopt Opt_WorkerWrapperUnlift dflags
}
=====================================
docs/users_guide/using-optimisation.rst
=====================================
@@ -376,6 +376,13 @@ as such you shouldn't need to set any of them explicitly. A flag
and then ``sum`` can inline to potentially cancel away the ``I#`` box.
+ With :ghc-flag:`-fno-cpr-anal`, CPR analysis does not run at all. As a
+ result the module's interface file records no CPR information (other
+ than for functions that definitely diverge), so CPR analysis in
+ importing modules sees less. CPR analysis also does not run with
+ :ghc-flag:`-fno-worker-wrapper`, because its results are used only by
+ the worker/wrapper transformation.
+
Here's an example of the function that *does not* return a constructed product: ::
f :: [Int] -> (Int -> Int) -> Int
@@ -788,16 +795,19 @@ as such you shouldn't need to set any of them explicitly. A flag
it on keeps all auto-generated rules.
.. ghc-flag:: -flate-dmd-anal
- :shortdesc: Run demand analysis again, at the end of the
- simplification pipeline
+ :shortdesc: Run demand analysis, CPR analysis and worker/wrapper
+ again, late in the simplification pipeline
:type: dynamic
:reverse: -fno-late-dmd-anal
:category:
:default: off
- Run demand analysis again, at the end of the simplification
- pipeline. We found some opportunities for discovering strictness
+ Run the demand analysis, CPR analysis and worker/wrapper passes a
+ second time, late in the simplification pipeline. Each of these
+ passes runs only if its own flag (:ghc-flag:`-fstrictness`,
+ :ghc-flag:`-fcpr-anal`, :ghc-flag:`-fworker-wrapper`) is on.
+ We found some opportunities for discovering strictness
that were not visible earlier; and optimisations like
:ghc-flag:`-fspec-constr` can create functions with unused arguments which
are eliminated by late demand analysis. Improvements are modest, but
@@ -1907,6 +1917,7 @@ as such you shouldn't need to set any of them explicitly. A flag
:shortdesc: Enable the worker/wrapper transformation. Implied by :ghc-flag:`-O`
and by :ghc-flag:`-fstrictness`.
:type: dynamic
+ :reverse: -fno-worker-wrapper
:category:
:default: off but enabled by :ghc-flag:`-O`.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51c9f96cc9559ca9cbd056988a8c775…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51c9f96cc9559ca9cbd056988a8c775…
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/io-manager-deadlock-detection] 21 commits: Narrow the window in which signals might be missed before poll/select
by Duncan Coutts (@dcoutts) 27 Nov '26
by Duncan Coutts (@dcoutts) 27 Nov '26
27 Nov '26
Duncan Coutts pushed to branch wip/io-manager-deadlock-detection at Glasgow Haskell Compiler / GHC
Commits:
6a6f04bb by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
d2618bd6 by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
988f34ea by Duncan Coutts at 2026-11-27T09:39:05+00: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
- - - - -
bd90f566 by Duncan Coutts at 2026-11-27T09:39:05+00: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
- - - - -
21e08307 by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
15f7e229 by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
1478b418 by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
cb3b7c1a by Duncan Coutts at 2026-11-27T09:39:05+00: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.
- - - - -
77ca2449 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
bbca39a8 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
df0dc96b by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
9cd32cd8 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
001d38c2 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
febd4c19 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
075aa709 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
525f3da7 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
2ace3417 by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
79c8081d by Duncan Coutts at 2026-11-27T09:39:06+00:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
f7e735ba by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
04a177e1 by Duncan Coutts at 2026-11-27T09:39:06+00: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
- - - - -
75c36daa by Duncan Coutts at 2026-11-27T09:39:06+00: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.
- - - - -
46 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/IOManager.c
- rts/IOManager.h
- rts/IdleGC.c
- rts/IdleGC.h
- rts/RtsFlags.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/Timeout.c
- rts/posix/Timeout.h
- rts/win32/AsyncMIO.c
- rts/win32/AsyncMIO.h
- rts/win32/AsyncWinIO.c
- rts/win32/AsyncWinIO.h
- rts/win32/AwaitEvent.c
- 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
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7e2611119475229334aa1b58d40017…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7e2611119475229334aa1b58d40017…
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/T28187] Make -fno-cpr-anal switch off CPR analysis
by Simon Peyton Jones (@simonpj) 27 Nov '26
by Simon Peyton Jones (@simonpj) 27 Nov '26
27 Nov '26
Simon Peyton Jones pushed to branch wip/T28187 at Glasgow Haskell Compiler / GHC
Commits:
cb0d5391 by Simon Peyton Jones at 2026-11-27T23:53:23+00:00
Make -fno-cpr-anal switch off CPR analysis
Fixes #28187.
Previously `-fcpr-anal` did not control whether CPR analysis ran: the
analysis ran whenever worker/wrapper was enabled, and the flag only
stopped worker/wrapper from exploiting its results, via the
`wo_cpr_anal` field of `WwOpts`.
This patch makes `dmd_cpr_ww` in GHC.Core.Opt.Pipeline decide on each
pass separately:
* Demand analysis runs if -fstrictness is on; it does boxity analysis
only if worker/wrapper follows.
* CPR analysis runs if -fcpr-anal is on, but only if worker/wrapper
follows. See Note [Don't change boxity without worker/wrapper].
* Worker/wrapper runs if -fworker-wrapper is on and at least one of
the analyses has run.
* The simplifier runs afterwards if at least one of the analyses has
run.
We can now drop `wo_cpr_anal` altogether: without CPR analysis, no
local binder has a constructed CPR signature, so worker/wrapper never
does CPR splitting anyway. (The simplifier gives bottoming bindings
`botCpr`, but `canUnboxResult` does not unbox for that.)
Consequences:
* A module compiled with -fno-cpr-anal has no CPR information in its
interface file.
* -fno-strictness -fworker-wrapper now runs CPR analysis and
worker/wrapper, where previously it ran neither.
* -flate-dmd-anal runs the same demand/CPR/worker-wrapper round a
second time, late in the pipeline, each pass under its own flag; the
user guide now says so.
* The final demand-analysis run is now guarded by -fstrictness alone;
previously -flate-dmd-anal also triggered it, even when no other
demand analysis had run.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
6 changed files:
- + changelog.d/T28187
- compiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Driver/Config/Core/Opt/WorkWrap.hs
- docs/users_guide/using-optimisation.rst
Changes:
=====================================
changelog.d/T28187
=====================================
@@ -0,0 +1,21 @@
+section: compiler
+synopsis:
+ ``-fno-cpr-anal`` now switches off CPR analysis itself, rather than just
+ stopping worker/wrapper from using its results.
+issues: #28187
+mrs: !17063
+description: {
+ Previously CPR analysis ran whenever worker/wrapper was enabled, regardless
+ of ``-fcpr-anal``. Now each of the demand analyser, CPR analyser and
+ worker/wrapper passes is controlled by its own flag:
+
+ - Demand analysis runs if ``-fstrictness`` is on.
+ - CPR analysis runs if both ``-fcpr-anal`` and ``-fworker-wrapper`` are on.
+ - Worker/wrapper runs if ``-fworker-wrapper`` is on and at least one of
+ the two analyses has run.
+
+ One consequence is that a module compiled with ``-fno-cpr-anal`` has no
+ CPR information in its interface file, so CPR analysis in importing
+ modules sees less. Also, ``-fno-strictness -fworker-wrapper`` now runs CPR
+ analysis and worker/wrapper, where previously it ran neither.
+}
=====================================
compiler/GHC/Core/Opt/DmdAnal.hs
=====================================
@@ -195,7 +195,8 @@ to transfer over the previous boxity to the new demand signature, in
`setIdDmdAndBoxSig`.
Why isn't CprAnal configured with a similar flag? Because if we aren't going to
-do worker/wrapper we don't run CPR analysis at all. (see GHC.Core.Opt.Pipeline)
+do worker/wrapper we don't run CPR analysis at all. (see `dmd_cpr_ww` in
+GHC.Core.Opt.Pipeline)
It might be surprising that we only try to preserve *arg* boxity, not boxity on
FVs. But FV demands won't make it into interface files anyway, so it's a waste
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -132,6 +132,7 @@ getCoreToDo dflags hpt_rule_base extra_vars
call_arity = gopt Opt_CallArity dflags
exitification = gopt Opt_Exitification dflags
strictness = gopt Opt_Strictness dflags
+ cpr_anal = gopt Opt_CprAnal dflags
full_laziness = gopt Opt_FullLaziness dflags
do_specialise = gopt Opt_Specialise dflags
do_float_in = gopt Opt_FloatIn dflags
@@ -172,14 +173,25 @@ getCoreToDo dflags hpt_rule_base extra_vars
simpl_gently = CoreDoSimplify $ initSimplifyOpts dflags extra_vars max_iter
(initGentleSimplMode dflags) hpt_rule_base
- dmd_cpr_ww = if ww_on then [CoreDoDemand True,CoreDoCpr,CoreDoWorkerWrapper]
- else [CoreDoDemand False] -- NB: No CPR! See Note [Don't change boxity without worker/wrapper]
-
-
- demand_analyser = (CoreDoPasses (
- dmd_cpr_ww ++
- [simplify "post-worker-wrapper"]
- ))
+ -- Demand analysis, CPR analysis, worker/wrapper, and a simplifier run
+ -- to clean up. Each is controlled by its own flag:
+ -- * Demand analysis runs if -fstrictness is on; it does boxity
+ -- analysis only if worker/wrapper follows.
+ -- * CPR analysis runs if -fcpr-anal is on, but only if worker/wrapper
+ -- follows. See Note [Don't change boxity without worker/wrapper]
+ -- in GHC.Core.Opt.DmdAnal
+ -- * Worker/wrapper runs if -fworker-wrapper is on, but only if at
+ -- least one of the analyses has run.
+ -- * The simplifier runs if at least one of the analyses has run.
+ dmd_cpr_ww simpl_name
+ = CoreDoPasses
+ [ runWhen strictness (CoreDoDemand ww_on)
+ , runWhen do_cpr CoreDoCpr
+ , runWhen do_ww CoreDoWorkerWrapper
+ , runWhen (strictness || do_cpr) (simplify simpl_name) ]
+ where
+ do_cpr = ww_on && cpr_anal
+ do_ww = ww_on && (strictness || do_cpr)
add_caller_ccs =
runWhen (profiling && not (null $ callerCcFilters dflags)) CoreAddCallerCcs
@@ -259,7 +271,7 @@ getCoreToDo dflags hpt_rule_base extra_vars
],
-- Strictness analysis
- runWhen strictness demand_analyser,
+ dmd_cpr_ww "post-worker-wrapper",
runWhen exitification CoreDoExitify,
-- See Note [Placement of the exitification pass]
@@ -319,16 +331,14 @@ getCoreToDo dflags hpt_rule_base extra_vars
--------- End of -O2 passes --------------
- runWhen late_dmd_anal $ CoreDoPasses (
- dmd_cpr_ww ++ [simplify "post-late-ww"]
- ),
+ runWhen late_dmd_anal $ dmd_cpr_ww "post-late-ww",
-- Final run of the demand_analyser, ensures that one-shot thunks are
-- really really one-shot thunks. Only needed if the demand analyser
-- has run at all. See Note [Final Demand Analyser run] in GHC.Core.Opt.DmdAnal
-- It is EXTREMELY IMPORTANT to run this pass, otherwise execution
-- can become /exponentially/ more expensive. See #11731, #12996.
- runWhen (strictness || late_dmd_anal) (CoreDoDemand False),
+ runWhen strictness (CoreDoDemand False),
maybe_rule_check FinalPhase,
=====================================
compiler/GHC/Core/Opt/WorkWrap/Utils.hs
=====================================
@@ -141,9 +141,6 @@ data WwOpts
wo_fam_envs :: !FamInstEnvs
, -- | Options for the "Simple optimiser"
wo_simple_opts :: !SimpleOpts
- , -- | Whether to enable "Constructed Product Result" analysis.
- -- (Originally from DOI: 10.1017/S0956796803004751)
- wo_cpr_anal :: !Bool
, -- | Used for absent argument error message
wo_module :: !Module
, -- | Generate workers even if the only effect is some args get passed
@@ -1603,9 +1600,7 @@ mkWWcpr_entry
CoreExpr -> CoreExpr, -- New wrapper. 'nop_fn' if not useful
CoreExpr -> CoreExpr) -- New worker. 'nop_fn' if not useful
-- ^ Entrypoint to CPR W/W. See Note [Worker/wrapper for CPR] for an overview.
-mkWWcpr_entry opts body_ty body_cpr
- | not (wo_cpr_anal opts) = return (boringSplit, nop_fn, nop_fn)
- | otherwise = do
+mkWWcpr_entry opts body_ty body_cpr = do
-- Part (1)
res_bndr <- mk_res_bndr body_ty
let bind_res_bndr body scope = mkDefaultCase body res_bndr scope
=====================================
compiler/GHC/Driver/Config/Core/Opt/WorkWrap.hs
=====================================
@@ -15,7 +15,6 @@ initWorkWrapOpts :: Module -> DynFlags -> FamInstEnvs -> WwOpts
initWorkWrapOpts this_mod dflags fam_envs = MkWwOpts
{ wo_fam_envs = fam_envs
, wo_simple_opts = initSimpleOpts dflags
- , wo_cpr_anal = gopt Opt_CprAnal dflags
, wo_module = this_mod
, wo_unlift_strict = gopt Opt_WorkerWrapperUnlift dflags
}
=====================================
docs/users_guide/using-optimisation.rst
=====================================
@@ -376,6 +376,13 @@ as such you shouldn't need to set any of them explicitly. A flag
and then ``sum`` can inline to potentially cancel away the ``I#`` box.
+ With :ghc-flag:`-fno-cpr-anal`, CPR analysis does not run at all. As a
+ result the module's interface file records no CPR information (other
+ than for functions that definitely diverge), so CPR analysis in
+ importing modules sees less. CPR analysis also does not run with
+ :ghc-flag:`-fno-worker-wrapper`, because its results are used only by
+ the worker/wrapper transformation.
+
Here's an example of the function that *does not* return a constructed product: ::
f :: [Int] -> (Int -> Int) -> Int
@@ -788,16 +795,19 @@ as such you shouldn't need to set any of them explicitly. A flag
it on keeps all auto-generated rules.
.. ghc-flag:: -flate-dmd-anal
- :shortdesc: Run demand analysis again, at the end of the
- simplification pipeline
+ :shortdesc: Run demand analysis, CPR analysis and worker/wrapper
+ again, late in the simplification pipeline
:type: dynamic
:reverse: -fno-late-dmd-anal
:category:
:default: off
- Run demand analysis again, at the end of the simplification
- pipeline. We found some opportunities for discovering strictness
+ Run the demand analysis, CPR analysis and worker/wrapper passes a
+ second time, late in the simplification pipeline. Each of these
+ passes runs only if its own flag (:ghc-flag:`-fstrictness`,
+ :ghc-flag:`-fcpr-anal`, :ghc-flag:`-fworker-wrapper`) is on.
+ We found some opportunities for discovering strictness
that were not visible earlier; and optimisations like
:ghc-flag:`-fspec-constr` can create functions with unused arguments which
are eliminated by late demand analysis. Improvements are modest, but
@@ -1907,6 +1917,7 @@ as such you shouldn't need to set any of them explicitly. A flag
:shortdesc: Enable the worker/wrapper transformation. Implied by :ghc-flag:`-O`
and by :ghc-flag:`-fstrictness`.
:type: dynamic
+ :reverse: -fno-worker-wrapper
:category:
:default: off but enabled by :ghc-flag:`-O`.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cb0d5391bebf37e717d9ade6f286f1c…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cb0d5391bebf37e717d9ade6f286f1c…
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