-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Clang importer] Don't bridge blocks to Swift functions in ObjC generic args #17247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,8 +974,8 @@ namespace { | |
// Convert the type arguments. | ||
for (auto typeArg : typeArgs) { | ||
Type importedTypeArg = Impl.importTypeIgnoreIUO( | ||
typeArg, ImportTypeKind::BridgedValue, AllowNSUIntegerAsInt, | ||
Bridging, OTK_None); | ||
typeArg, ImportTypeKind::ObjCCollectionElement, | ||
AllowNSUIntegerAsInt, Bridging, OTK_None); | ||
if (!importedTypeArg) { | ||
importedTypeArgs.clear(); | ||
break; | ||
|
@@ -1102,7 +1102,7 @@ static bool canBridgeTypes(ImportTypeKind importKind) { | |
case ImportTypeKind::CFUnretainedOutParameter: | ||
case ImportTypeKind::Property: | ||
case ImportTypeKind::PropertyWithReferenceSemantics: | ||
case ImportTypeKind::BridgedValue: | ||
case ImportTypeKind::ObjCCollectionElement: | ||
case ImportTypeKind::Typedef: | ||
return true; | ||
} | ||
|
@@ -1116,7 +1116,7 @@ static bool isCFAudited(ImportTypeKind importKind) { | |
case ImportTypeKind::Abstract: | ||
case ImportTypeKind::Typedef: | ||
case ImportTypeKind::Value: | ||
case ImportTypeKind::BridgedValue: | ||
case ImportTypeKind::ObjCCollectionElement: | ||
case ImportTypeKind::Variable: | ||
case ImportTypeKind::Result: | ||
case ImportTypeKind::Pointee: | ||
|
@@ -1287,10 +1287,24 @@ static ImportedType adjustTypeForConcreteImport( | |
// we would prefer to instead use the default Swift convention. | ||
if (hint == ImportHint::Block) { | ||
if (canBridgeTypes(importKind)) { | ||
// Determine the function type representation we need. | ||
// | ||
// For Objective-C collection arguments, we cannot bridge from a block | ||
// to a Swift function type, so force the block representation. Normally | ||
// the mapped type will have a block representation (making this a no-op), | ||
// but in cases where the Clang type was written as a typedef of a | ||
// block type, that typedef will have a Swift function type | ||
// representation. This code will then break down the imported type | ||
// alias and produce a function type with block representation. | ||
auto requiredFunctionTypeRepr = FunctionTypeRepresentation::Swift; | ||
if (importKind == ImportTypeKind::ObjCCollectionElement) { | ||
requiredFunctionTypeRepr = FunctionTypeRepresentation::Block; | ||
} | ||
|
||
auto fTy = importedType->castTo<FunctionType>(); | ||
FunctionType::ExtInfo einfo = fTy->getExtInfo(); | ||
if (einfo.getRepresentation() != FunctionTypeRepresentation::Swift) { | ||
einfo = einfo.withRepresentation(FunctionTypeRepresentation::Swift); | ||
if (einfo.getRepresentation() != requiredFunctionTypeRepr) { | ||
einfo = einfo.withRepresentation(requiredFunctionTypeRepr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the rathole I went down before, because the way in which we pass down the desired "bridgeability" of the imported type doesn't account for blocks, which are bridgeable in some positions but not others. The problem with simply trying to exclude There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, typedefs. In that case, can you update the comment above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. |
||
importedType = fTy->withExtInfo(einfo); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant this comment, which refers to
@convention(block)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grrrr. That comment above is a lie. I'll do a separate comment-only PR for that