Uh oh!
There was an error while loading. Please reload this page.
Make GlobalCtxt implement Sync - #45912
Conversation
Zoxc
commented
Nov 10, 2017
@bors try |
bors
commented
Nov 10, 2017
@Zoxc: 🔑 Insufficient privileges: and not in try users |
shepmaster
commented
Nov 10, 2017
@bors try |
bors
commented
Nov 10, 2017
WIP: Playing with adding thread safety to GlobalCtxt
shepmaster
commented
Nov 10, 2017
Assigning to... r? @pnkfelix |
bors
commented
Nov 10, 2017
💔 Test failed - status-travis |
Zoxc
commented
Nov 10, 2017
What is everyone opinion on introducing locks and cc @rust-lang/compiler |
eddyb
commented
Nov 10, 2017
I would rather not introduce |
Zoxc
commented
Nov 10, 2017
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 |
michaelwoerister
commented
Nov 13, 2017
If the |
7cb9fc5 to
7c78120Comparebors
commented
Nov 14, 2017
☔ The latest upstream changes (presumably #45916) made this pull request unmergeable. Please resolve the merge conflicts. |
Zoxc
commented
Nov 14, 2017
@bors try |
bors
commented
Nov 14, 2017
WIP: Playing with adding thread safety to GlobalCtxt
Zoxc
commented
Nov 14, 2017
@Mark-Simulacrum Can I get a perf run when bors completes? |
bors
commented
Nov 14, 2017
💔 Test failed - status-travis |
kennytm
commented
Nov 14, 2017
@Zoxc please break every tool in |
| crate-type = ["dylib"] | ||
| [dependencies] | ||
| rustc_data_structures = { path = "../librustc_data_structures" } No newline at end of file |
| [dependencies.parking_lot] | ||
| version = "0.5" | ||
| features = ["nightly", "owning_ref"] No newline at end of file |
| fn clone(&self) -> Self { | ||
| Lock::new(self.borrow().clone()) | ||
| } | ||
| } No newline at end of file |
7a7b7e8 to
edcc51aComparebors
commented
Nov 16, 2017
☔ The latest upstream changes (presumably #45825) made this pull request unmergeable. Please resolve the merge conflicts. |
…fg!(parallel_queries)
bors
commented
Dec 12, 2017
☔ The latest upstream changes (presumably #46657) made this pull request unmergeable. Please resolve the merge conflicts. |
Zoxc
commented
Dec 17, 2017
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.