Skip to content

Commit a640fe7

Browse files
authored
Merge pull request #19948 from DougGregor/autoclosure-demangle-to-metadata
2 parents b892e6b + 7d88a7d commit a640fe7

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/swift/Demangling/TypeDecoder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ class TypeDecoder {
246246
case NodeKind::CFunctionPointer:
247247
case NodeKind::ThinFunctionType:
248248
case NodeKind::NoEscapeFunctionType:
249+
case NodeKind::AutoClosureType:
250+
case NodeKind::EscapingAutoClosureType:
249251
case NodeKind::FunctionType: {
250252
if (Node->getNumChildren() < 2)
251253
return BuiltType();
252254

255+
// FIXME: autoclosure is not represented in function metadata
253256
FunctionTypeFlags flags;
254257
if (Node->getKind() == NodeKind::ObjCBlock) {
255258
flags = flags.withConvention(FunctionMetadataConvention::Block);
@@ -275,7 +278,9 @@ class TypeDecoder {
275278
flags =
276279
flags.withNumParameters(parameters.size())
277280
.withParameterFlags(hasParamFlags)
278-
.withEscaping(Node->getKind() == NodeKind::FunctionType);
281+
.withEscaping(
282+
Node->getKind() == NodeKind::FunctionType ||
283+
Node->getKind() == NodeKind::EscapingAutoClosureType);
279284

280285
auto result = decodeMangledType(Node->getChild(isThrow ? 2 : 1));
281286
if (!result) return BuiltType();

test/IRGen/function_metadata.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ func test_arch() {
5353
arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in })
5454

5555
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa"
56-
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1(i64 67108865
56+
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1({{i(32|64)}} 67108865
5757
arch({(x: @escaping () -> ()) -> () in })
5858
}

test/Runtime/demangleToMetadata.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func f1_owned(x: __owned AnyObject) { }
4545

4646
func f2_variadic_inout(x: ()..., y: inout ()) { }
4747

48+
func f1_escaping(_: @escaping (Int) -> Float) { }
49+
func f1_autoclosure(_: @autoclosure () -> Float) { }
50+
func f1_escaping_autoclosure(_: @autoclosure @escaping () -> Float) { }
51+
4852
DemangleToMetadataTests.test("function types") {
4953
// Conventions
5054
expectEqual(type(of: f0), _typeByMangledName("yyc")!)
@@ -77,6 +81,13 @@ DemangleToMetadataTests.test("function types") {
7781
// A function type that hasn't been built before.
7882
expectEqual("(Int, Float, Double, String, Character, UInt, Bool) -> ()",
7983
String(describing: _typeByMangledName("yySi_SfSdSSs9CharacterVSuSbtc")!))
84+
85+
// Escaping
86+
expectEqual(type(of: f1_escaping), _typeByMangledName("ySfSicc")!)
87+
88+
// Autoclosure
89+
expectEqual(type(of: f1_autoclosure), _typeByMangledName("ySfyXKc")!)
90+
expectEqual(type(of: f1_escaping_autoclosure), _typeByMangledName("ySfyXAc")!)
8091
}
8192

8293
DemangleToMetadataTests.test("metatype types") {

0 commit comments

Comments
 (0)