Skip to content

Commit 069db6e

Browse files
author
David Ungar
authored
Merge pull request #28038 from davidungar/rdar-56760957-dont-do-ide-lookups-into-inactive-clauses
[SourceKit NameLookup] Don't walk into inactive clauses.
2 parents 6d02fb7 + cd95ddb commit 069db6e

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ class ASTScope {
627627
return Mem;
628628
}
629629

630+
static bool areInactiveIfConfigClausesSupported();
631+
630632
private:
631633
static ast_scope::ASTSourceFileScope *createScopeTree(SourceFile *);
632634
};

lib/AST/ASTScopeCreation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ void ASTScope::
731731
impl->buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals();
732732
}
733733

734+
bool ASTScope::areInactiveIfConfigClausesSupported() {
735+
return ScopeCreator::includeInactiveIfConfigClauses;
736+
}
737+
734738
ASTSourceFileScope *ASTScope::createScopeTree(SourceFile *SF) {
735739
ScopeCreator *scopeCreator = new (SF->getASTContext()) ScopeCreator(SF);
736740
return scopeCreator->sourceFileScope;

lib/IDE/SyntaxModel.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "swift/AST/ASTWalker.h"
1616
#include "swift/AST/Decl.h"
1717
#include "swift/AST/Expr.h"
18+
#include "swift/AST/NameLookup.h"
1819
#include "swift/AST/Pattern.h"
1920
#include "swift/AST/ParameterList.h"
2021
#include "swift/AST/Module.h"
@@ -346,6 +347,21 @@ class ModelASTWalker : public ASTWalker {
346347
/// is considered as one, e.g. object literal expression.
347348
uint8_t AvoidPassingSyntaxToken = 0;
348349

350+
class InactiveClauseRAII {
351+
const bool wasInInactiveClause;
352+
bool &isInInactiveClause;
353+
354+
public:
355+
InactiveClauseRAII(bool &isInInactiveClauseArg, bool enteringInactiveClause)
356+
: wasInInactiveClause(isInInactiveClauseArg),
357+
isInInactiveClause(isInInactiveClauseArg) {
358+
isInInactiveClause |= enteringInactiveClause;
359+
}
360+
~InactiveClauseRAII() { isInInactiveClause = wasInInactiveClause; }
361+
};
362+
friend class InactiveClauseRAII;
363+
bool inInactiveClause = false;
364+
349365
public:
350366
SyntaxModelWalker &Walker;
351367
ArrayRef<SyntaxNode> TokenNodes;
@@ -890,7 +906,8 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
890906
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
891907
// Normally bindExtension() would take care of computing the extended
892908
// nominal. It must be done before asking for generic parameters.
893-
ED->computeExtendedNominal();
909+
if (!inInactiveClause || ASTScope::areInactiveIfConfigClausesSupported())
910+
ED->computeExtendedNominal();
894911
SyntaxStructureNode SN;
895912
setDecl(SN, D);
896913
SN.Kind = SyntaxStructureKind::Extension;
@@ -967,6 +984,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
967984
if (Clause.Cond && !annotateIfConfigConditionIdentifiers(Clause.Cond))
968985
return false;
969986

987+
InactiveClauseRAII inactiveClauseRAII(inInactiveClause, !Clause.isActive);
970988
for (auto &Element : Clause.Elements) {
971989
if (auto *E = Element.dyn_cast<Expr*>()) {
972990
E->walk(*this);

0 commit comments

Comments
 (0)