[MLton] leaf inlining

Matthew Fluet fluet at tti-c.org
Mon Jun 25 12:37:44 PDT 2007

skaller wrote:
> On Mon, 2007-06-25 at 07:20 -0500, Matthew Fluet wrote:
>> skaller wrote:
>>> On Sun, 2007-06-24 at 22:46 -0500, Matthew Fluet wrote:
>>>> I added an introduceLoops pass before inlining, since inlining can't be 
>>>> applied to recursive functions (and recursive functions aren't leaf).
>>> Huh? Is Mlton only inlining non-recursive leaves?
>> In the leafInline optimization pass, yes.  In the later general inlining 
>> pass, there is a more permissive inlining heuristic.
> Hmm .. what is a leaf? I this a leaf in the call graph,
> or a leaf in the child tree?

In the SSA IL, the program is represented by a (mutually-recursive) 
collection of first-order (and second-class) functions.  So, no function 
has child functions.

A leaf function is simply a function with no calls in its body.

> During inlining, many other rewrite rules are applied,
> for example self-tail-call-to-loop optimisation *must* be done
> during inlining. See the example above.

MLton takes the opposite approach.  Each optimization pass does one 
specific optimization, without trying to integrate multiple 
optimizations at once.  The inlining optimization just inlines; latter 
passes take care of contracting the resulting code.

Yes, combining optimizations in one pass can sometimes result in more 
optimization opportunities than applying the optimizations in sequence, but
1) combining optimizations can often be difficult to do correctly
2) it often isn't clear that the combined optimizations will be 
significantly more effective.

More information about the MLton mailing list