-
Notifications
You must be signed in to change notification settings - Fork 13k
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
thread_local: be excruciatingly explicit in dtor code #124387
thread_local: be excruciatingly explicit in dtor code #124387
Conversation
Instead, use raw pointers to accomplish internal mutability throughout.
141bba9
to
496fa7f
Compare
LazyKeyInner::take
to use less &mut T
sthread_local
: be excruciatingly explicit in dtor code
thread_local
: be excruciatingly explicit in dtor code496fa7f
to
43f21a6
Compare
let value = inner.take(); | ||
dtor_state.set(DtorState::RunningOrHasRun); | ||
drop(value); |
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.
something that's not clear to me is whether we can simply rearrange this: do dtor_state.set(DtorState::RunningOrHasRun)
and then call the more lightweight drop_in_place
?
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.
We could, and there are some other improvements possible as well, see #116123.
let Key { inner, dtor_state } = &*ptr; | ||
let value = inner.take(); |
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.
The purpose of adding this two-step is to make it clear, combined with the other change, that we are using internal mutability and not relying on upgrading the pointer to &mut
.
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.
👍
r=me with the updated safety comment
let value = inner.take(); | ||
dtor_state.set(DtorState::RunningOrHasRun); | ||
drop(value); |
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.
We could, and there are some other improvements possible as well, see #116123.
Co-authored-by: joboet <[email protected]>
@bors r=joboet rollup |
…-thread-locals, r=joboet thread_local: be excruciatingly explicit in dtor code Use raw pointers to accomplish internal mutability, and clearly split references where applicable. This reduces the likelihood that any of these parts are misunderstood, either by humans or the compiler's optimizations. Fixes rust-lang#124317 r? `@joboet`
Rollup of 3 pull requests Successful merges: - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases) - rust-lang#124382 (ast: Generalize item kind visiting) - rust-lang#124387 (thread_local: be excruciatingly explicit in dtor code) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 3 pull requests Successful merges: - rust-lang#124382 (ast: Generalize item kind visiting) - rust-lang#124387 (thread_local: be excruciatingly explicit in dtor code) - rust-lang#124427 (Add missing tests for an ICE) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124387 - workingjubilee:use-raw-pointers-in-thread-locals, r=joboet thread_local: be excruciatingly explicit in dtor code Use raw pointers to accomplish internal mutability, and clearly split references where applicable. This reduces the likelihood that any of these parts are misunderstood, either by humans or the compiler's optimizations. Fixes rust-lang#124317 r? ``@joboet``
Use raw pointers to accomplish internal mutability, and clearly split references where applicable. This reduces the likelihood that any of these parts are misunderstood, either by humans or the compiler's optimizations.
Fixes #124317
r? @joboet