-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Make GlobalCtxt implement Sync #45912
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
|
@bors try |
|
@Zoxc: 🔑 Insufficient privileges: and not in try users |
|
@bors try |
WIP: Playing with adding thread safety to GlobalCtxt
|
Assigning to... r? @pnkfelix |
|
💔 Test failed - status-travis |
|
What is everyone opinion on introducing locks and cc @rust-lang/compiler |
|
I would rather not introduce |
|
I'd like the ability to turn on and off thread safety so we can easily measure the overhead of it. That is going to require some |
|
If the |
7cb9fc5 to
7c78120
Compare
|
☔ The latest upstream changes (presumably #45916) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@bors try |
WIP: Playing with adding thread safety to GlobalCtxt
|
@Mark-Simulacrum Can I get a perf run when bors completes? |
|
💔 Test failed - status-travis |
|
@Zoxc please break every tool in |
| crate-type = ["dylib"] | ||
|
|
||
| [dependencies] | ||
| rustc_data_structures = { path = "../librustc_data_structures" } |
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.
Missing trailing newline
|
|
||
| [dependencies.parking_lot] | ||
| version = "0.5" | ||
| features = ["nightly", "owning_ref"] |
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.
Missing newline
src/librustc_data_structures/lock.rs
Outdated
| fn clone(&self) -> Self { | ||
| Lock::new(self.borrow().clone()) | ||
| } | ||
| } No newline at end of file |
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.
Missing newline
7a7b7e8 to
edcc51a
Compare
|
☔ The latest upstream changes (presumably #45825) made this pull request unmergeable. Please resolve the merge conflicts. |
…fg!(parallel_queries)
|
☔ The latest upstream changes (presumably #46657) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This is being split into smaller PRs. |
Work towards thread safety in rustc This PR is split out from #45912. It contains changes which do not require the `sync` module.
This PR makes the
GlobalCtxtimplementSync, which is the first step towards making rustc thread safe so we can execute queries in multiple threads.The changes here are mostly mechanical where
Cellis replaced byLockCell,Rcis replaced byLrcandRefCellis replaced by eitherLockorRwLock. Some thread local variables are now declared withrustc_global!, which indicates that they are intended to be global to a rustc session, however they aren't changed to global variables since rustdoc has multiple threads with rustc sessions in them.Here is a list of the larger changes:
src/librustc_data_structures/sync.rshas the new types other items related to thread safety.src/libarena/lib.rsis changed so that there's a lock around each arena if thread safety is enabled.[rust] experimental_parallel_queriesentry forconfig.tomlwhich enables thread safety. It is disabled by default.-Z query_threadsallows you to set the number of thread used to compute queries, although it is current ignored.OwningRefinto a thread-safe type.GlobalArenasandDroplessArenaare combined intoAllArenaswhich is the type drivers shoud use. This refactoring makes it easier to create thread-local arenas in the future.SameThreadtype is introduces insrc/librustc_trans/metadata.rswhich asserts that operations on the inner type all happen on the same thread. This is used to makeArchiveROandObjectFileSend + Syncso we can make the[u8]metadata reference into themSend + Sync.ThreadCtxtis introduced.TyCtxtnow points to it instead ofGlobalCtxt.ThreadCtxtcontains a references to aGlobalCtxtand contains the parts of the `GlobalCtxt which has to be thread local.mk_attr_idinsrc/libsyntax/attr.rsis changed to use anAtomicUsize.err_countfield ofHandlerinsrc/librustc_errors/lib.rsis now aAtomicUsizeinstead ofCell<usize>.One thing to note is that
LockandRwLockimplementsClone, since there's code which relies theCloneimpl forRefCell. There's some risk of deadlocks due to that. ReplacingRefCellwithLockalso risks deadlocks, sinceRefCellis re-entrant for read-locks, whileLockis not.