On Jul 31, 2007, at 10:20 AM, Simon Peyton-Jones wrote:
| However my point was more on a semantic point of view: If I write
a function
| in a recursive way, but actually do nothing else than a loop, I
would like
| a) that the compiler unrolls it to a loop and
| b) that I can specify such a requirement, while violating it
emits an error.
What does it mean to say "the compiler unrolls it to a loop". If
GHC sees a tail recursive function, it certainly compiles it to a
loop! (But that's not called "unrolling".)
I think what's meant here is translating something like this:
{-# INLINE f #-}
f x y z = ... f x' y' z' ...
into this:
{-# INLINE f #-}
f x y z = f' x y z
where f' x y z = ... f' x' y' z' ...
That is, shoving (all of) the recursion in a level. Then inlining f
results in a fresh loop, which presumably can be specialized or
optimized in various ways. I did this in pH, mostly because it was
less irritating than performing the same transformation by hand on
key bits of the Prelude. Whether it's actually beneficial on a large
scale probably depends on the effectiveness of transformations that
can specialise f' to the site where it was inlined; invariant
argument elimination comes to mind here, and I never did a good job
with that. It does remove one irritant from performance tuning,
though, by letting us write a simple top-level recursive function and
have it inlined.
-Jan
Simon
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users