-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fixes #4695; closure iterators support for JS backend #23493
Conversation
There's a small error in the PR description: |
import asyncdispatch
proc main {.async.} =
proc foo: Future[int] {.async.} =
echo 1
let x = await foo()
waitFor(main()) expands into previously goto :state 1
var :state
state 0: Now: var :state
case :state
of 0: I suppose |
check: tests/async/tasynctry.nim |
read(cast[typeof(problemCall(
template yieldFuture() {.redefine.} =
yield FutureBase()
var internalTmpFuture`gensym30: FutureBase = expandValue()
yield internalTmpFuture`gensym30
read(cast[typeof(expandValue())](internalTmpFuture`gensym30))))](internalTmpFuture`gensym32)) Here is the problem. The previous implementation split the state on the case that there is a yield in the dest type of the It was translated into state 3:
read(cast[...](...))
state 4:
:envP.`:state` = 5 But it is supposed to have a state assignement in the state 3 part |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
fixes #4695
ref #15818
Since
nkState
is only for the main loop state labels andnkGotoState
is used only for dispatching the:state
(since #7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend.nkState
Node is replaced by a label and Node pair andnkGotoState
is only used for intermediary processing. Backends only need to implementnkBreakState
andclosureIterSetupExc
to support closure iterators.pending #23484
I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode)allPathsAsgnResult???