-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 GlobalCtxt implement Sync #45912
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 |
@@ -7,3 +7,6 @@ version = "0.0.0" | |||
name = "arena" | |||
path = "lib.rs" | |||
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()) | ||
} | ||
} |
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
GlobalCtxt
implementSync
, 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
Cell
is replaced byLockCell
,Rc
is replaced byLrc
andRefCell
is replaced by eitherLock
orRwLock
. 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.rs
has the new types other items related to thread safety.src/libarena/lib.rs
is changed so that there's a lock around each arena if thread safety is enabled.[rust] experimental_parallel_queries
entry forconfig.toml
which enables thread safety. It is disabled by default.-Z query_threads
allows you to set the number of thread used to compute queries, although it is current ignored.OwningRef
into a thread-safe type.GlobalArenas
andDroplessArena
are combined intoAllArenas
which is the type drivers shoud use. This refactoring makes it easier to create thread-local arenas in the future.SameThread
type is introduces insrc/librustc_trans/metadata.rs
which asserts that operations on the inner type all happen on the same thread. This is used to makeArchiveRO
andObjectFile
Send + Sync
so we can make the[u8]
metadata reference into themSend + Sync
.ThreadCtxt
is introduced.TyCtxt
now points to it instead ofGlobalCtxt
.ThreadCtxt
contains a references to aGlobalCtxt
and contains the parts of the `GlobalCtxt which has to be thread local.mk_attr_id
insrc/libsyntax/attr.rs
is changed to use anAtomicUsize
.err_count
field ofHandler
insrc/librustc_errors/lib.rs
is now aAtomicUsize
instead ofCell<usize>
.One thing to note is that
Lock
andRwLock
implementsClone
, since there's code which relies theClone
impl forRefCell
. There's some risk of deadlocks due to that. ReplacingRefCell
withLock
also risks deadlocks, sinceRefCell
is re-entrant for read-locks, whileLock
is not.