Check eta-expansion in the compiler
@nomeata reported on his blog [1] that the ReaderT pattern (i.e. a newtype containing a function) can lead to missed eta-expansions. In his case he reports "Improvement: Allocations: -23.20% Time: -23.00%"
We use this pattern in GHC too so we should check if we could gain anything by forcing eta-expansions in a few places.
Things done:
- !3503 (merged): make the unifier use a one-shot monad.
- !3751 (closed): make the Simplifier use a one-shot monad
[1] https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT
Edit by me (@AndreasK): We should just check all Monads. So far it seems this was beneficial to any monad it was applied to.
Based on grep here is a list of Monads in GHC:
Monads and checked:
-
compiler/GHC/ByteCode/Asm.hs:instance Monad Assembler where -
compiler/GHC/Cmm/Lint.hs:instance Monad CmmLint where -
compiler/GHC/Cmm/Parser/Monad.hs:instance Monad PD where -
compiler/GHC/CmmToAsm/CFG/Dominators.hs:instance Monad (S z s) where -
compiler/GHC/CmmToAsm/Monad.hs:instance Monad NatM where -
compiler/GHC/CmmToAsm/Reg/Linear/State.hs:instance Monad (RegM freeRegs) where
!4759 (merged) -
compiler/GHC/CmmToAsm.hs:instance Monad CmmOptM where -
compiler/GHC/CmmToC.hs:instance Monad TE where -
compiler/GHC/CmmToLlvm/Base.hs:instance Monad LlvmM where -
compiler/GHC/Core/FamInstEnv.hs:instance Monad NormM where -
compiler/GHC/Core/Lint.hs:instance Monad LintM where -
compiler/GHC/Core/Opt/ConstantFold.hs:instance Monad RuleM where -
compiler/GHC/Core/Opt/Monad.hs:instance Monad CoreM where -
compiler/GHC/Core/Opt/Monad.hs-boot:instance Monad CoreM -
compiler/GHC/Core/Opt/Simplify/Monad.hs:instance Monad SimplM where -
compiler/GHC/Core/Unify.hs:instance Monad UnifyResultM where -
compiler/GHC/Core/Unify.hs:instance Monad UM where -
compiler/GHC/CoreToByteCode.hs:instance Monad BcM where -
compiler/GHC/CoreToStg.hs:instance Monad CtsM where -
compiler/GHC/Data/IOEnv.hs:instance Monad (IOEnv m) where -
compiler/GHC/Data/Maybe.hs:instance Monad (MaybeErr err) where -
compiler/GHC/Data/Stream.hs:instance Monad f => Functor (Stream f a) where -
compiler/GHC/Data/Stream.hs:instance Monad m => Applicative (Stream m a) where -
compiler/GHC/Data/Stream.hs:instance Monad m => Monad (Stream m a) where -
compiler/GHC/Driver/CmdLine.hs:instance Monad m => Functor (EwM m) where -
compiler/GHC/Driver/CmdLine.hs:instance Monad m => Applicative (EwM m) where -
compiler/GHC/Driver/CmdLine.hs:instance Monad m => Monad (EwM m) where -
compiler/GHC/Driver/CmdLine.hs:instance Monad (CmdLineP s) where -
compiler/GHC/Driver/Env/Types.hs:instance Monad Hsc where -
compiler/GHC/Driver/Monad.hs:instance Monad Ghc where -
compiler/GHC/Driver/Monad.hs:instance Monad m => Monad (GhcT m) where -
compiler/GHC/Driver/Pipeline/Monad.hs:instance Monad CompPipeline where -
compiler/GHC/HsToCore/Coverage.hs:instance Monad TM where -
compiler/GHC/Iface/Tidy.hs:instance Monad DFFV where -
compiler/GHC/Parser/Lexer.x:instance Monad P where -
compiler/GHC/Parser/PostProcess.hs:instance Monad PV where -
compiler/GHC/Rename/Pat.hs:instance Monad CpsRn where -
compiler/GHC/Stg/Lint.hs:instance Monad LintM where -
compiler/GHC/StgToCmm/ExtCode.hs:instance Monad CmmParse where -
compiler/GHC/StgToCmm/Monad.hs:instance Monad FCode where -
compiler/GHC/Tc/Deriv.hs: instance Monad [] => Monad S -- by coercion sym (Monad :CoS) : Monad [] ~ Monad S -
compiler/GHC/Tc/Deriv.hs: instance Monad [] => Monad (T Int) -- only if we can eta reduce??? -
compiler/GHC/Tc/Deriv.hs: instance Monad [] => Monad (T Int) -- only if we can eta reduce??? -
compiler/GHC/Tc/Deriv.hs: -- instance Monad (ST s) => Monad (T s) where -
compiler/GHC/Tc/Solver/Monad.hs:instance Monad TcS where -
compiler/GHC/Tc/Solver/Rewrite.hs:instance Monad RewriteM where -
compiler/GHC/Tc/TyCl/Utils.hs:instance Monad SynCycleM where -
compiler/GHC/Tc/TyCl/Utils.hs:instance Monad RoleM where -
compiler/GHC/Tc/Types.hs:instance Monad TcPluginM where -
compiler/GHC/ThToHs.hs:instance Monad CvtM where -
compiler/GHC/Types/Unique/Supply.hs:instance Monad UniqSM where -
compiler/GHC/Utils/Monad/State.hs:instance Monad (State s) where -
compiler/GHC/Utils/Monad.hs: instance Monad M where