-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix FP in threadlocal!
when falling back to os_local
#12276
Conversation
@rustbot label +beta-nominated I think this should be merged upstream as well. |
Just tested this patch on an ARM 64-bit Linux, that's a target that the CI doesn't look for. Quinn has checked for Windows (which I'd think she'd be able to check for both MSVC and GNU), and nobody uses 32-bit Windows. I think that this patch is covered on the test department. |
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.
Just some mini-nits. Mainly regarding to consistency with the rest of the codebase. I'll benchmark this PR, I'm a little bit worried about the optimized-MIR call, but that may not have as big of an effect as we might think.
Sorry for being so thorough, you asked for high standards, and these are my highest reasonable standards 😅
Thank you Alejandra I appreciate your time and effort! I found another case I hadn't considered initially, and will add that with the changes. |
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.
Need more tests to check the case where we should peel.
Okis, sorry for the delay. I finally have the benchmark results: There isn't really a big performance change |
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 should have a comment linking to this issue and some conditional compilation. If the issue only shows on a fallback, it's kinda silly to check this for non-fallback compilations.
Apart from that, LGTM
If this is fine, maybe we can merge this to bundle it with the release? |
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, thanks! ❤️ Could you squash the commits?
`os_local` impl of `thread_local` — regardless of whether it is const and unlike other implementations — includes an `fn __init(): EXPR`. Existing implementation of the lint checked for the presence of said function and whether the expr can be made const. Because for `os_local` we always have an `__init()`, it triggers for const implementations. The solution is to check whether the `__init()` function is already const. If it is `const`, there is nothing to do. Otherwise, we verify that we can make it const. Co-authored-by: Alejandra González <[email protected]>
Done, thanks! |
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
…ulacrum [beta] Clippy backports Backports included in this PR: - rust-lang/rust-clippy#12276 Fixing the lint on some platforms before hitting stable - rust-lang/rust-clippy#12405 Respect MSRV before hitting stable - rust-lang/rust-clippy#12266 Fixing an (unlikely) ICE - rust-lang/rust-clippy#12177 Fixing FPs before hitting stable Each backport on its own might not warrant a backport, but the collection of those are nice QoL fixes for Clippy users, before those bugs hit stable. All of those commits are already on `master`. r? `@Mark-Simulacrum`
Issue: The lint always triggers for some targets.
Why: The lint assumes an
__init
function is not present for const initializers.This does not hold for all targets. Some targets always have an initializer function.
Fix: If an initializer function exists, we check that it is not a
const
fn.Lint overview before the patch:
threadlocal!
, then exit early.threadlocal!
and__init
does not exist => is const already, exit early.threadlocal!
and__init
exists and__init
body can beconst
=> we lint.Lint overview after the patch:
threadlocal!
, then exit early.threadlocal!
and__init
does not exist => is const already, exit early.threadlocal!
and__init
exists and isconst fn
=> is const already, exit early.threadlocal!
and__init
exists and is notconst fn
and__init
body can beconst
=> we lint.The patch adds step 3.
changelog: Fixed fp in [
thread_local_initializer_can_be_made_const
] where fallback implementation ofthreadlocal!
was always linted.Verifying the changes
For each of these platforms [ mac, x86_64-windows-gnu, x86_64-windows-msvc ]:
How platform affects the lint:
The compiler performs a conditional compilation depending on platform features. The
os_local
fallback includes a call to__init
, without step 3, we lint in all cases.r? @llogiq