flatter closure conversion
Henry Cejtin
henry@clairv.com
Fri, 15 Oct 1999 19:08:52 -0500
I assume that in the `usual free variable function' you meant the last rule
to be
FV(let x = e1 in e2 end) = FV(e1) U (FV(e2) - {x})
Basically you are delaying the construction of closures. This might be a
win, but it might be a loss. If you can avoid building the closure at all
(lets say because of some inlining) then you win. On the other hand, you
might end up building the closure many times, in which case you lose.
Perhaps it is still safe-for-space (in our slightly weakened sense that the
blow up is a constant dependent on the program), but it is still a loss.
To be specific, consider the following example:
let val f = fn _ => a + b
val g = fn _ => f
in ...
end
In the straight `flat' closures, each call to g will allocate nothing. In
your version, each call to g will allocate the tuple. (I'm ignoring the
potential optimization of noticing that the environment for f is the SAME as
that for g, so you can skip the construction. The example can be goosed to
make that not happened.)
Are you convinced that it really is going to be a win over all? I don't see
why. (Mind you, I'm sure that there are programs where it would be.)