Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: a4c177e8 by sheaf at 2026-10-18T13:53:28-04:00 Carefully implement coercion zapping This commit implements coercion zapping in the rewriter, controlled by the -fzap-coercions flag (on by default). This significantly reduces the size of coercions produced when rewriting type family applications, resulting in much faster compilation. See Note [Coercion zapping] in GHC.Tc.Solver.Rewrite for an explanation and further details. The rewriter now keeps track of the `CoVar`s and `CoercionHole`s it uses when rewriting, which allows computing the dependencies of a zapped coercion without traversing the coercion the rewriter produced, as explained in Note [Computing coercion dependencies] in GHC.Tc.Solver.Rewrite. Accompanying changes: - Rework how dependencies of 'UnivCo's are tracked, purely for performance reasons. We now use the 'UnivCoDeps' datatype instead of '[Coercion]', and we now insist that 'uco_deps' also contains the CoVars that appear in the LHS and RHS types of the UnivCo (as a caching mechanism). - Several performance improvements to the rewriter (e.g. increased strictness). - Improvements to the family application cache, including: - Better documentation. - Only cache a whole chain of reduction steps. - Don't put coercion holes in the cache, fixing #27518. - Allow Core Lint to be called from within the typechecker (and from within the coercion optimiser). - Move out "annotation linting" from Core Lint into the general Core pipeline, to avoid the dependency GHC.Core.Coercion.Opt->GHC.Core.Lint causing a regression in CountDepsParser due to transitive dependencies of GHC.Core.Opt.Monad and GHC.Unit.Module.ModGuts. Fixes #8095 #27336 #27518 Summary of performance numbers Compile-time byte allocated in GHC's testsuite (0 regressions) CoOpt_Singletons(normal) ghc/alloc 634,040,332 595,448,728 -6.1% GOOD FamAppCachePerf(normal) ghc/alloc 495,629,812 191,612,920 -61.3% GOOD LargeRecord(normal) ghc/alloc 1,226,806,434 966,260,976 -21.2% GOOD SimplCastPerf(normal) ghc/alloc 160,505,678 148,112,688 -7.7% GOOD T12227(normal) ghc/alloc 244,668,982 233,037,216 -4.8% GOOD T12545(normal) ghc/alloc 697,804,842 424,705,152 -39.1% GOOD T13386(normal) ghc/alloc 422,871,076 35,213,656 -91.7% GOOD T15703(normal) ghc/alloc 288,402,364 273,692,560 -5.1% GOOD T26426(normal) ghc/alloc 86,002,052 78,152,104 -9.1% GOOD T27336(normal) ghc/alloc 498,932,268 35,886,016 -92.8% GOOD T5030(normal) ghc/alloc 117,057,706 88,785,648 -24.2% GOOD T5321Fun(normal) ghc/alloc 252,552,628 243,820,176 -3.5% GOOD T8095(normal) ghc/alloc 768,198,564 127,779,520 -83.4% GOOD T9872a(normal) ghc/alloc 1,655,675,020 1,406,017,008 -15.1% GOOD T9872b(normal) ghc/alloc 1,864,180,628 1,644,706,696 -11.8% GOOD T9872b_defer(normal) ghc/alloc 2,834,585,468 1,657,729,760 -41.5% GOOD T9872c(normal) ghc/alloc 1,572,573,116 1,354,055,424 -13.9% GOOD T9872d(normal) ghc/alloc 351,516,004 331,071,424 -5.8% GOOD TcPlugin_RewritePerf(normal) ghc/alloc 2,063,065,680 1,847,464,272 -10.5% GOOD Chesskell (github.com/Proxymoron461/chesskell/issues) Typechecking that the first N plies of kholmovVsBronsteinShort are a valid chess game: Plies | GHC 9.14 time/alloc | This commit time/alloc | -----:|---------------------|------------------------| 2 | 41s/20GB | 0.2s/19MB | 4 | 95s/49GB | 0.3s/25MB | 6 | timed out | 0.6s/522MB | 8 | timed out | 7s/673MB | 10 | timed out | timed out | Compilation of singletons-base: compile time -28%, allocations -25% ------------------------- Metric Decrease: CoOpt_Singletons FamAppCachePerf LargeRecord SimplCastPerf T12227 T12545 T13386 T15703 T24984 T26426 T27336 T5030 T5321Fun T8095 T9872a T9872b T9872b_defer T9872c T9872d TcPlugin_RewritePerf ------------------------- Co-Authored-By: Sylvain Henry <sylvain@haskus.fr> - - - - - d50b2ff1 by Sylvain Henry at 2026-10-18T13:53:50-04:00 JS: fix stack corruption in h$ap_gen_fast's pushAllRegs (#27624) The loop added in 9e46990976 ("JS: support more than 128 registers (#26558)") pushed register N to stack[sp - N - 2] while the switch it falls through into, and every reader of the h$ap_gen frame, uses stack[sp - (N - 2)]. Registers >= R32 were therefore written 4 slots too low: the slots the readers consult were left stale and the frame below was silently corrupted. Fix the loop to use the same slot formula as the switch, and add a regression test: an unknown call to a thunk with 35 argument register slots, which goes through the generic apply. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> - - - - - 54 changed files: - + changelog.d/27624 - + changelog.d/zap-coercions - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Coercion.hs-boot - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/FamInstEnv.hs - compiler/GHC/Core/Lint.hs - + compiler/GHC/Core/Lint.hs-boot - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Reduction.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/FVs.hs-boot - compiler/GHC/Core/TyCo/Make.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/TyCo/Rep.hs-boot - compiler/GHC/Core/TyCo/Subst.hs - compiler/GHC/Core/TyCo/Tidy.hs - compiler/GHC/Core/Utils.hs - compiler/GHC/CoreToIface.hs - compiler/GHC/Driver/Config.hs - compiler/GHC/Driver/Config/Core/Lint.hs - compiler/GHC/Driver/DynFlags.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Rename.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Runtime/Eval/Types.hs - compiler/GHC/StgToJS/Apply.hs - compiler/GHC/Tc/Instance/Family.hs - compiler/GHC/Tc/Solver/Default.hs - compiler/GHC/Tc/Solver/Equality.hs - compiler/GHC/Tc/Solver/InertSet.hs - compiler/GHC/Tc/Solver/Monad.hs - compiler/GHC/Tc/Solver/Rewrite.hs - compiler/GHC/Tc/Solver/Solve.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Tc/Utils/TcMType.hs - compiler/GHC/Types/Unique/DSet.hs - compiler/GHC/Types/Var/Set.hs - docs/users_guide/extending_ghc.rst - docs/users_guide/exts/type_families.rst - + testsuite/tests/codeGen/should_run/T27624.hs - + testsuite/tests/codeGen/should_run/T27624.stdout - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/corelint/T27374.hs - testsuite/tests/count-deps/CountDepsParser.stdout - testsuite/tests/dependent/should_compile/T14729.stderr - + testsuite/tests/indexed-types/should_compile/ZapDeps.hs - testsuite/tests/indexed-types/should_compile/all.T - testsuite/tests/rep-poly/RepPolyRule3.stderr - testsuite/tests/simplCore/should_compile/T26051.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0a01049ab7a4f46d2dd29d7cba0d384... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0a01049ab7a4f46d2dd29d7cba0d384... 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