[e-lang] Q: asynchronous tail recursion?
constantine.plotnikov at gmail.com
Thu Dec 28 06:26:11 CST 2006
On 12/28/06, Kevin Reid <kpreid at mac.com> wrote:
> On Dec 27, 2006, at 9:21, Kevin Reid wrote:
> > On Dec 27, 2006, at 5:22, Constantine Plotnikov wrote:
> >> Is tail recursion supported for asynchronous loops in E? My current
> >> guess (based on E.send*() API) that tail recursion for asynchronous
> >> processes is not supported for loops that return a value and it
> >> cannot
> >> be supported unless changes to API and to kernel E expansions are
> >> made.
> > *If* this is in fact a problem, which I'm not sure about, then I
> > think it can be fixed as part of the implementation: any time a
> > promise is resolved to another promise, the resolved-ref should do a
> > whenMoreResolved on its target, changing its target whenever it gets
> > a response. This would ensure that there is at most one layer of
> > resolved promise in any such resolution chain.
> MarkM pointed out that this puts the leakage elsewhere: the most
> recent promise in the chain will accumulate queued __whenMoreResolved
> messages until the final resolution.
> We have discussed an implementation technique that we think will work:
> As above, except that instead of using __whenMoreResolved, promises
> have a weak set or weak-keyed map containing all forwarding
> references (former promises, what I called resolved-ref above) which
> refer to that promise.
> When a promise is resolved, it updates (shortens) every forwarding-
> ref to point to its resolution (and discards the set).
> This is equivalent to the previous mechanism except that the
> intermediate promises and their requests for shortening are not
> retained by anything, and so can be discarded.
I do not understand how the solution that you are proposing will work.
Could you please elaborate?
My understanding is that the vat receives the message
and invokes referred method. Beyond own object state, the method to be
executed has access at most to information provided in the class
Message. I see a reference to resolver. I see no object on which
__whenMoreResolved might be invoked with useful effect.
My idea is to pass this resolver reference directly to further
invocations of the loop if compiler detects if that call is tail
recursive (for example last call body in when/finally is not tail
recursive and last call in the "finally" section is tail recursive
only if method returns promise for null).
I do not see how this could be done outside the method. However I see
how it could be done inside the method. And this will work in context
on the single vat and when there is a tail recursive loop that involve
More information about the e-lang