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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 6705 matching lines...) Expand 10 before | Expand all | Expand 10 after
6716 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type); 6716 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type);
6717 current_block_->scope->AddVariable(await_ctx_var); 6717 current_block_->scope->AddVariable(await_ctx_var);
6718 current_block_->scope->CaptureVariable(Symbols::AwaitContextVar()); 6718 current_block_->scope->CaptureVariable(Symbols::AwaitContextVar());
6719 await_ctx_var->set_is_captured(); 6719 await_ctx_var->set_is_captured();
6720 } 6720 }
6721 6721
6722 6722
6723 void Parser::AddAsyncClosureVariables() { 6723 void Parser::AddAsyncClosureVariables() {
6724 // Add to current block's scope: 6724 // Add to current block's scope:
6725 // var :async_op; 6725 // var :async_op;
6726 // var :async_then_callback;
6727 // var :async_catch_error_callback;
6726 // var :async_completer; 6728 // var :async_completer;
6727 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6729 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6728 LocalVariable* async_op_var = new(Z) LocalVariable( 6730 LocalVariable* async_op_var = new(Z) LocalVariable(
6729 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6731 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6730 current_block_->scope->AddVariable(async_op_var); 6732 current_block_->scope->AddVariable(async_op_var);
6731 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6733 current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
6732 async_op_var->set_is_captured(); 6734 async_op_var->set_is_captured();
6735 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6736 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6737 current_block_->scope->AddVariable(async_then_callback_var);
6738 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
6739 async_then_callback_var->set_is_captured();
6740 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6741 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6742 current_block_->scope->AddVariable(async_catch_error_callback_var);
6743 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
6744 async_catch_error_callback_var->set_is_captured();
6733 LocalVariable* async_completer = new(Z) LocalVariable( 6745 LocalVariable* async_completer = new(Z) LocalVariable(
6734 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type); 6746 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type);
6735 current_block_->scope->AddVariable(async_completer); 6747 current_block_->scope->AddVariable(async_completer);
6736 current_block_->scope->CaptureVariable(Symbols::AsyncCompleter()); 6748 current_block_->scope->CaptureVariable(Symbols::AsyncCompleter());
6737 async_completer->set_is_captured(); 6749 async_completer->set_is_captured();
6738 } 6750 }
6739 6751
6740 6752
6741 void Parser::AddAsyncGeneratorVariables() { 6753 void Parser::AddAsyncGeneratorVariables() {
6742 // Add to current block's scope: 6754 // Add to current block's scope:
6743 // var :controller; 6755 // var :controller;
6744 // The :controller variable is used by the async generator closure to 6756 // The :controller variable is used by the async generator closure to
6745 // store the StreamController object to which the yielded expressions 6757 // store the StreamController object to which the yielded expressions
6746 // are added. 6758 // are added.
6747 // var :async_op; 6759 // var :async_op;
6748 // This variable is used to store the async generator closure containing 6760 // var :async_then_callback;
6761 // var :async_catch_error_callback;
6762 // These variables are used to store the async generator closure containing
6749 // the body of the async* function. It is used by the await operator. 6763 // the body of the async* function. It is used by the await operator.
6750 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6764 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6751 LocalVariable* controller_var = new(Z) LocalVariable( 6765 LocalVariable* controller_var = new(Z) LocalVariable(
6752 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type); 6766 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type);
6753 current_block_->scope->AddVariable(controller_var); 6767 current_block_->scope->AddVariable(controller_var);
6754 current_block_->scope->CaptureVariable(Symbols::Controller()); 6768 current_block_->scope->CaptureVariable(Symbols::Controller());
6755 controller_var->set_is_captured(); 6769 controller_var->set_is_captured();
6756 6770
6757 LocalVariable* async_op_var = new(Z) LocalVariable( 6771 LocalVariable* async_op_var = new(Z) LocalVariable(
6758 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6772 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6759 current_block_->scope->AddVariable(async_op_var); 6773 current_block_->scope->AddVariable(async_op_var);
6760 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6774 current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
6761 async_op_var->set_is_captured(); 6775 async_op_var->set_is_captured();
6776 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6777 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6778 current_block_->scope->AddVariable(async_then_callback_var);
6779 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
6780 async_then_callback_var->set_is_captured();
6781 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6782 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6783 current_block_->scope->AddVariable(async_catch_error_callback_var);
6784 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
6785 async_catch_error_callback_var->set_is_captured();
6762 } 6786 }
6763 6787
6764 6788
6765 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) { 6789 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) {
6766 TRACE_PARSER("OpenAsyncGeneratorFunction"); 6790 TRACE_PARSER("OpenAsyncGeneratorFunction");
6767 AddContinuationVariables(); 6791 AddContinuationVariables();
6768 AddAsyncGeneratorVariables(); 6792 AddAsyncGeneratorVariables();
6769 6793
6770 Function& closure = Function::Handle(Z); 6794 Function& closure = Function::Handle(Z);
6771 bool is_new_closure = false; 6795 bool is_new_closure = false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
6833 // Generate the Ast nodes for the implicit code of the async* function. 6857 // Generate the Ast nodes for the implicit code of the async* function.
6834 // 6858 //
6835 // f(...) async* { 6859 // f(...) async* {
6836 // var :controller; 6860 // var :controller;
6837 // var :await_jump_var = -1; 6861 // var :await_jump_var = -1;
6838 // var :await_context_var; 6862 // var :await_context_var;
6839 // f_async_body() { 6863 // f_async_body() {
6840 // ... source code of f ... 6864 // ... source code of f ...
6841 // } 6865 // }
6842 // var :async_op = f_async_body; 6866 // var :async_op = f_async_body;
6867 // var :async_then_callback = _asyncThenWrapperHelper(:async_op);
6868 // var :async_catch_error_callback = _asyncCatchErrorWrapperHelper(:async_op);
6843 // :controller = new _AsyncStarStreamController(:async_op); 6869 // :controller = new _AsyncStarStreamController(:async_op);
6844 // return :controller.stream; 6870 // return :controller.stream;
6845 // } 6871 // }
6846 SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func, 6872 SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func,
6847 SequenceNode* closure_body) { 6873 SequenceNode* closure_body) {
6848 TRACE_PARSER("CloseAsyncGeneratorFunction"); 6874 TRACE_PARSER("CloseAsyncGeneratorFunction");
6849 ASSERT(!closure_func.IsNull()); 6875 ASSERT(!closure_func.IsNull());
6850 ASSERT(closure_body != NULL); 6876 ASSERT(closure_body != NULL);
6851 6877
6852 // The block for the async closure body has already been closed. Close the 6878 // The block for the async closure body has already been closed. Close the
6853 // corresponding function block. 6879 // corresponding function block.
6854 CloseBlock(); 6880 CloseBlock();
6855 6881
6856 // Make sure the implicit variables of the async generator function 6882 // Make sure the implicit variables of the async generator function
6857 // are captured. 6883 // are captured.
6858 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); 6884 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
6859 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); 6885 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false);
6860 closure_body->scope()->LookupVariable(Symbols::Controller(), false); 6886 closure_body->scope()->LookupVariable(Symbols::Controller(), false);
6861 closure_body->scope()->LookupVariable(Symbols::AsyncOperation(), false); 6887 closure_body->scope()->LookupVariable(Symbols::AsyncOperation(), false);
6888 closure_body->scope()->LookupVariable(Symbols::AsyncThenCallback(), false);
6889 closure_body->scope()->LookupVariable(
6890 Symbols::AsyncCatchErrorCallback(), false);
6862 6891
6863 const Class& controller_class = Class::Handle(Z, 6892 const Class& controller_class = Class::Handle(Z,
6864 Library::LookupCoreClass(Symbols::_AsyncStarStreamController())); 6893 Library::LookupCoreClass(Symbols::_AsyncStarStreamController()));
6865 ASSERT(!controller_class.IsNull()); 6894 ASSERT(!controller_class.IsNull());
6866 const Function& controller_constructor = Function::ZoneHandle(Z, 6895 const Function& controller_constructor = Function::ZoneHandle(Z,
6867 controller_class.LookupConstructorAllowPrivate( 6896 controller_class.LookupConstructorAllowPrivate(
6868 Symbols::_AsyncStarStreamControllerConstructor())); 6897 Symbols::_AsyncStarStreamControllerConstructor()));
6869 6898
6870 // :await_jump_var = -1; 6899 // :await_jump_var = -1;
6871 LocalVariable* jump_var = 6900 LocalVariable* jump_var =
6872 current_block_->scope->LookupVariable(Symbols::AwaitJumpVar(), false); 6901 current_block_->scope->LookupVariable(Symbols::AwaitJumpVar(), false);
6873 LiteralNode* init_value = 6902 LiteralNode* init_value =
6874 new(Z) LiteralNode(Scanner::kNoSourcePos, Smi::ZoneHandle(Smi::New(-1))); 6903 new(Z) LiteralNode(Scanner::kNoSourcePos, Smi::ZoneHandle(Smi::New(-1)));
6875 current_block_->statements->Add( 6904 current_block_->statements->Add(
6876 new(Z) StoreLocalNode(Scanner::kNoSourcePos, jump_var, init_value)); 6905 new(Z) StoreLocalNode(Scanner::kNoSourcePos, jump_var, init_value));
6877 6906
6878 // Add to AST: 6907 // Add to AST:
6879 // :async_op = <closure>; (containing the original body) 6908 // :async_op = <closure>; (containing the original body)
6880 LocalVariable* async_op_var = 6909 LocalVariable* async_op_var =
6881 current_block_->scope->LookupVariable(Symbols::AsyncOperation(), false); 6910 current_block_->scope->LookupVariable(Symbols::AsyncOperation(), false);
6882 ClosureNode* closure_obj = new(Z) ClosureNode( 6911 ClosureNode* closure_obj = new(Z) ClosureNode(
6883 Scanner::kNoSourcePos, closure_func, NULL, closure_body->scope()); 6912 Scanner::kNoSourcePos, closure_func, NULL, closure_body->scope());
6884 StoreLocalNode* store_async_op = new (Z) StoreLocalNode( 6913 StoreLocalNode* store_async_op = new (Z) StoreLocalNode(
6885 Scanner::kNoSourcePos, 6914 Scanner::kNoSourcePos,
6886 async_op_var, 6915 async_op_var,
6887 closure_obj); 6916 closure_obj);
6917
6888 current_block_->statements->Add(store_async_op); 6918 current_block_->statements->Add(store_async_op);
6889 6919
6920 const Library& async_lib = Library::Handle(Library::AsyncLibrary());
6921 // :async_then_callback = _asyncThenWrapperHelper(:async_op)
6922 const Function& async_then_wrapper_helper = Function::ZoneHandle(
6923 Z, async_lib.LookupFunctionAllowPrivate(
6924 Symbols::AsyncThenWrapperHelper()));
6925 ASSERT(!async_then_wrapper_helper.IsNull());
6926 ArgumentListNode* async_then_wrapper_helper_args = new (Z) ArgumentListNode(
6927 Scanner::kNoSourcePos);
6928 async_then_wrapper_helper_args->Add(
6929 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
6930 StaticCallNode* then_wrapper_call = new (Z) StaticCallNode(
6931 Scanner::kNoSourcePos,
6932 async_then_wrapper_helper,
6933 async_then_wrapper_helper_args);
6934 LocalVariable* async_then_callback_var =
6935 current_block_->scope->LookupVariable(
6936 Symbols::AsyncThenCallback(), false);
6937 StoreLocalNode* store_async_then_callback = new (Z) StoreLocalNode(
6938 Scanner::kNoSourcePos,
6939 async_then_callback_var,
6940 then_wrapper_call);
6941
6942 current_block_->statements->Add(store_async_then_callback);
6943
6944 // :async_catch_error_callback = _asyncErrorWrapperHelper(:async_op)
6945
6946 const Function& async_error_wrapper_helper = Function::ZoneHandle(
6947 Z, async_lib.LookupFunctionAllowPrivate(
6948 Symbols::AsyncErrorWrapperHelper()));
6949 ASSERT(!async_error_wrapper_helper.IsNull());
6950 ArgumentListNode* async_error_wrapper_helper_args = new (Z) ArgumentListNode(
6951 Scanner::kNoSourcePos);
6952 async_error_wrapper_helper_args->Add(
6953 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
6954 StaticCallNode* error_wrapper_call = new (Z) StaticCallNode(
6955 Scanner::kNoSourcePos,
6956 async_error_wrapper_helper,
6957 async_error_wrapper_helper_args);
6958 LocalVariable* async_catch_error_callback_var =
6959 current_block_->scope->LookupVariable(
6960 Symbols::AsyncCatchErrorCallback(), false);
6961 StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode(
6962 Scanner::kNoSourcePos,
6963 async_catch_error_callback_var,
6964 error_wrapper_call);
6965
6966 current_block_->statements->Add(store_async_catch_error_callback);
6967
6890 // :controller = new _AsyncStarStreamController(body_closure); 6968 // :controller = new _AsyncStarStreamController(body_closure);
6891 ArgumentListNode* arguments = new(Z) ArgumentListNode(Scanner::kNoSourcePos); 6969 ArgumentListNode* arguments = new(Z) ArgumentListNode(Scanner::kNoSourcePos);
6892 arguments->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var)); 6970 arguments->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
6893 ConstructorCallNode* controller_constructor_call = 6971 ConstructorCallNode* controller_constructor_call =
6894 new(Z) ConstructorCallNode(Scanner::kNoSourcePos, 6972 new(Z) ConstructorCallNode(Scanner::kNoSourcePos,
6895 TypeArguments::ZoneHandle(Z), 6973 TypeArguments::ZoneHandle(Z),
6896 controller_constructor, 6974 controller_constructor,
6897 arguments); 6975 arguments);
6898 LocalVariable* controller_var = 6976 LocalVariable* controller_var =
6899 current_block_->scope->LookupVariable(Symbols::Controller(), false); 6977 current_block_->scope->LookupVariable(Symbols::Controller(), false);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
7036 LocalVariable* async_op_var = current_block_->scope->LookupVariable( 7114 LocalVariable* async_op_var = current_block_->scope->LookupVariable(
7037 Symbols::AsyncOperation(), false); 7115 Symbols::AsyncOperation(), false);
7038 ClosureNode* cn = new(Z) ClosureNode( 7116 ClosureNode* cn = new(Z) ClosureNode(
7039 Scanner::kNoSourcePos, closure, NULL, closure_body->scope()); 7117 Scanner::kNoSourcePos, closure, NULL, closure_body->scope());
7040 StoreLocalNode* store_async_op = new (Z) StoreLocalNode( 7118 StoreLocalNode* store_async_op = new (Z) StoreLocalNode(
7041 Scanner::kNoSourcePos, 7119 Scanner::kNoSourcePos,
7042 async_op_var, 7120 async_op_var,
7043 cn); 7121 cn);
7044 current_block_->statements->Add(store_async_op); 7122 current_block_->statements->Add(store_async_op);
7045 7123
7124 const Library& async_lib = Library::Handle(Library::AsyncLibrary());
7125 // :async_then_callback = _asyncThenWrapperHelper(:async_op)
7126 const Function& async_then_wrapper_helper = Function::ZoneHandle(
7127 Z, async_lib.LookupFunctionAllowPrivate(
7128 Symbols::AsyncThenWrapperHelper()));
7129 ASSERT(!async_then_wrapper_helper.IsNull());
7130 ArgumentListNode* async_then_wrapper_helper_args = new (Z) ArgumentListNode(
7131 Scanner::kNoSourcePos);
7132 async_then_wrapper_helper_args->Add(
7133 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
7134 StaticCallNode* then_wrapper_call = new (Z) StaticCallNode(
7135 Scanner::kNoSourcePos,
7136 async_then_wrapper_helper,
7137 async_then_wrapper_helper_args);
7138 LocalVariable* async_then_callback_var =
7139 current_block_->scope->LookupVariable(
7140 Symbols::AsyncThenCallback(), false);
7141 StoreLocalNode* store_async_then_callback = new (Z) StoreLocalNode(
7142 Scanner::kNoSourcePos,
7143 async_then_callback_var,
7144 then_wrapper_call);
7145
7146 current_block_->statements->Add(store_async_then_callback);
7147
7148 // :async_catch_error_callback = _asyncErrorWrapperHelper(:async_op)
7149
7150 const Function& async_error_wrapper_helper = Function::ZoneHandle(
7151 Z, async_lib.LookupFunctionAllowPrivate(
7152 Symbols::AsyncErrorWrapperHelper()));
7153 ASSERT(!async_error_wrapper_helper.IsNull());
7154 ArgumentListNode* async_error_wrapper_helper_args = new (Z) ArgumentListNode(
7155 Scanner::kNoSourcePos);
7156 async_error_wrapper_helper_args->Add(
7157 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_op_var));
7158 StaticCallNode* error_wrapper_call = new (Z) StaticCallNode(
7159 Scanner::kNoSourcePos,
7160 async_error_wrapper_helper,
7161 async_error_wrapper_helper_args);
7162 LocalVariable* async_catch_error_callback_var =
7163 current_block_->scope->LookupVariable(
7164 Symbols::AsyncCatchErrorCallback(), false);
7165 StoreLocalNode* store_async_catch_error_callback = new (Z) StoreLocalNode(
7166 Scanner::kNoSourcePos,
7167 async_catch_error_callback_var,
7168 error_wrapper_call);
7169
7170 current_block_->statements->Add(store_async_catch_error_callback);
7171
7046 // Add to AST: 7172 // Add to AST:
7047 // new Future.microtask(:async_op); 7173 // new Future.microtask(:async_op);
7048 ArgumentListNode* arguments = new (Z) ArgumentListNode(Scanner::kNoSourcePos); 7174 ArgumentListNode* arguments = new (Z) ArgumentListNode(Scanner::kNoSourcePos);
7049 arguments->Add(new (Z) LoadLocalNode( 7175 arguments->Add(new (Z) LoadLocalNode(
7050 Scanner::kNoSourcePos, async_op_var)); 7176 Scanner::kNoSourcePos, async_op_var));
7051 ConstructorCallNode* future_node = new (Z) ConstructorCallNode( 7177 ConstructorCallNode* future_node = new (Z) ConstructorCallNode(
7052 Scanner::kNoSourcePos, TypeArguments::ZoneHandle(Z), constructor, 7178 Scanner::kNoSourcePos, TypeArguments::ZoneHandle(Z), constructor,
7053 arguments); 7179 arguments);
7054 current_block_->statements->Add(future_node); 7180 current_block_->statements->Add(future_node);
7055 7181
(...skipping 6990 matching lines...) Expand 10 before | Expand all | Expand 10 after
14046 void Parser::SkipQualIdent() { 14172 void Parser::SkipQualIdent() {
14047 ASSERT(IsIdentifier()); 14173 ASSERT(IsIdentifier());
14048 ConsumeToken(); 14174 ConsumeToken();
14049 if (CurrentToken() == Token::kPERIOD) { 14175 if (CurrentToken() == Token::kPERIOD) {
14050 ConsumeToken(); // Consume the kPERIOD token. 14176 ConsumeToken(); // Consume the kPERIOD token.
14051 ExpectIdentifier("identifier expected after '.'"); 14177 ExpectIdentifier("identifier expected after '.'");
14052 } 14178 }
14053 } 14179 }
14054 14180
14055 } // namespace dart 14181 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698