Skip to content

Commit ef4e84b

Browse files
committed
[index] Subsume CallRefIndexSymbol into IndexSymbol
Eventually we should just have one IndexSymbol, with all the information. Once we kill FuncDeclIndexSymbol and can get rid of the enum, we will regain most of the bytes we lost by inlining receiverUSR.
1 parent 50eeeb7 commit ef4e84b

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ using SymbolRole = clang::index::SymbolRole;
7878
using SymbolRoleSet = clang::index::SymbolRoleSet;
7979

8080
struct IndexSymbol {
81-
enum TypeKind { Base, FuncDecl, CallReference };
81+
enum TypeKind { Base, FuncDecl };
8282
TypeKind entityType = Base;
8383

8484
SymbolKind kind;
@@ -89,6 +89,7 @@ struct IndexSymbol {
8989
StringRef name;
9090
StringRef USR; // USR may be safely compared by pointer.
9191
StringRef group;
92+
StringRef receiverUSR;
9293
unsigned line = 0;
9394
unsigned column = 0;
9495

@@ -104,10 +105,6 @@ struct FuncDeclIndexSymbol : public IndexSymbol {
104105
FuncDeclIndexSymbol() : IndexSymbol(FuncDecl) {}
105106
};
106107

107-
struct CallRefIndexSymbol : public IndexSymbol {
108-
StringRef ReceiverUSR;
109-
CallRefIndexSymbol() : IndexSymbol(CallReference) {}
110-
};
111108

112109
SymbolKind getSymbolKindForDecl(const Decl *D);
113110

lib/Index/Index.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
280280
IndexSymbol &Info);
281281
bool initFuncDeclIndexSymbol(ValueDecl *D, FuncDeclIndexSymbol &Info);
282282
bool initCallRefIndexSymbol(Expr *CurrentE, Expr *ParentE, ValueDecl *D,
283-
SourceLoc Loc, CallRefIndexSymbol &Info);
283+
SourceLoc Loc, IndexSymbol &Info);
284284

285285
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
286286
if (Loc.isInvalid())
@@ -481,7 +481,7 @@ bool IndexSwiftASTWalker::startEntityRef(ValueDecl *D, SourceLoc Loc) {
481481
return false;
482482

483483
if (isa<AbstractFunctionDecl>(D)) {
484-
CallRefIndexSymbol Info;
484+
IndexSymbol Info;
485485
if (initCallRefIndexSymbol(ExprStack.back(), getParentExpr(), D, Loc, Info))
486486
return false;
487487

@@ -590,7 +590,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
590590
};
591591

592592
if (IsRef) {
593-
CallRefIndexSymbol Info;
593+
IndexSymbol Info;
594594
if (initCallRefIndexSymbol(ExprStack.back(), getParentExpr(), D, Loc, Info))
595595
return true; // continue walking.
596596

@@ -860,7 +860,7 @@ static bool isDynamicCall(Expr *BaseE, ValueDecl *D) {
860860

861861
bool IndexSwiftASTWalker::initCallRefIndexSymbol(Expr *CurrentE, Expr *ParentE,
862862
ValueDecl *D, SourceLoc Loc,
863-
CallRefIndexSymbol &Info) {
863+
IndexSymbol &Info) {
864864
if (!ParentE)
865865
return true;
866866

@@ -888,7 +888,7 @@ bool IndexSwiftASTWalker::initCallRefIndexSymbol(Expr *CurrentE, Expr *ParentE,
888888

889889
if (auto TyD = ReceiverTy->getAnyNominal()) {
890890
StringRef unused;
891-
if (getNameAndUSR(TyD, unused, Info.ReceiverUSR))
891+
if (getNameAndUSR(TyD, unused, Info.receiverUSR))
892892
return true;
893893
if (isDynamicCall(BaseE, D))
894894
Info.roles |= (unsigned)SymbolRole::Dynamic;

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ class SKIndexDataConsumer : public IndexDataConsumer {
103103
info.Column = symbol.column;
104104
};
105105

106+
if (symbol.roles & (unsigned)SymbolRole::Call) {
107+
assert(symbol.entityType == IndexSymbol::Base);
108+
CallRefEntityInfo info;
109+
initEntity(info, symbol);
110+
info.ReceiverUSR = symbol.receiverUSR;
111+
info.IsDynamic = symbol.roles & (unsigned)SymbolRole::Dynamic;
112+
return func(info);
113+
}
114+
106115
switch (symbol.entityType) {
107116
case IndexSymbol::Base: {
108117
EntityInfo info;
@@ -116,14 +125,6 @@ class SKIndexDataConsumer : public IndexDataConsumer {
116125
static_cast<const FuncDeclIndexSymbol &>(symbol).IsTestCandidate;
117126
return func(info);
118127
}
119-
case IndexSymbol::CallReference: {
120-
CallRefEntityInfo info;
121-
initEntity(info, symbol);
122-
auto call = static_cast<const CallRefIndexSymbol &>(symbol);
123-
info.ReceiverUSR = call.ReceiverUSR;
124-
info.IsDynamic = call.roles & (unsigned)SymbolRole::Dynamic;
125-
return func(info);
126-
}
127128
}
128129
llvm_unreachable("unexpected symbol kind");
129130
}

0 commit comments

Comments
 (0)