Skip to content

Commit b5fb342

Browse files
authored
Merge pull request #7721 from eeckstein/new-usr-mangling
2 parents 77ee77f + 7995d3d commit b5fb342

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+989
-1017
lines changed

lib/AST/USRGeneration.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,10 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
210210
if (isa<ParamDecl>(VD) && isa<DestructorDecl>(VD->getDeclContext()))
211211
return true;
212212

213-
std::string Old = getUSRSpacePrefix().str();
214-
Mangler Mangler;
215-
216-
Mangler.bindGenericParameters(VD->getDeclContext());
217-
218-
if (auto Ctor = dyn_cast<ConstructorDecl>(VD)) {
219-
Mangler.mangleConstructorEntity(Ctor, /*isAllocating=*/false,
220-
/*uncurryingLevel=*/0);
221-
} else if (auto Dtor = dyn_cast<DestructorDecl>(VD)) {
222-
Mangler.mangleDestructorEntity(Dtor, /*isDeallocating=*/false);
223-
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
224-
Mangler.mangleNominalType(NTD);
225-
} else if (isa<TypeAliasDecl>(VD) || isa<AssociatedTypeDecl>(VD)) {
226-
Mangler.mangleContextOf(VD);
227-
Mangler.mangleDeclName(VD);
228-
} else {
229-
Mangler.mangleEntity(VD, /*uncurryingLevel=*/0);
230-
}
231-
232-
Old += Mangler.finalize();
233-
234213
NewMangling::ASTMangler NewMangler;
235-
std::string New = NewMangler.mangleDeclAsUSR(VD, getUSRSpacePrefix());
214+
std::string Mangled = NewMangler.mangleDeclAsUSR(VD, getUSRSpacePrefix());
236215

237-
OS << NewMangling::selectMangling(Old, New);
216+
OS << Mangled;
238217

239218
return false;
240219
}
@@ -260,16 +239,11 @@ bool ide::printAccessorUSR(const AbstractStorageDecl *D, AccessorKind AccKind,
260239
return printObjCUSRForAccessor(SD, AccKind, OS);
261240
}
262241

263-
std::string Old = getUSRSpacePrefix().str();
264-
Mangler Mangler;
265-
Mangler.mangleAccessorEntity(AccKind, AddressorKind::NotAddressor, SD);
266-
Old += Mangler.finalize();
267-
268242
NewMangling::ASTMangler NewMangler;
269-
std::string New = NewMangler.mangleAccessorEntityAsUSR(AccKind,
243+
std::string Mangled = NewMangler.mangleAccessorEntityAsUSR(AccKind,
270244
AddressorKind::NotAddressor, SD, getUSRSpacePrefix());
271245

272-
OS << NewMangling::selectMangling(Old, New);
246+
OS << Mangled;
273247

274248
return false;
275249
}

lib/IDE/TypeReconstruction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,11 +2139,7 @@ Decl *ide::getDeclFromUSR(ASTContext &context, StringRef USR,
21392139
// This relies on USR generation being very close to symbol mangling; if we
21402140
// need to support entities with customized USRs (e.g. extensions), we will
21412141
// need to do something smarter here.
2142-
#ifdef USE_NEW_MANGLING
21432142
mangledName.replace(0, 2, MANGLING_PREFIX_STR);
2144-
#else
2145-
mangledName.replace(0, 2, "_T");
2146-
#endif
21472143

21482144
return getDeclFromMangledSymbolName(context, mangledName, error);
21492145
}

test/IDE/reconstruct_type_from_mangled_name.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func f1() {
4949

5050
if let ifletf1 = Int?(1) {
5151
// FIXME: lookup incorrect for if let binding.
52-
// CHECK: decl: struct Int : {{.*}} for 'ifletf1' usr=s:vF14swift_ide_test2f1FT_T_L_7ifletf1Si
52+
// CHECK: decl: struct Int : {{.*}} for 'ifletf1' usr=s:14swift_ide_test2f1yyF7ifletf1L_Siv
5353
}
5454
}
5555

@@ -64,7 +64,7 @@ class Myclass2 {
6464

6565
arr1.append(1)
6666
// FIXME: missing append()
67-
// CHECK: dref: FAILURE for 'append' usr=s:FSa6appendFxT_
67+
// CHECK: dref: FAILURE for 'append' usr=s:Sa6appendyxF
6868
// CHECK: type: (@lvalue Array<Int>) -> (Int) -> ()
6969

7070
var arr2 : [Mystruct1]
@@ -89,9 +89,10 @@ class Myclass2 {
8989
struct MyGenStruct1<T, U: ExpressibleByStringLiteral, V: Sequence> {
9090
// CHECK: decl: struct MyGenStruct1<T, U, V> where U : ExpressibleByStringLiteral, V : Sequence
9191
// FIXME: why are these references to the base type?
92-
// CHECK: decl: struct MyGenStruct1<{{.*}}> where {{.*}} for 'T' usr=s:tV14swift_ide_test12MyGenStruct11TMx
93-
// CHECK: decl: struct MyGenStruct1<{{.*}}> where {{.*}} for 'U' usr=s:tV14swift_ide_test12MyGenStruct11UMq_
94-
// CHECK: decl: struct MyGenStruct1<{{.*}}> where {{.*}} for 'V' usr=s:tV14swift_ide_test12MyGenStruct11VMq0_
92+
// FIXME: TypeReconstruction should support Node::Kind::GenericTypeParamDecl ('fp')
93+
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test12MyGenStruct1V1Txmfp
94+
// CHECK: decl: FAILURE for 'U' usr=s:14swift_ide_test12MyGenStruct1V1Uq_mfp
95+
// CHECK: decl: FAILURE for 'V' usr=s:14swift_ide_test12MyGenStruct1V1Vq0_mfp
9596

9697
let x: T
9798
// CHECK: decl: let x: T
@@ -132,6 +133,6 @@ func test001() {
132133

133134
protocol P1 {}
134135
func foo1(p : P1) {}
135-
// CHECK: decl: protocol P1 for 'P1' usr=s:P14swift_ide_test2P1
136-
// CHECK: decl: func foo1(p: P1) for 'foo1' usr=s:F14swift_ide_test4foo1FT1pPS_2P1__T_
137-
// CHECK: decl: let p: P1 for 'p' usr=s:vF14swift_ide_test4foo1FT1pPS_2P1__T_L_1pPS0__
136+
// CHECK: decl: protocol P1 for 'P1' usr=s:14swift_ide_test2P1P
137+
// CHECK: decl: func foo1(p: P1) for 'foo1' usr=s:14swift_ide_test4foo1yAA2P1_p1p_tF
138+
// CHECK: decl: let p: P1 for 'p' usr=s:14swift_ide_test4foo1yAA2P1_p1p_tFADL_AaC_pv

test/IDE/reconstruct_type_from_mangled_name_invalid.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// RUN: %target-swift-ide-test -reconstruct-type -source-filename %s | %FileCheck %s -implicit-check-not="FAILURE"
2+
// REQUIRES: rdar://problem/30680565
23

34
struct GS<T> {
45
// CHECK: decl: struct GS<T> for 'GS'
56
// FIXME: why do we get this?
6-
// CHECK: decl: struct GS<T> for 'T' usr=s:tV14swift_ide_test2GS1TMx
7+
// CHECK: decl: struct GS<T> for 'T' usr=s:14swift_ide_test2GSVD1TMx
78

89
let a: T.Nope
910
// CHECK: decl: let a: <<error type>>
@@ -20,15 +21,15 @@ let global3 = GS<Int>(a: 1, b: 2).b
2021

2122
protocol P {
2223
// FIXME: missing protocol entries?
23-
// CHECK: decl: protocol P for 'P' usr=s:P14swift_ide_test1P
24+
// CHECK: decl: protocol P for 'P' usr=s:14swift_ide_test1PP
2425
associatedtype T
25-
// CHECK: decl: protocol P for 'T' usr=s:P14swift_ide_test1P1T
26+
// CHECK: decl: protocol P for 'T' usr=s:14swift_ide_test1PP1T
2627
func foo() -> T
27-
// CHECK: decl: func foo() -> Self.T for 'foo' usr=s:FP14swift_ide_test1P3fooFT_wx1T
28+
// CHECK: decl: func foo() -> Self.T for 'foo' usr=s:14swift_ide_test1PP3foo1TQzyF
2829
}
2930
struct SP: P {
3031
// CHECK: decl: struct SP : P for 'SP'
3132
typealias TT = Self.T
3233
// FIXME: should be the typealias decl
33-
// CHECK: decl: struct SP : P for 'TT' usr=s:V14swift_ide_test2SP2TT
34+
// CHECK: decl: struct SP : P for 'TT' usr=s:14swift_ide_test2SPV2TT
3435
}

0 commit comments

Comments
 (0)