-
6bbca569
by Andreas Klebinger at 2026-10-21T10:01:10+00:00
Fix a few tag inference bugs.
* Treat bottoming functions and nullary join points as functions.
* When generating bytecode don't rely on imported tag sigs.
Fixes #27831, #27841 and #27842.
-
71808e29
by Sylvain Henry at 2026-10-22T04:50:24-04:00
Add GHC.Internal.Unboxed.Do: do-notation for unboxed values (#27944)
QualifiedDo operators can be representation-polymorphic: a do-block is
expanded into ordinary applications before typechecking, and the only
check on a bound variable is the deferred fixed-runtime-rep check. A
representation-polymorphic (>>=) cannot be defined directly, though,
because its body would bind a variable of unknown representation.
The new module provides such operators for State#-passing code as
methods of a class indexed by RuntimeRep, with one instance per
representation. With optimisation the dictionaries disappear and a
block compiles to the usual nested case expressions:
Ubx.do { x <- readWordArray# mba 0# -- x :: Word#
; writeWordArray# mba 1# x -- unit actions are statements
; Ubx.pure x }
Also add users guide documentation and tests.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
33247780
by Sylvain Henry at 2026-10-22T04:50:24-04:00
Bignum: use Ubx.do for State#-passing code (#27944)
Rewrite the State#-passing code of the GHC.Internal.Bignum modules
(Primitives, WordArray, BigNat, Natural, Integer, Backend.Native,
Backend.GMP) with the qualified do-notation of GHC.Internal.Unboxed.Do.
Nested case chains such as
case newWordArray# sz s of { (# s, mwa #) ->
case act mwa s of { s ->
unsafeFreezeByteArray# mwa s }}
become
Ubx.do
mwa <- newWordArray# sz
act mwa
unsafeFreezeByteArray# mwa
The optimised Core is unchanged (compared per top-level binding).
BigNat now enables MonoLocalBinds: local loops written with Ubx.do
must stay monomorphic in the state type, otherwise GHC does not turn
them into join points.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-
593f5f5b
by Sylvain Henry at 2026-10-22T04:51:16-04:00
JS: remove archive padding after wasm objects (#25665)
On Darwin hosts, emar (llvm-ar) writes archives in the Darwin format when
the first member is not a known object file, which is the case for the
archives of the JS backend. This format pads each member to 8 bytes with
'\n' and includes the padding in the member size. Wasm objects do not
accept trailing bytes: wasm-ld failed with "section too large".
The JS linker now removes this padding when it extracts a wasm object from
an archive. In addition, Hadrian passes --format=gnu to emar for the JS
target. See Note [Wasm objects in Darwin archives].
Also document the format of Cc (wasm) objects in Note [Cc object format].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
ba8e329b
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Make pushCast pure, and move it to Simplify.Utils
pushCast and pushCastMCo were in the SimplM monad, but no longer do
anything monadic. (Historically, pushing a coercion into an argument
used to simplify that argument; but now the coercion is recorded in
the sc_cast field of ApplyToVal.)
This patch makes them pure functions, and moves them, together with
addCastMCo, optOutCoercion and Note [The sc_cast field of ApplyToVal],
from GHC.Core.Opt.Simplify.Iteration to GHC.Core.Opt.Simplify.Utils,
alongside the SimplCont type they manipulate.
No change in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
4519927e
by Simon Peyton Jones at 2026-10-22T17:46:09+01: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 the
new Note [Lambda and case binders have vanilla IdInfo] in GHC.Core.
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 such IdInfo, we now use a fresh binder for the join point
let x = <> in b ==> join j x' = let x = x' in b in j <>
See (DSB1) in Note [Duplicating StrictBind].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
d61f1a7f
by Simon Peyton Jones at 2026-10-22T17:46:09+01: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].
* 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@anthropic.com>
-
66e95655
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Fix the runRW# case of simplOutId to respect a pending cast
In the runRW# case of simplOutId, if the argument was a literal lambda
we took a short cut, simplifying the lambda body directly. But we
ignored any pending cast on the argument, arising from pushing a cast
into it; e.g. after inlining
myRun :: (State# RealWorld -> N) -> N
myRun = coerce (runRW# :: (State# RealWorld -> Int) -> Int)
That yielded ill-typed Core (#27962).
Fix: only take the short cut if there is no pending cast. Otherwise use
the general case, which deals with the cast properly.
Test: T27962, T27962a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
d0960e5b
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Get the DupFlag right in the runRW# case of simplOutId
In the runRW# case of simplOutId we built an ApplyToVal continuation
with sc_dup = OkDup, regardless of whether its tail, inner_cont, was
itself dupable. That violates invariant (AV2) in
Note [The argument of ApplyToVal], and could lead mkDupableCont to
duplicate a large continuation.
Fix: use OkDup only if (contIsDupable inner_cont).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
c503ddb7
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Add regression test for #27963
The bug itself was fixed by "Use SimplClo for the argument of ApplyToVal".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
fda04119
by Simon Peyton Jones at 2026-10-22T17:46:09+01: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).
No change in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
518ca15e
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Document evaluated-ness on case binders; tighten lamBndrInfoOK
Case binders and strict-field case-alternative binders carry an OtherCon
(evaluated-ness) unfolding in the syntax tree. This patch adds
Note [Evaluated-ness on case binders] in GHC.Core, explaining which passes
use that information and why it must be on the binder (many passes rebuild
occurrences from binders, notably CoreTidy just before CorePrep).
It also tightens GHC.Types.Id.lamBndrInfoOK, and hence the Core Lint check
on lambda, case, and case-alternative binders: previously it rejected only
stable unfoldings; now it allows only NoUnfolding or an OtherCon unfolding.
(Lambda binders are still separately required to have no unfolding at all.)
The tighter check exposed another source of bad case binders:
GHC.Core.Utils.bindNonRec (used by mkCoreLet, and hence the Simplifier's
wrapFloats) turns let x = rhs in body into a case when rhs is unlifted
and not ok-for-speculation, re-using the let-binder x, complete with its
let-unfolding (e.g. from makeTrivial), as the case binder. Now both
bindNonRec and the desugarer's seqVar use the new
GHC.Types.Id.mkCaseBndrFromLetBndr, which resets the binder's IdInfo
(except to record that it is evaluated).
See #27965.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
793bc0ba
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Wibble comments
-
04d6888e
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
SpecConstr: give the case binder in mkSeqs suitable IdInfo
mkSeqs (see Note [SpecConstr and strict fields]) builds
case arg of arg' { DEFAULT -> rhs }
where arg' is arg, localised. But arg may have IdInfo that a case binder
must not have; e.g. in test T24944 it was an imported global with a
top-level unfolding, which tripped the new Core Lint check. Use
mkCaseBndrFromLetBndr. See Note [Lambda and case binders have vanilla
IdInfo] in GHC.Core, and #27965.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
4fd3480f
by Simon Peyton Jones at 2026-10-22T17:46:09+01:00
Wibbles