Skip to content

Commit 1b07ec8

Browse files
authored
Merge pull request swiftlang#22356 from slavapestov/more-type-reconstruction-fixes
A couple more type reconstruction fixes
2 parents ed15071 + 0ddf475 commit 1b07ec8

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class TypeDecoder {
301301
if (!decodeMangledTypeDecl(Node, typeDecl, parent, typeAlias))
302302
return BuiltType();
303303

304-
if (typeAlias && Node->getKind() == NodeKind::TypeAlias)
304+
if (typeAlias)
305305
return Builder.createTypeAliasType(typeDecl, parent);
306306

307307
return Builder.createNominalType(typeDecl, parent);

lib/AST/ASTDemangler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ Type ASTBuilder::createTypeAliasType(GenericTypeDecl *decl, Type parent) {
126126
if (aliasDecl->getGenericParams())
127127
return Type();
128128

129+
// Imported types can be renamed to be members of other (non-generic)
130+
// types, but the mangling does not have a parent type. Just use the
131+
// declared type directly in this case and skip the parent check below.
132+
if (aliasDecl->hasClangNode() && !aliasDecl->isGenericContext())
133+
return aliasDecl->getDeclaredInterfaceType();
134+
129135
// Validate the parent type.
130136
if (!validateParentType(aliasDecl, parent))
131137
return Type();
@@ -307,6 +313,10 @@ Type ASTBuilder::createFunctionType(
307313
.withVariadic(flags.isVariadic())
308314
.withAutoClosure(flags.isAutoClosure());
309315

316+
if (auto *fnType = type->getAs<FunctionType>())
317+
if (!fnType->isNoEscape())
318+
parameterFlags = parameterFlags.withEscaping(true);
319+
310320
funcParams.push_back(AnyFunctionType::Param(type, label, parameterFlags));
311321
}
312322

test/TypeDecoder/objc_classes.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ do {
1818
let x2: NSFastEnumeration = x1
1919
let x3: OurObjCProtocol = OurObjCClass()
2020
let x4: NSCache = NSCache<NSNumber, NSString>()
21+
let x5: PropertyListSerialization.WriteOptions = 0
2122

22-
blackHole(x1, x2, x3, x4)
23+
blackHole(x1, x2, x3, x4, x5)
2324
}
2425

2526
do {
2627
let x1: NSSet.Type = NSSet.self
2728
let x2: NSFastEnumeration.Type = x1
2829
let x3: OurObjCProtocol.Type = OurObjCClass.self
2930
let x4: NSCache.Type = NSCache<NSNumber, NSString>.self
31+
let x5: PropertyListSerialization.WriteOptions = 0
3032

31-
blackHole(x1, x2, x3, x4)
33+
blackHole(x1, x2, x3, x4, x5)
3234
}
3335

3436
do {
@@ -42,17 +44,20 @@ do {
4244
// DEMANGLE: $sSo17NSFastEnumeration_pD
4345
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pD
4446
// DEMANGLE: $sSo7NSCacheCySo8NSNumberCSo8NSStringCGD
47+
// DEMANGLE: $sSo26NSPropertyListWriteOptionsaD
4548

4649
// CHECK: NSSet
4750
// CHECK: NSFastEnumeration
4851
// CHECK: OurObjCProtocol
4952
// CHECK: NSCache<NSNumber, NSString>
53+
// CHECK: PropertyListSerialization.WriteOptions
5054

5155
// DEMANGLE: $sSo5NSSetCmD
5256
// DEMANGLE: $sSo5NSSetCXMTD
5357
// DEMANGLE: $sSo17NSFastEnumeration_pXpD
5458
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pXpD
5559
// DEMANGLE: $sSo7NSCacheCySo8NSNumberCSo8NSStringCGmD
60+
// DEMANGLE: $sSo26NSPropertyListWriteOptionsamD
5661

5762
// CHECK: NSSet.Type
5863
// CHECK: @thick NSSet.Type
@@ -62,6 +67,8 @@ do {
6267

6368
// CHECK: NSCache<NSNumber, NSString>.Type
6469

70+
// CHECK: PropertyListSerialization.WriteOptions.Type
71+
6572
// DEMANGLE: $sSo17NSFastEnumeration_pmD
6673
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pmD
6774

test/TypeDecoder/structural_types.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ do {
116116
blackHole(metatype)
117117
}
118118

119+
do {
120+
let escaping: (@escaping () -> ()) -> () = { _ in }
121+
blackHole(escaping)
122+
}
119123
// DEMANGLE: $syycD
120124
// DEMANGLE: $sySSzcD
121125
// DEMANGLE: $sySSncD
@@ -131,6 +135,7 @@ do {
131135
// DEMANGLE: $sSi_SfSitD
132136
// DEMANGLE: $sSim_Sf1xSitD
133137
// DEMANGLE: $sSi1x_SfSim1ytD
138+
// DEMANGLE: $syyyccD
134139

135140
// CHECK: () -> ()
136141
// CHECK: (inout String) -> ()
@@ -147,6 +152,7 @@ do {
147152
// CHECK: (Int, Float, Int)
148153
// CHECK: (Int.Type, x: Float, Int)
149154
// CHECK: (x: Int, Float, y: Int.Type)
155+
// CHECK: (@escaping () -> ()) -> ()
150156

151157
// DEMANGLE: $sSimD
152158
// DEMANGLE: $syycmD
@@ -164,6 +170,7 @@ do {
164170
// DEMANGLE: $sSi_SfSitmD
165171
// DEMANGLE: $sSim_Sf1xSitmD
166172
// DEMANGLE: $sSi1x_SfSim1ytmD
173+
// DEMANGLE: $syyyccmD
167174

168175
// CHECK: Int.Type
169176
// CHECK: ((inout String) -> ()).Type
@@ -180,3 +187,4 @@ do {
180187
// CHECK: (Int, Float, Int).Type
181188
// CHECK: (Int.Type, x: Float, Int).Type
182189
// CHECK: (x: Int, Float, y: Int.Type).Type
190+
// CHECK: ((@escaping () -> ()) -> ()).Type

0 commit comments

Comments
 (0)