Repository navigation
Implement Fn traits for safe functions of any ABI - #160186
Jules-Bertholet wants to merge 1 commit into
Conversation
|
cc @rust-lang/miri |
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Don't you need to generate shims or Happy Things will happen? |
|
I don't think so? The basic tests I added work fine, and Miri doesn't complain. But I don't really know that part of the codebase, am relying on Cunningham's Law |
|
I suggest you check with |
|
Nothing broke… |
|
🤷 Maybe it is fine... |
|
Although the practical ABI for |
|
Probably should make sure the function that calls the |
|
Yeah I'd expect the rust-call / argument (un)tupling to go wrong here as that needs the Rust ABI. Does this actually solve a problem? If not I'd rather update the docs. |
32a4f77 to
2403142
Compare
|
Modified the tests to use a function that I confirmed with Godbolt has a completely different |
With new ABIs like |
|
I guess what happens is that we synthesize a But someone should dig into where that happens. |
|
|
||
| pub fn is_fn_trait_compatible(self) -> bool { | ||
| !self.c_variadic() && self.safety().is_safe() && self.abi() == ExternAbi::Rust | ||
| !self.c_variadic() && self.safety().is_safe() && self.abi().is_fn_trait_compatible() |
There was a problem hiding this comment.
| !self.c_variadic() && self.safety().is_safe() && self.abi().is_fn_trait_compatible() | |
| self.safety().is_safe() && self.abi().is_fn_trait_compatible() |
We could try to remove the !self.c_variadic() condition. But there's not much point, as any actual use of variadics is necessarily unsafe. It would also be a bunch of work, as the trait solver currently assumes no type has more than one impl of each Fn trait.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Does this need an update to the Rust Reference, which currently says:
https://doc.rust-lang.org/stable/reference/types/function-item.html#r-type.fn-item.traits Or do we do those kinds of updates later? |
|
Reference PR: rust-lang/reference#2383 |
This comment has been minimized.
This comment has been minimized.
This brings the behavior of the language in line with the documentation in `library/core/src/primitive_docs.rs`.
cd9fa00 to
4621dfe
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
Makes sense to me. Thanks @Jules-Bertholet (and thanks for filing the Reference PR). @rfcbot reviewed |
|
@rfcbot reviewed |
|
I remember we talked about tracking this in some fashion, but I don't think that applies to the |
|
I see some discussion about whether this causes ABI compatability problems. Why does it not cause any such issues, can this reasoning be written down somewhere? |
@teor2345 tracked it down in #160186 (comment). Essentially, nothing in |
|
Or put differently, IIUC this ends up generating a shim that serves as an ABI conversion trampoline. |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
@tmandry Could you resolve your concern? Thanks. |
View all comments
This brings the behavior of the language in line with its documentation:
rust/library/core/src/primitive_docs.rs
Lines 1930 to 1931 in 1a833e1
ABIs that are not callable, or that are internal implementation details, are excluded.
Reference PR: rust-lang/reference#2383
@rustbot label T-lang needs-fcp A-ABI A-extern-fn I-lang-nominated