Commit 3e3fc9f2 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Use ScopedPtrList to avoid static prediction of ZonePtrList sizes

This CL introduces a ScopedPtrList that's a view over an underlying ZonePtrList
buffer. Whenever a ScopedPtrList is the top-of-stack list, you can add values
through it, which will add them to the end of the buffer. Once the list is
done, you can copy out the values to a real ZonePtrList. That way you do not
need to guess what the required size of the list is, and you get better cache
locality.

Change-Id: I2d229d73bb25bbb450ae5b6767ab100abad2b3a3
Reviewed-on: https://chromium-review.googlesource.com/c/1296458
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56939}
parent ecbf6296
...@@ -41,7 +41,7 @@ class AstTraversalVisitor : public AstVisitor<Subclass> { ...@@ -41,7 +41,7 @@ class AstTraversalVisitor : public AstVisitor<Subclass> {
// Iteration left-to-right. // Iteration left-to-right.
void VisitDeclarations(Declaration::List* declarations); void VisitDeclarations(Declaration::List* declarations);
void VisitStatements(ZonePtrList<Statement>* statements); void VisitStatements(const ZonePtrList<Statement>* statements);
// Individual nodes // Individual nodes
#define DECLARE_VISIT(type) void Visit##type(type* node); #define DECLARE_VISIT(type) void Visit##type(type* node);
...@@ -112,7 +112,7 @@ void AstTraversalVisitor<Subclass>::VisitDeclarations( ...@@ -112,7 +112,7 @@ void AstTraversalVisitor<Subclass>::VisitDeclarations(
template <class Subclass> template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitStatements( void AstTraversalVisitor<Subclass>::VisitStatements(
ZonePtrList<Statement>* stmts) { const ZonePtrList<Statement>* stmts) {
for (int i = 0; i < stmts->length(); ++i) { for (int i = 0; i < stmts->length(); ++i) {
Statement* stmt = stmts->at(i); Statement* stmt = stmts->at(i);
RECURSE(Visit(stmt)); RECURSE(Visit(stmt));
...@@ -205,7 +205,7 @@ void AstTraversalVisitor<Subclass>::VisitSwitchStatement( ...@@ -205,7 +205,7 @@ void AstTraversalVisitor<Subclass>::VisitSwitchStatement(
Expression* label = clause->label(); Expression* label = clause->label();
RECURSE(Visit(label)); RECURSE(Visit(label));
} }
ZonePtrList<Statement>* stmts = clause->statements(); const ZonePtrList<Statement>* stmts = clause->statements();
RECURSE(VisitStatements(stmts)); RECURSE(VisitStatements(stmts));
} }
} }
...@@ -330,7 +330,7 @@ void AstTraversalVisitor<Subclass>::VisitRegExpLiteral(RegExpLiteral* expr) { ...@@ -330,7 +330,7 @@ void AstTraversalVisitor<Subclass>::VisitRegExpLiteral(RegExpLiteral* expr) {
template <class Subclass> template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitObjectLiteral(ObjectLiteral* expr) { void AstTraversalVisitor<Subclass>::VisitObjectLiteral(ObjectLiteral* expr) {
PROCESS_EXPRESSION(expr); PROCESS_EXPRESSION(expr);
ZonePtrList<ObjectLiteralProperty>* props = expr->properties(); const ZonePtrList<ObjectLiteralProperty>* props = expr->properties();
for (int i = 0; i < props->length(); ++i) { for (int i = 0; i < props->length(); ++i) {
ObjectLiteralProperty* prop = props->at(i); ObjectLiteralProperty* prop = props->at(i);
RECURSE_EXPRESSION(Visit(prop->key())); RECURSE_EXPRESSION(Visit(prop->key()));
...@@ -341,7 +341,7 @@ void AstTraversalVisitor<Subclass>::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -341,7 +341,7 @@ void AstTraversalVisitor<Subclass>::VisitObjectLiteral(ObjectLiteral* expr) {
template <class Subclass> template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitArrayLiteral(ArrayLiteral* expr) { void AstTraversalVisitor<Subclass>::VisitArrayLiteral(ArrayLiteral* expr) {
PROCESS_EXPRESSION(expr); PROCESS_EXPRESSION(expr);
ZonePtrList<Expression>* values = expr->values(); const ZonePtrList<Expression>* values = expr->values();
for (int i = 0; i < values->length(); ++i) { for (int i = 0; i < values->length(); ++i) {
Expression* value = values->at(i); Expression* value = values->at(i);
RECURSE_EXPRESSION(Visit(value)); RECURSE_EXPRESSION(Visit(value));
...@@ -404,7 +404,7 @@ template <class Subclass> ...@@ -404,7 +404,7 @@ template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitCall(Call* expr) { void AstTraversalVisitor<Subclass>::VisitCall(Call* expr) {
PROCESS_EXPRESSION(expr); PROCESS_EXPRESSION(expr);
RECURSE_EXPRESSION(Visit(expr->expression())); RECURSE_EXPRESSION(Visit(expr->expression()));
ZonePtrList<Expression>* args = expr->arguments(); const ZonePtrList<Expression>* args = expr->arguments();
for (int i = 0; i < args->length(); ++i) { for (int i = 0; i < args->length(); ++i) {
Expression* arg = args->at(i); Expression* arg = args->at(i);
RECURSE_EXPRESSION(Visit(arg)); RECURSE_EXPRESSION(Visit(arg));
...@@ -415,7 +415,7 @@ template <class Subclass> ...@@ -415,7 +415,7 @@ template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitCallNew(CallNew* expr) { void AstTraversalVisitor<Subclass>::VisitCallNew(CallNew* expr) {
PROCESS_EXPRESSION(expr); PROCESS_EXPRESSION(expr);
RECURSE_EXPRESSION(Visit(expr->expression())); RECURSE_EXPRESSION(Visit(expr->expression()));
ZonePtrList<Expression>* args = expr->arguments(); const ZonePtrList<Expression>* args = expr->arguments();
for (int i = 0; i < args->length(); ++i) { for (int i = 0; i < args->length(); ++i) {
Expression* arg = args->at(i); Expression* arg = args->at(i);
RECURSE_EXPRESSION(Visit(arg)); RECURSE_EXPRESSION(Visit(arg));
...@@ -425,7 +425,7 @@ void AstTraversalVisitor<Subclass>::VisitCallNew(CallNew* expr) { ...@@ -425,7 +425,7 @@ void AstTraversalVisitor<Subclass>::VisitCallNew(CallNew* expr) {
template <class Subclass> template <class Subclass>
void AstTraversalVisitor<Subclass>::VisitCallRuntime(CallRuntime* expr) { void AstTraversalVisitor<Subclass>::VisitCallRuntime(CallRuntime* expr) {
PROCESS_EXPRESSION(expr); PROCESS_EXPRESSION(expr);
ZonePtrList<Expression>* args = expr->arguments(); const ZonePtrList<Expression>* args = expr->arguments();
for (int i = 0; i < args->length(); ++i) { for (int i = 0; i < args->length(); ++i) {
Expression* arg = args->at(i); Expression* arg = args->at(i);
RECURSE_EXPRESSION(Visit(arg)); RECURSE_EXPRESSION(Visit(arg));
......
...@@ -646,7 +646,7 @@ void ArrayLiteral::BuildBoilerplateDescription(Isolate* isolate) { ...@@ -646,7 +646,7 @@ void ArrayLiteral::BuildBoilerplateDescription(Isolate* isolate) {
bool ArrayLiteral::IsFastCloningSupported() const { bool ArrayLiteral::IsFastCloningSupported() const {
return depth() <= 1 && return depth() <= 1 &&
values()->length() <= values_.length() <=
ConstructorBuiltins::kMaximumClonedShallowArrayElements; ConstructorBuiltins::kMaximumClonedShallowArrayElements;
} }
...@@ -862,8 +862,11 @@ Call::CallType Call::GetCallType() const { ...@@ -862,8 +862,11 @@ Call::CallType Call::GetCallType() const {
return OTHER_CALL; return OTHER_CALL;
} }
CaseClause::CaseClause(Expression* label, ZonePtrList<Statement>* statements) CaseClause::CaseClause(Expression* label,
: label_(label), statements_(statements) {} const ScopedPtrList<Statement>& statements)
: label_(label), statements_(0, nullptr) {
statements.CopyTo(&statements_);
}
bool Literal::IsPropertyName() const { bool Literal::IsPropertyName() const {
if (type() != kString) return false; if (type() != kString) return false;
......
This diff is collapsed.
...@@ -501,14 +501,14 @@ void CallPrinter::VisitRewritableExpression(RewritableExpression* node) { ...@@ -501,14 +501,14 @@ void CallPrinter::VisitRewritableExpression(RewritableExpression* node) {
Find(node->expression()); Find(node->expression());
} }
void CallPrinter::FindStatements(ZonePtrList<Statement>* statements) { void CallPrinter::FindStatements(const ZonePtrList<Statement>* statements) {
if (statements == nullptr) return; if (statements == nullptr) return;
for (int i = 0; i < statements->length(); i++) { for (int i = 0; i < statements->length(); i++) {
Find(statements->at(i)); Find(statements->at(i));
} }
} }
void CallPrinter::FindArguments(ZonePtrList<Expression>* arguments) { void CallPrinter::FindArguments(const ZonePtrList<Expression>* arguments) {
if (found_) return; if (found_) return;
for (int i = 0; i < arguments->length(); i++) { for (int i = 0; i < arguments->length(); i++) {
Find(arguments->at(i)); Find(arguments->at(i));
...@@ -813,13 +813,13 @@ void AstPrinter::PrintParameters(DeclarationScope* scope) { ...@@ -813,13 +813,13 @@ void AstPrinter::PrintParameters(DeclarationScope* scope) {
} }
} }
void AstPrinter::PrintStatements(ZonePtrList<Statement>* statements) { void AstPrinter::PrintStatements(const ZonePtrList<Statement>* statements) {
for (int i = 0; i < statements->length(); i++) { for (int i = 0; i < statements->length(); i++) {
Visit(statements->at(i)); Visit(statements->at(i));
} }
} }
void AstPrinter::PrintArguments(ZonePtrList<Expression>* arguments) { void AstPrinter::PrintArguments(const ZonePtrList<Expression>* arguments) {
for (int i = 0; i < arguments->length(); i++) { for (int i = 0; i < arguments->length(); i++) {
Visit(arguments->at(i)); Visit(arguments->at(i));
} }
...@@ -1050,7 +1050,7 @@ void AstPrinter::VisitInitializeClassFieldsStatement( ...@@ -1050,7 +1050,7 @@ void AstPrinter::VisitInitializeClassFieldsStatement(
} }
void AstPrinter::PrintClassProperties( void AstPrinter::PrintClassProperties(
ZonePtrList<ClassLiteral::Property>* properties) { const ZonePtrList<ClassLiteral::Property>* properties) {
for (int i = 0; i < properties->length(); i++) { for (int i = 0; i < properties->length(); i++) {
ClassLiteral::Property* property = properties->at(i); ClassLiteral::Property* property = properties->at(i);
const char* prop_kind = nullptr; const char* prop_kind = nullptr;
...@@ -1126,7 +1126,7 @@ void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { ...@@ -1126,7 +1126,7 @@ void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
} }
void AstPrinter::PrintObjectProperties( void AstPrinter::PrintObjectProperties(
ZonePtrList<ObjectLiteral::Property>* properties) { const ZonePtrList<ObjectLiteral::Property>* properties) {
for (int i = 0; i < properties->length(); i++) { for (int i = 0; i < properties->length(); i++) {
ObjectLiteral::Property* property = properties->at(i); ObjectLiteral::Property* property = properties->at(i);
const char* prop_kind = nullptr; const char* prop_kind = nullptr;
......
...@@ -59,8 +59,8 @@ class CallPrinter final : public AstVisitor<CallPrinter> { ...@@ -59,8 +59,8 @@ class CallPrinter final : public AstVisitor<CallPrinter> {
protected: protected:
void PrintLiteral(Handle<Object> value, bool quote); void PrintLiteral(Handle<Object> value, bool quote);
void PrintLiteral(const AstRawString* value, bool quote); void PrintLiteral(const AstRawString* value, bool quote);
void FindStatements(ZonePtrList<Statement>* statements); void FindStatements(const ZonePtrList<Statement>* statements);
void FindArguments(ZonePtrList<Expression>* arguments); void FindArguments(const ZonePtrList<Expression>* arguments);
}; };
...@@ -98,10 +98,10 @@ class AstPrinter final : public AstVisitor<AstPrinter> { ...@@ -98,10 +98,10 @@ class AstPrinter final : public AstVisitor<AstPrinter> {
void PrintIndented(const char* txt); void PrintIndented(const char* txt);
void PrintIndentedVisit(const char* s, AstNode* node); void PrintIndentedVisit(const char* s, AstNode* node);
void PrintStatements(ZonePtrList<Statement>* statements); void PrintStatements(const ZonePtrList<Statement>* statements);
void PrintDeclarations(Declaration::List* declarations); void PrintDeclarations(Declaration::List* declarations);
void PrintParameters(DeclarationScope* scope); void PrintParameters(DeclarationScope* scope);
void PrintArguments(ZonePtrList<Expression>* arguments); void PrintArguments(const ZonePtrList<Expression>* arguments);
void PrintCaseClause(CaseClause* clause); void PrintCaseClause(CaseClause* clause);
void PrintLiteralIndented(const char* info, Literal* literal, bool quote); void PrintLiteralIndented(const char* info, Literal* literal, bool quote);
void PrintLiteralIndented(const char* info, const AstRawString* value, void PrintLiteralIndented(const char* info, const AstRawString* value,
...@@ -112,8 +112,10 @@ class AstPrinter final : public AstVisitor<AstPrinter> { ...@@ -112,8 +112,10 @@ class AstPrinter final : public AstVisitor<AstPrinter> {
const AstRawString* value); const AstRawString* value);
void PrintLabelsIndented(ZonePtrList<const AstRawString>* labels, void PrintLabelsIndented(ZonePtrList<const AstRawString>* labels,
const char* prefix = ""); const char* prefix = "");
void PrintObjectProperties(ZonePtrList<ObjectLiteral::Property>* properties); void PrintObjectProperties(
void PrintClassProperties(ZonePtrList<ClassLiteral::Property>* properties); const ZonePtrList<ObjectLiteral::Property>* properties);
void PrintClassProperties(
const ZonePtrList<ClassLiteral::Property>* properties);
void inc_indent() { indent_++; } void inc_indent() { indent_++; }
void dec_indent() { indent_--; } void dec_indent() { indent_--; }
......
...@@ -1327,7 +1327,8 @@ void BytecodeGenerator::VisitDeclarations(Declaration::List* declarations) { ...@@ -1327,7 +1327,8 @@ void BytecodeGenerator::VisitDeclarations(Declaration::List* declarations) {
globals_builder_ = new (zone()) GlobalDeclarationsBuilder(zone()); globals_builder_ = new (zone()) GlobalDeclarationsBuilder(zone());
} }
void BytecodeGenerator::VisitStatements(ZonePtrList<Statement>* statements) { void BytecodeGenerator::VisitStatements(
const ZonePtrList<Statement>* statements) {
for (int i = 0; i < statements->length(); i++) { for (int i = 0; i < statements->length(); i++) {
// Allocate an outer register allocations scope for the statement. // Allocate an outer register allocations scope for the statement.
RegisterAllocationScope allocation_scope(this); RegisterAllocationScope allocation_scope(this);
...@@ -2450,7 +2451,7 @@ void BytecodeGenerator::BuildArrayLiteralSpread(Spread* spread, Register array, ...@@ -2450,7 +2451,7 @@ void BytecodeGenerator::BuildArrayLiteralSpread(Spread* spread, Register array,
} }
void BytecodeGenerator::BuildCreateArrayLiteral( void BytecodeGenerator::BuildCreateArrayLiteral(
ZonePtrList<Expression>* elements, ArrayLiteral* expr) { const ZonePtrList<Expression>* elements, ArrayLiteral* expr) {
RegisterAllocationScope register_scope(this); RegisterAllocationScope register_scope(this);
Register index = register_allocator()->NewRegister(); Register index = register_allocator()->NewRegister();
Register array = register_allocator()->NewRegister(); Register array = register_allocator()->NewRegister();
...@@ -3578,7 +3579,7 @@ void BytecodeGenerator::VisitResolvedProperty(ResolvedProperty* expr) { ...@@ -3578,7 +3579,7 @@ void BytecodeGenerator::VisitResolvedProperty(ResolvedProperty* expr) {
UNREACHABLE(); UNREACHABLE();
} }
void BytecodeGenerator::VisitArguments(ZonePtrList<Expression>* args, void BytecodeGenerator::VisitArguments(const ZonePtrList<Expression>* args,
RegisterList* arg_regs) { RegisterList* arg_regs) {
// Visit arguments. // Visit arguments.
for (int i = 0; i < static_cast<int>(args->length()); i++) { for (int i = 0; i < static_cast<int>(args->length()); i++) {
...@@ -3755,7 +3756,7 @@ void BytecodeGenerator::VisitCall(Call* expr) { ...@@ -3755,7 +3756,7 @@ void BytecodeGenerator::VisitCall(Call* expr) {
void BytecodeGenerator::VisitCallSuper(Call* expr) { void BytecodeGenerator::VisitCallSuper(Call* expr) {
RegisterAllocationScope register_scope(this); RegisterAllocationScope register_scope(this);
SuperCallReference* super = expr->expression()->AsSuperCallReference(); SuperCallReference* super = expr->expression()->AsSuperCallReference();
ZonePtrList<Expression>* args = expr->arguments(); const ZonePtrList<Expression>* args = expr->arguments();
int first_spread_index = 0; int first_spread_index = 0;
for (; first_spread_index < args->length(); first_spread_index++) { for (; first_spread_index < args->length(); first_spread_index++) {
......
...@@ -44,7 +44,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { ...@@ -44,7 +44,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
// Visiting function for declarations list and statements are overridden. // Visiting function for declarations list and statements are overridden.
void VisitDeclarations(Declaration::List* declarations); void VisitDeclarations(Declaration::List* declarations);
void VisitStatements(ZonePtrList<Statement>* statments); void VisitStatements(const ZonePtrList<Statement>* statments);
private: private:
class ContextScope; class ContextScope;
...@@ -101,7 +101,8 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { ...@@ -101,7 +101,8 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
// Visit the arguments expressions in |args| and store them in |args_regs|, // Visit the arguments expressions in |args| and store them in |args_regs|,
// growing |args_regs| for each argument visited. // growing |args_regs| for each argument visited.
void VisitArguments(ZonePtrList<Expression>* args, RegisterList* arg_regs); void VisitArguments(const ZonePtrList<Expression>* args,
RegisterList* arg_regs);
// Visit a keyed super property load. The optional // Visit a keyed super property load. The optional
// |opt_receiver_out| register will have the receiver stored to it // |opt_receiver_out| register will have the receiver stored to it
...@@ -186,7 +187,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { ...@@ -186,7 +187,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
// Create Array literals. |expr| can be nullptr, but if provided, // Create Array literals. |expr| can be nullptr, but if provided,
// a boilerplate will be used to create an initial array for elements // a boilerplate will be used to create an initial array for elements
// before the first spread. // before the first spread.
void BuildCreateArrayLiteral(ZonePtrList<Expression>* elements, void BuildCreateArrayLiteral(const ZonePtrList<Expression>* elements,
ArrayLiteral* expr); ArrayLiteral* expr);
void BuildCreateObjectLiteral(Register literal, uint8_t flags, size_t entry); void BuildCreateObjectLiteral(Register literal, uint8_t flags, size_t entry);
void AllocateTopLevelRegisters(); void AllocateTopLevelRegisters();
......
This diff is collapsed.
This diff is collapsed.
...@@ -137,6 +137,10 @@ struct ParserTypes<Parser> { ...@@ -137,6 +137,10 @@ struct ParserTypes<Parser> {
typedef ParserFormalParameters FormalParameters; typedef ParserFormalParameters FormalParameters;
typedef v8::internal::Statement* Statement; typedef v8::internal::Statement* Statement;
typedef ZonePtrList<v8::internal::Statement>* StatementList; typedef ZonePtrList<v8::internal::Statement>* StatementList;
typedef ScopedPtrList<v8::internal::Statement> ScopedStatementList;
typedef ScopedPtrList<v8::internal::Expression> ScopedExpressionList;
typedef ScopedPtrList<v8::internal::ObjectLiteralProperty>
ScopedObjectPropertyList;
typedef v8::internal::Block* Block; typedef v8::internal::Block* Block;
typedef v8::internal::BreakableStatement* BreakableStatement; typedef v8::internal::BreakableStatement* BreakableStatement;
typedef v8::internal::ForStatement* ForStatement; typedef v8::internal::ForStatement* ForStatement;
...@@ -533,11 +537,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -533,11 +537,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
Expression* tag); Expression* tag);
ArrayLiteral* ArrayLiteralFromListWithSpread(ZonePtrList<Expression>* list); ArrayLiteral* ArrayLiteralFromListWithSpread(
Expression* SpreadCall(Expression* function, ZonePtrList<Expression>* args, const ScopedPtrList<Expression>& list);
int pos, Call::PossiblyEval is_possibly_eval); Expression* SpreadCall(Expression* function,
Expression* SpreadCallNew(Expression* function, ZonePtrList<Expression>* args, const ScopedPtrList<Expression>& args, int pos,
int pos); Call::PossiblyEval is_possibly_eval);
Expression* SpreadCallNew(Expression* function,
const ScopedPtrList<Expression>& args, int pos);
Expression* RewriteSuperCall(Expression* call_expression); Expression* RewriteSuperCall(Expression* call_expression);
void SetLanguageMode(Scope* scope, LanguageMode mode); void SetLanguageMode(Scope* scope, LanguageMode mode);
...@@ -736,9 +742,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -736,9 +742,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// A shortcut for performing a ToString operation // A shortcut for performing a ToString operation
V8_INLINE Expression* ToString(Expression* expr) { V8_INLINE Expression* ToString(Expression* expr) {
if (expr->IsStringLiteral()) return expr; if (expr->IsStringLiteral()) return expr;
ZonePtrList<Expression>* args = ScopedPtrList<Expression> args(zone(), expression_buffer());
new (zone()) ZonePtrList<Expression>(1, zone()); args.Add(expr);
args->Add(expr, zone());
return factory()->NewCallRuntime(Runtime::kInlineToString, args, return factory()->NewCallRuntime(Runtime::kInlineToString, args,
expr->position()); expr->position());
} }
...@@ -898,8 +903,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -898,8 +903,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
} }
V8_INLINE Expression* NewV8Intrinsic(const AstRawString* name, V8_INLINE Expression* NewV8Intrinsic(const AstRawString* name,
ZonePtrList<Expression>* args, int pos, const ScopedPtrList<Expression>& args,
bool* ok); int pos, bool* ok);
V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) { V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) {
return factory()->NewExpressionStatement( return factory()->NewExpressionStatement(
...@@ -953,7 +958,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -953,7 +958,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
const Scanner::Location& params_loc, const Scanner::Location& params_loc,
bool* ok); bool* ok);
Expression* ExpressionListToExpression(ZonePtrList<Expression>* args); Expression* ExpressionListToExpression(const ScopedPtrList<Expression>& args);
void SetFunctionNameFromPropertyName(LiteralProperty* property, void SetFunctionNameFromPropertyName(LiteralProperty* property,
const AstRawString* name, const AstRawString* name,
......
...@@ -110,6 +110,11 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> { ...@@ -110,6 +110,11 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> {
AstValueFactory* ast_value_factory() const { AstValueFactory* ast_value_factory() const {
return parser_->ast_value_factory(); return parser_->ast_value_factory();
} }
ZonePtrList<Expression>* expression_buffer() {
return parser_->expression_buffer();
}
Zone* zone() const { return parser_->zone(); } Zone* zone() const { return parser_->zone(); }
Scope* scope() const { return scope_; } Scope* scope() const { return scope_; }
...@@ -336,15 +341,9 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, ...@@ -336,15 +341,9 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
Variable** temp_var) { Variable** temp_var) {
auto temp = *temp_var = CreateTempVar(current_value_); auto temp = *temp_var = CreateTempVar(current_value_);
ZonePtrList<Expression>* rest_runtime_callargs = nullptr; ScopedPtrList<Expression> rest_runtime_callargs(zone(), expression_buffer());
if (pattern->has_rest_property()) { if (pattern->has_rest_property()) {
// non_rest_properties_count = pattern->properties()->length - 1; rest_runtime_callargs.Add(factory()->NewVariableProxy(temp));
// args_length = 1 + non_rest_properties_count because we need to
// pass temp as well to the runtime function.
int args_length = pattern->properties()->length();
rest_runtime_callargs =
new (zone()) ZonePtrList<Expression>(args_length, zone());
rest_runtime_callargs->Add(factory()->NewVariableProxy(temp), zone());
} }
block_->statements()->Add(parser_->BuildAssertIsCoercible(temp, pattern), block_->statements()->Add(parser_->BuildAssertIsCoercible(temp, pattern),
...@@ -378,8 +377,8 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, ...@@ -378,8 +377,8 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
if (property->is_computed_name()) { if (property->is_computed_name()) {
DCHECK(!key->IsPropertyName() || !key->IsNumberLiteral()); DCHECK(!key->IsPropertyName() || !key->IsNumberLiteral());
auto args = new (zone()) ZonePtrList<Expression>(1, zone()); ScopedPtrList<Expression> args(zone(), expression_buffer());
args->Add(key, zone()); args.Add(key);
auto to_name_key = CreateTempVar(factory()->NewCallRuntime( auto to_name_key = CreateTempVar(factory()->NewCallRuntime(
Runtime::kToName, args, kNoSourcePosition)); Runtime::kToName, args, kNoSourcePosition));
key = factory()->NewVariableProxy(to_name_key); key = factory()->NewVariableProxy(to_name_key);
...@@ -388,8 +387,7 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, ...@@ -388,8 +387,7 @@ void PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
DCHECK(key->IsPropertyName() || key->IsNumberLiteral()); DCHECK(key->IsPropertyName() || key->IsNumberLiteral());
} }
DCHECK_NOT_NULL(rest_runtime_callargs); rest_runtime_callargs.Add(excluded_property);
rest_runtime_callargs->Add(excluded_property, zone());
} }
value = factory()->NewProperty(factory()->NewVariableProxy(temp), key, value = factory()->NewProperty(factory()->NewVariableProxy(temp), key,
...@@ -557,7 +555,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node, ...@@ -557,7 +555,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
// let array = []; // let array = [];
Variable* array; Variable* array;
{ {
auto empty_exprs = new (zone()) ZonePtrList<Expression>(0, zone()); ScopedPtrList<Expression> empty_exprs(zone(), expression_buffer());
array = CreateTempVar( array = CreateTempVar(
factory()->NewArrayLiteral(empty_exprs, kNoSourcePosition)); factory()->NewArrayLiteral(empty_exprs, kNoSourcePosition));
} }
......
...@@ -414,61 +414,67 @@ class PreParserExpression { ...@@ -414,61 +414,67 @@ class PreParserExpression {
friend class PreParser; friend class PreParser;
friend class PreParserFactory; friend class PreParserFactory;
friend class PreParserExpressionList; friend class PreParserScopedExpressionList;
}; };
// The pre-parser doesn't need to build lists of expressions, identifiers, or // The pre-parser doesn't need to build lists of expressions, identifiers, or
// the like. If the PreParser is used in variable tracking mode, it needs to // the like. If the PreParser is used in variable tracking mode, it needs to
// build lists of variables though. // build lists of variables though.
class PreParserExpressionList { class PreParserExpressionList {};
class PreParserStatement;
class PreParserStatementList {
public:
PreParserStatementList() : PreParserStatementList(false) {}
PreParserStatementList* operator->() { return this; }
void Add(const PreParserStatement& element, Zone* zone) {}
static PreParserStatementList Null() { return PreParserStatementList(true); }
bool IsNull() const { return is_null_; }
private:
explicit PreParserStatementList(bool is_null) : is_null_(is_null) {}
bool is_null_;
};
class PreParserScopedStatementList {
public:
PreParserScopedStatementList(Zone* zone,
const PreParserStatementList& buffer) {}
void Add(const PreParserStatement& element) {}
};
class PreParserScopedExpressionList {
using VariableZoneThreadedListType = using VariableZoneThreadedListType =
ZoneThreadedList<VariableProxy, VariableProxy::PreParserNext>; ZoneThreadedList<VariableProxy, VariableProxy::PreParserNext>;
public: public:
// These functions make list->Add(some_expression) work (and do nothing). PreParserScopedExpressionList(Zone* zone,
PreParserExpressionList() : PreParserExpressionList(0) {} const PreParserExpressionList& buffer)
PreParserExpressionList* operator->() { return this; } : length_(0), variables_(nullptr) {}
void Add(const PreParserExpression& expression, Zone* zone) {
int length() const { return length_; }
void Add(const PreParserExpression& expression) {
if (expression.variables_ != nullptr) { if (expression.variables_ != nullptr) {
DCHECK_NOT_NULL(zone);
if (variables_ == nullptr) { if (variables_ == nullptr) {
variables_ = new (zone) VariableZoneThreadedListType(); variables_ = expression.variables_;
} else {
variables_->Append(std::move(*expression.variables_));
} }
variables_->Append(std::move(*expression.variables_));
} }
++length_; ++length_;
} }
int length() const { return length_; }
static PreParserExpressionList Null() { return PreParserExpressionList(-1); }
bool IsNull() const { return length_ == -1; }
void Set(int index, const PreParserExpression& element) {}
private: private:
explicit PreParserExpressionList(int n) : length_(n), variables_(nullptr) {}
int length_; int length_;
VariableZoneThreadedListType* variables_; VariableZoneThreadedListType* variables_;
friend class PreParser; friend class PreParser;
friend class PreParserFactory; friend class PreParserFactory;
}; };
class PreParserStatement;
class PreParserStatementList {
public:
PreParserStatementList() : PreParserStatementList(false) {}
PreParserStatementList* operator->() { return this; }
void Add(const PreParserStatement& element, Zone* zone) {}
static PreParserStatementList Null() { return PreParserStatementList(true); }
bool IsNull() const { return is_null_; }
private:
explicit PreParserStatementList(bool is_null) : is_null_(is_null) {}
bool is_null_;
};
class PreParserStatement { class PreParserStatement {
public: public:
static PreParserStatement Default() { static PreParserStatement Default() {
...@@ -589,8 +595,9 @@ class PreParserFactory { ...@@ -589,8 +595,9 @@ class PreParserFactory {
int js_flags, int pos) { int js_flags, int pos) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
PreParserExpression NewArrayLiteral(const PreParserExpressionList& values, PreParserExpression NewArrayLiteral(
int first_spread_index, int pos) { const PreParserScopedExpressionList& values, int first_spread_index,
int pos) {
return PreParserExpression::ArrayLiteral(values.variables_); return PreParserExpression::ArrayLiteral(values.variables_);
} }
PreParserExpression NewClassLiteralProperty(const PreParserExpression& key, PreParserExpression NewClassLiteralProperty(const PreParserExpression& key,
...@@ -613,8 +620,8 @@ class PreParserFactory { ...@@ -613,8 +620,8 @@ class PreParserFactory {
return PreParserExpression::Default(value.variables_); return PreParserExpression::Default(value.variables_);
} }
PreParserExpression NewObjectLiteral( PreParserExpression NewObjectLiteral(
const PreParserExpressionList& properties, int boilerplate_properties, const PreParserScopedExpressionList& properties,
int pos, bool has_rest_property) { int boilerplate_properties, int pos, bool has_rest_property) {
return PreParserExpression::ObjectLiteral(properties.variables_); return PreParserExpression::ObjectLiteral(properties.variables_);
} }
PreParserExpression NewVariableProxy(void* variable) { PreParserExpression NewVariableProxy(void* variable) {
...@@ -686,8 +693,9 @@ class PreParserFactory { ...@@ -686,8 +693,9 @@ class PreParserFactory {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
PreParserExpression NewCall( PreParserExpression NewCall(
PreParserExpression expression, const PreParserExpressionList& arguments, PreParserExpression expression,
int pos, Call::PossiblyEval possibly_eval = Call::NOT_EVAL) { const PreParserScopedExpressionList& arguments, int pos,
Call::PossiblyEval possibly_eval = Call::NOT_EVAL) {
if (possibly_eval == Call::IS_POSSIBLY_EVAL) { if (possibly_eval == Call::IS_POSSIBLY_EVAL) {
DCHECK(expression.IsIdentifier() && expression.AsIdentifier().IsEval()); DCHECK(expression.IsIdentifier() && expression.AsIdentifier().IsEval());
return PreParserExpression::CallEval(); return PreParserExpression::CallEval();
...@@ -695,12 +703,12 @@ class PreParserFactory { ...@@ -695,12 +703,12 @@ class PreParserFactory {
return PreParserExpression::Call(); return PreParserExpression::Call();
} }
PreParserExpression NewTaggedTemplate( PreParserExpression NewTaggedTemplate(
PreParserExpression expression, const PreParserExpressionList& arguments, PreParserExpression expression,
int pos) { const PreParserScopedExpressionList& arguments, int pos) {
return PreParserExpression::CallTaggedTemplate(); return PreParserExpression::CallTaggedTemplate();
} }
PreParserExpression NewCallNew(const PreParserExpression& expression, PreParserExpression NewCallNew(const PreParserExpression& expression,
const PreParserExpressionList& arguments, const PreParserScopedExpressionList& arguments,
int pos) { int pos) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
...@@ -800,8 +808,9 @@ class PreParserFactory { ...@@ -800,8 +808,9 @@ class PreParserFactory {
return PreParserStatement::Default(); return PreParserStatement::Default();
} }
PreParserStatement NewCaseClause(const PreParserExpression& label, PreParserStatement NewCaseClause(
PreParserStatementList statements) { const PreParserExpression& label,
const PreParserScopedStatementList& statements) {
return PreParserStatement::Default(); return PreParserStatement::Default();
} }
...@@ -922,6 +931,9 @@ struct ParserTypes<PreParser> { ...@@ -922,6 +931,9 @@ struct ParserTypes<PreParser> {
typedef PreParserFormalParameters FormalParameters; typedef PreParserFormalParameters FormalParameters;
typedef PreParserStatement Statement; typedef PreParserStatement Statement;
typedef PreParserStatementList StatementList; typedef PreParserStatementList StatementList;
typedef PreParserScopedStatementList ScopedStatementList;
typedef PreParserScopedExpressionList ScopedExpressionList;
typedef PreParserScopedExpressionList ScopedObjectPropertyList;
typedef PreParserStatement Block; typedef PreParserStatement Block;
typedef PreParserStatement BreakableStatement; typedef PreParserStatement BreakableStatement;
typedef PreParserStatement IterationStatement; typedef PreParserStatement IterationStatement;
...@@ -1082,13 +1094,13 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1082,13 +1094,13 @@ class PreParser : public ParserBase<PreParser> {
} }
V8_INLINE void SetAsmModule() {} V8_INLINE void SetAsmModule() {}
V8_INLINE PreParserExpression SpreadCall(const PreParserExpression& function, V8_INLINE PreParserExpression
const PreParserExpressionList& args, SpreadCall(const PreParserExpression& function,
int pos, const PreParserScopedExpressionList& args, int pos,
Call::PossiblyEval possibly_eval); Call::PossiblyEval possibly_eval);
V8_INLINE PreParserExpression V8_INLINE PreParserExpression
SpreadCallNew(const PreParserExpression& function, SpreadCallNew(const PreParserExpression& function,
const PreParserExpressionList& args, int pos); const PreParserScopedExpressionList& args, int pos);
V8_INLINE void RewriteDestructuringAssignments() {} V8_INLINE void RewriteDestructuringAssignments() {}
...@@ -1553,10 +1565,6 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1553,10 +1565,6 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE static PreParserExpression NullLiteralProperty() { V8_INLINE static PreParserExpression NullLiteralProperty() {
return PreParserExpression::Null(); return PreParserExpression::Null();
} }
V8_INLINE static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList::Null();
}
V8_INLINE static PreParserStatementList NullStatementList() { V8_INLINE static PreParserStatementList NullStatementList() {
return PreParserStatementList::Null(); return PreParserStatementList::Null();
} }
...@@ -1651,9 +1659,9 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1651,9 +1659,9 @@ class PreParser : public ParserBase<PreParser> {
return PreParserStatementList(); return PreParserStatementList();
} }
V8_INLINE PreParserExpression V8_INLINE PreParserExpression NewV8Intrinsic(
NewV8Intrinsic(const PreParserIdentifier& name, const PreParserIdentifier& name,
const PreParserExpressionList& arguments, int pos, bool* ok) { const PreParserScopedExpressionList& arguments, int pos, bool* ok) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
...@@ -1714,7 +1722,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1714,7 +1722,7 @@ class PreParser : public ParserBase<PreParser> {
} }
V8_INLINE PreParserExpression V8_INLINE PreParserExpression
ExpressionListToExpression(const PreParserExpressionList& args) { ExpressionListToExpression(const PreParserScopedExpressionList& args) {
return PreParserExpression::Default(args.variables_); return PreParserExpression::Default(args.variables_);
} }
...@@ -1752,16 +1760,16 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1752,16 +1760,16 @@ class PreParser : public ParserBase<PreParser> {
PreParsedScopeDataBuilder* preparsed_scope_data_builder_; PreParsedScopeDataBuilder* preparsed_scope_data_builder_;
}; };
PreParserExpression PreParser::SpreadCall(const PreParserExpression& function, PreParserExpression PreParser::SpreadCall(
const PreParserExpressionList& args, const PreParserExpression& function,
int pos, const PreParserScopedExpressionList& args, int pos,
Call::PossiblyEval possibly_eval) { Call::PossiblyEval possibly_eval) {
return factory()->NewCall(function, args, pos, possibly_eval); return factory()->NewCall(function, args, pos, possibly_eval);
} }
PreParserExpression PreParser::SpreadCallNew( PreParserExpression PreParser::SpreadCallNew(
const PreParserExpression& function, const PreParserExpressionList& args, const PreParserExpression& function,
int pos) { const PreParserScopedExpressionList& args, int pos) {
return factory()->NewCallNew(function, args, pos); return factory()->NewCallNew(function, args, pos);
} }
......
...@@ -225,6 +225,9 @@ class ZoneList final { ...@@ -225,6 +225,9 @@ class ZoneList final {
V8_INLINE int capacity() const { return capacity_; } V8_INLINE int capacity() const { return capacity_; }
Vector<T> ToVector() const { return Vector<T>(data_, length_); } Vector<T> ToVector() const { return Vector<T>(data_, length_); }
Vector<T> ToVector(int start, int length) const {
return Vector<T>(data_ + start, Min(length_ - start, length));
}
Vector<const T> ToConstVector() const { Vector<const T> ToConstVector() const {
return Vector<const T>(data_, length_); return Vector<const T>(data_, length_);
...@@ -318,6 +321,47 @@ class ZoneList final { ...@@ -318,6 +321,47 @@ class ZoneList final {
template <typename T> template <typename T>
using ZonePtrList = ZoneList<T*>; using ZonePtrList = ZoneList<T*>;
template <typename T>
class ScopedPtrList final {
public:
ScopedPtrList(Zone* zone, ZonePtrList<T>* buffer)
: zone_(zone),
buffer_(buffer),
start_(buffer->length()),
end_(buffer->length()) {}
~ScopedPtrList() {
DCHECK_EQ(buffer_->length(), end_);
buffer_->Rewind(start_);
}
int length() const { return end_ - start_; }
T* at(int i) const { return buffer_->at(i + start_); }
void CopyTo(ZonePtrList<T>* target) const {
target->Initialize(length(), zone_);
target->AddAll(buffer_->ToVector(start_, length()), zone_);
}
void Add(T* value) {
DCHECK_EQ(buffer_->length(), end_);
buffer_->Add(value, zone_);
++end_;
}
void AddAll(const ZonePtrList<T>& list) {
DCHECK_EQ(buffer_->length(), end_);
buffer_->AddAll(list, zone_);
end_ += list.length();
}
private:
Zone* zone_;
ZonePtrList<T>* buffer_;
int start_;
int end_;
};
// ZoneThreadedList is a special variant of the ThreadedList that can be put // ZoneThreadedList is a special variant of the ThreadedList that can be put
// into a Zone. // into a Zone.
template <typename T, typename TLTraits = base::ThreadedListTraits<T>> template <typename T, typename TLTraits = base::ThreadedListTraits<T>>
......
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