Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: runtime/vm/parser.cc

Issue 1274133002: Don't zone-register async callbacks for every await call in the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: load async-op var. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 08d6bb74fa7ada3496a89d8d39d1647dce40a5da..7a95d110aaf46eb7c17464529ec70827f89561df 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -6742,6 +6742,8 @@ void Parser::AddContinuationVariables() {
void Parser::AddAsyncClosureVariables() {
// Add to current block's scope:
// var :async_op;
+ // var :async_then_callback;
+ // var :async_catch_error_callback;
// var :async_completer;
const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
LocalVariable* async_op_var = new(Z) LocalVariable(
@@ -6749,6 +6751,16 @@ void Parser::AddAsyncClosureVariables() {
current_block_->scope->AddVariable(async_op_var);
current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
async_op_var->set_is_captured();
+ LocalVariable* async_then_callback_var = new(Z) LocalVariable(
+ Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
+ current_block_->scope->AddVariable(async_then_callback_var);
+ current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
+ async_then_callback_var->set_is_captured();
+ LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
+ Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
+ current_block_->scope->AddVariable(async_catch_error_callback_var);
+ current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
+ async_catch_error_callback_var->set_is_captured();
LocalVariable* async_completer = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type);
current_block_->scope->AddVariable(async_completer);
@@ -6764,8 +6776,10 @@ void Parser::AddAsyncGeneratorVariables() {
// store the StreamController object to which the yielded expressions
// are added.
// var :async_op;
- // This variable is used to store the async generator closure containing
- // the body of the async* function. It is used by the await operator.
+ // var :async_then_callback;
+ // var :async_catch_error_callback;
+ // These variables are used to store the async generator closure containing
+ // the body of the async* function. They are used by the await operator.
const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
LocalVariable* controller_var = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type);
@@ -6778,6 +6792,16 @@ void Parser::AddAsyncGeneratorVariables() {
current_block_->scope->AddVariable(async_op_var);
current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
async_op_var->set_is_captured();
+ LocalVariable* async_then_callback_var = new(Z) LocalVariable(
+ Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
+ current_block_->scope->AddVariable(async_then_callback_var);
+ current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
+ async_then_callback_var->set_is_captured();
+ LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
+ Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
+ current_block_->scope->AddVariable(async_catch_error_callback_var);
+ current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
+ async_catch_error_callback_var->set_is_captured();
}
@@ -6859,6 +6883,8 @@ RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) {
// ... source code of f ...
// }
// var :async_op = f_async_body;
+// var :async_then_callback = _asyncThenWrapperHelper(:async_op);
+// var :async_catch_error_callback = _asyncCatchErrorWrapperHelper(:async_op);
// :controller = new _AsyncStarStreamController(:async_op);
// return :controller.stream;
// }
@@ -6878,9 +6904,15 @@ SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func,
closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false);
closure_body->scope()->LookupVariable(Symbols::Controller(), false);
closure_body->scope()->LookupVariable(Symbols::AsyncOperation(), false);
+ closure_body->scope()->LookupVariable(Symbols::AsyncThenCallback(), false);
+ closure_body->scope()->LookupVariable(
+ Symbols::AsyncCatchErrorCallback(), false);
+
+ const Library& async_lib = Library::Handle(Library::AsyncLibrary());
const Class& controller_class = Class::Handle(Z,
- Library::LookupCoreClass(Symbols::_AsyncStarStreamController()));
+ async_lib.LookupClassAllowPrivate(
+ Symbols::_AsyncStarStreamController()));
ASSERT(!controller_class.IsNull());
const Function& controller_constructor = Function::ZoneHandle(Z,
controller_class.LookupConstructorAllowPrivate(
@@ -6904,8 +6936,56 @@ SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func,
Scanner::kNoSourcePos,
async_op_var,
closure_obj);
+
current_block_->statements->Add(store_async_op);
+ // :async_then_callback = _asyncThenWrapperHelper(:async_op)
+ const Function& async_then_wrapper_helper = Function::ZoneHandle(
+ Z, async_lib.LookupFunctionAllowPrivate(
+ Symbols::AsyncThenWrapperHelper()));
+ ASSERT(!async_then_wrapper_helper.IsNull());
+ ArgumentListNode* async_then_wrapper_helper_args = new (Z) ArgumentListNode(
+ Scanner::kNoSourcePos);
+ async_then_wrapper_helper_args->Add(
+ new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
+ StaticCallNode* then_wrapper_call = new (Z) StaticCallNode(
+ Scanner::kNoSourcePos,
+ async_then_wrapper_helper,
+ async_then_wrapper_helper_args);
+ LocalVariable* async_then_callback_var =
+ current_block_->scope->LookupVariable(
+ Symbols::AsyncThenCallback(), false);
+ StoreLocalNode* store_async_then_callback = new (Z) StoreLocalNode(
+ Scanner::kNoSourcePos,
+ async_then_callback_var,
+ then_wrapper_call);
+
+ current_block_->statements->Add(store_async_then_callback);
+
+ // :async_catch_error_callback = _asyncErrorWrapperHelper(:async_op)
+
+ const Function& async_error_wrapper_helper = Function::ZoneHandle(
+ Z, async_lib.LookupFunctionAllowPrivate(
+ Symbols::AsyncErrorWrapperHelper()));
+ ASSERT(!async_error_wrapper_helper.IsNull());
+ ArgumentListNode* async_error_wrapper_helper_args = new (Z) ArgumentListNode(
+ Scanner::kNoSourcePos);
+ async_error_wrapper_helper_args->Add(
+ new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
+ StaticCallNode* error_wrapper_call = new (Z) StaticCallNode(
+ Scanner::kNoSourcePos,
+ async_error_wrapper_helper,
+ async_error_wrapper_helper_args);
+ LocalVariable* async_catch_error_callback_var =
+ current_block_->scope->LookupVariable(
+ Symbols::AsyncCatchErrorCallback(), false);
+ StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode(
+ Scanner::kNoSourcePos,
+ async_catch_error_callback_var,
+ error_wrapper_call);
+
+ current_block_->statements->Add(store_async_catch_error_callback);
+
// :controller = new _AsyncStarStreamController(body_closure);
ArgumentListNode* arguments = new(Z) ArgumentListNode(Scanner::kNoSourcePos);
arguments->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
@@ -7062,6 +7142,54 @@ SequenceNode* Parser::CloseAsyncFunction(const Function& closure,
cn);
current_block_->statements->Add(store_async_op);
+ const Library& async_lib = Library::Handle(Library::AsyncLibrary());
+ // :async_then_callback = _asyncThenWrapperHelper(:async_op)
+ const Function& async_then_wrapper_helper = Function::ZoneHandle(
+ Z, async_lib.LookupFunctionAllowPrivate(
+ Symbols::AsyncThenWrapperHelper()));
+ ASSERT(!async_then_wrapper_helper.IsNull());
+ ArgumentListNode* async_then_wrapper_helper_args = new (Z) ArgumentListNode(
+ Scanner::kNoSourcePos);
+ async_then_wrapper_helper_args->Add(
+ new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
+ StaticCallNode* then_wrapper_call = new (Z) StaticCallNode(
+ Scanner::kNoSourcePos,
+ async_then_wrapper_helper,
+ async_then_wrapper_helper_args);
+ LocalVariable* async_then_callback_var =
+ current_block_->scope->LookupVariable(
+ Symbols::AsyncThenCallback(), false);
+ StoreLocalNode* store_async_then_callback = new (Z) StoreLocalNode(
+ Scanner::kNoSourcePos,
+ async_then_callback_var,
+ then_wrapper_call);
+
+ current_block_->statements->Add(store_async_then_callback);
+
+ // :async_catch_error_callback = _asyncErrorWrapperHelper(:async_op)
+
+ const Function& async_error_wrapper_helper = Function::ZoneHandle(
+ Z, async_lib.LookupFunctionAllowPrivate(
+ Symbols::AsyncErrorWrapperHelper()));
+ ASSERT(!async_error_wrapper_helper.IsNull());
+ ArgumentListNode* async_error_wrapper_helper_args = new (Z) ArgumentListNode(
+ Scanner::kNoSourcePos);
+ async_error_wrapper_helper_args->Add(
+ new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
+ StaticCallNode* error_wrapper_call = new (Z) StaticCallNode(
+ Scanner::kNoSourcePos,
+ async_error_wrapper_helper,
+ async_error_wrapper_helper_args);
+ LocalVariable* async_catch_error_callback_var =
+ current_block_->scope->LookupVariable(
+ Symbols::AsyncCatchErrorCallback(), false);
+ StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode(
+ Scanner::kNoSourcePos,
+ async_catch_error_callback_var,
+ error_wrapper_call);
+
+ current_block_->statements->Add(store_async_catch_error_callback);
+
// Add to AST:
// new Future.microtask(:async_op);
ArgumentListNode* arguments = new (Z) ArgumentListNode(Scanner::kNoSourcePos);
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698