-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Allow closure to extern fn pointer coercion #61528
Conversation
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
This is not analogous to #59580 because in that case we had a coercion A => B (closure -> |
It's unclear to me exactly what this would do: you might have a closure that is called once in rust and then passed into a function or place which expected a C ABI. Is a C ABI used for both? Are two functions generated? One function and a shim? Also, how does this interact with the improper C-types lint? These questions feel pretty easily resolvable to me, but there is design work here-- this isn't an entirely obvious/self-explanatory addition IMO. I'd like to see a (short) RFC for this so that we can more formally specify the behavior of this feature. |
r? @cramertj |
I actually wanted to add a test case for improper_ctypes but then noticed that extern function definitions don't trigger it, only functions in an extern block do (see #19834). So for now nothing needs to be done to be consistent with free-standing extern functions.
Okay. I might have time in the next few days to write one, but I'm not sure. |
We discussed this on the language team meeting yesterday where we had some questions along the lines outlined by @cramertj in #61528 (comment). We felt that while we can land this PR separately and under a feature gate with an associated tracking issue, it would indeed be good to follow up with an RFC to flesh out the details. To the end of feature gating, I think it would be a good idea to move all tests introduced and modified into a separate folder under |
☔ The latest upstream changes (presumably #61506) made this pull request unmergeable. Please resolve the merge conflicts. |
380fbc2
to
117c8b1
Compare
Rebased and moved the tests. I didn't try feature-gating this yet, will do so when I find the time. |
and add a corresponding test. It still fails because the feature gate is not actually implemented. [ci skip]
☔ The latest upstream changes (presumably #60732) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -192,7 +192,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |||
} | |||
} | |||
} | |||
mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_)) => { | |||
mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_, _)) => { |
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 wrong, it needs a shim to work correctly. I think we should consider having a coercion from a Rust function item (not a fn
pointer) to an extern "..." fn
pointer.
Then the closure coercion would still be "like coercing <typeof(|| ...) as FnOnce<_>>::call_once
, modulo first argument", and they would both have the extra capability of switching ABI.
Given @eddyb's review, this looks like it is not as straight-forward as I had hoped. This feature is more of a nice-to-have for me rather than something I'd like to invest significant time into, so I'd be happy if somebody else took over. Otherwise, I might still come back to this some time in the future. This PR could probably be tagged |
@jplatte thanks for the comment but we don't tag PRs with "E-help-wanted". Closing this, and will leave a comment on the main issue |
Analogous to #59580, resolves #44291.
I'm still quite new to rustc and don't know how legit it was to basically just redo the same thing the PR for closure to unsafe fn pointer coercion did with abi instead of unsafety.