Commit 54db0236 authored by Wiktor Garbacz's avatar Wiktor Garbacz Committed by Commit Bot

[parser] Parse tasks: make them pass all tests.

Parse tasks are still WIP so there is really no benefit turning them on.

Turn off irrelevant tests.
Fix duplicate parameters inverted logic.
Fix use_counts tracking.
Fix language mode, super_property, evals.
Fix modules and stack overflow.

BUG=v8:6093

Change-Id: I8567b36eef7b9de6799789e7520810bde9c86e5b
Reviewed-on: https://chromium-review.googlesource.com/455916
Commit-Queue: Wiktor Garbacz <wiktorg@google.com>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43903}
parent ac4a77cc
......@@ -625,9 +625,19 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source));
if (FLAG_use_parse_tasks) {
// FIXME(wiktorg) make it useful for something
scanner_.Initialize(stream.get());
reusable_preparser()->PreParseProgram();
stream->Seek(0);
// TODO(wiktorg) make preparser work also with modules
if (!info->is_module()) {
scanner_.Initialize(stream.get());
// NOTE: Some features will be double counted - once here and one more
// time while being fully parsed by a parse task.
PreParser::PreParseResult result =
reusable_preparser()->PreParseProgram(false, use_counts_);
if (result == PreParser::kPreParseStackOverflow) {
set_stack_overflow();
return nullptr;
}
stream->Seek(0);
}
}
scanner_.Initialize(stream.get());
result = DoParseProgram(info);
......@@ -2808,6 +2818,13 @@ Parser::LazyParsingResult Parser::SkipFunction(
*function_length = data.function_length;
*has_duplicate_parameters = data.has_duplicate_parameters;
*expected_property_count = data.expected_property_count;
SetLanguageMode(function_scope, data.language_mode);
if (data.uses_super_property) {
function_scope->RecordSuperPropertyUsage();
}
if (data.calls_eval) {
function_scope->RecordEvalCall();
}
SkipFunctionLiterals(data.num_inner_functions);
return kLazyParsingComplete;
}
......
......@@ -123,19 +123,26 @@ class PreParseData final {
bool has_duplicate_parameters;
int expected_property_count;
int num_inner_functions;
LanguageMode language_mode;
bool uses_super_property;
bool calls_eval;
FunctionData() : start(-1), end(-1) {}
FunctionData(int start, int end, int num_parameters, int function_length,
bool has_duplicate_parameters, int expected_property_count,
int num_inner_functions)
int num_inner_functions, LanguageMode language_mode,
bool uses_super_property, bool calls_eval)
: start(start),
end(end),
num_parameters(num_parameters),
function_length(function_length),
has_duplicate_parameters(has_duplicate_parameters),
expected_property_count(expected_property_count),
num_inner_functions(num_inner_functions) {}
num_inner_functions(num_inner_functions),
language_mode(language_mode),
uses_super_property(uses_super_property),
calls_eval(calls_eval) {}
bool is_valid() const { return start < end; }
};
......
......@@ -85,8 +85,10 @@ PreParserIdentifier PreParser::GetSymbol() const {
return symbol;
}
PreParser::PreParseResult PreParser::PreParseProgram(bool is_module) {
PreParser::PreParseResult PreParser::PreParseProgram(bool is_module,
int* use_counts) {
DCHECK_NULL(scope_);
use_counts_ = use_counts;
DeclarationScope* scope = NewScriptScope();
#ifdef DEBUG
scope->set_is_being_lazily_parsed(true);
......@@ -105,6 +107,7 @@ PreParser::PreParseResult PreParser::PreParseProgram(bool is_module) {
PreParserStatementList body;
ParseStatementList(body, Token::EOS, &ok);
original_scope_ = nullptr;
use_counts_ = nullptr;
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
......@@ -313,23 +316,22 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
}
if (FLAG_use_parse_tasks && is_top_level && preparse_data_) {
bool has_duplicate_parameters =
!formals_classifier.is_valid_formal_parameter_list_without_duplicates();
preparse_data_->AddTopLevelFunctionData(PreParseData::FunctionData(
start_position, end_position, formals.num_parameters(),
formals.function_length,
formals_classifier.is_valid_formal_parameter_list_without_duplicates(),
formals.function_length, has_duplicate_parameters,
function_state_->expected_property_count(),
GetLastFunctionLiteralId() - func_id));
GetLastFunctionLiteralId() - func_id, language_mode,
function_scope->uses_super_property(), function_scope->calls_eval()));
// TODO(wiktorg) spin-off a parse task
if (FLAG_trace_parse_tasks) {
PrintF("Saved function at %d to %d with:\n", start_position,
end_position);
PrintF("\t- %d params\n", formals.num_parameters());
PrintF("\t- %d function length\n", formals.function_length);
PrintF(
"\t- %s duplicate parameters\n",
formals_classifier.is_valid_formal_parameter_list_without_duplicates()
? "NO"
: "SOME");
PrintF("\t- %s duplicate parameters\n",
has_duplicate_parameters ? "SOME" : "NO");
PrintF("\t- %d expected properties\n",
function_state_->expected_property_count());
PrintF("\t- %d inner-funcs\n", GetLastFunctionLiteralId() - func_id);
......
......@@ -900,7 +900,8 @@ class PreParser : public ParserBase<PreParser> {
// success (even if parsing failed, the pre-parse data successfully
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
PreParseResult PreParseProgram(bool is_module = false);
PreParseResult PreParseProgram(bool is_module = false,
int* use_counts = nullptr);
// Parses a single function literal, from the opening parentheses before
// parameters to the closing brace after the body.
......
......@@ -280,6 +280,8 @@ TEST(UsingCachedData) {
TEST(PreparseFunctionDataIsUsed) {
// Producing cached parser data while parsing eagerly is not supported.
if (!i::FLAG_lazy) return;
// Test does not apply if parse tasks are used.
if (i::FLAG_use_parse_tasks) return;
// This tests that we actually do use the function data generated by the
// preparser.
......@@ -490,6 +492,8 @@ TEST(RegressChromium62639) {
TEST(Regress928) {
// Test only applies when lazy parsing.
if (!i::FLAG_lazy) return;
// Test does not apply if parse tasks are used
if (i::FLAG_use_parse_tasks) return;
// Tests that the first non-toplevel function is not included in the preparse
// data.
......@@ -2423,6 +2427,10 @@ TEST(NoErrorsIdentifierNames) {
TEST(DontRegressPreParserDataSizes) {
// These tests make sure that Parser doesn't start producing less "preparse
// data" (data which the embedder can cache).
// Test does not apply if parse tasks are used.
if (i::FLAG_use_parse_tasks) return;
v8::V8::Initialize();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
......
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