-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Updating async function implementation to fix the symbol capturing issues #1456
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
73fbef9
to
8727492
Compare
@ianwjhalliday @pleath @akroshg Can you please take a look? |
@@ -846,8 +846,8 @@ Func::AjustLocalVarSlotOffset() | |||
bool | |||
Func::DoGlobOptsForGeneratorFunc() | |||
{ | |||
// Disable GlobOpt optimizations for generators initially. Will visit and enable each one by one. | |||
return !m_jnFunction->IsGenerator(); | |||
// Disable GlobOpt optimizations for generators and asyn functions initially. Will visit and enable each one by one. |
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.
asyn [](start = 56, length = 4)
typo
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.
Fixed
Note for later, this may not be necessary with how we fix default parameter expression evaluation. The try catch could probably go in the C++ code that does the initial next() call on the generator. Refers to: lib/Runtime/ByteCode/ByteCodeEmitter.cpp:2897 in 8727492. [](commit_id = 8727492, deletion_comment = False) |
|
||
Var* argsHeapCopy = RecyclerNewArray(scriptContext->GetRecycler(), Var, stackArgs.Info.Count); | ||
js_memcpy_s(argsHeapCopy, sizeof(Var) * stackArgs.Info.Count, stackArgs.Values, sizeof(Var) * stackArgs.Info.Count); | ||
Arguments heapArgs(callInfo, argsHeapCopy); |
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.
Are we getting two heap copies of the arguments since we're doing another heap allocation and copy above in CreateGenerator? We only need one heap allocated copy of the arguments.
Please check.
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.
Removed it.
I found a few cases where there was old code specific to async functions that no longer applied, in bytecode generator. I did not do a look through our code base though. Please do a quick look through search results for IsAsync to see if there are any other special cases that should be removed. |
nit: the title of this PR is incorrect. We were desugaring before, now we are implementing it natively (taking advantage of heavy reuse of JavascriptGeneratorFunction). |
3ed055a
to
5e26878
Compare
@@ -338,6 +338,7 @@ struct PnFnc | |||
bool IsDeclaration() const { return HasFlags(kFunctionDeclaration); } | |||
bool IsGeneratedDefault() const { return HasFlags(kFunctionIsGeneratedDefault); } | |||
bool IsGenerator() const { return HasFlags(kFunctionIsGenerator); } | |||
bool IsCoroutine() const { return HasFlags(kFunctionIsGenerator) || HasFlags(kFunctionIsAsync); } |
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.
HasFlags accepts multiple flags, so you could do HasFlags(kFunctionIsGenerator | kFunctionIsAsync)
instead. Doesn't matter though.
Or at least HasFlags should support multiple flags, I'm not sure if that's ever been used and thus tested
5e26878
to
9e3ce48
Compare
@@ -5869,6 +5934,15 @@ namespace Js | |||
return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptGeneratorFunction, type, scriptFunction); | |||
} | |||
|
|||
JavascriptAsyncFunction* JavascriptLibrary::CreateAsyncFunction(JavascriptMethod entryPoint, GeneratorVirtualScriptFunction* scriptFunction) | |||
{ | |||
Assert(scriptContext->GetConfig()->IsES6GeneratorsEnabled()); |
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.
Is this the right assert here?
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.
Yes, we need the generator functionality all available for the async functions. But right now generators are enabled by default still I will just keep it there for now.
Overall looks good to me. Are you planning to add debugger tests as well? |
00795c5
to
2d71a1a
Compare
I will add debugger test cases in a separate change set |
@dotnet-bot test Windows x64_debug please |
…sues This change removes the function wrapper implementation of async functions. Now the async functions will behave similar to generator functions. The actual function body will be in the sciptFunction field. Symbols now need not be forced to slots. asyncspawn opcode and parse node are no more needed.In the backend async functions are also added to the generator JIT flag. await is desugared into yield.
90f2d97
to
a99327b
Compare
… the symbol capturing issues Merge pull request #1456 from aneeshdk:AsyncFuncAsGenerator This change removes the function wrapper implementation of async functions. Now the async functions will behave similar to generator functions. The actual function body will be in the sciptFunction field. Symbols now need not be forced to slots. asyncspawn opcode and parse node are no more needed.In the backend async functions are also added to the generator JIT flag. await is desugared into yield.
Updating async function implementation by desugaring to generators
This change removes the function wrapper implementation of async
functions. Now the async functions will behave similar to generator
functions. The actual function body will be in the sciptFunction field.
Symbols now need not be forced to slots. asyncspawn opcode and parse
node are no more needed.In the backend async functions are also
added to the generator JIT flag. await is desugared into yield.