-
ac870ad5
by Simon Jakobi at 2026-10-28T04:40:42-04:00
X86 NCG: use 32-bit POPCNT for sub-word popcounts
A 32-bit write zero-extends the result to the full register, so we
don't need to emit additional code for this.
We also skip emitting zero-extension instructions for the argument
when it is already visibly zero-extended.
For the byte-wise popcount loop from #24813, this shrinks the popcount
sequence from 5 instructions to 3.
Assisted-by: Claude Fable 5.1
-
53087373
by Facundo Domínguez at 2026-10-28T04:41:32-04:00
Use a ShortByteString in Serialized instead of [Word8]
This makes the in-memory representation 40x more compact for all values
stored in annotations.
A test is added to measure the representation size of annotations
specified in the compiler input.
The GHC API is modified. All functions that previously handled annotations
in [Word8] form now use ShortByteString. The following definitions have
modified types:
* GHC.findGlobalAnns
* GHC.Tc.Gen.Splice.getAnnotationsByTypeRep
* GHC.Core.Opt.Monad.getAnnotations
* GHC.Core.Opt.Monad.getFirstAnnotations
* GHC.Types.Annotations.deserializeAnns
* GHC.Types.Annotations.findAnns
* GHC.Types.Annotations.findAnnsByTypeRep
* GHC.Serialized.Serialized
* GHC.Serialized.toSerialized
* GHC.Serialized.fromSerialized
* GHC.Serialized.serializeWithData
* GHC.Serialized.deserializeWithData
* GHCi.Message.ReifyAnnotations
Fixes #28002.
-
cc533b66
by Sasha Bogicevic at 2026-10-31T09:18:15-04:00
Don't report -XStrict-generated bangs under -Wredundant-bang-patterns
The -XStrict flag causes the desugarer to insert bang patterns.
These are not user-written, so -Wredundant-bang-patterns must not
report them.
To achieve this, the desugarer now tracks whether it is desugaring
compiler-generated code (similar to the typechecker's 'tcl_in_gen_code').
Bangs inserted by -XStrict are given generated spans, which suppresses
the "redundant bang" warnings without otherwise affecting pattern-match
warnings.
Fixes #27323
-
13d38047
by Luite Stegeman at 2026-10-31T09:19:11-04:00
rts: tombstone Weak# copies that lose an evacuation race (#23160)
Mark the losing copy of a Weak# during an evacuation race in parallel
GC with stg_DEAD_WEAK_info. This ensures that the nonmoving GC
doesn't follow dangling pointers, leading to crashes.
Fixes #23160
-
63347328
by Zubin Duggal at 2026-10-31T09:19:52-04:00
ghci: Drop GHCi's exception context when rethrowing in ghc -e
Fixes #27847.
-
a85fef3f
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context in modifyIOError
Fixes #27851.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/446
-
1d60b591
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context in mapException
Fixes #27851.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/446
-
3c029a1b
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context when rethrowing exceptions in Handle reads
Fixes #27875.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/447
-
ab2b317a
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context when rethrowing exceptions in hClose
Fixes #27875.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/447
-
f5abf277
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context when rethrowing exceptions in Windows openFile
Fixes #27875.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/447
-
d842c672
by Zubin Duggal at 2026-10-31T09:19:52-04:00
base: Preserve exception context when rethrowing exceptions in executablePath
Fixes #27875.
CLC proposal: https://github.com/haskell/core-libraries-committee/issues/447
-
c5a8bb9f
by Simon Peyton Jones at 2026-10-31T09:20:34-04:00
Simplify a tc-trace which could crash the compiler
The trace formatted an error message, which prematurely
read the ExpType in a FunResCtxt.
Solution: don't put call the error message formatting
when tc-tracing.
-
ab49b1d2
by Simon Peyton Jones at 2026-10-31T09:20:34-04:00
Tiny comment change to uniqAway
-
6efe4ba3
by Simon Peyton Jones at 2026-10-31T09:20:34-04:00
Make niFixSubst idempotent
I discovered (when fixing #27994) that `niFixSubst` didn't actually
generate an idempotent subsitution despite its claims. It could
return a substitution that mentions domain variables on in its range,
when those variables are hidden inside the kind of a type variable
occurrence. As a result it can generate ill-kinded types. Boo!
The fix is simple, and uses deep substitution.
See Note [Finding the substitution fixpoint]
I don't think it actually /caused/ any bugs, so there is no
regression test.
-
3b60ae7e
by Simon Peyton Jones at 2026-10-31T09:20:34-04:00
Fix a nasty bug in fundeps
This MR fixes #27994, which turned out to be very tricky.
See Note [Exploiting closed type famililes], especially (CF7). I was
ending up with TyVars (not TcTyVars) in the solver, because the
substitution computed in `getRelevantBranches` mixed the two.
The code was just too clever. I ended up simplifying it quite a bit.
For /closed/ families we no longer call `trimQtvs` (was `trim_qtvs`).
Open families still do use `trimQtvs`. See Note [trimQTvs]
This patch also fixes one other buglet in the same code.
* Over-saturated type families were being mis-handled.
See the new use of `saturatedFamApp_maybe`.
-
e4610f2d
by Facundo Domínguez at 2026-10-31T09:21:24-04:00
Have haddock --incremental look for the module in -this-unit-id
-
bc6c0db6
by sheaf at 2026-10-31T09:22:20-04:00
mightBeFunTy: hotfix for #27979
ce01ccb6 refactored 'GHC.Types.RepType.mightBeFunTy' to look through
unary classes. That change introduced the helper function 'unwrap_type'
which was supposed to always return an unwrapped type, but its fallback
equation mistakenly returned the original type. This caused the
subsequent 'tyConAppTyCon_maybe' to fail in cases where it should
succeed (e.g. looking through foralls).
In this commit, we move all the unary class unwrapping logic into
'unwrapType' where it belonged from the start, and update the
documentation of 'unwrapType' to better explain what it should be used
for (#26695).
Fixes #27979 #26695
-------------------------
Metric Increase:
T5642
-------------------------
-
233cce46
by Alan Zimmerman at 2026-10-31T09:23:01-04:00
EPA: Tidy up ExactPrint.markAnnListA'
It takes an action which can modify the AnnList, but this
is never used. So remove it.
-
3594a908
by Sylvain Henry at 2026-10-31T09:23:51-04:00
gitmodules: ignore dirty libffi-clib submodule (#26785)
`./boot` runs autoreconf in libraries/libffi-clib, which leaves
`configure~` behind and rewrites the tracked `aclocal.m4` whenever the
local automake version differs from the one that generated it. Every
checkout then looks dirty. Ignore working-tree changes in the submodule
(`ignore = dirty`); a changed submodule commit is still reported.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
341223c0
by Rodrigo Mesquita at 2026-10-31T09:24:33-04:00
refactor: Keep the interactive Ids directly rather than Name
Removes things like
names <- map idName ids
map (\i -> let id = find (\x -> i==idName x) names) idso
and is more straightforward because there's less state going around (no
more updating HscEnv as an output)
It also kills `printTypeOfNames` completely, since now we just have the
Ids. No longer `lookupName` names to get back the ids...
```
printTypeOfName :: GHC.GhcMonad m => Name -> m ()
printTypeOfName n
= do maybe_tything <- GHC.lookupName n
case maybe_tything of
Nothing -> return ()
Just thing -> printTyThing thing
```
now is just `printTyThing . AnId`
Also:
```diff
- tythings <- catMaybes `liftM` mapM GHC.lookupName namesSorted
- docs <- mapM pprTypeAndContents [i | AnId i <- tythings]
+ docs <- mapM pprTypeAndContents idsSorted
```
(and yes, in ExecBreaks there are only Ids, no TyThings, bc they are
only constructed by the interpreter execution which can only bind ids.
for TyThings use runDecls which doesn't return execBreaks.)
There's some care to be had to make sure we use the "most refined" Ids,
whereas when using `Name`s we'd always fetch the most refined Id from
scratch.
Fixes #28052
-
54cf3c1e
by sheaf at 2026-11-03T07:00:23-05:00
Consolidate all CPU feature handling
This commit introduces GHC.Platform.CpuFeatures which consolidates all
of the logic for implications between CPU feature flags (mainly X86):
- DynFlags now only records the set of -m<feature> flags that were
passed, as an EnumSet CpuFeature. That keeps it a simple record of
the flags the user passed, with no post-processing.
- GHC.Platform.CpuFeatures.initCpuFeatures turns this set into a
CpuFeatures value, applying all implications and the per-architecture
baseline. This is the single home for all of the feature implication
logic.
Some datatypes were reworked to better reflect the implication
structure in the types, e.g. SseAvxVersion has a strategically
placed 'FMA' boolean.
- The NCG, LLVM backend, StgToCmm, CPP defines and LLVM -mattr
flags all consult CpuFeatures, via targetCpuFeatures.
See Note [CPU features], which replaces
Note [Implications between X86 CPU feature flags].
Behaviour changes:
- x86 feature flags (-msse3, -mavx, -mavx512*, -mgfni, ...) passed
when targeting a non-x86 architecture no longer cause x86 CPP
macros (__SSE3__, __AVX512BW__, __GFNI__, ...) to be defined, nor
x86 attributes to be passed to LLVM.
- Error messages reported when required CPU features are not enabled
now print out the minimal set of flags required
(e.g. "-mavx512vl" rather than "-mavx512f -mavx512vl").
-
9af64305
by Luite Stegeman at 2026-11-03T07:01:23-05:00
rts: move stack check to the start of the stg_unpack_cstring thunks
fixes a deadlock
see #27272
-
a2208b21
by Simon Jakobi at 2026-11-03T07:02:05-05:00
Cmm: exclude the entry block from common block elimination
a1d8139054c had fixed #27722 only partially, because it didn't prevent
elimination of the entry block in later rounds, where the entry block is
no longer guaranteed to come first.
To close this loophole, we exclude the entry block from the CBE merge
logic. See Note [Retain entry block during common block elimination] for
details.
This also deletes a misleading comment regarding unreachable blocks: the
control-flow optimiser doesn't actually guarantee that no unreachable
blocks reach CBE.
Fixes #27722.
Assisted-by: Claude Fable 5.1
-
37ad4710
by Alan Zimmerman at 2026-11-03T07:02:46-05:00
EPA: Use AnnList for GADT declarations
Continuing the process of using AnnList to capture parser layout
-
56757900
by Sebastian Graf at 2026-11-04T20:36:47+01:00
Documentation for the Core data constructors
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
9f57c265
by Sylvain Henry at 2026-11-06T06:46:15-05:00
ghc-internal: avoid unnecessary allocations in bignum division (#27231)
Avoid unnecessary allocations in bignum division in the Haskell (native)
backend. The long-division loop used to allocate a fresh BigNat for the
partial product on every iteration, plus one more per quotient-digit
correction; it now subtracts the partial product in place and
materializes nothing.
The quotient-digit estimate is also refined against the second-highest
divisor word, so the add-back correction runs at most once per
iteration.
bignat_quotrem_normalized now requires a divisor of at least 2 words, so
bignat_quotrem dispatches 1-word divisors to bignat_quotrem_word.
See Note [Knuth division loop] and Note [Fused multiply-subtract for
long division] in GHC.Internal.Bignum.Backend.Native.
Measured on the new T27231 perf test (10000 native-backend 8192/2048-bit
Integer quotRem calls): bytes allocated drops from 305 MB to 52 MB (-83%).
Improvement on CI (x86-64-linux-deb13-int_native):
space_leak_001(normal) run/alloc 12,492,185,536 9,073,055,928 -27.4% GOOD
Metric Decrease:
space_leak_001
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
c5b80f4e
by mangoiv at 2026-11-06T06:46:57-05:00
ci: build and test stage
Split up CI in a build and test stage:
1. in the build stage, just produce a bindist as well as running the
stage1 tests
2. in the test stage, install the bindist, then run the testsuite with
out of tree args
-
e4b1c892
by mangoiv at 2026-11-06T06:46:57-05:00
ci: reorder packaging and testing stages
-
19901b41
by mangoiv at 2026-11-06T06:46:57-05:00
ci: out of tree compiler does not imply no hadrian being available
-
83a860a7
by mangoiv at 2026-11-06T06:46:57-05:00
ci: don't do msys deps check on stage1 compiler
-
abf5b3af
by mangoiv at 2026-11-06T06:46:57-05:00
testsuite: allow metric decreases on windows
Metric Decrease:
LinkableUsage01
MultiLayerModulesTH_OneShot
T10547
T12234
T12425
T13035
T13253-spj
T13820
T18140
T18730
T18923
T9198
TcPlugin_RewritePerf
mhu-perf
-
9185f1ab
by mangoiv at 2026-11-06T06:46:57-05:00
ci: stop using ellipses in testsuite output and output env before invoking hadrian
-
bf9ece2b
by Simon Jakobi at 2026-11-06T06:47:42-05:00
testsuite: Skip the changelog-d test in CI
Full-build validate jobs run the whole testsuite and thus repeated the
changelog validation that the dedicated lint-changelog job had already
reported in the early tool-lint stage.
Skip the test when GITLAB_CI is set, making lint-changelog the only CI
check of changelog.d while keeping the test available in local
testsuite runs.
Fixes #27325.
Assisted-by: Claude Fable 5
-
ef6adb30
by ARATA Mizuki at 2026-11-06T06:48:31-05:00
testsuite: Mark T367_letnoescape fragile for the optllvm way
It was marked broken, but it is now unexpectedly passing on aarch64-linux-deb13-validate+llvm.
Marking it fragile for now.
See #7292
-
1db5f9d7
by Rodrigo Mesquita at 2026-11-06T06:49:13-05:00
interp: Make resumeExec and ExecBreak use `Resume` directly
Previously, `Resume` contexts were just put directly in the global
interactive environment state, so they were only accessible through it.
However, in the context of multi-threaded debugging, in that many
threads may hit breakpoints, it no longer suffices to have a global
linear list of breakpoints hit. We need a per-breakpoint Resume context
and need to be able to wield it directly rather than going through a
global context.
The driving changes of this commit are:
- Put the Resume data in ExecBreak
- Make resumeExec receive a Resume as an argument
This also simplifies the interpreter in that we no longer necessarily
rely on the global interactive state to resume a thread. We can do it
directly from the ExecBreak.
The interactive context still maintains a stack of resumes, but
`resumeExec` can no longer pop the resume it resumes off of the
breakpoints stack, since it is no longer guaranteed to be resuming the
first in that list. Hence, callers of `resumeExec` must update ic_resume
on their own.
Fixes #28058
-
fd00a88c
by Rodrigo Mesquita at 2026-11-06T06:49:54-05:00
Per-thread break-on exception (TSO_STOP_ON_EXCEPTION)
The `-fbreak-on-exception` flag allows the interactive interpreter to stop
when a synchronous exception is raised.
However, this is a global toggle backed by a global variable in the RTS
(rts_stop_on_exception) which is not compatible with a multi-threaded
debugger where we may want to stop if some threads raise a synchronous
exception but not other.
This commit makes -break-on-exception similar to step-next and step-out
where there is a per-thread toggle on each TSO (TSO_STOP_ON_EXCEPTION),
and that break-on-exception set in EvalOpts when resuming a statement
only affect the thread being resumed.
Fixes #28068
-
d735b507
by Andrea Vezzosi at 2026-11-06T06:50:35-05:00
driver: Don't let -dynamic unset -fsplit-sections
`addWay' WayDyn` used to unset Opt_SplitSections, so -fsplit-sections was
ignored if it came before -dynamic, but worked if it came after.
The -fsplit-sections -dynamic combination has legitimate uses, e.g. an
executable can be linked dynamically against libraries and still have dead code
from its own sources to eliminate. Or the same objects could be used for both
static archives and shared objects.
The removal of Opt_SplitSections was also motivated by problems on Darwin.
It is now done in `makeDynFlagsConsistent` instead, see Note [Split sections are not
supported on Mach-O].
For consistency, we also keep Opt_SplitSections when `dynamicNow` is activated.
There is a cost of larger .dyn_o (but not .so) files and slower link times (esp.
with ld.bfd), but does not seem significant enough to warrant special casing.
Fixes #28061
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
10e36bd2
by Alan Zimmerman at 2026-11-06T06:51:18-05:00
EPA: Use AnnList in AnnClassDecl
Capture parser layout
-
20334e1d
by sheaf at 2026-11-06T06:52:06-05:00
Avoid panic in 'solveImplicationsUsingUnsatGiven'
Commit 52a4d1da refactored this code to use 'setWantedDict' which panics
for equality constraints. This commit fixes that by explicitly handling
HoleDest.
Fixes #28081
-
0423f413
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
testsuite: add tests for the IO manager lock-up of #21969
T21969a 'closeFdWith' takes every 'EventManager''s 'callbackTableVar'
inside 'uninterruptibleMask_' and only puts them back on the paths
that do not throw, so a throw from 'closeFd_' leaves those MVars
empty for good. Afterwards every 'threadWaitRead' and
'closeFdWith' on an fd in the same bucket blocks forever.
T21969b 'closeFdWith' runs the fd's callbacks while asynchronous exceptions
are uninterruptibly masked, so a callback that blocks makes the
thread calling it permanently unkillable.
T21969c 'closeFd_' drops the registrations before telling the backend to
forget the fd, so when the backend throws the fd is never closed
and the threads waiting on it are never woken.
T21969d the cleanup handler of 'threadWait' calls 'unregisterFd_', which
throws on backend errors. It runs inside the handler for the
asynchronous exception being delivered, so its exception replaces
that one: 'killThread' returns but 'ThreadKilled' never arrives.
T21969e an exception from re-arming an fd escapes the poll loop, and 'loop'
turns it into 'cleanup mgr': the 'EventManager' of that capability
is shut down and every thread using it is left blocked. This is
the lock-up of #21969 itself.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
5c197e2e
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
Make the IO manager cope with errors from the polling backend (#21969)
Three changes in 'GHC.Internal.Event.Thread': 'closeFdWith' puts every
'callbackTableVar' back on the paths that throw too and no longer skips the
callbacks when 'close' fails, those callbacks now run under the 'mask_' of
'close_loop' rather than uninterruptibly masked, and the cleanup of
'threadWait' ignores a failure from 'unregisterFd_'.
This fixes T21969a, T21969b and T21969d, and clears their expect_broken.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
cb765ded
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
Do not let backend errors abandon the close of a file descriptor (#21969)
'closeFd_' and 'closeFd' now ignore errors from telling the backend to forget
the fd: the registration is being torn down and the error says it is already
gone. 'registerFd_' still reports them (!10643), where the caller has to
learn that the registration did not happen. Both also test
'I.elEvent oldEls /= mempty' rather than 'oldEls /= mempty'.
This fixes T21969c, and clears its expect_broken.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
9073bc43
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
Do not let a backend error take down a capability's IO manager (#21969)
A failure to re-arm an fd in 'selectCallbacks' is now handled the way
'registerFd_' handles one (!10643): the registrations are taken back out of
the callback table and returned, so their callbacks run and the waiting
threads find out for themselves instead of hanging. Checked on aarch64 Linux
(epoll) and aarch64 macOS (kqueue), 10 runs each way.
This fixes T21969e, and clears its expect_broken.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
cdff4e76
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
Do not let the deregistration of threadWaitSTM throw either (#21969)
'threadWaitReadSTM' and 'threadWaitWriteSTM' return the action that gives up
interest in the fd as the second component of their pair, and it was
return (waitAction, unregisterFd_ mgr reg >> return ())
'unregisterFd_' talks to the polling backend, which throws on errors such as
ENOENT and EBADF -- which is how a backend reports an fd it no longer knows,
once that fd has been closed without going through 'closeFdWith'.
That is the same shape as the cleanup of 'threadWait', which the rest of this
series made quiet, and it is the same on both counts. There is nothing to
decide: the registration is being abandoned, and "the backend does not know
this fd" is the state the action is trying to reach. And it does harm: the
action is what a caller uses from the cleanup of a 'bracket', where an
exception out of it replaces whatever was being propagated.
It now goes through 'quietUnregisterFd', as the cleanup of 'threadWait' does,
and that function's comment covers both callers.
T21969f covers it, and is deterministic on both backends: dropping the only
registration changes the event set, so 'unregisterFd_' always reaches the
backend.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
a7ed305b
by Kazu Yamamoto at 2026-11-07T08:06:59+09:00
testsuite: let T21969 run on FreeBSD, and unmark it (#21969, #25512)
T21969 now carries the descriptor from 'createPipe' instead of recovering it
with 'handleToFd', which rejects the 'DuplexHandle' that FreeBSD's
bidirectional pipes become and killed the test in setup there (#25512). The
expect_broken goes with it: with the descriptor problem out of the way the
test times out on master, so it can only be unmarked on top of this series.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
3074ae61
by Sylvain Henry at 2026-11-08T10:21:50-05:00
rts: heap census counts every small pinned object
Blocks of small pinned objects carry BF_LARGE as well as BF_PINNED but
hold many objects. heapCensusChain treated every BF_LARGE block whose
first object is an ARR_WORDS as holding that single object, a workaround
for the slop left by shrinkMutableByteArray# (#11627). So every heap
profile mode under-reported pinned byte arrays, i.e. ByteString payloads.
Shrinking now writes a slop marker that skipSlop understands (#19048,
#27585), so the block walk is safe for large and pinned blocks alike.
The block that a capability fills with small pinned objects stays
attached to the capability until it is full (see allocatePinned), so it
is on no generation list and the census never saw its objects. heapCensus
now walks cap->pinned_object_block too.
A pinned block is kept or freed as a whole (#28005), so dead pinned
objects are counted until their block is freed. T7275 gains one sample in
which its dead small arrays still show. The user guide and changelog
document this.
T7257 retains most of its pinned blocks and takes a census at every GC
(+RTS -i0 -hT), so walking every pinned object made it 7x slower and it
hit the CI timeout. It now runs 1000000 iterations instead of 5000000.
Metric Decrease:
T7257
Fixes #28000
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
16fd075a
by Sylvain Henry at 2026-11-08T10:22:39-05:00
rts: fix GC CPU time accounting with idle GC threads (#26169)
stat_endGC summed gc_end_cpu - gc_start_cpu over every GC thread, but
only the threads that take part in a collection set these fields, and
new_gc_thread did not initialise them. With -qn below the capability
count, the first collection after setNumCapabilities added garbage to
the GC CPU time.
Let each participating thread add its own CPU time to an accumulator
in stat_endGCWorker, and let stat_endGC take the total. This removes
the loop over gc_threads, the reset from #21082 and the gc_end_cpu
field. Also drop the unused gc_end_elapsed field.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
0ef732e2
by Sylvain Henry at 2026-11-08T10:23:30-05:00
Serialized: encode numbers with LEB128
serializeWithData used the Binary instances of Data.Binary for the
numbers in a ConstrRep. They have a fixed width: 8 bytes for the
constructor index (an Int) and 5 bytes for a small Integer. Each
element of a [Int] cost 15 bytes.
Now the constructor representation is one unsigned LEB128 number that
also contains the index of an algebraic constructor, and the payloads
(Integer, Rational, Char) are LEB128 encoded. Most constructors take
one byte, and small numbers two. See Note [Serialized encoding].
Sizes measured by the T16841 test:
[1..100] :: [Int] 1509 -> 338 bytes
"helloworld" 119 -> 31 bytes
2^100 :: Integer 24 -> 16 bytes
Just True 18 -> 2 bytes
3.25 :: Double 11 -> 3 bytes
42 :: Int 6 -> 2 bytes
A new test, SerializedRoundTrip, round-trips values at the boundaries
of the encoding (negative numbers, big Integers, Rationals, Chars).
Follow-up to !16841 (#28002).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
22344fbc
by Sylvain Henry at 2026-11-08T10:24:21-05:00
docs: fix duplicate label in qualified_strings.rst
The file started with the label "multiline-strings", copied from
multiline_strings.rst. Sphinx warned about the duplicate label on every
build. Use the label "qualified-strings" instead.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
b7022624
by Alan Zimmerman at 2026-11-08T10:25:02-05:00
EPA: Use LHsLocalBinds instead of HsLocalBinds
This reverses an earlier change, and brings processing of local binds
into alignement with the exact printing principle that the LocatedA
contents provide the location and extent of the enclosed item,
together with any comments or context-specific trailing items like
commas or semi colons.
The internal TTG extension points only carry exact print annotations
related to printing the item within its bounds.
This change brings back the problem of EmptyLocalBinds, which by
definition cannot have a location. These get a noSrcSpan location,
which is ignored in the exact printing process.
-
bc2fae45
by Rodrigo Mesquita at 2026-11-08T18:37:40-05:00
Build EvalOpts once per exec rather than per breakpoint stop
We were unnecessarily constructing `eval_opts` in `handleRunStatus`
(which is run many times in a loop until we hit a breakpoint we care
about, e.g. when :steplocal), despite the `eval_opts` being constant
across all these runs.
So, construct `eval_opts` outside `handleRunStatus` and share the value
in all loop calls. The loop always uses the same eval_opts, so no point
in constructing them inside `handleRunStatus` from scratch every time.
I found out about the significance of this re-construction of `EvalOpts`
when I added a record update of `eval_opts` *after* the construction
from scratch inside `handleRunStatus` that regressed allocations
significantly.
This improves the performance of `interpreter_steplocal` on my machine:
Baseline
Test Metric value New value Change
-------------------------------------------------------------------------
interpreter_steplocal(ghci) ghc/alloc 459,845,696 449,843,480 -2.2%
Fixes #28068
-
ba579288
by Rodrigo Mesquita at 2026-11-08T18:38:21-05:00
refactor: move and order helper functions in GHCi.Run
A small refactor to the order of top-level functions in GHCi.Run
-
24927752
by Luite Stegeman at 2026-11-09T09:21:24-05:00
rts: add missing nonmoving write barrier in out-of-line array copies
The out-of-line entries stg_copyArrayzh/stg_copyMutableArrayzh (taken
whenever the element count of copyArray#/copyMutableArray# is not a
compile-time constant) didn't push the overwritten elements to the
nonmoving collector's remembered set.
Fixes #27376
-
6dbcca65
by Rodrigo Mesquita at 2026-11-09T09:22:06-05:00
interp: Set per-thread break flags consistently on eval/resume
Currently, the per-thread flags are:
- Single-step: Stop at the immediate next breakpoint in this thread
- Step-out: Stop at the next continuation with a breakpoint this thread
returns to.
- Break-on-exception: Stop the next time a synchronous exception is
raised in this thread.
Originally, these flags were all set globally across all threads. More
recently, these flags are set per-thread when `resume`ing that thread,
but globally when starting the evaluation of a new expression
(`evalStmt`).
With this commit, we now use per-TSO flags in both scenarios evaluating
expressions in the interpreter (`evalStmt` and `resumeStmt`).
- In `resumeStmt` we set the `EvalOpts` specifically in the `ThreadId`
being resumed.
- In `evalStmt`, we set the `EvalOpts` exclusively on the sandbox thread
we fork to evaluate the given expression
- When not using the sandbox thread (i.e. -fno-ghci-sandbox), we
don't support the debugger anyway, so the break flags are
irrelevant.
We do this by consistently calling `setBreakFlags` when starting,
resuming, or killing the evaluation.
See Note [Always setBreakFlags on running thread].
This slightly changes the behavior of evaluating a new expression in
the debugger (resuming a thread behaves the same as before). Namely,
`:step <expr>`, where <expr> forks a thread, will stop at the immediate
next breakpoint in the <expr> main thread, not on a breakpoint of any
forked thread.
NB: the forked thread may still stop at breakpoint, if it is enabled by
index specifically, and then :step-ing from that thread's breakpoint
will toggle per-thread stepping for that forked thread.
We will want to control stepping in "all threads, regardless of whether
we control them or if they were spawned by the debuggee" separately from
the commands which trigger evaluation of just an expression. Namely,
we'll likely want a "break at the next immediate breakpoint hit on ANY
thread" command that the user can execute before launching a debuggee
which is multi-threaded. This may even be the default for GHCi.
Towards #26064
Fixes #28080
-
19ff36f2
by Simon Jakobi at 2026-11-09T09:22:47-05:00
testsuite: Mark T8209 fragile for the ghci ways on FreeBSD and darwin
A shutdown race in the I/O manager intermittently fails T8209(ghci) on
x86_64-freebsd14-validate and aarch64-darwin-validate, recently killing
several Marge batches. Mark it fragile there until the race is fixed.
See #27948.
Assisted-by: Claude Opus 5.5
-
212c292f
by Rajkumar Natarajan at 2026-11-11T13:54:08-05:00
document what ->>> stands for in heap profile
updates the profiling section of the user's guide to explain how types
are approximated when using -hy. Also adds haddocks to getTyDescription
with the same information.
Fixes #26754
-
c64fc319
by Jonathan at 2026-11-11T13:54:55-05:00
Fix AArch64 veneer target for relocations with an addend
Fixes #27807
The RTS linker would construct invalid relocation veneers on AArch64 if
the addend was non-zero, which typically caused SIGILL crashes. This
could be triggered by evaluating Template Haskell in a package with a
large number of dependencies using a static build of GHC.
-
cd4dce19
by Kazu Yamamoto at 2026-11-11T13:55:45-05:00
testsuite: add a test for registerFd_ trusting the callback table (#27821)
registerFd001 shows a 'threadWaitRead' that never finishes after an fd is
closed with 'closeFd' rather than 'closeFdWith'. Darwin is the only platform
this reaches -- one-shot registrations are implemented but not used there
(#7651) -- so the test is expect_broken on Darwin only.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
5ab442ee
by Kazu Yamamoto at 2026-11-11T13:55:45-05:00
registerFd_: always tell the polling backend (#27821)
Where the backend has no one-shot registrations, 'registerFd_' now tells it
about every registration, rather than only when the events differ from the
ones the callback table records: the table alone cannot say whether the
backend still knows the fd. The 'modify' it returns is unchanged. See Note
[Do not trust the callback table].
This fixes registerFd001 and clears its expect_broken.
Changelog wording from Duncan Coutts in review.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-
ab8b5b06
by Vladislav Zavialov at 2026-11-11T13:56:27-05:00
Curried contexts in prefix GADT constructors (#27424)
Prefix GADT constructor declarations now accept multiple consecutive
contexts, equivalent to a single conjoined context:
data G a where
MkCurried :: C a => (D a, E a) => G a
MkConjoined :: (C a, D a, E a) => G a
This is a step towards GHC Proposal #402 "Stable GADT constructor syntax".
To represent multiple contexts, the `con_mb_cxt` field of `ConDeclGADT` has
been replaced by `con_cxts`, which stores a list instead of a Maybe:
- con_mb_cxt :: Maybe (LHsContext pass)
+ con_cxts :: [LHsContext pass]
The rest of this patch follows from this change.
Note that in ConDeclH98, the optional context is still stored as a Maybe.
To accommodate this difference, a few helper functions were generalised over
a Foldable container `t`:
hsConDeclTheta :: Foldable t => t (LHsContext ...) -> [LHsType ...]
pprLHsContext :: (Foldable t, ...) => t (LHsContext ...) -> SDoc
repContexts :: Foldable t => t (LHsContext GhcRn) -> MetaM (Core (M TH.Cxt))
tcHsContext :: Foldable t => t (LHsContext GhcRn) -> TcM [PredType]
In practice, the instantiations of `t` are either `Maybe` or `[]`.
Record-style GADT constructors continue to accept at most one context.
`splitLHsGadtTy` accounts for this by splitting off only the first context
if it detects record syntax, leaving the offending part of the type in the
body for the renamer to reject later on.
Test cases: T12087a T27424a T27424b T27424c T27424d GadtConSigs_th_dump1
-
d2f135ff
by Sylvain Henry at 2026-11-11T13:57:22-05:00
NCG: cache register usage in liveness annotations
regUsageOfInstr allocates fresh register lists on every call, and on the
linear allocator path it was called three times per instruction: in the
backward liveness pass, in the forward liveness pass and in the allocator
itself. Store the usage computed by the backward pass in the Liveness
annotation and reuse it in the other passes (and in the graph allocator's
spill passes). patchRegsLiveInstr recomputes it for the patched
instruction.
See Note [Cached register usage in liveness annotations].
Part of #28008.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
ff0a5d32
by Sylvain Henry at 2026-11-11T13:57:22-05:00
NCG: describe register usage with a small DSL
This new register usage DSL (see Note [Register usage DSL] in
GHC.CmmToAsm.RegUsage) reduces allocation compared to the previous
list-based approach.
Fixes #28008.
Metric Decrease:
ManyAlternatives
T12707
T13035
T13379
T13960
T18698b
T19695
T21839c
T3064
T3294
T4801
T5321FD
T5321Fun
T783
T9198
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
51f38f3a
by Sylvain Henry at 2026-11-11T13:58:14-05:00
haddock-library: fix the build of the spec and fixtures test suites
The documentation pipeline moved from String to Text (commit 202ed264141)
but the two test suites of haddock-library were left behind and no
longer compiled. They are not run by GHC's CI (see #16206), so this went
unnoticed.
The fixtures suite still has four pre-existing failures (list-blocks1,
table1, table4, table5) that are not addressed here.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
394d9d6d
by Sylvain Henry at 2026-11-11T13:58:14-05:00
haddock: parse backtick spans as monospaced text
A backtick span whose content is not a valid Haskell identifier, such as
`foo bar`, was rendered as plain text with literal backticks. It is now
parsed as monospaced text, like @foo bar@. A closed backtick span whose
whole content is one identifier keeps its meaning as a hyperlinked
identifier. A span such as `foldl' f z xs` is code: it is no longer read
as the identifier foldl between a backtick and a single quote. The
TeX-style form `foo' stays an identifier when no backtick closes the
span on the same line.
Code spans follow the CommonMark rules: a span opened by a run of N
backticks ends at the next run of exactly N backticks on the same line,
so ``x `plus` y`` is code "x `plus` y". One space is removed at each end
when both are present, and an unclosed opening run is plain text. The
content is literal: no markup is parsed and backslashes are kept, so
`\x -> x` renders as written.
See Note [Backtick code spans] in Documentation.Haddock.Parser.
Fixes #28090
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
7ae41c37
by Sylvain Henry at 2026-11-11T13:58:14-05:00
Use 'T' instead of `T' in Haddock comments next to backtick spans
With backtick code spans, a TeX-style quote `T' followed by a backtick on
the same line opens a code span up to that backtick. Use the 'T' form in
the Haddock comments where this happens.
See Note [Backtick code spans] in Documentation.Haddock.Parser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
ce96f0b6
by Sylvain Henry at 2026-11-11T13:58:14-05:00
haddock: do not parse backtick spans inside @...@
Text between @...@ is already code, so backtick code spans are no longer
parsed there. Thus in
@x <- f -- of type `M Bool`@
the backticks stay as text. Inline markup inside @...@, such as /.../,
passes this context down.
See Note [Backticks in code] in Documentation.Haddock.Parser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
744b3036
by Sylvain Henry at 2026-11-11T13:58:15-05:00
haddock: keep the backticks of infix identifiers inside @...@
A backticked identifier inside @...@ was always rendered without its
backticks, so @f `elem` xs@ rendered as "f elem xs". Now an identifier
in an infix application or an operator section, such as @f `elem` xs@
or @(`elem` xs)@, is parsed in infix form, as if written ``elem``, and
renders with its backticks and with elem linked. Elsewhere, as in
@`foldlM` :: ...@, the backticks still only mark the link.
See Note [Backticks in code] in Documentation.Haddock.Parser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
0d8e1f8d
by Sylvain Henry at 2026-11-11T13:59:05-05:00
PPC NCG: print non-standard NaN literals in target byte order
The PowerPC NCG printed a non-standard NaN literal byte by byte with
floatToBytes/doubleToBytes, which use the byte order of the host. This
is wrong when the host and the target have a different endianness (e.g.
from x86_64 to big-endian PowerPC). Print the bits with `.long`/`.quad`
instead, so that the assembler uses the target byte order.
Also make `ppr_item` print its argument: some clauses printed the
literal of `pprDataItem` instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
5a9db1ed
by Sylvain Henry at 2026-11-11T13:59:05-05:00
Print all NaN literals as integer bits (#28101)
The x86 and PowerPC NCGs printed the quiet NaNs 0x7fc00000 and
0x7ff8000000000000 as `.float NaN`/`.double NaN`. GNU as and clang
encode these with all mantissa bits set, so constant-folded bit casts
of these values gave 0x7fffffff/0x7fffffffffffffff. The C backend
printed every NaN as `NAN`, losing its sign and payload.
Now the NCGs print all NaNs with `.long`/`.quad` and the C backend with
hs_bitcastword2float/hs_bitcastword642double.
See Note [Printing NaN literals].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
b4ceb6a9
by mangoiv at 2026-11-11T13:59:47-05:00
ci: fix ghcup nightly script misbehaviour
- download all jobs instead of just the first 100
- stop using a canary job to detect whether it's a nightly or release
pipeline
-
aefa0c1b
by Alan Zimmerman at 2026-11-11T14:00:28-05:00
EPA: Use AnnList in HsMultiIf
It introduces layout, capture it
-
d72505e4
by Simon Jakobi at 2026-11-12T15:26:14-05:00
testsuite: Fix T17088 flakiness and restore bug coverage
T17088 reads and prints a byte from an uninitialized array. Debug RTS
ways fill allocated memory with 0xaa, so the test can fail due to an
output mismatch unrelated to the pointer-tagging bug it covers.
Initialize the byte to zero to make the output deterministic.
The original bug requires the compacting collector and particular
compiler and RTS settings. Run the test only in the compacting_gc way
with -O1 and -A128k. Also disable STG lambda lifting because it removes
the closure shape needed to reproduce the pointer-tagging failure.
This makes the test reliable while ensuring it remains an effective
reproducer for #17088.
Closes #27534.
Assisted-by: gpt-5.6-sol via Codex CLI
-
5a7591b3
by David Eichmann at 2026-11-12T15:26:56-05:00
testsuite: Fix python type errors
These errors appear when using the VSCode python extension which uses
Pylance under the hood.
-
52f129f8
by David Eichmann at 2026-11-12T15:26:56-05:00
Add test modifier to test over all IO Managers
-
22e8b92a
by David Eichmann at 2026-11-12T15:26:56-05:00
testsuite: include custom IO Manager in test name
-
82c34ccd
by Simon Jakobi at 2026-11-12T15:27:40-05:00
Make T2464 actually test #ifdef'd pragmas
The test guarded a LANGUAGE EmptyDataDecls pragma behind #if, but
EmptyDataDecls is on by default since Haskell2010, so the module
compiled even when the guarded pragma was ignored. Guard MagicHash
instead, which is unlikely to be included in a future default language.
The test also checks that warnings from file-header pragmas are emitted
only once, even though the pragmas are parsed both before and after
CPP, using the -fffi deprecation warning as the canary. Use an
unrecognised warning flag instead, so the test no longer depends on a
deprecated flag that is about to be removed.
Context: #27939
Assisted-by: Claude Fable 5.1
-
419f2a12
by Simon Jakobi at 2026-11-12T15:27:40-05:00
Remove command-line flags deprecated in GHC 8.2 or earlier
Also remove the INCLUDE file-header pragma, which only expanded to
the now-removed -#include.
Closes #27939.
Assisted-by: Claude Fable 5.1
-
adc294d0
by Erik de Castro Lopo at 2026-11-12T15:28:21-05:00
TimerManager: publish only evaluated timeout queues (#9809)
The issue in #9809 was triggered by many threads registering timeouts
at the same time and those timeouts being stored as unevaluated thunks
in the shared list. When say 100,000 timeouts are registered at the
same time, the program can be slowed down considerably and the memory
usage grow unacceptably large.
The commit that caused the problem was 2d5eccdf1c, a 2013 change that
fixed #7653.
The fix is to add a modifyTimeouts function which applies an edit to a
copy of the list and fully evaluates the result before replacing the
shared list with a CAS operation.
Performance has improved for the threaded case and not regressed for
the single thread case:
Forked registrations of 100k timeouts (median of 5 runs):
-N4: 0.577 s, 428 MB -> 0.078 s, 39 MB
-N12: 1.227 s, 479 MB -> 0.127 s, 80 MB
Forked registrations of 1M timeouts on -N1 (median of 3 and 10 runs):
5.21 s (range 0.67-9.47 s), 1613 MB -> 0.67 s, 250 MB
Single-thread registrations are unchanged or slightly faster, and timer
latency during registration storms improves (p99 lateness of a 1 ms
threadDelay during 100k forked registrations on -N4: 302-394 ms ->
3.5-4.1 ms).
The registration code still runs in constant stack, so #7653 stays fixed;
T7653 and the concurrent, base and ghc-internal testsuites pass.
modifyTimeouts is OPAQUE so that the optimiser cannot expose the edit
function's inspection of the old queue next to the compare-and-swap and
replace the expected pointer with the evaluated queue, which would make the
compare-and-swap keep failing when the MutVar# holds a thunk or indirection.
Regression test T9809.hs included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
b294b82f
by Moritz Angermann at 2026-11-12T15:28:21-05:00
testsuite: give pause_resume_via_safe_ffi_concurrent 60s on Darwin CI
The 10s System.Timeout watchdog was a false deadlock: five serialized
1s pauses plus rts_pause waiting on threadDelay/timer-manager traffic
overruns that budget on loaded Mac runners. Keep a watchdog so a real
hang still fails.
-
1543f834
by Simon Jakobi at 2026-11-12T15:29:03-05:00
testsuite/README: Don't append new tests at the end of all.T
Patches that each add a test at the end of the same all.T conflict
with each other. Tests added elsewhere in the file usually merge cleanly.
Context: #26285
Assisted-by: Claude Opus 5.5
-
9ad25cb2
by Sven Tennie at 2026-11-14T06:20:13-05:00
hadrian: Add Stage3 cross-compiled target bindist (#26924)
Add a `binary-dist-stage3` Hadrian target that packages target
executables (produced by the stage2 compiler) into a separate
'_build/bindist-stage3/' folder, distinct from the stage2 regular or
cross-compiler bindist in '_build/bindist/'.
This allows a single CI pipeline job to produce both a cross-compiler
bindist (e.g. x86_64 -> RISC-V) and a target-architecture bindist (e.g.
RISC-V -> RISC-V) that can be installed and run natively on the target.
To avoid issues with stale files or race-conditions on them, generate
the `configure` script per stage in `_build/<stage>/distrib`
directories.
-
ca91017d
by Sven Tennie at 2026-11-14T06:20:13-05:00
ci: Build Stage3 and Stage2 bindists for cross targets in one job (#26924)
Building the stage3 target bindist already produces most of the stage2
cross-compiler bindist as a byproduct, so building them in separate jobs
duplicates the build efforts for no benefit. Instead of a separate
CROSS_STAGE=3 job, the stage3 job now also builds and publishes the
stage2 bindist.
The stage3 tarball is named and versioned as if it were built natively
on the target (target triple prefix, non-cross opsys), so its artifact
name stays what downstream consumers already expect and no changes are
needed on their side.
For now, this is only enabled for the RISC-V job. Others can easily
follow.
-
71b41e09
by Sven Tennie at 2026-11-14T06:20:14-05:00
ci: model cross targets as structured TargetPlatform triples (#26924)
Storing the cross target as a raw triple forced ad-hoc parsing at every
use, and broke the single responsibility rule. Modelling it as a
structured `TargetPlatform`` instead, avoids parsing and provides a
clear separation of concerns.
-
8067c2f9
by Sven Tennie at 2026-11-14T06:20:14-05:00
ci: extract the cross smoke tests into a separate smoke_test command (#26924)
This reduces if-nesting and complexity of the main `test_hadrian`
command. The decision how to test is now made by the caller. This is a
fair choice, because most test cases can run under emulation - they are
just very slow then.
The Stage3 smoke test also checks that the target compiler does not report
itself as cross-compiling and, when supported, runs a small GHCi expression.
-
7ece99a7
by fendor at 2026-11-14T06:20:57-05:00
Add `-dep-json` flag to `ghc -M`
Add an optional flag to `ghc -M` that allows to write the dependency
information in JSON Lines format.
The JSON Lines format enables us to stream the output of the dependency
generation to a consumer.
The output of `-dep-json` is streamed to a temporary file and then
copied to the final destination to avoid partial writes.
Each line contains one of two possible json objects:
1. A Home Unit Dependency
* Contains the name of the home module, its unit, where it is
located, whether a preprocessor is used, and all of its imports.
Importantly, the imports include `-XExplicitLevelImports`
information.
* If requested via `-include-pkg-deps`, includes imports of external
units, e.g. modules from `base`.
* If requested via `-include-cpp-deps`, files included via CPP.
2. External Unit Dependency
* Only if `-include-pkg-deps` is given
* Contains unit-id, its package name and package id.
---
This PR refactors the Makefile generation to use phases appropriately.
We introduce an intermediate data structure that is generated based on
the module graph nodes, and only then generate the Makefile rules.
This allows the dep-json and dep-makefile generation to use the same
dependency processing.
-
0f6e0146
by fendor at 2026-11-14T06:20:57-05:00
Add multiple home unit support to `ghc -M`
Allows to process the module graph of multiple home units at once using
the same syntax as `--make` and `--interactive`:
ghc -M -unit @unitA -unit @unitB
The semantics are identical to `--make` and `--interactive`.
Each home unit can declare individually to use `-include-cpp-deps` and
`-include-pkg-deps`.
However, there can only be one output file, and `-dep-json` and
`-dep-makefile` can only be provided at the top of the cli invocation.
We introduce a new GHC API `doMkDepend` that allows to use multiple home
units conveniently.
The output of `-dep-json` and `-dep-makefile` does not change, since we
were careful to choose a format that supports multiple home units from
the start.
Single home units are still accepted like before with no changes.
-
5598e6a0
by fendor at 2026-11-14T06:20:57-05:00
Deprecate `doMkDependHS` in favour of `doMkDepend`
-
39f2943e
by David Eichmann at 2026-11-14T06:21:41-05:00
rts: Expose getRtsSymbols() and store redirect labels and external symbols tag
-
aa159605
by David Eichmann at 2026-11-14T06:21:41-05:00
hadrian: when running tests, properly set have_gdb and have_readelf
-
ff826da4
by David Eichmann at 2026-11-14T06:21:41-05:00
testsuite: add have_ldd() test modifier
-
b9f0b7e2
by David Eichmann at 2026-11-14T06:21:41-05:00
testsuite driver: on windows, ensure PATH correctly contains mingw and ghc-pkg libraries
-
543c108e
by David Eichmann at 2026-11-14T06:21:41-05:00
testsuite: driver now sets WAY_FLAGS variable for makefile tests
-
13408a2b
by David Eichmann at 2026-11-14T06:21:41-05:00
Add golden test for rts/RtsSymbols.c
This test compares declared symbols against symbols observed
in the rts DSO (.so file).
-
b63a56c8
by Rodrigo Mesquita at 2026-11-15T14:49:28+01:00
Asynchronous RPC with external interpreter
There's a single pipe to connect the host compiler to the external
interpreter. On this pipe, we have historically done synchronous
request/reply communication to invoke methods on the external
interpreter.
However, with the advent of multi-threaded debugging, it has become
necessary to do asynchronous calls on the external interpreter, where we
may block on the host waiting for a reply, but the external interpreter
should handle the request asynchronously and reply when ready. For
instance, we want to start the evaluation of the debuggee but not block
the interpreter waiting for it to finish or hit a breakpoint. Or e.g. we
want to resume two threads of the debuggee simulatenously instead of
blocking waiting for the resume result of each one sequentially.
And it turns out, we were already doing some ad-hoc asynchronous
communication to evaluate Template Haskell on the external interpreter.
It used to go as an ad-hoc "send request without expecting reply",
followed by handling on the host a set of 'THMessage's sent by the
interpreter, followed by "expect a response to arrive now". It worked
because there was still a fixed order of messages, but it fits an async
model in a non-ad-hoc way.
Asynchronous communication that unblocks the external interpreter main
thread will also make it possible to resolve issues such as #18852
(exceptions leaving the external interpreter in an unrecoverrable state)
The new design
--------------
The new invariant: every single request should receive a matching reply.
The pipe is bidirectional (the ext. interpreter can receive requests,
but it can also send requests for TH evaluation; the host can send
requests, but it can also receive TH requests from the interpreter).
When a request is sent in whichever direction, it always contains a
correlation-id header. The Sender places an empty MVar on a
pending-reply map keyed by id and waits on it for a response.
See 'remoteCall' and 'remoteTHCall'.
The pipe is associated to a thread which drains the read end. Because
it's bidirectional, two things may be read off the pipe:
- A Reply, with a correlation-id header, which we match against the
pending requests map to unblock the corresponding pending-reply MVar
- A Request, which is queued to the pending-request queue.
To handle a message, we take a Request from the pending-request queue
and run a handler that produces a Reply. Currently, the handler is run
synchronously in the thread, but it is trivial to make the handler run
in a forked thread for certain ("interruptible") messages in an upcoming
patch (when it is necessary for the multi-threaded debugger).
See 'handleRemoteCall' and 'handleRemoteTHCall'.
The old interp lock now just protect the pipe writing (reads don't lock
bc they are done exclusively by drainPipe), it doesn't need nor should
lock the full remote procedure call.
Fixes #27960
-
c02b05c5
by Rodrigo Mesquita at 2026-11-15T14:49:28+01:00
interp: Add separate mailboxes for TH async RPC
When the host sends a `RunTH` command to the interpreter, it expects a
few "reverse requests" from the interpreter (e.g. `NewName`) which must
be run in the same context that initiated the `RunTH`.
When the host is evaluating many splices at once, it will send many
`RunTH` commands to the interpreter and start listening for reverse
requests in the meantime. However, a received request previously had no
way to be associated to the scope of a particular `RunTH` invocation, so
the reverse commands could get replied to from incorrect contexts, or
e.g. a `RunTHDone` from the interp. could terminate early the wrong
`RunTH` computation.
In this commit we add independent mailboxes to the interpreter
asynchronous RPC infrastructure, allowing a RunTH to announce a
particular `InboxId` that all reverse requests for that RunTH should
use. On the host, we create that mailbox id and have
`handleRemoteTHCall` listen on that specific mailbox rather than for
requests without a specific mailbox address.
-
2bce180f
by Rodrigo Mesquita at 2026-11-15T14:49:28+01:00
refactor: Move Async RPC abstraction into GHCi.Message.Async
Carves out the Async RPC over the Pipe abstraction to a new module,
making the GHCi.Message more about the specific interpreter messages
rather than about the IPC protocol.
-
13038cd0
by Rodrigo Mesquita at 2026-11-15T14:49:28+01:00
interp: If we have pending reads in the queue we can deliver them
We may still be able to reply even if the read end was closed.
As long as we have pending messages we should try to deliver them.
-
1fe95adc
by Andrea Vezzosi at 2026-11-15T14:49:28+01:00
interp: close Handles when done with Pipe
Ensures we close the pipe handles (if created using 'mkPipeFromHandles')
on `closePipe`, and do `closePipe` on `Shutdown`.
The thread draining the read end always `'finally'` closes the read end.
And `closePipe` kills the draining thread and closes the write end.
When `remoteAsyncReq`, we throw PipeReadClosedException if the pipe read is
closed, since we wouldn't be able to receive the reply.
It's fine for the drain thread not to close the write end, even if it
dies without `closePipe` (which does close the write end), because:
- requests pending a reply will get PipeClosedException (we'll not be
able to read any further "real" reply)
- new calls to `remoteAsyncReq` will throw PipeReadClosedException
- pending pipe writes, in response to an already read request, might still succeed
And the clean up code should call close pipe to ensure the write end is
closed as well.
So, if the drain thread dies naturally and the read end is closed, may
still be attempted to be used, but it will throw accordingly. The user
likely wants to catch this to close the write end as well.
-
50b6d6c4
by Zubin Duggal at 2026-11-15T14:49:28+01:00
interp: fix external interpreter shutdown deadlock on Windows
On shutdown both GHC and iserv call `closePipe`, which stopped the drain
thread before closing the write end. On Windows the drain thread reads
with a safe foreign call to _read, which `throwTo' can't interrupt, so
the two sides were stuck in the deadlock deadlock.
Closing the write end first is not enough on its own. On Windows a read
on a pipe only unblocks once all write handles to it are closed [1].
However, all all four pipe ends were inheritable and we didn't close the
child's ends in the parent. This means a close on any one side wouldn't
unblock any reads, becuase the other side had another copy open.
* runWithPipes now uses System.Process.CommunicationHandle [2], which is
built for passing pipes to a child process: only the child's ends are
inheritable, and it simplifies our mess of CPP. Additionally, it is
important to close our copy of the endpoints passed to the child so
each side only keeps open copies it needs to allow a close to unblock
reads.
* readGhcHandle makes the handle non-inheritable so we don't have
additional references floating around that stop reads from unblocking
on close.
* In closePipe the ordering is subtle and important. We first fail any
requests still waiting for a reply, then close the write end so the
other side sees EOF. We take the write lock to close it, so we never
close under a concurrent write [3]. Only then do we stop the drain
thread, which closes the read end itself once its read has finished.
Bump bound to process >= 1.6.20 as this is the version with
System.Process.CommunicationHandle
[1] https://learn.microsoft.com/en-us/windows/win32/ipc/anonymous-pipe-operations
[2] https://github.com/haskell/process/pull/308
[3] https://gitlab.haskell.org/ghc/ghc/-/work_items/27801
-
e4c6f7ff
by Andrea Vezzosi at 2026-11-15T14:49:28+01:00
GHCi.Server: handle RunTH and RunModFinalizers in forked thread
This commit makes the external interpreter able to many interpret
template haskell splices in parallel without blocking the main server
thread. Simply: fork off a thread to handle a RunTH request. The handler
will issue the reverse-requests on the given RunTH mailbox, to keep each
RunTH isolated from the others.
`handleRemoteCall` was generalised slightly by allowing `WriteReply` to
be used linearly in the handler directly, so that the caller of
`handleRemoteCall` may `WriteReply` in the forked thread rather than in
the main thread.
The only question is how can we guarantee `WriteReply` is used linearly
if we want to use it inside a forked thread? We need two guarantees:
1. `WriteReply` is used in the forked thread regardless of whether an
exception is thrown to that thread.
2. The forked thread is always awaited for, so that the main program
doesn't exit before the thread has a chance to actually use
`WriteReply`.
We introduced a small `ThreadManager` which provides a `spawnFinally`
that provides these two guarantees:
1. is guaranteed by `forkFinally`, which always runs the clean up action
exactly once.
2. is guaranteed by `ThreadManager` being abstract and the only exposed
function that introduces `ThreadManager` being `withThreadManager`,
which always awaits for all spawned threads.
Co-authored-by: Rodrigo Mesquita <rodrigo.m.mesquita@gmail.com>
-
e5f4c636
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: spawn fillPipe thread, writePipe now safely interruptible
Previously an async exception during a call to `writePipe` could have caused a
partial write, making any further write impossible to parse from the other end.
Now `writePipe` merely pushes the message onto a queue, and the actual write
happens in a separate `fillPipe` thread. As a result of this and previous
changes, `interpCmd` no longer needs `interruptibleMask` to preserve the state
of the protocol.
`writePipe` waits for the actual write to complete, and rethrows exceptions
raised in the write attempt, if any.
-
95bf6456
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
Follow `Note [Exceptions in TH]` in `qReport` implementation
`qReport b msg` should use `seqList msg` to trigger any exceptions in the
`String`, as explained in the note.
Through refactors the `seqList msg` call followed the bulk of the implementation
in `GHC.Tc.Gen.Splice.report`, but the call should be in `qReport` itself, so
that, even with -fexternal-interpreter, `msg` gets forced right away and any
exceptions get reported as a compilation error.
Follow up to 'interp: spawn fillPipe thread, writePipe now safely
interruptible'.
-
c86bbf7f
by Rodrigo Mesquita at 2026-11-15T14:49:29+01: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
-
0a9fe296
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: cancel requests if async exceptions while waiting for reply.
-
b79b7199
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: do not terminate ext. interp. process on exception
`sendMessage` throwing an exception does not warrant terminating the external
interpreter process anymore, because communication can keep going no matter what.
`stopInterp` now resets the whole `Interp` state, so that a new
ExtInterpInstance can be later created and work correctly.
`withExtInterp` now calls `stopInterp` on a `PipeClosedException` and rethrows.
Fixes #18852
-
523eea29
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
remoteAsyncReq cleans up a pendingReply on exception.
-
d3da741b
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
remoteAsyncReq: send cancel if exception during writePipe
fixes gap in exception coverage.
-
86e01e71
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: single-threaded sendTHComputation
-
aecc6923
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: test: no deadlock when handleTHMessage throws.
it used to be that handleTHMessage throwing would neglect to notify and/or tear
down the external interpreter, causing it to deadlock (or fail with blocked
indefinitely).
Now we reply with the exception, before rethrowing it, so the external
interpreter can shutdown cleanly.
-
7af05b1c
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: test: panic in handleTHMessage does not deadlock
similar to TH_ReifyModuleFail but with a plugin.
-
c72bb720
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: cleanup on cancel
interp: don't drop pending frees if the drain is interrupted
interp: release RemoteRefs and RemotePtrs from replies of canceled requests
-
c18232cb
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: mask while handling RemoteRefs in dynLinkCompiledByteCode
Between 'createBCOs' and 'makeForeignNamedHValueRefs' the refs are not tracked,
so could have been leaked if interrupted.
Modified 'makeForeignNamedHValueRefs' so it does not have interruption points
when the interpreter is running.
-
688b96d7
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: return ForeignRef rather than RemoteRef whenever possible.
and more generally masking until a finalizer is attached.
Anything to do with EvalStatus_ is not fixed here, as it would require larger
changes to the API.
-
854366cb
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
linker: purge the symbol cache before unloading
Unloading might throw at which point it's uncertain which symbols are still
loaded, purging the symbol cache upfront means we don't risk holding a reference
to an unloaded symbol..
See Note [LoaderState may lag the interpreter].
-
db54fee2
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: add finalizer to ModFinalizer under mask
-
eca348e8
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
ghci: fixed 'freeForeignCallInfo' to properly free 'arg_types' array.
freeForeignCallInfo used to free the 'p->arg_types' field itself, rather than
the array it points to. Now reads the pointer stored at 'p->arg_types', frees
that, then frees 'p'.
-
b0114604
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: test resources are cleaned up when request interrupted.
-
580763a5
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: exit cleanly if pipe closed while replying to Shutdown.
iserv avoids reporting exceptions coming from pipe operations after we received
Shutdown: writing a reply after the host closed its end because the grace period
elapsed shouldn't look like a bug.
We do so by indicating the pipe is closing right after we receive Shutdown, so
both the main loop and any running handler threads can tell a closed pipe is
expected.
-
653e4ffc
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
template-haskell: force arguments of Q primitives up front.
Exceptions in arguments of 'Quote Q' and 'Quasi Q' were not detected until the
last minute, where they could cause panics or cause implementation details to
leak into error messages.
Now they are 'deepseq'eq up front, types permitting, so any exceptions are
cleanly reported as originating from the splice.
Follow up to 'Follow `Note [Exceptions in TH]` in `qReport` implementation'
which already handled the `qReport` case.
Fixes #28112
-
8c797068
by Andrea Vezzosi at 2026-11-15T14:49:29+01:00
interp: fix runWithPipes on Windows when without -threaded
Test 'static-plugin-interp-panic' happens to build without -threaded
and would timeout on Windows CI.
Turns out that in such a configuration the 'Handle's we get from
'System.Process.CommunicationHandle' cause the whole process to lock.
Rebuilding them with 'hANDLEToHandle' fixes it.