[MLton] MLton misses 'assumed' Word optimization

Matthew Fluet fluet@cs.cornell.edu
Mon, 23 May 2005 14:33:01 -0400 (EDT)


> > It seems that this works for Int..?
>
> That does appear to be the case.  I don't know if the coercions are
> specifically optimized in this case, or if it is a consequence of the
> internal representation of IntInf.int.

Actually, I'll revise this.  The compiler doesn't do anything special in
this case.  It happens to be the case that the Int16.toLarge is
implemented in basis-library/integer/patch.sml as:

structure Int16: INTEGER_EXTRA =
   struct
      open Int16

      val fromLarge = fromInt o IntInf.toInt
      val toLarge = IntInf.fromInt o toInt
   end

So the  WordS16_toWord32  that you see is the  toInt.  There is a lot of
code off the fast-path that handles the case when the IntInf.fromInt
can't fit the 32-bit integer into the high 31-bits used to represent a 
"small" IntInf.int.  Of course, when coming from a 16-bit integer, this 
path is never taken, but neither is it optimized away.