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

Unified Diff: runtime/vm/ast_transformer.cc

Issue 1861963007: Dart VM: Fix an order-of-evaluation bug in async code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge upstream/master. Created 4 years, 8 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.h ('k') | tests/language/regress_26175_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ast_transformer.cc
diff --git a/runtime/vm/ast_transformer.cc b/runtime/vm/ast_transformer.cc
index 4b058676fa08bc1867077e1510ef91eda954954d..2137931d3acd75f4b2a66044a748573e861fa421 100644
--- a/runtime/vm/ast_transformer.cc
+++ b/runtime/vm/ast_transformer.cc
@@ -73,7 +73,7 @@ LocalVariable* AwaitTransformer::EnsureCurrentTempVar() {
LocalVariable* await_tmp = async_temp_scope_->LocalLookupVariable(symbol);
if (await_tmp == NULL) {
// We need a new temp variable; add it to the function's top scope.
- await_tmp = new (Z) LocalVariable(
+ await_tmp = new(Z) LocalVariable(
TokenPosition::kNoSource, symbol, Object::dynamic_type());
async_temp_scope_->AddVariable(await_tmp);
// After adding it to the top scope, we can look it up from the preamble.
@@ -92,7 +92,7 @@ LocalVariable* AwaitTransformer::GetVariableInScope(LocalScope* scope,
}
-LocalVariable* AwaitTransformer::AddToPreambleNewTempVar(
+LocalVariable* AwaitTransformer::AddNewTempVarToPreamble(
AstNode* node,
TokenPosition token_pos) {
LocalVariable* tmp_var = EnsureCurrentTempVar();
@@ -103,6 +103,12 @@ LocalVariable* AwaitTransformer::AddToPreambleNewTempVar(
}
+LoadLocalNode* AwaitTransformer::MakeName(AstNode* node) {
+ LocalVariable* temp = AddNewTempVarToPreamble(node, ST(node->token_pos()));
+ return new(Z) LoadLocalNode(ST(node->token_pos()), temp);
+}
+
+
void AwaitTransformer::VisitLiteralNode(LiteralNode* node) {
result_ = node;
}
@@ -140,11 +146,11 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) {
preamble_->scope(), Symbols::AsyncOperationStackTraceParam());
AstNode* transformed_expr = Transform(node->expr());
- LocalVariable* await_temp = AddToPreambleNewTempVar(transformed_expr,
+ LocalVariable* await_temp = AddNewTempVarToPreamble(transformed_expr,
ST(node->token_pos()));
AwaitMarkerNode* await_marker =
- new (Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos);
+ new(Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos);
preamble_->Add(await_marker);
// :result_param = _awaitHelper(
@@ -154,14 +160,14 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) {
Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper()));
ASSERT(!async_await_helper.IsNull());
ArgumentListNode* async_await_helper_args =
- new (Z) ArgumentListNode(token_pos);
+ new(Z) ArgumentListNode(token_pos);
async_await_helper_args->Add(
new(Z) LoadLocalNode(token_pos, await_temp));
async_await_helper_args->Add(
new(Z) LoadLocalNode(token_pos, async_then_callback));
async_await_helper_args->Add(
new(Z) LoadLocalNode(token_pos, async_catch_error_callback));
- StaticCallNode* await_helper_call = new (Z) StaticCallNode(
+ StaticCallNode* await_helper_call = new(Z) StaticCallNode(
node->token_pos(),
async_await_helper,
async_await_helper_args);
@@ -177,17 +183,17 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) {
// restoring the saved try context that lives on the stack and possibly the
// saved try context of the outer try block.
if (node->saved_try_ctx() != NULL) {
- preamble_->Add(new (Z) StoreLocalNode(
+ preamble_->Add(new(Z) StoreLocalNode(
token_pos,
node->saved_try_ctx(),
- new (Z) LoadLocalNode(token_pos,
- node->async_saved_try_ctx())));
+ new(Z) LoadLocalNode(token_pos,
+ node->async_saved_try_ctx())));
if (node->outer_saved_try_ctx() != NULL) {
- preamble_->Add(new (Z) StoreLocalNode(
+ preamble_->Add(new(Z) StoreLocalNode(
token_pos,
node->outer_saved_try_ctx(),
- new (Z) LoadLocalNode(token_pos,
- node->outer_async_saved_try_ctx())));
+ new(Z) LoadLocalNode(token_pos,
+ node->outer_async_saved_try_ctx())));
}
} else {
ASSERT(node->outer_saved_try_ctx() == NULL);
@@ -195,31 +201,31 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) {
// Load the async_op variable. It is unused, but the observatory uses it
// to determine if a breakpoint is inside an asynchronous function.
- LoadLocalNode* load_async_op = new (Z) LoadLocalNode(token_pos, async_op);
+ LoadLocalNode* load_async_op = new(Z) LoadLocalNode(token_pos, async_op);
preamble_->Add(load_async_op);
- LoadLocalNode* load_error_param = new (Z) LoadLocalNode(
+ LoadLocalNode* load_error_param = new(Z) LoadLocalNode(
token_pos, error_param);
- LoadLocalNode* load_stack_trace_param = new (Z) LoadLocalNode(
+ LoadLocalNode* load_stack_trace_param = new(Z) LoadLocalNode(
token_pos, stack_trace_param);
- SequenceNode* error_ne_null_branch = new (Z) SequenceNode(
+ SequenceNode* error_ne_null_branch = new(Z) SequenceNode(
token_pos, ChainNewScope(preamble_->scope()));
- error_ne_null_branch->Add(new (Z) ThrowNode(
+ error_ne_null_branch->Add(new(Z) ThrowNode(
token_pos,
load_error_param,
load_stack_trace_param));
- preamble_->Add(new (Z) IfNode(
+ preamble_->Add(new(Z) IfNode(
token_pos,
- new (Z) ComparisonNode(
+ new(Z) ComparisonNode(
token_pos,
Token::kNE,
load_error_param,
- new (Z) LiteralNode(token_pos,
+ new(Z) LiteralNode(token_pos,
Object::null_instance())),
error_ne_null_branch,
NULL));
- LocalVariable* result = AddToPreambleNewTempVar(new(Z) LoadLocalNode(
+ LocalVariable* result = AddNewTempVarToPreamble(new(Z) LoadLocalNode(
token_pos, result_param), ST(node->token_pos()));
result_ = new(Z) LoadLocalNode(token_pos, result);
}
@@ -247,7 +253,7 @@ AstNode* AwaitTransformer::LazyTransform(const Token::Kind logical_op,
AstNode* result = NULL;
const Token::Kind compare_logical_op = (logical_op == Token::kAND) ?
Token::kEQ : Token::kNE;
- SequenceNode* eval = new (Z) SequenceNode(
+ SequenceNode* eval = new(Z) SequenceNode(
ST(new_left->token_pos()), ChainNewScope(preamble_->scope()));
SequenceNode* saved_preamble = preamble_;
preamble_ = eval;
@@ -268,7 +274,7 @@ AstNode* AwaitTransformer::LazyTransform(const Token::Kind logical_op,
LocalScope* AwaitTransformer::ChainNewScope(LocalScope* parent) {
- return new (Z) LocalScope(
+ return new(Z) LocalScope(
parent, parent->function_level(), parent->loop_level());
}
@@ -282,12 +288,10 @@ void AwaitTransformer::VisitBinaryOpNode(BinaryOpNode* node) {
} else {
new_right = Transform(node->right());
}
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) BinaryOpNode(node->token_pos(),
- node->kind(),
- new_left,
- new_right), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) BinaryOpNode(node->token_pos(),
+ node->kind(),
+ new_left,
+ new_right));
}
@@ -296,34 +300,29 @@ void AwaitTransformer::VisitBinaryOpWithMask32Node(
ASSERT((node->kind() != Token::kAND) && (node->kind() != Token::kOR));
AstNode* new_left = Transform(node->left());
AstNode* new_right = Transform(node->right());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) BinaryOpWithMask32Node(node->token_pos(),
- node->kind(),
- new_left,
- new_right,
- node->mask32()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) BinaryOpWithMask32Node(node->token_pos(),
+ node->kind(),
+ new_left,
+ new_right,
+ node->mask32()));
}
void AwaitTransformer::VisitComparisonNode(ComparisonNode* node) {
AstNode* new_left = Transform(node->left());
AstNode* new_right = Transform(node->right());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) ComparisonNode(node->token_pos(),
- node->kind(),
- new_left,
- new_right), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) ComparisonNode(node->token_pos(),
+ node->kind(),
+ new_left,
+ new_right));
}
void AwaitTransformer::VisitUnaryOpNode(UnaryOpNode* node) {
AstNode* new_operand = Transform(node->operand());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) UnaryOpNode(node->token_pos(), node->kind(), new_operand),
- ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) UnaryOpNode(node->token_pos(),
+ node->kind(),
+ new_operand));
}
@@ -331,12 +330,12 @@ void AwaitTransformer::VisitUnaryOpNode(UnaryOpNode* node) {
//
void AwaitTransformer::VisitConditionalExprNode(ConditionalExprNode* node) {
AstNode* new_condition = Transform(node->condition());
- SequenceNode* new_true = new (Z) SequenceNode(
+ SequenceNode* new_true = new(Z) SequenceNode(
ST(node->true_expr()->token_pos()), ChainNewScope(preamble_->scope()));
SequenceNode* saved_preamble = preamble_;
preamble_ = new_true;
AstNode* new_true_result = Transform(node->true_expr());
- SequenceNode* new_false = new (Z) SequenceNode(
+ SequenceNode* new_false = new(Z) SequenceNode(
ST(node->false_expr()->token_pos()), ChainNewScope(preamble_->scope()));
preamble_ = new_false;
AstNode* new_false_result = Transform(node->false_expr());
@@ -346,12 +345,10 @@ void AwaitTransformer::VisitConditionalExprNode(ConditionalExprNode* node) {
new_true,
new_false);
preamble_->Add(new_if);
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) ConditionalExprNode(ST(node->token_pos()),
- new_condition,
- new_true_result,
- new_false_result), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) ConditionalExprNode(ST(node->token_pos()),
+ new_condition,
+ new_true_result,
+ new_false_result));
}
@@ -376,10 +373,8 @@ void AwaitTransformer::VisitArrayNode(ArrayNode* node) {
void AwaitTransformer::VisitStringInterpolateNode(StringInterpolateNode* node) {
ArrayNode* new_value = Transform(node->value())->AsArrayNode();
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) StringInterpolateNode(node->token_pos(),
- new_value), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) StringInterpolateNode(node->token_pos(),
+ new_value));
}
@@ -388,12 +383,10 @@ void AwaitTransformer::VisitClosureNode(ClosureNode* node) {
if (new_receiver != NULL) {
new_receiver = Transform(new_receiver);
}
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) ClosureNode(node->token_pos(),
- node->function(),
- new_receiver,
- node->scope()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) ClosureNode(node->token_pos(),
+ node->function(),
+ new_receiver,
+ node->scope()));
}
@@ -401,47 +394,39 @@ void AwaitTransformer::VisitInstanceCallNode(InstanceCallNode* node) {
AstNode* new_receiver = Transform(node->receiver());
ArgumentListNode* new_args =
Transform(node->arguments())->AsArgumentListNode();
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) InstanceCallNode(node->token_pos(),
- new_receiver,
- node->function_name(),
- new_args,
- node->is_conditional()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) InstanceCallNode(node->token_pos(),
+ new_receiver,
+ node->function_name(),
+ new_args,
+ node->is_conditional()));
}
void AwaitTransformer::VisitStaticCallNode(StaticCallNode* node) {
ArgumentListNode* new_args =
Transform(node->arguments())->AsArgumentListNode();
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) StaticCallNode(node->token_pos(),
- node->function(),
- new_args), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) StaticCallNode(node->token_pos(),
+ node->function(),
+ new_args));
}
void AwaitTransformer::VisitConstructorCallNode(ConstructorCallNode* node) {
ArgumentListNode* new_args =
Transform(node->arguments())->AsArgumentListNode();
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) ConstructorCallNode(node->token_pos(),
- node->type_arguments(),
- node->constructor(),
- new_args), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) ConstructorCallNode(node->token_pos(),
+ node->type_arguments(),
+ node->constructor(),
+ new_args));
}
void AwaitTransformer::VisitInstanceGetterNode(InstanceGetterNode* node) {
AstNode* new_receiver = Transform(node->receiver());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) InstanceGetterNode(node->token_pos(),
- new_receiver,
- node->field_name(),
- node->is_conditional()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) InstanceGetterNode(node->token_pos(),
+ new_receiver,
+ node->field_name(),
+ node->is_conditional()));
}
@@ -451,13 +436,11 @@ void AwaitTransformer::VisitInstanceSetterNode(InstanceSetterNode* node) {
new_receiver = Transform(new_receiver);
}
AstNode* new_value = Transform(node->value());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) InstanceSetterNode(node->token_pos(),
- new_receiver,
- node->field_name(),
- new_value,
- node->is_conditional()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) InstanceSetterNode(node->token_pos(),
+ new_receiver,
+ node->field_name(),
+ new_value,
+ node->is_conditional()));
}
@@ -472,9 +455,7 @@ void AwaitTransformer::VisitStaticGetterNode(StaticGetterNode* node) {
node->cls(),
node->field_name());
new_getter->set_owner(node->owner());
- LocalVariable* result =
- AddToPreambleNewTempVar(new_getter, ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new_getter);
}
@@ -497,46 +478,43 @@ void AwaitTransformer::VisitStaticSetterNode(StaticSetterNode* node) {
node->function(),
new_value);
- LocalVariable* result =
- AddToPreambleNewTempVar(new_setter, ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new_setter);
}
void AwaitTransformer::VisitLoadLocalNode(LoadLocalNode* node) {
- result_ = node;
+ result_ = MakeName(node);
}
void AwaitTransformer::VisitStoreLocalNode(StoreLocalNode* node) {
AstNode* new_value = Transform(node->value());
- result_ = new(Z) StoreLocalNode(node->token_pos(), &node->local(), new_value);
+ result_ = MakeName(new(Z) StoreLocalNode(node->token_pos(),
+ &node->local(),
+ new_value));
}
void AwaitTransformer::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) {
- result_ = node;
+ result_ = MakeName(node);
}
void AwaitTransformer::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) {
AstNode* new_value = Transform(node->value());
- result_ = new(Z) StoreStaticFieldNode(
- node->token_pos(),
+ result_ = MakeName(new(Z) StoreStaticFieldNode(node->token_pos(),
Field::ZoneHandle(Z, node->field().Original()),
- new_value);
+ new_value));
}
void AwaitTransformer::VisitLoadIndexedNode(LoadIndexedNode* node) {
AstNode* new_array = Transform(node->array());
AstNode* new_index = Transform(node->index_expr());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) LoadIndexedNode(node->token_pos(),
- new_array,
- new_index,
- node->super_class()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) LoadIndexedNode(node->token_pos(),
+ new_array,
+ new_index,
+ node->super_class()));
}
@@ -544,24 +522,20 @@ void AwaitTransformer::VisitStoreIndexedNode(StoreIndexedNode* node) {
AstNode* new_array = Transform(node->array());
AstNode* new_index = Transform(node->index_expr());
AstNode* new_value = Transform(node->value());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) StoreIndexedNode(node->token_pos(),
- new_array,
- new_index,
- new_value,
- node->super_class()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) StoreIndexedNode(node->token_pos(),
+ new_array,
+ new_index,
+ new_value,
+ node->super_class()));
}
void AwaitTransformer::VisitAssignableNode(AssignableNode* node) {
AstNode* new_expr = Transform(node->expr());
- LocalVariable* result = AddToPreambleNewTempVar(
- new(Z) AssignableNode(node->token_pos(),
- new_expr,
- node->type(),
- node->dst_name()), ST(node->token_pos()));
- result_ = new(Z) LoadLocalNode(ST(node->token_pos()), result);
+ result_ = MakeName(new(Z) AssignableNode(node->token_pos(),
+ new_expr,
+ node->type(),
+ node->dst_name()));
}
@@ -598,9 +572,9 @@ void AwaitTransformer::VisitLetNode(LetNode* node) {
void AwaitTransformer::VisitThrowNode(ThrowNode* node) {
AstNode* new_exception = Transform(node->exception());
- result_ = new(Z) ThrowNode(node->token_pos(),
- new_exception,
- node->stacktrace());
+ result_ = MakeName(new(Z) ThrowNode(node->token_pos(),
+ new_exception,
+ node->stacktrace()));
}
} // namespace dart
« no previous file with comments | « runtime/vm/ast_transformer.h ('k') | tests/language/regress_26175_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698