-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Strengthen validation of FFI attributes #107257
Conversation
Previously, we verified that FFI attrs were used on foreign items, but this allowed them on both foreign functions and foreign statics. This change only allows them on foreign functions.
r? @nagisa (rustbot has picked a reviewer for you, use r? to override) |
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki |
Not an official reviewer, but I looked through the commits and it looks good to me.
I think it'd be better if you move them into the |
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.
LGTM, but this is technically a breaking change, so I think we'll want to do a crater run to see how safe this is to land.
r? @davidtwco |
@bors try |
⌛ Trying commit 0983ac8b4283fec01e83fe3d41cf3add0597691a with merge cc7a22a8fa04e430abcb30a0b627b66011dd0ec3... |
All these attributes are still unstable, so it shouldn't be a problem? Unless we're worried about breaking nightly code. |
Oh, I should have checked that, great - that's much simpler. |
@bors r+ |
📌 Commit 0983ac8b4283fec01e83fe3d41cf3add0597691a has been approved by It is now in the queue for this repository. |
I did mention it in the OP, but I don't blame you for missing it - I'm not the most concise. Thanks for the review! ❤️ |
☀️ Test successful - checks-actions |
👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward |
For future reference, do not approve a PR when a try-build is running, or else it will try to be merged into master 😬 |
Oh, oops, hadn't done that before. My bad. |
I'm going to force push and then close and reopen to reset things (at least, those are the steps I've seen before; not sure which of the two is required, but doing both can't hurt). |
0983ac8
to
bc23e9a
Compare
I think if someone approves again we should be set? The change to the last commit only affected the commit message. |
Finished benchmarking commit (cc7a22a8fa04e430abcb30a0b627b66011dd0ec3): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
@davidtwco: could you |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (11d96b5): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
Previously,
codegen_attrs
validated the attributes#[ffi_pure]
,#[ffi_const]
, and#[ffi_returns_twice]
to make sure that they were only used on foreign functions. However, this validation was insufficient in two ways:codegen_attrs
only sees items for which code must be generated, so it was unable to raise errors when the attribute was incorrectly applied to macros and the like.This PR moves the validation to
check_attr
, which sees all items. It additionally changes the validation to ensure that the attribute's target isTarget::ForeignFunction
, only allowing the attributes on foreign functions and not foreign statics. Because these attributes are unstable, there is no risk for backwards compatibility. The changes also ending up making the code much easier to read.This PR is best reviewed commit by commit. Additionally, I was considering moving the tests to the
attribute
subdirectory, to get them out of the general UI directory. I could do that as part of this PR or a follow-up, as the reviewer prefers.CC: #58328, #58329