Skip to content

[Runtime] Demangle @autoclosure function types to metadata. #19948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
7 changes: 6 additions & 1 deletion include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ class TypeDecoder {
case NodeKind::CFunctionPointer:
case NodeKind::ThinFunctionType:
case NodeKind::NoEscapeFunctionType:
case NodeKind::AutoClosureType:
case NodeKind::EscapingAutoClosureType:
case NodeKind::FunctionType: {
if (Node->getNumChildren() < 2)
return BuiltType();

// FIXME: autoclosure is not represented in function metadata
FunctionTypeFlags flags;
if (Node->getKind() == NodeKind::ObjCBlock) {
flags = flags.withConvention(FunctionMetadataConvention::Block);
Expand All @@ -275,7 +278,9 @@ class TypeDecoder {
flags =
flags.withNumParameters(parameters.size())
.withParameterFlags(hasParamFlags)
.withEscaping(Node->getKind() == NodeKind::FunctionType);
.withEscaping(
Node->getKind() == NodeKind::FunctionType ||
Node->getKind() == NodeKind::EscapingAutoClosureType);

auto result = decodeMangledType(Node->getChild(isThrow ? 2 : 1));
if (!result) return BuiltType();
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/function_metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func test_arch() {
arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in })

// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa"
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1(i64 67108865
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1({{i(32|64)}} 67108865
arch({(x: @escaping () -> ()) -> () in })
}
11 changes: 11 additions & 0 deletions test/Runtime/demangleToMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func f1_owned(x: __owned AnyObject) { }

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

func f1_escaping(_: @escaping (Int) -> Float) { }
func f1_autoclosure(_: @autoclosure () -> Float) { }
func f1_escaping_autoclosure(_: @autoclosure @escaping () -> Float) { }

DemangleToMetadataTests.test("function types") {
// Conventions
expectEqual(type(of: f0), _typeByMangledName("yyc")!)
Expand Down Expand Up @@ -77,6 +81,13 @@ DemangleToMetadataTests.test("function types") {
// A function type that hasn't been built before.
expectEqual("(Int, Float, Double, String, Character, UInt, Bool) -> ()",
String(describing: _typeByMangledName("yySi_SfSdSSs9CharacterVSuSbtc")!))

// Escaping
expectEqual(type(of: f1_escaping), _typeByMangledName("ySfSicc")!)

// Autoclosure
expectEqual(type(of: f1_autoclosure), _typeByMangledName("ySfyXKc")!)
expectEqual(type(of: f1_escaping_autoclosure), _typeByMangledName("ySfyXAc")!)
}

DemangleToMetadataTests.test("metatype types") {
Expand Down