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