Skip to content

Commit 03a7042

Browse files
committed
[libSyntax] Disable caching of token nodes
Since nodes have unique IDs now, we cannot reuse the nodes at multiple locations in the source file
1 parent 4516873 commit 03a7042

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

lib/Syntax/SyntaxArena.cpp

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ struct SyntaxArena::Implementation {
2929
/// List of pointers to the allocated RawSyntax
3030
std::vector<RawSyntax *> AllocatedRawSyntaxList;
3131

32-
/// Cached Tokens.
33-
llvm::FoldingSet<RawSyntaxCacheNode> CachedTokens;
34-
3532
Implementation() = default;
3633
void *Allocate(size_t size, size_t alignment) {
3734
return Allocator.Allocate(size, alignment);
@@ -125,38 +122,6 @@ RC<RawSyntax> RawSyntax::getToken(SyntaxArena &Arena, tok TokKind,
125122
llvm::ArrayRef<TriviaPiece> LeadingTrivia,
126123
llvm::ArrayRef<TriviaPiece> TrailingTrivia) {
127124

128-
// Determine whether this token is worth to cache.
129-
if (
130-
// Is string_literal with >16 length.
131-
(TokKind == tok::string_literal && Text.size() > 16) ||
132-
// Has leading comment trivia et al.
133-
any_of(LeadingTrivia,
134-
[](const syntax::TriviaPiece &T) { return T.getText().size(); }) ||
135-
// Has trailing comment trivia et al.
136-
any_of(TrailingTrivia,
137-
[](const syntax::TriviaPiece &T) { return T.getText().size(); })) {
138-
139-
// Do not use cache.
140-
return RawSyntax::make(TokKind, Text, LeadingTrivia, TrailingTrivia,
141-
SourcePresence::Present, &Arena);
142-
}
143-
144-
// This node is cacheable. Get or create.
145-
auto &CachedTokens = Arena.Impl.CachedTokens;
146-
147-
llvm::FoldingSetNodeID ID;
148-
RawSyntax::Profile(ID, TokKind, Text, LeadingTrivia, TrailingTrivia);
149-
150-
void *insertPos = nullptr;
151-
if (auto existing = CachedTokens.FindNodeOrInsertPos(ID, insertPos))
152-
// Found in the cache. Just return it.
153-
return existing->get();
154-
155-
// Could not found in the cache. Create it.
156-
auto Raw = RawSyntax::make(TokKind, Text, LeadingTrivia, TrailingTrivia,
157-
SourcePresence::Present, &Arena);
158-
auto IDRef = ID.Intern(Arena.getAllocator());
159-
auto CacheNode = new (Arena) RawSyntaxCacheNode(Raw.get(), IDRef);
160-
CachedTokens.InsertNode(CacheNode, insertPos);
161-
return Raw;
125+
return RawSyntax::make(TokKind, Text, LeadingTrivia, TrailingTrivia,
126+
SourcePresence::Present, &Arena);
162127
}

0 commit comments

Comments
 (0)