[Git][ghc/ghc] Pushed new branch wip/sjakobi/T28190-js-th-tests-alone
by Simon Jakobi (@sjakobi) 26 Nov '26
by Simon Jakobi (@sjakobi) 26 Nov '26
26 Nov '26
Simon Jakobi pushed new branch wip/sjakobi/T28190-js-th-tests-alone at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/T28190-js-th-tests-al…
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/davide/fix_tests_over_io_managers] 2 commits: testsuite: fix framework failure on window for tests using all_available_io_managers_except()
by David Eichmann (@DavidEichmann) 26 Nov '26
by David Eichmann (@DavidEichmann) 26 Nov '26
26 Nov '26
David Eichmann pushed to branch wip/davide/fix_tests_over_io_managers at Glasgow Haskell Compiler / GHC
Commits:
272565f4 by David Eichmann at 2026-11-26T11:50:33+00:00
testsuite: fix framework failure on window for tests using all_available_io_managers_except()
- - - - -
a936120d by David Eichmann at 2026-11-26T12:09:57+00:00
testsuite: use `all_available_io_managers` for various tests
Affected tests:
* T10590
* T21969
* T21969a
* T21969b
* T21969c
* T21969d
* T21969e
* T21969f
- - - - -
3 changed files:
- testsuite/driver/testutil.py
- testsuite/tests/concurrent/should_run/all.T
- testsuite/tests/rts/all.T
Changes:
=====================================
testsuite/driver/testutil.py
=====================================
@@ -184,8 +184,10 @@ def shorten_metric_name(name: str) -> str:
# I/O manager discovery for a haskell binary. Returns the set of IO Manager
# strings supported by the binary
def discover_io_managers(hs_exe: Union[str, Path], cwd: Union[str, Path]) -> Set[str]:
+ # We must use an absolute path for the executable. Relative paths break on windows.
+ hs_exe_path = Path(cwd).joinpath(hs_exe)
rp = subprocess.run(
- [str(hs_exe), '+RTS', '--info', '-RTS'],
+ [hs_exe_path, '+RTS', '--info', '-RTS'],
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
=====================================
testsuite/tests/concurrent/should_run/all.T
=====================================
@@ -271,7 +271,8 @@ test('T21969',
extra_run_opts('50000'),
run_timeout_multiplier(0.3), # default timeout seems to be 300, but lockups happen quickly
req_target_smp,
- req_ghc_smp
+ req_ghc_smp,
+ all_available_io_managers,
],
compile_and_run, [''])
@@ -289,24 +290,28 @@ test('T21969',
test('T21969a',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969b',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969c',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969d',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
@@ -314,12 +319,14 @@ test('T21969e',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
run_timeout_multiplier(0.3),
+ all_available_io_managers,
],
compile_and_run, [''])
test('T21969f',
[ only_ways(['threaded1','threaded2', 'nonmoving_thr', 'profthreaded']),
when(opsys('mingw32'),skip), # POSIX only
+ all_available_io_managers,
],
compile_and_run, [''])
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -408,6 +408,7 @@ test('T10590', [ ignore_stderr
, when(opsys('mingw32'), skip)
, js_skip # JS backend doesn't support pipes
, req_process
+ , all_available_io_managers
], compile_and_run, [''])
# Run with stdin and stdout closed -- that is what leaves those descriptors
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a0424fca10ad0f2333369de84b71aa…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a0424fca10ad0f2333369de84b71aa…
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/romes/global-break-action] 23 commits: CoreMap: look up a non-recursive let with the key order of the store
by Rodrigo Mesquita (@alt-romes) 26 Nov '26
by Rodrigo Mesquita (@alt-romes) 26 Nov '26
26 Nov '26
Rodrigo Mesquita pushed to branch wip/romes/global-break-action 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.
- - - - -
2c614766 by Rodrigo Mesquita at 2026-11-26T11:13:26+00: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
- - - - -
8fa152ed by Rodrigo Mesquita at 2026-11-26T11:13:26+00:00
Global break action which uses a per-thread context map
Previously, everytime an expression was run in the interpreter (`sandboxIO`):
1) the RTS global variable `rts_breakpoint_io_action`, which is run
anytime any thread hits a breakpoint, got set to a new action that:
a) Wrote the breakpoint hit by the thread to the `statusMVar`
b) Blocked waiting on a newly created MVar `breakMVar` for a `resumeStmt` to
signal it.
2) Start the expression evaluation on a new "sandbox" thread
3) Block waiting on `statusMVar` for a breakpoint to be hit, and we'd
return the read `EvalBreak`
4) Set the `rts_breakpoint_io_action` to a no-op which prints "Ignored breakpoint..."
At some later point, we could `resumeStmt` with the `EvalBreak` context
by signaling the `breakMVar` on which the thread that hit the breakpoint
is blocked.
However, if you consider an expression which forks off threads which hit
breakpoints, surprising things may happen:
main = do
-- the `worker` code has a breakpoint
mapM (forkIO . worker) [1..10]
forever $ threadDelay 10000000
Interpreting this program, we'll do (1,2,3), and all workers will hit
their breakpoint and run `rts_breakpoint_io_action`. Here's a first
issue:
1. The first worker succeeds in `putMVar statusMVar`
2. The interpreter will read `takeMVar statusMVar` (3) and then (4)
3. The remaining workers are hitting the breakpoint concurrently:
- Some may block trying to `putMVar statusMVar`
- Some may run the no-op action which discards the breakpoint
Depending on whether the remaining workers hit the breakpoint or (4)
happens first, some workers will skip their breakpoint.
Now, let's pretend all workers can block on `putMVar statusMVar`. Since
the interpreter will take the breakpoints one by one, and resume them
one by one, it seemingly works. However, that's only fine when we assume
only one expression is evaluated at once. As soon as multiple
expressions can be evaluated at once (a desireable property of a
debugger, as well as something that can already happen today in some
scenarios (see `break049`)), it becomes madness:
The second issue comes the global break action being swapped by a second
evaluation and threads from the first evaluation running the "wrong" action.
Consider:
1. eval `expr_A` installs a break action that puts on `statusMVar_A`
2. `expr_A` forks off a few threads, they're running in the background
3. eval `expr_B` sets the break action to put on `statusMVar_B`
4. the `expr_A` forked threads hit a breakpoint and put `statusMVar_B`
5. `expr_B` returns with a breakpoint of `expr_A`, `resume expr_B` would
resume `expr_A`, etc...
A third issue with having a single MVar for all threads of an execution
is that there is no way to have fine-grained control over which threads
are resumed and which are stopped. This is often necessary to debug
multi-threaded programs too.
Therefore, it is imperative that the global break action does not
capture a global single MVar when many expressions with many
corresponding threads can be running in the interpreter/debugger at
once, if we want to support debugging multi-threaded programs at all.
---
This commit fixes these foundational issues by making the global break
action truly global (i.e. never modified and never capturing any locals).
The global break action is installed once in `sandboxIO` and never
removed (`withBreakAciton` and `noBreakAction` were killed). Subsequent
runs of `sandboxIO` re-rewrite the same break action (a no-op).
When any thread hits the global break action, it looks its `ThreadId` up
in the global per-thread context mapping, returning a `ResumeContext`
which contains that thread's `breakMVar` (now `resumeBreakVar`) and
`statusMVar` (now `resumeEvalStatus`). Each thread blocks on its own
MVar and replies on its own TVar. There is no longer one global status
nor break MVar.
To resume a thread by its `ThreadId`, we can simply fetch its
`ResumeContext` and signal the corresponding `resumeBreakMVar`
To wait for a result or for a breakpoint in a specific thread, we do
`readThreadEvalStatus`. To wait for any breakpoint hit in any thread at
all, we have `readAnyThreadEvalBreak`.
Some evaluations will only care to look at their own result and breaks
(so they run with `readAllBreaks` `= False`); and the main thread of an
evaluation should not be read by other evaluations. In short, only
threads forked off by the main thread of evaluations get read with
`readAnyThreadEvalBreak`. If two evaluations fork off threads in the
background, `readAnyThreadEvalBreak` may return threads from any of
them. There is no just way to distinguish their "parents" at runtime.
For instance, `compileParsedExprRemote` should run an expression until
completion without any existing threads interfering with its execution,
so it runs with `readAllBreaks = False`. Otherwise, by default, running
`main` on the REPL, we'll want to stop at any break any forked thread
hits, just like we did before.
P.S. Currently, we need to keep track of the "main expression thread"
being currently evaluated to fetch its result, but, when `evalStmt`
becomes asynchronous by returning the `ThreadId` of the "sandbox"
thread, the whole `evaluationMainThreadGlobalVar` hack can be deleted.
---
New tests observing behavior that we don't want to break (which I broke
at some point while developing this patch):
- break032: we don't stop at breakpoints in TH
- break033: :continue after -fbreak-on-exception doesn't hit exception breakpoint
- break034: test :abandon doesn't hang with -fbreak-on-error
- conc033: also run with the external interpreter
- ForceInterrupt(Ext): ^C during :force interrupts the forced expression
- break043: :continue of a forked thread reads main thread breaks/results too
- break046: evaluating expr while stopped doesn't change what :continue resumes
- break048: evaluating expr while forked thread is stopped doesn't hit again current breakpoint
New tests that failed before this commit:
- T3171(ext)nosandbox: T3171 with -fno-ghci-sandbox (T3171extnosandbox still fails)
- break050(ext): ^C during :continue of a forked thread interrupts that thread
Fixed ext-interp bc. resumeStmt now does unsafeUnmask, just like
sandboxIO, so the UserInterrupt reaches the resume.
- break049: breakpoints in forked threads don't get mixed up with other evaluations
This test demonstrates one way multi-threaded debugging can go wrong
bc the global break action used to capture a break MVar for a
specific thread that is shared by all threads (described above as
"the second issue"). Here is the annotated execution of the test
*before this commit*:
```haskell
ghci> main
Stopped in Main.inMain, break049.hs:30:12-18
_result :: IO () = _
[break049.hs:30:12-18] ghci> :force slow
-- ANN: the breakpoint we're ignoring on :force is the worker's
-- breakpoint, and it's just discarded
*** Ignoring breakpoint [break049.hs:27:14-20]
slow = 5
[break049.hs:30:12-18] ghci> :cmd return ""
-- ANN: we :continue `main`, but the worker should still be blocked
-- so `main` should block.
[break049.hs:30:12-18] ghci> :continue
-- ANN: however, it completes; recall the worker break was ignored
-- instead of stopping there
main done
-- ANN: after this commit, the worker break wouldn't have been read
-- by `:force`, and we'd see it when resuming `:main`, and
-- `:continue` here would resume the worker and only then main would
-- complete.
ghci> :continue
-- ANN: bc this is ghci before the commit, we see:
not stopped at a breakpoint
ghci>
```
- break042: main forks workers and all workers hit a breakpoint
This test witnesses "the first issue" described above, where the
workers hit breaks after the global break action was already removed
and so are lost.
Fixes #28124
- - - - -
206 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/27892
- + changelog.d/28124
- + 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/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.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.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/Runtime/Eval.hs
- compiler/GHC/Runtime/Eval/Types.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/C.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- + distrib/configure.ac
- docs/users_guide/make-depends-json-schema-1_0.json
- docs/users_guide/separate_compilation.rst
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Run.hs
- + libraries/ghci/GHCi/Run/Breakpoints.hs
- libraries/ghci/ghci.cabal.in
- rts/Interpreter.c
- 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/concurrent/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/ghci.debugger/scripts/Makefile
- testsuite/tests/ghci.debugger/scripts/T14690.stdout
- testsuite/tests/ghci.debugger/scripts/all.T
- testsuite/tests/ghci.debugger/scripts/break024.stdout
- + testsuite/tests/ghci.debugger/scripts/break032.hs
- + testsuite/tests/ghci.debugger/scripts/break032.script
- + testsuite/tests/ghci.debugger/scripts/break032.stdout
- + testsuite/tests/ghci.debugger/scripts/break033.hs
- + testsuite/tests/ghci.debugger/scripts/break033.script
- + testsuite/tests/ghci.debugger/scripts/break033.stdout
- + testsuite/tests/ghci.debugger/scripts/break034.hs
- + testsuite/tests/ghci.debugger/scripts/break034.script
- + testsuite/tests/ghci.debugger/scripts/break034.stdout
- + testsuite/tests/ghci.debugger/scripts/break042.hs
- + testsuite/tests/ghci.debugger/scripts/break042.script
- + testsuite/tests/ghci.debugger/scripts/break042.stderr
- + testsuite/tests/ghci.debugger/scripts/break042.stdout
- + testsuite/tests/ghci.debugger/scripts/break043.hs
- + testsuite/tests/ghci.debugger/scripts/break043.script
- + testsuite/tests/ghci.debugger/scripts/break043.stdout
- + testsuite/tests/ghci.debugger/scripts/break046.hs
- + testsuite/tests/ghci.debugger/scripts/break046.script
- + testsuite/tests/ghci.debugger/scripts/break046.stdout
- + testsuite/tests/ghci.debugger/scripts/break048.hs
- + testsuite/tests/ghci.debugger/scripts/break048.script
- + testsuite/tests/ghci.debugger/scripts/break048.stdout
- + testsuite/tests/ghci.debugger/scripts/break049.hs
- + testsuite/tests/ghci.debugger/scripts/break049.script
- + testsuite/tests/ghci.debugger/scripts/break049.stdout
- + testsuite/tests/ghci.debugger/scripts/break050.hs
- + testsuite/tests/ghci.debugger/scripts/break050.script
- + testsuite/tests/ghci.debugger/scripts/break050.stdout
- + testsuite/tests/ghci.debugger/scripts/break050ext.stdout
- + testsuite/tests/ghci/should_run/ForceInterrupt.script
- + testsuite/tests/ghci/should_run/ForceInterrupt.stdout
- + testsuite/tests/ghci/should_run/ForceInterruptExt.stdout
- testsuite/tests/ghci/should_run/Makefile
- testsuite/tests/ghci/should_run/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/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/3d92ebe4b1bdfcbc09f382d951a423…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3d92ebe4b1bdfcbc09f382d951a423…
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/T28171] rts/nonmoving: fix wakeBlockingQueue missing update remembered set push
by Teo Camarasu (@teo) 26 Nov '26
by Teo Camarasu (@teo) 26 Nov '26
26 Nov '26
Teo Camarasu pushed to branch wip/T28171 at Glasgow Haskell Compiler / GHC
Commits:
c9ac9ddb by Teo Camarasu at 2026-11-26T10:38:37+00:00
rts/nonmoving: fix wakeBlockingQueue missing update remembered set push
When we wake up a blocking queue, we replace the blocking queue with an
indirection.
An indirection has fewer fields than a blocking queue, so we are, in
essence, overwriting some fields with NULL. Thus they need to be pushed
to the update remembered set.
The test shows that this is observable. We can have a situation where a
thread is ONLY being kept alive by being on a blocking queue. If the
nonmoving mark can't see it there then it will be GC'd overly eagerly
and we will get a NonTermination exception when it gets cleaned up.
We also push the other fields to the update remembered set to enforce
the invariant, but I'm not sure if those will ever cause issues in the
same way.
Resolves #28171
- - - - -
5 changed files:
- + changelog.d/T28171
- rts/Threads.c
- + testsuite/tests/rts/T28171.hs
- + testsuite/tests/rts/T28171.stdout
- testsuite/tests/rts/all.T
Changes:
=====================================
changelog.d/T28171
=====================================
@@ -0,0 +1,8 @@
+section: rts
+synopsis: Fix the nonmoving GC sending spurious NonTermination exceptions
+description:
+ We fix the nonmoving GC's logic for waking up threads blocked on a thunk, which had
+ a bug leading to threads being falsely being GC'd too soon.
+ This could lead to spurious NonTermination exceptions.
+mrs: !17050
+issues: #28171
=====================================
rts/Threads.c
=====================================
@@ -440,9 +440,19 @@ wakeBlockingQueue(Capability *cap, StgBlockingQueue *bq)
if (i != &stg_IND_info) {
ASSERT(i == &stg_MSG_BLACKHOLE_info);
tryWakeupThread(cap,msg->tso);
+
}
}
+ // Changing the closure type to IND makes these fields inaccessible,
+ // so we need to push them to the update remembered set.
+ // See Note [Update remembered set] in rts/sm/NonMovingMark.c
+ IF_NONMOVING_WRITE_BARRIER_ENABLED {
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->bh);
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->owner);
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->queue);
+ }
+
// overwrite the BQ with an indirection so it will be
// collected at the next GC.
OVERWRITE_INFO(bq, &stg_IND_info);
=====================================
testsuite/tests/rts/T28171.hs
=====================================
@@ -0,0 +1,32 @@
+import Control.Concurrent
+import Control.Concurrent.MVar
+import Control.Exception
+import Control.Monad
+import System.Mem
+import System.IO.Unsafe
+
+main :: IO ()
+main = do
+ forM_ [1 .. 1000] $ \r -> do
+ -- Create a thunk that will never finish evaluating
+ let t = unsafePerformIO (threadDelay (100000000000 + r))
+ -- Begin nonmoving GC
+ performMajorGC
+ performMajorGC
+ x <- newEmptyMVar
+ y <- newEmptyMVar
+ -- we start evaluating it on two threads in parallel
+ k <- forkIO (putMVar x () >> void (evaluate t))
+ performMajorGC
+ -- The second thread gets added to the waking queue
+ _ <- forkIO (putMVar y () >> void (evaluate t))
+ takeMVar x
+ takeMVar y
+ -- We kill the original thread.
+ -- And now wake up the other threads.
+ -- We need to ensure that the nonmoving GC can see that thread.
+ -- Otherwise we will get a NonTermination exception
+ killThread k
+ performMajorGC
+ performMajorGC
+ putStrLn "done"
=====================================
testsuite/tests/rts/T28171.stdout
=====================================
@@ -0,0 +1 @@
+done
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -807,3 +807,9 @@ test('T27376',
only_ways(['nonmoving_thr', 'nonmoving_thr_sanity']),
extra_run_opts('+RTS -A2m -RTS') ],
compile_and_run, ['-O2'])
+
+test('T28171',
+ [ req_target_smp,
+ extra_ways(['nonmoving_thr', 'nonmoving_thr_sanity']),
+ only_ways(['nonmoving_thr', 'nonmoving_thr_sanity'])],
+ compile_and_run, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c9ac9ddb655b3146dff9ec86873e07d…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c9ac9ddb655b3146dff9ec86873e07d…
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/dcoutts/posix-cond-vars] 36 commits: NCG: List each destination of a jump table once
by Duncan Coutts (@dcoutts) 26 Nov '26
by Duncan Coutts (@dcoutts) 26 Nov '26
26 Nov '26
Duncan Coutts pushed to branch wip/dcoutts/posix-cond-vars at Glasgow Haskell Compiler / GHC
Commits:
01a5b0ac by Sylvain Henry at 2026-11-22T16:35:34-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
e4498112 by Andreas Klebinger at 2026-11-22T16:35:34-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
f59fb957 by Sylvain Henry at 2026-11-22T16:35:34-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
2091b89a by fendor at 2026-11-22T16:36:17-05:00
`ghc -M`: Add support for link nodes to json output
`LinkNode`s are part of the module graph and indicate that a certain
linking artefact is to be produced from other module graph nodes.
We expose `LinkNode`s in the output of `ghc -M -dep-json`, allowing
consumers to see when a linking artefact is to be produced.
Only the JSON output format of `ghc -M` supports `LinkNode` as it is
unclear how the Makefile output should be retrofitted to express the
dependencies, and whether it would require a feature guard.
Closes #28007
- - - - -
cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
06e71ddf by Simon Peyton Jones at 2026-11-22T16:37:40-05:00
Better desugaring for bang patterns
Ticket #27862 showed that we were desugaring bang patterns in a
silly way, which led to bad code. This small fix makes it much
better.
I ended up refactoring `decomposeFirstPat` to be of type
(LPat -> LPat) instead of (Pat -> Pat)
which made it much easier to keep the locations correct.
On the way I also fixed #28137, a missing warning.
See Note [Tidying patterns] which has new (TP1) and (TP2)
and Note [Grouping equations] especially (GE1)
- - - - -
cd6c2a96 by Simon Jakobi at 2026-11-22T16:38:23-05:00
Cmm: drop eliminated blocks from the graph in CBE
Previously, common block elimination only made the eliminated blocks
unreachable. They stayed in the graph until stack layout discarded
them.
Removing these blocks right away reduces the potential for confusion
(e.g. #27368). It does not appear to make any significant difference
to compiler allocations.
Assisted-by: Claude Opus 5.5
- - - - -
c0764c69 by Hannes Siebenhandl at 2026-11-22T16:39:04-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
242f8daf by Alan Zimmerman at 2026-11-22T16:39:46-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
1e568190 by David Eichmann at 2026-11-22T16:40:28-05:00
Fix race condition in IOManager test
- - - - -
64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00
Fix a zonking bug
As #28135 showed, we were failing to zonk some type-variable
binders before doing scoped-sort dependency analysis, resulting
in chaos.
The fix is easy.
- - - - -
ed5124b3 by mangoiv at 2026-11-22T16:41:50-05:00
ci: nightly push can run on any arch
- - - - -
1340d255 by ARATA Mizuki at 2026-11-23T20:13:03-05:00
rts: Fix unwinding information for StgRun
The unwinding rule for rsp updated in a5ec467ee3d4e77c026437a545981269acde3434
was wrong. It gave the value of rsp _after_ the call instruction (i.e.
on entry to StgRun), whereas it should give the value _before_ the call
instruction (i.e. the caller's rsp).
Fixes #27637
- - - - -
56bb91d9 by Alan Zimmerman at 2026-11-23T20:13:44-05:00
EPA: Replace AnnListLayout / AnnListBrackets with EpLayout
We have harmonised the use of `AnnListLayout` and `AnnListBrackets` to
be equivalent to `EpLayout`.
We now take the final step, and remove them completely in favour of
`EpLayout`.
The change looks bigger than it is, because a lot of golden test
output gets updated.
- - - - -
6c648418 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Make clock_gettime required on posix platforms
It was defined in POSIX.1-2001 and has been manditory since
POSIX.1-2008. We will rely on CLOCK_MONOTONIC for the RTS-internal
monotonic time source.
On macOS it has been available since 10.12 released in 2016 (and EOL
2019). We already have 11.0 as our minimum version for which we build
binaries (MACOSX_DEPLOYMENT_TARGET=11.0).
Also we must now drop the workaround from #12858 that would make the CI
configuration invoke configure in a way that would always fail to detect
clock_gettime (since obviously now we must detect it). Re-generate the
gitlab jobs files for the benefit of CI.
- - - - -
15089ab3 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Simplify time code based on assuming defined(HAVE_CLOCK_GETTIME)
No need to fall back to gettimeofday or times
- - - - -
3af0e05e by Duncan Coutts at 2026-11-26T09:34:03+00:00
Use clock_gettime CLOCK_REALTIME for getUnixEpochTime
- - - - -
e7a633c4 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Simplify getCurrentThreadCPUTime to use clock_gettime
except on Solaris where it doesn't work.
In particular, this means we now use it on macOS. It apparently works
there from 10.12 onwards.
We drop the check for clock_getcpuclockid which is linux-specific,
archaic, and in any case isn't necessarily fatal.
- - - - -
fadaf01a by Duncan Coutts at 2026-11-26T09:34:03+00:00
Remove now-redundant darwin time code
- - - - -
59b3e667 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Simplify getProcessCPUTime to use clock_gettime CLOCK_PROCESS_CPUTIME_ID
It would be nice to check during startup using sysconf that this is
really available. Unfortunately this doesn't actually work on macOS: it
reports via sysconf that it is not available, when actually it is.
Great.
- - - - -
4a29464f by Duncan Coutts at 2026-11-26T09:34:03+00:00
Tidy up posix time headers in various places
Also remove the definition of CLOCK_ID in HsBase.h, where CLOCK_ID does
not appear to be used at all. And we're going to tweak the clock
definitions soon so we don't want these parallel definitions getting
out of sync.
- - - - -
85f219c7 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Split getPageFaults out into OSStats.{h,c}
Strictly speaking it never had any business living with the time
functions. It was merely convenience. Moving it out allows the remainder
to use PosixSource.h (at least on posix).
- - - - -
ed86f8a2 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Move getProcessTimes to its only use site
Historically getProcessTimes made sense, since the main way to get the
elapsed time would also get the cpu time as well. After recent time code
simplification on posix then in all platforms it is just the pair of
getProcessCPUTime and getProcessElapsedTime separarely. So we can remove
three identical implementations and move it to be a local function in
Stats.c where it is used.
- - - - -
c90c7905 by Duncan Coutts at 2026-11-26T09:34:03+00:00
Make the "get the time" functions more consistent
We had:
Time getProcessElapsedTime(void); // pulbic
StgWord64 getMonotonicNSec(void); // public
void getUnixEpochTime(StgWord64 *sec, StgWord32 *nsec); // internal
These don't follow any naming convention, nor any common type
convention.
Now we have:
Time getMonotonicTime(void); // internal
Time getWallClockTime(void); // internal
StgWord64 getMonotonicNSec(void); // public compat alias
Time getProcessElapsedTime(void); // public compat alias
Now the two main ones use a common representation: Time which is int64_t
nanoseconds since the epoch. And their names better reflect that they
use different clocks: a monotonic clock, or a real time / wall clock.
We keep getMonotonicNSec and getProcessElapsedTime as aliases for
getMonotonicTime(). They are still used in ghc-internal.
Future directions: export the new ones from ghc-internal and base, and
provide clock precision functions. Provide more clocks, like coarse
ones: faster but less precise.
- - - - -
cd5ded58 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Improve win32 implementation of getMonotonicNSec
We don't need the fallback GetTickCount method.
Fixes #14233
- - - - -
6398ae00 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Improve win32 implementation of getUnixEpochTime
We can now use GetSystemTimePreciseAsFileTime, which is supported from
Windows 8 onwards. This is the recommendation from MS.
- - - - -
0372f600 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Remove initializeTimer
It is now a no-op on all platforms.
- - - - -
11181865 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Refine the meaning of the main monotonic clock and add a high-res clock
We now define the monotonic clock to prioritise accuracy, and to be
steady: which implies it must count time while the system is suspended.
In particular this means that on Linux we must use CLOCK_BOOTTIME.
Since different use cases want different trade-offs (where such
trade-offs are necessary on some platforms) we also add support for a
high resolution clock. This is defined to be as precise as possible, but
not necessarily steady or accurate over long timer periods. This is the
appropriate choice for measuring the time of short-running actions. We
don't get use this one, but will do in susbequent changes.
- - - - -
23cc892e by Duncan Coutts at 2026-11-26T09:40:00+00:00
Switch some RTS uses from getMonotonicTime to getHighResolutionTime
Wherever we want to measure the duration of relatively short time
intervals then we want getHighResolutionTime rather than
getMonotonicTime. In particular this is appropriate for RTS stats,
profiling and the eventlog timestamps.
In practice this is hardly a change in behaviour compared to the prior
implementation of getMonotonicNSec/getProcessElapsedTime. On Linux and
FreeBSD it used CLOCK_MONOTONIC, and still does (or the more-or-less
equivalent CLOCK_BOOTTIME on Linux). On macOS it used the low-level
mach_absolute_time and now uses the equivalent CLOCK_UPTIME_RAW for
getHighResolutionTime. While on Windows getHighResolutionTime uses
QueryPerformanceCounter, the same as previously.
- - - - -
979bb3a4 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Add support for macOS non-standard clock_gettime_nsec_np
It's a way to get what we want with fewer conversions, so plausibly
faster.
- - - - -
f9f1227d by Duncan Coutts at 2026-11-26T09:40:00+00:00
Remove unused rtsSleep utility
- - - - -
01ca4f22 by Duncan Coutts at 2026-11-26T09:40:00+00:00
Add a changelog entry for the clock_gettime changes
- - - - -
b17be13d by Duncan Coutts at 2026-11-26T09:42:11+00:00
Rename timedWaitCondition to waitConditionTimedRelative
We will add an absolute variant, at least for posix.
- - - - -
26b28309 by Duncan Coutts at 2026-11-26T09:42:11+00:00
Improve waitConditionTimedRelative
We really want to use the monotonic clock, to avoid discontinuities due
to the real time clock, but support for the monotonic clock for cond var
timed waits is patchy. There are newer posix functions that provide it,
but many platforms don't support these yet and have some of their own
non-standard extensions.
Furthermore, the existing timed wait code is pretty unpleasent: it uses
both a static and a dynamic test to try to use a monotonic clock, but if
either test fails then it falls back to a realtime clock. This is ok ish
for implementing relative timeouts, but we will also want to support
absolute timeouts (in the monotonic clock). Fortunately the static test
can go because we now require clock_gettime unconditionally. The dynamic
test is weird: it presumes the existence of platforms supporting
pthread_condattr_setclock but not supporting CLOCK_MONOTONIC. There do
not appear to be any such platforms (which is unsurprising since
clock_gettime predates pthread_condattr_setclock).
- - - - -
07583214 by Duncan Coutts at 2026-11-26T09:42:11+00:00
Add waitConditionTimedAbsolute for posix platforms
We add support for a waitConditionTimedAbsolute using an absolute
timeout using the monotonic clock. This will be useful later for
flexible timers, where the timeout is most naturally expressed as an
absolute (monotonic) time.
We don't currently provide this for Win32 because we do not need it for
flexible timers there: win32 uses a different timer implementation
entirely.
If more portable use cases arise, we could provide this on win32 but it
would have to do some time conversions to implement it in terms of a
relative-time timed wait (with only millisecond precision).
- - - - -
0f246338 by Duncan Coutts at 2026-11-26T09:42:11+00:00
Remove wrong initialiser INIT_COND_VAR, and add MUTEX_STATIC_INIT
INIT_COND_VAR was a static initialiser for condition variables. It had a
bogus implementation on Windows (though it could have a correct one,
namely CONDITION_VARIABLE_INIT). On posix, although
PTHREAD_COND_INITIALIZER exists, our own Condition abstraction relies
sometimes on setting attributes, which cannot be done statically (in a
portable way).
INIT_COND_VAR was also unused, so removing it is easy.
Add MUTEX_STATIC_INIT which is a (hopefully) correct portable static
initialiser for mutexes. This is convenient to avoid initSubsystemFoo
calls that do nothing but initialise mutexes.
- - - - -
155 changed files:
- .gitlab-ci.yml
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- + changelog.d/27694
- + changelog.d/T27137
- + changelog.d/T27637
- + changelog.d/T27862
- + changelog.d/T28135
- + changelog.d/clock_gettime
- + changelog.d/make-depends-link-nodes
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.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/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- + distrib/configure.ac
- docs/users_guide/make-depends-json-schema-1_0.json
- libraries/ghc-internal/include/HsBase.h
- m4/fp_check_pthreads.m4
- + rts/GetTime.c
- rts/GetTime.h
- + rts/OSStats.h
- rts/RtsStartup.c
- rts/RtsUtils.c
- rts/Stats.c
- rts/StgCRun.c
- rts/configure.ac
- rts/eventlog/EventLog.c
- rts/include/rts/GetTime.h
- rts/include/rts/OSThreads.h
- rts/include/rts/Time.h
- rts/posix/Clock.h
- rts/posix/GetTime.c
- + rts/posix/OSStats.c
- rts/posix/OSThreads.c
- + rts/posix/OSThreads.h
- rts/posix/Poll.c
- rts/posix/Select.c
- rts/posix/SelectBis.c
- rts/posix/Ticker.c
- rts/posix/Timeout.c
- rts/rts.cabal
- rts/sm/GC.c
- rts/wasm/GetTime.c
- + rts/wasm/OSStats.c
- rts/win32/GetTime.c
- + rts/win32/OSStats.c
- rts/win32/OSThreads.c
- testsuite/tests/ado/T22483.stderr
- + testsuite/tests/codeGen/should_compile/T27694.hs
- + testsuite/tests/codeGen/should_compile/T27694c.hs
- + testsuite/tests/codeGen/should_compile/T27694d.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_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_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/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/TimeoutQueue.c
- testsuite/tests/rts/all.T
- testsuite/tests/rts/symbols/rts-check-symbols.stdout
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/tcfail203a.stderr
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ba943922650eb4a2c1122a96158ef9…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ba943922650eb4a2c1122a96158ef9…
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/dcoutts/signals-cleanup] 70 commits: NCG: List each destination of a jump table once
by Duncan Coutts (@dcoutts) 26 Nov '26
by Duncan Coutts (@dcoutts) 26 Nov '26
26 Nov '26
Duncan Coutts pushed to branch wip/dcoutts/signals-cleanup at Glasgow Haskell Compiler / GHC
Commits:
01a5b0ac by Sylvain Henry at 2026-11-22T16:35:34-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
e4498112 by Andreas Klebinger at 2026-11-22T16:35:34-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
f59fb957 by Sylvain Henry at 2026-11-22T16:35:34-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
2091b89a by fendor at 2026-11-22T16:36:17-05:00
`ghc -M`: Add support for link nodes to json output
`LinkNode`s are part of the module graph and indicate that a certain
linking artefact is to be produced from other module graph nodes.
We expose `LinkNode`s in the output of `ghc -M -dep-json`, allowing
consumers to see when a linking artefact is to be produced.
Only the JSON output format of `ghc -M` supports `LinkNode` as it is
unclear how the Makefile output should be retrofitted to express the
dependencies, and whether it would require a feature guard.
Closes #28007
- - - - -
cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
06e71ddf by Simon Peyton Jones at 2026-11-22T16:37:40-05:00
Better desugaring for bang patterns
Ticket #27862 showed that we were desugaring bang patterns in a
silly way, which led to bad code. This small fix makes it much
better.
I ended up refactoring `decomposeFirstPat` to be of type
(LPat -> LPat) instead of (Pat -> Pat)
which made it much easier to keep the locations correct.
On the way I also fixed #28137, a missing warning.
See Note [Tidying patterns] which has new (TP1) and (TP2)
and Note [Grouping equations] especially (GE1)
- - - - -
cd6c2a96 by Simon Jakobi at 2026-11-22T16:38:23-05:00
Cmm: drop eliminated blocks from the graph in CBE
Previously, common block elimination only made the eliminated blocks
unreachable. They stayed in the graph until stack layout discarded
them.
Removing these blocks right away reduces the potential for confusion
(e.g. #27368). It does not appear to make any significant difference
to compiler allocations.
Assisted-by: Claude Opus 5.5
- - - - -
c0764c69 by Hannes Siebenhandl at 2026-11-22T16:39:04-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
242f8daf by Alan Zimmerman at 2026-11-22T16:39:46-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
1e568190 by David Eichmann at 2026-11-22T16:40:28-05:00
Fix race condition in IOManager test
- - - - -
64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00
Fix a zonking bug
As #28135 showed, we were failing to zonk some type-variable
binders before doing scoped-sort dependency analysis, resulting
in chaos.
The fix is easy.
- - - - -
ed5124b3 by mangoiv at 2026-11-22T16:41:50-05:00
ci: nightly push can run on any arch
- - - - -
1340d255 by ARATA Mizuki at 2026-11-23T20:13:03-05:00
rts: Fix unwinding information for StgRun
The unwinding rule for rsp updated in a5ec467ee3d4e77c026437a545981269acde3434
was wrong. It gave the value of rsp _after_ the call instruction (i.e.
on entry to StgRun), whereas it should give the value _before_ the call
instruction (i.e. the caller's rsp).
Fixes #27637
- - - - -
56bb91d9 by Alan Zimmerman at 2026-11-23T20:13:44-05:00
EPA: Replace AnnListLayout / AnnListBrackets with EpLayout
We have harmonised the use of `AnnListLayout` and `AnnListBrackets` to
be equivalent to `EpLayout`.
We now take the final step, and remove them completely in favour of
`EpLayout`.
The change looks bigger than it is, because a lot of golden test
output gets updated.
- - - - -
dcf23d36 by Duncan Coutts at 2026-11-24T13:15:41+00: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.
- - - - -
3e459ac5 by Duncan Coutts at 2026-11-24T13:15:41+00: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.
- - - - -
0e02d4d6 by Duncan Coutts at 2026-11-24T13:15:41+00: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.
- - - - -
a296562f by Duncan Coutts at 2026-11-24T13:15:41+00: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.
- - - - -
bb787e0d by Duncan Coutts at 2026-11-24T13:15:42+00: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.
- - - - -
0921a9a7 by Duncan Coutts at 2026-11-24T13:16:53+00:00
Remove variable n_haskell_handlers which has become write-only
The previous commit removed the last read of this variable.
- - - - -
9d86f6a6 by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
e921f47d by Duncan Coutts at 2026-11-24T13:17:13+00:00
FIXUP review finding f1
- - - - -
d135013f by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
bfc7e703 by Duncan Coutts at 2026-11-24T13:17:13+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
- - - - -
6bbf2907 by Duncan Coutts at 2026-11-24T13:17:13+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
- - - - -
3d23c3df by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
45a9c56a by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
34aa6b61 by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
910bdef6 by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
6325298d by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
4183fd7f by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
f422ab1e by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
5290214e by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
bea382f8 by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
a9308aae by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
a5df9d5c by Duncan Coutts at 2026-11-24T13:17:13+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.
- - - - -
6b9c9c46 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
95fdb942 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
e746472c by Duncan Coutts at 2026-11-26T00:22:08+00:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
12c563d7 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
8970c37d by Duncan Coutts at 2026-11-26T00:22:08+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
- - - - -
7e261111 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
66742bd0 by Duncan Coutts at 2026-11-26T09:22:57+00:00
Remove use of (un)blockUserSignals in GC
Once upon a time, prior to 7ed3f7556f46b957f7efb97ed7ebdc92db2f8ab7 in
2009, the signal handlers were stored within the RTS as a table of
StablePtrs. This meant that the table could be accessed concurrently by
the C signal handler (picking out a Haskell signal handler when the
signal was delivered) and by the GC when it looks at the stable
pointers. To avoid problems, the relevant signals were masked around
this critical section in the GC.
The use of blockUserSignals/unblockUserSignals in the GC was missed
when the scheme was rewritten. We can safely remove it now. The GC no
longer has anything to do with the data structures within the RTS used
for signals.
This probably fixes #10686, by avoiding using blockUserSignals in the
GC, but the proper fix is later.
- - - - -
0613bf7d by Duncan Coutts at 2026-11-26T09:22:57+00:00
Change sigprocmask to pthread_sigmask in a couple places in the rts
This is part of a series of changes to fix or remove uses of
sigprocmask. See issue #27968.
According to Posix:
> The use of the sigprocmask() function is unspecified in a
> multi-threaded process.
and indeed it does different things on different platforms. In
particular on macOS the behaviour is to change the signal mask for every
thread in the process (there is no per-process mask, it changes the
per-thread mask for every thread). This obviously does not mix well with
other concurrent changes to signal masks in other threads.
The use of sigprocmask in exitBySignal just needs to unmask a signal in
the current OS thread so that it can send a signal to itself. This
purpose only requires changing the signal mask of the calling thread,
which is exactly what pthread_sigmask is specified to do.
In resetTerminalSettings, sigprocmask (now pthread_sigmask) is used in
an attempt to mask a signal. It is unclear if this is effective. It
depends on whether there are any remaining threads running by the time
the function is called during shutdown.
Add a Note [pthread_sigmask and the ineffectiveness of masking signals]
and refer to it.
- - - - -
3a7ba65f by Duncan Coutts at 2026-11-26T09:22:57+00:00
Change (un)blockUserSignals to use pthread_sigmask, not sigprocmask
These functions are exported from the RTS (on posix platforms). They are
used in the process library to temporarily mask signals during a fork().
This is only needed to ensure the new process has the signals masked
initially. So in particular for this use case we want it to only affect
the signal mask of the calling thread. Thus pthread_sigmask is
appropriate.
This probably fixes #10686. It should mean that there's no interaction
between threads that create new processes (which manipulate the signal
mask) and GC (which no longer uses blockUserSignals), or multiple
OS threads that create processes concurrently, because now they only
manipulate their local thread's signal mask.
- - - - -
28166cfc by Duncan Coutts at 2026-11-26T09:22:58+00:00
Make (un)blockUserSignals local functions in win32 console handling
These functions were defined for all platforms in the RTS public
headers but only exported from the RTS on non-win32 platforms. They are
only used externally (by the process library) on posix platforms.
So for win32, break the link with the exported names and use local only
C static functions. They do serve a local purpose, but are now unrelated
to the posix ones.
- - - - -
03bfb734 by Duncan Coutts at 2026-11-26T09:22:58+00:00
In System.Posix.Internals, change import of sigprocmask to pthread_sigmask
and refer to the Note. It's still pretty dubious!
- - - - -
dfaa482b by Duncan Coutts at 2026-11-26T09:22:58+00:00
Drop use of sigprocmask in stg_sig_install
It is somewhat unclear what the signal masking was trying to protect in
stg_sig_install. The comment said
// Block the signal until we figure out what to do
There are no shared data structured between stg_sig_install and the
generic_handler that it installs.
In any case, masking signals does not in general work, so whatever it
was doing was a false sense of security.
This was the last use of sigprocmask within the RTS. This completes the
fix for #27968.
- - - - -
7a978d5f by Duncan Coutts at 2026-11-26T09:22:58+00:00
Make startPendingSignalHandlers a per-platform, not common, API
The direction of travel is that user-signal handling should be managed
by the I/O manager(s). This is because signals (& win32 console events)
are (a funny kind of) I/O, and also because they have to be involved in
noticing signals and starting signal handlers.
And how we communicate between the low level signal handler and starting
the Haskell signal handler threads is also speific to the I/O manager
implementation.
There is no need for a common API here. These are just utilities shared
between some I/O manager implementations.
- - - - -
9c865277 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Unify freeSignalHandlers and finiUserSignals in RTS shutdown
They were called at different stages of shutdown. Historically this
might have made sense when the handler mechanism used stable pointers.
Now there appears to be no good reason.
On win32, freeSignalHandlers did nothing. On posix, finiUserSignals did
nothing. There appears to be no dependency on the stage of shutdown. It
is all local resources.
- - - - -
c8d91642 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Push checks on install_signal_handlers flag into signal functions
Also, change the logic slightly. The docs for --install-signal-handlers
say that it installs handlers for ctl-c etc. It does _not_ say that it
disables the API for Haskell code to install signal handerls. Previously
however the RTS startup code would guard initUserSignals behind the flag
install_signal_handlers. All that code does is initalise variables
properly. This meant that when user code installs a handler, it would be
working with ill-defined userSignals value and an un-initialised mutex!
Similarly, in the win32 console handling, it would skip initialising the
hConsoleEvent, which certainly cannot lead to good outcomes.
So now we only guard initDefaultHandlers and resetDefaultHandlers behind
the install_signal_handlers flag.
- - - - -
d12884b2 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Fix user guide reference to --install-signal-handlers
While reviewing --install-signal-handlers docs, noticed a typo in the
--generate-crash-dumps docs that referred to --install-signal-handlers
when it means --install-seh-handlers. Yes I double-checked the code.
- - - - -
d86873da by Duncan Coutts at 2026-11-26T09:22:58+00:00
Split user signal functions out of posix/Signals into new file
The direction of travel is that user-signal handling should be managed
by the I/O manager(s).
The user signal functions (i.e. to allow Haskell code to set signal
handlers) should stop being first class functions called by the rest of
the RTS and become utilities used by the I/O managers.
Start here by splitting them out.
- - - - -
bf26eda5 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Make stg_sig_install part of the IOManager API
This is the external entry point for user code to install signal
handlers. So it becomes part of the I/O manager API. Eventually it will
dispatch to the I/O manager implementations (which will do different
things), but for now it dispatches to the same old implementation, under
a new name.
- - - - -
921517d1 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Document that nocldstop is a totally mad implicit parameter
and it's part of our public API!
- - - - -
1094843d by Duncan Coutts at 2026-11-26T09:22:58+00:00
Move user signal init and fini into the I/O manager
Initially just moved into start/stopIOManager, but a later step will be
to make that be part of the initialisation of each I/O manager.
Why? Because they cannot have a common init if they have different data
structures that need initialisation. In fact they already do have
different code and data (threaded/non-threaded, windows/other), but
this is fudged using CPP.
- - - - -
16423123 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Push {init,fini}{UserSignals,ConsoleEvents} down into I/O managers
So they become part of individual I/O managers, which will allow us to
start specialising them more sanely.
Rename the Win32 ones to {init,fini}ConsoleEvents.
- - - - -
5b92b040 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Push installUserSignalHandler down into individual I/O managers
This will allow us to specialise them.
Initally they all use the same (existing) generic_handler.
- - - - -
1bfd4ffe by Duncan Coutts at 2026-11-26T09:22:58+00:00
Specialise MIO's installing of signals
It already used a separate implementation, but using cpp via the
signal "generic_handler". Now it is much more direct and local.
MIO writes signals into a pipe and reads and dispatches them at the
other end (in Haskell).
- - - - -
dfdf16ce by Duncan Coutts at 2026-11-26T09:22:58+00:00
Introduce an I/O manager data structure shared between all caps
Accessed via iomgr->shared, but it points to the same struct for all
capabilities.
We initialise and free this with cap 0. We will use it initially for
signal handling, since only one capability needs to dispatch signals.
This is a fairly general mechanism, so I/O managers may be able to make
use of it for other purposes, especially once in-RTS ones are adapted
to work in the threaded RTS with multiple capabilities.
- - - - -
14877d40 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Use the shared I/O manager data structure for MIO for signals
Move the MIO I/O manager's timer manager control fd from a global
variable into the shared I/O manager struct.
Soon we will use the same mechanism for the same purpose of signal
handling for the other posix I/O managers.
- - - - -
243e7cf5 by Duncan Coutts at 2026-11-26T09:22:58+00:00
Extract and add more utility functions for the signal self-pipe trick
Extract a utility function writeSignalInfoToPipe from the MIO I/O
manager so we can use it in other I/O managers too.
Also add related utility functions readSignalInfoFromPipe,
newNonBlockingPipe and startSignalHandler.
We will use these in the poll and selectbis I/O managers.
- - - - -
010195bd by Duncan Coutts at 2026-11-26T09:23:31+00:00
Redo the scheme for special fds in the poll and selectbis I/O managers
At the moment we only have one special fd for these I/O managers: the
pipe (or eventfd) for interrupting them when they're sleeping. We're
about to gain a second for signal handling.
The existing scheme was rather ad-hoc and hard to extend. It was
already complicated by the fact that the interrupt fd is optional. The
signal fd will also be optional in the sense that cap 0 will have it but
cap >0 will not.
So the new scheme is that we add special aiop entries into the
aiop_table, and for the most part we can treat these uniformly with
other aiops. But the action we take for them if/when they are ready is
handled specially.
This seems much cleaner and will be easy to extend for signals.
This change allocates a small (24 byte) byte array during startup, which
peturbs the output of the census_pinned test. To fix this we update the
test to do a baseline census, and then we post-process to subtract the
baseline. This removes the sensitivity to small initial allocations that
depends on platform and I/O manager (there was already one such output
difference for windows).
- - - - -
e61dd6d2 by Duncan Coutts at 2026-11-26T09:31:30+00:00
Use the signal self-pipe trick for the poll and selectbis I/O managers
So now the low level signal handler delivers signals into a pipe that is
monitored by the I/O manager (on cap 0). The I/O manager then dispatches
the handler (starting a Haskell thread).
There are two important reasons for this change:
1. This method does not have any windows of time where signals can be
missed for arbitrary periods of time. The previous method has a race
where a signal delivered just before the I/O manager calls
poll/select will not notice the signal until some unrelated event
causes poll/select to return. See issue #27540. The new method
ensures that a fd is ready and so poll/select will notice
immediately (if the signal was delivered prior to the call to
poll/select) or later.
2. The existing method relies on temporarily masking signals for
concurrency safety which cannot work reliably in a multi-threaded
process. Fixing this is a necessary pre-requisite to enable these
in-RTS I/O managers to work in the threaded RTS. The issue is that
startPendingSignalHandlers and the low level signal handler share the
pending_handler_buf data structure, and so startPendingSignalHandlers
has to mask delivery of signals to avoid the shared data being
mutated concurrently. But masking signals in a multi-threaded process
is not generally effective because the signal can still be delivered
in any thread
Document the self-pipe trick in a Note.
This fixes issue #27540.
- - - - -
be9d8e62 by Duncan Coutts at 2026-11-26T09:31:30+00:00
Move the legacy user signal handler into legacy select I/O manager
We do not convert the legacy select I/O manager to use the self-pipe
trick. It keeps the existing code, but since it is now the only user of
it, then that code can move from being a shared utility to live with the
select I/O manager.
There are some minor modifications to the code moved so that it is not
entangled with other remaining shared signal utils.
- - - - -
c373e9e8 by Duncan Coutts at 2026-11-26T09:31:30+00:00
Deprecate (un)blockUserSignals for external RTS users
Encourage external users to stop using these actions.
- - - - -
ef89339a by Duncan Coutts at 2026-11-26T09:31:31+00:00
Split interruptStgRts and remove wakeUpRtsViaTicker.
Split the two uses of interruptStgRts into their posix and win32 cases,
and move them to their use sites.
Make the posix case not rely on wakeUpRts or wakeUpRtsViaTicker. The use
of wakeUpRtsViaTicker while it seemed to cleverly solve overly-close
coupling in one area, causes overly-close coupling in another area:
ticker(s). And we want to start improving the ticker(s) but the
existence of wakeUpRtsViaTicker holds that back.
Delete wakeUpRtsViaTicker and its related implementation pieces.
In the posix case, we add interruptIOManagerFromSignal, which is
specific for the circumstance of use within a signal handler. The
implementation of this for the in-RTS I/O managers is just
interruptIOManager but for MIO it has to wake up the timer manager
thread.
All of this seems pretty unnecessary since it is all to support a ctl-c
handler that is almost never used since it is duplicated and overridden
by a ctl-c handler installed by runMainIO. See issue #28066.
- - - - -
27f8f992 by Duncan Coutts at 2026-11-26T09:31:31+00:00
Simplify execution of signal handlers
We make a few related changes:
1. Don't use malloc/free for passing siginfo_t from C to Haskell, use
heap allocated byte arrays indead. The Haskell side already uses
ForeignPtr which can use byte array directly.
2. Don't redundantly fork IO threads for signal handlers, when invoked
from in-RTS I/O managers. The I/O manager already creates a new IO
thread, but the existing runHandlers would then redundantly forkIO
again. This is a waste of resources but also means signal handlers
end up getting scheduled last.
3. Schedule signal handler threads first.
This should fix #28067
Introduce new runHandler/runHandlerPtr to replace the existing
runHandlers/runHandlersPtr. Conveniently the old ones have a weird name
(they only invoke one handler!) so we can use a sensible name, and leave
the old ones (which are exported via base!) alone. Add deprecation
warnings though, since nobody should be using them via base.
Update the caller in ghc-internal: the MIO timer manager. This one does
need to use forkIO, but it's clearer if that forkIO is done there.
- - - - -
edd145bc by Duncan Coutts at 2026-11-26T09:31:31+00:00
Stop using signal-unsafe functions in signal handlers
Fixes #19205
Unfortunately this does mean that the SIGQUIT functionality of dumping a
stack trace has to be disabled for now. There's no short term practical
way to allow that to work. The stack trace functions all use dynamic
memory allocation using malloc/free, which is verboten in signal
handlers.
See #28071 about re-enabling the stack trace info.
- - - - -
8025ce0c by Duncan Coutts at 2026-11-26T09:31:31+00:00
Add a changelog entry for the signals changes
- - - - -
203 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/T27137
- + changelog.d/T27637
- + changelog.d/T27862
- + changelog.d/T28135
- + changelog.d/idle-gc-and-deadlock-detection
- + changelog.d/make-depends-link-nodes
- + changelog.d/signals-cleanup
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.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/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- + distrib/configure.ac
- docs/users_guide/make-depends-json-schema-1_0.json
- docs/users_guide/profiling.rst
- docs/users_guide/runtime_control.rst
- libraries/ghc-experimental/src/System/Mem/Experimental.hs
- libraries/ghc-internal/include/RtsIfaceSymbols.h
- libraries/ghc-internal/src/GHC/Internal/Conc/Signal.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Control.hs
- libraries/ghc-internal/src/GHC/Internal/Event/TimerManager.hs
- libraries/ghc-internal/src/GHC/Internal/System/Mem.hs
- libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs
- rts/Capability.c
- rts/IOManager.c
- rts/IOManager.h
- rts/IOManagerInternals.h
- + rts/IdleGC.c
- + rts/IdleGC.h
- rts/Linker.c
- rts/Prelude.h
- rts/RtsFlags.c
- rts/RtsSignals.h
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/Schedule.c
- rts/Schedule.h
- rts/StgCRun.c
- rts/Ticker.h
- rts/Timer.c
- rts/configure.ac
- rts/include/Rts.h
- rts/include/rts/BlockSignals.h
- rts/include/rts/IOInterface.h
- rts/include/rts/OSThreads.h
- rts/include/rts/PosixSource.h
- rts/include/rts/RtsToHsIface.h
- rts/include/rts/storage/Closures.h
- rts/include/rts/storage/GC.h
- rts/js/environment.js
- rts/posix/MIO.c
- rts/posix/MIO.h
- rts/posix/Poll.c
- rts/posix/Poll.h
- rts/posix/Select.c
- rts/posix/Select.h
- rts/posix/SelectBis.c
- rts/posix/SelectBis.h
- rts/posix/Signals.c
- − rts/posix/Signals.h
- rts/posix/TTY.c
- rts/posix/Ticker.c
- rts/posix/Timeout.c
- rts/posix/Timeout.h
- + rts/posix/UserSignals.c
- + rts/posix/UserSignals.h
- rts/rts.cabal
- rts/sm/GC.c
- rts/win32/AsyncMIO.c
- rts/win32/AsyncMIO.h
- rts/win32/AsyncWinIO.c
- rts/win32/AsyncWinIO.h
- rts/win32/AwaitEvent.c
- rts/win32/ConsoleHandler.c
- rts/win32/ConsoleHandler.h
- testsuite/tests/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_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/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- 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/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/profiling/should_run/Makefile
- testsuite/tests/rts/IOManager.hsc
- 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/census_pinned.hs
- testsuite/tests/rts/census_pinned.stdout-ws-32
- testsuite/tests/rts/census_pinned.stdout-ws-64
- − testsuite/tests/rts/census_pinned.stdout-ws-64-mingw32
- testsuite/tests/rts/symbols/rts-check-symbols.stdout
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/tcfail203a.stderr
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1f069d02a5b3780137f2771697caa8…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1f069d02a5b3780137f2771697caa8…
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/case-bndr-unf] 4 commits: Lambda and case binders have vanilla IdInfo (#27965)
by Simon Peyton Jones (@simonpj) 26 Nov '26
by Simon Peyton Jones (@simonpj) 26 Nov '26
26 Nov '26
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC
Commits:
c1d423a9 by Simon Peyton Jones at 2026-11-26T09:28:13+00: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>
- - - - -
643c1157 by Simon Peyton Jones at 2026-11-26T09:28:13+00: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>
- - - - -
50cb7929 by Simon Peyton Jones at 2026-11-26T09:28:13+00: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>
- - - - -
b9721943 by Simon Peyton Jones at 2026-11-26T09:28:13+00: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.
- - - - -
33 changed files:
- + changelog.d/T27962
- + changelog.d/T27963
- compiler/GHC/Builtin/WiredIn/Ids.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/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Types/Cpr.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Utils/Monad.hs
- 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/c7f08910da9d383b48286f30f7b92e…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c7f08910da9d383b48286f30f7b92e…
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] 20 commits: Use a different herald for -ddump-simpl-trace
by Marge Bot (@marge-bot) 26 Nov '26
by Marge Bot (@marge-bot) 26 Nov '26
26 Nov '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
b13482d0 by Simon Peyton Jones at 2026-11-26T02:38:27-05:00
Use a different herald for -ddump-simpl-trace
... so that we can more easily skip the high-volume ones
- - - - -
18f04ca1 by Simon Peyton Jones at 2026-11-26T02:38:27-05:00
Update comments and user manual
This commit addresses the comment-related suggestions in #27973
- - - - -
c73f2fb7 by Simon Peyton Jones at 2026-11-26T02:38: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.
- - - - -
842dd531 by Zubin Duggal at 2026-11-26T02:38:28-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.
- - - - -
4b6b5696 by Zubin Duggal at 2026-11-26T02:38:28-05:00
Identify Linkable with fingerprints of their contents rather than modtimes
- - - - -
a628d935 by Zubin Duggal at 2026-11-26T02:38:28-05:00
Linker cleanup
delete a bunch of unused functions
- - - - -
ccf20937 by Zubin Duggal at 2026-11-26T02:38:28-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.
- - - - -
1cd7855d by Zubin Duggal at 2026-11-26T02:38:28-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.
- - - - -
e22a20d2 by Zubin Duggal at 2026-11-26T02:38:28-05:00
driver: Refresh ms_bytecode_date when reusing a ModSummary
- - - - -
81f472ca by Zubin Duggal at 2026-11-26T02:38:29-05:00
bytecode: Treat persistent bytecode files with a bad header as stale
- - - - -
39b11783 by Zubin Duggal at 2026-11-26T02:38:29-05:00
bytecode: Record the inputs hash in BytecodeLib
-------------------------
Metric Increase:
MultiLayerModulesRecomp
MultiLayerModulesTH_Make
MultiLayerModulesTH_OneShot
-------------------------
- - - - -
4b9232c4 by Simon Jakobi at 2026-11-26T02:38:30-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
- - - - -
b992a8e5 by Simon Jakobi at 2026-11-26T02:38:31-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
- - - - -
0ed2d22c by Simon Jakobi at 2026-11-26T02:38:31-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
- - - - -
0b89678c by Simon Jakobi at 2026-11-26T02:38:32-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
- - - - -
e8f7ed35 by Simon Jakobi at 2026-11-26T02:38:33-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
- - - - -
d8e090d8 by Teo Camarasu at 2026-11-26T02:38:34-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.
- - - - -
b77cfa91 by Wolfgang Jeltsch at 2026-11-26T02:38:35-05:00
Switch fingerprint caches to `FastString` keys
Resolves #28139.
- - - - -
04b6a41c by mangoiv at 2026-11-26T02:38:36-05:00
ci: fix a bug where there's no runner that can pick up nightly push jobs
- - - - -
b238fd2b by Alan Zimmerman at 2026-11-26T02:38:36-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.
- - - - -
77 changed files:
- .gitlab-ci.yml
- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- + 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/Config/Core/Opt/Simplify.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Main/Compile.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/HsToCore/Usage.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/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- docs/users_guide/debug-info.rst
- docs/users_guide/using-optimisation.rst
- + 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/hpc/fork/test.T
- testsuite/tests/lib/base/all.T
- testsuite/tests/parser/should_compile/DumpSemis.hs
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- + testsuite/tests/printer/Layout.hs
- testsuite/tests/printer/Makefile
- testsuite/tests/printer/T18052a.stderr
- 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/Utils.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2a6198940f5618ffc237054b4f6327…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2a6198940f5618ffc237054b4f6327…
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
26 Nov '26
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC
Commits:
c7f08910 by Simon Peyton Jones at 2026-11-26T00:40:06+00: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.
- - - - -
10 changed files:
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Types/Cpr.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Utils/Monad.hs
- + testsuite/tests/simplCore/should_compile/T28158.hs
- + testsuite/tests/simplCore/should_compile/T28158.stderr
- testsuite/tests/simplCore/should_compile/all.T
Changes:
=====================================
compiler/GHC/Core/Opt/CprAnal.hs
=====================================
@@ -173,6 +173,25 @@ So currently we have
1. Strictness
2. CPR
3. worker/wrapper (for strictness and CPR)
+
+Wrinkles
+
+(CPR1) We have a flag `-fcpr-anal`, which sets `Opt_CprAnal`, enabled in -O1 and
+ -O1. Strangely, it does /not/ switch off CPR analysis! Rather, it just
+ switches off the worker/wrapper exploitation of CPR analysis, in `mkWWcpr_entry`.
+ The analysis itself runes whenever `-fstrictness` is on.
+
+ This is peculiar and, I suspect accidental. It would make more sense to switch
+ off the analysis itself with `-fno-cpr-anal`.
+
+ It goes back to at least
+ commit ecb1752ffa12dfa71053f640e6cce64d15e47e8f
+ Author: Christiaan Baaij <christiaan.baaij(a)gmail.com>
+ Date: Wed Aug 5 14:22:14 2015 +0200
+
+ Make -fcpr-off a dynamic flag
+
+ This note is just a breadcrumb to inform the next person who trips over this.
-}
--
@@ -343,7 +362,7 @@ cprTransform env id args
-- Any local binding, except for data structure bindings
-- See Note [Efficient Top sigs in SigEnv]
| Just sig <- lookupSigEnv env id
- = applyCprTy (getCprSig sig) (length args)
+ = applyCprTy (cprSigType sig) (length args)
-- See Note [CPR for data structures]
| Just rhs <- cprDataStructureUnfolding_maybe id
= fst $ cprAnal env rhs
@@ -362,7 +381,7 @@ cprTransform env id args
= cprTransformDataConWork env con args
-- Imported function
| otherwise
- = applyCprTy (getCprSig (idCprSig id)) (length args)
+ = applyCprTy (cprSigType (idCprSig id)) (length args)
-- | Precise, hand-written CPR transformers for select Ids
cprTransformBespoke :: Id -> [(CprType, CoreArg)] -> Maybe CprType
@@ -870,27 +889,42 @@ Does f have the CPR property? Well, no.
However, if the strictness analyser has figured out (in a previous
iteration) that it's strict, then we DON'T need to forget the CPR info.
Instead we can retain the CPR info and do the thunk-splitting transform
-(see WorkWrap.splitThunk).
+(see Note [Thunk splitting] esp (B) CPR-led thunk splitting).
This made a big difference to PrelBase.modInt, which had something like
modInt = \ x -> let r = ... -> I# v in
...body strict in r...
-r's RHS isn't a value yet; but modInt returns r in various branches, so
-if r doesn't have the CPR property then neither does modInt
+r's RHS isn't a value yet; but `modInt` returns `r` in various branches, so
+if `r` doesn't have the CPR property then neither does `modInt`
+
Another case I found in practice (in Complex.magnitude), looks like this:
- let k = if ... then I# a else I# b
- in ... body strict in k ....
+ let k* = if ... then I# a else I# b
+ in ... body strict in k ....
(For this example, it doesn't matter whether k is returned as part of
the overall result; but it does matter that k's RHS has the CPR property.)
+
Left to itself, the simplifier will make a join point thus:
- let $j k = ...body strict in k...
- if ... then $j (I# a) else $j (I# b)
+ let $j k = ...body strict in k...
+ if ... then $j (I# a) else $j (I# b)
+
With thunk-splitting, we get instead
- let $j x = let k = I#x in ...body strict in k...
- in if ... then $j a else $j b
+ let k* = case (if ... then I# a else I# b) of I# z -> I# z
+ in ... body strict in k ....
+Now the simplifier should pull out the `case` to give
+ case (if ... then I# a else I# b) of I# z ->
+ let k = I# z in ... body strict in k ...
+Now case-of-if will give
+ let $j z = let k = I# z in ...body strict in k... in
+ if ... then $j a else $j b
This is much better; there's a good chance the I# won't get allocated.
+TL'DR: During CPR analysis we want to give `k` the CPR property in `body`.
+
+What if the type involved has more than one constructor? E.g.
+ let k* = if ... then Just a else Just b
+ in ... body strict in k ....
+That is good too: see (TS5) in Note [Thunk splitting]
-But what about botCpr? Consider
+Finally, what about botCpr? Consider
lvl = error "boom"
fac -1 = lvl
fac 0 = 1
=====================================
compiler/GHC/Core/Opt/Simplify/Iteration.hs
=====================================
@@ -51,7 +51,6 @@ import GHC.Types.Literal ( litIsLifted ) --, mkLitInt ) -- temporarily comment
import GHC.Types.SourceText
import GHC.Types.Id
import GHC.Types.Id.Info
-import GHC.Types.Cpr( isTopCprSig )
import GHC.Types.InlinePragma
import GHC.Types.Name ( mkSystemVarName, isExternalName, getOccFS )
import GHC.Types.Demand
@@ -1830,7 +1829,7 @@ simplNonRecE :: HasDebugCallStack
simplNonRecE env from_what bndr (rhs, rhs_se) body cont
| assertPpr (isId bndr && not (isJoinId bndr)) (ppr bndr) True
- , useStrictBind env from_what bndr
+ , useStrictBind env from_what bndr rhs
= -- Evaluate RHS strictly
simplExprF (rhs_se `setInScopeFromE` env) rhs
(StrictBind { sc_bndr = bndr, sc_body = body, sc_from = from_what
@@ -1865,11 +1864,10 @@ simplRecE env pairs body cont
; return (floats1 `addFloats` floats2, expr') }
-useStrictBind :: SimplEnv -> FromWhat -> InId -> Bool
+useStrictBind :: SimplEnv -> FromWhat -> InId -> InExpr -> Bool
-- Can we use a StrictBind continuation for this let-binding?
--- If so, return a binder that is suitable to become a lambda binder,
--- i.e. one satisfying `lamBndrInfoOK`; see (SB3) in Note [StrictBind]
-useStrictBind env from_what bndr
+-- See (SB3) in Note [StrictBind]
+useStrictBind env from_what bndr rhs
-- If we are coming from a beta-reduction (FromBeta) we must
-- establish the let-can-float invariant, so we must go via StrictBind
-- If not, the invariant holds already, and it's optional.
@@ -1880,6 +1878,11 @@ useStrictBind env from_what bndr
| not (isStrUsedDmd dmd_info)
= False
+ -- Not if the RHS is ok-for-spec; no benefit. In particular if the RHS is a
+ -- value lambda, we return False: only thunks use StrictBind
+ | exprOkForSpeculation rhs
+ = False
+
-- Not if case-of-case is off
-- See (SB1) in Note [StrictBind]
| not (seCaseCase env)
@@ -1889,13 +1892,8 @@ useStrictBind env from_what bndr
= True
-- Not for things with RULES or INLINE or NOINLINE
- -- or with a strictnes or CPR signature -- all things we might lose
-- See (SB3) in Note [StrictBind]
- | isStableUnfolding (unfoldingInfo info)
- || not (isEmptyRuleInfo (ruleInfo info))
- || not (isAlwaysActive (inlinePragmaActivation (inlinePragInfo info)))
- || not (isNopSig (dmdSigInfo info))
- || not (isTopCprSig (cprSigInfo info))
+ | hasRulesOrInline info
= False
| otherwise
@@ -4243,9 +4241,8 @@ mkDupableAlt _env case_bndr jfloats (Alt con alt_bndrs alt_rhs_in)
, alt') }
-- See Note [Duplicated env]
-{-
-Note [Do not add unfoldings to join points at birth]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+{- Note [Do not add unfoldings to join points at birth]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this (#15360)
case (case (case (case ...))) of
@@ -4316,7 +4313,7 @@ The simplifier will find
(Var v) with continuation
Select (pn -> rn) (
Select [I# a -> I# a] (
- StrictBind body Stop
+ StrictBind body Stop))
So we'll call mkDupableCont on
Select [I# a -> I# a] (StrictBind body Stop)
@@ -4455,7 +4452,7 @@ hack and bit us in multiple small and not-so-small ways
Consider this
case (case .. ) of c {
- I# c# -> ....c....
+ I# c# -> ....c.... }
If we make a join point with c but not c# we get
$j = \c -> ....c....
@@ -4655,30 +4652,56 @@ We simplify `rhs` with a StrictBind continuation that continues with
invariants] in GHC.Core. But a let-binder `x` usually has IdInfo that a
lambda binder may not have (an unfolding, arity, a demand signature...).
- So `useStrictBind_maybe` zaps that info, keeping only the occurrence info
- and the demand info. If it happens to stay as a let-binding arity info will
- be re-derived, so nothing is lost.
+ So when we duplicate StrictBind, in `mkDupableContWithDmds`, we use
+ `mkLamBndrFromLetBndr` to zap that info, keeping only the occurrence
+ info and the demand info.
- The exceptions are RULES, a stable unfolding, and a non-default inlining
- activation: these cannot be re-derived, and we have nowhere convenient to
- put them if `x` becomes a lambda binder. For example:
+ However, if the let-binder has
+ * RULES
+ * a stable unfolding
+ * a non-default inlining activation
+ we'd permanently lose these things if we lambda-bind it. For example:
let {-# NOINLINE x #-}
x! = case y of { ... }
in blah
- If we make a join point j x = blah, we have nowhere convenient
- to put that NOINLINE. Ditto INLINE or RULES. So in these cases we
- simply don't use StrictBind. It's very unusual, so no harm done.
- But it does happen; one example is this, in the Applicative (ST s)
- instance in GHC.Internal.Control.Monad.St.Lazy.Imp
+ If we make a join point j x = blah, we have nowhere convenient to put that
+ NOINLINE. Ditto INLINE or RULES. It's unusual. But it happens; one example
+ is the Applicative (ST s) instance in GHC.Internal.Control.Monad.St.Lazy.Imp
{-# NOINLINE res1 #-}
!res1 = unST fm s
- TL;DR: the sc_bndr::Id field in StrictBind always satisfies `lamBndrInfoOK`.
- This means that in the above example { x! = case y of ... } we won't
- float the `case y` out. And perhaps that's fine because of the NOINLNE.
- We could imagine instead imposing these conditions only when we /duplicate/
- the StrictBind, rather than when we /create/ it, but that would require a
- bigger refactor.
+ So in these cases we simply don't use StrictBind -- see `useStrictBind`. We
+ could imagine instead imposing these conditions only when we /duplicate/ the
+ StrictBind, rather than when we /create/ it, but that would require a bigger
+ refactor. See (SB5) for why we don't worry if the binder has strictness or
+ CPR information.
+
+(SB4) Shortcoming: not using StrictBind has a cost. If we have
+ {-# NOINLINE x #-}
+ x! = case y of (a,b) -> a
+ then isnce x is used strictly, we'd usually float that `case y` outwards -- but
+ we do so precisely by using StrictBind. But since the NOINLINE stops us using
+ StrictBind we won't float out the case.
+
+ Fixing this would require `mkDupableCont` to return a non-duplicable tail of
+ the continuation (declining to duplicate a StrictBind with a NOINLINE, say).
+ But that's a lot of plumbing for a very narrow case. Who writes INLINE or NOINLINE
+ or RULES for a thunk? So we just accept the shortcoming.
+
+(SB5) What if a thunk has a strictness signature, or CPR information? We
+ could make `useStrictBind` say False in these cases too, but that turns
+ out to be a net loss: keeping a thunk is worse than losing the strictness
+ information. Example, where f1,f2 are both strict:
+ let f* {- Str=<S> -} = case x of { True -> f1; False -> f2 }
+ in body
+ Keeping it as-is would use CBV for calls of `f` in `body`. But
+ allowing StrictBind would give us
+ join j f* = body
+ in case x of { True -> j f1; False -> j f2 }
+ which avoids the thunk. It's a trade-off.
+
+ For CPR info, see Note [Thunk splitting] in GHC.Core.Opt.WorkWrap,
+ especially (B) CPR-led thunk splitting.
Note [Join point abstraction] Historical note
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
compiler/GHC/Core/Opt/WorkWrap.hs
=====================================
@@ -598,13 +598,20 @@ tryWW ww_opts is_rec fn_id rhs
= splitFun ww_opts new_fn_id rhs
-- See Note [Thunk splitting]
- | isNonRec is_rec, is_thunk
- = splitThunk ww_opts is_rec new_fn_id rhs
+ | isNonRec is_rec -- See (TS4)
+ , is_thunk -- All join points go via splitFun
+ , not (hasRulesOrInline (fn_info)) -- See (TS9)
+ = do { -- Try strictness then CPR; see (TS5)
+ rhs' <- splitThunkStr ww_opts new_fn_id rhs `orElseM`
+ splitThunkCpr ww_opts new_fn_id rhs `orElseM`
+ return rhs
+ ; return [ (new_fn_id, rhs') ] }
| otherwise
= return [ (new_fn_id, rhs) ]
where
+ is_join = isJoinId fn_id
fn_info = idInfo fn_id
(wrap_dmds, _) = splitDmdSig (dmdSigInfo fn_info)
new_fn_id = zap_join_cpr $ zap_usage fn_id
@@ -613,14 +620,13 @@ tryWW ww_opts is_rec fn_id rhs
-- See Note [Zapping DmdEnv after Demand Analyzer] and
-- See Note [Zapping Used Once info in WorkWrap]
- zap_join_cpr id
- | isJoinId id = id `setIdCprSig` topCprSig
- | otherwise = id
+ zap_join_cpr id | is_join = id `setIdCprSig` topCprSig
+ | otherwise = id
-- See Note [Don't w/w join points for CPR]
- is_fun = notNull wrap_dmds || isJoinId fn_id
- is_thunk = not is_fun && not (exprIsHNF rhs) && not (isJoinId fn_id)
- && not (isUnliftedType (idType fn_id))
+ is_fun = notNull wrap_dmds || is_join
+ is_thunk = not (exprIsHNF rhs)
+ && not (isUnliftedType (idType fn_id))
{-
Note [Zapping DmdEnv after Demand Analyzer]
@@ -806,7 +812,7 @@ splitFun ww_opts fn_id rhs
(wrap_dmds, div) = splitDmdSig (dmdSigInfo fn_info)
- cpr_ty = getCprSig (cprSigInfo fn_info)
+ cpr_ty = cprSigType (cprSigInfo fn_info)
-- Arity of the CPR sig should match idArity when it's not a join point.
-- See Note [Arity trimming for CPR signatures] in GHC.Core.Opt.CprAnal
cpr = assertPpr (isJoinId fn_id || cpr_ty == topCprType || ct_arty cpr_ty == arityInfo fn_info)
@@ -957,114 +963,182 @@ the form [Demand=<L,1*(C(1,...(C(1,U))))>]
Note [Thunk splitting]
~~~~~~~~~~~~~~~~~~~~~~
-Suppose x is used strictly; never mind whether it has the CPR
-property. I'll use a '*' to mean "x* is demanded strictly".
-
- let
- x* = x-rhs
+The worker/wrapper split mainly affects let-bound /functions/. But we can also use
+demand and CPR information to improve let-bound /thunks/. Specifically:
+
+* (A) Demand-led thunk splitting:
+ If a thunk is demanded strictly, perhaps nestedly, we can turn it into a
+ case, perhaps nestedly. For example
+ let x :: (Int, Int)
+ {- Dmd = SP(S,L) -}
+ x = rhs
+ in body
+ We would ultimately like to get
+ case rhs of x { (a,b) ->
+ case a of { I# a# ->
+ body
+
+ This is much better: no thunk for `rhs`; and known-data-con unfoldings for `x`
+ and `a` inside `body`.
+
+* (B) CPR-led thunk splitting:
+ If a thunk has the (possibly-nested) CPR property /and/ is demanded strictly
+ at top level, we can again generate a case
+ let x :: (Int, Int)
+ {- Dmd = S, Cpr = (_, I# _) -}
+ x = rhs
+ in body
+ The CPR info says that if `x` is evaluated (which it is), it'll return a pair,
+ whose second component can very cheaply be evaluated to a (I# b#). We would
+ like to end up with
+ case rhs of x { (a,b) ->
+ case b of { I# b# ->
+ body
+ which is good for the same reasons as before. See (TS3) for an example.
+
+Implementation
+~~~~~~~~~~~~~~
+The worker/wrapper pass does not generate these nested case expressions directly.
+Instead it generates a regular let-binding but, since the binder is marked as
+strict, any `case` expressions in the RHS will float out. Specifically:
+
+(TS1) For (A), `splitThunkStr` generates the binding
+ let x! = case rhs of { (a,b) ->
+ case a of { I# a# ->
+ (I# a, b)
+ Now when the Simplifier floats the `case` expressions out, we get
+ case rhs of { (a,b) ->
+ case a of { I# a# ->
+ let x = (I# a, b)
in body
+ which is equivalent to the expression in (A) above.
-splitThunk transforms like this:
- let
- x* = let x = x-rhs in
- case x of { I# a -> I# a }
- in body
+ `splitThunkStr` also works on /absent/ thunks: see (TS6).
-This is a little strange: we are re-using the same `x` in the RHS; and
-the RHS takes `x` apart and reboxes it. But because the outer 'let' is
-strict, and the inner let mentions `x` only once, the simplifier
-transform it to
- case x-rhs of
- I# a -> let x* = I# a
- in body
-
-That is good: in `body` we know the form of `x`, which
- * gives the CPR property, and
- * allows case-of-case to happen on x
-
-Notes
-* I tried transforming like this:
- let
- x* = let x = x-rhs in
- case x of { I# a -> x }
- in body
- where I return `x` itself, rather than reboxing it. But this
- turned out to cause some regressions, which I never fully
- investigated.
-
-* Suppose x-rhs is itself a case:
- x-rhs = case e of { T -> I# e1; F -> I# e2 }
- Then we'll get
- join j a = let x* = I# a in body
- in case e of { T -> j e1; F -> j e2 }
- which is good (no boxing). But in the original, unsplit program
- we would transform
- let x* = case e of ... in body
- ==> join j2 x = body
- in case e of { T -> j2 (I# e1); F -> j (I# e2) }
- which is not good (boxing).
+ Rather cleverly, `splitThunkStr` uses `mkWWstr_one`, the /existing/ function
+ argument w/w splitting function, to do the unpacking. This automatically
+ deals with nested strictness.
-* In fact, splitThunk uses the function argument w/w splitting
- function, mkWWstr_one, so that if x's demand is deeper (say U(U(L,L),L))
- then the splitting will go deeper too.
+(TS2) For (B), `splitThunkCpr` behaves exactly analogously, again
+ using `mkWWcpr_one` to do the unpacking. It works only for /demanded/ thunks.
-* For recursive thunks, the Simplifier is unable to float `x-rhs` out of
- `x*`'s RHS, because `x*` occurs freely in `x-rhs`, and will just change it
- back to the original definition, so we just split non-recursive thunks.
+Wrinkles:
-Note [Thunk splitting for top-level binders]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Top-level bindings are never strict. Yet they can be absent, as T14270 shows:
-
- module T14270 (mkTrApp) where
- mkTrApp x y
- | Just ... <- ... typeRepKind x ...
- = undefined
- | otherwise
- = undefined
- typeRepKind = Tick scc undefined
-
-(T19180 is a profiling-free test case for this)
-Note that `typeRepKind` is not exported and its only use site in
-`mkTrApp` guards a bottoming expression. Thus, demand analysis
-figures out that `typeRepKind` is absent and splits the thunk to
-
- typeRepKind =
- let typeRepKind = Tick scc undefined in
- let typeRepKind = absentError in
- typeRepKind
-
-But now we have a local binding with an External Name
-(See Note [About the NameSorts]). That will trigger a CoreLint error, which we
-get around by localising the Id for the auxiliary bindings in 'splitThunk'.
+(TS3) Here's an example of (B), thunk-splitting based on CPR information.
+ Suppose we have
+ let x! = case e of { T -> Just e1; F -> Just e2 }
+ in body
+ If the Simplifier floats the `case` out, we get
+ join j2 x = body
+ in case e of { T -> j2 (Just e1); F -> j2 (Just e2) }
+ which is not good (boxing).
+
+ If we first do the thunk-splitting transformation, we get
+ let x! = case (case e of { T -> Just e1; F -> Just e2 }) of
+ Just a -> Just a
+ in body
+
+ Now when the Simplifier floats we will get:
+ join j a = let x = Just a in body
+ in case e of { T -> j e1; F -> j e2 }
+ which is much better (no boxing). But see (TS9).
+
+(TS4) We only do thunk-splitting for thunks that are non-recursive
+ For recursive thunks, the Simplifier is unable to float `rhs` out of
+ x's RHS, because `x` occurs freely in `rhs`, and will just change it
+ back to the original definition.
+
+(TS5) Notice that (B) CPR-led thunk splitting can be useful:
+ * when multi-constructor data types are involved, so that the argument-unboxing
+ mechanism (A) is impotent. See the example in (TS3), which uses `Maybe`.
+ * when the binder is only demanded head-strictly, but CPR has nested information.
+
+ So (A) and (B) have complementary benefits. We might do even better by
+ /combining/ (A) and (B), but at the moment we try (A) first, and then try (B)
+ if (A) is impotent. Combining them would be more work.
+
+(TS6) We can also exploit /absence/. Consider
+ let x {-# Dmd = A #-} = rhs
+ in body
+ Generally speaking `x` will be absent becuase it is passed to functions that
+ don't use it, in which case worker/wrapper on those calls will make `x` unused.
+ But suppose `x` is absent inside a /lazy/ argument:
+ let f p = (fst p, 99) in
+ let x = rhs in
+ f (True, x)
+ Here f's argument is lazy, but `x` is definitely absent, and we could replace
+ `x` with an absent filler. Using (TS1) would give us
+ let x = absentError "urk" in ...
+ which is great.
+
+ So `splitThunkStr` works /regardless/ of the demand on `x`; whether it fires is
+ determined only by the `useful` flag returned by `mkWWstr_one`.
+
+(TS7) Adopting (TS6) leads to one other complication: a top-level binder with
+ an External Name (see Note [About the NameSorts]) can be Absent. If so,
+ it must not be used as a local binder in the `Let` created by `splitThunkStr`.
+ T19180 is a test case for this rather obscure situation.
+
+ Solution: use `localiseId` to localise the binder for the `Let`.
+
+(TS8) Consider out poster child test case for `splitThunkCpr`, in (TS3).
+ x! = case e of { True -> Just 1; False -> Just 2 }
+ But suppose we have `-fworker-wrapper-cbv` enabled (reminder: see
+ Note [Worker/wrapper for strict arguments]). Then alas `splitThunkStr`
+ will fire, but it'll be a no-op in this case. But since it fires, `splitThunkCpr`
+ never gets a chance.
+
+ Hacky but effective solution: switch off `wo_unlift_strict` locally in `splitThunkStr`.
+
+(TS9) `splitThunkStr` implicitly relies on floating a case out of a strict binding.
+ But if the thunk has a RULE or INLINE/NOINLINE pragma that won't happen; see
+ (SB4) in Note [StrictBind] in GHC.Core.Opt.Simplify.Iteration. So we test
+ these things before applying thunk splitting.
-}
--- | See Note [Thunk splitting].
---
--- splitThunk converts the *non-recursive* binding
+-- | splitThunkStr converts the *non-recursive* binding
-- x = e
-- into
--- x = let x' = e in
--- case x' of I# y -> let x' = I# y in x'
--- See comments above. Is it not beautifully short?
--- Moreover, it works just as well when there are
--- several binders, and if the binders are lifted
--- E.g. x = e
--- --> x = let x' = e in
--- case x' of (a,b) -> let x' = (a,b) in x'
--- Here, x' is a localised version of x, in case x is a
--- top-level Id with an External Name, because Lint rejects local binders with
--- External Names; see Note [About the NameSorts] in GHC.Types.Name.
---
--- How can we do thunk-splitting on a top-level binder? See
--- Note [Thunk splitting for top-level binders].
-splitThunk :: WwOpts -> RecFlag -> Var -> Expr Var -> UniqSM [(Var, Expr Var)]
-splitThunk ww_opts is_rec x rhs
- = assert (not (isJoinId x)) $
- do { let x' = localiseId x -- See comment above
- ; (useful,_args, wrap_fn, fn_arg)
- <- mkWWstr_one ww_opts x' NotMarkedStrict
- ; let res = [ (x, Let (NonRec x' rhs) (wrap_fn fn_arg)) ]
- ; if useful then assertPpr (isNonRec is_rec) (ppr x) -- The thunk must be non-recursive
- return res
- else return [(x, rhs)] }
+-- x = let x = e in
+-- case x of I# y -> I# y
+-- See Note [Thunk splitting].
+splitThunkStr :: WwOpts -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
+splitThunkStr ww_opts x rhs
+ = -- NB: does not depend on x's demand being strict; it might be absent, see (TS6)
+ do { let x' = localiseId x -- See (TS7)
+ ww_opts' = ww_opts { wo_unlift_strict = False } -- See (TS8)
+ ; (useful, _transit_vars, wrap_fn, fn_arg) <- mkWWstr_one ww_opts' x' NotMarkedStrict
+ -- Use mkWWstr_one: see (TS1) in Note [Thunk splitting]
+
+ ; if useful
+ then return (Just (Let (NonRec x' rhs) $
+ wrap_fn fn_arg))
+ else return Nothing }
+
+splitThunkCpr :: WwOpts -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
+-- See Note [Thunk splitting]
+-- Given x* = rhs, where x* is used outermost-strictly, and x* has a (nested) CPR
+-- property, say Just (Just _), return this new RHS:
+-- let x' = rhs in
+-- case x' of { Just p -> case p of { Just q -> -- Unpacking code
+-- Just (Just q) }} -- Repacking code
+-- Works for multi-constructor data types, where splitThunkStr will fail
+splitThunkCpr ww_opts x rhs
+ | wo_cpr_anal ww_opts -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
+ , isStrUsedDmd (idDemandInfo x) -- See (TS2)
+ = assertPpr (cprTypeArity cpr_type == 0) (ppr x) $ -- It's a thunk
+ do { (useful, _transit_vars, rebuild_result, unpacker) <- mkWWcpr_one ww_opts x cpr
+ -- Use mkWWcpr_one: see (TS2) in Note [Thunk splitting]
+ ; if useful
+ then return (Just (Let (NonRec x rhs) $
+ unpacker rebuild_result))
+ else return Nothing }
+
+ | otherwise
+ = return Nothing
+ where
+ cpr_type :: CprType
+ cpr_type = cprSigType (idCprSig x)
+ cpr :: Cpr
+ cpr = cprTypeCpr cpr_type
+
=====================================
compiler/GHC/Core/Opt/WorkWrap/Utils.hs
=====================================
@@ -8,7 +8,7 @@ A library for the ``worker\/wrapper'' back-end to the strictness analyser
{-# LANGUAGE ViewPatterns #-}
module GHC.Core.Opt.WorkWrap.Utils
- ( WwOpts(..), mkWwBodies, mkWWstr, mkWWstr_one
+ ( WwOpts(..), mkWwBodies, mkWWstr, mkWWstr_one, mkWWcpr_one
, needsVoidWorkerArg
, DataConPatContext(..)
, UnboxingDecision(..), canUnboxArg
@@ -139,13 +139,18 @@ data WwOpts
= MkWwOpts
{ -- | Environment of type/data family instances
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)
+ -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
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
-- unlifted. See Note [WW for calling convention]
wo_unlift_strict :: !Bool }
@@ -230,8 +235,7 @@ mkWwBodies opts fun_id ww_arity arg_vars res_ty demands res_cpr
; let (work_args, work_marks) = unzip work_args_str
-- Do CPR w/w. See Note [Always do CPR w/w]
- ; (useful2, wrap_fn_cpr, work_fn_cpr)
- <- mkWWcpr_entry opts res_ty' res_cpr
+ ; (useful2, wrap_fn_cpr, work_fn_cpr) <- mkWWcpr_entry opts res_ty' res_cpr
; let (work_lam_args, work_call_args, work_call_str)
| needsVoidWorkerArg fun_id arg_vars work_args
@@ -662,8 +666,10 @@ canUnboxResult fam_envs ty cpr
= DontUnbox
where
- -- See Note [non-algebraic or open body type warning]
- open_body_ty_warning = warnPprTrace True "canUnboxResult: non-algebraic or open body type" (ppr ty) Nothing
+ -- See Note [Non-algebraic or open body type warning]
+ open_body_ty_warning
+ = warnPprTrace True "canUnboxResult: non-algebraic or open body type"
+ (ppr ty) Nothing
@@ -808,7 +814,7 @@ match the number of constructor arguments; this happened in #8037.
If so, the worker/wrapper split doesn't work right and we get a Core Lint
bug. The fix here is simply to decline to do w/w if that happens.
-Note [non-algebraic or open body type warning]
+Note [Non-algebraic or open body type warning]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are a few cases where the W/W transformation is told that something
returns a constructor, but the type at hand doesn't really match this. One
@@ -829,8 +835,60 @@ This warning also triggers for the stream fusion library within `text`.
We can't easily W/W constructed results like `Stream` because we have no simple
way to express existential types in the worker's type signature.
+Note [Worker/wrapper for strict arguments]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+ f x = case x of
+ [] -> blah
+ (y:ys) -> f ys
+
+Clearly `f` is strict, but its argument is not a product type, so by default
+we don't worker/wrapper it. But it is arguably valuable to do so. We could
+do this:
+
+ f x = case x of xx { DEFAULT -> $wf xx }
+ $wf xx = case xx of
+ [] -> blah
+ (y:ys) -> f ys
+
+Now the worker `$wf` knows that its argument `xx` will be evaluated
+and properly tagged, so the code for the `case xx` does not need to do
+an "eval" (see `GHC.StgToCmm.Expr.cgCase`). A call (f (a:as)) will
+have the wrapper inlined, and will drop the `case x`, so no eval
+happens at all.
+
+The worker `$wf` is a CBV function (see `Note [CBV Function Ids: overview]`
+in GHC.Types.Id.Info) and the code generator guarantees that every
+call to `$wf` has a properly tagged argument (see `GHC.Stg.EnforceEpt.Rewrite`).
+
+Is this a win? Not always:
+* It can cause slight code size increases. This is since we push evals to every
+ call sites which there might be many. And the evals will only disappear at
+ call sites where we already known that the argument is evaluated.
+
+* It will also cause many more functions to get a worker/wrapper split
+ which can play badly with rules (see Ticket #20364). In particular
+ if you depend on rules firing on functions marked as NOINLINE
+ without marking use sites of these functions as INLINE or INLINEABLE
+ then things will break.
+
+ But if you want a function to match in a RULE, it is /in any case/ good
+ practice to have a `INLINE[1]` or `NOINLNE[1]` pragma, to ensure that it
+ doesn't inline until the rule has had a chance to fire.
+
+So there is a flag, `-fworker-wrapper-cbv`, to control whether we do
+w/w on strict arguments (internally `Opt_WorkerWrapperUnlift`). The
+flag is off by default. The choice is made in
+GHC.Core.Opt.WorkWrap.Utils.wwUseForUnlifting
+
+See also `Note [WW for calling convention]`
+
Note [WW for calling convention]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ NB: This Note is more of a discussion.
+ Read Note [Worker/wrapper for strict arguments] first,
+ which covers the same ground with more precision
+
If we know a function f will always evaluate a particular argument
we might decide that it should rather get evaluated by the caller.
We call this "unlifting" the argument.
@@ -856,10 +914,9 @@ Hence we have the following strategies with different trade-offs:
A) Never do W/W *just* for unlifting of arguments.
+ Very conservative - doesn't break any rules
- - Lot's of performance left on the table
+ - Lots of performance left on the table
-B) Do W/W on just about anything where it might be
- beneficial.
+B) Do W/W on just about anything where it might be beneficial.
+ Exploits pretty much every opportunity for unlifting.
- A bit of compile time/code size cost for all the wrappers.
- Can break rules which would otherwise fire. See #20364.
@@ -883,10 +940,10 @@ C) Unlift *any* (non-boot exported) functions arguments if they are strict.
functionality. I haven't tried this approach because it's not trivial to
implement and doing W/W splits seems to work well enough.
-Currently we use the first approach A) by default, with a flag that allows users
-to fall back to the more aggressive approach B).
+Currently we use the first approach (A) by default, with a flag `-fworker-wrapper-cbv`
+that allows users to fall back to the more aggressive approach (B).
-I also tried the third approach C) using eta-expansion at call sites to avoid
+I also tried the third approach (C) using eta-expansion at call sites to avoid
modifying the PAP-handling code which wasn't fruitful. See
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5614#note_389903. We could
still try to do C) in the future by having PAP calls which will evaluate the
@@ -895,53 +952,6 @@ be neither a small nor simple change so we stick with A) and a flag for B) for
now.
See also Note [EPT enforcement] and Note [CBV Function Ids: overview]
-
-Note [Worker/wrapper for strict arguments]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider
- f x = case x of
- [] -> blah
- (y:ys) -> f ys
-
-Clearly `f` is strict, but its argument is not a product type, so by default
-we don't worker/wrapper it. But it is arguably valuable to do so. We could
-do this:
-
- f x = case x of xx { DEFAULT -> $wf xx }
- $wf xx = case xx of
- [] -> blah
- (y:ys) -> f ys
-
-Now the worker `$wf` knows that its argument `xx` will be evaluated
-and properly tagged, so the code for the `case xx` does not need to do
-an "eval" (see `GHC.StgToCmm.Expr.cgCase`). A call (f (a:as)) will
-have the wrapper inlined, and will drop the `case x`, so no eval
-happens at all.
-
-The worker `$wf` is a CBV function (see `Note [CBV Function Ids: overview]`
-in GHC.Types.Id.Info) and the code generator guarantees that every
-call to `$wf` has a properly tagged argument (see `GHC.Stg.EnforceEpt.Rewrite`).
-
-Is this a win? Not always:
-* It can cause slight codesize increases. This is since we push evals to every
- call sites which there might be many. And the evals will only disappear at
- call sites where we already known that the argument is evaluated.
-
-* It will also cause many more functions to get a worker/wrapper split
- which can play badly with rules (see Ticket #20364). In particular
- if you depend on rules firing on functions marked as NOINLINE
- without marking use sites of these functions as INLINE or INLINEABLE
- then things will break.
- But if you want a function to match in a RULE, it is /in any case/ good practice to
- have a `INLINE[1]` or `NOINLNE[1]` pragma, to ensure that it doesn't inline until
- the rule has had a chance to fire.
-
-So there is a flag, `-fworker-wrapper-cbv`, to control whether we do
-w/w on strict arguments (internally `Opt_WorkerWrapperUnlift`). The
-flag is off by default. The choice is made in
-GHC.Core.Opt.WorkWrape.Utils.wwUseForUnlifting
-
-See also `Note [WW for calling convention]` in GHC.Core.Opt.WorkWrap.Utils
-}
{-
@@ -985,6 +995,12 @@ mkWWstr opts args str_marks
-- * wrap_arg assumes work_args are in scope, and builds a ConApp that
-- reconstructs the RHS of wrap_var that we pass to the original RHS
-- See Note [Worker/wrapper for Strictness and Absence]
+--
+-- E.g. mkWWstr_one (x :: (Int,Int) with strictess saying to unbox the pair and second Int
+-- = ( True -- useful
+-- , [p,q#], -- work_args
+-- , \e -> case x of (p,q) -> case q of I# q# -> e -- wrap_fn
+-- , (p, I# q) ) -- wrap_arg
mkWWstr_one :: WwOpts
-> Var
-> StrictnessMark
@@ -1008,7 +1024,7 @@ mkWWstr_one opts arg str_mark =
DontUnbox
| isStrictDmd arg_dmd || isMarkedStrict str_mark
- , wwUseForUnlifting opts -- See Note [WW for calling convention]
+ , wwUseForUnlifting opts -- See Note [Worker/wrapper for strict arguments]
, not (isFunTy arg_ty)
, not (isUnliftedType arg_ty) -- Already unlifted!
-- NB: function arguments have a fixed RuntimeRep,
@@ -1163,7 +1179,7 @@ function is worthy for splitting:
2b But if e.g. a large tuple or product type is always demanded we might
decide to "unlift" it. That is tighten the calling convention for that
argument to require it to be passed as a pointer to the value itself.
- See Note [WW for calling convention].
+ See Note [Worker/wrapper for strict arguments]
3. In all other cases (e.g., lazy, used demand and not eval'd),
'finaliseArgBoxities' will have cleared the Boxity flag to 'Boxed'
@@ -1604,7 +1620,9 @@ mkWWcpr_entry
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)
+ | not (wo_cpr_anal opts) -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
+ = return (boringSplit, nop_fn, nop_fn)
+
| otherwise = do
-- Part (1)
res_bndr <- mk_res_bndr body_ty
@@ -1637,7 +1655,9 @@ mk_res_bndr body_ty = do
-- 1. A 'WwUse' capturing whether the split does anything useful.
-- 2. The list of transit variables (see the Note).
-- 3. The result builder expression for the wrapper. The original case binder if not useful.
--- 4. The result unpacking expression for the worker. 'nop_fn' if not useful.
+-- Assumes that the transit vars are in scope
+-- 4. The result unpacking expression for the worker. 'nop_fn' if not useful
+-- Brings the transit vars into scope
type CprWwResultOne = (WwUse, OrdList Var, CoreExpr , CoreExpr -> CoreExpr)
type CprWwResultMany = (WwUse, OrdList Var, [CoreExpr], CoreExpr -> CoreExpr)
@@ -1768,7 +1788,7 @@ To achieve said transformation, 'mkWWcpr_entry'
what belongs in the case scrutinee of the unpacker through the communicated
Id `r`: The unpacking expression will be free in that variable.
(This is a similar contract as that of 'mkWWstr_one' for strict args.)
- 3. 'mkWWstr_one' produces a bunch of *transit vars*: Those result variables
+ 3. 'mkWWcpr_one' produces a bunch of *transit vars*: Those result variables
that have to be transferred from the worker to the wrapper, where the
constructed result can be rebuilt, `a` and `b` above. Part (3) is
responsible for tupling them up in the worker and taking the tuple apart
=====================================
compiler/GHC/Types/Cpr.hs
=====================================
@@ -8,6 +8,7 @@
module GHC.Types.Cpr (
Cpr (ConCpr), topCpr, botCpr, flatConCpr, asConCpr,
CprType (..), topCprType, botCprType, flatConCprType,
+ cprTypeArity, cprTypeCpr,
lubCprType, applyCprTy, abstractCprTy, trimCprTy,
UnpackConFieldsResult (..), unpackConFieldsCpr,
CprSig (..), topCprSig, isTopCprSig, mkCprSigForArity, mkCprSig,
@@ -106,6 +107,12 @@ data CprType
-- 'ct_arty' arguments
}
+cprTypeArity :: CprType -> Arity
+cprTypeArity = ct_arty
+
+cprTypeCpr :: CprType -> Cpr
+cprTypeCpr = ct_cpr
+
instance Eq CprType where
a == b = ct_cpr a == ct_cpr b
&& (ct_arty a == ct_arty b || ct_cpr a == topCpr)
@@ -167,7 +174,7 @@ seqCprTy (CprType _ cpr) = seqCpr cpr
-- | The arity of the wrapped 'CprType' is the arity at which it is safe
-- to unleash. See Note [Understanding DmdType and DmdSig] in "GHC.Types.Demand"
-newtype CprSig = CprSig { getCprSig :: CprType }
+newtype CprSig = CprSig { cprSigType :: CprType }
deriving (Eq, Binary)
-- | Turns a 'CprType' computed for the particular 'Arity' into a 'CprSig'
=====================================
compiler/GHC/Types/Id/Info.hs
=====================================
@@ -32,7 +32,7 @@ module GHC.Types.Id.Info (
setOneShotInfo,
-- ** Zapping various forms of Info
- zapLamInfo, zapFragileInfo,
+ zapLamInfo, zapFragileInfo, hasRulesOrInline,
lazifyDemandInfo, floatifyDemandInfo,
zapUsageInfo, zapUsageEnvInfo, zapUsedOnceInfo,
zapTailCallInfo, zapCallArityInfo, trimUnfolding,
@@ -963,3 +963,10 @@ zapTailCallInfo info
zapCallArityInfo :: IdInfo -> IdInfo
zapCallArityInfo info = setCallArityInfo info 0
+
+hasRulesOrInline :: IdInfo -> Bool
+-- See (SB3) of Note [StrictBind]
+hasRulesOrInline info
+ = isStableUnfolding (unfoldingInfo info)
+ || not (isEmptyRuleInfo (ruleInfo info))
+ || not (isAlwaysActive (inlinePragmaActivation (inlinePragInfo info)))
=====================================
compiler/GHC/Utils/Monad.hs
=====================================
@@ -16,7 +16,7 @@ module GHC.Utils.Monad
, mapAccumLM
, mapSndM
, concatMapM
- , mapMaybeM
+ , mapMaybeM, orElseM
, anyM, allM, orM
, foldlM, foldlM_, foldrM, foldMapM
, whenM, unlessM
@@ -250,6 +250,14 @@ unlessM :: Monad m => m Bool -> m () -> m ()
unlessM condM acc = do { cond <- condM
; unless cond acc }
+-- | Monadic version of @orElse@
+infixr 4 `orElseM`
+orElseM :: Monad m => m (Maybe a) -> m a -> m a
+orElseM ma def = do { mb_r <- ma
+ ; case mb_r of
+ Just x -> return x
+ Nothing -> def }
+
-- | Like 'filterM', only it reverses the sense of the test.
filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a]
filterOutM p =
=====================================
testsuite/tests/simplCore/should_compile/T28158.hs
=====================================
@@ -0,0 +1,22 @@
+{-# OPTIONS_GHC -fworker-wrapper-cbv #-}
+-- Adding this option makes things harder for splitThunkCpr, which
+-- this test is testing. See (TS8) in Note [Thunk splitting]
+
+module T28158 where
+
+-- Here we miss CPR on y
+-- It's a bit of an obscure example, but still; see #28158
+f :: a -> a -> a -> [Int] -> [Int]
+f a b c xs = let y = case xs of
+ [0] -> Just a
+ [1] -> Just b
+ _ -> Just c
+ in h y (case y of
+ Just z -> reverse (reverse (reverse (
+ reverse (reverse (reverse (
+ reverse (reverse xs)))))))
+ Nothing -> xs++xs)
+
+h :: Maybe a -> b -> b
+h (Just y) e = h Nothing e
+h Nothing e = e
=====================================
testsuite/tests/simplCore/should_compile/T28158.stderr
=====================================
@@ -0,0 +1,58 @@
+
+==================== Tidy Core ====================
+Result size of Tidy Core
+ = {terms: 98, types: 108, coercions: 0, joins: 1/1}
+
+Rec {
+$wh
+ = \ @a @b ds e ->
+ case ds of ds1 { __DEFAULT ->
+ case e of e1 { __DEFAULT ->
+ case ds1 of {
+ Nothing -> e1;
+ Just y -> $wh Nothing e1
+ }
+ }
+ }
+end Rec }
+
+h = \ @a @b ds e -> $wh ds e
+
+$wf
+ = \ @a a1 b c xs ->
+ join {
+ $j ww
+ = $wh
+ (Just ww)
+ (reverse1
+ (reverse1
+ (reverse1
+ (reverse1
+ (reverse1 (reverse1 (reverse1 (reverse1 xs []) []) []) []) [])
+ [])
+ [])
+ []) } in
+ case xs of {
+ [] -> jump $j c;
+ : ds ds1 ->
+ case ds of { I# ds2 ->
+ case ds2 of {
+ __DEFAULT -> jump $j c;
+ 0# ->
+ case ds1 of {
+ [] -> jump $j a1;
+ : ipv ipv1 -> jump $j c
+ };
+ 1# ->
+ case ds1 of {
+ [] -> jump $j b;
+ : ipv ipv1 -> jump $j c
+ }
+ }
+ }
+ }
+
+f = \ @a a1 b c xs -> $wf a1 b c xs
+
+
+
=====================================
testsuite/tests/simplCore/should_compile/all.T
=====================================
@@ -637,5 +637,5 @@ test('T27963', [grep_errmsg(r'f/42')], compile, ['-O -ddump-rule-firings'])
test('T27965', normal, compile, ['-O'])
test('T27965a', normal, compile, ['-O'])
test('T27965b', normal, compile, ['-O'])
-
+test('T28158', normal, compile, ['-O -dno-typeable-binds -dsuppress-all -dsuppress-uniques -ddump-simpl'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c7f08910da9d383b48286f30f7b92eb…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c7f08910da9d383b48286f30f7b92eb…
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] 6 commits: Add opportunistic deadlock detection without idle GC
by Duncan Coutts (@dcoutts) 26 Nov '26
by Duncan Coutts (@dcoutts) 26 Nov '26
26 Nov '26
Duncan Coutts pushed to branch wip/io-manager-deadlock-detection at Glasgow Haskell Compiler / GHC
Commits:
6b9c9c46 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
95fdb942 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
e746472c by Duncan Coutts at 2026-11-26T00:22:08+00:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
12c563d7 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
8970c37d by Duncan Coutts at 2026-11-26T00:22:08+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
- - - - -
7e261111 by Duncan Coutts at 2026-11-26T00:22:08+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.
- - - - -
37 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/IdleGC.c
- rts/IdleGC.h
- rts/RtsFlags.c
- rts/RtsSymbols.c
- rts/Schedule.c
- rts/Timer.c
- rts/include/rts/OSThreads.h
- rts/include/rts/storage/GC.h
- rts/js/environment.js
- rts/posix/Poll.c
- rts/posix/Select.c
- rts/posix/SelectBis.c
- rts/posix/Timeout.c
- rts/posix/Timeout.h
- rts/win32/AsyncMIO.c
- rts/win32/AsyncWinIO.c
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- 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/f8e9fb69c865261740f040b18f35ec…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f8e9fb69c865261740f040b18f35ec…
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