[MLton] callcc and space use

Daniel Spoonhower spoons at cs.cmu.edu
Wed Jan 23 06:06:12 PST 2008



Matthew Fluet wrote:
>   fun f x =
>      let val y = ... x ... in
>        (* no more occurrences of x *)
>        callcc (fn k => (enq (fn () => ... k ...);
>                         raise Continue))
>        ; raise Foo
>      end
> 
> and the captured continuation will necessarily throw an exception that 
> leaves g (and makes g's y dead), we can't propagate that kind of 
> liveness information down the stack.

That's OK: there is no "Foo" in my case.  In other words, the 
continuation is meaningful, I just want to suspend it for a while.

In any case, in trying to get a smaller example, I've learned something: 
In the code that attached to my earlier email, the exception carried a 
list of thunks.  If the exception is nullary (and the thunks are queued 
before the exception is raised) then my space leak goes away.  The 
difference essentially comes down too:

 >        callcc (fn k => (enq (fn () => ... k ...);
 >                         raise Continue))

vs

 >        ... handle Continue ws => app enq ws
 > ...
 >        ... callcc (fn k => (raise Continue [fn () => ... k ...]))

(Where the second version leaks.)  I attached another version of my 
example that uses a nullary exception instead.

I will keep investigating.  Still, any hints are appreciated.

Thanks,

--djs

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple2.sml
Type: application/smil
Size: 1851 bytes
Desc: not available
Url : http://mlton.org/pipermail/mlton/attachments/20080123/4bf1563f/simple2.smi


More information about the MLton mailing list