[Haskell-cafe] Announce: ghc-core, command line pager for reading GHC Core

Josef Svenningsson josef.svenningsson at gmail.com
Mon May 26 10:54:04 EDT 2008


On Fri, May 23, 2008 at 9:55 PM, Duncan Coutts
<duncan.coutts at worc.ox.ac.uk> wrote:
>
> On Fri, 2008-05-23 at 21:24 +0200, Henning Thielemann wrote:
>> On Fri, 23 May 2008, Bulat Ziganshin wrote:
>>
>> > Hello Henning,
>> >
>> > Friday, May 23, 2008, 8:31:24 PM, you wrote:
>> >
>> >> would guarantee speed in every case. Or I can SPECIALISE the function,
>> >> then the function will only be called, but with polymorphism overhead
>> >> eliminated. This would only work for a restricted range of types. I'd like
>> >> to have a pragma, that tells GHC to specialise a function for every type
>> >> it is called with.
>> >
>> > me too. btw, this already present in jhc. inlining doesn't work in any
>> > complex case since recursive functions can't be inlined
>>
>> GHC inlines recursive functions, too, otherwise it could not turn 'foldl'
>> and friends into plain machine loops.
>
> Actually ghc's definition of foldl is not recursive, though it does of
> course contain a local recursion:
>
> foldl        :: (a -> b -> a) -> a -> [b] -> a
> foldl f z xs = lgo z xs
>             where
>                lgo z []     =  z
>                lgo z (x:xs) = lgo (f z x) xs
>
> The lgo recursive call is then specialised at the call site and we can
> get good code.
>
> As I understand it, if foldl was written in the standard directly way
> then ghc would not inline it. So we have to manually apply the static
> argument transformation. You'll see that foldr is written in the same
> way.
>
Note that the static argument transformation (SAT) was recently
revived in ghc. Info from the patch:
Fri Apr 11 18:21:37 CEST 2008  simonpj at microsoft.com
  * Revive the static argument transformation

  This patch revives the Static Argument Transformation, thanks to
  Max Bolingbroke.  It is enabled with
        -fstatic-argument-transformation
  or    -O2

  Headline nofib results

                    Size    Allocs   Runtime
  Min             +0.0%    -13.7%    -21.4%
  Max             +0.1%     +0.0%     +5.4%
  Geometric Mean  +0.0%     -0.2%     -6.9%

Haskell programs just keep getting faster and faster. And having ghc
do the SAT to enable inlining recursive functions is really nice.

Cheers,

Josef


More information about the Haskell-Cafe mailing list