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

Side by Side Diff: runtime/vm/ast_transformer.cc

Issue 1308163006: Reduce the number of captured variables in async code, by only capturing local (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/ast_transformer.h" 5 #include "vm/ast_transformer.h"
6 6
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/parser.h" 8 #include "vm/parser.h"
9 #include "vm/thread.h" 9 #include "vm/thread.h"
10 10
(...skipping 28 matching lines...) Expand all
39 39
40 #define DEFINE_UNREACHABLE(BaseName) \ 40 #define DEFINE_UNREACHABLE(BaseName) \
41 void AwaitTransformer::Visit##BaseName##Node(BaseName##Node* node) { \ 41 void AwaitTransformer::Visit##BaseName##Node(BaseName##Node* node) { \
42 UNREACHABLE(); \ 42 UNREACHABLE(); \
43 } 43 }
44 44
45 FOR_EACH_UNREACHABLE_NODE(DEFINE_UNREACHABLE) 45 FOR_EACH_UNREACHABLE_NODE(DEFINE_UNREACHABLE)
46 #undef DEFINE_UNREACHABLE 46 #undef DEFINE_UNREACHABLE
47 47
48 AwaitTransformer::AwaitTransformer(SequenceNode* preamble, 48 AwaitTransformer::AwaitTransformer(SequenceNode* preamble,
49 LocalScope* function_top) 49 LocalScope* function_top)
hausner 2015/09/02 22:07:55 Rename function_top_ to async_temp_scope_ so the n
regis 2015/09/03 01:28:04 Done.
50 : preamble_(preamble), 50 : preamble_(preamble),
51 temp_cnt_(0), 51 temp_cnt_(0),
52 function_top_(function_top), 52 function_top_(function_top),
53 thread_(Thread::Current()) { 53 thread_(Thread::Current()) {
54 ASSERT(function_top_ != NULL); 54 ASSERT(function_top_ != NULL);
55 } 55 }
56 56
57 57
58 AstNode* AwaitTransformer::Transform(AstNode* expr) { 58 AstNode* AwaitTransformer::Transform(AstNode* expr) {
59 expr->Visit(this); 59 expr->Visit(this);
60 return result_; 60 return result_;
61 } 61 }
62 62
63 63
64 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() { 64 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() {
65 const char* await_temp_prefix = ":await_temp_var_"; 65 const char* await_temp_prefix = Symbols::AwaitTempVarPrefix().ToCString();
hausner 2015/09/02 22:07:55 Does it make sense to define this string constant
regis 2015/09/03 01:28:03 Done.
srdjan 2015/09/03 01:50:47 This is problematic as it allocates a String in th
regis 2015/09/03 16:48:38 The previous version also allocates a new string,
66 const String& cnt_str = String::ZoneHandle( 66 const String& cnt_str = String::ZoneHandle(
67 Z, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_)); 67 Z, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_));
68 const String& symbol = String::ZoneHandle(Z, Symbols::New(cnt_str)); 68 const String& symbol = String::ZoneHandle(Z, Symbols::New(cnt_str));
69 ASSERT(!symbol.IsNull()); 69 ASSERT(!symbol.IsNull());
70 // Look up the variable in the scope used for async temp variables. 70 // Look up the variable in the scope used for async temp variables.
71 LocalVariable* await_tmp = function_top_->LocalLookupVariable(symbol); 71 LocalVariable* await_tmp = function_top_->LocalLookupVariable(symbol);
72 if (await_tmp == NULL) { 72 if (await_tmp == NULL) {
73 // We need a new temp variable; add it to the function's top scope. 73 // We need a new temp variable; add it to the function's top scope.
74 await_tmp = new (Z) LocalVariable( 74 await_tmp = new (Z) LocalVariable(
75 Scanner::kNoSourcePos, symbol, Type::ZoneHandle(Type::DynamicType())); 75 Scanner::kNoSourcePos, symbol, Type::ZoneHandle(Type::DynamicType()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 LocalVariable* result_param = GetVariableInScope( 129 LocalVariable* result_param = GetVariableInScope(
130 preamble_->scope(), Symbols::AsyncOperationParam()); 130 preamble_->scope(), Symbols::AsyncOperationParam());
131 LocalVariable* error_param = GetVariableInScope( 131 LocalVariable* error_param = GetVariableInScope(
132 preamble_->scope(), Symbols::AsyncOperationErrorParam()); 132 preamble_->scope(), Symbols::AsyncOperationErrorParam());
133 LocalVariable* stack_trace_param = GetVariableInScope( 133 LocalVariable* stack_trace_param = GetVariableInScope(
134 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); 134 preamble_->scope(), Symbols::AsyncOperationStackTraceParam());
135 135
136 AstNode* transformed_expr = Transform(node->expr()); 136 AstNode* transformed_expr = Transform(node->expr());
137 LocalVariable* await_temp = AddToPreambleNewTempVar(transformed_expr); 137 LocalVariable* await_temp = AddToPreambleNewTempVar(transformed_expr);
138 138
139 AwaitMarkerNode* await_marker = new (Z) AwaitMarkerNode(); 139 AwaitMarkerNode* await_marker =
140 await_marker->set_scope(preamble_->scope()); 140 new (Z) AwaitMarkerNode(function_top_, node->scope());
141 preamble_->Add(await_marker); 141 preamble_->Add(await_marker);
142 142
143 // :result_param = _awaitHelper( 143 // :result_param = _awaitHelper(
144 // :await_temp, :async_then_callback, :async_catch_error_callback) 144 // :await_temp, :async_then_callback, :async_catch_error_callback)
145 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); 145 const Library& async_lib = Library::Handle(Library::AsyncLibrary());
146 const Function& async_await_helper = Function::ZoneHandle( 146 const Function& async_await_helper = Function::ZoneHandle(
147 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper())); 147 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper()));
148 ASSERT(!async_await_helper.IsNull()); 148 ASSERT(!async_await_helper.IsNull());
149 ArgumentListNode* async_await_helper_args = new (Z) ArgumentListNode( 149 ArgumentListNode* async_await_helper_args = new (Z) ArgumentListNode(
150 Scanner::kNoSourcePos); 150 Scanner::kNoSourcePos);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 578
579 579
580 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { 580 void AwaitTransformer::VisitThrowNode(ThrowNode* node) {
581 AstNode* new_exception = Transform(node->exception()); 581 AstNode* new_exception = Transform(node->exception());
582 result_ = new(Z) ThrowNode(node->token_pos(), 582 result_ = new(Z) ThrowNode(node->token_pos(),
583 new_exception, 583 new_exception,
584 node->stacktrace()); 584 node->stacktrace());
585 } 585 }
586 586
587 } // namespace dart 587 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698