propagate TIME_DEPTH to the helper threads for -Z time-passes

This commit is contained in:
Niko Matsakis 2016-12-27 21:35:34 -05:00
parent d849b13267
commit ad747c5869
2 changed files with 21 additions and 4 deletions

View file

@ -27,13 +27,27 @@
#[derive(Clone, Copy, Debug)]
pub struct ErrorReported;
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
/// Read the current depth of `time()` calls. This is used to
/// encourage indentation across threads.
pub fn time_depth() -> usize {
TIME_DEPTH.with(|slot| slot.get())
}
/// Set the current depth of `time()` calls. The idea is to call
/// `set_time_depth()` with the result from `time_depth()` in the
/// parent thread.
pub fn set_time_depth(depth: usize) {
TIME_DEPTH.with(|slot| slot.set(depth));
}
pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
F: FnOnce() -> T,
{
thread_local!(static DEPTH: Cell<usize> = Cell::new(0));
if !do_it { return f(); }
let old = DEPTH.with(|slot| {
let old = TIME_DEPTH.with(|slot| {
let r = slot.get();
slot.set(r + 1);
r
@ -56,7 +70,7 @@ pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
mem_string,
what);
DEPTH.with(|slot| slot.set(old));
TIME_DEPTH.with(|slot| slot.set(old));
rv
}

View file

@ -19,7 +19,7 @@
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
use llvm::SMDiagnosticRef;
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
use util::common::time;
use util::common::{time, time_depth, set_time_depth};
use util::common::path2cstr;
use util::fs::link_or_copy;
use errors::{self, Handler, Level, DiagnosticBuilder};
@ -1033,7 +1033,10 @@ fn run_work_multithreaded(sess: &Session,
let incr_comp_session_dir = sess.incr_comp_session_dir_opt().map(|r| r.clone());
let depth = time_depth();
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
set_time_depth(depth);
let diag_handler = Handler::with_emitter(true, false, box diag_emitter);
// Must construct cgcx inside the proc because it has non-Send