[Git][ghc/ghc][wip/spj-try-opt-coercion] Drastically reduce the use of the coercion optimiser
Simon Peyton Jones pushed to branch wip/spj-try-opt-coercion at Glasgow Haskell Compiler / GHC Commits: 843b9a2a by Simon Peyton Jones at 2026-05-22T12:00:39+01: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 Serious attempt to avoid duplicating large coercions 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 Fix expression-equality for (Coercion co) We were just saying "True" which is utterly wrong. See Note [Equality for coercions] in GHC.Core.Map.Type Wibbles on coercion bindings Try a very cheap coercion optimiser Comments -- almost all just about core invariants Fuse optCoRefl and substCo Maybe this will be better than either Update Notes about core binding invariants T26332 really should fail with -dlinear-core-lint Try switching off the big optCoercion except in O2 Comments only Try dropping all optimisation The Simplifier just calls substCo, instead of optCoRefl Flags for tracing coercion sizes More optCoRefl * Deal with submultiplicities * In InitialPhase run even with empty subst Update user manual Care with the simple refl optimiser Improve the gobbler Fix warning Add changelog - - - - - 57 changed files: - + changelog.d/opt-coercion - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Core.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/LateCC/TopLevelBinds.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Make.hs - compiler/GHC/Core/Map/Expr.hs - compiler/GHC/Core/Map/Type.hs - compiler/GHC/Core/Opt/CSE.hs - compiler/GHC/Core/Opt/ConstantFold.hs - compiler/GHC/Core/Opt/FloatIn.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Pipeline/Types.hs - compiler/GHC/Core/Opt/SetLevels.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/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/Rules.hs - compiler/GHC/Core/SimpleOpt.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/Data/TrieMap.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/Make.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/Stg/Lint.hs - compiler/GHC/Types/Id.hs - compiler/GHC/Types/Literal.hs - compiler/GHC/Types/Var/Env.hs - compiler/GHC/Utils/Misc.hs - compiler/GHC/Utils/Outputable.hs - compiler/GHC/Utils/Trace.hs - docs/users_guide/debugging.rst - docs/users_guide/using-optimisation.rst - testsuite/tests/count-deps/CountDepsAst.stdout - testsuite/tests/count-deps/CountDepsParser.stdout - testsuite/tests/linear/should_compile/T26332.hs - testsuite/tests/linear/should_compile/all.T The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/843b9a2a0d9b8f99528a6f45053b7aaa... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/843b9a2a0d9b8f99528a6f45053b7aaa... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Peyton Jones (@simonpj)