Skip to content

Commit 9936f64

Browse files
committed
Ignore inactive IfConfigDecls in SourceKit's syntax model
Clients that need syntactic information should use SourceKit-LSP or swift-syntax.
1 parent 70c93c6 commit 9936f64

File tree

8 files changed

+24
-914
lines changed

8 files changed

+24
-914
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
66
## Swift (next)
77

8+
* Syntactic SourceKit queries no longer attempt to provide information
9+
within the inactive `#if` regions. For example, given:
10+
11+
```swift
12+
#if DEBUG
13+
extension MyType: CustomDebugStringConvertible {
14+
var debugDescription: String { ... }
15+
}
16+
#endif
17+
```
18+
19+
If `DEBUG` is not set, SourceKit results will not involve the
20+
inactive code. Clients should use either SourceKit-LSP or
21+
swift-syntax for syntactic queries that are independent of the
22+
specific build configuration.
23+
824
* [SE-0442][]:
925
TaskGroups can now be created without explicitly specifying their child task's result types:
1026

lib/IDE/SyntaxModel.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ class ModelASTWalker : public ASTWalker {
416416
private:
417417
static bool findUrlStartingLoc(StringRef Text, unsigned &Start,
418418
std::regex& Regex);
419-
bool annotateIfConfigConditionIdentifiers(Expr *Cond);
420419
bool handleAttrs(const ParsedDeclAttributes &Attrs);
421420
bool handleAttrs(ArrayRef<TypeOrCustomAttr> Attrs);
422421

@@ -1003,24 +1002,8 @@ ASTWalker::PreWalkAction ModelASTWalker::walkToDeclPre(Decl *D) {
10031002
}
10041003
pushStructureNode(SN, VD);
10051004

1006-
} else if (auto *ConfigD = dyn_cast<IfConfigDecl>(D)) {
1007-
for (auto &Clause : ConfigD->getClauses()) {
1008-
if (Clause.Cond && !annotateIfConfigConditionIdentifiers(Clause.Cond))
1009-
return Action::SkipNode();
1010-
1011-
InactiveClauseRAII inactiveClauseRAII(inInactiveClause, !Clause.isActive);
1012-
for (auto &Element : Clause.Elements) {
1013-
if (auto *E = Element.dyn_cast<Expr*>()) {
1014-
E->walk(*this);
1015-
} else if (auto *S = Element.dyn_cast<Stmt*>()) {
1016-
S->walk(*this);
1017-
} else {
1018-
Element.get<Decl*>()->walk(*this);
1019-
}
1020-
NodesVisitedBefore.insert(Element);
1021-
}
1022-
}
1023-
1005+
} else if (isa<IfConfigDecl>(D)) {
1006+
// Note: nothing to do.
10241007
} else if (auto *EnumCaseD = dyn_cast<EnumCaseDecl>(D)) {
10251008
SyntaxStructureNode SN;
10261009
setDecl(SN, D);
@@ -1172,17 +1155,6 @@ class IdRefWalker : public ASTWalker {
11721155
};
11731156
} // end anonymous namespace
11741157

1175-
bool ModelASTWalker::annotateIfConfigConditionIdentifiers(Expr *Cond) {
1176-
if (!Cond)
1177-
return true;
1178-
auto passNode = [&](CharSourceRange R) {
1179-
return passNonTokenNode({ SyntaxNodeKind::BuildConfigId, R });
1180-
};
1181-
1182-
IdRefWalker<decltype(passNode)> Walker(passNode);
1183-
return Cond->walk(Walker);
1184-
}
1185-
11861158
bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D,
11871159
ArrayRef<Token> Toks) {
11881160
if (!D)

0 commit comments

Comments
 (0)