-
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
Even more thread-safety changes #49558
Conversation
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
d873356
to
0b4571c
Compare
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ping from triage, @michaelwoerister ! |
☔ The latest upstream changes (presumably #49714) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc_data_structures/sync.rs
Outdated
@@ -241,6 +242,75 @@ impl<K: Eq + Hash, V: Eq, S: BuildHasher> HashMapExt<K, V> for HashMap<K, V, S> | |||
} | |||
} | |||
|
|||
/// A type whose inner value can be written once and then will stay read-only | |||
pub struct Once<T>(Lock<Option<T>>, PhantomData<T>); |
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.
What's the PhantomData
for?
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.
Once
conceptually owns a T
outside the lock once it is initialized. This ensures we get the right impl for Sync
: impl<T: Sync> Sync for Once<T>
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 catch! Could you add a comment explaining that?
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.
Plus maybe an example of how one could exploit Once<T>
if the PhantomData
was not there?
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.
Done.
@@ -154,13 +154,13 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize { | |||
} | |||
} | |||
|
|||
pub fn create_target_machine(sess: &Session) -> TargetMachineRef { | |||
target_machine_factory(sess)().unwrap_or_else(|err| { | |||
pub fn create_target_machine(sess: &Session, find_features: bool) -> TargetMachineRef { |
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.
What's the find_features
parameter about?
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.
create_target_machine
calls is_pie_binary
which requires crate_types
. However when we are discovering the target CPU features, crate_types
is uninitialized. So we pass in find_features
to let create_target_machine
assume that we aren't looking at a pie binary.
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.
Ah, OK. Could you add a comment explaining that?
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.
Done.
src/librustc/traits/select.rs
Outdated
// This may overwrite the cache with the same value | ||
self.tcx().evaluation_cache | ||
.hashmap.borrow_mut() | ||
.insert(trait_ref, WithDepNode::new(dep_node, result)); |
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.
Should this use insert_same()
?
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.
The type inserted doesn't implement Eq
, so it cannot use insert_same
.
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.
For this one, implementing Eq
should be easy. Let's do 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.
Done.
src/librustc/traits/select.rs
Outdated
// This may overwrite the cache with the same value | ||
tcx.selection_cache | ||
.hashmap.borrow_mut() | ||
.insert(trait_ref, WithDepNode::new(dep_node, candidate)); |
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.
This might also be a candidate for insert_same()
.
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 thing, the type inserted doesn't implement Eq
, so it cannot use insert_same
.
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.
Yeah, this one looks more complicated. Pity.
src/librustc_data_structures/sync.rs
Outdated
} | ||
|
||
#[inline] | ||
pub fn try_set(&self, value: T) -> Option<T> { |
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 document this method, especially what the return value is.
src/librustc_data_structures/sync.rs
Outdated
} | ||
|
||
#[inline(always)] | ||
pub fn try_get(&self) -> Option<&T> { |
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.
This method could use documentation too.
src/librustc_data_structures/sync.rs
Outdated
} | ||
|
||
#[inline] | ||
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) { |
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.
init_locking
and init_nonlocking
should be documented to. I needed a while to see what these are about but the difference can be explained rather quickly.
Looks great, thanks @Zoxc! |
@bors r+ |
📌 Commit 006f9b2 has been approved by |
Even more thread-safety changes r? @michaelwoerister
☀️ Test successful - status-appveyor, status-travis |
Make SelectionCache and EvaluationCache thread-safe Split out from #49558 r? @nikomatsakis
The included measurements have varied over the years. At one point there were quite a few more, but rust-lang#49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable. I think it has been well and truly subsumed by self-profiling, which collects way more data.
The included measurements have varied over the years. At one point there were quite a few more, but rust-lang#49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable. I think it has been well and truly subsumed by self-profiling, which collects way more data.
…wiser Remove `-Zperf-stats`. The included measurements have varied over the years. At one point there were quite a few more, but rust-lang#49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable. I think it has been well and truly subsumed by self-profiling, which collects way more data. r? `@wesleywiser`
r? @michaelwoerister