Skip to content

Commit f47ec2a

Browse files
committed
Auto merge of #58455 - Centril:rollup, r=Centril
Rollup of 7 pull requests Successful merges: - #58309 (Add more profiler events) - #58347 (Closure bounds fixes) - #58365 (Add an option to print the status of incremental tasks / dep nodes after running them) - #58371 (Check user type annotations for range patterns.) - #58378 (rustc: Implement incremental "fat" LTO) - #58407 (specify "upper camel case" in style lint) - #58449 (Notify @topecongiro when the state of rustfmt has changed) Failed merges: r? @ghost
2 parents c67d474 + 410b445 commit f47ec2a

File tree

35 files changed

+885
-427
lines changed

35 files changed

+885
-427
lines changed

src/librustc/dep_graph/graph.rs

+15
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,28 @@ impl DepGraph {
292292
task_deps.map(|lock| lock.into_inner()),
293293
);
294294

295+
let print_status = cfg!(debug_assertions) && hcx.sess().opts.debugging_opts.dep_tasks;
296+
295297
// Determine the color of the new DepNode.
296298
if let Some(prev_index) = data.previous.node_to_index_opt(&key) {
297299
let prev_fingerprint = data.previous.fingerprint_by_index(prev_index);
298300

299301
let color = if let Some(current_fingerprint) = current_fingerprint {
300302
if current_fingerprint == prev_fingerprint {
303+
if print_status {
304+
eprintln!("[task::green] {:?}", key);
305+
}
301306
DepNodeColor::Green(dep_node_index)
302307
} else {
308+
if print_status {
309+
eprintln!("[task::red] {:?}", key);
310+
}
303311
DepNodeColor::Red
304312
}
305313
} else {
314+
if print_status {
315+
eprintln!("[task::unknown] {:?}", key);
316+
}
306317
// Mark the node as Red if we can't hash the result
307318
DepNodeColor::Red
308319
};
@@ -312,6 +323,10 @@ impl DepGraph {
312323
insertion for {:?}", key);
313324

314325
data.colors.insert(prev_index, color);
326+
} else {
327+
if print_status {
328+
eprintln!("[task::new] {:?}", key);
329+
}
315330
}
316331

317332
(result, dep_node_index)

src/librustc/infer/error_reporting/nice_region_error/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::infer::InferCtxt;
22
use crate::infer::lexical_region_resolve::RegionResolutionError;
33
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
4-
use syntax::source_map::Span;
54
use crate::ty::{self, TyCtxt};
65
use crate::util::common::ErrorReported;
6+
use errors::DiagnosticBuilder;
7+
use syntax::source_map::Span;
78

89
mod different_lifetimes;
910
mod find_anon_type;
@@ -59,7 +60,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
5960
self.infcx.tcx
6061
}
6162

62-
pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
63+
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'cx>> {
6364
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
6465
// the nice region errors are required when running under the MIR borrow checker.
6566
self.try_report_named_anon_conflict()
@@ -68,6 +69,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
6869

