From 23ea7ee64b98218e06cf3217372ade7b401250f8 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sun, 10 Mar 2019 19:48:02 -0700 Subject: [PATCH] deps: v8, backport coverage fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pulls in patches from V8 (52e2b5, 512175, aac2f8, 9365d09, 2d08967) which address a variety of coverage bugs, bringing Node v10 coverage to parity with Node v11. Original commit message: [coverage] Extend SourceRangeAstVisitor for throw statements The SourceRangeAstVisitor has custom logic for blocks ending with a statement that has a continuation range. In these cases, the trailing continuation is removed which makes the reported coverage ranges a bit nicer. throw Error('foo') consists of an ExpressionStatement, with a Throw expression stored within the statement. The source range itself is stored with the Throw, not the statement. We now properly extract the correct AST node for trailing throw statements. R=jgruber@chromium.org, neis@chromium.org, yangguo@chromium.org Bug: v8:8691 Change-Id: Ibcbab79fbe54719a8993045040349c863b139011 Reviewed-on: https://chromium-review.googlesource.com/c/1480632 Commit-Queue: Georg Neis Reviewed-by: Georg Neis Reviewed-by: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#59936} Refs: v8/v8@2d08967 Original commit message: [coverage] Rework continuation counter handling This changes a few bits about how continuation counters are handled. It introduces a new mechanism that allows removal of a continuation range after it has been created. If coverage is enabled, we run a first post-processing pass on the AST immediately after parsing, which removes problematic continuation ranges in two situations: 1. nested continuation counters - only the outermost stays alive. 2. trailing continuation counters within a block-like structure are removed if the containing structure itself has a continuation. R=bmeurer@chromium.org, jgruber@chromium.org, yangguo@chromium.org Bug: v8:8381, v8:8539 Change-Id: I6bcaea5060d8c481d7bae099f6db9f993cc30ee3 Reviewed-on: https://chromium-review.googlesource.com/c/1339119 Reviewed-by: Yang Guo Reviewed-by: Leszek Swirski Reviewed-by: Georg Neis Commit-Queue: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#58443} Refs: v8/v8@9365d09 Original commit message: [coverage] Filter out singleton ranges that alias full ranges Block coverage is based on a system of ranges that can either have both a start and end position, or only a start position (so-called singleton ranges). When formatting coverage information, singletons are expanded until the end of the immediate full parent range. E.g. in: {0, 10} // Full range. {5, -1} // Singleton range. the singleton range is expanded to {5, 10}. Singletons are produced mostly for continuation counters that track whether we execute past a specific language construct. Unfortunately, continuation counters can turn up in spots that confuse our post-processing. For example: if (true) { ... block1 ... } else { ... block2 ... } If block1 produces a continuation counter, it could end up with the same start position as the else-branch counter. Since we merge identical blocks, the else-branch could incorrectly end up with an execution count of one. We need to avoid merging such cases. A full range should always take precedence over a singleton range; a singleton range should never expand to completely fill a full range. An additional post-processing pass ensures this. Bug: v8:8237 Change-Id: Idb3ec7b2feddc0585313810b9c8be1e9f4ec64bf Reviewed-on: https://chromium-review.googlesource.com/c/1273095 Reviewed-by: Georg Neis Reviewed-by: Yang Guo Commit-Queue: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#56531} Refs: v8/v8@aac2f8c Original commit message: [ast] Introduce ZonePtrList typedef for ZoneList. This is a preliminary step before changing the way we store zone pointers in the zones. Bug: v8:7903, v8:7754 Change-Id: I1e1af1823766c888ee0f8fe190f205f5b7e21973 Reviewed-on: https://chromium-review.googlesource.com/1118887 Reviewed-by: Ross McIlroy Reviewed-by: Marja Hölttä Reviewed-by: Camillo Bruni Commit-Queue: Igor Sheludko Cr-Commit-Position: refs/heads/master@{#54193} Refs: v8/v8@512175a Original commit message: [explicit isolates] Replace every Handle(T*) in parsing/ Replace all but one Handle(T*) calls with ones that explicitly pass in an Isolate. Requires plumbing Isolate* through several Parser functions which previously avoided it because of worries about accessing the heap off the main thread. In all off-main-thread cases, isolate will be nullptr and every such function asserts with: DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr); Also deletes unused function ParseInfo::ReopenHandlesInNewHandleScope. Bug: v8:7786 Change-Id: I3dd9c49dcde49fdbcb684ba73f47a30d00fc495e Reviewed-on: https://chromium-review.googlesource.com/1087272 Commit-Queue: Dan Elphick Reviewed-by: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#53820} Refs: v8/v8@52e2b5a PR-URL: https://github.com/nodejs/node/pull/26579 Reviewed-By: Rich Trott Reviewed-By: Ujjwal Sharma Reviewed-By: Shelley Vohr Reviewed-By: Guy Bedford Reviewed-By: Beth Griggs --- common.gypi | 2 +- deps/v8/AUTHORS | 2 +- deps/v8/BUILD.gn | 2 + deps/v8/gypfiles/v8.gyp | 2 + deps/v8/src/ast/ast-source-ranges.h | 101 ++++++- deps/v8/src/ast/ast-traversal-visitor.h | 22 +- deps/v8/src/ast/ast.cc | 4 +- deps/v8/src/ast/ast.h | 202 +++++++------- deps/v8/src/ast/prettyprinter.cc | 21 +- deps/v8/src/ast/prettyprinter.h | 16 +- deps/v8/src/ast/scopes.cc | 2 +- deps/v8/src/ast/scopes.h | 4 +- deps/v8/src/ast/source-range-ast-visitor.cc | 79 ++++++ deps/v8/src/ast/source-range-ast-visitor.h | 49 ++++ deps/v8/src/debug/debug-coverage.cc | 59 +++-- deps/v8/src/interpreter/bytecode-generator.cc | 19 +- deps/v8/src/interpreter/bytecode-generator.h | 6 +- .../src/interpreter/control-flow-builders.cc | 2 +- .../src/interpreter/control-flow-builders.h | 7 - .../parsing/expression-scope-reparenter.cc | 2 +- deps/v8/src/parsing/parse-info.cc | 2 +- deps/v8/src/parsing/parse-info.h | 10 - deps/v8/src/parsing/parser-base.h | 98 +++---- deps/v8/src/parsing/parser.cc | 227 +++++++++------- deps/v8/src/parsing/parser.h | 116 ++++---- deps/v8/src/parsing/parsing.cc | 4 +- deps/v8/src/parsing/pattern-rewriter.cc | 16 +- deps/v8/src/parsing/preparser.cc | 4 +- deps/v8/src/parsing/preparser.h | 69 ++--- deps/v8/src/parsing/rewriter.cc | 11 +- deps/v8/src/zone/zone-list-inl.h | 8 - deps/v8/src/zone/zone.h | 12 +- .../cpu-profiler/coverage-block-expected.txt | 138 +++------- .../test/mjsunit/code-coverage-block-opt.js | 4 +- deps/v8/test/mjsunit/code-coverage-block.js | 247 ++++++++++++++++-- 35 files changed, 964 insertions(+), 605 deletions(-) create mode 100644 deps/v8/src/ast/source-range-ast-visitor.cc create mode 100644 deps/v8/src/ast/source-range-ast-visitor.h diff --git a/common.gypi b/common.gypi index 4c643398ac222b..15497032e7e51b 100644 --- a/common.gypi +++ b/common.gypi @@ -33,7 +33,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.51', + 'v8_embedder_string': '-node.52', # Enable disassembler for `--print-code` v8 options 'v8_enable_disassembler': 1, diff --git a/deps/v8/AUTHORS b/deps/v8/AUTHORS index afad3a50414858..1c5a1faf03d1aa 100644 --- a/deps/v8/AUTHORS +++ b/deps/v8/AUTHORS @@ -49,7 +49,7 @@ Andrew Paprocki Andrei Kashcha Anna Henningsen Bangfu Tao -Ben Coe +Ben Coe Ben Newman Ben Noordhuis Benjamin Tan diff --git a/deps/v8/BUILD.gn b/deps/v8/BUILD.gn index 19ffdb38867782..6b5edbf473a700 100644 --- a/deps/v8/BUILD.gn +++ b/deps/v8/BUILD.gn @@ -1496,6 +1496,8 @@ v8_source_set("v8_base") { "src/ast/prettyprinter.h", "src/ast/scopes.cc", "src/ast/scopes.h", + "src/ast/source-range-ast-visitor.cc", + "src/ast/source-range-ast-visitor.h", "src/ast/variables.cc", "src/ast/variables.h", "src/bailout-reason.cc", diff --git a/deps/v8/gypfiles/v8.gyp b/deps/v8/gypfiles/v8.gyp index 8c78f022551e66..e7ea54c39b076f 100644 --- a/deps/v8/gypfiles/v8.gyp +++ b/deps/v8/gypfiles/v8.gyp @@ -516,6 +516,8 @@ '../src/ast/prettyprinter.h', '../src/ast/scopes.cc', '../src/ast/scopes.h', + "../src/ast/source-range-ast-visitor.cc", + "../src/ast/source-range-ast-visitor.h", '../src/ast/variables.cc', '../src/ast/variables.h', '../src/bailout-reason.cc', diff --git a/deps/v8/src/ast/ast-source-ranges.h b/deps/v8/src/ast/ast-source-ranges.h index cf7bab53daa607..e5306cc74773d8 100644 --- a/deps/v8/src/ast/ast-source-ranges.h +++ b/deps/v8/src/ast/ast-source-ranges.h @@ -58,6 +58,8 @@ class AstNodeSourceRanges : public ZoneObject { public: virtual ~AstNodeSourceRanges() {} virtual SourceRange GetRange(SourceRangeKind kind) = 0; + virtual bool HasRange(SourceRangeKind kind) = 0; + virtual void RemoveContinuationRange() { UNREACHABLE(); } }; class BinaryOperationSourceRanges final : public AstNodeSourceRanges { @@ -65,11 +67,15 @@ class BinaryOperationSourceRanges final : public AstNodeSourceRanges { explicit BinaryOperationSourceRanges(const SourceRange& right_range) : right_range_(right_range) {} - SourceRange GetRange(SourceRangeKind kind) { - DCHECK_EQ(kind, SourceRangeKind::kRight); + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); return right_range_; } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kRight; + } + private: SourceRange right_range_; }; @@ -79,11 +85,20 @@ class ContinuationSourceRanges : public AstNodeSourceRanges { explicit ContinuationSourceRanges(int32_t continuation_position) : continuation_position_(continuation_position) {} - SourceRange GetRange(SourceRangeKind kind) { - DCHECK_EQ(kind, SourceRangeKind::kContinuation); + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); return SourceRange::OpenEnded(continuation_position_); } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kContinuation; + } + + void RemoveContinuationRange() override { + DCHECK(HasRange(SourceRangeKind::kContinuation)); + continuation_position_ = kNoSourcePosition; + } + private: int32_t continuation_position_; }; @@ -99,11 +114,15 @@ class CaseClauseSourceRanges final : public AstNodeSourceRanges { explicit CaseClauseSourceRanges(const SourceRange& body_range) : body_range_(body_range) {} - SourceRange GetRange(SourceRangeKind kind) { - DCHECK_EQ(kind, SourceRangeKind::kBody); + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); return body_range_; } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kBody; + } + private: SourceRange body_range_; }; @@ -114,7 +133,8 @@ class ConditionalSourceRanges final : public AstNodeSourceRanges { const SourceRange& else_range) : then_range_(then_range), else_range_(else_range) {} - SourceRange GetRange(SourceRangeKind kind) { + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); switch (kind) { case SourceRangeKind::kThen: return then_range_; @@ -125,6 +145,10 @@ class ConditionalSourceRanges final : public AstNodeSourceRanges { } } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kThen || kind == SourceRangeKind::kElse; + } + private: SourceRange then_range_; SourceRange else_range_; @@ -136,13 +160,15 @@ class IfStatementSourceRanges final : public AstNodeSourceRanges { const SourceRange& else_range) : then_range_(then_range), else_range_(else_range) {} - SourceRange GetRange(SourceRangeKind kind) { + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); switch (kind) { case SourceRangeKind::kElse: return else_range_; case SourceRangeKind::kThen: return then_range_; case SourceRangeKind::kContinuation: { + if (!has_continuation_) return SourceRange::Empty(); const SourceRange& trailing_range = else_range_.IsEmpty() ? then_range_ : else_range_; return SourceRange::ContinuationOf(trailing_range); @@ -152,9 +178,20 @@ class IfStatementSourceRanges final : public AstNodeSourceRanges { } } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kThen || kind == SourceRangeKind::kElse || + kind == SourceRangeKind::kContinuation; + } + + void RemoveContinuationRange() override { + DCHECK(HasRange(SourceRangeKind::kContinuation)); + has_continuation_ = false; + } + private: SourceRange then_range_; SourceRange else_range_; + bool has_continuation_ = true; }; class IterationStatementSourceRanges final : public AstNodeSourceRanges { @@ -162,19 +199,32 @@ class IterationStatementSourceRanges final : public AstNodeSourceRanges { explicit IterationStatementSourceRanges(const SourceRange& body_range) : body_range_(body_range) {} - SourceRange GetRange(SourceRangeKind kind) { + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); switch (kind) { case SourceRangeKind::kBody: return body_range_; case SourceRangeKind::kContinuation: + if (!has_continuation_) return SourceRange::Empty(); return SourceRange::ContinuationOf(body_range_); default: UNREACHABLE(); } } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kBody || + kind == SourceRangeKind::kContinuation; + } + + void RemoveContinuationRange() override { + DCHECK(HasRange(SourceRangeKind::kContinuation)); + has_continuation_ = false; + } + private: SourceRange body_range_; + bool has_continuation_ = true; }; class JumpStatementSourceRanges final : public ContinuationSourceRanges { @@ -198,7 +248,8 @@ class NaryOperationSourceRanges final : public AstNodeSourceRanges { void AddRange(const SourceRange& range) { ranges_.push_back(range); } size_t RangeCount() const { return ranges_.size(); } - SourceRange GetRange(SourceRangeKind kind) { UNREACHABLE(); } + SourceRange GetRange(SourceRangeKind kind) override { UNREACHABLE(); } + bool HasRange(SourceRangeKind kind) override { return false; } private: ZoneVector ranges_; @@ -227,19 +278,32 @@ class TryCatchStatementSourceRanges final : public AstNodeSourceRanges { explicit TryCatchStatementSourceRanges(const SourceRange& catch_range) : catch_range_(catch_range) {} - SourceRange GetRange(SourceRangeKind kind) { + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); switch (kind) { case SourceRangeKind::kCatch: return catch_range_; case SourceRangeKind::kContinuation: + if (!has_continuation_) return SourceRange::Empty(); return SourceRange::ContinuationOf(catch_range_); default: UNREACHABLE(); } } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kCatch || + kind == SourceRangeKind::kContinuation; + } + + void RemoveContinuationRange() override { + DCHECK(HasRange(SourceRangeKind::kContinuation)); + has_continuation_ = false; + } + private: SourceRange catch_range_; + bool has_continuation_ = true; }; class TryFinallyStatementSourceRanges final : public AstNodeSourceRanges { @@ -247,19 +311,32 @@ class TryFinallyStatementSourceRanges final : public AstNodeSourceRanges { explicit TryFinallyStatementSourceRanges(const SourceRange& finally_range) : finally_range_(finally_range) {} - SourceRange GetRange(SourceRangeKind kind) { + SourceRange GetRange(SourceRangeKind kind) override { + DCHECK(HasRange(kind)); switch (kind) { case SourceRangeKind::kFinally: return finally_range_; case SourceRangeKind::kContinuation: + if (!has_continuation_) return SourceRange::Empty(); return SourceRange::ContinuationOf(finally_range_); default: UNREACHABLE(); } } + bool HasRange(SourceRangeKind kind) override { + return kind == SourceRangeKind::kFinally || + kind == SourceRangeKind::kContinuation; + } + + void RemoveContinuationRange() override { + DCHECK(HasRange(SourceRangeKind::kContinuation)); + has_continuation_ = false; + } + private: SourceRange finally_range_; + bool has_continuation_ = true; }; // Maps ast node pointers to associated source ranges. The parser creates these diff --git a/deps/v8/src/ast/ast-traversal-visitor.h b/deps/v8/src/ast/ast-traversal-visitor.h index 35432fa6476ea3..640de541b548cd 100644 --- a/deps/v8/src/ast/ast-traversal-visitor.h +++ b/deps/v8/src/ast/ast-traversal-visitor.h @@ -41,7 +41,7 @@ class AstTraversalVisitor : public AstVisitor { // Iteration left-to-right. void VisitDeclarations(Declaration::List* declarations); - void VisitStatements(ZoneList* statements); + void VisitStatements(ZonePtrList* statements); // Individual nodes #define DECLARE_VISIT(type) void Visit##type(type* node); @@ -112,7 +112,7 @@ void AstTraversalVisitor::VisitDeclarations( template void AstTraversalVisitor::VisitStatements( - ZoneList* stmts) { + ZonePtrList* stmts) { for (int i = 0; i < stmts->length(); ++i) { Statement* stmt = stmts->at(i); RECURSE(Visit(stmt)); @@ -198,14 +198,14 @@ void AstTraversalVisitor::VisitSwitchStatement( PROCESS_NODE(stmt); RECURSE(Visit(stmt->tag())); - ZoneList* clauses = stmt->cases(); + ZonePtrList* clauses = stmt->cases(); for (int i = 0; i < clauses->length(); ++i) { CaseClause* clause = clauses->at(i); if (!clause->is_default()) { Expression* label = clause->label(); RECURSE(Visit(label)); } - ZoneList* stmts = clause->statements(); + ZonePtrList* stmts = clause->statements(); RECURSE(VisitStatements(stmts)); } } @@ -330,7 +330,7 @@ void AstTraversalVisitor::VisitRegExpLiteral(RegExpLiteral* expr) { template void AstTraversalVisitor::VisitObjectLiteral(ObjectLiteral* expr) { PROCESS_EXPRESSION(expr); - ZoneList* props = expr->properties(); + ZonePtrList* props = expr->properties(); for (int i = 0; i < props->length(); ++i) { ObjectLiteralProperty* prop = props->at(i); RECURSE_EXPRESSION(Visit(prop->key())); @@ -341,7 +341,7 @@ void AstTraversalVisitor::VisitObjectLiteral(ObjectLiteral* expr) { template void AstTraversalVisitor::VisitArrayLiteral(ArrayLiteral* expr) { PROCESS_EXPRESSION(expr); - ZoneList* values = expr->values(); + ZonePtrList* values = expr->values(); for (int i = 0; i < values->length(); ++i) { Expression* value = values->at(i); RECURSE_EXPRESSION(Visit(value)); @@ -404,7 +404,7 @@ template void AstTraversalVisitor::VisitCall(Call* expr) { PROCESS_EXPRESSION(expr); RECURSE_EXPRESSION(Visit(expr->expression())); - ZoneList* args = expr->arguments(); + ZonePtrList* args = expr->arguments(); for (int i = 0; i < args->length(); ++i) { Expression* arg = args->at(i); RECURSE_EXPRESSION(Visit(arg)); @@ -415,7 +415,7 @@ template void AstTraversalVisitor::VisitCallNew(CallNew* expr) { PROCESS_EXPRESSION(expr); RECURSE_EXPRESSION(Visit(expr->expression())); - ZoneList* args = expr->arguments(); + ZonePtrList* args = expr->arguments(); for (int i = 0; i < args->length(); ++i) { Expression* arg = args->at(i); RECURSE_EXPRESSION(Visit(arg)); @@ -425,7 +425,7 @@ void AstTraversalVisitor::VisitCallNew(CallNew* expr) { template void AstTraversalVisitor::VisitCallRuntime(CallRuntime* expr) { PROCESS_EXPRESSION(expr); - ZoneList* args = expr->arguments(); + ZonePtrList* args = expr->arguments(); for (int i = 0; i < args->length(); ++i) { Expression* arg = args->at(i); RECURSE_EXPRESSION(Visit(arg)); @@ -487,7 +487,7 @@ void AstTraversalVisitor::VisitClassLiteral(ClassLiteral* expr) { if (expr->instance_fields_initializer_function() != nullptr) { RECURSE_EXPRESSION(Visit(expr->instance_fields_initializer_function())); } - ZoneList* props = expr->properties(); + ZonePtrList* props = expr->properties(); for (int i = 0; i < props->length(); ++i) { ClassLiteralProperty* prop = props->at(i); if (!prop->key()->IsLiteral()) { @@ -501,7 +501,7 @@ template void AstTraversalVisitor::VisitInitializeClassFieldsStatement( InitializeClassFieldsStatement* stmt) { PROCESS_NODE(stmt); - ZoneList* props = stmt->fields(); + ZonePtrList* props = stmt->fields(); for (int i = 0; i < props->length(); ++i) { ClassLiteralProperty* prop = props->at(i); if (!prop->key()->IsLiteral()) { diff --git a/deps/v8/src/ast/ast.cc b/deps/v8/src/ast/ast.cc index 15b8bff61b697f..f2c1ef2759abd0 100644 --- a/deps/v8/src/ast/ast.cc +++ b/deps/v8/src/ast/ast.cc @@ -831,7 +831,7 @@ Call::CallType Call::GetCallType() const { return OTHER_CALL; } -CaseClause::CaseClause(Expression* label, ZoneList* statements) +CaseClause::CaseClause(Expression* label, ZonePtrList* statements) : label_(label), statements_(statements) {} bool Literal::IsPropertyName() const { @@ -954,7 +954,7 @@ const char* CallRuntime::debug_name() { case k##NodeType: \ return static_cast(this)->labels(); -ZoneList* BreakableStatement::labels() const { +ZonePtrList* BreakableStatement::labels() const { switch (node_type()) { BREAKABLE_NODE_LIST(RETURN_LABELS) ITERATION_NODE_LIST(RETURN_LABELS) diff --git a/deps/v8/src/ast/ast.h b/deps/v8/src/ast/ast.h index 35dede266b37e3..2d0928dacadc38 100644 --- a/deps/v8/src/ast/ast.h +++ b/deps/v8/src/ast/ast.h @@ -255,7 +255,7 @@ class BreakableStatement : public Statement { TARGET_FOR_NAMED_ONLY }; - ZoneList* labels() const; + ZonePtrList* labels() const; // Testers. bool is_target_for_anonymous() const { @@ -277,12 +277,12 @@ class BreakableStatement : public Statement { class Block : public BreakableStatement { public: - ZoneList* statements() { return &statements_; } + ZonePtrList* statements() { return &statements_; } bool ignore_completion_value() const { return IgnoreCompletionField::decode(bit_field_); } - inline ZoneList* labels() const; + inline ZonePtrList* labels() const; bool IsJump() const { return !statements_.is_empty() && statements_.last()->IsJump() && @@ -295,7 +295,7 @@ class Block : public BreakableStatement { private: friend class AstNodeFactory; - ZoneList statements_; + ZonePtrList statements_; Scope* scope_; class IgnoreCompletionField @@ -304,7 +304,7 @@ class Block : public BreakableStatement { : public BitField {}; protected: - Block(Zone* zone, ZoneList* labels, int capacity, + Block(Zone* zone, ZonePtrList* labels, int capacity, bool ignore_completion_value) : BreakableStatement(TARGET_FOR_NAMED_ONLY, kNoSourcePosition, kBlock), statements_(capacity, zone), @@ -319,18 +319,18 @@ class LabeledBlock final : public Block { friend class AstNodeFactory; friend class Block; - LabeledBlock(Zone* zone, ZoneList* labels, int capacity, - bool ignore_completion_value) + LabeledBlock(Zone* zone, ZonePtrList* labels, + int capacity, bool ignore_completion_value) : Block(zone, labels, capacity, ignore_completion_value), labels_(labels) { DCHECK_NOT_NULL(labels); DCHECK_GT(labels->length(), 0); } - ZoneList* labels_; + ZonePtrList* labels_; }; -inline ZoneList* Block::labels() const { +inline ZonePtrList* Block::labels() const { if (IsLabeledField::decode(bit_field_)) { return static_cast(this)->labels_; } @@ -437,10 +437,10 @@ class IterationStatement : public BreakableStatement { Statement* body() const { return body_; } void set_body(Statement* s) { body_ = s; } - ZoneList* labels() const { return labels_; } + ZonePtrList* labels() const { return labels_; } protected: - IterationStatement(ZoneList* labels, int pos, + IterationStatement(ZonePtrList* labels, int pos, NodeType type) : BreakableStatement(TARGET_FOR_ANONYMOUS, pos, type), labels_(labels), @@ -451,7 +451,7 @@ class IterationStatement : public BreakableStatement { BreakableStatement::kNextBitFieldIndex; private: - ZoneList* labels_; + ZonePtrList* labels_; Statement* body_; }; @@ -468,7 +468,7 @@ class DoWhileStatement final : public IterationStatement { private: friend class AstNodeFactory; - DoWhileStatement(ZoneList* labels, int pos) + DoWhileStatement(ZonePtrList* labels, int pos) : IterationStatement(labels, pos, kDoWhileStatement), cond_(nullptr) {} Expression* cond_; @@ -487,7 +487,7 @@ class WhileStatement final : public IterationStatement { private: friend class AstNodeFactory; - WhileStatement(ZoneList* labels, int pos) + WhileStatement(ZonePtrList* labels, int pos) : IterationStatement(labels, pos, kWhileStatement), cond_(nullptr) {} Expression* cond_; @@ -511,7 +511,7 @@ class ForStatement final : public IterationStatement { private: friend class AstNodeFactory; - ForStatement(ZoneList* labels, int pos) + ForStatement(ZonePtrList* labels, int pos) : IterationStatement(labels, pos, kForStatement), init_(nullptr), cond_(nullptr), @@ -537,7 +537,7 @@ class ForEachStatement : public IterationStatement { } protected: - ForEachStatement(ZoneList* labels, int pos, + ForEachStatement(ZonePtrList* labels, int pos, NodeType type) : IterationStatement(labels, pos, type) {} }; @@ -564,7 +564,7 @@ class ForInStatement final : public ForEachStatement { private: friend class AstNodeFactory; - ForInStatement(ZoneList* labels, int pos) + ForInStatement(ZonePtrList* labels, int pos) : ForEachStatement(labels, pos, kForInStatement), each_(nullptr), subject_(nullptr) { @@ -630,7 +630,7 @@ class ForOfStatement final : public ForEachStatement { private: friend class AstNodeFactory; - ForOfStatement(ZoneList* labels, int pos) + ForOfStatement(ZonePtrList* labels, int pos) : ForEachStatement(labels, pos, kForOfStatement), iterator_(nullptr), assign_iterator_(nullptr), @@ -757,40 +757,40 @@ class CaseClause final : public ZoneObject { DCHECK(!is_default()); return label_; } - ZoneList* statements() const { return statements_; } + ZonePtrList* statements() const { return statements_; } private: friend class AstNodeFactory; - CaseClause(Expression* label, ZoneList* statements); + CaseClause(Expression* label, ZonePtrList* statements); Expression* label_; - ZoneList* statements_; + ZonePtrList* statements_; }; class SwitchStatement final : public BreakableStatement { public: - ZoneList* labels() const { return labels_; } + ZonePtrList* labels() const { return labels_; } Expression* tag() const { return tag_; } void set_tag(Expression* t) { tag_ = t; } - ZoneList* cases() { return &cases_; } + ZonePtrList* cases() { return &cases_; } private: friend class AstNodeFactory; - SwitchStatement(Zone* zone, ZoneList* labels, + SwitchStatement(Zone* zone, ZonePtrList* labels, Expression* tag, int pos) : BreakableStatement(TARGET_FOR_ANONYMOUS, pos, kSwitchStatement), labels_(labels), tag_(tag), cases_(4, zone) {} - ZoneList* labels_; + ZonePtrList* labels_; Expression* tag_; - ZoneList cases_; + ZonePtrList cases_; }; @@ -1280,7 +1280,7 @@ class ObjectLiteral final : public AggregateLiteral { return constant_properties_; } int properties_count() const { return boilerplate_properties_; } - ZoneList* properties() const { return properties_; } + ZonePtrList* properties() const { return properties_; } bool has_elements() const { return HasElementsField::decode(bit_field_); } bool has_rest_property() const { return HasRestPropertyField::decode(bit_field_); @@ -1355,7 +1355,7 @@ class ObjectLiteral final : public AggregateLiteral { private: friend class AstNodeFactory; - ObjectLiteral(ZoneList* properties, + ObjectLiteral(ZonePtrList* properties, uint32_t boilerplate_properties, int pos, bool has_rest_property) : AggregateLiteral(pos, kObjectLiteral), @@ -1381,7 +1381,7 @@ class ObjectLiteral final : public AggregateLiteral { uint32_t boilerplate_properties_; Handle constant_properties_; - ZoneList* properties_; + ZonePtrList* properties_; class HasElementsField : public BitField {}; @@ -1427,7 +1427,7 @@ class ArrayLiteral final : public AggregateLiteral { return constant_elements_; } - ZoneList* values() const { return values_; } + ZonePtrList* values() const { return values_; } int first_spread_index() const { return first_spread_index_; } @@ -1458,15 +1458,14 @@ class ArrayLiteral final : public AggregateLiteral { private: friend class AstNodeFactory; - ArrayLiteral(ZoneList* values, int first_spread_index, int pos) + ArrayLiteral(ZonePtrList* values, int first_spread_index, int pos) : AggregateLiteral(pos, kArrayLiteral), first_spread_index_(first_spread_index), - values_(values) { - } + values_(values) {} int first_spread_index_; Handle constant_elements_; - ZoneList* values_; + ZonePtrList* values_; }; enum class HoleCheckMode { kRequired, kElided }; @@ -1633,7 +1632,7 @@ class ResolvedProperty final : public Expression { class Call final : public Expression { public: Expression* expression() const { return expression_; } - ZoneList* arguments() const { return arguments_; } + ZonePtrList* arguments() const { return arguments_; } bool is_possibly_eval() const { return IsPossiblyEvalField::decode(bit_field_); @@ -1672,17 +1671,15 @@ class Call final : public Expression { private: friend class AstNodeFactory; - Call(Expression* expression, ZoneList* arguments, int pos, + Call(Expression* expression, ZonePtrList* arguments, int pos, PossiblyEval possibly_eval) - : Expression(pos, kCall), - expression_(expression), - arguments_(arguments) { + : Expression(pos, kCall), expression_(expression), arguments_(arguments) { bit_field_ |= IsPossiblyEvalField::encode(possibly_eval == IS_POSSIBLY_EVAL) | IsTaggedTemplateField::encode(false); } - Call(Expression* expression, ZoneList* arguments, int pos, + Call(Expression* expression, ZonePtrList* arguments, int pos, TaggedTemplateTag tag) : Expression(pos, kCall), expression_(expression), arguments_(arguments) { bit_field_ |= IsPossiblyEvalField::encode(false) | @@ -1695,14 +1692,14 @@ class Call final : public Expression { : public BitField {}; Expression* expression_; - ZoneList* arguments_; + ZonePtrList* arguments_; }; class CallNew final : public Expression { public: Expression* expression() const { return expression_; } - ZoneList* arguments() const { return arguments_; } + ZonePtrList* arguments() const { return arguments_; } bool only_last_arg_is_spread() { return !arguments_->is_empty() && arguments_->last()->IsSpread(); @@ -1711,14 +1708,13 @@ class CallNew final : public Expression { private: friend class AstNodeFactory; - CallNew(Expression* expression, ZoneList* arguments, int pos) + CallNew(Expression* expression, ZonePtrList* arguments, int pos) : Expression(pos, kCallNew), expression_(expression), - arguments_(arguments) { - } + arguments_(arguments) {} Expression* expression_; - ZoneList* arguments_; + ZonePtrList* arguments_; }; // The CallRuntime class does not represent any official JavaScript @@ -1727,7 +1723,7 @@ class CallNew final : public Expression { // implemented in JavaScript. class CallRuntime final : public Expression { public: - ZoneList* arguments() const { return arguments_; } + ZonePtrList* arguments() const { return arguments_; } bool is_jsruntime() const { return function_ == nullptr; } int context_index() const { @@ -1745,11 +1741,11 @@ class CallRuntime final : public Expression { friend class AstNodeFactory; CallRuntime(const Runtime::Function* function, - ZoneList* arguments, int pos) + ZonePtrList* arguments, int pos) : Expression(pos, kCallRuntime), function_(function), arguments_(arguments) {} - CallRuntime(int context_index, ZoneList* arguments, int pos) + CallRuntime(int context_index, ZonePtrList* arguments, int pos) : Expression(pos, kCallRuntime), context_index_(context_index), function_(nullptr), @@ -1757,7 +1753,7 @@ class CallRuntime final : public Expression { int context_index_; const Runtime::Function* function_; - ZoneList* arguments_; + ZonePtrList* arguments_; }; @@ -2190,7 +2186,7 @@ class FunctionLiteral final : public Expression { const AstConsString* raw_name() const { return raw_name_; } void set_raw_name(const AstConsString* name) { raw_name_ = name; } DeclarationScope* scope() const { return scope_; } - ZoneList* body() const { return body_; } + ZonePtrList* body() const { return body_; } void set_function_token_position(int pos) { function_token_position_ = pos; } int function_token_position() const { return function_token_position_; } int start_position() const; @@ -2310,7 +2306,7 @@ class FunctionLiteral final : public Expression { FunctionLiteral( Zone* zone, const AstRawString* name, AstValueFactory* ast_value_factory, - DeclarationScope* scope, ZoneList* body, + DeclarationScope* scope, ZonePtrList* body, int expected_property_count, int parameter_count, int function_length, FunctionType function_type, ParameterFlag has_duplicate_parameters, EagerCompileHint eager_compile_hint, int position, bool has_braces, @@ -2359,7 +2355,7 @@ class FunctionLiteral final : public Expression { const AstConsString* raw_name_; DeclarationScope* scope_; - ZoneList* body_; + ZonePtrList* body_; const AstConsString* raw_inferred_name_; Handle inferred_name_; ProducedPreParsedScopeData* produced_preparsed_scope_data_; @@ -2407,15 +2403,16 @@ class ClassLiteralProperty final : public LiteralProperty { class InitializeClassFieldsStatement final : public Statement { public: typedef ClassLiteralProperty Property; - ZoneList* fields() const { return fields_; } + + ZonePtrList* fields() const { return fields_; } private: friend class AstNodeFactory; - InitializeClassFieldsStatement(ZoneList* fields, int pos) + InitializeClassFieldsStatement(ZonePtrList* fields, int pos) : Statement(pos, kInitializeClassFieldsStatement), fields_(fields) {} - ZoneList* fields_; + ZonePtrList* fields_; }; class ClassLiteral final : public Expression { @@ -2426,7 +2423,7 @@ class ClassLiteral final : public Expression { Variable* class_variable() const { return class_variable_; } Expression* extends() const { return extends_; } FunctionLiteral* constructor() const { return constructor_; } - ZoneList* properties() const { return properties_; } + ZonePtrList* properties() const { return properties_; } int start_position() const { return position(); } int end_position() const { return end_position_; } bool has_name_static_property() const { @@ -2455,7 +2452,7 @@ class ClassLiteral final : public Expression { friend class AstNodeFactory; ClassLiteral(Scope* scope, Variable* class_variable, Expression* extends, - FunctionLiteral* constructor, ZoneList* properties, + FunctionLiteral* constructor, ZonePtrList* properties, FunctionLiteral* static_fields_initializer, FunctionLiteral* instance_fields_initializer_function, int start_position, int end_position, @@ -2481,7 +2478,7 @@ class ClassLiteral final : public Expression { Variable* class_variable_; Expression* extends_; FunctionLiteral* constructor_; - ZoneList* properties_; + ZonePtrList* properties_; FunctionLiteral* static_fields_initializer_; FunctionLiteral* instance_fields_initializer_function_; class HasNameStaticProperty @@ -2636,10 +2633,10 @@ class GetIterator final : public Expression { // (defined at https://tc39.github.io/ecma262/#sec-gettemplateobject). class GetTemplateObject final : public Expression { public: - const ZoneList* cooked_strings() const { + const ZonePtrList* cooked_strings() const { return cooked_strings_; } - const ZoneList* raw_strings() const { + const ZonePtrList* raw_strings() const { return raw_strings_; } @@ -2648,34 +2645,35 @@ class GetTemplateObject final : public Expression { private: friend class AstNodeFactory; - GetTemplateObject(const ZoneList* cooked_strings, - const ZoneList* raw_strings, int pos) + GetTemplateObject(const ZonePtrList* cooked_strings, + const ZonePtrList* raw_strings, int pos) : Expression(pos, kGetTemplateObject), cooked_strings_(cooked_strings), raw_strings_(raw_strings) {} - const ZoneList* cooked_strings_; - const ZoneList* raw_strings_; + const ZonePtrList* cooked_strings_; + const ZonePtrList* raw_strings_; }; class TemplateLiteral final : public Expression { public: - using StringList = ZoneList; - using ExpressionList = ZoneList; - - const StringList* string_parts() const { return string_parts_; } - const ExpressionList* substitutions() const { return substitutions_; } + const ZonePtrList* string_parts() const { + return string_parts_; + } + const ZonePtrList* substitutions() const { + return substitutions_; + } private: friend class AstNodeFactory; - TemplateLiteral(const StringList* parts, const ExpressionList* substitutions, - int pos) + TemplateLiteral(const ZonePtrList* parts, + const ZonePtrList* substitutions, int pos) : Expression(pos, kTemplateLiteral), string_parts_(parts), substitutions_(substitutions) {} - const StringList* string_parts_; - const ExpressionList* substitutions_; + const ZonePtrList* string_parts_; + const ZonePtrList* substitutions_; }; // ---------------------------------------------------------------------------- @@ -2692,7 +2690,7 @@ class AstVisitor BASE_EMBEDDED { for (Declaration* decl : *declarations) Visit(decl); } - void VisitStatements(ZoneList* statements) { + void VisitStatements(ZonePtrList* statements) { for (int i = 0; i < statements->length(); i++) { Statement* stmt = statements->at(i); Visit(stmt); @@ -2700,7 +2698,7 @@ class AstVisitor BASE_EMBEDDED { } } - void VisitExpressions(ZoneList* expressions) { + void VisitExpressions(ZonePtrList* expressions) { for (int i = 0; i < expressions->length(); i++) { // The variable statement visiting code may pass null expressions // to this code. Maybe this should be handled by introducing an @@ -2794,7 +2792,7 @@ class AstNodeFactory final BASE_EMBEDDED { } Block* NewBlock(int capacity, bool ignore_completion_value, - ZoneList* labels = nullptr) { + ZonePtrList* labels = nullptr) { return labels != nullptr ? new (zone_) LabeledBlock(zone_, labels, capacity, ignore_completion_value) @@ -2802,22 +2800,22 @@ class AstNodeFactory final BASE_EMBEDDED { Block(zone_, labels, capacity, ignore_completion_value); } -#define STATEMENT_WITH_LABELS(NodeType) \ - NodeType* New##NodeType(ZoneList* labels, int pos) { \ - return new (zone_) NodeType(labels, pos); \ +#define STATEMENT_WITH_LABELS(NodeType) \ + NodeType* New##NodeType(ZonePtrList* labels, int pos) { \ + return new (zone_) NodeType(labels, pos); \ } STATEMENT_WITH_LABELS(DoWhileStatement) STATEMENT_WITH_LABELS(WhileStatement) STATEMENT_WITH_LABELS(ForStatement) #undef STATEMENT_WITH_LABELS - SwitchStatement* NewSwitchStatement(ZoneList* labels, + SwitchStatement* NewSwitchStatement(ZonePtrList* labels, Expression* tag, int pos) { return new (zone_) SwitchStatement(zone_, labels, tag, pos); } ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, - ZoneList* labels, + ZonePtrList* labels, int pos) { switch (visit_mode) { case ForEachStatement::ENUMERATE: { @@ -2830,7 +2828,7 @@ class AstNodeFactory final BASE_EMBEDDED { UNREACHABLE(); } - ForOfStatement* NewForOfStatement(ZoneList* labels, + ForOfStatement* NewForOfStatement(ZonePtrList* labels, int pos) { return new (zone_) ForOfStatement(labels, pos); } @@ -2921,7 +2919,7 @@ class AstNodeFactory final BASE_EMBEDDED { } CaseClause* NewCaseClause(Expression* label, - ZoneList* statements) { + ZonePtrList* statements) { return new (zone_) CaseClause(label, statements); } @@ -2961,7 +2959,7 @@ class AstNodeFactory final BASE_EMBEDDED { } ObjectLiteral* NewObjectLiteral( - ZoneList* properties, + ZonePtrList* properties, uint32_t boilerplate_properties, int pos, bool has_rest_property) { return new (zone_) ObjectLiteral(properties, boilerplate_properties, pos, has_rest_property); @@ -2986,12 +2984,11 @@ class AstNodeFactory final BASE_EMBEDDED { return new (zone_) RegExpLiteral(pattern, flags, pos); } - ArrayLiteral* NewArrayLiteral(ZoneList* values, - int pos) { + ArrayLiteral* NewArrayLiteral(ZonePtrList* values, int pos) { return new (zone_) ArrayLiteral(values, -1, pos); } - ArrayLiteral* NewArrayLiteral(ZoneList* values, + ArrayLiteral* NewArrayLiteral(ZonePtrList* values, int first_spread_index, int pos) { return new (zone_) ArrayLiteral(values, first_spread_index, pos); } @@ -3027,35 +3024,34 @@ class AstNodeFactory final BASE_EMBEDDED { return new (zone_) ResolvedProperty(obj, property, pos); } - Call* NewCall(Expression* expression, ZoneList* arguments, + Call* NewCall(Expression* expression, ZonePtrList* arguments, int pos, Call::PossiblyEval possibly_eval = Call::NOT_EVAL) { return new (zone_) Call(expression, arguments, pos, possibly_eval); } Call* NewTaggedTemplate(Expression* expression, - ZoneList* arguments, int pos) { + ZonePtrList* arguments, int pos) { return new (zone_) Call(expression, arguments, pos, Call::TaggedTemplateTag::kTrue); } CallNew* NewCallNew(Expression* expression, - ZoneList* arguments, - int pos) { + ZonePtrList* arguments, int pos) { return new (zone_) CallNew(expression, arguments, pos); } CallRuntime* NewCallRuntime(Runtime::FunctionId id, - ZoneList* arguments, int pos) { + ZonePtrList* arguments, int pos) { return new (zone_) CallRuntime(Runtime::FunctionForId(id), arguments, pos); } CallRuntime* NewCallRuntime(const Runtime::Function* function, - ZoneList* arguments, int pos) { + ZonePtrList* arguments, int pos) { return new (zone_) CallRuntime(function, arguments, pos); } CallRuntime* NewCallRuntime(int context_index, - ZoneList* arguments, int pos) { + ZonePtrList* arguments, int pos) { return new (zone_) CallRuntime(context_index, arguments, pos); } @@ -3158,7 +3154,7 @@ class AstNodeFactory final BASE_EMBEDDED { FunctionLiteral* NewFunctionLiteral( const AstRawString* name, DeclarationScope* scope, - ZoneList* body, int expected_property_count, + ZonePtrList* body, int expected_property_count, int parameter_count, int function_length, FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::FunctionType function_type, @@ -3176,7 +3172,7 @@ class AstNodeFactory final BASE_EMBEDDED { // result of an eval (top-level or otherwise), or the result of calling // the Function constructor. FunctionLiteral* NewScriptOrEvalFunctionLiteral(DeclarationScope* scope, - ZoneList* body, + ZonePtrList* body, int expected_property_count, int parameter_count) { return new (zone_) FunctionLiteral( @@ -3198,7 +3194,7 @@ class AstNodeFactory final BASE_EMBEDDED { ClassLiteral* NewClassLiteral( Scope* scope, Variable* variable, Expression* extends, FunctionLiteral* constructor, - ZoneList* properties, + ZonePtrList* properties, FunctionLiteral* static_fields_initializer, FunctionLiteral* instance_fields_initializer_function, int start_position, int end_position, bool has_name_static_property, @@ -3255,14 +3251,14 @@ class AstNodeFactory final BASE_EMBEDDED { } GetTemplateObject* NewGetTemplateObject( - const ZoneList* cooked_strings, - const ZoneList* raw_strings, int pos) { + const ZonePtrList* cooked_strings, + const ZonePtrList* raw_strings, int pos) { return new (zone_) GetTemplateObject(cooked_strings, raw_strings, pos); } TemplateLiteral* NewTemplateLiteral( - const ZoneList* string_parts, - const ZoneList* substitutions, int pos) { + const ZonePtrList* string_parts, + const ZonePtrList* substitutions, int pos) { return new (zone_) TemplateLiteral(string_parts, substitutions, pos); } @@ -3271,7 +3267,7 @@ class AstNodeFactory final BASE_EMBEDDED { } InitializeClassFieldsStatement* NewInitializeClassFieldsStatement( - ZoneList* args, int pos) { + ZonePtrList* args, int pos) { return new (zone_) InitializeClassFieldsStatement(args, pos); } diff --git a/deps/v8/src/ast/prettyprinter.cc b/deps/v8/src/ast/prettyprinter.cc index 4f9029810a044a..ef086bcefc2d55 100644 --- a/deps/v8/src/ast/prettyprinter.cc +++ b/deps/v8/src/ast/prettyprinter.cc @@ -498,16 +498,14 @@ void CallPrinter::VisitRewritableExpression(RewritableExpression* node) { Find(node->expression()); } - -void CallPrinter::FindStatements(ZoneList* statements) { +void CallPrinter::FindStatements(ZonePtrList* statements) { if (statements == nullptr) return; for (int i = 0; i < statements->length(); i++) { Find(statements->at(i)); } } - -void CallPrinter::FindArguments(ZoneList* arguments) { +void CallPrinter::FindArguments(ZonePtrList* arguments) { if (found_) return; for (int i = 0; i < arguments->length(); i++) { Find(arguments->at(i)); @@ -589,7 +587,7 @@ void AstPrinter::Print(const char* format, ...) { } } -void AstPrinter::PrintLabels(ZoneList* labels) { +void AstPrinter::PrintLabels(ZonePtrList* labels) { if (labels != nullptr) { for (int i = 0; i < labels->length(); i++) { PrintLiteral(labels->at(i), false); @@ -748,8 +746,7 @@ void AstPrinter::PrintLiteralWithModeIndented(const char* info, Variable* var, } } - -void AstPrinter::PrintLabelsIndented(ZoneList* labels) { +void AstPrinter::PrintLabelsIndented(ZonePtrList* labels) { if (labels == nullptr || labels->length() == 0) return; PrintIndented("LABELS "); PrintLabels(labels); @@ -809,15 +806,13 @@ void AstPrinter::PrintParameters(DeclarationScope* scope) { } } - -void AstPrinter::PrintStatements(ZoneList* statements) { +void AstPrinter::PrintStatements(ZonePtrList* statements) { for (int i = 0; i < statements->length(); i++) { Visit(statements->at(i)); } } - -void AstPrinter::PrintArguments(ZoneList* arguments) { +void AstPrinter::PrintArguments(ZonePtrList* arguments) { for (int i = 0; i < arguments->length(); i++) { Visit(arguments->at(i)); } @@ -1040,7 +1035,7 @@ void AstPrinter::VisitInitializeClassFieldsStatement( } void AstPrinter::PrintClassProperties( - ZoneList* properties) { + ZonePtrList* properties) { for (int i = 0; i < properties->length(); i++) { ClassLiteral::Property* property = properties->at(i); const char* prop_kind = nullptr; @@ -1119,7 +1114,7 @@ void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) { } void AstPrinter::PrintObjectProperties( - ZoneList* properties) { + ZonePtrList* properties) { for (int i = 0; i < properties->length(); i++) { ObjectLiteral::Property* property = properties->at(i); const char* prop_kind = nullptr; diff --git a/deps/v8/src/ast/prettyprinter.h b/deps/v8/src/ast/prettyprinter.h index d93137b7cf10b1..cc29052c2d9783 100644 --- a/deps/v8/src/ast/prettyprinter.h +++ b/deps/v8/src/ast/prettyprinter.h @@ -56,8 +56,8 @@ class CallPrinter final : public AstVisitor { protected: void PrintLiteral(Handle value, bool quote); void PrintLiteral(const AstRawString* value, bool quote); - void FindStatements(ZoneList* statements); - void FindArguments(ZoneList* arguments); + void FindStatements(ZonePtrList* statements); + void FindArguments(ZonePtrList* arguments); }; @@ -88,17 +88,17 @@ class AstPrinter final : public AstVisitor { void Init(); - void PrintLabels(ZoneList* labels); + void PrintLabels(ZonePtrList* labels); void PrintLiteral(const AstRawString* value, bool quote); void PrintLiteral(const AstConsString* value, bool quote); void PrintLiteral(Literal* literal, bool quote); void PrintIndented(const char* txt); void PrintIndentedVisit(const char* s, AstNode* node); - void PrintStatements(ZoneList* statements); + void PrintStatements(ZonePtrList* statements); void PrintDeclarations(Declaration::List* declarations); void PrintParameters(DeclarationScope* scope); - void PrintArguments(ZoneList* arguments); + void PrintArguments(ZonePtrList* arguments); void PrintCaseClause(CaseClause* clause); void PrintLiteralIndented(const char* info, Literal* literal, bool quote); void PrintLiteralIndented(const char* info, const AstRawString* value, @@ -107,9 +107,9 @@ class AstPrinter final : public AstVisitor { bool quote); void PrintLiteralWithModeIndented(const char* info, Variable* var, const AstRawString* value); - void PrintLabelsIndented(ZoneList* labels); - void PrintObjectProperties(ZoneList* properties); - void PrintClassProperties(ZoneList* properties); + void PrintLabelsIndented(ZonePtrList* labels); + void PrintObjectProperties(ZonePtrList* properties); + void PrintClassProperties(ZonePtrList* properties); void inc_indent() { indent_++; } void dec_indent() { indent_--; } diff --git a/deps/v8/src/ast/scopes.cc b/deps/v8/src/ast/scopes.cc index 42affeea2c9dd5..ed95330092141f 100644 --- a/deps/v8/src/ast/scopes.cc +++ b/deps/v8/src/ast/scopes.cc @@ -1327,7 +1327,7 @@ Declaration* Scope::CheckConflictingVarDeclarations() { } Declaration* Scope::CheckLexDeclarationsConflictingWith( - const ZoneList& names) { + const ZonePtrList& names) { DCHECK(is_block_scope()); for (int i = 0; i < names.length(); ++i) { Variable* var = LookupLocal(names.at(i)); diff --git a/deps/v8/src/ast/scopes.h b/deps/v8/src/ast/scopes.h index c95e3a380a660c..0a06a54b5f46b5 100644 --- a/deps/v8/src/ast/scopes.h +++ b/deps/v8/src/ast/scopes.h @@ -256,7 +256,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { // which is an error even though the two 'e's are declared in different // scopes. Declaration* CheckLexDeclarationsConflictingWith( - const ZoneList& names); + const ZonePtrList& names); // --------------------------------------------------------------------------- // Scope-specific info. @@ -964,7 +964,7 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { bool has_inferred_function_name_ : 1; // Parameter list in source order. - ZoneList params_; + ZonePtrList params_; // Map of function names to lists of functions defined in sloppy blocks SloppyBlockFunctionMap* sloppy_block_function_map_; // Convenience variable. diff --git a/deps/v8/src/ast/source-range-ast-visitor.cc b/deps/v8/src/ast/source-range-ast-visitor.cc new file mode 100644 index 00000000000000..f3a3dbcd9b1385 --- /dev/null +++ b/deps/v8/src/ast/source-range-ast-visitor.cc @@ -0,0 +1,79 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/ast/source-range-ast-visitor.h" + +#include "src/ast/ast-source-ranges.h" + +namespace v8 { +namespace internal { + +SourceRangeAstVisitor::SourceRangeAstVisitor(uintptr_t stack_limit, + Expression* root, + SourceRangeMap* source_range_map) + : AstTraversalVisitor(stack_limit, root), + source_range_map_(source_range_map) {} + +void SourceRangeAstVisitor::VisitBlock(Block* stmt) { + AstTraversalVisitor::VisitBlock(stmt); + ZonePtrList* stmts = stmt->statements(); + AstNodeSourceRanges* enclosingSourceRanges = source_range_map_->Find(stmt); + if (enclosingSourceRanges != nullptr) { + CHECK(enclosingSourceRanges->HasRange(SourceRangeKind::kContinuation)); + MaybeRemoveLastContinuationRange(stmts); + } +} + +void SourceRangeAstVisitor::VisitFunctionLiteral(FunctionLiteral* expr) { + AstTraversalVisitor::VisitFunctionLiteral(expr); + ZonePtrList* stmts = expr->body(); + MaybeRemoveLastContinuationRange(stmts); +} + +bool SourceRangeAstVisitor::VisitNode(AstNode* node) { + AstNodeSourceRanges* range = source_range_map_->Find(node); + + if (range == nullptr) return true; + if (!range->HasRange(SourceRangeKind::kContinuation)) return true; + + // Called in pre-order. In case of conflicting continuation ranges, only the + // outermost range may survive. + + SourceRange continuation = range->GetRange(SourceRangeKind::kContinuation); + if (continuation_positions_.find(continuation.start) != + continuation_positions_.end()) { + range->RemoveContinuationRange(); + } else { + continuation_positions_.emplace(continuation.start); + } + + return true; +} + +void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange( + ZonePtrList* statements) { + if (statements == nullptr || statements->is_empty()) return; + + Statement* last_statement = statements->last(); + AstNodeSourceRanges* last_range = nullptr; + + if (last_statement->IsExpressionStatement() && + last_statement->AsExpressionStatement()->expression()->IsThrow()) { + // For ThrowStatement, source range is tied to Throw expression not + // ExpressionStatement. + last_range = source_range_map_->Find( + last_statement->AsExpressionStatement()->expression()); + } else { + last_range = source_range_map_->Find(last_statement); + } + + if (last_range == nullptr) return; + + if (last_range->HasRange(SourceRangeKind::kContinuation)) { + last_range->RemoveContinuationRange(); + } +} + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/src/ast/source-range-ast-visitor.h b/deps/v8/src/ast/source-range-ast-visitor.h new file mode 100644 index 00000000000000..4ea36a947f58e6 --- /dev/null +++ b/deps/v8/src/ast/source-range-ast-visitor.h @@ -0,0 +1,49 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_AST_SOURCE_RANGE_AST_VISITOR_H_ +#define V8_AST_SOURCE_RANGE_AST_VISITOR_H_ + +#include + +#include "src/ast/ast-traversal-visitor.h" + +namespace v8 { +namespace internal { + +class SourceRangeMap; + +// Post-processes generated source ranges while the AST structure still exists. +// +// In particular, SourceRangeAstVisitor +// +// 1. deduplicates continuation source ranges, only keeping the outermost one. +// See also: https://crbug.com/v8/8539. +// +// 2. removes the source range associated with the final statement in a block +// or function body if the parent itself has a source range associated with it. +// See also: https://crbug.com/v8/8381. +class SourceRangeAstVisitor final + : public AstTraversalVisitor { + public: + SourceRangeAstVisitor(uintptr_t stack_limit, Expression* root, + SourceRangeMap* source_range_map); + + private: + friend class AstTraversalVisitor; + + void VisitBlock(Block* stmt); + void VisitFunctionLiteral(FunctionLiteral* expr); + bool VisitNode(AstNode* node); + + void MaybeRemoveLastContinuationRange(ZonePtrList* stmts); + + SourceRangeMap* source_range_map_ = nullptr; + std::unordered_set continuation_positions_; +}; + +} // namespace internal +} // namespace v8 + +#endif // V8_AST_SOURCE_RANGE_AST_VISITOR_H_ diff --git a/deps/v8/src/debug/debug-coverage.cc b/deps/v8/src/debug/debug-coverage.cc index f27e22cfbbb0da..4fc4bd0a7daca3 100644 --- a/deps/v8/src/debug/debug-coverage.cc +++ b/deps/v8/src/debug/debug-coverage.cc @@ -172,6 +172,12 @@ class CoverageBlockIterator final { return function_->blocks[read_index_ + 1]; } + CoverageBlock& GetPreviousBlock() { + DCHECK(IsActive()); + DCHECK_GT(read_index_, 0); + return function_->blocks[read_index_ - 1]; + } + CoverageBlock& GetParent() { DCHECK(IsActive()); return nesting_stack_.back(); @@ -228,25 +234,6 @@ bool HaveSameSourceRange(const CoverageBlock& lhs, const CoverageBlock& rhs) { return lhs.start == rhs.start && lhs.end == rhs.end; } -void MergeDuplicateSingletons(CoverageFunction* function) { - CoverageBlockIterator iter(function); - - while (iter.Next() && iter.HasNext()) { - CoverageBlock& block = iter.GetBlock(); - CoverageBlock& next_block = iter.GetNextBlock(); - - // Identical ranges should only occur through singleton ranges. Consider the - // ranges for `for (.) break;`: continuation ranges for both the `break` and - // `for` statements begin after the trailing semicolon. - // Such ranges are merged and keep the maximal execution count. - if (!HaveSameSourceRange(block, next_block)) continue; - - DCHECK_EQ(kNoSourcePosition, block.end); // Singleton range. - next_block.count = std::max(block.count, next_block.count); - iter.DeleteBlock(); - } -} - void MergeDuplicateRanges(CoverageFunction* function) { CoverageBlockIterator iter(function); @@ -326,6 +313,30 @@ void MergeNestedRanges(CoverageFunction* function) { } } +void FilterAliasedSingletons(CoverageFunction* function) { + CoverageBlockIterator iter(function); + + iter.Next(); // Advance once since we reference the previous block later. + + while (iter.Next()) { + CoverageBlock& previous_block = iter.GetPreviousBlock(); + CoverageBlock& block = iter.GetBlock(); + + bool is_singleton = block.end == kNoSourcePosition; + bool aliases_start = block.start == previous_block.start; + + if (is_singleton && aliases_start) { + // The previous block must have a full range since duplicate singletons + // have already been merged. + DCHECK_NE(previous_block.end, kNoSourcePosition); + // Likewise, the next block must have another start position since + // singletons are sorted to the end. + DCHECK_IMPLIES(iter.HasNext(), iter.GetNextBlock().start != block.start); + iter.DeleteBlock(); + } + } +} + void FilterUncoveredRanges(CoverageFunction* function) { CoverageBlockIterator iter(function); @@ -396,8 +407,14 @@ void CollectBlockCoverage(Isolate* isolate, CoverageFunction* function, // If in binary mode, only report counts of 0/1. if (mode == debug::Coverage::kBlockBinary) ClampToBinary(function); - // Remove duplicate singleton ranges, keeping the max count. - MergeDuplicateSingletons(function); + // Remove singleton ranges with the same start position as a full range and + // throw away their counts. + // Singleton ranges are only intended to split existing full ranges and should + // never expand into a full range. Consider 'if (cond) { ... } else { ... }' + // as a problematic example; if the then-block produces a continuation + // singleton, it would incorrectly expand into the else range. + // For more context, see https://crbug.com/v8/8237. + FilterAliasedSingletons(function); // Rewrite all singletons (created e.g. by continuations and unconditional // control flow) to ranges. diff --git a/deps/v8/src/interpreter/bytecode-generator.cc b/deps/v8/src/interpreter/bytecode-generator.cc index 432b271343bdbe..24494643309019 100644 --- a/deps/v8/src/interpreter/bytecode-generator.cc +++ b/deps/v8/src/interpreter/bytecode-generator.cc @@ -369,7 +369,6 @@ class BytecodeGenerator::ControlScopeForBreakable final protected: bool Execute(Command command, Statement* statement, int source_position) override { - control_builder_->set_needs_continuation_counter(); if (statement != statement_) return false; switch (command) { case CMD_BREAK: @@ -1327,7 +1326,7 @@ void BytecodeGenerator::VisitDeclarations(Declaration::List* declarations) { globals_builder_ = new (zone()) GlobalDeclarationsBuilder(zone()); } -void BytecodeGenerator::VisitStatements(ZoneList* statements) { +void BytecodeGenerator::VisitStatements(ZonePtrList* statements) { for (int i = 0; i < statements->length(); i++) { // Allocate an outer register allocations scope for the statement. RegisterAllocationScope allocation_scope(this); @@ -1416,7 +1415,7 @@ void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { void BytecodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { // We need this scope because we visit for register values. We have to // maintain a execution result scope where registers can be allocated. - ZoneList* clauses = stmt->cases(); + ZonePtrList* clauses = stmt->cases(); SwitchBuilder switch_builder(builder(), block_coverage_builder_, stmt, clauses->length()); ControlScopeForBreakable scope(this, stmt, &switch_builder); @@ -2315,15 +2314,15 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { } void BytecodeGenerator::BuildArrayLiteralElementsInsertion( - Register array, int first_spread_index, ZoneList* elements, + Register array, int first_spread_index, ZonePtrList* elements, bool skip_constants) { DCHECK_LT(first_spread_index, elements->length()); Register index = register_allocator()->NewRegister(); int array_index = 0; - ZoneList::iterator iter = elements->begin(); - ZoneList::iterator first_spread_or_end = + ZonePtrList::iterator iter = elements->begin(); + ZonePtrList::iterator first_spread_or_end = first_spread_index >= 0 ? elements->begin() + first_spread_index : elements->end(); @@ -3424,7 +3423,7 @@ void BytecodeGenerator::VisitResolvedProperty(ResolvedProperty* expr) { UNREACHABLE(); } -void BytecodeGenerator::VisitArguments(ZoneList* args, +void BytecodeGenerator::VisitArguments(ZonePtrList* args, RegisterList* arg_regs) { // Visit arguments. for (int i = 0; i < static_cast(args->length()); i++) { @@ -3595,7 +3594,7 @@ void BytecodeGenerator::VisitCall(Call* expr) { void BytecodeGenerator::VisitCallSuper(Call* expr) { RegisterAllocationScope register_scope(this); SuperCallReference* super = expr->expression()->AsSuperCallReference(); - ZoneList* args = expr->arguments(); + ZonePtrList* args = expr->arguments(); int first_spread_index = 0; for (; first_spread_index < args->length(); first_spread_index++) { @@ -4309,8 +4308,8 @@ void BytecodeGenerator::VisitGetTemplateObject(GetTemplateObject* expr) { } void BytecodeGenerator::VisitTemplateLiteral(TemplateLiteral* expr) { - const TemplateLiteral::StringList& parts = *expr->string_parts(); - const TemplateLiteral::ExpressionList& substitutions = *expr->substitutions(); + const ZonePtrList& parts = *expr->string_parts(); + const ZonePtrList& substitutions = *expr->substitutions(); // Template strings with no substitutions are turned into StringLiterals. DCHECK_GT(substitutions.length(), 0); DCHECK_EQ(parts.length(), substitutions.length() + 1); diff --git a/deps/v8/src/interpreter/bytecode-generator.h b/deps/v8/src/interpreter/bytecode-generator.h index b02d416860bab5..47ddafbad3f794 100644 --- a/deps/v8/src/interpreter/bytecode-generator.h +++ b/deps/v8/src/interpreter/bytecode-generator.h @@ -43,7 +43,7 @@ class BytecodeGenerator final : public AstVisitor { // Visiting function for declarations list and statements are overridden. void VisitDeclarations(Declaration::List* declarations); - void VisitStatements(ZoneList* statments); + void VisitStatements(ZonePtrList* statments); private: class ContextScope; @@ -100,7 +100,7 @@ class BytecodeGenerator final : public AstVisitor { // Visit the arguments expressions in |args| and store them in |args_regs|, // growing |args_regs| for each argument visited. - void VisitArguments(ZoneList* args, RegisterList* arg_regs); + void VisitArguments(ZonePtrList* args, RegisterList* arg_regs); // Visit a keyed super property load. The optional // |opt_receiver_out| register will have the receiver stored to it @@ -179,7 +179,7 @@ class BytecodeGenerator final : public AstVisitor { FeedbackSlot element_slot); void BuildArrayLiteralElementsInsertion(Register array, int first_spread_index, - ZoneList* elements, + ZonePtrList* elements, bool skip_constants); void AllocateTopLevelRegisters(); diff --git a/deps/v8/src/interpreter/control-flow-builders.cc b/deps/v8/src/interpreter/control-flow-builders.cc index bada935e4a22fb..6b1bdc34240d83 100644 --- a/deps/v8/src/interpreter/control-flow-builders.cc +++ b/deps/v8/src/interpreter/control-flow-builders.cc @@ -13,7 +13,7 @@ namespace interpreter { BreakableControlFlowBuilder::~BreakableControlFlowBuilder() { BindBreakTarget(); DCHECK(break_labels_.empty() || break_labels_.is_bound()); - if (block_coverage_builder_ != nullptr && needs_continuation_counter()) { + if (block_coverage_builder_ != nullptr) { block_coverage_builder_->IncrementBlockCounter( node_, SourceRangeKind::kContinuation); } diff --git a/deps/v8/src/interpreter/control-flow-builders.h b/deps/v8/src/interpreter/control-flow-builders.h index 405e81bc7632da..0bdcb615acaf1f 100644 --- a/deps/v8/src/interpreter/control-flow-builders.h +++ b/deps/v8/src/interpreter/control-flow-builders.h @@ -58,11 +58,6 @@ class V8_EXPORT_PRIVATE BreakableControlFlowBuilder BytecodeLabels* break_labels() { return &break_labels_; } - void set_needs_continuation_counter() { needs_continuation_counter_ = true; } - bool needs_continuation_counter() const { - return needs_continuation_counter_; - } - protected: void EmitJump(BytecodeLabels* labels); void EmitJumpIfTrue(BytecodeArrayBuilder::ToBooleanMode mode, @@ -81,7 +76,6 @@ class V8_EXPORT_PRIVATE BreakableControlFlowBuilder // A continuation counter (for block coverage) is needed e.g. when // encountering a break statement. AstNode* node_; - bool needs_continuation_counter_ = false; BlockCoverageBuilder* block_coverage_builder_; }; @@ -107,7 +101,6 @@ class V8_EXPORT_PRIVATE LoopBuilder final : public BreakableControlFlowBuilder { : BreakableControlFlowBuilder(builder, block_coverage_builder, node), continue_labels_(builder->zone()) { if (block_coverage_builder_ != nullptr) { - set_needs_continuation_counter(); block_coverage_body_slot_ = block_coverage_builder_->AllocateBlockCoverageSlot( node, SourceRangeKind::kBody); diff --git a/deps/v8/src/parsing/expression-scope-reparenter.cc b/deps/v8/src/parsing/expression-scope-reparenter.cc index bdb0aeadd6d637..f3e233f26e9739 100644 --- a/deps/v8/src/parsing/expression-scope-reparenter.cc +++ b/deps/v8/src/parsing/expression-scope-reparenter.cc @@ -55,7 +55,7 @@ void Reparenter::VisitClassLiteral(ClassLiteral* class_literal) { #if DEBUG // The same goes for the rest of the class, but we do some // sanity checking in debug mode. - ZoneList* props = class_literal->properties(); + ZonePtrList* props = class_literal->properties(); for (int i = 0; i < props->length(); ++i) { ClassLiteralProperty* prop = props->at(i); // No need to visit the values, since all values are functions with diff --git a/deps/v8/src/parsing/parse-info.cc b/deps/v8/src/parsing/parse-info.cc index 451d2e81319217..64dee8f6a9e70f 100644 --- a/deps/v8/src/parsing/parse-info.cc +++ b/deps/v8/src/parsing/parse-info.cc @@ -59,7 +59,7 @@ ParseInfo::ParseInfo(Handle shared) set_language_mode(shared->language_mode()); set_asm_wasm_broken(shared->is_asm_wasm_broken()); - Handle