Commit 40567349 authored by Sven Panne's avatar Sven Panne

Remove funky 2-stage initialization of ParserInfo and an adventurous memset.

R=titzer@chromium.org

Review URL: https://codereview.chromium.org/1002673002

Cr-Commit-Position: refs/heads/master@{#27155}
parent 0902b5f4
......@@ -1570,18 +1570,16 @@ bool CompilationPhase::ShouldProduceTraceOutput() const {
CompilationInfoWithZone::CompilationInfoWithZone(Handle<Script> script)
: CompilationInfo((new ParseInfo(&zone_))->InitializeFromScript(script)) {}
: CompilationInfo(new ParseInfo(&zone_, script)) {}
CompilationInfoWithZone::CompilationInfoWithZone(Handle<JSFunction> function)
: CompilationInfo(
(new ParseInfo(&zone_))->InitializeFromJSFunction(function)) {}
: CompilationInfo(new ParseInfo(&zone_, function)) {}
CompilationInfoWithZone::CompilationInfoWithZone(
Handle<SharedFunctionInfo> shared_info)
: CompilationInfo((new ParseInfo(&zone_))
->InitializeFromSharedFunctionInfo(shared_info)) {}
: CompilationInfo(new ParseInfo(&zone_, shared_info)) {}
CompilationInfoWithZone::~CompilationInfoWithZone() {
......
......@@ -7848,8 +7848,7 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
// Parse and allocate variables.
// Use the same AstValueFactory for creating strings in the sub-compilation
// step, but don't transfer ownership to target_info.
ParseInfo parse_info(zone());
parse_info.InitializeFromJSFunction(target);
ParseInfo parse_info(zone(), target);
parse_info.set_ast_value_factory(
top_info()->parse_info()->ast_value_factory());
parse_info.set_ast_value_factory_owned(false);
......
......@@ -35,17 +35,32 @@ ScriptData::ScriptData(const byte* data, int length)
}
ParseInfo* ParseInfo::InitializeFromJSFunction(Handle<JSFunction> function) {
Handle<SharedFunctionInfo> shared(function->shared());
InitializeFromSharedFunctionInfo(shared);
ParseInfo::ParseInfo(Zone* zone)
: zone_(zone),
flags_(0),
source_stream_(nullptr),
source_stream_encoding_(ScriptCompiler::StreamedSource::ONE_BYTE),
extension_(nullptr),
compile_options_(ScriptCompiler::kNoCompileOptions),
script_scope_(nullptr),
unicode_cache_(nullptr),
stack_limit_(0),
hash_seed_(0),
cached_data_(nullptr),
ast_value_factory_(nullptr),
literal_(nullptr),
scope_(nullptr) {}
ParseInfo::ParseInfo(Zone* zone, Handle<JSFunction> function)
: ParseInfo(zone, Handle<SharedFunctionInfo>(function->shared())) {
set_closure(function);
set_context(Handle<Context>(function->context()));
return this;
}
ParseInfo* ParseInfo::InitializeFromSharedFunctionInfo(
Handle<SharedFunctionInfo> shared) {
ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared)
: ParseInfo(zone) {
isolate_ = shared->GetIsolate();
set_lazy();
......@@ -61,11 +76,10 @@ ParseInfo* ParseInfo::InitializeFromSharedFunctionInfo(
if (!script.is_null() && script->type()->value() == Script::TYPE_NATIVE) {
set_native();
}
return this;
}
ParseInfo* ParseInfo::InitializeFromScript(Handle<Script> script) {
ParseInfo::ParseInfo(Zone* zone, Handle<Script> script) : ParseInfo(zone) {
isolate_ = script->GetIsolate();
set_this_has_uses();
......@@ -77,7 +91,6 @@ ParseInfo* ParseInfo::InitializeFromScript(Handle<Script> script) {
if (script->type()->value() == Script::TYPE_NATIVE) {
set_native();
}
return this;
}
......
......@@ -25,10 +25,10 @@ class Target;
// A container for the inputs, configuration options, and outputs of parsing.
class ParseInfo {
public:
explicit ParseInfo(Zone* zone) {
memset(this, 0, sizeof(ParseInfo));
zone_ = zone;
}
explicit ParseInfo(Zone* zone);
ParseInfo(Zone* zone, Handle<JSFunction> function);
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
ParseInfo(Zone* zone, Handle<Script> script);
~ParseInfo() {
if (ast_value_factory_owned()) {
......@@ -38,11 +38,6 @@ class ParseInfo {
ast_value_factory_ = nullptr;
}
ParseInfo* InitializeFromJSFunction(Handle<JSFunction> function);
ParseInfo* InitializeFromSharedFunctionInfo(
Handle<SharedFunctionInfo> shared);
ParseInfo* InitializeFromScript(Handle<Script> script);
Zone* zone() { return zone_; }
// Convenience accessor methods for flags.
......
......@@ -1201,11 +1201,10 @@ class ScopeIterator {
// Check whether we are in global, eval or function code.
Handle<ScopeInfo> scope_info(shared_info->scope_info());
Zone zone;
ParseInfo info(&zone);
if (scope_info->scope_type() != FUNCTION_SCOPE &&
scope_info->scope_type() != ARROW_SCOPE) {
// Global or eval code.
info.InitializeFromScript(script);
ParseInfo info(&zone, script);
if (scope_info->scope_type() == SCRIPT_SCOPE) {
info.set_global();
} else {
......@@ -1219,7 +1218,7 @@ class ScopeIterator {
RetrieveScopeChain(scope, shared_info);
} else {
// Function code
info.InitializeFromSharedFunctionInfo(shared_info);
ParseInfo info(&zone, shared_info);
if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) {
scope = info.function()->scope();
}
......
......@@ -179,19 +179,16 @@ RUNTIME_FUNCTION(Runtime_RenderCallSite) {
if (location.start_pos() == -1) return isolate->heap()->empty_string();
Zone zone;
ParseInfo info(&zone);
if (location.function()->shared()->is_function()) {
info.InitializeFromJSFunction(location.function());
} else {
info.InitializeFromScript(location.script());
}
SmartPointer<ParseInfo> info(location.function()->shared()->is_function()
? new ParseInfo(&zone, location.function())
: new ParseInfo(&zone, location.script()));
if (!Parser::ParseStatic(&info)) {
if (!Parser::ParseStatic(info.get())) {
isolate->clear_pending_exception();
return isolate->heap()->empty_string();
}
CallPrinter printer(isolate, &zone);
const char* string = printer.Print(info.function(), location.start_pos());
const char* string = printer.Print(info->function(), location.start_pos());
return *isolate->factory()->NewStringFromAsciiChecked(string);
}
......
......@@ -44,8 +44,8 @@ class DeoptCodegenTester {
explicit DeoptCodegenTester(HandleAndZoneScope* scope, const char* src)
: scope_(scope),
function(NewFunction(src)),
parse_info(scope->main_zone()),
info(parse_info.InitializeFromJSFunction(function)),
parse_info(scope->main_zone(), function),
info(&parse_info),
bailout_id(-1) {
CHECK(Parser::ParseStatic(&parse_info));
info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
......
......@@ -29,8 +29,7 @@ struct TestHelper : public HandleAndZoneScope {
void CheckLoopAssignedCount(int expected, const char* var_name) {
// TODO(titzer): don't scope analyze every single time.
ParseInfo parse_info(main_zone());
parse_info.InitializeFromJSFunction(function);
ParseInfo parse_info(main_zone(), function);
CompilationInfo info(&parse_info);
CHECK(Parser::ParseStatic(&parse_info));
......
......@@ -1046,8 +1046,7 @@ TEST(ScopeUsesArgumentsSuperThis) {
.ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_arrow_functions(true);
parser.set_allow_harmony_classes(true);
......@@ -1299,8 +1298,7 @@ TEST(ScopePositions) {
CHECK_EQ(source->length(), kProgramSize);
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_lazy(true);
parser.set_allow_harmony_scoping(true);
......@@ -1459,8 +1457,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
{
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
SetParserFlags(&parser, flags);
info.set_global();
......@@ -2548,8 +2545,7 @@ TEST(DontRegressPreParserDataSizes) {
factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::ScriptData* sd = NULL;
info.set_cached_data(&sd);
info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
......@@ -3375,8 +3371,7 @@ TEST(InnerAssignment) {
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_scoping(true);
CHECK(parser.Parse(&info));
......@@ -5086,8 +5081,7 @@ TEST(BasicImportExportParsing) {
{
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
......@@ -5115,8 +5109,7 @@ TEST(BasicImportExportParsing) {
{
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
......@@ -5207,8 +5200,7 @@ TEST(ImportExportParsingErrors) {
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
......@@ -5238,8 +5230,7 @@ TEST(ModuleParsingInternals) {
i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
i::Parser parser(&info);
parser.set_allow_harmony_modules(true);
......@@ -5364,8 +5355,7 @@ void TestLanguageMode(const char* source,
i::Handle<i::Script> script =
factory->NewScript(factory->NewStringFromAsciiChecked(source));
i::Zone zone;
i::ParseInfo info(&zone);
info.InitializeFromScript(script);
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_strong_mode(true);
info.set_global();
......
......@@ -89,8 +89,7 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
// First round of parsing (produce data to cache).
{
Zone zone;
ParseInfo info(&zone);
info.InitializeFromScript(script);
ParseInfo info(&zone, script);
info.set_global();
info.set_cached_data(&cached_data_impl);
info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
......@@ -108,8 +107,7 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
// Second round of parsing (consume cached data).
{
Zone zone;
ParseInfo info(&zone);
info.InitializeFromScript(script);
ParseInfo info(&zone, script);
info.set_global();
info.set_cached_data(&cached_data_impl);
info.set_compile_options(v8::ScriptCompiler::kConsumeParserCache);
......
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