From d9790bc7ed8adb422a857415dbd564c077634330 Mon Sep 17 00:00:00 2001 From: "Ben L. Titzer" Date: Thu, 12 Feb 2015 12:56:57 +0100 Subject: [PATCH] Inline the ParseInfo structure as parameters to the Parser constructor. R=mstarzinger@chromium.org BUG= Review URL: https://codereview.chromium.org/913183005 Cr-Commit-Position: refs/heads/master@{#26606} --- src/background-parsing-task.cc | 9 ++++--- src/parser.cc | 23 ++++++++++++---- src/parser.h | 26 +++--------------- test/cctest/test-parsing.cc | 49 ++++++++++++---------------------- 4 files changed, 43 insertions(+), 64 deletions(-) diff --git a/src/background-parsing-task.cc b/src/background-parsing-task.cc index 6ac743e1e5..393a9481b8 100644 --- a/src/background-parsing-task.cc +++ b/src/background-parsing-task.cc @@ -45,13 +45,14 @@ void BackgroundParsingTask::Run() { source_->info->SetCachedData(&script_data, options_); } - uintptr_t limit = reinterpret_cast(&limit) - stack_size_ * KB; - Parser::ParseInfo parse_info = {limit, source_->hash_seed, - &source_->unicode_cache}; + uintptr_t stack_limit = + reinterpret_cast(&stack_limit) - stack_size_ * KB; // Parser needs to stay alive for finalizing the parsing on the main // thread. Passing &parse_info is OK because Parser doesn't store it. - source_->parser.Reset(new Parser(source_->info.get(), &parse_info)); + source_->parser.Reset(new Parser(source_->info.get(), stack_limit, + source_->hash_seed, + &source_->unicode_cache)); source_->parser->set_allow_lazy(source_->allow_lazy); source_->parser->ParseOnBackground(); diff --git a/src/parser.cc b/src/parser.cc index 6db0053a69..c1e6815b00 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -788,11 +788,12 @@ ClassLiteral* ParserTraits::ParseClassLiteral( } -Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) +Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed, + UnicodeCache* unicode_cache) : ParserBase(info->isolate(), info->zone(), &scanner_, - parse_info->stack_limit, info->extension(), + stack_limit, info->extension(), info->ast_value_factory(), NULL, this), - scanner_(parse_info->unicode_cache), + scanner_(unicode_cache), reusable_preparser_(NULL), original_scope_(NULL), target_stack_(NULL), @@ -827,8 +828,7 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) } if (info->ast_value_factory() == NULL) { // info takes ownership of AstValueFactory. - info->SetAstValueFactory( - new AstValueFactory(zone(), parse_info->hash_seed)); + info->SetAstValueFactory(new AstValueFactory(zone(), hash_seed)); ast_value_factory_ = info->ast_value_factory(); } } @@ -5251,6 +5251,19 @@ bool RegExpParser::ParseRegExp(Isolate* isolate, Zone* zone, } +bool Parser::Parse(CompilationInfo* info, bool allow_lazy) { + Parser parser(info, info->isolate()->stack_guard()->real_climit(), + info->isolate()->heap()->HashSeed(), + info->isolate()->unicode_cache()); + parser.set_allow_lazy(allow_lazy); + if (parser.Parse()) { + info->SetLanguageMode(info->function()->language_mode()); + return true; + } + return false; +} + + bool Parser::Parse() { DCHECK(info()->function() == NULL); FunctionLiteral* result = NULL; diff --git a/src/parser.h b/src/parser.h index a91f62ad50..c1b0361980 100644 --- a/src/parser.h +++ b/src/parser.h @@ -635,16 +635,8 @@ class ParserTraits { class Parser : public ParserBase { public: - // Note that the hash seed in ParseInfo must be the hash seed from the - // Isolate's heap, otherwise the heap will be in an inconsistent state once - // the strings created by the Parser are internalized. - struct ParseInfo { - uintptr_t stack_limit; - uint32_t hash_seed; - UnicodeCache* unicode_cache; - }; - - Parser(CompilationInfo* info, ParseInfo* parse_info); + Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed, + UnicodeCache* unicode_cache); ~Parser() { delete reusable_preparser_; reusable_preparser_ = NULL; @@ -655,19 +647,7 @@ class Parser : public ParserBase { // Parses the source code represented by the compilation info and sets its // function literal. Returns false (and deallocates any allocated AST // nodes) if parsing failed. - static bool Parse(CompilationInfo* info, - bool allow_lazy = false) { - ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), - info->isolate()->heap()->HashSeed(), - info->isolate()->unicode_cache()}; - Parser parser(info, &parse_info); - parser.set_allow_lazy(allow_lazy); - if (parser.Parse()) { - info->SetLanguageMode(info->function()->language_mode()); - return true; - } - return false; - } + static bool Parse(CompilationInfo* info, bool allow_lazy = false); bool Parse(); void ParseOnBackground(); diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index a59566bd80..5c7ff06af7 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -1054,10 +1054,8 @@ TEST(ScopeUsesArgumentsSuperThis) { .ToHandleChecked(); i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_harmony_arrow_functions(true); parser.set_allow_harmony_classes(true); parser.set_allow_harmony_object_literals(true); @@ -1312,10 +1310,8 @@ TEST(ScopePositions) { CHECK_EQ(source->length(), kProgramSize); i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_lazy(true); parser.set_allow_harmony_scoping(true); parser.set_allow_harmony_arrow_functions(true); @@ -1473,10 +1469,8 @@ void TestParserSyncWithFlags(i::Handle source, { i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); SetParserFlags(&parser, flags); info.MarkAsGlobal(); parser.Parse(); @@ -3439,10 +3433,9 @@ TEST(InnerAssignment) { i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = { - isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), + isolate->unicode_cache()); parser.set_allow_harmony_scoping(true); CHECK(parser.Parse()); CHECK(i::Compiler::Analyze(&info)); @@ -5052,10 +5045,8 @@ TEST(BasicImportExportParsing) { { i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_harmony_classes(true); parser.set_allow_harmony_modules(true); parser.set_allow_harmony_scoping(true); @@ -5082,10 +5073,8 @@ TEST(BasicImportExportParsing) { { i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_harmony_classes(true); parser.set_allow_harmony_modules(true); parser.set_allow_harmony_scoping(true); @@ -5174,10 +5163,8 @@ TEST(ImportExportParsingErrors) { i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_harmony_classes(true); parser.set_allow_harmony_modules(true); parser.set_allow_harmony_scoping(true); @@ -5270,10 +5257,8 @@ void TestLanguageMode(const char* source, i::Handle script = factory->NewScript(factory->NewStringFromAsciiChecked(source)); i::CompilationInfoWithZone info(script); - i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), - isolate->heap()->HashSeed(), - isolate->unicode_cache()}; - i::Parser parser(&info, &parse_info); + i::Parser parser(&info, isolate->stack_guard()->real_climit(), + isolate->heap()->HashSeed(), isolate->unicode_cache()); parser.set_allow_strong_mode(true); info.MarkAsGlobal(); parser.Parse();