Skip to content

[5.7] SILGen: Use ObjC types to lower async completion handler arguments. #59175

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
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
11 changes: 11 additions & 0 deletions lib/SILGen/SILGenThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ SILFunction *SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
}
return maybeCompletionHandlerOrigTy.getValue();
}();

// Bridge the block type, so that if it is formally expressed in terms of
// bridged Swift types, we still lower the parameters to their ultimate
// ObjC types.
completionHandlerOrigTy = Types
.getBridgedFunctionType(AbstractionPattern(origFormalType.getGenericSignatureOrNull(),
completionHandlerOrigTy),
completionHandlerOrigTy,
Bridgeability::Full,
SILFunctionTypeRepresentation::Block);

auto blockParams = completionHandlerOrigTy.getParams();

// Build up the implementation function type, which matches the
Expand Down
22 changes: 22 additions & 0 deletions test/SILGen/objc_async_defined_in_swift_any.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) -disable-availability-checking -verify %s
// REQUIRES: concurrency
// REQUIRES: objc_interop

import Foundation
@objc public protocol TAService {
func removeKey() async -> Any
}

class FakeService : TAService {
func removeKey() async -> Any {
return ""
}
}

class FakeClassHolder {
var service : TAService = FakeService()

func removeKey(_ key: String) async {
_ = await self.service.removeKey()
}
}