Skip to content

Commit 5c80f1e

Browse files
committed
[IDE] Don't produce USRs for nameless parameters.
...and /do/ produce them for 'self' parameters in destructors when they /are/ named. I suspect this was the cause of the original problem.
1 parent 7c73ba5 commit 5c80f1e

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ASTMangler : public Mangler {
122122

123123
std::string mangleTypeAsContextUSR(const NominalTypeDecl *type);
124124

125-
std::string mangleDeclAsUSR(ValueDecl *Decl, StringRef USRPrefix);
125+
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);
126126

127127
std::string mangleAccessorEntityAsUSR(AccessorKind kind,
128128
AddressorKind addressorKind,

lib/AST/USRGeneration.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static bool ShouldUseObjCUSR(const Decl *D) {
141141
}
142142

143143
bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
144-
if (!D->hasName() && !isa<ParamDecl>(D) &&
144+
if (!D->hasName() &&
145145
(!isa<FuncDecl>(D) ||
146146
cast<FuncDecl>(D)->getAccessorKind() == AccessorKind::NotAccessor))
147147
return true; // Ignore.
@@ -150,8 +150,6 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
150150
if (isa<ModuleDecl>(D))
151151
return true; // Ignore.
152152

153-
ValueDecl *VD = const_cast<ValueDecl *>(D);
154-
155153
auto interpretAsClangNode = [](const ValueDecl *D)->ClangNode {
156154
ClangNode ClangN = D->getClangNode();
157155
if (auto ClangD = ClangN.getAsDecl()) {
@@ -204,8 +202,8 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
204202
return Ignore;
205203
}
206204

207-
if (ShouldUseObjCUSR(VD)) {
208-
return printObjCUSR(VD, OS);
205+
if (ShouldUseObjCUSR(D)) {
206+
return printObjCUSR(D, OS);
209207
}
210208

211209
if (!D->hasInterfaceType())
@@ -217,12 +215,8 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
217215
}))
218216
return true;
219217

220-
// FIXME: mangling 'self' in destructors crashes in mangler.
221-
if (isa<ParamDecl>(VD) && isa<DestructorDecl>(VD->getDeclContext()))
222-
return true;
223-
224218
Mangle::ASTMangler NewMangler;
225-
std::string Mangled = NewMangler.mangleDeclAsUSR(VD, getUSRSpacePrefix());
219+
std::string Mangled = NewMangler.mangleDeclAsUSR(D, getUSRSpacePrefix());
226220

227221
OS << Mangled;
228222

test/IDE/print_usrs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GenericClass {
6464
// CHECK: [[@LINE+1]]:3 s:14swift_ide_test12GenericClassCfd{{$}}
6565
deinit {
6666
// CHECK: [[@LINE+2]]:18 s:14swift_ide_test12GenericClassC9classFuncyACFZ{{$}}
67-
// CHECK: [[@LINE+1]]:28 ERROR:no-usr{{$}}
67+
// CHECK: [[@LINE+1]]:28 s:14swift_ide_test12GenericClassCfd4selfL_ACv{{$}}
6868
GenericClass.classFunc(self)
6969
}
7070

test/Index/kinds.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class AClass {
5151
// CHECK-NEXT: RelChild | instance-method/Swift | instanceMethod(a:b:_:d:_:) | s:14swift_ide_test6AClassC14instanceMethodySi1a_Si1bS2i1dSitF
5252
// CHECK: [[@LINE-5]]:33 | param(local)/Swift | b | s:{{.*}} | Def,RelChild | rel: 1
5353
// CHECK: [[@LINE-6]]:43 | param(local)/Swift | c | s:{{.*}} | Def,RelChild | rel: 1
54-
// CHECK: [[@LINE-7]]:53 | param(local)/Swift | _ | s:{{.*}} | Def,RelChild | rel: 1
55-
// CHECK: [[@LINE-8]]:61 | param/Swift | _ | s:{{.*}} | Def,RelChild | rel: 1
54+
// CHECK-NOT: {{^}}[[@LINE-7]]:53 |
55+
// CHECK-NOT: {{^}}[[@LINE-8]]:61 |
5656

5757
_ = a
5858
// CHECK: [[@LINE-1]]:9 | param/Swift | a | s:{{.*}} | Ref,Read,RelCont | rel: 1

0 commit comments

Comments
 (0)