Skip to content

[libSyntax] Don't cache token nodes #36352

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

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/SyntaxParse/SyntaxTreeCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "llvm/ADT/StringRef.h"

namespace swift {
class RawSyntaxTokenCache;
class SourceManager;
class SyntaxParsingCache;
class SourceFile;
Expand Down Expand Up @@ -49,10 +48,6 @@ class SyntaxTreeCreator: public SyntaxParseActions {
/// tree.
SyntaxParsingCache *SyntaxCache;

/// Tokens nodes that have already been created and may be reused in other
/// parts of the syntax tree.
std::unique_ptr<RawSyntaxTokenCache> TokenCache;

public:
SyntaxTreeCreator(SourceManager &SM, unsigned bufferID,
SyntaxParsingCache *syntaxCache,
Expand Down
1 change: 0 additions & 1 deletion lib/SyntaxParse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set_swift_llvm_is_available()
add_swift_host_library(swiftSyntaxParse STATIC
RawSyntaxTokenCache.cpp
SyntaxTreeCreator.cpp)
target_link_libraries(swiftSyntaxParse PRIVATE
swiftParse
Expand Down
87 changes: 0 additions & 87 deletions lib/SyntaxParse/RawSyntaxTokenCache.cpp

This file was deleted.

97 changes: 0 additions & 97 deletions lib/SyntaxParse/RawSyntaxTokenCache.h

This file was deleted.

13 changes: 5 additions & 8 deletions lib/SyntaxParse/SyntaxTreeCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@
#include "swift/AST/Module.h"
#include "swift/AST/SourceFile.h"
#include "swift/Basic/OwnedString.h"
#include "RawSyntaxTokenCache.h"

using namespace swift;
using namespace swift::syntax;

SyntaxTreeCreator::SyntaxTreeCreator(SourceManager &SM, unsigned bufferID,
SyntaxParsingCache *syntaxCache,
RC<syntax::SyntaxArena> arena)
: SM(SM), BufferID(bufferID),
Arena(std::move(arena)),
SyntaxCache(syntaxCache),
TokenCache(new RawSyntaxTokenCache()) {
: SM(SM), BufferID(bufferID), Arena(std::move(arena)),
SyntaxCache(syntaxCache) {
StringRef BufferContent = SM.getEntireTextForBuffer(BufferID);
const char *Data = BufferContent.data();
Arena->copyStringToArenaIfNecessary(Data, BufferContent.size());
Expand Down Expand Up @@ -126,9 +123,9 @@ OpaqueSyntaxNode SyntaxTreeCreator::recordToken(tok tokenKind,
StringRef trailingTriviaText = ArenaSourceBuffer.substr(
trailingTriviaStartOffset, trailingTrivia.size());

auto raw =
TokenCache->getToken(Arena, tokenKind, range.getByteLength(), tokenText,
leadingTriviaText, trailingTriviaText);
auto raw = RawSyntax::make(tokenKind, tokenText, range.getByteLength(),
leadingTriviaText, trailingTriviaText,
SourcePresence::Present, Arena);
return static_cast<OpaqueSyntaxNode>(raw);
}

Expand Down
18 changes: 9 additions & 9 deletions test/Syntax/Inputs/serialize_multiple_decls.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": 17,
"id": 19,
"kind": "SourceFile",
"layout": [
{
"id": 16,
"id": 18,
"kind": "CodeBlockItemList",
"layout": [
{
Expand Down Expand Up @@ -78,11 +78,11 @@
"presence": "Present"
},
{
"id": 14,
"id": 16,
"kind": "CodeBlockItem",
"layout": [
{
"id": 13,
"id": 15,
"kind": "StructDecl",
"layout": [
null,
Expand Down Expand Up @@ -110,11 +110,11 @@
null,
null,
{
"id": 12,
"id": 14,
"kind": "MemberDeclBlock",
"layout": [
{
"id": 3,
"id": 11,
"tokenKind": {
"kind": "l_brace"
},
Expand All @@ -123,13 +123,13 @@
"presence": "Present"
},
{
"id": 11,
"id": 12,
"kind": "MemberDeclList",
"layout": [],
"presence": "Present"
},
{
"id": 5,
"id": 13,
"tokenKind": {
"kind": "r_brace"
},
Expand All @@ -152,7 +152,7 @@
"presence": "Present"
},
{
"id": 15,
"id": 17,
"tokenKind": {
"kind": "eof",
"text": ""
Expand Down
Loading