[MLton-devel] Minimizing space usage in ML (fwd)

Stephen Weeks MLton@mlton.org
Mon, 21 Oct 2002 22:02:52 -0700


> I thought you might be interested in the following optimization that I
> passed on to Peter Sestoft a couple of months ago. He responded that
> although promising it didn't make much difference in Moscow ML, but
> perhaps it will in MLton...
...
> The idea is that if you compare the following two terms for equality
> 
> CON subterm1 = CON subterm2
> 
> and the test succeeds, then it's fine to swing the pointer from
> subterm1 to subterm2 (correcting the reference counts as you do it).
...
> Has this been tried before? Can you see any flaws with the scheme?

Thanks for the idea.  The idea works for any two values that are equal
in the sense of SML polymorphic equality, such as tuples, vectors,
etc.  We have not implemented in MLton, and I haven't seen it before.
I would guess that it wouldn't make much difference in MLton, just as
it didn't in Moscow ML.  But of course one can construct examples
where it would help a lot.

There is possibly an additional complication in MLton because
polymorphic equality is not implemented in the runtime.  Rather, it is
implemented via specialized equality routines constructed at compile
time after the program has been translated into a simply-typed
intermediate language (IL).  In this IL, constructors, tuples, and
vectors are immutable, and this is part of the semantics of the IL
relied on by the optimizer.  It seems like it would be OK to add a
special primitive that swings a pointer from one equal value to
another, but we'd have to think a bit to make sure.

Assuming it's OK, it shouldn't be too hard to modify the pass
(ssa/poly-equal.fun) that implements polymorphic equality to do the
pointer manipulation.

Are you interested in doing any compiler hacking? :-)  Anyone else
interested?


-------------------------------------------------------
This sf.net emial is sponsored by: Influence the future of 
Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) 
program now. http://ad.doubleclick.net/clk;4699841;7576301;v?
http://www.sun.com/javavote
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel