Commit 83dee31e authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Parser] Split building logic out of ProducedPreParserScopeData.

Splits PreParsedScopeDataBuilder out of ProducedPreParserScopeData to make the split between
building PreParsedScopeData and using already build PreParserScopeData more explicit.

BUG=v8:8041

Change-Id: Iab42cab84c247152c14ac39f3136f985753160ec
Reviewed-on: https://chromium-review.googlesource.com/1202104
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55718}
parent ce589362
...@@ -319,7 +319,7 @@ void DeclarationScope::SetDefaults() { ...@@ -319,7 +319,7 @@ void DeclarationScope::SetDefaults() {
should_eager_compile_ = false; should_eager_compile_ = false;
was_lazily_parsed_ = false; was_lazily_parsed_ = false;
is_skipped_function_ = false; is_skipped_function_ = false;
produced_preparsed_scope_data_ = nullptr; preparsed_scope_data_builder_ = nullptr;
#ifdef DEBUG #ifdef DEBUG
DeclarationScope* outer_declaration_scope = DeclarationScope* outer_declaration_scope =
outer_scope_ ? outer_scope_->GetDeclarationScope() : nullptr; outer_scope_ ? outer_scope_->GetDeclarationScope() : nullptr;
...@@ -1532,7 +1532,7 @@ void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory, ...@@ -1532,7 +1532,7 @@ void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory,
void Scope::SavePreParsedScopeData() { void Scope::SavePreParsedScopeData() {
DCHECK(FLAG_preparser_scope_analysis); DCHECK(FLAG_preparser_scope_analysis);
if (ProducedPreParsedScopeData::ScopeIsSkippableFunctionScope(this)) { if (PreParsedScopeDataBuilder::ScopeIsSkippableFunctionScope(this)) {
AsDeclarationScope()->SavePreParsedScopeDataForDeclarationScope(); AsDeclarationScope()->SavePreParsedScopeDataForDeclarationScope();
} }
...@@ -1542,9 +1542,9 @@ void Scope::SavePreParsedScopeData() { ...@@ -1542,9 +1542,9 @@ void Scope::SavePreParsedScopeData() {
} }
void DeclarationScope::SavePreParsedScopeDataForDeclarationScope() { void DeclarationScope::SavePreParsedScopeDataForDeclarationScope() {
if (produced_preparsed_scope_data_ != nullptr) { if (preparsed_scope_data_builder_ != nullptr) {
DCHECK(FLAG_preparser_scope_analysis); DCHECK(FLAG_preparser_scope_analysis);
produced_preparsed_scope_data_->SaveScopeAllocationData(this); preparsed_scope_data_builder_->SaveScopeAllocationData(this);
} }
} }
...@@ -1554,8 +1554,8 @@ void DeclarationScope::AnalyzePartially(AstNodeFactory* ast_node_factory) { ...@@ -1554,8 +1554,8 @@ void DeclarationScope::AnalyzePartially(AstNodeFactory* ast_node_factory) {
if (!outer_scope_->is_script_scope() || if (!outer_scope_->is_script_scope() ||
(FLAG_preparser_scope_analysis && (FLAG_preparser_scope_analysis &&
produced_preparsed_scope_data_ != nullptr && preparsed_scope_data_builder_ != nullptr &&
produced_preparsed_scope_data_->ContainsInnerFunctions())) { preparsed_scope_data_builder_->ContainsInnerFunctions())) {
// Try to resolve unresolved variables for this Scope and migrate those // Try to resolve unresolved variables for this Scope and migrate those
// which cannot be resolved inside. It doesn't make sense to try to resolve // which cannot be resolved inside. It doesn't make sense to try to resolve
// them in the outer Scopes here, because they are incomplete. // them in the outer Scopes here, because they are incomplete.
......
...@@ -20,8 +20,7 @@ class AstValueFactory; ...@@ -20,8 +20,7 @@ class AstValueFactory;
class AstRawString; class AstRawString;
class Declaration; class Declaration;
class ParseInfo; class ParseInfo;
class PreParsedScopeData; class PreParsedScopeDataBuilder;
class ProducedPreParsedScopeData;
class SloppyBlockFunctionStatement; class SloppyBlockFunctionStatement;
class Statement; class Statement;
class StringSet; class StringSet;
...@@ -919,13 +918,13 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { ...@@ -919,13 +918,13 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
// saved in produced_preparsed_scope_data_. // saved in produced_preparsed_scope_data_.
void SavePreParsedScopeDataForDeclarationScope(); void SavePreParsedScopeDataForDeclarationScope();
void set_produced_preparsed_scope_data( void set_preparsed_scope_data_builder(
ProducedPreParsedScopeData* produced_preparsed_scope_data) { PreParsedScopeDataBuilder* preparsed_scope_data_builder) {
produced_preparsed_scope_data_ = produced_preparsed_scope_data; preparsed_scope_data_builder_ = preparsed_scope_data_builder;
} }
ProducedPreParsedScopeData* produced_preparsed_scope_data() const { PreParsedScopeDataBuilder* preparsed_scope_data_builder() const {
return produced_preparsed_scope_data_; return preparsed_scope_data_builder_;
} }
private: private:
...@@ -981,7 +980,7 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { ...@@ -981,7 +980,7 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
Variable* arguments_; Variable* arguments_;
// For producing the scope allocation data during preparsing. // For producing the scope allocation data during preparsing.
ProducedPreParsedScopeData* produced_preparsed_scope_data_; PreParsedScopeDataBuilder* preparsed_scope_data_builder_;
struct RareData : public ZoneObject { struct RareData : public ZoneObject {
// Convenience variable; Subclass constructor only // Convenience variable; Subclass constructor only
......
...@@ -33,7 +33,7 @@ struct PreParsedScopeByteDataConstants { ...@@ -33,7 +33,7 @@ struct PreParsedScopeByteDataConstants {
4 * kUint32Size + 1 * kUint8Size; 4 * kUint32Size + 1 * kUint8Size;
}; };
class ProducedPreParsedScopeData::ByteData class PreParsedScopeDataBuilder::ByteData
: public ZoneObject, : public ZoneObject,
public PreParsedScopeByteDataConstants { public PreParsedScopeByteDataConstants {
public: public:
......
This diff is collapsed.
...@@ -62,23 +62,15 @@ class ZonePreParsedScopeData; ...@@ -62,23 +62,15 @@ class ZonePreParsedScopeData;
*/ */
class ProducedPreParsedScopeData : public ZoneObject { class PreParsedScopeDataBuilder : public ZoneObject {
public: public:
class ByteData; class ByteData;
// Create a ProducedPreParsedScopeData object which will collect data as we // Create a PreParsedScopeDataBuilder object which will collect data as we
// parse. // parse.
ProducedPreParsedScopeData(Zone* zone, ProducedPreParsedScopeData* parent); PreParsedScopeDataBuilder(Zone* zone, PreParsedScopeDataBuilder* parent);
// Create a ProducedPreParsedScopeData which is just a proxy for a previous
// produced PreParsedScopeData on the heap.
ProducedPreParsedScopeData(Handle<PreParsedScopeData> data, Zone* zone);
// Create a ProducedPreParsedScopeData which is just a proxy for a previous
// produced PreParsedScopeData in zone.
ProducedPreParsedScopeData(ZonePreParsedScopeData* data, Zone* zone);
ProducedPreParsedScopeData* parent() const { return parent_; } PreParsedScopeDataBuilder* parent() const { return parent_; }
// For gathering the inner function data and splitting it up according to the // For gathering the inner function data and splitting it up according to the
// laziness boundaries. Each lazy function gets its own // laziness boundaries. Each lazy function gets its own
...@@ -93,7 +85,7 @@ class ProducedPreParsedScopeData : public ZoneObject { ...@@ -93,7 +85,7 @@ class ProducedPreParsedScopeData : public ZoneObject {
private: private:
DeclarationScope* function_scope_; DeclarationScope* function_scope_;
PreParser* preparser_; PreParser* preparser_;
ProducedPreParsedScopeData* produced_preparsed_scope_data_; PreParsedScopeDataBuilder* builder_;
DISALLOW_COPY_AND_ASSIGN(DataGatheringScope); DISALLOW_COPY_AND_ASSIGN(DataGatheringScope);
}; };
...@@ -129,20 +121,15 @@ class ProducedPreParsedScopeData : public ZoneObject { ...@@ -129,20 +121,15 @@ class ProducedPreParsedScopeData : public ZoneObject {
bool ContainsInnerFunctions() const; bool ContainsInnerFunctions() const;
// If there is data (if the Scope contains skippable inner functions), move
// the data into the heap and return a Handle to it; otherwise return a null
// MaybeHandle.
MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
// If there is data (if the Scope contains skippable inner functions), return
// an off-heap ZonePreParsedScopeData representing the data; otherwise
// return nullptr.
ZonePreParsedScopeData* Serialize(Zone* zone);
static bool ScopeNeedsData(Scope* scope); static bool ScopeNeedsData(Scope* scope);
static bool ScopeIsSkippableFunctionScope(Scope* scope); static bool ScopeIsSkippableFunctionScope(Scope* scope);
private: private:
friend class BuilderProducedPreParsedScopeData;
virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
virtual ZonePreParsedScopeData* Serialize(Zone* zone);
void AddSkippableFunction(int start_position, int end_position, void AddSkippableFunction(int start_position, int end_position,
int num_parameters, int num_inner_functions, int num_parameters, int num_inner_functions,
LanguageMode language_mode, LanguageMode language_mode,
...@@ -152,27 +139,43 @@ class ProducedPreParsedScopeData : public ZoneObject { ...@@ -152,27 +139,43 @@ class ProducedPreParsedScopeData : public ZoneObject {
void SaveDataForVariable(Variable* var); void SaveDataForVariable(Variable* var);
void SaveDataForInnerScopes(Scope* scope); void SaveDataForInnerScopes(Scope* scope);
ProducedPreParsedScopeData* parent_; PreParsedScopeDataBuilder* parent_;
ByteData* byte_data_; ByteData* byte_data_;
ZoneChunkList<ProducedPreParsedScopeData*> data_for_inner_functions_; ZoneChunkList<PreParsedScopeDataBuilder*> data_for_inner_functions_;
// Whether we've given up producing the data for this function. // Whether we've given up producing the data for this function.
bool bailed_out_; bool bailed_out_;
// ProducedPreParsedScopeData can also hold a Handle<PreParsedScopeData> DISALLOW_COPY_AND_ASSIGN(PreParsedScopeDataBuilder);
// which was produced already earlier. This happens for deeper lazy functions. };
// TODO(rmcilroy): Split apart ProducedPreParsedScopeData into different
// classes for situations where it has already been produced.
Handle<PreParsedScopeData> previously_produced_on_heap_preparsed_scope_data_;
// ProducedPreParsedScopeData can also hold a ZonePreParsedScopeData* class ProducedPreParsedScopeData : public ZoneObject {
// which was produced already earlier. This happens for deeper lazy functions. public:
// TODO(rmcilroy): Split apart ProducedPreParsedScopeData into different // If there is data (if the Scope contains skippable inner functions), move
// classes for situations where it has already been produced. // the data into the heap and return a Handle to it; otherwise return a null
ZonePreParsedScopeData* previously_produced_zone_preparsed_scope_data_; // MaybeHandle.
virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate) = 0;
DISALLOW_COPY_AND_ASSIGN(ProducedPreParsedScopeData); // If there is data (if the Scope contains skippable inner functions), return
// an off-heap ZonePreParsedScopeData representing the data; otherwise
// return nullptr.
virtual ZonePreParsedScopeData* Serialize(Zone* zone) = 0;
// Create a ProducedPreParsedScopeData which is a proxy for a previous
// produced PreParsedScopeData in zone.
static ProducedPreParsedScopeData* For(PreParsedScopeDataBuilder* builder,
Zone* zone);
// Create a ProducedPreParsedScopeData which is a proxy for a previous
// produced PreParsedScopeData on the heap.
static ProducedPreParsedScopeData* For(Handle<PreParsedScopeData> data,
Zone* zone);
// Create a ProducedPreParsedScopeData which is a proxy for a previous
// produced PreParsedScopeData in zone.
static ProducedPreParsedScopeData* For(ZonePreParsedScopeData* data,
Zone* zone);
}; };
class ConsumedPreParsedScopeData { class ConsumedPreParsedScopeData {
......
...@@ -134,12 +134,12 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -134,12 +134,12 @@ PreParser::PreParseResult PreParser::PreParseFunction(
// Start collecting data for a new function which might contain skippable // Start collecting data for a new function which might contain skippable
// functions. // functions.
std::unique_ptr<ProducedPreParsedScopeData::DataGatheringScope> std::unique_ptr<PreParsedScopeDataBuilder::DataGatheringScope>
produced_preparsed_scope_data_scope; preparsed_scope_data_builder_scope;
if (FLAG_preparser_scope_analysis && !IsArrowFunction(kind)) { if (FLAG_preparser_scope_analysis && !IsArrowFunction(kind)) {
DCHECK(track_unresolved_variables_); DCHECK(track_unresolved_variables_);
produced_preparsed_scope_data_scope.reset( preparsed_scope_data_builder_scope.reset(
new ProducedPreParsedScopeData::DataGatheringScope(function_scope, new PreParsedScopeDataBuilder::DataGatheringScope(function_scope,
this)); this));
} }
...@@ -239,7 +239,8 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -239,7 +239,8 @@ PreParser::PreParseResult PreParser::PreParseFunction(
allow_duplicate_parameters, allow_duplicate_parameters,
CHECK_OK_VALUE(kPreParseSuccess)); CHECK_OK_VALUE(kPreParseSuccess));
*produced_preparsed_scope_data = produced_preparsed_scope_data_; *produced_preparsed_scope_data = ProducedPreParsedScopeData::For(
preparsed_scope_data_builder_, main_zone());
} }
if (is_strict(function_scope->language_mode())) { if (is_strict(function_scope->language_mode())) {
...@@ -292,14 +293,14 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -292,14 +293,14 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// Start collecting data for a new function which might contain skippable // Start collecting data for a new function which might contain skippable
// functions. // functions.
std::unique_ptr<ProducedPreParsedScopeData::DataGatheringScope> std::unique_ptr<PreParsedScopeDataBuilder::DataGatheringScope>
produced_preparsed_scope_data_scope; preparsed_scope_data_builder_scope;
if (!function_state_->next_function_is_likely_called() && if (!function_state_->next_function_is_likely_called() &&
produced_preparsed_scope_data_ != nullptr) { preparsed_scope_data_builder_ != nullptr) {
DCHECK(FLAG_preparser_scope_analysis); DCHECK(FLAG_preparser_scope_analysis);
DCHECK(track_unresolved_variables_); DCHECK(track_unresolved_variables_);
produced_preparsed_scope_data_scope.reset( preparsed_scope_data_builder_scope.reset(
new ProducedPreParsedScopeData::DataGatheringScope(function_scope, new PreParsedScopeDataBuilder::DataGatheringScope(function_scope,
this)); this));
} }
...@@ -348,8 +349,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -348,8 +349,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
} }
if (produced_preparsed_scope_data_scope) { if (preparsed_scope_data_builder_scope) {
produced_preparsed_scope_data_scope->MarkFunctionAsSkippable( preparsed_scope_data_builder_scope->MarkFunctionAsSkippable(
end_position, GetLastFunctionLiteralId() - func_id); end_position, GetLastFunctionLiteralId() - func_id);
} }
if (V8_UNLIKELY(FLAG_log_function_events)) { if (V8_UNLIKELY(FLAG_log_function_events)) {
...@@ -396,19 +397,19 @@ PreParserStatement PreParser::BuildParameterInitializationBlock( ...@@ -396,19 +397,19 @@ PreParserStatement PreParser::BuildParameterInitializationBlock(
DCHECK(scope()->is_function_scope()); DCHECK(scope()->is_function_scope());
if (FLAG_preparser_scope_analysis && if (FLAG_preparser_scope_analysis &&
scope()->AsDeclarationScope()->calls_sloppy_eval() && scope()->AsDeclarationScope()->calls_sloppy_eval() &&
produced_preparsed_scope_data_ != nullptr) { preparsed_scope_data_builder_ != nullptr) {
// We cannot replicate the Scope structure constructed by the Parser, // We cannot replicate the Scope structure constructed by the Parser,
// because we've lost information whether each individual parameter was // because we've lost information whether each individual parameter was
// simple or not. Give up trying to produce data to skip inner functions. // simple or not. Give up trying to produce data to skip inner functions.
if (produced_preparsed_scope_data_->parent() != nullptr) { if (preparsed_scope_data_builder_->parent() != nullptr) {
// Lazy parsing started before the current function; the function which // Lazy parsing started before the current function; the function which
// cannot contain skippable functions is the parent function. (Its inner // cannot contain skippable functions is the parent function. (Its inner
// functions cannot either; they are implicitly bailed out.) // functions cannot either; they are implicitly bailed out.)
produced_preparsed_scope_data_->parent()->Bailout(); preparsed_scope_data_builder_->parent()->Bailout();
} else { } else {
// Lazy parsing started at the current function; it cannot contain // Lazy parsing started at the current function; it cannot contain
// skippable functions. // skippable functions.
produced_preparsed_scope_data_->Bailout(); preparsed_scope_data_builder_->Bailout();
} }
} }
......
...@@ -22,7 +22,7 @@ namespace internal { ...@@ -22,7 +22,7 @@ namespace internal {
// interface as AstNodeFactory, so ParserBase doesn't need to care which one is // interface as AstNodeFactory, so ParserBase doesn't need to care which one is
// used. // used.
class ProducedPreParsedScopeData; class PreParsedScopeDataBuilder;
class PreParserIdentifier { class PreParserIdentifier {
public: public:
...@@ -958,7 +958,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -958,7 +958,7 @@ class PreParser : public ParserBase<PreParser> {
parsing_module, parsing_on_main_thread), parsing_module, parsing_on_main_thread),
use_counts_(nullptr), use_counts_(nullptr),
track_unresolved_variables_(false), track_unresolved_variables_(false),
produced_preparsed_scope_data_(nullptr) {} preparsed_scope_data_builder_(nullptr) {}
static bool IsPreParser() { return true; } static bool IsPreParser() { return true; }
...@@ -990,13 +990,13 @@ class PreParser : public ParserBase<PreParser> { ...@@ -990,13 +990,13 @@ class PreParser : public ParserBase<PreParser> {
return FLAG_preparser_scope_analysis || is_inner_function; return FLAG_preparser_scope_analysis || is_inner_function;
} }
ProducedPreParsedScopeData* produced_preparsed_scope_data() const { PreParsedScopeDataBuilder* preparsed_scope_data_builder() const {
return produced_preparsed_scope_data_; return preparsed_scope_data_builder_;
} }
void set_produced_preparsed_scope_data( void set_preparsed_scope_data_builder(
ProducedPreParsedScopeData* produced_preparsed_scope_data) { PreParsedScopeDataBuilder* preparsed_scope_data_builder) {
produced_preparsed_scope_data_ = produced_preparsed_scope_data; preparsed_scope_data_builder_ = preparsed_scope_data_builder;
} }
private: private:
...@@ -1769,7 +1769,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1769,7 +1769,7 @@ class PreParser : public ParserBase<PreParser> {
bool track_unresolved_variables_; bool track_unresolved_variables_;
PreParserLogger log_; PreParserLogger log_;
ProducedPreParsedScopeData* produced_preparsed_scope_data_; PreParsedScopeDataBuilder* preparsed_scope_data_builder_;
}; };
PreParserExpression PreParser::SpreadCall(const PreParserExpression& function, PreParserExpression PreParser::SpreadCall(const PreParserExpression& function,
......
...@@ -815,7 +815,7 @@ TEST(ProducingAndConsumingByteData) { ...@@ -815,7 +815,7 @@ TEST(ProducingAndConsumingByteData) {
LocalContext env; LocalContext env;
i::Zone zone(isolate->allocator(), ZONE_NAME); i::Zone zone(isolate->allocator(), ZONE_NAME);
i::ProducedPreParsedScopeData::ByteData bytes(&zone); i::PreParsedScopeDataBuilder::ByteData bytes(&zone);
// Write some data. // Write some data.
bytes.WriteUint32(1983); // This will be overwritten. bytes.WriteUint32(1983); // This will be overwritten.
bytes.WriteUint32(2147483647); bytes.WriteUint32(2147483647);
......
...@@ -24,7 +24,7 @@ class ScopeTestHelper { ...@@ -24,7 +24,7 @@ class ScopeTestHelper {
baseline->AsDeclarationScope()->function_kind() == baseline->AsDeclarationScope()->function_kind() ==
scope->AsDeclarationScope()->function_kind()); scope->AsDeclarationScope()->function_kind());
if (!ProducedPreParsedScopeData::ScopeNeedsData(baseline)) { if (!PreParsedScopeDataBuilder::ScopeNeedsData(baseline)) {
return; return;
} }
......
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