Skip to content

Commit eedf288

Browse files
author
Nathan Hawes
authored
Merge pull request #7820 from nathawes/rdar30098853
[indexer] report defs/refs of parameters without a separate external name
2 parents 9c39793 + 2684564 commit eedf288

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

lib/Index/Index.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
400400
}
401401

402402
bool isLocal(ValueDecl *D) const {
403-
return D->getDeclContext()->getLocalContext();
403+
return D->getDeclContext()->getLocalContext() &&
404+
(!isa<ParamDecl>(D) || cast<ParamDecl>(D)->getArgumentNameLoc().isValid());
404405
}
405406

406407
void getModuleHash(SourceFileOrModule SFOrMod, llvm::raw_ostream &OS);

lib/Index/IndexSymbol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ SymbolInfo index::getSymbolInfoForDecl(const Decl *D) {
112112
info.SubKind = SymbolSubKind::SwiftSubscript;
113113
break;
114114
case DeclKind::Constructor: info.Kind = SymbolKind::Constructor; break;
115-
case DeclKind::Destructor: info.Kind = SymbolKind::Destructor; break;;
115+
case DeclKind::Destructor: info.Kind = SymbolKind::Destructor; break;
116116
case DeclKind::Param:
117-
llvm_unreachable("unexpected parameter seen while indexing");
118-
117+
info.Kind = SymbolKind::Parameter;
118+
break;
119119
case DeclKind::Func:
120120
setFuncSymbolInfo(cast<FuncDecl>(D), info);
121121
break;

test/Index/kinds.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ struct AStruct {
4343
class AClass {
4444
// CHECK: [[@LINE-1]]:7 | class/Swift | AClass | s:14swift_ide_test6AClassC | Def | rel: 0
4545

46-
// InstanceMethod
47-
func instanceMethod() {}
48-
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | instanceMethod() | s:14swift_ide_test6AClassC14instanceMethodyyF | Def,RelChild | rel: 1
49-
// CHECK-NEXT: RelChild | AClass | s:14swift_ide_test6AClassC
46+
// InstanceMethod + Parameters
47+
func instanceMethod(a: Int, b b: Int, _ c: Int) {}
48+
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | instanceMethod(a:b:_:) | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitF | Def,RelChild | rel: 1
49+
// CHECK-NEXT: RelChild | AClass | s:14swift_ide_test6AClassC
50+
// CHECK: [[@LINE-3]]:23 | param/Swift | a | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitFAEL_Siv | Def,RelChild | rel: 1
51+
// CHECK-NEXT: RelChild | instanceMethod(a:b:_:) | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitF
52+
// CHECK-NOT: [[@LINE-5]]:31 | param/Swift | b | s:{{.*}} | Def,RelChild | rel: 1
53+
// CHECK-NOT: [[@LINE-6]]:43 | param/Swift | c | s:{{.*}} | Def,RelChild | rel: 1
5054

5155
// ClassMethod
5256
class func classMethod() {}

test/Index/roles.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,36 @@ z = z + 1
5454
// CHECK: [[@LINE-4]]:5 | function/acc-get/Swift | getter:z | s:14swift_ide_test1zSifg | Ref,Call,Impl | rel: 0
5555

5656
// Call
57-
func aCalledFunction() {}
58-
// CHECK: [[@LINE-1]]:6 | function/Swift | aCalledFunction() | s:14swift_ide_test15aCalledFunctionyyF | Def | rel: 0
57+
func aCalledFunction(a: Int, b: inout Int) {
58+
// CHECK: [[@LINE-1]]:6 | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF | Def | rel: 0
59+
// CHECK: [[@LINE-2]]:22 | param/Swift | a | s:{{.*}} | Def,RelChild | rel: 1
60+
// CHECK-NEXT: RelChild | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF
61+
// CHECK: [[@LINE-4]]:30 | param/Swift | b | s:{{.*}} | Def,RelChild | rel: 1
62+
// CHECK-NEXT: RelChild | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF
63+
64+
var _ = a + b
65+
// CHECK: [[@LINE-1]]:11 | param/Swift | a | s:{{.*}} | Ref,Read | rel: 0
66+
// CHECK: [[@LINE-2]]:15 | param/Swift | b | s:{{.*}} | Ref,Read | rel: 0
67+
68+
b = a + 1
69+
// CHECK: [[@LINE-1]]:3 | param/Swift | b | s:{{.*}} | Ref,Writ | rel: 0
70+
// CHECK: [[@LINE-2]]:7 | param/Swift | a | s:{{.*}} | Ref,Read | rel: 0
71+
}
5972

60-
aCalledFunction()
61-
// CHECK: [[@LINE-1]]:1 | function/Swift | aCalledFunction() | s:14swift_ide_test15aCalledFunctionyyF | Ref,Call | rel: 0
73+
aCalledFunction(a: 1, b: &z)
74+
// CHECK: [[@LINE-1]]:1 | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF | Ref,Call | rel: 0
75+
// CHECK: [[@LINE-2]]:27 | variable/Swift | z | s:14swift_ide_test1zSiv | Ref,Read,Writ | rel: 0
6276

6377
func aCaller() {
6478
// CHECK: [[@LINE-1]]:6 | function/Swift | aCaller() | s:14swift_ide_test7aCalleryyF | Def | rel: 0
6579

66-
aCalledFunction()
67-
// CHECK: [[@LINE-1]]:3 | function/Swift | aCalledFunction() | s:14swift_ide_test15aCalledFunctionyyF | Ref,Call,RelCall | rel: 1
80+
aCalledFunction(a: 1, b: &z)
81+
// CHECK: [[@LINE-1]]:3 | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF | Ref,Call,RelCall | rel: 1
6882
// CHECK-NEXT: RelCall | aCaller() | s:14swift_ide_test7aCalleryyF
6983
}
7084

7185
let _ = aCalledFunction
72-
// CHECK: [[@LINE-1]]:9 | function/Swift | aCalledFunction() | s:14swift_ide_test15aCalledFunctionyyF | Ref | rel: 0
86+
// CHECK: [[@LINE-1]]:9 | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF | Ref | rel: 0
7387

7488
// RelationChildOf, Implicit
7589
struct AStruct {

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class SKIndexDataConsumer : public IndexDataConsumer {
6565
}
6666

6767
Action startSourceEntity(const IndexSymbol &symbol) override {
68+
if (symbol.symInfo.Kind == SymbolKind::Parameter)
69+
return Skip;
6870

6971
// report any parent relations to this reference
7072
if (symbol.roles & (SymbolRoleSet)SymbolRole::RelationBaseOf) {

0 commit comments

Comments
 (0)