Skip to content

Commit 1a5bc04

Browse files
authored
Merge pull request #39713 from bnbarham/remove-param-getter-setters
[Index] Do not generate pseudo accessors for parameters
2 parents 8fc1257 + 76e2c7b commit 1a5bc04

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

lib/Index/Index.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
11671167
// Pass accessors.
11681168
if (auto StoreD = dyn_cast<AbstractStorageDecl>(D)) {
11691169
bool usedPseudoAccessors = false;
1170-
if (isa<VarDecl>(D) &&
1170+
if (isa<VarDecl>(D) && !isa<ParamDecl>(D) &&
11711171
!StoreD->getParsedAccessor(AccessorKind::Get) &&
11721172
!StoreD->getParsedAccessor(AccessorKind::Set)) {
11731173
usedPseudoAccessors = true;
@@ -1256,17 +1256,19 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
12561256

12571257
// Report the accessors that were utilized.
12581258
if (auto *ASD = dyn_cast<AbstractStorageDecl>(D)) {
1259-
bool UsesGetter = Info.roles & (SymbolRoleSet)SymbolRole::Read;
1260-
bool UsesSetter = Info.roles & (SymbolRoleSet)SymbolRole::Write;
1259+
if (!isa<ParamDecl>(D)) {
1260+
bool UsesGetter = Info.roles & (SymbolRoleSet)SymbolRole::Read;
1261+
bool UsesSetter = Info.roles & (SymbolRoleSet)SymbolRole::Write;
12611262

1262-
if (UsesGetter)
1263-
if (!reportPseudoAccessor(ASD, AccessorKind::Get, /*IsRef=*/true,
1264-
Loc))
1265-
return false;
1266-
if (UsesSetter)
1267-
if (!reportPseudoAccessor(ASD, AccessorKind::Set, /*IsRef=*/true,
1268-
Loc))
1269-
return false;
1263+
if (UsesGetter)
1264+
if (!reportPseudoAccessor(ASD, AccessorKind::Get, /*IsRef=*/true,
1265+
Loc))
1266+
return false;
1267+
if (UsesSetter)
1268+
if (!reportPseudoAccessor(ASD, AccessorKind::Set, /*IsRef=*/true,
1269+
Loc))
1270+
return false;
1271+
}
12701272
}
12711273

12721274
return finishCurrentEntity();

test/Index/invalid_code.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ extension Protector where T: RangeReplaceableCollection {
4242
func append(_ newElement: T.Iterator.Element) {
4343
undefined { (foo: T) in
4444
// CHECK: [[@LINE-1]]:18 | param(local)/Swift | foo | {{.*}} | Def,RelChild
45-
// CHECK: [[@LINE-2]]:18 | function/acc-get(local)/Swift | getter:foo | {{.*}} | Def,Impl,RelChild,RelAcc
46-
// CHECK: [[@LINE-3]]:18 | function/acc-set(local)/Swift | setter:foo | {{.*}} | Def,Impl,RelChild,RelAcc
4745
_ = newElement
4846
}
4947
}

test/Index/local.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
// RUN: %target-swift-ide-test -print-indexed-symbols -include-locals -source-filename %s | %FileCheck -check-prefix=LOCAL %s
33

44
func foo(a: Int, b: Int, c: Int) {
5+
// CHECK-NOT: [[@LINE-1]]:10 | function/acc-get/Swift | getter:a
6+
// CHECK-NOT: [[@LINE-1]]:10 | function/acc-set/Swift | setter:a
7+
58
let x = a + b
69
// LOCAL: [[@LINE-1]]:9 | variable(local)/Swift | x | [[x_USR:.*]] | Def,RelChild | rel: 1
710
// CHECK-NOT: [[@LINE-2]]:9 | variable(local)/Swift | x | {{.*}} | Def,RelChild | rel: 1
11+
// LOCAL-NOT: [[@LINE-3]]:13 | function/acc-get/Swift | getter:a
812

913
let y = x + c
1014
// LOCAL: [[@LINE-1]]:9 | variable(local)/Swift | y | [[y_USR:.*]] | Def,RelChild | rel: 1

0 commit comments

Comments
 (0)