-
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
Work towards thread safety in rustc #46779
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
c67d30e
to
6b295aa
Compare
Ok(vec.into()) | ||
}) | ||
} | ||
} |
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
src/libsyntax_pos/lib.rs
Outdated
@@ -163,10 +163,6 @@ impl SpanData { | |||
} | |||
} | |||
|
|||
// The interner in thread-local, so `Span` shouldn't move between threads. | |||
impl !Send for Span {} |
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.
Could you please make the interner thread-safe?
src/libsyntax_pos/symbol.rs
Outdated
@@ -83,10 +83,6 @@ impl Decodable for Ident { | |||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | |||
pub struct Symbol(u32); | |||
|
|||
// The interner in thread-local, so `Symbol` shouldn't move between threads. | |||
impl !Send for Symbol { } |
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.
Same here
@bjorn3 Thread-safety for the interners happens in a later commit. |
@Zoxc that commit doesnt seem to be included in this pr. |
It is in #45912. |
Each PR must leave the compiler in safe/valid state. Implementing |
@michaelwoerister The |
My concern is just that this PR, as it is, would leave the compiler in a state where I can send |
@@ -42,6 +42,8 @@ use std::cell::{RefCell, Cell}; | |||
use std::mem; | |||
use std::rc::Rc; | |||
use std::{error, fmt}; | |||
use std::sync::atomic::AtomicUsize; |
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.
err_count
probably needs to be done in a smarter way than here to assure thread-safety, so could you add a FIXME
? In any case this is better than the way before this.
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.
In which case is this not thread safe?
let files = self.codemap.files(); | ||
|
||
if files.len() > 0 { | ||
if self.codemap.files().len() > 0 { |
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.
Don't we need a better locking discipline for the codemap? It feels like "too many locks, not enough discipline". Maybe just add a fixme to it?
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.
Given that I just convert all RefCell
s into locks, there's probably plenty of places where there are too many locks.
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.
ok
src/libsyntax_pos/lib.rs
Outdated
@@ -163,10 +163,6 @@ impl SpanData { | |||
} |
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.
How is this sound?
src/libsyntax_pos/symbol.rs
Outdated
@@ -384,8 +384,6 @@ impl<'a> ::std::cmp::PartialEq<InternedString> for &'a String { | |||
} |
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.
How is this sound?
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.
Oh, InternedString
storing a &'static str
isn't sound at all. I'll have to change it to using a u32
like Symbol.
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.
Well that made it unable to implement Deref<Target=str>
, so I went with the approach suggested in a FIXME and just leak interned strings.
6b295aa
to
dbee5b9
Compare
dbee5b9
to
84ce4f1
Compare
@bors r=arielb1 |
📌 Commit 84ce4f1 has been approved by |
Work towards thread safety in rustc This PR is split out from #45912. It contains changes which do not require the `sync` module.
☀️ Test successful - status-appveyor, status-travis |
slot.set(r + 1); | ||
r | ||
}); | ||
let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst); |
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.
@rust-lang/compiler Not sure how I feel about this kind of stuff - it will behave non-deterministically in any process running multiple rustc threads in parallel (atm rustc "owns" a thread).
IMO all thread-locals should change to scoped thread locals initialized to point to some memory owned by the thread that started the compilation, if we want multiple threads per rustc "instance".
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.
Good point. I'll make this either a scoped thread local or put it in ParseSess
if that happens to be easy.
This PR is split out from #45912. It contains changes which do not require the
sync
module.