Skip to content

Commit 18361c9

Browse files
authored
Merge pull request swiftlang#7166 from akyrtzi/index-system-module-enhancements
[index] Add testing for indexing a system overlay module, along with fine-grained control on the relations we want to index.
2 parents 602235e + a3919f5 commit 18361c9

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

lib/Index/Index.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,13 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
302302
}
303303

304304
void repressRefAtLoc(SourceLoc Loc) {
305+
if (Loc.isInvalid()) return;
305306
assert(!EntitiesStack.empty());
306307
EntitiesStack.back().RefsToSuppress.push_back(Loc);
307308
}
308309

309310
bool isRepressed(SourceLoc Loc) {
310-
if (EntitiesStack.empty())
311+
if (EntitiesStack.empty() || Loc.isInvalid())
311312
return false;
312313
auto &Suppressed = EntitiesStack.back().RefsToSuppress;
313314
return std::find(Suppressed.begin(), Suppressed.end(), Loc) != Suppressed.end();
@@ -786,7 +787,17 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
786787
return !Cancelled;
787788
}
788789

789-
//
790+
static bool hasUsefulRoleInSystemModule(SymbolRoleSet roles) {
791+
return roles | (SymbolRoleSet)SymbolRole::Definition |
792+
(SymbolRoleSet)SymbolRole::Declaration |
793+
(SymbolRoleSet)SymbolRole::RelationChildOf |
794+
(SymbolRoleSet)SymbolRole::RelationBaseOf |
795+
(SymbolRoleSet)SymbolRole::RelationOverrideOf |
796+
(SymbolRoleSet)SymbolRole::RelationExtendedBy |
797+
(SymbolRoleSet)SymbolRole::RelationAccessorOf |
798+
(SymbolRoleSet)SymbolRole::RelationIBTypeOf;
799+
}
800+
790801
bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
791802
IndexSymbol &Info) {
792803
if (!shouldIndex(D))
@@ -803,10 +814,11 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
803814
return true;
804815
}
805816

817+
if (isSystemModule && !hasUsefulRoleInSystemModule(Info.roles))
818+
return true;
806819

807-
if (!startEntity(D, Info)) {
820+
if (!startEntity(D, Info))
808821
return true;
809-
}
810822

811823
// Report the accessors that were utilized.
812824
if (AbstractStorageDecl *ASD = dyn_cast<AbstractStorageDecl>(D)) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module my_system_overlay [system] {
2+
header "my_system_overlay_header.h"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@_exported import my_system_overlay
2+
3+
public func some_func() {}
4+
5+
public class BaseCls {
6+
func theMeth() {}
7+
}
8+
9+
public class SubCls : BaseCls {
10+
override func theMeth() {}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void some_c_func(void);

test/Index/index_system_module.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
//
4+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/my_system_overlay/my_system_overlay.swift -Xcc -I -Xcc %S/Inputs/my_system_overlay
5+
// RUN: %target-swift-ide-test -print-indexed-symbols -module-to-print my_system_overlay -source-filename %s -I %t -Xcc -I -Xcc %S/Inputs/my_system_overlay > %t.out
6+
// RUN: %FileCheck %s -input-file=%t.out
7+
8+
// CHECK: class/Swift | SubCls | [[SUBCLS_USR:.*]] | Def | rel: 0
9+
// CHECK: class/Swift | BaseCls | [[BASECLS_USR:.*]] | Ref,RelBase | rel: 1
10+
// CHECK-NEXT: RelBase | SubCls | [[SUBCLS_USR]]
11+
// CHECK: instance-method/Swift | theMeth() | [[SUBCLSMETH_USR:.*]] | Def,RelChild,RelOver | rel: 2
12+
// CHECK-NEXT: RelOver | theMeth() | [[BASECLSMETH_USR:.*]]
13+
// CHECK-NEXT: RelChild | SubCls | [[SUBCLS_USR]]
14+
// CHECK: class/Swift | BaseCls | [[BASECLS_USR]] | Def | rel: 0
15+
// CHECK: instance-method/Swift | theMeth() | [[BASECLSMETH_USR]] | Def,RelChild | rel: 1
16+
// CHECK-NEXT: RelChild | BaseCls | [[BASECLS_USR]]
17+
// CHECK: function/Swift | some_func() | [[SOMEFUNC_USR:.*]] | Def | rel: 0

0 commit comments

Comments
 (0)