Skip to content

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

Merged
merged 1 commit into from
Aug 22, 2016

Conversation

aneeshdk
Copy link
Contributor

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.

@aneeshdk
Copy link
Contributor Author

@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.
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@ianwjhalliday
Copy link
Collaborator

                sym->GetScope()->GetFunc()->root->sxFnc.IsAsync());

I think this IsAsync check should be removed from this assert now


Refers to: lib/Runtime/ByteCode/ByteCodeGenerator.cpp:2434 in 8727492. [](commit_id = 8727492, deletion_comment = False)

@ianwjhalliday
Copy link
Collaborator

            if (parentFunc->root->sxFnc.IsAsync())

This should be removed, no longer true


Refers to: lib/Runtime/ByteCode/ByteCodeGenerator.cpp:5037 in 8727492. [](commit_id = 8727492, deletion_comment = False)

@ianwjhalliday
Copy link
Collaborator

if (pnode->sxFnc.IsAsync())

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);
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

@ianwjhalliday
Copy link
Collaborator

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.

@ianwjhalliday
Copy link
Collaborator

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).

@aneeshdk aneeshdk force-pushed the AsyncFuncAsGenerator branch 2 times, most recently from 3ed055a to 5e26878 Compare August 18, 2016 21:58
@aneeshdk aneeshdk changed the title Updating async function implementation by desugaring to generators Updating async function implementation to fix the symbol capturing issues Aug 18, 2016
@@ -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); }
Copy link
Collaborator

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

@aneeshdk aneeshdk force-pushed the AsyncFuncAsGenerator branch from 5e26878 to 9e3ce48 Compare August 18, 2016 23:59
@@ -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());
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@akroshg
Copy link
Contributor

akroshg commented Aug 19, 2016

Overall looks good to me. Are you planning to add debugger tests as well?

@aneeshdk aneeshdk force-pushed the AsyncFuncAsGenerator branch 2 times, most recently from 00795c5 to 2d71a1a Compare August 19, 2016 18:56
@aneeshdk
Copy link
Contributor Author

I will add debugger test cases in a separate change set

@dilijev
Copy link
Contributor

dilijev commented Aug 19, 2016

@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.
@aneeshdk aneeshdk force-pushed the AsyncFuncAsGenerator branch from 90f2d97 to a99327b Compare August 22, 2016 20:50
@chakrabot chakrabot merged commit a99327b into chakra-core:master Aug 22, 2016
chakrabot pushed a commit that referenced this pull request Aug 22, 2016
… 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.
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.

6 participants