CWS paper
Stephen Weeks
MLton@sourcelight.com
Mon, 4 Dec 2000 15:05:53 -0800 (PST)
> Is the contification strategy you are working on different than the one I
> suggested (where the continuation of a function f ends with return-from-f)?
> That seems pretty much optimal to me. I guess it could also end with
> tail-call-to-g.
The one you suggested (as I understood it) failed on the example that I sent out
on Nov 22.
> fun f () = ... h () ... g () ...
> fun g () = ... h () ... f () ...
> fun h () = ...
> ... K (f ()) ...
>
> All calls are tail calls. It seems to me that the extended analysis will not
> be able to contify h because it will be called with two different
> continuations: "return to f" and "return to g". On the other hand, with the
> old analysis, the set of continuations for f, g, and h would be {K}, and all
> would be contified.
Matthew sent a proposed fix to the continuation based analysis to handle this
problem. Intuitively, it made sense, but I haven't quite figured out how to
make an analysis of it.
> A completely different possibility is to observe that the main thing being
> saved (in turning a procedure into a continuation) is construction of a
> fram. Thus you could turn procedures which are only called with a few
> continuations into continuations which take a flag argument to indicate where
> they should go when they are done. I.e., it really is a form of closure
> representation in the world of full CPS.
This could work.
I think the problem is that the CPS IL ties together the notions of environment
and stack. For example, there is no way to keep around one environment while
doing a nontail recursion that refers to that environment.