6970
pub fn try_report(&self) -> Option<ErrorReported> {
7071
self.try_report_from_nll()
72+
.map(|mut diag| { diag.emit(); ErrorReported })
7173
.or_else(|| self.try_report_anon_anon_conflict())
7274
.or_else(|| self.try_report_outlives_closure())
7375
.or_else(|| self.try_report_static_impl_trait())

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
//! where one region is named and the other is anonymous.
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::ty;
5-
use crate::util::common::ErrorReported;
6-
use errors::Applicability;
5+
use errors::{Applicability, DiagnosticBuilder};
76

87
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
98
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
109
/// an anonymous region, emit an descriptive diagnostic error.
11-
pub(super) fn try_report_named_anon_conflict(&self) -> Option<ErrorReported> {
10+
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'a>> {
1211
let (span, sub, sup) = self.get_regions();
1312

1413
debug!(
@@ -96,21 +95,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
9695
("parameter type".to_owned(), "type".to_owned())
9796
};
9897

99-
struct_span_err!(
98+
let mut diag = struct_span_err!(
10099
self.tcx().sess,
101100
span,
102101
E0621,
103102
"explicit lifetime required in {}",
104103
error_var
105-
).span_suggestion(
106-
new_ty_span,
107-
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
108-
new_ty.to_string(),
109-
Applicability::Unspecified,
110-
)
111-
.span_label(span, format!("lifetime `{}` required", named))
112-
.emit();
113-
return Some(ErrorReported);
104+
);
105+
106+
diag.span_suggestion(
107+
new_ty_span,
108+
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
109+
new_ty.to_string(),
110+
Applicability::Unspecified,
111+
)
112+
.span_label(span, format!("lifetime `{}` required", named));
113+
114+
Some(diag)
114115
}
115116

116117
// This method returns whether the given Region is Named

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
88
use crate::ty;
99
use crate::ty::error::ExpectedFound;
1010
use crate::ty::subst::Substs;
11-
use crate::util::common::ErrorReported;
1211
use crate::util::ppaux::RegionHighlightMode;
1312

1413
impl NiceRegionError<'me, 'gcx, 'tcx> {
1514
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
1615
/// an anonymous region, emit a descriptive diagnostic error.
17-
pub(super) fn try_report_placeholder_conflict(&self) -> Option<ErrorReported> {
16+
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'me>> {
1817
match &self.error {
1918
///////////////////////////////////////////////////////////////////////////
2019
// NB. The ordering of cases in this match is very
@@ -178,7 +177,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
178177
trait_def_id: DefId,
179178
expected_substs: &'tcx Substs<'tcx>,
180179
actual_substs: &'tcx Substs<'tcx>,
181-
) -> ErrorReported {
180+
) -> DiagnosticBuilder<'me> {
182181
debug!(
183182
"try_report_placeholders_trait(\
184183
vid={:?}, \
@@ -295,8 +294,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
295294
any_self_ty_has_vid,
296295
);
297296

298-
err.emit();
299-
ErrorReported
297+
err
300298
}
301299

302300
/// Add notes with details about the expected and actual trait refs, with attention to cases

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12371237
"show extended diagnostic help"),
12381238
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
12391239
"attempt to recover from parse errors (experimental)"),
1240+
dep_tasks: bool = (false, parse_bool, [UNTRACKED],
1241+
"print tasks that execute and the color their dep node gets (requires debug build)"),
12401242
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
12411243
"enable incremental compilation (experimental)"),
12421244
incremental_queries: bool = (true, parse_bool, [UNTRACKED],

src/librustc/session/mod.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::lint;
99
use crate::lint::builtin::BuiltinLintDiagnostics;
1010
use crate::middle::allocator::AllocatorKind;
1111
use crate::middle::dependency_format;
12-
use crate::session::config::{OutputType, Lto};
12+
use crate::session::config::OutputType;
1313
use crate::session::search_paths::{PathKind, SearchPath};
1414
use crate::util::nodemap::{FxHashMap, FxHashSet};
1515
use crate::util::common::{duration_to_secs_str, ErrorReported};
@@ -1246,20 +1246,6 @@ pub fn build_session_(
12461246
// If it is useful to have a Session available already for validating a
12471247
// commandline argument, you can do so here.
12481248
fn validate_commandline_args_with_session_available(sess: &Session) {
1249-
1250-
if sess.opts.incremental.is_some() {
1251-
match sess.lto() {
1252-
Lto::Thin |
1253-
Lto::Fat => {
1254-
sess.err("can't perform LTO when compiling incrementally");
1255-
}
1256-
Lto::ThinLocal |
1257-
Lto::No => {
1258-
// This is fine
1259-
}
1260-
}
1261-
}
1262-
12631249
// Since we don't know if code in an rlib will be linked to statically or
12641250
// dynamically downstream, rustc generates `__imp_` symbols that help the
12651251
// MSVC linker deal with this lack of knowledge (#27438). Unfortunately,

src/librustc/ty/query/plumbing.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
124124
let job = match lock.active.entry((*key).clone()) {
125125
Entry::Occupied(entry) => {
126126
match *entry.get() {
127-
QueryResult::Started(ref job) => job.clone(),
127+
QueryResult::Started(ref job) => {
128+
//For parallel queries, we'll block and wait until the query running
129+
//in another thread has completed. Record how long we wait in the
130+
//self-profiler
131+
#[cfg(parallel_compiler)]
132+
tcx.sess.profiler(|p| p.query_blocked_start(Q::NAME, Q::CATEGORY));
133+
134+
job.clone()
135+
},
128136
QueryResult::Poisoned => FatalError.raise(),
129137
}
130138
}
@@ -160,7 +168,10 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
160168
// thread
161169
#[cfg(parallel_compiler)]
162170
{
163-
if let Err(cycle) = job.r#await(tcx, span) {
171+
let result = job.r#await(tcx, span);
172+
tcx.sess.profiler(|p| p.query_blocked_end(Q::NAME, Q::CATEGORY));
173+
174+
if let Err(cycle) = result {
164175
return TryGetJob::JobCompleted(Err(cycle));
165176
}
166177
}
@@ -441,7 +452,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
441452
// First we try to load the result from the on-disk cache
442453
let result = if Q::cache_on_disk(self.global_tcx(), key.clone()) &&
443454
self.sess.opts.debugging_opts.incremental_queries {
455+
self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME));
444456
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index);
457+
self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME));
445458

446459
// We always expect to find a cached result for things that
447460
// can be forced from DepNode.

src/librustc/util/profiling.rs

