-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement ES2018 Async Iteration (Experimental) #5834
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
Conversation
b90937e
to
88f04c2
Compare
Thanks, @rhuanjl . You mention that you're adding runtime checks. Do those checks determine which context await/yield are being employed in, and/or to distinguish between await and yield? |
The runtime checks this contains which could clearly be removed by refactoring (likely with more code in total) are:
The other painful point performance wise with await and yield is that currently the bytecode is set to create an object and attach the awaited or yielded value as the .value property of the object. In an async generator even with yield you have to await the value so in both cases i’m discarding the created object. |
I see. Yes, you're right, we want to be able to resolve static properties of the code without using runtime checks. A separate opcode for yield in different contexts is a good place to start and something we anticipated having to do to implement the feature. I'll be glad to help you do that. We can handle the JIT after getting things working in the interpreter. You'll need to:
|
Whilst this version should work as is certainly agree that it could do with improvements, I'll aim to submit an update with additional opcodes by the end of this week or start of next. |
312649c
to
505e13e
Compare
Changes made:
OtherNotes
|
d06b889
to
218eebc
Compare
Small update - I'm about half way there offline with the remaining pieces needed to meet the spec i.e. for-await-of and async from sync iterator. It's going to be 500+ more lines of code when done so may be easier if this part is reviewed first before I add the rest? |
Thanks, @rhuanjl . Are you still hitting the assert? If so, can you give me some detail about it? |
@pleath I've fixed the assert issue, thanks. Question - Should I leave this PR as is or update it with my further work - I've implemented for-await-of and AsyncFromSyncIterator (the remaining parts of the feature) offline but they're another 600 lines and I haven't written full tests for them yet. (worried about the sheer size of the diff) |
@rhuanjl I mentioned this in private already but it seems that this feature currently can be enabled only with a flags-enabled build of |
89975a7
to
fe4dc66
Compare
UPDATE: see edited first post for details - this is now a complete implementation of ES2018 Async Iteration (though could do with more tests) Please could people find some time to begin reviewing this? |
Awesome. Thanks, @rhuanjl . I'll give this a close review this week. |
FYI, I'm about half way through the review, and so far everything looks nice and clean. I want to walk through a couple of use cases before I sign off. |
This still is not usable with |
@pleath thanks for the prelim feedback - I've done a re-read/check and noticed a couple of things, not going to update the PR whilst you're mid review, notes for ref:
|
@pleath Any update on this - as fixing the hit piece is out of scope per discussion in #5877 only other points I'm aware of are that it probably needs more tests and a couple of my comments are wrong - didn't want to add anything when you were mid-review though (Also really expected your review to find some errors in my code this is the largest piece of c++ I've ever written) |
Sorry for the holdup, @rhuanjl. Many fire drills the last couple of weeks. I’ll wrap this up today. Feel free to correct your comments; it won’t interfere. |
Uh oh, looks like Candle Jack got hi |
(Hah. My previous comment was mangled, but I’ve fixed it.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, @rhuanjl . I have just a couple of comments and questions. I would go ahead and make the changes you mentioned that you were holding on to, and we can probably go ahead with getting this in.
fe4dc66
to
bce4afb
Compare
Thanks for the review, I've:
Note this PR still adds this as a disabled feature - partly as no one has told me to enable it since I opened the PR and partly as I'm worried my test coverage is insufficient for a shipping feature this big. |
bce4afb
to
5d8fcd2
Compare
Keep in mind that if the feature is fully disabled, including with the EnableExperimentalFeatures runtime attribute, then nobody can test it unless they have a flags-enabled build of CC. That's not likely to be the case for embedders shipping an application, so in practice the feature will get no real-world testing. |
@fatcerberus I'm hoping this can be enabled soon but leaving that decision to the CC team - as an additional note node-chrakracore uses EnableExperimentalFeatures so if I switched it to an experimental feature of that kind it would be on in node-chakracore - it should really have TTD support before then I assume; and I don't know how to do TTD support. |
Yes, I was aware - I was simply bringing the above up as a discussion point. |
Would it be possible to move forward with this or is it parked indefinitely? Is there anything specific I can do to move this towards being mergeable? |
Hi @rhuanjl - Thanks for pinging on this! I intend to pick this up within the next few days. In the meantime, would you mind doing a rebase? |
@zenparsing I saw it got out of date, and had bytecode conflicts so I've just regenerated the bytecode and rebased again. I also squashed the fixes commit for neatness. Please let me know if you'd like me to do anything else on this. |
} | ||
}, | ||
{ | ||
name : "Async Generaotr function instances have the correct prototype object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name : "Async Generaotr function instances have the correct prototype object", | |
name : "Async Generator function instances have the correct prototype object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed this typo in the follow up PR #6172 thanks.
Thanks for merging this @zenparsing As noted above whilst this is a full implementation it's disabled by default - please let me know if there's anything I can contribute to help get towards it being enabled by default. |
Merge pull request #6172 from rhuanjl:asyncGeneratorFixes I missed async generator properties of objects when updating the parser in #5834 This PR: 1. fixes that omission enabling async generator properties of objects when async generators are enabled 2. adds tests for a couple of async generator syntax options that were not currently tested (including for point 1) 3. updates the async generator continue methods to use the new PerformPromiseThen from #6163 - this has no observable effect but improves internal consistency @zenparsing please could you take a look at this?
Also took this opportunity to do a bit refactor on how we initialize the `generator` pointer inside `ResumeYieldData`. I think it's cleaner if we do everything in one place instead of setting it in CallAsyncGenerator. Related PR: chakra-core#5834
This PR implements ES2018 Async Iteration (Async Generator Functions and for await):
UPDATE: This is now a complete implementation except:
Implementation notes:
Test262 results
I've run this against the test 262 tests in the following folders, I used the ES6FunctionNameFull and ES2018ObjectRestSpread flags when running the tests as some of these tests require those features:
https://github.com/tc39/test262/tree/master/test/built-ins/AsyncFromSyncIteratorPrototype
https://github.com/tc39/test262/tree/master/test/built-ins/AsyncGeneratorFunction
https://github.com/tc39/test262/tree/master/test/built-ins/AsyncIteratorPrototype/Symbol.asyncIterator
https://github.com/tc39/test262/tree/master/test/language/statements/async-generator
https://github.com/tc39/test262/tree/master/test/language/statements/for-await-of
Most tests pass, fails relate to existing issues:
a. Next isn't cached - issue exists with synch iterators BUG: GetIterator should cache next method #5860
b. the
async
keyword is not allowed to contain unicode escapes (affects normal async functions as well as async generators)c.
of
in a loop header is not allowed to contain a unicode escaped. 12 other issues to do with destructuring syntax and loop headers
ref: #2720