Explore when to apply static argument transformation
The Static Argument transformation optimises
f x y = ....f x' y...
into
f x y = let g x = ....g x'...
in g x
Instead of passing y
along unchanged, we make it into a free variable of a local function definition g
.
Unfortunately, it's not always a win. Andre Santos gives a discussion, and quite a few numbers in his thesis.
But sometimes it is a pretty big win. Here's the example that recently motivated me, which Roman Leshchinskiy showed me. You need the attached file Stream.hs, and then try compiling
import Stream
foo :: (a -> b) -> [a] -> [c]
foo f = mapL f
Thus inspired, I think I have a set of criteria that would make the static arg transformation into a guaranteed win:
- there is only one (external) call to the function
- OR its RHS is small enough to inline
- OR it is marked INLINE (?)
So I'd like to try this idea out.
Trac metadata
Trac field | Value |
---|---|
Version | 6.4.2 |
Type | Task |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |