-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow C++ function templates to be instantiated with Swift closures #81016
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
Conversation
@swift-ci please test |
lib/AST/ClangTypeConverter.cpp
Outdated
@@ -991,6 +1007,22 @@ clang::QualType ClangTypeConverter::convertTemplateArgument(Type type) { | |||
return clang::QualType(); | |||
} | |||
|
|||
if (auto functionType = type->getAs<FunctionType>()) { | |||
if (llvm::none_of(functionType->getParams(), [](auto ¶m) { |
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.
Why do we have this restriction for FunctionType
but not for SILFunctionType
?
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.
Oh, good catch! I'll add this check to SILFunctionType as well.
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.
I actually decided to remove the check. All template instantiations involving FRTs are wonky because of nullable<->optional round-tripping, so I think we should keep that behavior at least consistent (even if the behavior is wrong).
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.
(specifically, the behavior is that the compiler crashes...)
a81d356
to
d3d08f9
Compare
@swift-ci please test |
Hm. Apparently raw C function pointers don't work without the blocks runtime either. I'm going to move these to the |
d3d08f9
to
922cc65
Compare
@swift-ci please test |
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.
Thanks!
@swift-ci please test macOS |
1 similar comment
@swift-ci please test macOS |
@swift-ci please test macos |
…ift closures Swift started to explicitly forbid the instantiation of C++ function templates with arbitrary types in swiftlang#77430, because many types cause the Swift compiler to crash. However, those checks prevented them from being instantiated with Swift closures (which were previously fine), causing a regression. This patch relaxes the convertTemplateArgument() function to also allow converting Swift function types, and adds some tests to make sure doing so is fine. This patch also does some cleanup of existing tests checking the instantiation of various types, and adds testing for C function pointers and Obj-C blocks. rdar://148124104
This Boolean flag is used in ClangTypeConverter to indicate whether a type is being converted in the context of a template type parameter. This parameter can be made a template parameter because it is always a compile-time constant.
922cc65
to
fee1dd3
Compare
@swift-ci please test |
@swift-ci please test macos |
1 similar comment
@swift-ci please test macos |
Swift started to explicitly forbid the instantiation of C++ function templates with arbitrary types in #77430, because many types cause the Swift compiler to crash. However, those checks prevented them from being instantiated with Swift closures (which were previously fine), causing a regression.
This patch relaxes the convertTemplateArgument() function to also allow converting Swift function types, and adds some tests to make sure doing so is fine. This patch also does some cleanup of an existing test checking the instantiation of various types.
rdar://148124104