mirrored from https://chromium.googlesource.com/v8/v8.git
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <yangguo@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#58443}
- Loading branch information
Showing
12 changed files
with
382 additions
and
162 deletions.
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 |
---|---|---|
@@ -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->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_ |
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
Oops, something went wrong.