Skip to content

[indexer] report defs/refs of parameters without a separate external name #7820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
}

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

void getModuleHash(SourceFileOrModule SFOrMod, llvm::raw_ostream &OS);
Expand Down
6 changes: 3 additions & 3 deletions lib/Index/IndexSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ SymbolInfo index::getSymbolInfoForDecl(const Decl *D) {
info.SubKind = SymbolSubKind::SwiftSubscript;
break;
case DeclKind::Constructor: info.Kind = SymbolKind::Constructor; break;
case DeclKind::Destructor: info.Kind = SymbolKind::Destructor; break;;
case DeclKind::Destructor: info.Kind = SymbolKind::Destructor; break;
case DeclKind::Param:
llvm_unreachable("unexpected parameter seen while indexing");

info.Kind = SymbolKind::Parameter;
break;
case DeclKind::Func:
setFuncSymbolInfo(cast<FuncDecl>(D), info);
break;
Expand Down
12 changes: 8 additions & 4 deletions test/Index/kinds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ struct AStruct {
class AClass {
// CHECK: [[@LINE-1]]:7 | class/Swift | AClass | s:14swift_ide_test6AClassC | Def | rel: 0

// InstanceMethod
func instanceMethod() {}
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | instanceMethod() | s:14swift_ide_test6AClassC14instanceMethodyyF | Def,RelChild | rel: 1
// CHECK-NEXT: RelChild | AClass | s:14swift_ide_test6AClassC
// InstanceMethod + Parameters
func instanceMethod(a: Int, b b: Int, _ c: Int) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more parameter test cases: d _: Int and _: Int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll add this in a related patch I'm working on at the moment.

// CHECK: [[@LINE-1]]:8 | instance-method/Swift | instanceMethod(a:b:_:) | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitF | Def,RelChild | rel: 1
// CHECK-NEXT: RelChild | AClass | s:14swift_ide_test6AClassC
// CHECK: [[@LINE-3]]:23 | param/Swift | a | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitFAEL_Siv | Def,RelChild | rel: 1
// CHECK-NEXT: RelChild | instanceMethod(a:b:_:) | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bSitF
// CHECK-NOT: [[@LINE-5]]:31 | param/Swift | b | s:{{.*}} | Def,RelChild | rel: 1
// CHECK-NOT: [[@LINE-6]]:43 | param/Swift | c | s:{{.*}} | Def,RelChild | rel: 1

// ClassMethod
class func classMethod() {}
Expand Down
28 changes: 21 additions & 7 deletions test/Index/roles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,36 @@ z = z + 1
// CHECK: [[@LINE-4]]:5 | function/acc-get/Swift | getter:z | s:14swift_ide_test1zSifg | Ref,Call,Impl | rel: 0

// Call
func aCalledFunction() {}
// CHECK: [[@LINE-1]]:6 | function/Swift | aCalledFunction() | s:14swift_ide_test15aCalledFunctionyyF | Def | rel: 0
func aCalledFunction(a: Int, b: inout Int) {
// CHECK: [[@LINE-1]]:6 | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF | Def | rel: 0
// CHECK: [[@LINE-2]]:22 | param/Swift | a | s:{{.*}} | Def,RelChild | rel: 1
// CHECK-NEXT: RelChild | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF
// CHECK: [[@LINE-4]]:30 | param/Swift | b | s:{{.*}} | Def,RelChild | rel: 1
// CHECK-NEXT: RelChild | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF

var _ = a + b
// CHECK: [[@LINE-1]]:11 | param/Swift | a | s:{{.*}} | Ref,Read | rel: 0
// CHECK: [[@LINE-2]]:15 | param/Swift | b | s:{{.*}} | Ref,Read | rel: 0

b = a + 1
// CHECK: [[@LINE-1]]:3 | param/Swift | b | s:{{.*}} | Ref,Writ | rel: 0
// CHECK: [[@LINE-2]]:7 | param/Swift | a | s:{{.*}} | Ref,Read | rel: 0
}

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

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

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

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

// RelationChildOf, Implicit
struct AStruct {
Expand Down
2 changes: 2 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class SKIndexDataConsumer : public IndexDataConsumer {
}

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

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