thread_local: be excruciatingly explicit in dtor code#124387
thread_local: be excruciatingly explicit in dtor code#124387bors merged 3 commits intorust-lang:masterfrom
Conversation
Instead, use raw pointers to accomplish internal mutability throughout.
141bba9 to
496fa7f
Compare
LazyKeyInner::take to use less &mut Tsthread_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.
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.
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.
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.
joboet
left a comment
There was a problem hiding this comment.
👍
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.
We could, and there are some other improvements possible as well, see #116123.
Co-authored-by: joboet <jonasboettiger@icloud.com>
|
@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