-
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
When testing std, don't create two variants of threading internals #58399
Conversation
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
src/libstd/io/stdio.rs
Outdated
@@ -7,6 +7,9 @@ use io::{self, Initializer, BufReader, LineWriter}; | |||
use sync::{Arc, Mutex, MutexGuard}; | |||
use sys::stdio; | |||
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; | |||
#[cfg(test)] | |||
use realstd::thread::LocalKey; | |||
#[cfg(not(test))] |
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 is... ugly. But I don't really see another way.
Note for people following along via email: I updated the description to include info about the second commit. |
☔ The latest upstream changes (presumably #58098) made this pull request unmergeable. Please resolve the merge conflicts. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
fa3df5c
to
4612722
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
4612722
to
1beafad
Compare
Ok, this should be ready for review now. I originally tried to surgically replace use of the affected globals (see e.g. a982943da5fb3f288cfa7e99fc218b34159ac695), but they're hidden behind various layers of abstraction that are not accessible through the I've come up with some alternatives that could be considered instead:
|
8e0b3c6
to
5a8d3a5
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
5a8d3a5
to
4ba369c
Compare
There are some remaining unit tests in |
Closing this in favor of using |
When compiling the unit tests of
std
, there are basically two copies ofstd
: one normal one, and one withcfg(test)
. This can lead to problems if both copies think they uniquely define a global resource.One such global resource is the static variables used for the Thread Local Storage implementation on some platforms, including SGX and possibly Redox (cc @jackpot51). Another is the static variables used for the Task Queue implementation on some platforms, including SGX. This PR does two things:
cfg(test)
-copy ofmod thread
, just re-exportrealstd::thread
. Move all the unit tests that were in that module to a separate module. This all leads to some dead code fallout, so addallow
directives in various places.cfg(test)
-version of the implementation early.I didn't audit
std
for other uses ofstatic
that might be problematic.