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

Unified Diff: runtime/vm/parser.cc

Issue 1317213003: Improve async code in VM by not unnecessarily capturing parameters of async and (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Avoid duplicate aliases 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/flow_graph_builder.cc ('k') | runtime/vm/scopes.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 aa27a73b13b0348134750d225480a44e1f32a885..7df47357276501a91de28dd5a11ad8b013836c5c 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -6602,17 +6602,12 @@ RawFunction* Parser::OpenSyncGeneratorFunction(intptr_t func_pos) {
OpenFunctionBlock(body);
AddFormalParamsToScope(&closure_params, current_block_->scope);
- OpenBlock();
async_temp_scope_ = current_block_->scope;
return body.raw();
}
SequenceNode* Parser::CloseSyncGenFunction(const Function& closure,
SequenceNode* closure_body) {
- // The block for the closure body has already been closed. Close the
- // corresponding function block.
- CloseBlock();
-
LocalVariable* existing_var =
closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
ASSERT((existing_var != NULL) && existing_var->is_captured());
@@ -6745,7 +6740,6 @@ RawFunction* Parser::OpenAsyncFunction(intptr_t async_func_pos) {
}
OpenFunctionBlock(closure);
AddFormalParamsToScope(&closure_params, current_block_->scope);
- OpenBlock();
async_temp_scope_ = current_block_->scope;
return closure.raw();
}
@@ -6759,11 +6753,11 @@ void Parser::AddContinuationVariables() {
LocalVariable* await_jump_var = new (Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type);
current_block_->scope->AddVariable(await_jump_var);
- current_block_->scope->CaptureVariable(Symbols::AwaitJumpVar());
+ current_block_->scope->CaptureVariable(await_jump_var);
LocalVariable* await_ctx_var = new (Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type);
current_block_->scope->AddVariable(await_ctx_var);
- current_block_->scope->CaptureVariable(Symbols::AwaitContextVar());
+ current_block_->scope->CaptureVariable(await_ctx_var);
}
@@ -6777,19 +6771,19 @@ void Parser::AddAsyncClosureVariables() {
LocalVariable* async_op_var = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
current_block_->scope->AddVariable(async_op_var);
- current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
+ current_block_->scope->CaptureVariable(async_op_var);
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());
+ current_block_->scope->CaptureVariable(async_then_callback_var);
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());
+ current_block_->scope->CaptureVariable(async_catch_error_callback_var);
LocalVariable* async_completer = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type);
current_block_->scope->AddVariable(async_completer);
- current_block_->scope->CaptureVariable(Symbols::AsyncCompleter());
+ current_block_->scope->CaptureVariable(async_completer);
}
@@ -6808,20 +6802,19 @@ void Parser::AddAsyncGeneratorVariables() {
LocalVariable* controller_var = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type);
current_block_->scope->AddVariable(controller_var);
- current_block_->scope->CaptureVariable(Symbols::Controller());
-
+ current_block_->scope->CaptureVariable(controller_var);
LocalVariable* async_op_var = new(Z) LocalVariable(
Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
current_block_->scope->AddVariable(async_op_var);
- current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
+ current_block_->scope->CaptureVariable(async_op_var);
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());
+ current_block_->scope->CaptureVariable(async_then_callback_var);
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());
+ current_block_->scope->CaptureVariable(async_catch_error_callback_var);
}
@@ -6887,7 +6880,6 @@ RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) {
OpenFunctionBlock(closure);
AddFormalParamsToScope(&closure_params, current_block_->scope);
- OpenBlock();
async_temp_scope_ = current_block_->scope;
return closure.raw();
}
@@ -6914,10 +6906,6 @@ SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func,
ASSERT(!closure_func.IsNull());
ASSERT(closure_body != NULL);
- // The block for the async closure body has already been closed. Close the
- // corresponding function block.
- CloseBlock();
-
// Make sure the implicit variables of the async generator function
// are captured.
LocalVariable* existing_var = closure_body->scope()->LookupVariable(
@@ -7119,10 +7107,6 @@ SequenceNode* Parser::CloseAsyncFunction(const Function& closure,
ASSERT(!closure.IsNull());
ASSERT(closure_body != NULL);
- // The block for the async closure body has already been closed. Close the
- // corresponding function block.
- CloseBlock();
-
LocalVariable* existing_var =
closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
ASSERT((existing_var != NULL) && existing_var->is_captured());
@@ -7138,7 +7122,7 @@ SequenceNode* Parser::CloseAsyncFunction(const Function& closure,
// No need to capture parameters or other variables, since they have already
// been captured in the corresponding scope as the body has been parsed within
- // a nested block (contained in the async funtion's block).
+ // a nested block (contained in the async function's block).
const Class& future =
Class::ZoneHandle(Z, I->object_store()->future_class());
ASSERT(!future.IsNull());
@@ -7429,14 +7413,10 @@ LocalVariable* Parser::LookupPhaseParameter() {
void Parser::CaptureInstantiator() {
ASSERT(current_block_->scope->function_level() > 0);
- bool found = false;
- if (current_function().IsInFactoryScope()) {
- found = current_block_->scope->CaptureVariable(
- Symbols::TypeArgumentsParameter());
- } else {
- found = current_block_->scope->CaptureVariable(Symbols::This());
- }
- ASSERT(found);
+ const String* variable_name = current_function().IsInFactoryScope() ?
+ &Symbols::TypeArgumentsParameter() : &Symbols::This();
+ current_block_->scope->CaptureVariable(
+ current_block_->scope->LookupVariable(*variable_name, true));
}
@@ -7524,14 +7504,10 @@ AstNode* Parser::ParseVariableDeclaration(const AbstractType& type,
LocalVariable* existing_var =
current_block_->scope->LookupVariable(variable->name(), true);
ASSERT(existing_var != NULL);
- if (existing_var->owner() == current_block_->scope) {
- ReportError(ident_pos, "identifier '%s' already defined",
- variable->name().ToCString());
- } else {
- ReportError(ident_pos, "'%s' from outer scope has already been used, "
- "cannot redefine",
- variable->name().ToCString());
- }
+ // Use before define cases have already been detected and reported above.
+ ASSERT(existing_var->owner() == current_block_->scope);
+ ReportError(ident_pos, "identifier '%s' already defined",
+ variable->name().ToCString());
}
if (is_final || is_const) {
variable->set_is_final();
@@ -7724,15 +7700,10 @@ AstNode* Parser::ParseFunctionStatement(bool is_literal) {
current_block_->scope->LookupVariable(function_variable->name(),
true);
ASSERT(existing_var != NULL);
- if (existing_var->owner() == current_block_->scope) {
- ReportError(function_pos, "identifier '%s' already defined",
- function_variable->name().ToCString());
- } else {
- ReportError(function_pos,
- "'%s' from outer scope has already been used, "
- "cannot redefine",
- function_variable->name().ToCString());
- }
+ // Use before define cases have already been detected and reported above.
+ ASSERT(existing_var->owner() == current_block_->scope);
+ ReportError(function_pos, "identifier '%s' already defined",
+ function_variable->name().ToCString());
}
}
@@ -9602,7 +9573,7 @@ void Parser::SetupSavedTryContext(LocalVariable* saved_try_context) {
Type::ZoneHandle(Z, Type::DynamicType()));
ASSERT(async_temp_scope_ != NULL);
async_temp_scope_->AddVariable(async_saved_try_ctx);
- current_block_->scope->CaptureVariable(async_saved_try_ctx_name);
+ current_block_->scope->CaptureVariable(async_saved_try_ctx);
ASSERT(saved_try_context != NULL);
current_block_->statements->Add(new(Z) StoreLocalNode(
Scanner::kNoSourcePos,
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698