-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v11.x backport] deps: v8, cherry-pick 9365d09 #25728
Closed
+392
−166
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,24 @@ 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 { | ||
public: | ||
explicit BinaryOperationSourceRanges(const SourceRange& right_range) | ||
: right_range_(right_range) {} | ||
|
||
SourceRange GetRange(SourceRangeKind kind) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
DCHECK_EQ(kind, SourceRangeKind::kRight); | ||
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) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
DCHECK_EQ(kind, SourceRangeKind::kContinuation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
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) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
DCHECK_EQ(kind, SourceRangeKind::kBody); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
return body_range_; | ||
} | ||
|
||
bool HasRange(SourceRangeKind kind) override { | ||
return kind == SourceRangeKind::kBody; | ||
} | ||
|
||
private: | ||
SourceRange body_range_; | ||
}; | ||
|
@@ -114,7 +133,7 @@ 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 { | ||
switch (kind) { | ||
case SourceRangeKind::kThen: | ||
return then_range_; | ||
|
@@ -125,6 +144,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 +159,14 @@ 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 { | ||
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,29 +176,52 @@ 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 { | ||
public: | ||
explicit IterationStatementSourceRanges(const SourceRange& body_range) | ||
: body_range_(body_range) {} | ||
|
||
SourceRange GetRange(SourceRangeKind kind) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
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 { | ||
|
@@ -199,6 +246,7 @@ class NaryOperationSourceRanges final : public AstNodeSourceRanges { | |
size_t RangeCount() const { return ranges_.size(); } | ||
|
||
SourceRange GetRange(SourceRangeKind kind) { UNREACHABLE(); } | ||
bool HasRange(SourceRangeKind kind) { return false; } | ||
|
||
private: | ||
ZoneVector<SourceRange> ranges_; | ||
|
@@ -227,39 +275,63 @@ class TryCatchStatementSourceRanges final : public AstNodeSourceRanges { | |
explicit TryCatchStatementSourceRanges(const SourceRange& catch_range) | ||
: catch_range_(catch_range) {} | ||
|
||
SourceRange GetRange(SourceRangeKind kind) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
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 { | ||
public: | ||
explicit TryFinallyStatementSourceRanges(const SourceRange& finally_range) | ||
: finally_range_(finally_range) {} | ||
|
||
SourceRange GetRange(SourceRangeKind kind) { | ||
SourceRange GetRange(SourceRangeKind kind) override { | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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<Statement>* 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<Statement>* 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<Statement>* statements) { | ||
if (statements == nullptr || statements->is_empty()) return; | ||
|
||
Statement* last_statement = statements->last(); | ||
AstNodeSourceRanges* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <unordered_set> | ||
|
||
#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<SourceRangeAstVisitor> { | ||
public: | ||
SourceRangeAstVisitor(uintptr_t stack_limit, Expression* root, | ||
SourceRangeMap* source_range_map); | ||
|
||
private: | ||
friend class AstTraversalVisitor<SourceRangeAstVisitor>; | ||
|
||
void VisitBlock(Block* stmt); | ||
void VisitFunctionLiteral(FunctionLiteral* expr); | ||
bool VisitNode(AstNode* node); | ||
|
||
void MaybeRemoveLastContinuationRange(ZonePtrList<Statement>* stmts); | ||
|
||
SourceRangeMap* source_range_map_ = nullptr; | ||
std::unordered_set<int> continuation_positions_; | ||
}; | ||
|
||
} // namespace internal | ||
} // namespace v8 | ||
|
||
#endif // V8_AST_SOURCE_RANGE_AST_VISITOR_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original this was changed to
DCHECK(HasRange(kind))
as well. Little difference. Just for the record.