Globals...
Stephen Weeks
MLton@research.nj.nec.com
Sun, 13 Feb 2000 23:06:05 -0800 (PST)
> I'm in the process of hacking up the clousre converter, it's much easier
> than I thought.
Excellent. I was hoping the functor based approach would work out.
> In anycase, one thing I'm not clear about is what role
> globals play in the big scheme of things. Are they very important?
They are essential for good performance. Without them, too many
things get put in closure records, causing a lot of unnecessary work.
> Can someone explain the following comment... in particular the reference to
> the coercions.
...
> (* Must shrink because coercions may be inserted at constructor
> * applications. I'm pretty sure the shrinking will eliminate
> * any case expressions/local functions.
> * The "NoDelete" is because the shrinker is just processing
> * globals and hence cannot safely delete a variable that
> * has no occurrences, since there may still be occurrences in
> * functions.
> *)
The closure conversion algorithm may insert coercions at constructor
applications (for details see our upcoming ETAPS paper -- we can send
you a copy if necessary). These coercions are due to the flow
analysis, and change the type of the constructor argument to the type
actually desired by the constructor. In general, the coercions may
involve case statements, and hence local functions. However, for
globals, the case test will always be known since it is a global.
Hence, after running the shrinker, any case statements and local
functions will have been eliminated. This is necessary in order to
meet the restriction that the global declarations only involve Cps
PrimExps. The reason for this restriction is so that a sensible
semantics can be given to globals -- in particular, all the globals
are evaluated before any of the functions are defined, so there is no
mutual recursion between globals and functions.
I would recommend adding globals to your IL if it doesn't have them.
But if you don't want to, I think you would be all right to just
change isGlobal to "fn _ => false", causing the closure converter to
not introduce any globals. This may kill performance, though.
BTW, it'd be nice if this (and your other changes) would be controlled
by a flag added to the Control structure.