[MLton] ref flattening enabled

Stephen Weeks MLton@mlton.org
Fri, 23 Jul 2004 17:57:40 -0700


> I am ashamed to say that I wasn't thinking so much of space safety
> as much as of space efficiency, but ...

I don't see any problems with space efficiency.  Ref flattening always
saves space, by eliminating an indirection and a header word, and
possibly more (when there are beneficial interactions with packing).
The only problem I see is with extra fields that may get kept alive.

> Is 2 really doable?  Surely it would have to be some kind of
> approximation, right?  I.e., it would take some kind of must-alias
> analysis (i.e., this variable must keep this object alive) to get
> this right.

It does require approximate must-alias information, but a very simple
syntactic one will work.  I.E. if x is a variable bound to some tuple,
and r is a ref syntacically extracted from x, then we allow r to be
(more properly, don't prevent r from being) flattened into x if in
every basic block that refers to r, x is live.

> For efficiency, I guess that if Dan Wang's box primitive went in
> then I could at least forcibly stop the flattening (but not force
> the flattening).

Yes, I am planning to put that primitive in soon.  It seems nice, and
could allow us to do even more aggressive flattening, leaving it up to
the programmer to throttle it back.