Simon Peyton Jones pushed to branch wip/spj-try-opt-coercion at Glasgow Haskell Compiler / GHC Commits: 46af7510 by Simon Peyton Jones at 2026-01-06T16:09:19+00:00 Drastically reduce the use of the coercion optimiser This MR addresess #26679 by calling the coercion optimiser much less often; the coercion optimiser is expensive, and often ineffective, especially when it is called repeatedly. See Note [Coercion optimisation] in GHC.Core.Corecion.Opt. Specifically * Make coercion optimisation into its own pass, controlled by its own flag `-fopt-coercion` like any other pass. The pass runs early in the pipeline. * The Simplifier now contents itself with merely applying the current substitution to a coercion, and checking for reflexivity. * Kill off OptCoercionOpts, which is now unused. Another important, but only loosely related, improvement * In `GHC.Core.Subst.substIdBndr`, `GHC.Core.TyCo.Subst.substTyVarBndrUsing`, and `GHC.Core.TyCo.Subst.substTyVarBndrUsing`, check for an empty substitution. This keeps substitutions empty in the no-op case. See Note [Keeping the substitution empty] in GHC.Core.TyCo.Subst Compile time improves. Here are the compile-time allocation change over 1%: Baseline Test value Change ------------------------------------------------------------ CoOpt_Singletons(normal) 721,677,974 -7.9% GOOD LargeRecord(normal) 1,268,094,410 -20.4% GOOD T12545(normal) 772,150,124 -9.2% T12707(normal) 777,720,918 -1.5% GOOD T14766(normal) 918,228,179 -50.2% GOOD T15703(normal) 318,141,541 +1.0% BAD T18223(normal) 371,496,473 -7.6% GOOD T1969(normal) 670,830,326 +2.2% BAD T20261(normal) 573,444,953 -2.2% T24984(normal) 87,836,660 -1.5% T3064(normal) 171,636,592 -6.2% GOOD T5030(normal) 148,301,062 -16.4% GOOD T5321Fun(normal) 263,120,022 -3.3% GOOD T8095(normal) 777,033,006 -71.3% GOOD T9020(optasm) 222,159,574 -2.5% GOOD T9630(normal) 873,422,584 -15.4% GOOD T9872b(normal) 1,906,890,318 -2.9% GOOD T9872b_defer(normal) 2,878,170,737 -2.1% GOOD T9872d(normal) 356,978,798 -7.7% GOOD TcPlugin_RewritePerf(normal) 2,132,138,060 -2.6% GOOD geo. mean -2.7% minimum -71.3% maximum +2.2% Metric Decrease: CoOpt_Singletons LargeRecord T12707 T14766 T18223 T3064 T5030 T5321Fun T8095 T9020 T9630 T9872b T9872b_defer T9872d TcPlugin_RewritePerf Metric Increase: T15703 T1969 - - - - - ceeeb350 by Simon Peyton Jones at 2026-01-06T16:10:06+00:00 Try harder to keep the substitution empty See Note [Keeping the substitution empty] - - - - - 528c804f by Simon Peyton Jones at 2026-01-06T16:10:38+00:00 Serious attempt to avoid duplicating large coercions Wibbles Progress on not-inlining coercions Add a type signature More on exported coercions More on coercion bindings Allow in letrec; indeed make the invariants for letrec the same as the invariants for top-level bindings. ToDo: document this - - - - - 37 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Pipeline/Types.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/Ppr.hs - compiler/GHC/Core/Rules.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/TyCo/Subst.hs - compiler/GHC/Core/Utils.hs - compiler/GHC/CoreToIface.hs - compiler/GHC/CoreToStg.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Driver/Config.hs - compiler/GHC/Driver/Config/Core/Lint.hs - compiler/GHC/Driver/Config/Core/Opt/Simplify.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/Tidy.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Types/Var/Env.hs - docs/users_guide/using-optimisation.rst - hadrian/src/Flavour.hs - testsuite/tests/count-deps/CountDepsAst.stdout - testsuite/tests/count-deps/CountDepsParser.stdout - testsuite/tests/simplCore/should_compile/T8331.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5c1b0929866b379080e3f33a2aed445... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5c1b0929866b379080e3f33a2aed445... You're receiving this email because of your account on gitlab.haskell.org.