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

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

Issue 2377593002: Reland of Preparse functions in the scope that was created when parsing of the function was started (Closed)
Patch Set: 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/ast/scopes.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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 fni_->PushEnclosingName(raw_name); 922 fni_->PushEnclosingName(raw_name);
923 923
924 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 924 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
925 925
926 // Place holder for the result. 926 // Place holder for the result.
927 FunctionLiteral* result = nullptr; 927 FunctionLiteral* result = nullptr;
928 928
929 { 929 {
930 // Parse the function literal. 930 // Parse the function literal.
931 Scope* outer = original_scope_; 931 Scope* outer = original_scope_;
932 DeclarationScope* outer_function = outer->GetClosureScope();
932 DCHECK(outer); 933 DCHECK(outer);
933 FunctionState function_state(&function_state_, &scope_state_, outer, 934 FunctionState function_state(&function_state_, &scope_state_,
934 info->function_kind()); 935 outer_function,
936 outer_function->function_kind());
937 BlockState block_state(&scope_state_, outer);
935 DCHECK(is_sloppy(outer->language_mode()) || 938 DCHECK(is_sloppy(outer->language_mode()) ||
936 is_strict(info->language_mode())); 939 is_strict(info->language_mode()));
937 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); 940 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
938 bool ok = true; 941 bool ok = true;
939 942
940 if (info->is_arrow()) { 943 if (info->is_arrow()) {
941 bool is_async = allow_harmony_async_await() && info->is_async(); 944 bool is_async = allow_harmony_async_await() && info->is_async();
942 if (is_async) { 945 if (is_async) {
943 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); 946 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
944 if (!Check(Token::ASYNC)) { 947 if (!Check(Token::ASYNC)) {
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 FunctionKind::kAsyncFunction, pos, type, 2936 FunctionKind::kAsyncFunction, pos, type,
2934 language_mode(), CHECK_OK); 2937 language_mode(), CHECK_OK);
2935 } 2938 }
2936 2939
2937 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( 2940 Parser::LazyParsingResult Parser::SkipLazyFunctionBody(
2938 int* materialized_literal_count, int* expected_property_count, 2941 int* materialized_literal_count, int* expected_property_count,
2939 bool is_inner_function, bool may_abort, bool* ok) { 2942 bool is_inner_function, bool may_abort, bool* ok) {
2940 if (produce_cached_parse_data()) CHECK(log_); 2943 if (produce_cached_parse_data()) CHECK(log_);
2941 2944
2942 int function_block_pos = position(); 2945 int function_block_pos = position();
2943 DeclarationScope* scope = this->scope()->AsDeclarationScope(); 2946 DeclarationScope* scope = function_state_->scope();
2944 DCHECK(scope->is_function_scope()); 2947 DCHECK(scope->is_function_scope());
2945 scope->set_is_lazily_parsed(true); 2948 scope->set_is_lazily_parsed(true);
2946 // Inner functions are not part of the cached data. 2949 // Inner functions are not part of the cached data.
2947 if (!is_inner_function && consume_cached_parse_data() && 2950 if (!is_inner_function && consume_cached_parse_data() &&
2948 !cached_parse_data_->rejected()) { 2951 !cached_parse_data_->rejected()) {
2949 // If we have cached data, we use it to skip parsing the function body. The 2952 // If we have cached data, we use it to skip parsing the function body. The
2950 // data contains the information we need to construct the lazy function. 2953 // data contains the information we need to construct the lazy function.
2951 FunctionEntry entry = 2954 FunctionEntry entry =
2952 cached_parse_data_->GetFunctionEntry(function_block_pos); 2955 cached_parse_data_->GetFunctionEntry(function_block_pos);
2953 // Check that cached data is valid. If not, mark it as invalid (the embedder 2956 // Check that cached data is valid. If not, mark it as invalid (the embedder
(...skipping 12 matching lines...) Expand all
2966 if (entry.calls_eval()) scope->RecordEvalCall(); 2969 if (entry.calls_eval()) scope->RecordEvalCall();
2967 return kLazyParsingComplete; 2970 return kLazyParsingComplete;
2968 } 2971 }
2969 cached_parse_data_->Reject(); 2972 cached_parse_data_->Reject();
2970 } 2973 }
2971 // With no cached data, we partially parse the function, without building an 2974 // With no cached data, we partially parse the function, without building an
2972 // AST. This gathers the data needed to build a lazy function. 2975 // AST. This gathers the data needed to build a lazy function.
2973 SingletonLogger logger; 2976 SingletonLogger logger;
2974 PreParser::PreParseResult result = 2977 PreParser::PreParseResult result =
2975 ParseLazyFunctionBodyWithPreParser(&logger, is_inner_function, may_abort); 2978 ParseLazyFunctionBodyWithPreParser(&logger, is_inner_function, may_abort);
2979
2976 // Return immediately if pre-parser decided to abort parsing. 2980 // Return immediately if pre-parser decided to abort parsing.
2977 if (result == PreParser::kPreParseAbort) { 2981 if (result == PreParser::kPreParseAbort) {
2978 scope->set_is_lazily_parsed(false); 2982 scope->set_is_lazily_parsed(false);
2979 return kLazyParsingAborted; 2983 return kLazyParsingAborted;
2980 } 2984 }
2981 if (result == PreParser::kPreParseStackOverflow) { 2985 if (result == PreParser::kPreParseStackOverflow) {
2982 // Propagate stack overflow. 2986 // Propagate stack overflow.
2983 set_stack_overflow(); 2987 set_stack_overflow();
2984 *ok = false; 2988 *ok = false;
2985 return kLazyParsingComplete; 2989 return kLazyParsingComplete;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 SET_ALLOW(harmony_restrictive_declarations); 3471 SET_ALLOW(harmony_restrictive_declarations);
3468 SET_ALLOW(harmony_async_await); 3472 SET_ALLOW(harmony_async_await);
3469 SET_ALLOW(harmony_trailing_commas); 3473 SET_ALLOW(harmony_trailing_commas);
3470 SET_ALLOW(harmony_class_fields); 3474 SET_ALLOW(harmony_class_fields);
3471 #undef SET_ALLOW 3475 #undef SET_ALLOW
3472 } 3476 }
3473 // Aborting inner function preparsing would leave scopes in an inconsistent 3477 // Aborting inner function preparsing would leave scopes in an inconsistent
3474 // state; we don't parse inner functions in the abortable mode anyway. 3478 // state; we don't parse inner functions in the abortable mode anyway.
3475 DCHECK(!is_inner_function || !may_abort); 3479 DCHECK(!is_inner_function || !may_abort);
3476 3480
3477 FunctionKind kind = function_state_->kind(); 3481 DeclarationScope* function_scope = function_state_->scope();
3478 PreParser::PreParseResult result; 3482 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
3479 if (!is_inner_function) { 3483 function_scope, parsing_module_, logger, is_inner_function, may_abort,
3480 // If we don't need to look at the scope, construct a dummy scope chain 3484 use_counts_);
3481 // which is not connected to the real scope chain. 3485 // Detaching the scopes created by PreParser from the Scope chain must be done
3482 LanguageMode mode = language_mode(); 3486 // above (see ParseFunctionLiteral & AnalyzePartially).
3483 bool has_simple_parameters = 3487 if (!is_inner_function) function_scope->ResetAfterPreparsing();
3484 scope()->AsDeclarationScope()->has_simple_parameters();
3485 DeclarationScope* top_scope = NewScriptScope();
3486 top_scope->SetLanguageMode(mode);
3487 FunctionState top_state(&function_state_, &scope_state_, top_scope,
3488 kNormalFunction);
3489 DeclarationScope* function_scope = NewFunctionScope(kind);
3490 if (!has_simple_parameters) {
3491 function_scope->SetHasNonSimpleParameters();
3492 }
3493 result = reusable_preparser_->PreParseLazyFunction(
3494 kind, function_scope, parsing_module_, logger, is_inner_function,
3495 may_abort, use_counts_);
3496 } else {
3497 // Detaching the scopes created by PreParser from the Scope chain must be
3498 // done above (see ParseFunctionLiteral & AnalyzePartially).
3499 result = reusable_preparser_->PreParseLazyFunction(
3500 kind, scope()->AsDeclarationScope(), parsing_module_, logger,
3501 is_inner_function, may_abort, use_counts_);
3502 }
3503 if (pre_parse_timer_ != NULL) { 3488 if (pre_parse_timer_ != NULL) {
3504 pre_parse_timer_->Stop(); 3489 pre_parse_timer_->Stop();
3505 } 3490 }
3506 return result; 3491 return result;
3507 } 3492 }
3508 3493
3509 Expression* Parser::InstallHomeObject(Expression* function_literal, 3494 Expression* Parser::InstallHomeObject(Expression* function_literal,
3510 Expression* home_object) { 3495 Expression* home_object) {
3511 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); 3496 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
3512 Variable* result_var = 3497 Variable* result_var =
(...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5616 5601
5617 return final_loop; 5602 return final_loop;
5618 } 5603 }
5619 5604
5620 #undef CHECK_OK 5605 #undef CHECK_OK
5621 #undef CHECK_OK_VOID 5606 #undef CHECK_OK_VOID
5622 #undef CHECK_FAILED 5607 #undef CHECK_FAILED
5623 5608
5624 } // namespace internal 5609 } // namespace internal
5625 } // namespace v8 5610 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698