Skip to content

Uninline some debugging code and use unlikely! macro #57035

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

Merged
merged 1 commit into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,13 +1926,15 @@ pub mod tls {
/// to `value` during the call to `f`. It is restored to its previous value after.
/// This is used to set the pointer to the new ImplicitCtxt.
#[cfg(parallel_queries)]
#[inline]
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
rayon_core::tlv::with(value, f)
}

/// Gets Rayon's thread local variable which is preserved for Rayon jobs.
/// This is used to get the pointer to the current ImplicitCtxt.
#[cfg(parallel_queries)]
#[inline]
fn get_tlv() -> usize {
rayon_core::tlv::get()
}
Expand All @@ -1945,6 +1947,7 @@ pub mod tls {
/// It is restored to its previous value after.
/// This is used to set the pointer to the new ImplicitCtxt.
#[cfg(not(parallel_queries))]
#[inline]
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
let old = get_tlv();
let _reset = OnDrop(move || TLV.with(|tlv| tlv.set(old)));
Expand Down
57 changes: 34 additions & 23 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,37 +499,48 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

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

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

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

result.hash_stable(&mut hcx, &mut hasher);
Ok(result)
}

let new_hash: Fingerprint = hasher.finish();
debug!("END verify_ich({:?})", dep_node);
#[inline(never)]
#[cold]
fn incremental_verify_ich<Q: QueryDescription<'gcx>>(
self,
result: &Q::Value,
dep_node: &DepNode,
dep_node_index: DepNodeIndex,
) {
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
use ich::Fingerprint;

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

assert!(new_hash == old_hash, "Found unstable fingerprints \
for {:?}", dep_node);
}
debug!("BEGIN verify_ich({:?})", dep_node);
let mut hcx = self.create_stable_hashing_context();
let mut hasher = StableHasher::new();

if self.sess.opts.debugging_opts.query_dep_graph {
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
}
result.hash_stable(&mut hcx, &mut hasher);

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

Ok(result)
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);

assert!(new_hash == old_hash, "Found unstable fingerprints \
for {:?}", dep_node);
}

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

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

if self.sess.opts.debugging_opts.query_dep_graph {
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ pub struct OnDrop<F: Fn()>(pub F);
impl<F: Fn()> OnDrop<F> {
/// Forgets the function which prevents it from running.
/// Ensure that the function owns no memory, otherwise it will be leaked.
#[inline]
pub fn disable(self) {
std::mem::forget(self);
}
}

impl<F: Fn()> Drop for OnDrop<F> {
#[inline]
fn drop(&mut self) {
(self.0)();
}
Expand Down