-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Restructure and rename std thread_local internals to make it less of a maze #110861
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
Conversation
|
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@bors rollup=never (If there's breakage it is probably platform specific.) |
|
I was asked to take a look at this. r? @workingjubilee |
|
(Btw, this patch is probably easier to review with whitespace changes hidden, because of the removed indentation for the nested modules: https://github.com/rust-lang/rust/pull/110861/files?diff=unified&w=1) |
| enum DtorState { | ||
| Unregistered, | ||
| Registered, | ||
| RunningOrHasRun, |
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.
BeRunning?
BeganRunning
RunningStart
WouldEnglishPleaseGetARealPerfectiveTense
( these are silly thoughts, pay me no mind. )
| // This data structure has been carefully constructed so that the fast path | ||
| // only contains one branch on x86. That optimization is necessary to avoid | ||
| // duplicated tls lookups on OSX. | ||
| // | ||
| // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 |
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.
While we're doing spring cleaning: This comment is 4 years old. While the LLVM issue hasn't been closed, is this concern re: assembly generation still true? Well, I suppose that can be another issue. llvm/llvm-project#41067
|
Oh I see now, it's... ugh. Both of these views suck! @bors r+ |
|
The |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (cb9aa8c): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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. |
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? `@m-ou-se`
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ``@m-ou-se``
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ```@m-ou-se```
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ````@m-ou-se````
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? `````@m-ou-se`````
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang#100201 and rust-lang#106638, which got reverted by rust-lang#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ``````@m-ou-se``````
avoid duplicating TLS state between test std and realstd This basically re-lands rust-lang/rust#100201 and rust-lang/rust#106638, which got reverted by rust-lang/rust#110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ``````@m-ou-se``````
Every time I try to work on std's thread local internals, it feels like I'm trying to navigate a confusing maze made of macros, deeply nested modules, and types with multiple names/aliases. Time to clean it up a bit.
This PR:
Keywith its own name (Key), instead of__LocalKeyInnerpub macroto put__thread_local_innerinto a (unstable, hidden) module, removing#[macro_export], removing it from the crate root.__from__thread_local_inner.allow_internal_unstablefeatures from the macroslibstd_thread_internalsfeature. (Merged withthread_local_internals.)Keydefinitions (mod fast/mod os/mod statik).#[cfg]mess into a singlecfg_if, now that there's no#[macro_export]anymore that breaks withcfg_if.cfg_ifconditions to not repeat the conditions.normalize-stderr-test, which were left over from when theKeytypes had different names on different platforms.realstdre-export oncfg(test).This PR changes nothing about the thread local implementation. That's for a later PR. (Which should hopefully be easier once all this stuff is a bit cleaned up.)