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

Side by Side Diff: src/parsing/parser-base.h

Issue 2405813002: Allow lazy parsing of functions nested in eager compiled functions (Closed)
Patch Set: Rebase Created 4 years, 2 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
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 3904 matching lines...) Expand 10 before | Expand all | Expand 10 after
3915 } 3915 }
3916 3916
3917 StatementListT body = impl()->NullStatementList(); 3917 StatementListT body = impl()->NullStatementList();
3918 int num_parameters = formal_parameters.scope->num_parameters(); 3918 int num_parameters = formal_parameters.scope->num_parameters();
3919 int materialized_literal_count = -1; 3919 int materialized_literal_count = -1;
3920 int expected_property_count = -1; 3920 int expected_property_count = -1;
3921 3921
3922 FunctionKind kind = formal_parameters.scope->function_kind(); 3922 FunctionKind kind = formal_parameters.scope->function_kind();
3923 FunctionLiteral::EagerCompileHint eager_compile_hint = 3923 FunctionLiteral::EagerCompileHint eager_compile_hint =
3924 default_eager_compile_hint_; 3924 default_eager_compile_hint_;
3925 bool can_preparse = mode() == PARSE_LAZILY &&
3926 eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
3927 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
3928 // handling in Scope::ResolveVariable needs to change.
3929 bool is_lazy_top_level_function =
3930 can_preparse && scope()->AllowsLazyParsingWithoutUnresolvedVariables();
3925 bool should_be_used_once_hint = false; 3931 bool should_be_used_once_hint = false;
3926 { 3932 {
3927 FunctionState function_state(&function_state_, &scope_state_, 3933 FunctionState function_state(&function_state_, &scope_state_,
3928 formal_parameters.scope); 3934 formal_parameters.scope);
3929 3935
3930 function_state.SkipMaterializedLiterals( 3936 function_state.SkipMaterializedLiterals(
3931 formal_parameters.materialized_literals_count); 3937 formal_parameters.materialized_literals_count);
3932 3938
3933 impl()->ReindexLiterals(formal_parameters); 3939 impl()->ReindexLiterals(formal_parameters);
3934 3940
3935 Expect(Token::ARROW, CHECK_OK); 3941 Expect(Token::ARROW, CHECK_OK);
3936 3942
3937 if (peek() == Token::LBRACE) { 3943 if (peek() == Token::LBRACE) {
3938 // Multiple statement body 3944 // Multiple statement body
3939 Consume(Token::LBRACE); 3945 Consume(Token::LBRACE);
3940 DCHECK_EQ(scope(), formal_parameters.scope); 3946 DCHECK_EQ(scope(), formal_parameters.scope);
3941 bool is_lazily_parsed = 3947 if (is_lazy_top_level_function) {
3942 (mode() == PARSE_LAZILY &&
3943 formal_parameters.scope
3944 ->AllowsLazyParsingWithoutUnresolvedVariables() &&
3945 eager_compile_hint == FunctionLiteral::kShouldLazyCompile);
3946 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this
3947 // handling in Scope::ResolveVariable needs to change.
3948 if (is_lazily_parsed) {
3949 Scanner::BookmarkScope bookmark(scanner()); 3948 Scanner::BookmarkScope bookmark(scanner());
3950 bookmark.Set(); 3949 bookmark.Set();
3951 LazyParsingResult result = impl()->SkipLazyFunctionBody( 3950 LazyParsingResult result = impl()->SkipLazyFunctionBody(
3952 &materialized_literal_count, &expected_property_count, false, true, 3951 &materialized_literal_count, &expected_property_count, false, true,
3953 CHECK_OK); 3952 CHECK_OK);
3954 formal_parameters.scope->ResetAfterPreparsing( 3953 formal_parameters.scope->ResetAfterPreparsing(
3955 ast_value_factory_, result == kLazyParsingAborted); 3954 ast_value_factory_, result == kLazyParsingAborted);
3956 3955
3957 if (formal_parameters.materialized_literals_count > 0) { 3956 if (formal_parameters.materialized_literals_count > 0) {
3958 materialized_literal_count += 3957 materialized_literal_count +=
3959 formal_parameters.materialized_literals_count; 3958 formal_parameters.materialized_literals_count;
3960 } 3959 }
3961 3960
3962 if (result == kLazyParsingAborted) { 3961 if (result == kLazyParsingAborted) {
3963 bookmark.Apply(); 3962 bookmark.Apply();
3964 // Trigger eager (re-)parsing, just below this block. 3963 // Trigger eager (re-)parsing, just below this block.
3965 is_lazily_parsed = false; 3964 is_lazy_top_level_function = false;
3966 3965
3967 // This is probably an initialization function. Inform the compiler it 3966 // This is probably an initialization function. Inform the compiler it
3968 // should also eager-compile this function, and that we expect it to 3967 // should also eager-compile this function, and that we expect it to
3969 // be used once. 3968 // be used once.
3970 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; 3969 eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
3971 should_be_used_once_hint = true; 3970 should_be_used_once_hint = true;
3972 } 3971 }
3973 } 3972 }
3974 if (!is_lazily_parsed) { 3973 if (!is_lazy_top_level_function) {
3975 body = impl()->ParseEagerFunctionBody( 3974 body = impl()->ParseEagerFunctionBody(
3976 impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters, 3975 impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
3977 kind, FunctionLiteral::kAnonymousExpression, CHECK_OK); 3976 kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
3978 materialized_literal_count = 3977 materialized_literal_count =
3979 function_state.materialized_literal_count(); 3978 function_state.materialized_literal_count();
3980 expected_property_count = function_state.expected_property_count(); 3979 expected_property_count = function_state.expected_property_count();
3981 } 3980 }
3982 } else { 3981 } else {
3983 // Single-expression body 3982 // Single-expression body
3984 int pos = position(); 3983 int pos = position();
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
5456 has_seen_constructor_ = true; 5455 has_seen_constructor_ = true;
5457 return; 5456 return;
5458 } 5457 }
5459 } 5458 }
5460 5459
5461 5460
5462 } // namespace internal 5461 } // namespace internal
5463 } // namespace v8 5462 } // namespace v8
5464 5463
5465 #endif // V8_PARSING_PARSER_BASE_H 5464 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698