cps & contification

Stephen Weeks MLton@sourcelight.com
Wed, 24 Jan 2001 14:34:51 -0800 (PST)


> I'm  clearly  way  way behind on all this contification discussion.  Can some
> one tell me why we don't allow mutually recursive  continuations,  especially
> given  that we clearly DO allow simply recursive ones (otherwise we would not
> get loops).

It was a choice made a long long time ago solely for simplicity of the IL.  At
the time (and until this contification stuff came up), none of the optimizations
created mutually recursive computations.  Given that, it was easier to write
code that walked over
	       Fun of {
		       name: Jump.t,
		       args: (Var.t * Type.t) vector,
		       body: exp
		      }
than to have code that walked over
	       Fun of {
		       name: Jump.t,
		       args: (Var.t * Type.t) vector,
		       body: exp
		      } list

> To give a stupid example, if I have something like
> 
>     local fun even x =
>                  if x = 0
>                     then true
>                     else odd (x - 1)
>           and odd x =
>                  if x = 0
>                     then false
>                     else even (x - 1)
>     in fun f (flag, x) =
>               if flag
>                  then even x
>                  else odd x
>     end
> 
> Am I pimped to have calls to f do further full function calls?

Yes.  You can see this for yourself by running mlton -ka (or -keep a, or -keep
cps, depending on how up to date you are :-) and looking at the CPS code.  Even
and odd can not be contified because doing so would require mutually recursive
continuations.