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

Side by Side Diff: src/parsing/parser.cc

Issue 2506613002: Move allow_lazy from ParserBase to Parser and remove accessors (Closed)
Patch Set: fix Created 4 years, 1 month 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.h ('k') | src/parsing/parser-base.h » ('j') | 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 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // of functions without an outer context when setting a breakpoint through 608 // of functions without an outer context when setting a breakpoint through
609 // Debug::FindSharedFunctionInfoInScript 609 // Debug::FindSharedFunctionInfoInScript
610 bool can_compile_lazily = FLAG_lazy && !info->is_debug(); 610 bool can_compile_lazily = FLAG_lazy && !info->is_debug();
611 611
612 // Consider compiling eagerly when targeting the code cache. 612 // Consider compiling eagerly when targeting the code cache.
613 can_compile_lazily &= !(FLAG_serialize_eager && info->will_serialize()); 613 can_compile_lazily &= !(FLAG_serialize_eager && info->will_serialize());
614 614
615 set_default_eager_compile_hint(can_compile_lazily 615 set_default_eager_compile_hint(can_compile_lazily
616 ? FunctionLiteral::kShouldLazyCompile 616 ? FunctionLiteral::kShouldLazyCompile
617 : FunctionLiteral::kShouldEagerCompile); 617 : FunctionLiteral::kShouldEagerCompile);
618 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && 618 allow_lazy_ = FLAG_lazy && info->allow_lazy_parsing() && !info->is_native() &&
619 !info->is_native() && info->extension() == nullptr && 619 info->extension() == nullptr && can_compile_lazily;
620 can_compile_lazily);
621 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 620 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
622 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && 621 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
623 info->isolate()->is_tail_call_elimination_enabled()); 622 info->isolate()->is_tail_call_elimination_enabled());
624 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 623 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
625 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 624 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
626 set_allow_harmony_async_await(FLAG_harmony_async_await); 625 set_allow_harmony_async_await(FLAG_harmony_async_await);
627 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); 626 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators);
628 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); 627 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas);
629 set_allow_harmony_class_fields(FLAG_harmony_class_fields); 628 set_allow_harmony_class_fields(FLAG_harmony_class_fields);
630 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 629 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 } 722 }
724 723
725 724
726 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { 725 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
727 // Note that this function can be called from the main thread or from a 726 // Note that this function can be called from the main thread or from a
728 // background thread. We should not access anything Isolate / heap dependent 727 // background thread. We should not access anything Isolate / heap dependent
729 // via ParseInfo, and also not pass it forward. 728 // via ParseInfo, and also not pass it forward.
730 DCHECK_NULL(scope_state_); 729 DCHECK_NULL(scope_state_);
731 DCHECK_NULL(target_stack_); 730 DCHECK_NULL(target_stack_);
732 731
733 ParsingModeScope mode(this, allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY); 732 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
734 733
735 FunctionLiteral* result = NULL; 734 FunctionLiteral* result = NULL;
736 { 735 {
737 Scope* outer = original_scope_; 736 Scope* outer = original_scope_;
738 DCHECK_NOT_NULL(outer); 737 DCHECK_NOT_NULL(outer);
739 parsing_module_ = info->is_module(); 738 parsing_module_ = info->is_module();
740 if (info->is_eval()) { 739 if (info->is_eval()) {
741 outer = NewEvalScope(outer); 740 outer = NewEvalScope(outer);
742 } else if (parsing_module_) { 741 } else if (parsing_module_) {
743 DCHECK_EQ(outer, info->script_scope()); 742 DCHECK_EQ(outer, info->script_scope());
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 // (function foo() { 2561 // (function foo() {
2563 // var a = 1; 2562 // var a = 1;
2564 // bar = function() { return a; } 2563 // bar = function() { return a; }
2565 // })(); 2564 // })();
2566 2565
2567 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume 2566 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume
2568 // parenthesis before the function means that it will be called 2567 // parenthesis before the function means that it will be called
2569 // immediately). bar can be parsed lazily, but we need to parse it in a mode 2568 // immediately). bar can be parsed lazily, but we need to parse it in a mode
2570 // that tracks unresolved variables. 2569 // that tracks unresolved variables.
2571 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy); 2570 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy);
2572 DCHECK_IMPLIES(parse_lazily(), allow_lazy()); 2571 DCHECK_IMPLIES(parse_lazily(), allow_lazy_);
2573 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr); 2572 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr);
2574 2573
2575 bool can_preparse = parse_lazily() && 2574 bool can_preparse = parse_lazily() &&
2576 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; 2575 eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
2577 2576
2578 bool is_lazy_top_level_function = 2577 bool is_lazy_top_level_function =
2579 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); 2578 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
2580 2579
2581 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, 2580 RuntimeCallTimerScope runtime_timer(runtime_call_stats_,
2582 &RuntimeCallStats::ParseFunctionLiteral); 2581 &RuntimeCallStats::ParseFunctionLiteral);
(...skipping 14 matching lines...) Expand all
2597 // - For asm.js functions the body needs to be available when module 2596 // - For asm.js functions the body needs to be available when module
2598 // validation is active, because we examine the entire module at once. 2597 // validation is active, because we examine the entire module at once.
2599 2598
2600 // Inner functions will be parsed using a temporary Zone. After parsing, we 2599 // Inner functions will be parsed using a temporary Zone. After parsing, we
2601 // will migrate unresolved variable into a Scope in the main Zone. 2600 // will migrate unresolved variable into a Scope in the main Zone.
2602 // TODO(marja): Refactor parsing modes: simplify this. 2601 // TODO(marja): Refactor parsing modes: simplify this.
2603 bool use_temp_zone = 2602 bool use_temp_zone =
2604 (FLAG_lazy_inner_functions 2603 (FLAG_lazy_inner_functions
2605 ? can_preparse 2604 ? can_preparse
2606 : (is_lazy_top_level_function || 2605 : (is_lazy_top_level_function ||
2607 (allow_lazy() && function_type == FunctionLiteral::kDeclaration && 2606 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration &&
2608 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) && 2607 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) &&
2609 !(FLAG_validate_asm && scope()->IsAsmModule()); 2608 !(FLAG_validate_asm && scope()->IsAsmModule());
2610 bool is_lazy_inner_function = 2609 bool is_lazy_inner_function =
2611 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; 2610 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function;
2612 2611
2613 // This Scope lives in the main zone. We'll migrate data into that zone later. 2612 // This Scope lives in the main zone. We'll migrate data into that zone later.
2614 DeclarationScope* scope = NewFunctionScope(kind); 2613 DeclarationScope* scope = NewFunctionScope(kind);
2615 SetLanguageMode(scope, language_mode); 2614 SetLanguageMode(scope, language_mode);
2616 #ifdef DEBUG 2615 #ifdef DEBUG
2617 scope->SetScopeName(function_name); 2616 scope->SetScopeName(function_name);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 } 2783 }
2785 2784
2786 // With no cached data, we partially parse the function, without building an 2785 // With no cached data, we partially parse the function, without building an
2787 // AST. This gathers the data needed to build a lazy function. 2786 // AST. This gathers the data needed to build a lazy function.
2788 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); 2787 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse");
2789 2788
2790 if (reusable_preparser_ == NULL) { 2789 if (reusable_preparser_ == NULL) {
2791 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 2790 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
2792 &pending_error_handler_, 2791 &pending_error_handler_,
2793 runtime_call_stats_, stack_limit_); 2792 runtime_call_stats_, stack_limit_);
2794 reusable_preparser_->set_allow_lazy(true);
2795 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 2793 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
2796 SET_ALLOW(natives); 2794 SET_ALLOW(natives);
2797 SET_ALLOW(harmony_do_expressions); 2795 SET_ALLOW(harmony_do_expressions);
2798 SET_ALLOW(harmony_function_sent); 2796 SET_ALLOW(harmony_function_sent);
2799 SET_ALLOW(harmony_async_await); 2797 SET_ALLOW(harmony_async_await);
2800 SET_ALLOW(harmony_trailing_commas); 2798 SET_ALLOW(harmony_trailing_commas);
2801 SET_ALLOW(harmony_class_fields); 2799 SET_ALLOW(harmony_class_fields);
2802 #undef SET_ALLOW 2800 #undef SET_ALLOW
2803 } 2801 }
2804 // Aborting inner function preparsing would leave scopes in an inconsistent 2802 // Aborting inner function preparsing would leave scopes in an inconsistent
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 3151
3154 *materialized_literal_count = function_state.materialized_literal_count(); 3152 *materialized_literal_count = function_state.materialized_literal_count();
3155 *expected_property_count = function_state.expected_property_count(); 3153 *expected_property_count = function_state.expected_property_count();
3156 return body; 3154 return body;
3157 } 3155 }
3158 3156
3159 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 3157 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
3160 const AstRawString* function_name, int pos, 3158 const AstRawString* function_name, int pos,
3161 const ParserFormalParameters& parameters, FunctionKind kind, 3159 const ParserFormalParameters& parameters, FunctionKind kind,
3162 FunctionLiteral::FunctionType function_type, bool* ok) { 3160 FunctionLiteral::FunctionType function_type, bool* ok) {
3163 ParsingModeScope mode(this, allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY); 3161 ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
3164 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); 3162 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone());
3165 3163
3166 static const int kFunctionNameAssignmentIndex = 0; 3164 static const int kFunctionNameAssignmentIndex = 0;
3167 if (function_type == FunctionLiteral::kNamedExpression) { 3165 if (function_type == FunctionLiteral::kNamedExpression) {
3168 DCHECK(function_name != NULL); 3166 DCHECK(function_name != NULL);
3169 // If we have a named function expression, we add a local variable 3167 // If we have a named function expression, we add a local variable
3170 // declaration to the body of the function with the name of the 3168 // declaration to the body of the function with the name of the
3171 // function and let it refer to the function itself (closure). 3169 // function and let it refer to the function itself (closure).
3172 // Not having parsed the function body, the language mode may still change, 3170 // Not having parsed the function body, the language mode may still change,
3173 // so we reserve a spot and create the actual const assignment later. 3171 // so we reserve a spot and create the actual const assignment later.
(...skipping 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after
5437 5435
5438 return final_loop; 5436 return final_loop;
5439 } 5437 }
5440 5438
5441 #undef CHECK_OK 5439 #undef CHECK_OK
5442 #undef CHECK_OK_VOID 5440 #undef CHECK_OK_VOID
5443 #undef CHECK_FAILED 5441 #undef CHECK_FAILED
5444 5442
5445 } // namespace internal 5443 } // namespace internal
5446 } // namespace v8 5444 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698