Skip to content

Commit ae379bd

Browse files
committedMar 11, 2018
Auto merge of #48691 - Zoxc:profq-chan, r=michaelwoerister
Move PROFQ_CHAN to a Session field r? @michaelwoerister
·
1.88.01.26.0
2 parents 0bae326 + 184fd32 commit ae379bd

File tree

18 files changed

+175
-170
lines changed

18 files changed

+175
-170
lines changed
 

‎src/librustc/dep_graph/graph.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// except according to those terms.
1010

1111
use errors::DiagnosticBuilder;
12-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
13-
StableHashingContextProvider};
12+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1413
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1514
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1615
use rustc_data_structures::sync::Lrc;
@@ -20,7 +19,7 @@ use std::hash::Hash;
2019
use ty::TyCtxt;
2120
use util::common::{ProfileQueriesMsg, profq_msg};
2221

23-
use ich::Fingerprint;
22+
use ich::{StableHashingContext, StableHashingContextProvider, Fingerprint};
2423

2524
use super::debug::EdgeFilter;
2625
use super::dep_node::{DepNode, DepKind, WorkProductId};
@@ -189,47 +188,49 @@ impl DepGraph {
189188
/// `arg` parameter.
190189
///
191190
/// [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/incremental-compilation.html
192-
pub fn with_task<C, A, R, HCX>(&self,
191+
pub fn with_task<'gcx, C, A, R>(&self,
193192
key: DepNode,
194193
cx: C,
195194
arg: A,
196195
task: fn(C, A) -> R)
197196
-> (R, DepNodeIndex)
198-
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
199-
R: HashStable<HCX>,
197+
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
198+
R: HashStable<StableHashingContext<'gcx>>,
200199
{
201200
self.with_task_impl(key, cx, arg, task,
202201
|data, key| data.borrow_mut().push_task(key),
203202
|data, key| data.borrow_mut().pop_task(key))
204203
}
205204

206-
fn with_task_impl<C, A, R, HCX>(&self,
205+
fn with_task_impl<'gcx, C, A, R>(&self,
207206
key: DepNode,
208207
cx: C,
209208
arg: A,
210209
task: fn(C, A) -> R,
211210
push: fn(&RefCell<CurrentDepGraph>, DepNode),
212211
pop: fn(&RefCell<CurrentDepGraph>, DepNode) -> DepNodeIndex)
213212
-> (R, DepNodeIndex)
214-
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
215-
R: HashStable<HCX>,
213+
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
214+
R: HashStable<StableHashingContext<'gcx>>,
216215
{
217216
if let Some(ref data) = self.data {
218217
push(&data.current, key);
219-
if cfg!(debug_assertions) {
220-
profq_msg(ProfileQueriesMsg::TaskBegin(key.clone()))
221-
};
222218

223219
// In incremental mode, hash the result of the task. We don't
224220
// do anything with the hash yet, but we are computing it
225221
// anyway so that
226222
// - we make sure that the infrastructure works and
227223
// - we can get an idea of the runtime cost.
228-
let mut hcx = cx.create_stable_hashing_context();
224+
let mut hcx = cx.get_stable_hashing_context();
225+
226+
if cfg!(debug_assertions) {
227+
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
228+
};
229229

230230
let result = task(cx, arg);
231+
231232
if cfg!(debug_assertions) {
232-
profq_msg(ProfileQueriesMsg::TaskEnd)
233+
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd)
233234
};
234235

235236
let dep_node_index = pop(&data.current, key);
@@ -274,7 +275,7 @@ impl DepGraph {
274275
(result, dep_node_index)
275276
} else {
276277
if key.kind.fingerprint_needed_for_crate_hash() {
277-
let mut hcx = cx.create_stable_hashing_context();
278+
let mut hcx = cx.get_stable_hashing_context();
278279
let result = task(cx, arg);
279280
let mut stable_hasher = StableHasher::new();
280281
result.hash_stable(&mut hcx, &mut stable_hasher);
@@ -314,14 +315,14 @@ impl DepGraph {
314315

315316
/// Execute something within an "eval-always" task which is a task
316317
// that runs whenever anything changes.
317-
pub fn with_eval_always_task<C, A, R, HCX>(&self,
318+
pub fn with_eval_always_task<'gcx, C, A, R>(&self,
318319
key: DepNode,
319320
cx: C,
320321
arg: A,
321322
task: fn(C, A) -> R)
322323
-> (R, DepNodeIndex)
323-
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
324-
R: HashStable<HCX>,
324+
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
325+
R: HashStable<StableHashingContext<'gcx>>,
325326
{
326327
self.with_task_impl(key, cx, arg, task,
327328
|data, key| data.borrow_mut().push_eval_always_task(key),

‎src/librustc/ich/hcx.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use syntax::symbol::Symbol;
3030
use syntax_pos::{Span, DUMMY_SP};
3131
use syntax_pos::hygiene;
3232

33-
use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvider,
33+
use rustc_data_structures::stable_hasher::{HashStable,
3434
StableHasher, StableHasherResult,
3535
ToStableHashKey};
3636
use rustc_data_structures::accumulate_vec::AccumulateVec;
@@ -192,17 +192,33 @@ impl<'a> StableHashingContext<'a> {
192192
}
193193
}
194194

195-
impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
196-
type ContextType = StableHashingContext<'a>;
197-
fn create_stable_hashing_context(&self) -> Self::ContextType {
198-
(*self).create_stable_hashing_context()
195+
/// Something that can provide a stable hashing context.
196+
pub trait StableHashingContextProvider<'a> {
197+
fn get_stable_hashing_context(&self) -> StableHashingContext<'a>;
198+
}
199+
200+
impl<'a, 'b, T: StableHashingContextProvider<'a>> StableHashingContextProvider<'a>
201+
for &'b T {
202+
fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
203+
(**self).get_stable_hashing_context()
199204
}
200205
}
201206

207+
impl<'a, 'b, T: StableHashingContextProvider<'a>> StableHashingContextProvider<'a>
208+
for &'b mut T {
209+
fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
210+
(**self).get_stable_hashing_context()
211+
}
212+
}
213+
214+
impl<'a, 'gcx, 'lcx> StableHashingContextProvider<'a> for TyCtxt<'a, 'gcx, 'lcx> {
215+
fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
216+
(*self).create_stable_hashing_context()
217+
}
218+
}
202219

