Skip to content

Commit 2426f7c

Browse files
committed
Uninline some debugging code and use unlikely! macro
1 parent 6d34ec1 commit 2426f7c

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

src/librustc/ty/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,13 +1926,15 @@ pub mod tls {
19261926
/// to `value` during the call to `f`. It is restored to its previous value after.
19271927
/// This is used to set the pointer to the new ImplicitCtxt.
19281928
#[cfg(parallel_queries)]
1929+
#[inline]
19291930
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
19301931
rayon_core::tlv::with(value, f)
19311932
}
19321933

19331934
/// Gets Rayon's thread local variable which is preserved for Rayon jobs.
19341935
/// This is used to get the pointer to the current ImplicitCtxt.
19351936
#[cfg(parallel_queries)]
1937+
#[inline]
19361938
fn get_tlv() -> usize {
19371939
rayon_core::tlv::get()
19381940
}
@@ -1945,6 +1947,7 @@ pub mod tls {
19451947
/// It is restored to its previous value after.
19461948
/// This is used to set the pointer to the new ImplicitCtxt.
19471949
#[cfg(not(parallel_queries))]
1950+
#[inline]
19481951
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
19491952
let old = get_tlv();
19501953
let _reset = OnDrop(move || TLV.with(|tlv| tlv.set(old)));

src/librustc/ty/query/plumbing.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -499,37 +499,48 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
499499

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

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

511-
debug!("BEGIN verify_ich({:?})", dep_node);
512-
let mut hcx = self.create_stable_hashing_context();
513-
let mut hasher = StableHasher::new();
510+
job.complete(&result, dep_node_index);
514511

515-
result.hash_stable(&mut hcx, &mut hasher);
512+
Ok(result)
513+
}
516514

517-
let new_hash: Fingerprint = hasher.finish();
518-
debug!("END verify_ich({:?})", dep_node);
515+
#[inline(never)]
516+
#[cold]
517+
fn incremental_verify_ich<Q: QueryDescription<'gcx>>(
518+
self,
519+
result: &Q::Value,
520+
dep_node: &DepNode,
521+
dep_node_index: DepNodeIndex,
522+
) {
523+
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
524+
use ich::Fingerprint;
519525

520-
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
526+
assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
527+
self.dep_graph.prev_fingerprint_of(dep_node),
528+
"Fingerprint for green query instance not loaded \
529+
from cache: {:?}", dep_node);
521530

522-
assert!(new_hash == old_hash, "Found unstable fingerprints \
523-
for {:?}", dep_node);
524-
}
531+
debug!("BEGIN verify_ich({:?})", dep_node);
532+
let mut hcx = self.create_stable_hashing_context();
533+
let mut hasher = StableHasher::new();
525534

526-
if self.sess.opts.debugging_opts.query_dep_graph {
527-
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
528-
}
535+
result.hash_stable(&mut hcx, &mut hasher);
529536

530-
job.complete(&result, dep_node_index);
537+
let new_hash: Fingerprint = hasher.finish();
538+
debug!("END verify_ich({:?})", dep_node);
531539

532-
Ok(result)
540+
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
541+
542+
assert!(new_hash == old_hash, "Found unstable fingerprints \
543+
for {:?}", dep_node);
533544
}
534545

535546
fn force_query_with_job<Q: QueryDescription<'gcx>>(
@@ -574,7 +585,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
574585

575586
let ((result, dep_node_index), diagnostics) = res;
576587

577-
if self.sess.opts.debugging_opts.query_dep_graph {
588+
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
578589
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
579590
}
580591

src/librustc_data_structures/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ pub struct OnDrop<F: Fn()>(pub F);
113113
impl<F: Fn()> OnDrop<F> {
114114
/// Forgets the function which prevents it from running.
115115
/// Ensure that the function owns no memory, otherwise it will be leaked.
116+
#[inline]
116117
pub fn disable(self) {
117118
std::mem::forget(self);
118119
}
119120
}
120121

121122
impl<F: Fn()> Drop for OnDrop<F> {
123+
#[inline]
122124
fn drop(&mut self) {
123125
(self.0)();
124126
}

0 commit comments

Comments
 (0)