Skip to content

Commit 51783e9

Browse files
committed
Misc
1 parent 836b3bb commit 51783e9

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl Session {
838838

839839
#[inline(always)]
840840
pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) {
841-
if unsafe { std::intrinsics::unlikely(self.opts.debugging_opts.self_profile) } {
841+
if unlikely!(self.opts.debugging_opts.self_profile) {
842842
self.profiler_active(f)
843843
}
844844
}

src/librustc/ty/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,13 +1914,15 @@ pub mod tls {
19141914
/// to `value` during the call to `f`. It is restored to its previous value after.
19151915
/// This is used to set the pointer to the new ImplicitCtxt.
19161916
#[cfg(parallel_queries)]
1917+
#[inline]
19171918
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
19181919
rayon_core::tlv::with(value, f)
19191920
}
19201921

19211922
/// Gets Rayon's thread local variable which is preserved for Rayon jobs.
19221923
/// This is used to get the pointer to the current ImplicitCtxt.
19231924
#[cfg(parallel_queries)]
1925+
#[inline]
19241926
fn get_tlv() -> usize {
19251927
rayon_core::tlv::get()
19261928
}
@@ -1943,6 +1945,7 @@ pub mod tls {
19431945
/// It is restored to its previous value after.
19441946
/// This is used to set the pointer to the new ImplicitCtxt.
19451947
#[cfg(not(parallel_queries))]
1948+
#[inline]
19461949
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
19471950
let old = get_tlv();
19481951
let _reset = OnDrop(move || set_raw_tlv(old));

src/librustc/ty/query/plumbing.rs

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_data_structures::sync::{Lrc, Lock};
3030
use rustc_data_structures::by_move::{Move, MoveSlot};
3131
use std::mem;
3232
use std::ptr;
33-
use std::intrinsics::unlikely;
3433
use std::collections::hash_map::Entry;
3534
use syntax_pos::Span;
3635
use syntax::source_map::DUMMY_SP;
@@ -220,7 +219,8 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
220219
}
221220

222221
impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
223-
#[inline]
222+
#[inline(never)]
223+
#[cold]
224224
fn drop(&mut self) {
225225
// Poison the query so jobs waiting on it panic
226226
self.cache.borrow_mut().active.insert(self.key.clone(), QueryResult::Poisoned);
@@ -486,37 +486,48 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
486486

487487
// If -Zincremental-verify-ich is specified, re-hash results from
488488
// the cache and make sure that they have the expected fingerprint.
489-
if unsafe { unlikely(self.sess.opts.debugging_opts.incremental_verify_ich) } {
490-
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
491-
use ich::Fingerprint;
489+
if unlikely!(self.sess.opts.debugging_opts.incremental_verify_ich) {
490+
self.incremental_verify_ich::<Q>(&result, dep_node, dep_node_index);
491+
}
492492

493-
assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
494-
self.dep_graph.prev_fingerprint_of(dep_node),
495-
"Fingerprint for green query instance not loaded \
496-
from cache: {:?}", dep_node);
493+
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
494+
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
495+
}
497496

498-
debug!("BEGIN verify_ich({:?})", dep_node);
499-
let mut hcx = self.create_stable_hashing_context();
500-
let mut hasher = StableHasher::new();
497+
job.complete(&result, dep_node_index);
501498

502-
result.hash_stable(&mut hcx, &mut hasher);
499+
Ok(result)
500+
}
503501

504-
let new_hash: Fingerprint = hasher.finish();
505-
debug!("END verify_ich({:?})", dep_node);
502+
#[inline(never)]
503+
#[cold]
504+
fn incremental_verify_ich<Q: QueryDescription<'gcx>>(
505+
self,
506+
result: &Q::Value,
507+
dep_node: &DepNode,
508+
dep_node_index: DepNodeIndex,
509+
) {
510+
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
511+
use ich::Fingerprint;
506512

507-
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
513+
assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
514+
self.dep_graph.prev_fingerprint_of(dep_node),
515+
"Fingerprint for green query instance not loaded \
516+
from cache: {:?}", dep_node);
508517

509-
assert!(new_hash == old_hash, "Found unstable fingerprints \
510-
for {:?}", dep_node);
511-
}
518+
debug!("BEGIN verify_ich({:?})", dep_node);
519+
let mut hcx = self.create_stable_hashing_context();
520+
let mut hasher = StableHasher::new();
512521

513-
if unsafe { unlikely(self.sess.opts.debugging_opts.query_dep_graph) } {
514-
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
515-
}
522+
result.hash_stable(&mut hcx, &mut hasher);
516523

517-
job.complete(&result, dep_node_index);
524+
let new_hash: Fingerprint = hasher.finish();
525+
debug!("END verify_ich({:?})", dep_node);
518526

519-
Ok(result)
527+
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
528+
529+
assert!(new_hash == old_hash, "Found unstable fingerprints \
530+
for {:?}", dep_node);
520531
}
521532

522533
// Inlined so LLVM can tell what kind of DepNode we are using
@@ -544,7 +555,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
544555
p.record_query(Q::CATEGORY);
545556
});
546557

547-
let res = if dep_node.kind.is_eval_always() {
558+
let (result, dep_node_index) = if dep_node.kind.is_eval_always() {
548559
self.dep_graph.with_eval_always_task(self, dep_node, |task| {
549560
job.compute(self, task, key)
550561
})
@@ -557,9 +568,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
557568
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
558569
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
559570

560-
let (result, dep_node_index) = res;
561-
562-
if unsafe { unlikely(self.sess.opts.debugging_opts.query_dep_graph) } {
571+
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
563572
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
564573
}
565574

src/librustc_data_structures/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ pub struct OnDrop<F: Fn()>(pub F);
118118
impl<F: Fn()> OnDrop<F> {
119119
/// Forgets the function which prevents it from running.
120120
/// Ensure that the function owns no memory, otherwise it will be leaked.
121+
#[inline]
121122
pub fn disable(self) {
122123
std::mem::forget(self);
123124
}
124125
}
125126

126127
impl<F: Fn()> Drop for OnDrop<F> {
128+
#[inline]
127129
fn drop(&mut self) {
128130
(self.0)();
129131
}

0 commit comments

Comments
 (0)