203-
impl<'a> StableHashingContextProvider for StableHashingContext<'a> {
204-
type ContextType = StableHashingContext<'a>;
205-
fn create_stable_hashing_context(&self) -> Self::ContextType {
220+
impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
221+
fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
206222
self.clone()
207223
}
208224
}

‎src/librustc/ich/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
pub use self::fingerprint::Fingerprint;
1414
pub use self::caching_codemap_view::CachingCodemapView;
15-
pub use self::hcx::{StableHashingContext, NodeIdHashingMode,
15+
pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
1616
hash_stable_trait_impls, compute_ignored_attr_names};
1717
mod fingerprint;
1818
mod caching_codemap_view;

‎src/librustc/session/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ use session::config::{DebugInfoLevel, OutputType};
2424
use ty::tls;
2525
use util::nodemap::{FxHashMap, FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
27+
use util::common::ProfileQueriesMsg;
2728

28-
use rustc_data_structures::sync::Lrc;
29+
use rustc_data_structures::sync::{Lrc, Lock};
2930

3031
use syntax::ast::NodeId;
3132
use errors::{self, DiagnosticBuilder, DiagnosticId};
@@ -53,6 +54,7 @@ use std::io::Write;
5354
use std::path::{Path, PathBuf};
5455
use std::sync::{Once, ONCE_INIT};
5556
use std::time::Duration;
57+
use std::sync::mpsc;
5658

5759
mod code_stats;
5860
pub mod config;
@@ -126,6 +128,9 @@ pub struct Session {
126128
/// A cache of attributes ignored by StableHashingContext
127129
pub ignored_attr_names: FxHashSet<Symbol>,
128130

131+
/// Used by -Z profile-queries in util::common
132+
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,
133+
129134
/// Some measurements that are being gathered during compilation.
130135
pub perf_stats: PerfStats,
131136

@@ -1131,6 +1136,7 @@ pub fn build_session_(
11311136
imported_macro_spans: RefCell::new(HashMap::new()),
11321137
incr_comp_session: RefCell::new(IncrCompSession::NotInitialized),
11331138
ignored_attr_names: ich::compute_ignored_attr_names(),
1139+
profile_channel: Lock::new(None),
11341140
perf_stats: PerfStats {
11351141
svh_time: Cell::new(Duration::from_secs(0)),
11361142
incr_comp_hashes_time: Cell::new(Duration::from_secs(0)),

‎src/librustc/ty/maps/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
164164
macro_rules! profq_msg {
165165
($tcx:expr, $msg:expr) => {
166166
if cfg!(debug_assertions) {
167-
if $tcx.sess.profile_queries() {
168-
profq_msg($msg)
167+
if $tcx.sess.profile_queries() {
168+
profq_msg($tcx.sess, $msg)
169169
}
170170
}
171171
}

‎src/librustc/util/common.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ty::maps::{QueryMsg};
2626
use dep_graph::{DepNode};
2727
use proc_macro;
2828
use lazy_static;
29+
use session::Session;
2930

3031
// The name of the associated type for `Fn` return types
3132
pub const FN_OUTPUT_NAME: &'static str = "Output";
@@ -55,9 +56,6 @@ pub fn install_panic_hook() {
5556
lazy_static::initialize(&DEFAULT_HOOK);
5657
}
5758

58-
/// Initialized for -Z profile-queries
59-
thread_local!(static PROFQ_CHAN: RefCell<Option<Sender<ProfileQueriesMsg>>> = RefCell::new(None));
60-
6159
/// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
6260
#[derive(Clone,Debug)]
6361
pub struct ProfQDumpParams {
@@ -97,29 +95,23 @@ pub enum ProfileQueriesMsg {
9795
}
9896

9997
/// If enabled, send a message to the profile-queries thread
100-
pub fn profq_msg(msg: ProfileQueriesMsg) {
101-
PROFQ_CHAN.with(|sender|{
102-
if let Some(s) = sender.borrow().as_ref() {
103-
s.send(msg).unwrap()
104-
} else {
105-
// Do nothing.
106-
//
107-
// FIXME(matthewhammer): Multi-threaded translation phase triggers the panic below.
108-
// From backtrace: rustc_trans::back::write::spawn_work::{{closure}}.
109-
//
110-
// panic!("no channel on which to send profq_msg: {:?}", msg)
111-
}
112-
})
98+
pub fn profq_msg(sess: &Session, msg: ProfileQueriesMsg) {
99+
if let Some(s) = sess.profile_channel.borrow().as_ref() {
100+
s.send(msg).unwrap()
101+
} else {
102+
// Do nothing
103+
}
113104
}
114105

115106
/// Set channel for profile queries channel
116-
pub fn profq_set_chan(s: Sender<ProfileQueriesMsg>) -> bool {
117-
PROFQ_CHAN.with(|chan|{
118-
if chan.borrow().is_none() {
119-
*chan.borrow_mut() = Some(s);
120-
true
121-
} else { false }
122-
})
107+
pub fn profq_set_chan(sess: &Session, s: Sender<ProfileQueriesMsg>) -> bool {
108+
let mut channel = sess.profile_channel.borrow_mut();
109+
if channel.is_none() {
110+
*channel = Some(s);
111+
true
112+
} else {
113+
false
114+
}
123115
}
124116

125117
/// Read the current depth of `time()` calls. This is used to
@@ -135,7 +127,13 @@ pub fn set_time_depth(depth: usize) {
135127
TIME_DEPTH.with(|slot| slot.set(depth));
136128
}
137129

138-
pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
130+
pub fn time<T, F>(sess: &Session, what: &str, f: F) -> T where
131+
F: FnOnce() -> T,
132+
{
133+
time_ext(sess.time_passes(), Some(sess), what, f)
134+
}
135+
136+
pub fn time_ext<T, F>(do_it: bool, sess: Option<&Session>, what: &str, f: F) -> T where
139137
F: FnOnce() -> T,
140138
{
141139
if !do_it { return f(); }
@@ -146,15 +144,19 @@ pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
146144
r
147145
});
148146

149-
if cfg!(debug_assertions) {
150-
profq_msg(ProfileQueriesMsg::TimeBegin(what.to_string()))
151-
};
147+
if let Some(sess) = sess {
148+
if cfg!(debug_assertions) {
149+
profq_msg(sess, ProfileQueriesMsg::TimeBegin(what.to_string()))
150+
}
151+
}
152152
let start = Instant::now();
153153
let rv = f();
154154
let dur = start.elapsed();
155-
if cfg!(debug_assertions) {
156-
profq_msg(ProfileQueriesMsg::TimeEnd)
157-
};
155+
if let Some(sess) = sess {
156+
if cfg!(debug_assertions) {
157+
profq_msg(sess, ProfileQueriesMsg::TimeEnd)
158+
}
159+
}
158160

159161
print_time_passes_entry_internal(what, dur);
160162

‎src/librustc_data_structures/stable_hasher.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,6 @@ impl<W> Hasher for StableHasher<W> {
165165
}
166166
}
167167

168-
169-
/// Something that can provide a stable hashing context.
170-
pub trait StableHashingContextProvider {
171-
type ContextType;
172-
fn create_stable_hashing_context(&self) -> Self::ContextType;
173-
}
174-
175-
impl<'a, T: StableHashingContextProvider> StableHashingContextProvider for &'a T {
176-
type ContextType = T::ContextType;
177-
178-
fn create_stable_hashing_context(&self) -> Self::ContextType {
179-
(**self).create_stable_hashing_context()
180-
}
181-
}
182-
183-
impl<'a, T: StableHashingContextProvider> StableHashingContextProvider for &'a mut T {
184-
type ContextType = T::ContextType;
185-
186-
fn create_stable_hashing_context(&self) -> Self::ContextType {
187-
(**self).create_stable_hashing_context()
188-
}
189-
}
190-
191168
/// Something that implements `HashStable<CTX>` can be hashed in a way that is
192169
/// stable across multiple compilation sessions.
193170
pub trait HashStable<CTX> {

‎src/librustc_driver/driver.rs

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn compile_input(trans: Box<TransCrate>,
8989
}
9090

9191
if sess.profile_queries() {
92-
profile::begin();
92+
profile::begin(sess);
9393
}
9494

9595
// We need nested scopes here, because the intermediate results can keep
@@ -181,7 +181,7 @@ pub fn compile_input(trans: Box<TransCrate>,
181181
let arenas = AllArenas::new();
182182

183183
// Construct the HIR map
184-
let hir_map = time(sess.time_passes(),
184+
let hir_map = time(sess,
185185
"indexing hir",
186186
|| hir_map::map_crate(sess, cstore, &mut hir_forest, &defs));
187187

@@ -517,10 +517,10 @@ pub fn phase_1_parse_input<'a>(control: &CompileController,
517517
sess.diagnostic().set_continue_after_error(control.continue_parse_after_error);
518518

519519
if sess.profile_queries() {
520-
profile::begin();
520+
profile::begin(sess);
521521
}
522522

523-
let krate = time(sess.time_passes(), "parsing", || {
523+
let krate = time(sess, "parsing", || {
524524
match *input {
525525
Input::File(ref file) => {
526526
parse::parse_crate_from_file(file, &sess.parse_sess)
@@ -645,8 +645,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
645645
-> Result<InnerExpansionResult<'a>, CompileIncomplete>
646646
where F: FnOnce(&ast::Crate) -> CompileResult,
647647
{
648-
let time_passes = sess.time_passes();
649-
650648
let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess,
651649
sess.opts.test,
652650
sess.opts.debugging_opts.epoch);
@@ -664,7 +662,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
664662
);
665663

666664
if sess.opts.incremental.is_some() {
667-
time(time_passes, "garbage collect incremental cache directory", || {
665+
time(sess, "garbage collect incremental cache directory", || {
668666
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
669667
warn!("Error while trying to garbage collect incremental \
670668
compilation cache directory: {}", e);
@@ -674,22 +672,22 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
674672

675673
// If necessary, compute the dependency graph (in the background).
676674
let future_dep_graph = if sess.opts.build_dep_graph() {
677-
Some(rustc_incremental::load_dep_graph(sess, time_passes))
675+
Some(rustc_incremental::load_dep_graph(sess))
678676
} else {
679677
None
680678
};
681679

682-
time(time_passes, "recursion limit", || {
680+
time(sess, "recursion limit", || {
683681
middle::recursion_limit::update_limits(sess, &krate);
684682
});
685683

686-
krate = time(time_passes, "crate injection", || {
684+
krate = time(sess, "crate injection", || {
687685
let alt_std_name = sess.opts.alt_std_name.clone();
688686
syntax::std_inject::maybe_inject_crates_ref(krate, alt_std_name)
689687
});
690688

691689
let mut addl_plugins = Some(addl_plugins);
692-
let registrars = time(time_passes, "plugin loading", || {
690+
let registrars = time(sess, "plugin loading", || {
693691
plugin::load::load_plugins(sess,
694692
&cstore,
695693
&krate,
@@ -699,7 +697,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
699697

700698
let mut registry = registry.unwrap_or(Registry::new(sess, krate.span));
701699

702-
time(time_passes, "plugin registration", || {
700+
time(sess, "plugin registration", || {
703701
if sess.features_untracked().rustc_diagnostic_macros {
704702
registry.register_macro("__diagnostic_used",
705703
diagnostics::plugin::expand_diagnostic_used);
@@ -752,7 +750,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
752750
resolver.whitelisted_legacy_custom_derives = whitelisted_legacy_custom_derives;
753751
syntax_ext::register_builtins(&mut resolver, syntax_exts, sess.features_untracked().quote);
754752

755-
krate = time(time_passes, "expansion", || {
753+
krate = time(sess, "expansion", || {
756754
// Windows dlls do not have rpaths, so they don't know how to find their
757755
// dependencies. It's up to us to tell the system where to find all the
758756
// dependent dlls. Note that this uses cfg!(windows) as opposed to
@@ -814,7 +812,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
814812
krate
815813
});
816814

817-
krate = time(time_passes, "maybe building test harness", || {
815+
krate = time(sess, "maybe building test harness", || {
818816
syntax::test::modify_for_testing(&sess.parse_sess,
819817
&mut resolver,
820818
sess.opts.test,
@@ -833,7 +831,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
833831
// bunch of checks in the `modify` function below. For now just skip this
834832
// step entirely if we're rustdoc as it's not too useful anyway.
835833
if !sess.opts.actually_rustdoc {
836-
krate = time(time_passes, "maybe creating a macro crate", || {
834+
krate = time(sess, "maybe creating a macro crate", || {
837835
let crate_types = sess.crate_types.borrow();
838836
let num_crate_types = crate_types.len();
839837
let is_proc_macro_crate = crate_types.contains(&config::CrateTypeProcMacro);
@@ -848,7 +846,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
848846
});
849847
}
850848

851-
krate = time(time_passes, "creating allocators", || {
849+
krate = time(sess, "creating allocators", || {
852850
allocator::expand::modify(&sess.parse_sess,
853851
&mut resolver,
854852
krate,
@@ -869,11 +867,11 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
869867
println!("{}", json::as_json(&krate));
870868
}
871869

872-
time(time_passes,
870+
time(sess,
873871
"AST validation",
874872
|| ast_validation::check_crate(sess, &krate));
875873

876-
time(time_passes, "name resolution", || -> CompileResult {
874+
time(sess, "name resolution", || -> CompileResult {
877875
resolver.resolve_crate(&krate);
878876
Ok(())
879877
})?;
@@ -883,7 +881,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
883881
}
884882

885883
// Needs to go *after* expansion to be able to check the results of macro expansion.
886-
time(time_passes, "complete gated feature checking", || {
884+
time(sess, "complete gated feature checking", || {
887885
sess.track_errors(|| {
888886
syntax::feature_gate::check_crate(&krate,
889887
&sess.parse_sess,
@@ -898,15 +896,15 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
898896
let dep_graph = match future_dep_graph {
899897
None => DepGraph::new_disabled(),
900898
Some(future) => {
901-
let prev_graph = time(time_passes, "blocked while dep-graph loading finishes", || {
899+
let prev_graph = time(sess, "blocked while dep-graph loading finishes", || {
902900
future.open()
903901
.expect("Could not join with background dep_graph thread")
904902
.open(sess)
905903
});
906904
DepGraph::new(prev_graph)
907905
}
908906
};
909-
let hir_forest = time(time_passes, "lowering ast -> hir", || {
907+
let hir_forest = time(sess, "lowering ast -> hir", || {
910908
let hir_crate = lower_crate(sess, cstore, &dep_graph, &krate, &mut resolver);
911909

912910
if sess.opts.debugging_opts.hir_stats {
@@ -916,7 +914,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
916914
hir_map::Forest::new(hir_crate, &dep_graph)
917915
});
918916

919-
time(time_passes,
917+
time(sess,
920918
"early lint checks",
921919
|| lint::check_ast_crate(sess, &krate));
922920

@@ -973,22 +971,20 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
973971
mpsc::Receiver<Box<Any + Send>>,
974972
CompileResult) -> R
975973
{
976-
let time_passes = sess.time_passes();
977-
978-
let query_result_on_disk_cache = time(time_passes,
974+
let query_result_on_disk_cache = time(sess,
979975
"load query result cache",
980976
|| rustc_incremental::load_query_result_cache(sess));
981977

982-
time(time_passes,
978+
time(sess,
983979
"looking for entry point",
984980
|| middle::entry::find_entry_point(sess, &hir_map));
985981

986-
sess.plugin_registrar_fn.set(time(time_passes, "looking for plugin registrar", || {
982+
sess.plugin_registrar_fn.set(time(sess, "looking for plugin registrar", || {
987983
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
988984
}));
989985
sess.derive_registrar_fn.set(derive_registrar::find(&hir_map));
990986

991-
time(time_passes,
987+
time(sess,
992988
"loop checking",
993989
|| loops::check_crate(sess, &hir_map));
994990

@@ -1020,11 +1016,11 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
10201016
// tcx available.
10211017
rustc_incremental::dep_graph_tcx_init(tcx);
10221018

1023-
time(sess.time_passes(), "attribute checking", || {
1019+
time(sess, "attribute checking", || {
10241020
hir::check_attr::check_crate(tcx)
10251021
});
10261022

1027-
time(time_passes,
1023+
time(sess,
10281024
"stability checking",
10291025
|| stability::check_unstable_api_usage(tcx));
10301026

@@ -1037,38 +1033,38 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
10371033
}
10381034
}
10391035

1040-
time(time_passes,
1036+
time(sess,
10411037
"rvalue promotion",
10421038
|| rvalue_promotion::check_crate(tcx));
10431039

10441040
analysis.access_levels =
1045-
time(time_passes, "privacy checking", || rustc_privacy::check_crate(tcx));
1041+
time(sess, "privacy checking", || rustc_privacy::check_crate(tcx));
10461042

1047-
time(time_passes,
1043+
time(sess,
10481044
"intrinsic checking",
10491045
|| middle::intrinsicck::check_crate(tcx));
10501046

1051-
time(time_passes,
1047+
time(sess,
10521048
"match checking",
10531049
|| mir::matchck_crate(tcx));
10541050

10551051
// this must run before MIR dump, because
10561052
// "not all control paths return a value" is reported here.
10571053
//
10581054
// maybe move the check to a MIR pass?
1059-
time(time_passes,
1055+
time(sess,
10601056
"liveness checking",
10611057
|| middle::liveness::check_crate(tcx));
10621058

1063-
time(time_passes,
1059+
time(sess,
10641060
"borrow checking",
10651061
|| borrowck::check_crate(tcx));
10661062

1067-
time(time_passes,
1063+
time(sess,
10681064
"MIR borrow checking",
10691065
|| for def_id in tcx.body_owners() { tcx.mir_borrowck(def_id); });
10701066

1071-
time(time_passes,
1067+
time(sess,
10721068
"MIR effect checking",
10731069
|| for def_id in tcx.body_owners() {
10741070
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
@@ -1083,13 +1079,13 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
10831079
return Ok(f(tcx, analysis, rx, sess.compile_status()));
10841080
}
10851081

1086-
time(time_passes, "death checking", || middle::dead::check_crate(tcx));
1082+
time(sess, "death checking", || middle::dead::check_crate(tcx));
10871083

1088-
time(time_passes, "unused lib feature checking", || {
1084+
time(sess, "unused lib feature checking", || {
10891085
stability::check_unused_or_stable_features(tcx)
10901086
});
10911087

1092-
time(time_passes, "lint checking", || lint::check_crate(tcx));
1088+
time(sess, "lint checking", || lint::check_crate(tcx));
10931089

10941090
return Ok(f(tcx, analysis, rx, tcx.sess.compile_status()));
10951091
})
@@ -1101,18 +1097,16 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(trans: &TransCrate,
11011097
tcx: TyCtxt<'a, 'tcx, 'tcx>,
11021098
rx: mpsc::Receiver<Box<Any + Send>>)
11031099
-> Box<Any> {
1104-
let time_passes = tcx.sess.time_passes();
1105-
1106-
time(time_passes,
1100+
time(tcx.sess,
11071101
"resolving dependency formats",
11081102
|| ::rustc::middle::dependency_format::calculate(tcx));
11091103

11101104
let translation =
1111-
time(time_passes, "translation", move || {
1105+
time(tcx.sess, "translation", move || {
11121106
trans.trans_crate(tcx, rx)
11131107
});
11141108
if tcx.sess.profile_queries() {
1115-
profile::dump("profile_queries".to_string())
1109+
profile::dump(&tcx.sess, "profile_queries".to_string())
11161110
}
11171111

11181112
translation

‎src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
914914
pub fn enable_save_analysis(control: &mut CompileController) {
915915
control.keep_ast = true;
916916
control.after_analysis.callback = box |state| {
917-
time(state.session.time_passes(), "save analysis", || {
917+
time(state.session, "save analysis", || {
918918
save::process_crate(state.tcx.unwrap(),
919919
state.expanded_crate.unwrap(),
920920
state.analysis.unwrap(),

‎src/librustc_driver/profile/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rustc::session::Session;
1112
use rustc::util::common::{ProfQDumpParams, ProfileQueriesMsg, profq_msg, profq_set_chan};
1213
use std::sync::mpsc::{Receiver};
1314
use std::io::{Write};
@@ -17,11 +18,11 @@ use std::time::{Duration, Instant};
1718
pub mod trace;
1819

1920
/// begin a profile thread, if not already running
20-
pub fn begin() {
21+
pub fn begin(sess: &Session) {
2122
use std::thread;
2223
use std::sync::mpsc::{channel};
2324
let (tx, rx) = channel();
24-
if profq_set_chan(tx) {
25+
if profq_set_chan(sess, tx) {
2526
thread::spawn(move||profile_queries_thread(rx));
2627
}
2728
}
@@ -30,7 +31,7 @@ pub fn begin() {
3031
/// wait for this dump to complete.
3132
///
3233
/// wraps the RPC (send/recv channel logic) of requesting a dump.
33-
pub fn dump(path:String) {
34+
pub fn dump(sess: &Session, path: String) {
3435
use std::sync::mpsc::{channel};
3536
let (tx, rx) = channel();
3637
let params = ProfQDumpParams{
@@ -39,7 +40,7 @@ pub fn dump(path:String) {
3940
// is written; false for now
4041
dump_profq_msg_log:true,
4142
};
42-
profq_msg(ProfileQueriesMsg::Dump(params));
43+
profq_msg(sess, ProfileQueriesMsg::Dump(params));
4344
let _ = rx.recv().unwrap();
4445
}
4546

‎src/librustc_incremental/persist/load.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::dep_graph::{PreviousDepGraph, SerializedDepGraph};
1414
use rustc::session::Session;
1515
use rustc::ty::TyCtxt;
1616
use rustc::ty::maps::OnDiskCache;
17-
use rustc::util::common::time;
17+
use rustc::util::common::time_ext;
1818
use rustc_serialize::Decodable as RustcDecodable;
1919
use rustc_serialize::opaque::Decoder;
2020
use std::path::Path;
@@ -147,12 +147,14 @@ impl<T> MaybeAsync<T> {
147147
}
148148

149149
/// Launch a thread and load the dependency graph in the background.
150-
pub fn load_dep_graph(sess: &Session, time_passes: bool) ->
150+
pub fn load_dep_graph(sess: &Session) ->
151151
MaybeAsync<LoadResult<PreviousDepGraph>>
152152
{
153153
// Since `sess` isn't `Sync`, we perform all accesses to `sess`
154154
// before we fire the background thread.
155155

156+
let time_passes = sess.time_passes();
157+
156158
if sess.opts.incremental.is_none() {
157159
// No incremental compilation.
158160
return MaybeAsync::Sync(LoadResult::Ok {
@@ -167,7 +169,7 @@ pub fn load_dep_graph(sess: &Session, time_passes: bool) ->
167169
let expected_hash = sess.opts.dep_tracking_hash();
168170

169171
MaybeAsync::Async(std::thread::spawn(move || {
170-
time(time_passes, "background load prev dep-graph", move || {
172+
time_ext(time_passes, None, "background load prev dep-graph", move || {
171173
match load_data(report_incremental_info, &path) {
172174
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
173175
LoadResult::Error { message } => LoadResult::Error { message },

‎src/librustc_incremental/persist/save.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
3333
return;
3434
}
3535

36-
time(sess.time_passes(), "persist query result cache", || {
36+
time(sess, "persist query result cache", || {
3737
save_in(sess,
3838
query_cache_path(sess),
3939
|e| encode_query_cache(tcx, e));
4040
});
4141

4242
if tcx.sess.opts.debugging_opts.incremental_queries {
43-
time(sess.time_passes(), "persist dep-graph", || {
43+
time(sess, "persist dep-graph", || {
4444
save_in(sess,
4545
dep_graph_path(sess),
4646
|e| encode_dep_graph(tcx, e));

‎src/librustc_trans/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ fn link_natively(sess: &Session,
690690
let mut i = 0;
691691
loop {
692692
i += 1;
693-
prog = time(sess.time_passes(), "running linker", || {
693+
prog = time(sess, "running linker", || {
694694
exec_linker(sess, &mut cmd, tmpdir)
695695
});
696696
let output = match prog {
@@ -1321,7 +1321,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
13211321
let name = cratepath.file_name().unwrap().to_str().unwrap();
13221322
let name = &name[3..name.len() - 5]; // chop off lib/.rlib
13231323

1324-
time(sess.time_passes(), &format!("altering {}.rlib", name), || {
1324+
time(sess, &format!("altering {}.rlib", name), || {
13251325
let cfg = archive_config(sess, &dst, Some(cratepath));
13261326
let mut archive = ArchiveBuilder::new(cfg);
13271327
archive.update_symbols();

‎src/librustc_trans/back/lto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use llvm;
1919
use rustc::hir::def_id::LOCAL_CRATE;
2020
use rustc::middle::exported_symbols::SymbolExportLevel;
2121
use rustc::session::config::{self, Lto};
22-
use rustc::util::common::time;
22+
use rustc::util::common::time_ext;
2323
use time_graph::Timeline;
2424
use {ModuleTranslation, ModuleLlvm, ModuleKind, ModuleSource};
2525

@@ -172,7 +172,7 @@ pub(crate) fn run(cgcx: &CodegenContext,
172172
info!("adding bytecode {}", name);
173173
let bc_encoded = data.data();
174174

175-
let (bc, id) = time(cgcx.time_passes, &format!("decode {}", name), || {
175+
let (bc, id) = time_ext(cgcx.time_passes, None, &format!("decode {}", name), || {
176176
match DecodedBytecode::new(bc_encoded) {
177177
Ok(b) => Ok((b.bytecode(), b.identifier().to_string())),
178178
Err(e) => Err(diag_handler.fatal(&e)),
@@ -253,7 +253,7 @@ fn fat_lto(cgcx: &CodegenContext,
253253
let mut linker = Linker::new(llmod);
254254
for (bc_decoded, name) in serialized_modules {
255255
info!("linking {:?}", name);
256-
time(cgcx.time_passes, &format!("ll link {:?}", name), || {
256+
time_ext(cgcx.time_passes, None, &format!("ll link {:?}", name), || {
257257
let data = bc_decoded.data();
258258
linker.add(&data).map_err(|()| {
259259
let msg = format!("failed to load bc of {:?}", name);
@@ -498,7 +498,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
498498
assert!(!pass.is_null());
499499
llvm::LLVMRustAddPass(pm, pass);
500500

501-
time(cgcx.time_passes, "LTO passes", ||
501+
time_ext(cgcx.time_passes, None, "LTO passes", ||
502502
llvm::LLVMRunPassManager(pm, llmod));
503503

504504
llvm::LLVMDisposePassManager(pm);

‎src/librustc_trans/back/write.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ use {CrateTranslation, ModuleSource, ModuleTranslation, CompiledModule, ModuleKi
3131
use CrateInfo;
3232
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
3333
use rustc::ty::TyCtxt;
34-
use rustc::util::common::{time, time_depth, set_time_depth, path2cstr, print_time_passes_entry};
34+
use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passes_entry};
35+
use rustc::util::common::path2cstr;
3536
use rustc::util::fs::{link_or_copy};
3637
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
3738
use errors::emitter::{Emitter};
@@ -563,11 +564,19 @@ unsafe fn optimize(cgcx: &CodegenContext,
563564
diag_handler.abort_if_errors();
564565

565566
// Finally, run the actual optimization passes
566-
time(config.time_passes, &format!("llvm function passes [{}]", module_name.unwrap()), ||
567-
llvm::LLVMRustRunFunctionPassManager(fpm, llmod));
567+
time_ext(config.time_passes,
568+
None,
569+
&format!("llvm function passes [{}]", module_name.unwrap()),
570+
|| {
571+
llvm::LLVMRustRunFunctionPassManager(fpm, llmod)
572+
});
568573
timeline.record("fpm");
569-
time(config.time_passes, &format!("llvm module passes [{}]", module_name.unwrap()), ||
570-
llvm::LLVMRunPassManager(mpm, llmod));
574+
time_ext(config.time_passes,
575+
None,
576+
&format!("llvm module passes [{}]", module_name.unwrap()),
577+
|| {
578+
llvm::LLVMRunPassManager(mpm, llmod)
579+
});
571580

572581
// Deallocate managers that we're now done with
573582
llvm::LLVMDisposePassManager(fpm);
@@ -682,7 +691,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
682691
}
683692
}
684693

685-
time(config.time_passes, &format!("codegen passes [{}]", module_name.unwrap()),
694+
time_ext(config.time_passes, None, &format!("codegen passes [{}]", module_name.unwrap()),
686695
|| -> Result<(), FatalError> {
687696
if config.emit_ir {
688697
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);

‎src/librustc_trans/base.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
712712
// Translate the metadata.
713713
let llmod_id = "metadata";
714714
let (metadata_llcx, metadata_llmod, metadata) =
715-
time(tcx.sess.time_passes(), "write metadata", || {
715+
time(tcx.sess, "write metadata", || {
716716
write_metadata(tcx, llmod_id, &link_meta)
717717
});
718718

@@ -790,7 +790,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
790790
llcx,
791791
tm: create_target_machine(tcx.sess),
792792
};
793-
time(tcx.sess.time_passes(), "write allocator module", || {
793+
time(tcx.sess, "write allocator module", || {
794794
allocator::trans(tcx, &modules, kind)
795795
});
796796

@@ -924,11 +924,11 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
924924
}
925925

926926
fn assert_and_save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
927-
time(tcx.sess.time_passes(),
927+
time(tcx.sess,
928928
"assert dep graph",
929929
|| rustc_incremental::assert_dep_graph(tcx));
930930

931-
time(tcx.sess.time_passes(),
931+
time(tcx.sess,
932932
"serialize dep graph",
933933
|| rustc_incremental::save_dep_graph(tcx));
934934
}
@@ -939,7 +939,6 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
939939
) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>)
940940
{
941941
assert_eq!(cnum, LOCAL_CRATE);
942-
let time_passes = tcx.sess.time_passes();
943942

944943
let collection_mode = match tcx.sess.opts.debugging_opts.print_trans_items {
945944
Some(ref s) => {
@@ -968,7 +967,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
968967
};
969968

970969
let (items, inlining_map) =
971-
time(time_passes, "translation item collection", || {
970+
time(tcx.sess, "translation item collection", || {
972971
collector::collect_crate_mono_items(tcx, collection_mode)
973972
});
974973

@@ -982,7 +981,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
982981
PartitioningStrategy::FixedUnitCount(tcx.sess.codegen_units())
983982
};
984983

985-
let codegen_units = time(time_passes, "codegen unit partitioning", || {
984+
let codegen_units = time(tcx.sess, "codegen unit partitioning", || {
986985
partitioning::partition(tcx,
987986
items.iter().cloned(),
988987
strategy,

‎src/librustc_trans/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl TransCrate for LlvmTransCrate {
238238
back::write::dump_incremental_data(&trans);
239239
}
240240

241-
time(sess.time_passes(),
241+
time(sess,
242242
"serialize work products",
243243
move || rustc_incremental::save_work_products(sess, &dep_graph));
244244

@@ -251,7 +251,7 @@ impl TransCrate for LlvmTransCrate {
251251

252252
// Run the linker on any artifacts that resulted from the LLVM run.
253253
// This should produce either a finished executable or library.
254-
time(sess.time_passes(), "linking", || {
254+
time(sess, "linking", || {
255255
back::link::link_binary(sess, &trans, outputs, &trans.crate_name.as_str());
256256
});
257257

‎src/librustc_typeck/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,41 +315,39 @@ pub fn provide(providers: &mut Providers) {
315315
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
316316
-> Result<(), CompileIncomplete>
317317
{
318-
let time_passes = tcx.sess.time_passes();
319-
320318
// this ensures that later parts of type checking can assume that items
321319
// have valid types and not error
322320
tcx.sess.track_errors(|| {
323-
time(time_passes, "type collecting", ||
321+
time(tcx.sess, "type collecting", ||
324322
collect::collect_item_types(tcx));
325323

326324
})?;
327325

328326
tcx.sess.track_errors(|| {
329-
time(time_passes, "outlives testing", ||
327+
time(tcx.sess, "outlives testing", ||
330328
outlives::test::test_inferred_outlives(tcx));
331329
})?;
332330

333331
tcx.sess.track_errors(|| {
334-
time(time_passes, "impl wf inference", ||
332+
time(tcx.sess, "impl wf inference", ||
335333
impl_wf_check::impl_wf_check(tcx));
336334
})?;
337335

338336
tcx.sess.track_errors(|| {
339-
time(time_passes, "coherence checking", ||
337+
time(tcx.sess, "coherence checking", ||
340338
coherence::check_coherence(tcx));
341339
})?;
342340

343341
tcx.sess.track_errors(|| {
344-
time(time_passes, "variance testing", ||
342+
time(tcx.sess, "variance testing", ||
345343
variance::test::test_variance(tcx));
346344
})?;
347345

348-
time(time_passes, "wf checking", || check::check_wf_new(tcx))?;
346+
time(tcx.sess, "wf checking", || check::check_wf_new(tcx))?;
349347

350-
time(time_passes, "item-types checking", || check::check_item_types(tcx))?;
348+
time(tcx.sess, "item-types checking", || check::check_item_types(tcx))?;
351349

352-
time(time_passes, "item-bodies checking", || check::check_item_bodies(tcx))?;
350+
time(tcx.sess, "item-bodies checking", || check::check_item_bodies(tcx))?;
353351

354352
check_unused::check_crate(tcx);
355353
check_for_entry_fn(tcx);

0 commit comments

Comments
 (0)
Please sign in to comment.