Skip to content

Commit 9ff5d88

Browse files
committed
Remove SourceKit Support for the libSyntax Tree
1 parent 53029f0 commit 9ff5d88

File tree

23 files changed

+41
-435
lines changed

23 files changed

+41
-435
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,9 @@ namespace swift {
7575
class ValueDecl;
7676
class VarDecl;
7777
class VisibleDeclConsumer;
78-
class SyntaxParsingCache;
7978
class ASTScope;
8079
class SourceLookupCache;
8180

82-
namespace syntax {
83-
class SourceFileSyntax;
84-
}
8581
namespace ast_scope {
8682
class ASTSourceFileScope;
8783
}

include/swift/AST/ParseRequests.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/AST/SimpleRequest.h"
2222
#include "swift/Basic/Fingerprint.h"
2323
#include "swift/Parse/Token.h"
24-
#include "swift/Syntax/SyntaxNodes.h"
2524

2625
namespace swift {
2726

@@ -90,7 +89,6 @@ struct SourceFileParsingResult {
9089
ArrayRef<ASTNode> TopLevelItems;
9190
Optional<ArrayRef<Token>> CollectedTokens;
9291
Optional<StableHasher> InterfaceHasher;
93-
Optional<syntax::SourceFileSyntax> SyntaxRoot;
9492
};
9593

9694
/// Parse the top-level items of a SourceFile.

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ class SourceFile final : public FileUnit {
7878
/// and the associated language option.
7979
DisablePoundIfEvaluation = 1 << 1,
8080

81-
/// Whether to build a syntax tree.
82-
BuildSyntaxTree = 1 << 2,
83-
8481
/// Whether to save the file's parsed tokens.
85-
CollectParsedTokens = 1 << 3,
82+
CollectParsedTokens = 1 << 2,
8683

8784
/// Whether to compute the interface hash of the file.
88-
EnableInterfaceHash = 1 << 4,
85+
EnableInterfaceHash = 1 << 3,
8986

9087
/// Whether to suppress warnings when parsing. This is set for secondary
9188
/// files, as they get parsed multiple times.
92-
SuppressWarnings = 1 << 5,
89+
SuppressWarnings = 1 << 4,
9390
};
9491
using ParsingOptions = OptionSet<ParsingFlags>;
9592

@@ -248,10 +245,6 @@ class SourceFile final : public FileUnit {
248245
/// code for it. Note this method returns \c false in WMO.
249246
bool isPrimary() const { return IsPrimary; }
250247

251-
/// A cache of syntax nodes that can be reused when creating the syntax tree
252-
/// for this file.
253-
swift::SyntaxParsingCache *SyntaxParsingCache = nullptr;
254-
255248
/// The list of local type declarations in the source file.
256249
llvm::SetVector<TypeDecl *> LocalTypeDecls;
257250

@@ -633,14 +626,10 @@ class SourceFile final : public FileUnit {
633626
/// them to be accessed from \c getAllTokens.
634627
bool shouldCollectTokens() const;
635628

636-
bool shouldBuildSyntaxTree() const;
637-
638629
/// Whether the bodies of types and functions within this file can be lazily
639630
/// parsed.
640631
bool hasDelayedBodyParsing() const;
641632

642-
syntax::SourceFileSyntax getSyntaxRoot() const;
643-
644633
OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName) override;
645634

646635
/// Do not call when inside an inactive clause (\c
@@ -660,9 +649,6 @@ class SourceFile final : public FileUnit {
660649
/// If not \c None, the underlying vector contains the parsed tokens of this
661650
/// source file.
662651
Optional<ArrayRef<Token>> AllCollectedTokens;
663-
664-
/// The root of the syntax tree representing the source file.
665-
std::unique_ptr<syntax::SourceFileSyntax> SyntaxRoot;
666652
};
667653

668654
inline SourceFile::ParsingOptions operator|(SourceFile::ParsingFlags lhs,

include/swift/IDE/CompletionLookup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/IDE/CodeCompletionResult.h"
2727
#include "swift/IDE/CodeCompletionStringPrinter.h"
2828
#include "swift/IDE/PossibleParamInfo.h"
29+
#include "swift/Parse/CodeCompletionCallbacks.h"
2930
#include "swift/Sema/IDETypeChecking.h"
3031
#include "swift/Strings.h"
3132

@@ -599,7 +600,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
599600

600601
void collectPrecedenceGroups();
601602

602-
void getPrecedenceGroupCompletions(syntax::SyntaxKind SK);
603+
void getPrecedenceGroupCompletions(CodeCompletionCallbacks::PrecedenceGroupCompletionKind SK);
603604

604605
void getPoundAvailablePlatformCompletions();
605606

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,15 @@ class CodeCompletionCallbacks {
192192
/// Complete 'async' and 'throws' at effects specifier position.
193193
virtual void completeEffectsSpecifier(bool hasAsync, bool hasThrows) {};
194194

195+
enum class PrecedenceGroupCompletionKind {
196+
Relation,
197+
Associativity,
198+
AttributeList,
199+
Assignment,
200+
};
195201
/// Complete within a precedence group decl or after a colon in an
196202
/// operator decl.
197-
virtual void completeInPrecedenceGroup(SyntaxKind SK) {};
203+
virtual void completeInPrecedenceGroup(PrecedenceGroupCompletionKind SK) {};
198204

199205
/// Complete the platform names inside #available statements.
200206
virtual void completePoundAvailablePlatform() {};

lib/IDE/CodeCompletion.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
123123
/// In situations when \c SyntaxKind hints or determines
124124
/// completions, i.e. a precedence group attribute, this
125125
/// can be set and used to control the code completion scenario.
126-
SyntaxKind SyntxKind;
126+
CodeCompletionCallbacks::PrecedenceGroupCompletionKind SyntxKind;
127127

128128
int AttrParamIndex;
129129
bool IsInSil = false;
@@ -256,7 +256,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
256256
void completeDeclAttrBeginning(bool Sil, bool isIndependent) override;
257257
void completeDeclAttrParam(DeclAttrKind DK, int Index) override;
258258
void completeEffectsSpecifier(bool hasAsync, bool hasThrows) override;
259-
void completeInPrecedenceGroup(SyntaxKind SK) override;
259+
void completeInPrecedenceGroup(CodeCompletionCallbacks::PrecedenceGroupCompletionKind SK) override;
260260
void completeNominalMemberBeginning(
261261
SmallVectorImpl<StringRef> &Keywords, SourceLoc introducerLoc) override;
262262
void completeAccessorBeginning(CodeCompletionExpr *E) override;
@@ -466,7 +466,7 @@ void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(
466466
AttTargetIsIndependent = isIndependent;
467467
}
468468

469-
void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(SyntaxKind SK) {
469+
void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(CodeCompletionCallbacks::PrecedenceGroupCompletionKind SK) {
470470
assert(P.Tok.is(tok::code_complete));
471471

472472
SyntxKind = SK;
@@ -805,7 +805,7 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
805805

806806
#define DECL_KEYWORD(kw) \
807807
AddDeclKeyword(#kw, CodeCompletionKeywordKind::kw_##kw, None);
808-
#include "swift/Syntax/TokenKinds.def"
808+
#include "swift/AST/TokenKinds.def"
809809
// Manually add "actor" because it's a contextual keyword.
810810
AddDeclKeyword("actor", CodeCompletionKeywordKind::None, None);
811811

@@ -842,7 +842,7 @@ static void addStmtKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
842842
addKeyword(Sink, Name, Kind, "", flair);
843843
};
844844
#define STMT_KEYWORD(kw) AddStmtKeyword(#kw, CodeCompletionKeywordKind::kw_##kw);
845-
#include "swift/Syntax/TokenKinds.def"
845+
#include "swift/AST/TokenKinds.def"
846846
}
847847

848848
static void addCaseStmtKeywords(CodeCompletionResultSink &Sink) {

lib/IDE/CodeCompletionResult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void CodeCompletionResult::printPrefix(raw_ostream &OS) const {
455455
case CodeCompletionKeywordKind::pound_##X: \
456456
Prefix.append("[#" #X "]"); \
457457
break;
458-
#include "swift/Syntax/TokenKinds.def"
458+
#include "swift/AST/TokenKinds.def"
459459
}
460460
break;
461461
case CodeCompletionResultKind::Pattern:

lib/IDE/CompletionLookup.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
#include "ExprContextAnalysis.h"
1616
#include "swift/AST/ParameterList.h"
1717
#include "swift/AST/SourceFile.h"
18-
#include "swift/Syntax/SyntaxKind.h"
19-
#include "swift/Syntax/TokenKinds.h"
2018

2119
using namespace swift;
2220
using namespace swift::ide;
23-
using swift::syntax::SyntaxKind;
2421

2522
namespace {
2623

@@ -3050,31 +3047,30 @@ void CompletionLookup::collectPrecedenceGroups() {
30503047
}
30513048
}
30523049

3053-
void CompletionLookup::getPrecedenceGroupCompletions(SyntaxKind SK) {
3050+
void CompletionLookup::getPrecedenceGroupCompletions(CodeCompletionCallbacks::PrecedenceGroupCompletionKind SK) {
30543051
switch (SK) {
3055-
case SyntaxKind::PrecedenceGroupAssociativity:
3052+
case CodeCompletionCallbacks::PrecedenceGroupCompletionKind::Associativity:
30563053
addKeyword(getAssociativitySpelling(Associativity::None));
30573054
addKeyword(getAssociativitySpelling(Associativity::Left));
30583055
addKeyword(getAssociativitySpelling(Associativity::Right));
3059-
break;
3060-
case SyntaxKind::PrecedenceGroupAssignment:
3056+
return;
3057+
case CodeCompletionCallbacks::PrecedenceGroupCompletionKind::Assignment:
30613058
addKeyword(getTokenText(tok::kw_false), Type(), SemanticContextKind::None,
30623059
CodeCompletionKeywordKind::kw_false);
30633060
addKeyword(getTokenText(tok::kw_true), Type(), SemanticContextKind::None,
30643061
CodeCompletionKeywordKind::kw_true);
3065-
break;
3066-
case SyntaxKind::PrecedenceGroupAttributeList:
3062+
return;
3063+
case CodeCompletionCallbacks::PrecedenceGroupCompletionKind::AttributeList:
30673064
addKeyword("associativity");
30683065
addKeyword("higherThan");
30693066
addKeyword("lowerThan");
30703067
addKeyword("assignment");
3071-
break;
3072-
case SyntaxKind::PrecedenceGroupRelation:
3068+
return;
3069+
case CodeCompletionCallbacks::PrecedenceGroupCompletionKind::Relation:
30733070
collectPrecedenceGroups();
3074-
break;
3075-
default:
3076-
llvm_unreachable("not a precedencegroup SyntaxKind");
3071+
return;
30773072
}
3073+
llvm_unreachable("not a precedencegroup SyntaxKind");
30783074
}
30793075

30803076
void CompletionLookup::getPoundAvailablePlatformCompletions() {

lib/IDETool/CompletionInstance.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,6 @@ void swift::ide::CompletionInstance::performOperation(
567567
// because they're somewhat heavy operations and aren't needed for completion.
568568
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
569569

570-
// Disable to build syntax tree because code-completion skips some portion of
571-
// source text. That breaks an invariant of syntax tree building.
572-
Invocation.getLangOptions().BuildSyntaxTree = false;
573-
574570
// We don't need token list.
575571
Invocation.getLangOptions().CollectParsedToken = false;
576572

test/SourceKit/SyntaxTree/basic.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)