Repository navigation
Conversation
This change adds a variant of on_any, on_any_unsafe, such that the calls to f and g in on_any_unsafe t f g are tail calls. This makes the new function suitable for converting between continuation-passing style and Lwt code.
Collaborator
Author
|
Oops, fixed. I am not sure what the best name for this function is, or what to focus on in the documentation. |
Collaborator
Author
|
FYI this results in the need for an ugly workaround in Markup.ml: http://aantron.github.io/markup.ml/Markup_lwt.html#VALensure_tail_calls |
aantron
force-pushed
the
master
branch
8 times, most recently
from
October 4, 2016 15:06
4a60522 to
ffdb93f
Compare
Collaborator
Author
|
It's possible to get tail calls of match Lwt.state t with
| Lwt.Return v -> f v
| Lwt.Fail exn -> g exn
| Lwt.Sleep -> Lwt.on_any t f g
(* Can't get tail calls on a sleeping thread anyway, use Lwt.wakeup_later to
control stack growth for sleeping threads. *)So this is closed as not necessary right now. Will add some kind of mention of this in the API documentation. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a version of
on_anythat performs tail calls onfandg. The following test program:Fails with a stack overflow, when compiled and run as:
This is because
Lwt.on_anywraps the calls tofandgin exception handlers, resulting in a growing stack. ReplacingLwt.on_anywithLwt.on_any_unsafefixes the problem.I am working with CPS code, and this helps to interface it to Lwt. I think this can also be accomplished by exposing a function in Lwt that can tail-call a function on the completion of any given thread. I could then use that function together with a reference to get the same result. I think the solution in the current diff is more sensible, however.