-
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 1 commit
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::ObjCGenericArgument, | ||
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::ObjCGenericArgument: | ||
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::ObjCGenericArgument: | ||
case ImportTypeKind::Variable: | ||
case ImportTypeKind::Result: | ||
case ImportTypeKind::Pointee: | ||
|
@@ -1287,10 +1287,19 @@ static ImportedType adjustTypeForConcreteImport( | |
// we would prefer to instead use the default Swift convention. | ||
if (hint == ImportHint::Block) { | ||
if (canBridgeTypes(importKind)) { | ||
// Determine the representation we need. For Objective-C generic | ||
// arguments, we cannot bridge them to a block, so force a block | ||
// representation even if our imported type thus far is a Swift | ||
// function representation. | ||
auto requiredFunctionTypeRepr = FunctionTypeRepresentation::Swift; | ||
if (importKind == ImportTypeKind::ObjCGenericArgument) { | ||
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); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,8 +108,8 @@ enum class ImportTypeKind { | |
/// \brief Import the type of a literal value. | ||
Value, | ||
|
||
/// \brief Import the type of a literal value that can be bridged. | ||
BridgedValue, | ||
/// \brief Import the type of an Objective-C generic argument. | ||
ObjCGenericArgument, | ||
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. I feel like this isn't just any generic argument, since most of the time we'd import 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. Good point! |
||
|
||
/// \brief Import the declared type of a variable. | ||
Variable, | ||
|
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