Skip to content

Commit 9999d88

Browse files
authored
Merge pull request swiftlang#75171 from hamishknight/mod-access-6.0
[6.0] [Index] Mark accessors as implicit in modules
2 parents ba4165a + 3ea9a82 commit 9999d88

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

lib/Index/Index.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,9 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
10131013
return true;
10141014
}
10151015

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

1743+
bool IndexSwiftASTWalker::hasImplicitRole(Decl *D) {
1744+
if (D->isImplicit())
1745+
return true;
1746+
1747+
// Parsed accessors should be treated as implicit in a module since they won't
1748+
// have bodies in the generated interface (even if inlinable), and aren't
1749+
// useful symbols to jump to (the variable itself should be used instead).
1750+
// Currently generated interfaces don't even record USRs for them, so
1751+
// findUSRRange will always fail for them.
1752+
if (isa<AccessorDecl>(D) && IsModuleFile)
1753+
return true;
1754+
1755+
return false;
1756+
}
1757+
17401758
bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
17411759
bool IsRef, IndexSymbol &Info) {
17421760
assert(D);
@@ -1768,7 +1786,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
17681786
addContainedByRelationIfContained(Info);
17691787
} else {
17701788
Info.roles |= (unsigned)SymbolRole::Definition;
1771-
if (D->isImplicit())
1789+
if (hasImplicitRole(D))
17721790
Info.roles |= (unsigned)SymbolRole::Implicit;
17731791
if (auto Group = D->getGroupName())
17741792
Info.group = Group.value();
Lines changed: 33 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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)