-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow initializing std::function
from Swift closures
#71396
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 smoke test |
expectEqual(222, res) | ||
} | ||
|
||
// FIXME: assertion for address-only closure params |
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.
This is a major limitation that I intend to fix before merging this
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.
This will be fixed by #73561
e11d309
to
28d3e29
Compare
@swift-ci please smoke test |
This fixes a linker error when using `std::function` from Swift. rdar://103979602
8ebee73
to
2a43d8c
Compare
@swift-ci please smoke test |
2a43d8c
to
1bc7e54
Compare
@swift-ci please smoke test |
1bc7e54
to
7645a40
Compare
@swift-ci please smoke test |
This adds a Swift initializer to instantiations of `std::function` that accepts a Swift closure with `@convention(c)`. rdar://103979602
8fee0af
to
3243228
Compare
@swift-ci please smoke test |
I'm going to merge this to unblock some other work, but I'm happy to address review comments post-merge. |
#if !os(Windows) // FIXME: rdar://103979602 | ||
StdFunctionTestSuite.test("FunctionIntToInt init from closure and call") { | ||
let cClosure: @convention(c) (Int32) -> Int32 = { $0 + 1 } | ||
let f = FunctionIntToInt(cClosure) |
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.
Do we want to have a test case where the closure actually captures some local state? Or is it not yet supported?
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.
That's not supported yet. @convention(c)
closures (aka the ones that can be bridged to C function pointers) cannot capture context in Swift. In the future we'll need to add support for converting @convention(thick)
closures to std::function
, but it requires more work.
This adds a Swift initializer to instantiations of
std::function
that accepts a Swift closure with@convention(c)
.rdar://103979602