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

[parser] Only write into the active preparsed_scope_data_builder

Change-Id: I3d07bb2d1ae8c77a6b245f5e4ca6f755e2617730
Reviewed-on: https://chromium-review.googlesource.com/c/1335698Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57512}
parent ebb0f30f
......@@ -163,9 +163,7 @@ PreParsedScopeDataBuilder::PreParsedScopeDataBuilder(
PreParsedScopeDataBuilder::DataGatheringScope::DataGatheringScope(
DeclarationScope* function_scope, PreParser* preparser)
: function_scope_(function_scope),
preparser_(preparser),
builder_(nullptr) {
: preparser_(preparser), builder_(nullptr) {
PreParsedScopeDataBuilder* parent = preparser->preparsed_scope_data_builder();
Zone* main_zone = preparser->main_zone();
builder_ = new (main_zone) PreParsedScopeDataBuilder(main_zone, parent);
......@@ -177,16 +175,6 @@ PreParsedScopeDataBuilder::DataGatheringScope::~DataGatheringScope() {
preparser_->set_preparsed_scope_data_builder(builder_->parent_);
}
void PreParsedScopeDataBuilder::DataGatheringScope::MarkFunctionAsSkippable(
int end_position, int num_inner_functions) {
DCHECK_NOT_NULL(builder_);
DCHECK_NOT_NULL(builder_->parent_);
builder_->parent_->AddSkippableFunction(
function_scope_->start_position(), end_position,
function_scope_->num_parameters(), num_inner_functions,
function_scope_->language_mode(), function_scope_->NeedsHomeObject());
}
void PreParsedScopeDataBuilder::AddSkippableFunction(int start_position,
int end_position,
int num_parameters,
......
......@@ -80,10 +80,7 @@ class PreParsedScopeDataBuilder : public ZoneObject {
DataGatheringScope(DeclarationScope* function_scope, PreParser* preparser);
~DataGatheringScope();
void MarkFunctionAsSkippable(int end_position, int num_inner_functions);
private:
DeclarationScope* function_scope_;
PreParser* preparser_;
PreParsedScopeDataBuilder* builder_;
......@@ -123,6 +120,10 @@ class PreParsedScopeDataBuilder : public ZoneObject {
static bool ScopeNeedsData(Scope* scope);
static bool ScopeIsSkippableFunctionScope(Scope* scope);
void AddSkippableFunction(int start_position, int end_position,
int num_parameters, int num_inner_functions,
LanguageMode language_mode,
bool uses_super_property);
private:
friend class BuilderProducedPreParsedScopeData;
......@@ -130,11 +131,6 @@ class PreParsedScopeDataBuilder : public ZoneObject {
virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
virtual ZonePreParsedScopeData* Serialize(Zone* zone);
void AddSkippableFunction(int start_position, int end_position,
int num_parameters, int num_inner_functions,
LanguageMode language_mode,
bool uses_super_property);
void SaveDataForScope(Scope* scope);
void SaveDataForVariable(Variable* var);
void SaveDataForInnerScopes(Scope* scope);
......
......@@ -80,7 +80,7 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
FunctionState top_scope(&function_state_, &scope_, scope);
original_scope_ = scope_;
int start_position = scanner()->peek_location().beg_pos;
int start_position = peek_position();
PreParserScopedStatementList body(pointer_buffer());
ParseStatementList(&body, Token::EOS);
original_scope_ = nullptr;
......@@ -149,7 +149,7 @@ PreParser::PreParseResult PreParser::PreParseFunction(
if (!formals.is_simple) {
inner_scope = NewVarblockScope();
inner_scope->set_start_position(scanner()->location().beg_pos);
inner_scope->set_start_position(position());
}
{
......@@ -268,64 +268,70 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
DeclarationScope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
int func_id = GetNextFunctionLiteralId();
bool skippable_function = false;
// Start collecting data for a new function which might contain skippable
// functions.
std::unique_ptr<PreParsedScopeDataBuilder::DataGatheringScope>
preparsed_scope_data_builder_scope;
if (!function_state_->next_function_is_likely_called() &&
preparsed_scope_data_builder_ != nullptr) {
preparsed_scope_data_builder_scope.reset(
new PreParsedScopeDataBuilder::DataGatheringScope(function_scope,
this));
}
{
std::unique_ptr<PreParsedScopeDataBuilder::DataGatheringScope>
preparsed_scope_data_builder_scope;
if (!function_state_->next_function_is_likely_called() &&
preparsed_scope_data_builder_ != nullptr) {
skippable_function = true;
preparsed_scope_data_builder_scope.reset(
new PreParsedScopeDataBuilder::DataGatheringScope(function_scope,
this));
}
FunctionState function_state(&function_state_, &scope_, function_scope);
ExpressionClassifier formals_classifier(this);
int func_id = GetNextFunctionLiteralId();
FunctionState function_state(&function_state_, &scope_, function_scope);
ExpressionClassifier formals_classifier(this);
Expect(Token::LPAREN);
int start_position = scanner()->location().beg_pos;
function_scope->set_start_position(start_position);
PreParserFormalParameters formals(function_scope);
ParseFormalParameterList(&formals);
Expect(Token::RPAREN);
int formals_end_position = scanner()->location().end_pos;
Expect(Token::LPAREN);
int start_position = position();
function_scope->set_start_position(start_position);
PreParserFormalParameters formals(function_scope);
ParseFormalParameterList(&formals);
Expect(Token::RPAREN);
int formals_end_position = scanner()->location().end_pos;
CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position,
formals_end_position);
CheckArityRestrictions(formals.arity, kind, formals.has_rest,
start_position, formals_end_position);
Expect(Token::LBRACE);
Expect(Token::LBRACE);
// Parse function body.
PreParserScopedStatementList body(pointer_buffer());
int pos = function_token_pos == kNoSourcePosition ? peek_position()
: function_token_pos;
AcceptINScope scope(this, true);
ParseFunctionBody(&body, function_name, pos, formals, kind, function_type,
FunctionBodyType::kBlock);
// Parse function body.
PreParserScopedStatementList body(pointer_buffer());
int pos = function_token_pos == kNoSourcePosition ? peek_position()
: function_token_pos;
AcceptINScope scope(this, true);
ParseFunctionBody(&body, function_name, pos, formals, kind, function_type,
FunctionBodyType::kBlock);
// Parsing the body may change the language mode in our scope.
language_mode = function_scope->language_mode();
// Parsing the body may change the language mode in our scope.
language_mode = function_scope->language_mode();
if (is_sloppy(language_mode)) {
function_scope->HoistSloppyBlockFunctions(nullptr);
}
if (is_sloppy(language_mode)) {
function_scope->HoistSloppyBlockFunctions(nullptr);
}
// Validate name and parameter names. We can do this only after parsing the
// function, since the function can declare itself strict.
CheckFunctionName(language_mode, function_name, function_name_validity,
function_name_location);
// Validate name and parameter names. We can do this only after parsing the
// function, since the function can declare itself strict.
CheckFunctionName(language_mode, function_name, function_name_validity,
function_name_location);
int end_position = scanner()->location().end_pos;
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(start_position, end_position);
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(start_position, end_position());
}
}
if (preparsed_scope_data_builder_scope) {
preparsed_scope_data_builder_scope->MarkFunctionAsSkippable(
end_position, GetLastFunctionLiteralId() - func_id);
if (skippable_function) {
preparsed_scope_data_builder_->AddSkippableFunction(
function_scope->start_position(), end_position(),
function_scope->num_parameters(), GetLastFunctionLiteralId() - func_id,
function_scope->language_mode(), function_scope->NeedsHomeObject());
}
if (V8_UNLIKELY(FLAG_log_function_events)) {
double ms = timer.Elapsed().InMillisecondsF();
const char* event_name = "preparse-resolution";
......
......@@ -238,8 +238,8 @@ class PreParserExpression {
bool IsValidPattern() const {
STATIC_ASSERT(kObjectLiteralExpression + 1 == kArrayLiteralExpression);
return IsInRange(TypeField::decode(code_),
kObjectLiteralExpression, kArrayLiteralExpression);
return IsInRange(TypeField::decode(code_), kObjectLiteralExpression,
kArrayLiteralExpression);
}
bool IsStringLiteral() const {
......
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