Commit af07cd9a authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Move preparse abort handling to SkipFunction

Change-Id: I6c4f8c736e3c5f55f9541109f0093b2c026bce27
Reviewed-on: https://chromium-review.googlesource.com/1240136
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56177}
parent 141dd667
...@@ -4401,13 +4401,14 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4401,13 +4401,14 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
// parameters. // parameters.
int dummy_num_parameters = -1; int dummy_num_parameters = -1;
DCHECK_NE(kind & FunctionKind::kArrowFunction, 0); DCHECK_NE(kind & FunctionKind::kArrowFunction, 0);
LazyParsingResult result = impl()->SkipFunction( FunctionLiteral::EagerCompileHint hint;
bool parse_result = impl()->SkipFunction(
nullptr, kind, FunctionLiteral::kAnonymousExpression, nullptr, kind, FunctionLiteral::kAnonymousExpression,
formal_parameters.scope, &dummy_num_parameters, formal_parameters.scope, &dummy_num_parameters,
&produced_preparsed_scope_data, false, false, CHECK_OK); &produced_preparsed_scope_data, false, false, &hint, CHECK_OK);
DCHECK_NE(result, kLazyParsingAborted); DCHECK(parse_result);
USE(parse_result);
DCHECK_NULL(produced_preparsed_scope_data); DCHECK_NULL(produced_preparsed_scope_data);
USE(result);
formal_parameters.scope->ResetAfterPreparsing(ast_value_factory_, formal_parameters.scope->ResetAfterPreparsing(ast_value_factory_,
false); false);
// Discard any queued destructuring assignments which appeared // Discard any queued destructuring assignments which appeared
......
...@@ -2568,30 +2568,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2568,30 +2568,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// abort lazy parsing if it suspects that wasn't a good idea. If so (in // abort lazy parsing if it suspects that wasn't a good idea. If so (in
// which case the parser is expected to have backtracked), or if we didn't // which case the parser is expected to have backtracked), or if we didn't
// try to lazy parse in the first place, we'll have to parse eagerly. // try to lazy parse in the first place, we'll have to parse eagerly.
if (should_preparse) { bool did_preparse =
DCHECK(parse_lazily()); should_preparse &&
DCHECK(is_lazy_top_level_function || is_lazy_inner_function); SkipFunction(function_name, kind, function_type, scope, &num_parameters,
DCHECK(!is_wrapped); &produced_preparsed_scope_data, is_lazy_inner_function,
Scanner::BookmarkScope bookmark(scanner()); is_lazy_top_level_function, &eager_compile_hint, CHECK_OK);
bookmark.Set(); if (!did_preparse) {
LazyParsingResult result =
SkipFunction(function_name, kind, function_type, scope, &num_parameters,
&produced_preparsed_scope_data, is_lazy_inner_function,
is_lazy_top_level_function, CHECK_OK);
if (result == kLazyParsingAborted) {
DCHECK(is_lazy_top_level_function);
bookmark.Apply();
// This is probably an initialization function. Inform the compiler it
// should also eager-compile this function.
eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
scope->ResetAfterPreparsing(ast_value_factory(), true);
// Trigger eager (re-)parsing, just below this block.
should_preparse = false;
}
}
if (!should_preparse) {
body = ParseFunction( body = ParseFunction(
function_name, pos, kind, function_type, scope, &num_parameters, function_name, pos, kind, function_type, scope, &num_parameters,
&function_length, &has_duplicate_parameters, &expected_property_count, &function_length, &has_duplicate_parameters, &expected_property_count,
...@@ -2610,19 +2592,17 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2610,19 +2592,17 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
reinterpret_cast<const char*>(function_name->raw_data()), reinterpret_cast<const char*>(function_name->raw_data()),
function_name->byte_length()); function_name->byte_length());
} }
if (V8_UNLIKELY(FLAG_runtime_stats)) { if (V8_UNLIKELY(FLAG_runtime_stats) && did_preparse) {
if (should_preparse) { const RuntimeCallCounterId counters[2][2] = {
const RuntimeCallCounterId counters[2][2] = { {RuntimeCallCounterId::kPreParseBackgroundNoVariableResolution,
{RuntimeCallCounterId::kPreParseBackgroundNoVariableResolution, RuntimeCallCounterId::kPreParseNoVariableResolution},
RuntimeCallCounterId::kPreParseNoVariableResolution}, {RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution,
{RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution, RuntimeCallCounterId::kPreParseWithVariableResolution}};
RuntimeCallCounterId::kPreParseWithVariableResolution}}; if (runtime_call_stats_) {
if (runtime_call_stats_) { bool tracked_variables =
bool tracked_variables = PreParser::ShouldTrackUnresolvedVariables( PreParser::ShouldTrackUnresolvedVariables(is_lazy_top_level_function);
is_lazy_top_level_function); runtime_call_stats_->CorrectCurrentCounterId(
runtime_call_stats_->CorrectCurrentCounterId( counters[tracked_variables][parsing_on_main_thread_]);
counters[tracked_variables][parsing_on_main_thread_]);
}
} }
} }
...@@ -2656,12 +2636,13 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2656,12 +2636,13 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
return function_literal; return function_literal;
} }
Parser::LazyParsingResult Parser::SkipFunction( bool Parser::SkipFunction(
const AstRawString* function_name, FunctionKind kind, const AstRawString* function_name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
DeclarationScope* function_scope, int* num_parameters, DeclarationScope* function_scope, int* num_parameters,
ProducedPreParsedScopeData** produced_preparsed_scope_data, ProducedPreParsedScopeData** produced_preparsed_scope_data,
bool is_inner_function, bool may_abort, bool* ok) { bool is_inner_function, bool may_abort,
FunctionLiteral::EagerCompileHint* hint, bool* ok) {
FunctionState function_state(&function_state_, &scope_, function_scope); FunctionState function_state(&function_state_, &scope_, function_scope);
DCHECK_NE(kNoSourcePosition, function_scope->start_position()); DCHECK_NE(kNoSourcePosition, function_scope->start_position());
...@@ -2694,12 +2675,15 @@ Parser::LazyParsingResult Parser::SkipFunction( ...@@ -2694,12 +2675,15 @@ Parser::LazyParsingResult Parser::SkipFunction(
} }
SkipFunctionLiterals(num_inner_functions); SkipFunctionLiterals(num_inner_functions);
function_scope->ResetAfterPreparsing(ast_value_factory_, false); function_scope->ResetAfterPreparsing(ast_value_factory_, false);
return kLazyParsingComplete; return true;
} }
PreParser* preparser = reusable_preparser(); PreParser* preparser = reusable_preparser();
PreParserZoneScope zone_scope(preparser); PreParserZoneScope zone_scope(preparser);
Scanner::BookmarkScope bookmark(scanner());
bookmark.Set();
// With no cached data, we partially parse the function, without building an // With no cached data, we partially parse the function, without building an
// AST. This gathers the data needed to build a lazy function. // AST. This gathers the data needed to build a lazy function.
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse");
...@@ -2713,7 +2697,12 @@ Parser::LazyParsingResult Parser::SkipFunction( ...@@ -2713,7 +2697,12 @@ Parser::LazyParsingResult Parser::SkipFunction(
may_abort, use_counts_, produced_preparsed_scope_data, this->script_id()); may_abort, use_counts_, produced_preparsed_scope_data, this->script_id());
// Return immediately if pre-parser decided to abort parsing. // Return immediately if pre-parser decided to abort parsing.
if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; if (result == PreParser::kPreParseAbort) {
bookmark.Apply();
function_scope->ResetAfterPreparsing(ast_value_factory(), true);
*hint = FunctionLiteral::kShouldEagerCompile;
return false;
}
if (result == PreParser::kPreParseStackOverflow) { if (result == PreParser::kPreParseStackOverflow) {
// Propagate stack overflow. // Propagate stack overflow.
...@@ -2734,7 +2723,7 @@ Parser::LazyParsingResult Parser::SkipFunction( ...@@ -2734,7 +2723,7 @@ Parser::LazyParsingResult Parser::SkipFunction(
function_scope->AnalyzePartially(factory()); function_scope->AnalyzePartially(factory());
} }
return kLazyParsingComplete; return true;
} }
Statement* Parser::BuildAssertIsCoercible(Variable* var, Statement* Parser::BuildAssertIsCoercible(Variable* var,
......
...@@ -446,12 +446,12 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -446,12 +446,12 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// by parsing the function with PreParser. Consumes the ending }. // by parsing the function with PreParser. Consumes the ending }.
// If may_abort == true, the (pre-)parser may decide to abort skipping // If may_abort == true, the (pre-)parser may decide to abort skipping
// in order to force the function to be eagerly parsed, after all. // in order to force the function to be eagerly parsed, after all.
LazyParsingResult SkipFunction( bool SkipFunction(const AstRawString* function_name, FunctionKind kind,
const AstRawString* function_name, FunctionKind kind, FunctionLiteral::FunctionType function_type,
FunctionLiteral::FunctionType function_type, DeclarationScope* function_scope, int* num_parameters,
DeclarationScope* function_scope, int* num_parameters, ProducedPreParsedScopeData** produced_preparsed_scope_data,
ProducedPreParsedScopeData** produced_preparsed_scope_data, bool is_inner_function, bool may_abort,
bool is_inner_function, bool may_abort, bool* ok); FunctionLiteral::EagerCompileHint* hint, bool* ok);
Block* BuildParameterInitializationBlock( Block* BuildParameterInitializationBlock(
const ParserFormalParameters& parameters, bool* ok); const ParserFormalParameters& parameters, bool* ok);
......
...@@ -1037,12 +1037,13 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1037,12 +1037,13 @@ class PreParser : public ParserBase<PreParser> {
return pending_error_handler_; return pending_error_handler_;
} }
V8_INLINE LazyParsingResult V8_INLINE bool SkipFunction(
SkipFunction(const AstRawString* name, FunctionKind kind, const AstRawString* name, FunctionKind kind,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
DeclarationScope* function_scope, int* num_parameters, DeclarationScope* function_scope, int* num_parameters,
ProducedPreParsedScopeData** produced_preparsed_scope_data, ProducedPreParsedScopeData** produced_preparsed_scope_data,
bool is_inner_function, bool may_abort, bool* ok) { bool is_inner_function, bool may_abort,
FunctionLiteral::EagerCompileHint* hint, bool* ok) {
UNREACHABLE(); UNREACHABLE();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment