Skip to content

Commit f26d1e7

Browse files
committed
[Index] Mark accessors as implicit in modules
These won't have bodies in generated interfaces, and generally aren't useful things to jump to. The property ought to be used instead. rdar://130775560
1 parent bb16e50 commit f26d1e7

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

lib/Index/Index.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
10141014
return true;
10151015
}
10161016

1017+
/// Whether the given decl should be marked implicit in the index data.
1018+
bool hasImplicitRole(Decl *D);
1019+
10171020
bool initIndexSymbol(ValueDecl *D, SourceLoc Loc, bool IsRef,
10181021
IndexSymbol &Info);
10191022
bool initIndexSymbol(ExtensionDecl *D, ValueDecl *ExtendedD, SourceLoc Loc,
@@ -1738,6 +1741,21 @@ bool IndexSwiftASTWalker::reportImplicitConformance(ValueDecl *witness, ValueDec
17381741
return finishCurrentEntity();
17391742
}
17401743

1744+
bool IndexSwiftASTWalker::hasImplicitRole(Decl *D) {
1745+
if (D->isImplicit())
1746+
return true;
1747+
1748+
// Parsed accessors should be treated as implicit in a module since they won't
1749+
// have bodies in the generated interface (even if inlinable), and aren't
1750+
// useful symbols to jump to (the variable itself should be used instead).
1751+
// Currently generated interfaces don't even record USRs for them, so
1752+
// findUSRRange will always fail for them.
1753+
if (isa<AccessorDecl>(D) && IsModuleFile)
1754+
return true;
1755+
1756+
return false;
1757+
}
1758+
17411759
bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
17421760
bool IsRef, IndexSymbol &Info) {
17431761
assert(D);
@@ -1769,7 +1787,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
17691787
addContainedByRelationIfContained(Info);
17701788
} else {
17711789
Info.roles |= (unsigned)SymbolRole::Definition;
1772-
if (D->isImplicit())
1790+
if (hasImplicitRole(D))
17731791
Info.roles |= (unsigned)SymbolRole::Implicit;
17741792
if (auto Group = D->getGroupName())
17751793
Info.group = Group.value();
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Mod.swiftmodule -module-name Mod %s
4+
// RUN: %target-swift-ide-test -print-indexed-symbols -module-to-print Mod -source-filename %s -I %t | %FileCheck %s
5+
6+
// rdar://130775560 - Make sure the accessors are marked implicit in the index
7+
// data for the module.
8+
public struct S {
9+
// CHECK-DAG: instance-property/Swift | x | s:3Mod1SV1xSivp | Def,RelChild
10+
// CHECK-DAG: instance-method/acc-get/Swift | getter:x | s:3Mod1SV1xSivg | Def,Impl,RelChild,RelAcc
11+
public let x = 0
12+
13+
// CHECK-DAG: instance-property/Swift | y | s:3Mod1SV1ySivp | Def,RelChild
14+
// CHECK-DAG: instance-method/acc-get/Swift | getter:y | s:3Mod1SV1ySivg | Def,Impl,RelChild,RelAcc
15+
public var y: Int {
16+
0
17+
}
18+
19+
// CHECK-DAG: instance-property/Swift | z | s:3Mod1SV1zSivp | Def,RelChild
20+
// CHECK-DAG: instance-method/acc-get/Swift | getter:z | s:3Mod1SV1zSivg | Def,Impl,RelChild,RelAcc
21+
// CHECK-DAG: instance-method/acc-set/Swift | setter:z | s:3Mod1SV1zSivs | Def,Impl,RelChild,RelAcc
22+
public var z: Int {
23+
get { 0 }
24+
set {}
25+
}
26+
27+
// CHECK-DAG: instance-property/Swift | a | s:3Mod1SV1aSivp | Def,RelChild
28+
// CHECK-DAG: instance-method/acc-get/Swift | getter:a | s:3Mod1SV1aSivg | Def,Impl,RelChild,RelAcc
29+
public var a: Int {
30+
@inlinable
31+
get { 0 }
32+
}
33+
}

test/SourceKit/Indexing/Inputs/test_module.index.response

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@
9494
key.entities: [
9595
{
9696
key.kind: source.lang.swift.decl.function.accessor.getter,
97-
key.name: "getter:value",
9897
key.usr: "s:11test_module16ComputedPropertyC5valueSivg",
99-
key.is_dynamic: 1
98+
key.is_dynamic: 1,
99+
key.is_implicit: 1
100100
},
101101
{
102102
key.kind: source.lang.swift.decl.function.accessor.setter,
103-
key.name: "setter:value",
104103
key.usr: "s:11test_module16ComputedPropertyC5valueSivs",
105-
key.is_dynamic: 1
104+
key.is_dynamic: 1,
105+
key.is_implicit: 1
106106
}
107107
],
108108
key.effective_access: source.decl.effective_access.public

0 commit comments

Comments
 (0)