mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[libSyntax] Remove incremental JSON transfer option
We were only keeping track of `RawSyntax` node IDs to incrementally transfer a syntax tree via JSON. However, AFAICT the incremental JSON transfer option has been superceeded by `SyntaxParseActions`, which are more efficient. So, let’s clean up and remove the `RawSyntax` node ID and JSON incremental transfer option. In places that still need a notion of `RawSyntax` identity (like determining the reused syntax regions), use the `RawSyntax`’s pointer instead of the manually created ID. In `incr_transfer_round_trip.py` always use the code path that uses the `SyntaxParseActions` and remove the transitional code that was still using the incremental JSON transfer but was never called.
This commit is contained in:
@@ -111,7 +111,7 @@ llvm::Optional<Syntax> SyntaxParsingCache::lookUp(size_t NewPosition,
|
||||
|
||||
auto Node = lookUpFrom(OldSyntaxTree, /*NodeStart=*/0, *OldPosition, Kind);
|
||||
if (Node.hasValue()) {
|
||||
ReusedNodeIds.insert(Node->getId());
|
||||
ReusedNodes.insert(Node->getRaw());
|
||||
}
|
||||
return Node;
|
||||
}
|
||||
@@ -120,16 +120,16 @@ std::vector<SyntaxReuseRegion>
|
||||
SyntaxParsingCache::getReusedRegions(const SourceFileSyntax &SyntaxTree) const {
|
||||
/// Determines the reused source regions from reused syntax node IDs
|
||||
class ReusedRegionsCollector : public SyntaxVisitor {
|
||||
std::unordered_set<SyntaxNodeId> ReusedNodeIds;
|
||||
std::unordered_set<const RawSyntax *> ReusedNodes;
|
||||
std::vector<SyntaxReuseRegion> ReusedRegions;
|
||||
|
||||
bool didReuseNode(SyntaxNodeId NodeId) {
|
||||
return ReusedNodeIds.count(NodeId) > 0;
|
||||
bool didReuseNode(const RawSyntax *Node) {
|
||||
return ReusedNodes.count(Node) > 0;
|
||||
}
|
||||
|
||||
public:
|
||||
ReusedRegionsCollector(std::unordered_set<SyntaxNodeId> ReusedNodeIds)
|
||||
: ReusedNodeIds(ReusedNodeIds) {}
|
||||
ReusedRegionsCollector(std::unordered_set<const RawSyntax *> ReusedNodes)
|
||||
: ReusedNodes(ReusedNodes) {}
|
||||
|
||||
const std::vector<SyntaxReuseRegion> &getReusedRegions() {
|
||||
std::sort(ReusedRegions.begin(), ReusedRegions.end(),
|
||||
@@ -141,7 +141,7 @@ SyntaxParsingCache::getReusedRegions(const SourceFileSyntax &SyntaxTree) const {
|
||||
}
|
||||
|
||||
void visit(Syntax Node) override {
|
||||
if (didReuseNode(Node.getId())) {
|
||||
if (didReuseNode(Node.getRaw())) {
|
||||
// Node has been reused, add it to the list
|
||||
auto Start = Node.getAbsolutePositionBeforeLeadingTrivia();
|
||||
auto End = Node.getAbsoluteEndPositionAfterTrailingTrivia();
|
||||
@@ -158,7 +158,7 @@ SyntaxParsingCache::getReusedRegions(const SourceFileSyntax &SyntaxTree) const {
|
||||
}
|
||||
};
|
||||
|
||||
ReusedRegionsCollector ReuseRegionsCollector(getReusedNodeIds());
|
||||
ReusedRegionsCollector ReuseRegionsCollector(getReusedNodes());
|
||||
ReuseRegionsCollector.collectReusedRegions(SyntaxTree);
|
||||
return ReuseRegionsCollector.getReusedRegions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user