I suspect I am stupid again

Matthew Fluet Matthew Fluet <fluet@CS.Cornell.EDU>
Fri, 21 Sep 2001 12:55:15 -0400 (EDT)



On Wed, 19 Sep 2001, Stephen Weeks wrote:

> 
> > This code tickles at least 2 MLton bugs.  The bugs are in a couple of optional
> > optimization passes that can be turned off from the command line.  The following
> > call will successfully compile lrtl.sml until we track down the bugs.
> > 
> > mlton -drop-pass contify1 -drop-pass contify2 -drop-pass contify3 -drop-pass unusedArgs3 lrtl.sml
> 
> Matthew, can you look into both of these bugs?

Some progress on the confication bug.  Not surprisingly, its some bug in
the way that we resolve mutually recursive functions that are contified at
the same location.  I remember when I was working on this before, I wanted
to be a little more clever than to simply punt on all the functions when a
SCC had more than one outside caller.  In a nutshell, here's part of
what's going on with lrtl.sml (using abused ICFP notation): 

loop_1136 -- L_3773 --> exp_134
exp_134 ----> {x_100742, x_100801, x_100774, x_100771, x_100803, x_57425.
               x_100806, x_100716, x_100771, x_100803, x_57425, x_100771,
               x_100803, x_57425}
x_100806 ----> {x_100806, x_100852, x_100835}
x_100852 ----> {exp_134}
x_100835 ----> {x_100771, x_100803, x_57425}
...
(no other calls to x_100806)

Point being, there is a non-tail call to exp_134, which is the entry to a
mutually recursive mess.  But, exp_134 is the only function called from
outside the set, so we attempt to nest everything else inside it. 
Removing exp_134 from the set leaves x_100806 as it's own strongly
connected component.  One of the other sccs cannot be nested (too many
outside callers), so we can't contify them; there are tail calls to
exp_134 in these functions, so we can't contify exp_134 either.  However,
we should still be able to contify x_100806 in exp_134 (because x_100806
is Acall contifiable -- one outside caller).  In nesting x_100806 in
exp_134, we "scale back" contifing x_100806 in L_3773 to contifiying it in
exp_134.  But, somewhere else, we mark x_100806 as uncontified; somewhere
in the processing of the mutually recursive functions that aren't
contifiable.  This leads to the Option exception, because x_100806 is
considered a prefix of exp_134, but because it's contify flag is set to
false, we don't set it's replace field.

Various "hacks" let me compile lrtl.sml.  (For example, switching from
Adom/ancestor to Adom/parent.)  But, I want to figure out the right way of
doing this.  One way is to just punt on everything, but that seems bad.
In particular, the whole maximality of Adom is sort of an illusion -- if
we punt, then x_100806 which is Acall contifiable is not actually
contified by Adom.