Why does SpecConstr run far later than specialisation
Simon Peyton Jones
simonpj at microsoft.com
Tue Mar 20 22:03:02 UTC 2018
However, looking at the pass order in `SimplCore`, specialisation runs very early before any major simplification but SpecConstr runs very late right at the end of the pipeline. Does anyone know the justification for this?
Here’s my thought
* Typeclass specialisation makes a specialised copy of a function in which many higher order calls (via the dictionary) are replaced with calls to known functions. That exposes LOTS of stuff to all phases of optimisation including the strictness analyser. So running it early is good.
* Moreover typeclass specialisation is exposed simply by type at which we call an overloaded function, and that is apparent early. So running it early is OK.
* SpecConstr just eliminates data constructor allocation and case expressions, so it is less likely to unleash a cascade of further optimisations.
* Moreover, SpecConstr only works when we have f (a:b), and calls like that are more likely to be exposed after we’ve optimised the program. So do it late.
All of these things are doubtless only sort-of-true. Concrete examples to the contrary would be useful.
From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Joachim Breitner
Sent: 20 March 2018 13:42
To: ghc-devs at haskell.org
Subject: Re: Why does SpecConstr run far later than specialisation
Am Dienstag, den 20.03.2018, 13:23 +0000 schrieb Matthew Pickering:
> As far as I understand it, the goals of SpecConstr and specialisation
> are the same. One works for normal value arguments and one works for
> special type class dictionary arguments.
> However, looking at the pass order in `SimplCore`, specialisation runs
> very early before any major simplification but SpecConstr runs very
> late right at the end of the pipeline.
> Does anyone know the justification for this? It seems intuitively that
> they should work in the same way.
Just a guess: We want the demand analyzer to run before SpecConstr, because I expect that there are many functions where both the demand analyzer are happy to do something, and SpecConstr is happy to do something, but the worker-wrapper done by DmdAnal is strictly preferable (no code duplication, for example.)
But the Specializer and the demand analyzer have no overlap, and we we do want to strictness-analyzer the type-class-specialized code.
But as I said, it’s just a guess.
Joachim “nomeata” Breitner
mail at joachim-breitner.de
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ghc-devs