Skip to content

Commit c42c98c

Browse files
committed
swift-ide-test: Use Demangle::getTypeDeclForUSR() to implement -type-reconstruction flag
"Fixes" <rdar://problem/30680565> -- the "reconstruct_type_from_mangled_name_invalid" test has been disabled since 2017, and the output has changed a fair bit. But the FIXMEs have been addressed and it can reconstruct the associated type and type alias now, and there's no harm in re-enabling it now.
1 parent fd0e1cd commit c42c98c

File tree

3 files changed

+16
-106
lines changed

3 files changed

+16
-106
lines changed
Lines changed: 9 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
11
// RUN: %target-swift-ide-test -reconstruct-type -source-filename %s | %FileCheck %s -implicit-check-not="FAILURE"
22

3+
// This test doesn't test a whole lot now that the more general (but buggy)
4+
// getDeclFromMangledSymbolName() has been replaced with getTypeDeclForMangling().
5+
6+
// However we're still printing and reconstructing types for all the expressions
7+
// we see here, even though there are no check lines.
8+
9+
// More comprehensive tests for getType{,Decl}ForMangling() are found in
10+
// test/TypeDecoder/.
11+
312
struct Mystruct1 {
413
// CHECK: decl: struct Mystruct1
514
func s1f1() -> Int { return 0 }
6-
// CHECK: decl: func s1f1() -> Int
715
var intField = 3
8-
// CHECK: decl: @_hasInitialValue var intField: Int
9-
// CHECK: decl: init(intField: Int)
10-
// CHECK: decl: init()
1116
}
1217
struct MyStruct2 {
1318
// CHECK: decl: struct MyStruct2
1419
init() {}
15-
// CHECK: decl: init()
1620
init(x: Int) {}
17-
// CHECK: decl: init(x: Int)
1821
init(x: Int, y: Int) {}
19-
// CHECK: decl: init(x: Int, y: Int)
2022
}
2123

2224
class Myclass1 {
2325
// CHECK: decl: class Myclass1
2426
var intField = 4
25-
// CHECK: decl: @_hasInitialValue var intField: Int
26-
// CHECK: decl: init()
2727
}
2828

