-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
constify a couple thread_local statics #120976
Conversation
@@ -42,7 +42,7 @@ pub struct Registry(Arc<RegistryData>); | |||
thread_local! { | |||
/// The registry associated with the thread. | |||
/// This allows the `WorkerLocal` type to clone the registry in its constructor. | |||
static REGISTRY: OnceCell<Registry> = OnceCell::new(); | |||
static REGISTRY: OnceCell<Registry> = const { OnceCell::new() }; |
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.
What is the benefit of doing this?
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.
according to the docs it can be more efficient to wrap in const
https://rust-lang.github.io/rust-clippy/master/index.html#/thread_local_initializer_can_be_made_const
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.
A more practical demonstration: https://godbolt.org/z/K1Yxe8193 (You can see that the first variant does lazy initialization and the second does not).
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.
Gotcha, I missed that this is a thread_local! particular thing.
r? compiler |
@bors r+ rollup |
…r=lcnr constify a couple thread_local statics
…llaumeGomez Rollup of 9 pull requests Successful merges: - rust-lang#120976 (constify a couple thread_local statics) - rust-lang#121576 (Convert the rest of the visitors to use `VisitorResult`) - rust-lang#121826 (Use root obligation on E0277 for some cases) - rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`) - rust-lang#121958 (Fix redundant import errors for preload extern crate) - rust-lang#121959 (Removing absolute path in proc-macro) - rust-lang#121968 (Don't run test_get_os_named_thread on win7) - rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.) - rust-lang#121978 (Fix duplicated path in the "not found dylib" error) r? `@ghost` `@rustbot` modify labels: rollup
…r=lcnr constify a couple thread_local statics
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#120976 (constify a couple thread_local statics) - rust-lang#121683 (Fix LVI tests after frame pointers are enabled by default) - rust-lang#121703 (Add a way to add constructors for `rustc_type_ir` types) - rust-lang#121732 (Improve assert_matches! documentation) - rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`) - rust-lang#121939 (Small enhancement to description of From trait) - rust-lang#121968 (Don't run test_get_os_named_thread on win7) - rust-lang#121969 (`ParseSess` cleanups) - rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.) - rust-lang#121994 (Update platform-support.md with supported musl version) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#120976 (constify a couple thread_local statics) - rust-lang#121683 (Fix LVI tests after frame pointers are enabled by default) - rust-lang#121703 (Add a way to add constructors for `rustc_type_ir` types) - rust-lang#121732 (Improve assert_matches! documentation) - rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`) - rust-lang#121939 (Small enhancement to description of From trait) - rust-lang#121968 (Don't run test_get_os_named_thread on win7) - rust-lang#121969 (`ParseSess` cleanups) - rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.) - rust-lang#121994 (Update platform-support.md with supported musl version) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120976 - matthiaskrgr:constify_TL_statics, r=lcnr constify a couple thread_local statics
No description provided.