Skip to content

Avoid unbounded stack consumption for synchronous control flow #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2014

Conversation

retronym
Copy link
Member

Previously, as sequence of state transitions that did not pass through an
asynchrous boundary incurred stack frames. The trivial loop in the enclosed
test case would then overflow the stack.

This commit merges the resume and apply(tr: Try[Any]) methods into a
apply. It changes the body of this method to be an infinite loop with
returns at the terminal points in the state machine (or at a terminal
failure.)

To allow merging of these previously separate matches, states that contain
an await are now allocated two state ids: one for the setup code that calls
onComplete, and one for the code in the continuation that records the
result and advances the state machine.

Review by @phaller / @danarmak

@retronym retronym force-pushed the ticket/stack-safety branch from fbf3145 to 4602f6c Compare December 15, 2014 02:53
Previously, as sequence of state transitions that did not pass through
an asynchrous boundary incurred stack frames. The trivial loop in
the enclosed test case would then overflow the stack.

This commit merges the `resume` and `apply(tr: Try[Any])` methods into
a `apply`. It changes the body of this method to be an infinite loop
with returns at the terminal points in the state machine (or at a
terminal failure.)

To allow merging of these previously separate matches, states that
contain an await are now allocated two state ids: one for the setup
code that calls `onComplete`, and one for the code in the continuation
that records the result and advances the state machine.

Fixes scala#93
@retronym retronym force-pushed the ticket/stack-safety branch from 4602f6c to c0d7115 Compare December 15, 2014 02:55
@@ -49,6 +49,7 @@ private[async] trait TransformUtils {

private def isByName(fun: Tree): ((Int, Int) => Boolean) = {
if (Boolean_ShortCircuits contains fun.symbol) (i, j) => true
else if (fun.tpe == null) (x, y) => false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Candidate for hoisting? (or it is already hoisted by the compiler?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler will hoist these in 2.12, but it isn't done today.

@retronym
Copy link
Member Author

See also #98

@retronym retronym merged commit c0d7115 into scala:2.10.x Dec 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants