Skip to content
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
34 changes: 4 additions & 30 deletions lib/AST/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,10 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
if (isa<ParamDecl>(VD) && isa<DestructorDecl>(VD->getDeclContext()))
return true;

std::string Old = getUSRSpacePrefix().str();
Mangler Mangler;

Mangler.bindGenericParameters(VD->getDeclContext());

if (auto Ctor = dyn_cast<ConstructorDecl>(VD)) {
Mangler.mangleConstructorEntity(Ctor, /*isAllocating=*/false,
/*uncurryingLevel=*/0);
} else if (auto Dtor = dyn_cast<DestructorDecl>(VD)) {
Mangler.mangleDestructorEntity(Dtor, /*isDeallocating=*/false);
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
Mangler.mangleNominalType(NTD);
} else if (isa<TypeAliasDecl>(VD) || isa<AssociatedTypeDecl>(VD)) {
Mangler.mangleContextOf(VD);
Mangler.mangleDeclName(VD);
} else {
Mangler.mangleEntity(VD, /*uncurryingLevel=*/0);
}

Old += Mangler.finalize();

NewMangling::ASTMangler NewMangler;
std::string New = NewMangler.mangleDeclAsUSR(VD, getUSRSpacePrefix());
std::string Mangled = NewMangler.mangleDeclAsUSR(VD, getUSRSpacePrefix());

OS << NewMangling::selectMangling(Old, New);
OS << Mangled;

return false;
}
Expand All @@ -260,16 +239,11 @@ bool ide::printAccessorUSR(const AbstractStorageDecl *D, AccessorKind AccKind,
return printObjCUSRForAccessor(SD, AccKind, OS);
}

std::string Old = getUSRSpacePrefix().str();
Mangler Mangler;
Mangler.mangleAccessorEntity(AccKind, AddressorKind::NotAddressor, SD);
Old += Mangler.finalize();

NewMangling::ASTMangler NewMangler;
std::string New = NewMangler.mangleAccessorEntityAsUSR(AccKind,
std::string Mangled = NewMangler.mangleAccessorEntityAsUSR(AccKind,
AddressorKind::NotAddressor, SD, getUSRSpacePrefix());

OS << NewMangling::selectMangling(Old, New);
OS << Mangled;

return false;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2139,11 +2139,7 @@ Decl *ide::getDeclFromUSR(ASTContext &context, StringRef USR,
// This relies on USR generation being very close to symbol mangling; if we
// need to support entities with customized USRs (e.g. extensions), we will
// need to do something smarter here.
#ifdef USE_NEW_MANGLING
mangledName.replace(0, 2, MANGLING_PREFIX_STR);
#else
mangledName.replace(0, 2, "_T");
#endif

return getDeclFromMangledSymbolName(context, mangledName, error);
}
Expand Down
17 changes: 9 additions & 8 deletions test/IDE/reconstruct_type_from_mangled_name.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func f1() {

if let ifletf1 = Int?(1) {
// FIXME: lookup incorrect for if let binding.
// CHECK: decl: struct Int : {{.*}} for 'ifletf1' usr=s:vF14swift_ide_test2f1FT_T_L_7ifletf1Si
// CHECK: decl: struct Int : {{.*}} for 'ifletf1' usr=s:14swift_ide_test2f1yyF7ifletf1L_Siv
}
}

Expand All @@ -64,7 +64,7 @@ class Myclass2 {

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

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

let x: T
// CHECK: decl: let x: T
Expand Down Expand Up @@ -132,6 +133,6 @@ func test001() {

protocol P1 {}
func foo1(p : P1) {}
// CHECK: decl: protocol P1 for 'P1' usr=s:P14swift_ide_test2P1
// CHECK: decl: func foo1(p: P1) for 'foo1' usr=s:F14swift_ide_test4foo1FT1pPS_2P1__T_
// CHECK: decl: let p: P1 for 'p' usr=s:vF14swift_ide_test4foo1FT1pPS_2P1__T_L_1pPS0__
// CHECK: decl: protocol P1 for 'P1' usr=s:14swift_ide_test2P1P
// CHECK: decl: func foo1(p: P1) for 'foo1' usr=s:14swift_ide_test4foo1yAA2P1_p1p_tF
// CHECK: decl: let p: P1 for 'p' usr=s:14swift_ide_test4foo1yAA2P1_p1p_tFADL_AaC_pv
11 changes: 6 additions & 5 deletions test/IDE/reconstruct_type_from_mangled_name_invalid.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// RUN: %target-swift-ide-test -reconstruct-type -source-filename %s | %FileCheck %s -implicit-check-not="FAILURE"
// REQUIRES: rdar://problem/30680565

struct GS<T> {
// CHECK: decl: struct GS<T> for 'GS'
// FIXME: why do we get this?
// CHECK: decl: struct GS<T> for 'T' usr=s:tV14swift_ide_test2GS1TMx
// CHECK: decl: struct GS<T> for 'T' usr=s:14swift_ide_test2GSVD1TMx

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

protocol P {
// FIXME: missing protocol entries?
// CHECK: decl: protocol P for 'P' usr=s:P14swift_ide_test1P
// CHECK: decl: protocol P for 'P' usr=s:14swift_ide_test1PP
associatedtype T
// CHECK: decl: protocol P for 'T' usr=s:P14swift_ide_test1P1T
// CHECK: decl: protocol P for 'T' usr=s:14swift_ide_test1PP1T
func foo() -> T
// CHECK: decl: func foo() -> Self.T for 'foo' usr=s:FP14swift_ide_test1P3fooFT_wx1T
// CHECK: decl: func foo() -> Self.T for 'foo' usr=s:14swift_ide_test1PP3foo1TQzyF
}
struct SP: P {
// CHECK: decl: struct SP : P for 'SP'
typealias TT = Self.T
// FIXME: should be the typealias decl
// CHECK: decl: struct SP : P for 'TT' usr=s:V14swift_ide_test2SP2TT
// CHECK: decl: struct SP : P for 'TT' usr=s:14swift_ide_test2SPV2TT
}
Loading