-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Make GlobalContext Sync #15967
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
Make GlobalContext Sync #15967
Conversation
r? @weihanglo rustbot has assigned @weihanglo. Use |
Thanks! |
FYI we are fine with editing existing history and, in a case like this, I would prefer it over having fixup commits later in the history as it makes the commits I'm reviewing more understandable on their own. |
eb1396a
to
7f8e4f9
Compare
7f8e4f9
to
f2b8539
Compare
This will make it easier to change the implementation in the future.
64e7db5
to
cec5a22
Compare
a01b9bf
to
a590d3e
Compare
… is just a HashMap::defualt()
Previously, `gctx.shell().verbosity()` was used to check that `gctx.shell` is not borrowed. Since shell is now behind a `Mutex` and not a `RefCell`, this would hang waiting for the unlock instead panicking. Borrow state checking is now done using `Mutex::try_lock` in `GlobalContext::debug_assert_shell_not_borrowed`
a590d3e
to
9929c87
Compare
Thanks! |
What does this PR try to resolve?
By making
GlobalContext
Sync
, it will become much easier to parallelize parts of cargo. A concrete example is #15676.It was my understanding from #15934 (comment) that this would be a welcome change by the cargo team.
Overview
In
GlobalContext
and structs used in its fieldsRefCell
-s were replaced by either anstd::sync::Mutex
or anstd::sync::RwLock
, depending on API needsLazyCell
-s were replaced by a newOnceLock
implementation backed bystd::sync::OnceLock
, emulating unstable features needed by cargoLazyCell
/OnceLock
from fields where the initialization function is just aMutex<HashMap>::default()
util::context::tests::sync_context
test that does not compile ifGlobalContext
is notSync
How to test and review this PR?
This PR should add no user-facing changes. Tests must pass and benchmarks must report no changes.