-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
deps: v8, cherry-pick 9365d09, aac2f8c, 47d34a3 #25429
Closed
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
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 |
---|---|---|
@@ -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.
statements
is sometimes anullptr
, which was leading to a segfault. This does not seem to be possible in the mainline v8; my guess is that a patch that has not been back-ported eliminated the possibility ofexpr->body()
returning anullptr
. It felt like a reasonable stop gap (until we land a fully updated v8) to add the checkstatements == nullptr
.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.
I think this is the relevant change.