2929
func f1() {
30-
// CHECK: decl: func f1()
3130
var s1ins = Mystruct1() // Implicit ctor
32-
// CHECK: decl: @_hasInitialValue var s1ins: Mystruct1
3331
_ = Mystruct1(intField: 1) // Implicit ctor
3432

3533
s1ins.intField = 34
3634
// CHECK: type: Mystruct1
3735
// CHECK: type: Int
3836

3937
var c1ins = Myclass1()
40-
// CHECK: decl: @_hasInitialValue var c1ins: Myclass1
4138
// CHECK: type: Myclass1
4239

4340
c1ins.intField = 3
@@ -48,66 +45,49 @@ func f1() {
4845
// CHECK: type: (Mystruct1) -> () -> Int
4946

5047
if let ifletf1 = Int?(1) {
51-
// FIXME: lookup incorrect for if let binding.
52-
// CHECK: decl: struct Int : {{.*}} for 'ifletf1' usr=s:14swift_ide_test2f1yyF7ifletf1L_Siv
5348
}
5449
}
5550

5651
class Myclass2 {
5752
// CHECK: decl: class Myclass2
5853
func f1() {
59-
// CHECK: decl: func f1()
6054

6155
var arr1 = [1, 2]
62-
// CHECK: decl: @_hasInitialValue var arr1: [Int]
6356
// CHECK: type: [Int]
6457

6558
arr1.append(1)
66-
// FIXME: missing append()
67-
// CHECK: dref: FAILURE for 'append' usr=s:Sa6appendyyxnF
6859
// CHECK: type: (inout Array<Int>) -> (__owned Int) -> ()
6960

7061
var arr2 : [Mystruct1]
71-
// CHECK: decl: var arr2: [Mystruct1]
7262
// CHECK: type: [Mystruct1]
7363

7464
arr2.append(Mystruct1())
7565
// CHECK: type: (inout Array<Mystruct1>) -> (__owned Mystruct1) -> ()
7666

7767
var arr3 : [Myclass1]
78-
// CHECK: decl: var arr3: [Myclass1]
7968
// CHECK: type: [Myclass1]
8069

8170
arr3.append(Myclass1())
8271
// CHECK: type: (inout Array<Myclass1>) -> (__owned Myclass1) -> ()
8372

8473
_ = Myclass2.init()
85-
// CHECK: dref: init()
8674
}
8775
}
8876

8977
// CHECK: decl: enum MyEnum
9078
enum MyEnum {
91-
// FIXME
92-
// CHECK: decl: for 'ravioli'
9379
case ravioli
94-
// CHECK: decl: for 'pasta'
9580
case pasta
9681

97-
// CHECK: decl: func method() -> Int
9882
func method() -> Int { return 0 }
9983

100-
// CHECK: decl: func compare(_ other: MyEnum) -> Int
10184
func compare(_ other: MyEnum) -> Int {
102-
// CHECK: decl: let other: MyEnum
10385
return 0
10486
}
10587

106-
// CHECK: decl: mutating func mutatingMethod()
10788
mutating func mutatingMethod() {}
10889
}
10990

110-
// CHECK: decl: func f2()
11191
func f2() {
11292
// CHECK: type: (MyEnum.Type) -> MyEnum
11393
var e = MyEnum.pasta
@@ -122,18 +102,10 @@ func f2() {
122102

123103
struct MyGenStruct1<T, U: ExpressibleByStringLiteral, V: Sequence> {
124104
// CHECK: decl: struct MyGenStruct1<T, U, V> where U : ExpressibleByStringLiteral, V : Sequence
125-
// FIXME: why are these references to the base type?
126-
// FIXME: TypeReconstruction should support Node::Kind::GenericTypeParamDecl ('fp')
127-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test12MyGenStruct1V1Txmfp
128-
// CHECK: decl: FAILURE for 'U' usr=s:14swift_ide_test12MyGenStruct1V1Uq_mfp
129-
// CHECK: decl: FAILURE for 'V' usr=s:14swift_ide_test12MyGenStruct1V1Vq0_mfp
130105

131106
let x: T
132-
// CHECK: decl: let x: T
133107
let y: U
134-
// CHECK: decl: let y: U
135108
let z: V
136-
// CHECK: decl: let z: V
137109

138110
func test000() {
139111
_ = x
@@ -144,22 +116,17 @@ struct MyGenStruct1<T, U: ExpressibleByStringLiteral, V: Sequence> {
144116
// CHECK: type: V
145117
}
146118

147-
// CHECK: decl: func takesT(_ t: T)
148119
func takesT(_ t: T) {
149-
// CHECK: decl: let t: T
150120
}
151121
}
152122

153123
let genstruct1 = MyGenStruct1<Int, String, [Float]>(x: 1, y: "", z: [1.0])
154-
// CHECK: decl: @_hasInitialValue let genstruct1: MyGenStruct1<Int, String, [Float]>
155124

156125
func test001() {
157-
// CHECK: decl: func test001()
158126
_ = genstruct1
159127
// CHECK: type: MyGenStruct1<Int, String, [Float]>
160128

161129
var genstruct2: MyGenStruct1<Int, String, [Int: Int]>
162-
// CHECK: decl: var genstruct2: MyGenStruct1<Int, String, [Int : Int]>
163130
_ = genstruct2
164131
// CHECK: type: MyGenStruct1<Int, String, [Int : Int]>
165132
_ = genstruct2.x
@@ -175,41 +142,30 @@ func test001() {
175142
// CHECK: decl: protocol P1
176143
protocol P1 {}
177144

178-
// CHECK: decl: func foo1(p: P1)
179145
func foo1(p: P1) {
180-
// CHECK: decl: let p: P1
181146
// CHECK: type: (P1) -> ()
182147
foo1(p: p)
183148
}
184149

185150
// CHECK: decl: protocol P2
186151
protocol P2 {}
187152

188-
// CHECK: decl: func foo2(p: P1 & P2)
189153
func foo2(p: P1 & P2) {
190-
// CHECK: decl: let p: P1 & P2
191154
foo2(p: p)
192155
}
193156

194-
// CHECK: func foo3(p: P1 & AnyObject)
195157
func foo3(p: P1 & AnyObject) {
196-
// CHECK: decl: let p: P1 & AnyObject
197158
foo3(p: p)
198159
}
199160

200-
// CHECK: func foo4(p: Myclass1 & P1 & P2)
201161
func foo4(p: P1 & P2 & Myclass1) {
202-
// CHECK: decl: let p: Myclass1 & P1 & P2
203162
foo4(p: p)
204163
}
205164

206165
func genericFunction<T : AnyObject>(t: T) {
207-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test15genericFunction1tyx_tRlzClF1TL_xmfp
208166
genericFunction(t: t)
209167
}
210168

211-
// CHECK: decl: func takesInOut(fn: (inout Int) -> ())
212-
// CHECK: decl: let fn: (inout Int) -> () for 'fn'
213169
func takesInOut(fn: (inout Int) -> ()) {}
214170

215171
struct Outer {
@@ -218,36 +174,30 @@ struct Outer {
218174
}
219175

220176
struct GenericInner<T> {
221-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test5OuterV12GenericInnerV1Txmfp
222177
let t: T
223178
}
224179
}
225180

226181
struct GenericOuter<T> {
227-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test12GenericOuterV1Txmfp
228182
struct Inner {
229183
let t: T
230184
let x: Int
231185
}
232186

233187
struct GenericInner<U> {
234-
// CHECK: decl: FAILURE for 'U' usr=s:14swift_ide_test12GenericOuterV0D5InnerV1Uqd__mfp
235188
let t: T
236189
let u: U
237190
}
238191
}
239192

240-
// CHECK: decl: func takesGeneric(_ t: Outer.GenericInner<Int>)
241193
func takesGeneric(_ t: Outer.GenericInner<Int>) {
242194
takesGeneric(t)
243195
}
244196

245-
// CHECK: decl: func takesGeneric(_ t: GenericOuter<Int>.Inner)
246197
func takesGeneric(_ t: GenericOuter<Int>.Inner) {
247198
takesGeneric(t)
248199
}
249200

250-
// CHECK: decl: func takesGeneric(_ t: GenericOuter<Int>.GenericInner<String>)
251201
func takesGeneric(_ t: GenericOuter<Int>.GenericInner<String>) {
252202
takesGeneric(t)
253203
}
@@ -257,24 +207,14 @@ func hasLocalDecls() {
257207

258208
// CHECK: decl: struct LocalType for 'LocalType' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_V
259209
struct LocalType {
260-
// CHECK: func localMethod() for 'localMethod' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_V11localMethodyyF
261210
func localMethod() {}
262211

263-
// CHECK: subscript(x: Int) -> Int { get set } for 'subscript' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_VyS2icip
264212
subscript(x: Int) -> Int { get {} set {} }
265-
266-
// CHECK: decl: get for '' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_VyS2icig
267-
// CHECK: decl: set for '' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_VyS2icis
268-
// CHECK: decl: init() for '' usr=s:14swift_ide_test13hasLocalDeclsyyF0E4TypeL_VADycfc
269-
270213
}
271214

272215
// CHECK: decl: class LocalClass for 'LocalClass' usr=s:14swift_ide_test13hasLocalDeclsyyF0E5ClassL_C
273216
class LocalClass {
274-
// CHECK: decl: {{(@objc )?}}deinit for 'deinit' usr=s:14swift_ide_test13hasLocalDeclsyyF0E5ClassL_Cfd
275217
deinit {}
276-
277-
// CHECK: decl: init() for '' usr=s:14swift_ide_test13hasLocalDeclsyyF0E5ClassL_CADycfc
278218
}
279219

280220
// CHECK: decl: typealias LocalAlias = LocalType for 'LocalAlias' usr=s:14swift_ide_test13hasLocalDeclsyyF0E5AliasL_a
@@ -283,48 +223,27 @@ func hasLocalDecls() {
283223

284224
fileprivate struct VeryPrivateData {}
285225

286-
// CHECK: decl: fileprivate func privateFunction(_ d: VeryPrivateData) for 'privateFunction'
287226
fileprivate func privateFunction(_ d: VeryPrivateData) {}
288227

289228
struct HasSubscript {
290-
// CHECK: decl: subscript(t: Int) -> Int { get set }
291229
subscript(_ t: Int) -> Int {
292-
// CHECK: decl: get for '' usr=s:14swift_ide_test12HasSubscriptVyS2icig
293230
get {
294231
return t
295232
}
296-
// CHECK: decl: set for '' usr=s:14swift_ide_test12HasSubscriptVyS2icis
297233
set {}
298234
}
299235
}
300236

301-
// FIXME
302-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test19HasGenericSubscriptV1Txmfp
303237
struct HasGenericSubscript<T> {
304-
// CHECK: subscript<U>(t: T) -> U { get set } for 'subscript' usr=s:14swift_ide_test19HasGenericSubscriptVyqd__xcluip
305-
// FIXME
306-
// CHECK: decl: FAILURE for 'U'
307-
// FIXME
308-
// CHECK: decl: FAILURE for 't'
309238
subscript<U>(_ t: T) -> U {
310-
311-
// CHECK: decl: get for '' usr=s:14swift_ide_test19HasGenericSubscriptVyqd__xcluig
312-
// FIXME
313-
// CHECK: dref: FAILURE for 't'
314239
get {
315240
return t as! U
316241
}
317-
318-
// CHECK: decl: set for '' usr=s:14swift_ide_test19HasGenericSubscriptVyqd__xcluis
319242
set {}
320243
}
321244
}
322245

323246
private
324-
// CHECK: decl: private func patatino<T>(_ vers1: T, _ vers2: T) -> Bool where T : Comparable for
325247
func patatino<T: Comparable>(_ vers1: T, _ vers2: T) -> Bool {
326-
// CHECK: decl: FAILURE for 'T' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xtSLRzlF1TL_xmfp decl
327-
// CHECK: decl: let vers1: T for 'vers1' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xtSLRzlF5vers1L_xvp
328-
// CHECK: decl: let vers2: T for 'vers2' usr=s:14swift_ide_test8patatino33_D7B956AE2D93947DFA67A1ECF93EF238LLySbx_xtSLRzlF5vers2L_xvp
329248
return vers1 < vers2;
330249
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
// RUN: %target-swift-ide-test -reconstruct-type -source-filename %s | %FileCheck %s -implicit-check-not="FAILURE"
2-
// REQUIRES: rdar30680565
32

43
struct GS<T> {
54
// CHECK: decl: struct GS<T> for 'GS'
6-
// FIXME: why do we get this?
7-
// CHECK: decl: struct GS<T> for 'T' usr=s:14swift_ide_test2GSV1Txmfp
85

96
let a: T.Nope
10-
// CHECK: decl: let a: <<error type>>
117
let b: T
12-
// CHECK: decl: let b: T
138
}
149

1510
let global1: GS
16-
// CHECK: decl: let global1: <<error type>>
1711
let global2 = GS().x
18-
// CHECK: decl: let global2: <<error type>>
1912
let global3 = GS<Int>(a: 1, b: 2).b
20-
// CHECK: decl: let global3: <<error type>>
2113

2214
protocol P {
23-
// FIXME: missing protocol entries?
2415
// CHECK: decl: protocol P for 'P' usr=s:14swift_ide_test1PP
2516
associatedtype T
26-
// CHECK: decl: protocol P for 'T' usr=s:14swift_ide_test1PP1T
17+
// CHECK: decl: associatedtype T for 'T' usr=s:14swift_ide_test1PP1TQa
2718
func foo() -> T
28-
// CHECK: decl: func foo() -> Self.T for 'foo' usr=s:14swift_ide_test1PP3foo1TQzyF
2919
}
3020
struct SP: P {
3121
// CHECK: decl: struct SP : P for 'SP'
3222
typealias TT = Self.T
33-
// FIXME: should be the typealias decl
34-
// CHECK: decl: struct SP : P for 'TT' usr=s:14swift_ide_test2SPV2TT
23+
// CHECK: typealias TT = <<error type>> for 'TT' usr=s:14swift_ide_test2SPV2TTa
3524
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,9 @@ class TypeReconstructWalker : public SourceEntityWalker {
28452845
}
28462846

28472847
void tryDemangleDecl(ValueDecl *VD, CharSourceRange range, bool isRef) {
2848+
if (!isa<TypeDecl>(VD) || isa<GenericTypeParamDecl>(VD))
2849+
return;
2850+
28482851
std::string USR;
28492852
{
28502853
llvm::raw_string_ostream OS(USR);
@@ -2858,16 +2861,15 @@ class TypeReconstructWalker : public SourceEntityWalker {
28582861
Stream << "decl: ";
28592862
}
28602863

2861-
if (Decl *reDecl = getDeclFromUSR(Ctx, USR, error)) {
2864+
if (TypeDecl *reDecl = Demangle::getTypeDeclForUSR(Ctx, USR)) {
28622865
PrintOptions POpts;
28632866
POpts.PreferTypeRepr = false;
28642867
POpts.PrintParameterSpecifiers = true;
28652868
reDecl->print(Stream, POpts);
28662869
} else {
28672870
Stream << "FAILURE";
28682871
}
2869-
Stream << "\tfor '" << range.str() << "' usr=" << USR << " " << error
2870-
<< "\n";
2872+
Stream << "\tfor '" << range.str() << "' usr=" << USR << "\n";
28712873
}
28722874
};
28732875

0 commit comments

Comments
 (0)