[Git][ghc/ghc][wip/case-bndr-unf] 15 commits: Fix a few tag inference bugs.
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC Commits: 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 - - - - - 71 changed files: - + changelog.d/25665 - + changelog.d/T27831-bottoming-strict-field - + changelog.d/T27842-bytecode-imported-tags - + changelog.d/unboxed-do - compiler/GHC/Core.hs - compiler/GHC/Core/Lint.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/Utils.hs - compiler/GHC/Core/Utils.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Stg/EnforceEpt.hs - compiler/GHC/Stg/EnforceEpt/Rewrite.hs - compiler/GHC/Stg/EnforceEpt/TagSig.hs - compiler/GHC/Stg/EnforceEpt/Types.hs - compiler/GHC/StgToJS/Linker/Linker.hs - compiler/GHC/StgToJS/Object.hs - compiler/GHC/Types/Id.hs - docs/users_guide/exts/qualified_do.rst - hadrian/src/Settings/Builders/Ar.hs - libraries/ghc-internal/CHANGELOG.md - libraries/ghc-internal/ghc-internal.cabal.in - libraries/ghc-internal/src/GHC/Internal/Bignum/Backend/GMP.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/Backend/Native.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/BigNat.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/Natural.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/Primitives.hs - libraries/ghc-internal/src/GHC/Internal/Bignum/WordArray.hs - + libraries/ghc-internal/src/GHC/Internal/Unboxed/Do.hs - + testsuite/tests/bytecode/T27842.hs - + testsuite/tests/bytecode/T27842.stdout - + testsuite/tests/bytecode/T27842A.hs - + testsuite/tests/bytecode/T27842N.hs - testsuite/tests/bytecode/all.T - testsuite/tests/javascript/Makefile - + testsuite/tests/javascript/T25665.hs - + testsuite/tests/javascript/T25665.pkg - + testsuite/tests/javascript/T25665.stdout - + testsuite/tests/javascript/T25665Lib.hs - + testsuite/tests/javascript/T25665_c.c - + testsuite/tests/javascript/T25665_js.js - testsuite/tests/javascript/all.T - testsuite/tests/qualifieddo/should_compile/all.T - + testsuite/tests/qualifieddo/should_compile/qdocompile003.hs - + testsuite/tests/qualifieddo/should_compile/qdocompile003.stderr - testsuite/tests/qualifieddo/should_fail/all.T - + testsuite/tests/qualifieddo/should_fail/qdofail006.hs - + testsuite/tests/qualifieddo/should_fail/qdofail006.stderr - testsuite/tests/qualifieddo/should_run/all.T - + testsuite/tests/qualifieddo/should_run/qdorun008.hs - + testsuite/tests/qualifieddo/should_run/qdorun008.stdout - + 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/all.T - testsuite/tests/simplStg/should_compile/all.T - + testsuite/tests/simplStg/should_compile/inferTags005.hs - + testsuite/tests/simplStg/should_compile/inferTags005.stderr - + testsuite/tests/simplStg/should_compile/inferTags006.hs - + testsuite/tests/simplStg/should_compile/inferTags006.stderr - + testsuite/tests/simplStg/should_run/InferTags007_A.hs - + testsuite/tests/simplStg/should_run/T27831.hs - + testsuite/tests/simplStg/should_run/T27831.stdout - + testsuite/tests/simplStg/should_run/T27857.hs - + testsuite/tests/simplStg/should_run/T27857.stdout - testsuite/tests/simplStg/should_run/all.T - + testsuite/tests/simplStg/should_run/inferTags007.hs - + testsuite/tests/simplStg/should_run/inferTags007.stdout The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f48ae9853ff76e84ecda2b5f8de1ac4... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f48ae9853ff76e84ecda2b5f8de1ac4... 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
participants (1)
-
Simon Peyton Jones (@simonpj)