+57-18
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,28 @@ pub enum ProfilerEvent {
2525
GenericActivityEnd { category: ProfileCategory, time: Instant },
2626
QueryCacheHit { query_name: &'static str, category: ProfileCategory },
2727
QueryCount { query_name: &'static str, category: ProfileCategory, count: usize },
28+
IncrementalLoadResultStart { query_name: &'static str, time: Instant },
29+
IncrementalLoadResultEnd { query_name: &'static str, time: Instant },
30+
QueryBlockedStart { query_name: &'static str, category: ProfileCategory, time: Instant },
31+
QueryBlockedEnd { query_name: &'static str, category: ProfileCategory, time: Instant },
2832
}
2933

3034
impl ProfilerEvent {
3135
fn is_start_event(&self) -> bool {
3236
use self::ProfilerEvent::*;
3337

3438
match self {
35-
QueryStart { .. } | GenericActivityStart { .. } => true,
36-
QueryEnd { .. } | GenericActivityEnd { .. } |
37-
QueryCacheHit { .. } | QueryCount { .. } => false,
39+
QueryStart { .. } |
40+
GenericActivityStart { .. } |
41+
IncrementalLoadResultStart { .. } |
42+
QueryBlockedStart { .. } => true,
43+
44+
QueryEnd { .. } |
45+
GenericActivityEnd { .. } |
46+
QueryCacheHit { .. } |
47+
QueryCount { .. } |
48+
IncrementalLoadResultEnd { .. } |
49+
QueryBlockedEnd { .. } => false,
3850
}
3951
}
4052
}
@@ -57,12 +69,7 @@ impl CategoryResultData {
5769
}
5870

5971
fn total_time(&self) -> u64 {
60-
let mut total = 0;
61-
for (_, time) in &self.query_times {
62-
total += time;
63-
}
64-
65-
total
72+
self.query_times.iter().map(|(_, time)| time).sum()
6673
}
6774

6875
fn total_cache_data(&self) -> (u64, u64) {
@@ -121,13 +128,7 @@ impl CalculatedResults {
121128
}
122129

123130
fn total_time(&self) -> u64 {
124-
let mut total = 0;
125-
126-
for (_, data) in &self.categories {
127-
total += data.total_time();
128-
}
129-
130-
total
131+
self.categories.iter().map(|(_, data)| data.total_time()).sum()
131132
}
132133

133134
fn with_options(mut self, opts: &Options) -> CalculatedResults {
@@ -225,6 +226,40 @@ impl SelfProfiler {
225226
})
226227
}
227228

229+
#[inline]
230+
pub fn incremental_load_result_start(&mut self, query_name: &'static str) {
231+
self.record(ProfilerEvent::IncrementalLoadResultStart {
232+
query_name,
233+
time: Instant::now(),
234+
})
235+
}
236+
237+
#[inline]
238+
pub fn incremental_load_result_end(&mut self, query_name: &'static str) {
239+
self.record(ProfilerEvent::IncrementalLoadResultEnd {
240+
query_name,
241+
time: Instant::now(),
242+
})
243+
}
244+
245+
#[inline]
246+
pub fn query_blocked_start(&mut self, query_name: &'static str, category: ProfileCategory) {
247+
self.record(ProfilerEvent::QueryBlockedStart {
248+
query_name,
249+
category,
250+
time: Instant::now(),
251+
})
252+
}
253+
254+
#[inline]
255+
pub fn query_blocked_end(&mut self, query_name: &'static str, category: ProfileCategory) {
256+
self.record(ProfilerEvent::QueryBlockedEnd {
257+
query_name,
258+
category,
259+
time: Instant::now(),
260+
})
261+
}
262+
228263
#[inline]
229264
fn record(&mut self, event: ProfilerEvent) {
230265
let thread_id = std::thread::current().id();
@@ -317,6 +352,10 @@ impl SelfProfiler {
317352
result_data.query_cache_stats.entry(query_name).or_insert((0, 0));
318353
*totals += *count as u64;
319354
},
355+
//we don't summarize incremental load result events in the simple output mode
356+
IncrementalLoadResultStart { .. } | IncrementalLoadResultEnd { .. } => { },
357+
//we don't summarize parallel query blocking in the simple output mode
358+
QueryBlockedStart { .. } | QueryBlockedEnd { .. } => { },
320359
}
321360
}
322361

@@ -361,9 +400,9 @@ impl SelfProfiler {
361400
.unwrap();
362401

363402
let mut categories: Vec<_> = results.categories.iter().collect();
364-
categories.sort_by(|(_, data1), (_, data2)| data2.total_time().cmp(&data1.total_time()));
403+
categories.sort_by_cached_key(|(_, d)| d.total_time());
365404

366-
for (category, data) in categories {
405+
for (category, data) in categories.iter().rev() {
367406
let (category_hits, category_total) = data.total_cache_data();
368407
let category_hit_percent = calculate_percent(category_hits, category_total);
369408

0 commit comments

Comments
 (0)