Skip to content

Commit 1459b31

Browse files
committed
Auto merge of rust-lang#109538 - matthiaskrgr:rollup-ct58npj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#106964 (Clarify `Error::last_os_error` can be weird) - rust-lang#107718 (Add `-Z time-passes-format` to allow specifying a JSON output for `-Z time-passes`) - rust-lang#107880 (Lint ambiguous glob re-exports) - rust-lang#108549 (Remove issue number for `link_cfg`) - rust-lang#108588 (Fix the ffi_unwind_calls lint documentation) - rust-lang#109231 (Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canonicalize`) - rust-lang#109472 (Add parentheses properly for method calls) - rust-lang#109487 (Move useless_anynous_reexport lint into unused_imports) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e216300 + 3961ef5 commit 1459b31

File tree

52 files changed

+566
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+566
-266
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -4523,6 +4523,7 @@ dependencies = [
45234523
"rustc_index",
45244524
"rustc_macros",
45254525
"rustc_serialize",
4526+
"serde_json",
45264527
"smallvec",
45274528
"stable_deref_trait",
45284529
"stacker",
@@ -4826,6 +4827,7 @@ dependencies = [
48264827
"rustc_data_structures",
48274828
"rustc_errors",
48284829
"rustc_expand",
4830+
"rustc_fs_util",
48294831
"rustc_hir",
48304832
"rustc_hir_analysis",
48314833
"rustc_hir_typeck",
@@ -4950,6 +4952,7 @@ dependencies = [
49504952
"rustc_errors",
49514953
"rustc_expand",
49524954
"rustc_feature",
4955+
"rustc_fs_util",
49534956
"rustc_hir",
49544957
"rustc_hir_pretty",
49554958
"rustc_index",
@@ -5335,6 +5338,7 @@ dependencies = [
53355338
"rustc_abi",
53365339
"rustc_data_structures",
53375340
"rustc_feature",
5341+
"rustc_fs_util",
53385342
"rustc_index",
53395343
"rustc_macros",
53405344
"rustc_serialize",

compiler/rustc_codegen_llvm/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ impl CodegenBackend for LlvmCodegenBackend {
361361
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
362362
.join(sess);
363363

364-
sess.time("llvm_dump_timing_file", || {
365-
if sess.opts.unstable_opts.llvm_time_trace {
364+
if sess.opts.unstable_opts.llvm_time_trace {
365+
sess.time("llvm_dump_timing_file", || {
366366
let file_name = outputs.with_extension("llvm_timings.json");
367367
llvm_util::time_trace_profiler_finish(&file_name);
368-
}
369-
});
368+
});
369+
}
370370

371371
Ok((codegen_results, work_products))
372372
}

compiler/rustc_codegen_ssa/src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
786786
total_codegen_time,
787787
start_rss.unwrap(),
788788
end_rss,
789+
tcx.sess.opts.unstable_opts.time_passes_format,
789790
);
790791
}
791792

compiler/rustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rustc-hash = "1.1.0"
2121
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2222
rustc_macros = { path = "../rustc_macros" }
2323
rustc_serialize = { path = "../rustc_serialize" }
24+
serde_json = "1.0.59"
2425
smallvec = { version = "1.8.1", features = [
2526
"const_generics",
2627
"union",

compiler/rustc_data_structures/src/graph/scc/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn test_three_sccs() {
5656
assert_eq!(sccs.scc(1), 0);
5757
assert_eq!(sccs.scc(2), 0);
5858
assert_eq!(sccs.scc(3), 2);
59-
assert_eq!(sccs.successors(0), &[]);
59+
assert_eq!(sccs.successors(0), &[] as &[usize]);
6060
assert_eq!(sccs.successors(1), &[0]);
6161
assert_eq!(sccs.successors(2), &[0]);
6262
}
@@ -113,7 +113,7 @@ fn test_find_state_2() {
113113
assert_eq!(sccs.scc(2), 0);
114114
assert_eq!(sccs.scc(3), 0);
115115
assert_eq!(sccs.scc(4), 0);
116-
assert_eq!(sccs.successors(0), &[]);
116+
assert_eq!(sccs.successors(0), &[] as &[usize]);
117117
}
118118

119119
#[test]
@@ -138,7 +138,7 @@ fn test_find_state_3() {
138138
assert_eq!(sccs.scc(3), 0);
139139
assert_eq!(sccs.scc(4), 0);
140140
assert_eq!(sccs.scc(5), 1);
141-
assert_eq!(sccs.successors(0), &[]);
141+
assert_eq!(sccs.successors(0), &[] as &[usize]);
142142
assert_eq!(sccs.successors(1), &[0]);
143143
}
144144

compiler/rustc_data_structures/src/graph/vec_graph/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ fn successors() {
2727
let graph = create_graph();
2828
assert_eq!(graph.successors(0), &[1]);
2929
assert_eq!(graph.successors(1), &[2, 3]);
30-
assert_eq!(graph.successors(2), &[]);
30+
assert_eq!(graph.successors(2), &[] as &[usize]);
3131
assert_eq!(graph.successors(3), &[4]);
32-
assert_eq!(graph.successors(4), &[]);
32+
assert_eq!(graph.successors(4), &[] as &[usize]);
3333
assert_eq!(graph.successors(5), &[1]);
34-
assert_eq!(graph.successors(6), &[]);
34+
assert_eq!(graph.successors(6), &[] as &[usize]);
3535
}
3636

3737
#[test]

compiler/rustc_data_structures/src/profiling.rs

+58-14
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ use std::time::{Duration, Instant};
9797
pub use measureme::EventId;
9898
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
9999
use parking_lot::RwLock;
100+
use serde_json::json;
100101
use smallvec::SmallVec;
101102

102103
bitflags::bitflags! {
@@ -145,6 +146,15 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
145146
/// Something that uniquely identifies a query invocation.
146147
pub struct QueryInvocationId(pub u32);
147148

149+
/// Which format to use for `-Z time-passes`
150+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
151+
pub enum TimePassesFormat {
152+
/// Emit human readable text
153+
Text,
154+
/// Emit structured JSON
155+
Json,
156+
}
157+
148158
/// A reference to the SelfProfiler. It can be cloned and sent across thread
149159
/// boundaries at will.
150160
#[derive(Clone)]
@@ -158,14 +168,14 @@ pub struct SelfProfilerRef {
158168
// actually enabled.
159169
event_filter_mask: EventFilter,
160170

161-
// Print verbose generic activities to stderr?
162-
print_verbose_generic_activities: bool,
171+
// Print verbose generic activities to stderr.
172+
print_verbose_generic_activities: Option<TimePassesFormat>,
163173
}
164174

165175
impl SelfProfilerRef {
166176
pub fn new(
167177
profiler: Option<Arc<SelfProfiler>>,
168-
print_verbose_generic_activities: bool,
178+
print_verbose_generic_activities: Option<TimePassesFormat>,
169179
) -> SelfProfilerRef {
170180
// If there is no SelfProfiler then the filter mask is set to NONE,
171181
// ensuring that nothing ever tries to actually access it.
@@ -207,9 +217,10 @@ impl SelfProfilerRef {
207217
/// a measureme event, "verbose" generic activities also print a timing entry to
208218
/// stderr if the compiler is invoked with -Ztime-passes.
209219
pub fn verbose_generic_activity(&self, event_label: &'static str) -> VerboseTimingGuard<'_> {
210-
let message = self.print_verbose_generic_activities.then(|| event_label.to_owned());
220+
let message_and_format =
221+
self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), format));
211222

212-
VerboseTimingGuard::start(message, self.generic_activity(event_label))
223+
VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label))
213224
}
214225

215226
/// Like `verbose_generic_activity`, but with an extra arg.
@@ -221,11 +232,14 @@ impl SelfProfilerRef {
221232
where
222233
A: Borrow<str> + Into<String>,
223234
{
224-
let message = self
235+
let message_and_format = self
225236
.print_verbose_generic_activities
226-
.then(|| format!("{}({})", event_label, event_arg.borrow()));
237+
.map(|format| (format!("{}({})", event_label, event_arg.borrow()), format));
227238

228-
VerboseTimingGuard::start(message, self.generic_activity_with_arg(event_label, event_arg))
239+
VerboseTimingGuard::start(
240+
message_and_format,
241+
self.generic_activity_with_arg(event_label, event_arg),
242+
)
229243
}
230244

231245
/// Start profiling a generic activity. Profiling continues until the
@@ -703,17 +717,32 @@ impl<'a> TimingGuard<'a> {
703717
}
704718
}
705719

720+
struct VerboseInfo {
721+
start_time: Instant,
722+
start_rss: Option<usize>,
723+
message: String,
724+
format: TimePassesFormat,
725+
}
726+
706727
#[must_use]
707728
pub struct VerboseTimingGuard<'a> {
708-
start_and_message: Option<(Instant, Option<usize>, String)>,
729+
info: Option<VerboseInfo>,
709730
_guard: TimingGuard<'a>,
710731
}
711732

712733
impl<'a> VerboseTimingGuard<'a> {
713-
pub fn start(message: Option<String>, _guard: TimingGuard<'a>) -> Self {
734+
pub fn start(
735+
message_and_format: Option<(String, TimePassesFormat)>,
736+
_guard: TimingGuard<'a>,
737+
) -> Self {
714738
VerboseTimingGuard {
715739
_guard,
716-
start_and_message: message.map(|msg| (Instant::now(), get_resident_set_size(), msg)),
740+
info: message_and_format.map(|(message, format)| VerboseInfo {
741+
start_time: Instant::now(),
742+
start_rss: get_resident_set_size(),
743+
message,
744+
format,
745+
}),
717746
}
718747
}
719748

@@ -726,10 +755,10 @@ impl<'a> VerboseTimingGuard<'a> {
726755

727756
impl Drop for VerboseTimingGuard<'_> {
728757
fn drop(&mut self) {
729-
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
758+
if let Some(info) = &self.info {
730759
let end_rss = get_resident_set_size();
731-
let dur = start_time.elapsed();
732-
print_time_passes_entry(message, dur, start_rss, end_rss);
760+
let dur = info.start_time.elapsed();
761+
print_time_passes_entry(&info.message, dur, info.start_rss, end_rss, info.format);
733762
}
734763
}
735764
}
@@ -739,7 +768,22 @@ pub fn print_time_passes_entry(
739768
dur: Duration,
740769
start_rss: Option<usize>,
741770
end_rss: Option<usize>,
771+
format: TimePassesFormat,
742772
) {
773+
match format {
774+
TimePassesFormat::Json => {
775+
let json = json!({
776+
"pass": what,
777+
"time": dur.as_secs_f64(),
778+
"rss_start": start_rss,
779+
"rss_end": end_rss,
780+
});
781+
eprintln!("time: {}", json.to_string());
782+
return;
783+
}
784+
TimePassesFormat::Text => (),
785+
}
786+
743787
// Print the pass if its duration is greater than 5 ms, or it changed the
744788
// measured RSS.
745789
let is_notable = || {

compiler/rustc_driver_impl/src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ pub extern crate rustc_plugin_impl as plugin;
2020

2121
use rustc_ast as ast;
2222
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
23-
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
23+
use rustc_data_structures::profiling::{
24+
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
25+
};
2426
use rustc_data_structures::sync::SeqCst;
2527
use rustc_errors::registry::{InvalidErrorCode, Registry};
2628
use rustc_errors::{
@@ -161,7 +163,7 @@ pub trait Callbacks {
161163

162164
#[derive(Default)]
163165
pub struct TimePassesCallbacks {
164-
time_passes: bool,
166+
time_passes: Option<TimePassesFormat>,
165167
}
166168

167169
impl Callbacks for TimePassesCallbacks {
@@ -171,7 +173,8 @@ impl Callbacks for TimePassesCallbacks {
171173
// If a --print=... option has been given, we don't print the "total"
172174
// time because it will mess up the --print output. See #64339.
173175
//
174-
self.time_passes = config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes;
176+
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
177+
.then(|| config.opts.unstable_opts.time_passes_format);
175178
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
176179
}
177180
}
@@ -1354,9 +1357,9 @@ pub fn main() -> ! {
13541357
RunCompiler::new(&args, &mut callbacks).run()
13551358
});
13561359

1357-
if callbacks.time_passes {
1360+
if let Some(format) = callbacks.time_passes {
13581361
let end_rss = get_resident_set_size();
1359-
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss);
1362+
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format);
13601363
}
13611364

13621365
process::exit(exit_code)

compiler/rustc_feature/src/active.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ declare_features! (
160160
(active, intrinsics, "1.0.0", None, None),
161161
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
162162
(active, lang_items, "1.0.0", None, None),
163+
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
164+
(active, link_cfg, "1.14.0", None, None),
163165
/// Allows the `multiple_supertrait_upcastable` lint.
164166
(active, multiple_supertrait_upcastable, "1.69.0", None, None),
165167
/// Allows using `#[omit_gdb_pretty_printer_section]`.
@@ -432,8 +434,6 @@ declare_features! (
432434
(active, large_assignments, "1.52.0", Some(83518), None),
433435
/// Allows `if/while p && let q = r && ...` chains.
434436
(active, let_chains, "1.37.0", Some(53667), None),
435-
/// Allows `#[link(..., cfg(..))]`.
436-
(active, link_cfg, "1.14.0", Some(37406), None),
437437
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
438438
(active, lint_reasons, "1.31.0", Some(54503), None),
439439
/// Give access to additional metadata about declarative macro meta-variables.

compiler/rustc_fs_util/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#![feature(absolute_path)]
12
#![deny(rustc::untranslatable_diagnostic)]
23
#![deny(rustc::diagnostic_outside_of_impl)]
34

45
use std::ffi::CString;
56
use std::fs;
67
use std::io;
7-
use std::path::{Path, PathBuf};
8+
use std::path::{absolute, Path, PathBuf};
89

910
// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
1011
// verbatim paths under the hood to non-verbatim paths! This manifests itself as
@@ -91,3 +92,8 @@ pub fn path_to_c_string(p: &Path) -> CString {
9192
pub fn path_to_c_string(p: &Path) -> CString {
9293
CString::new(p.to_str().unwrap()).unwrap()
9394
}
95+
96+
#[inline]
97+
pub fn try_canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
98+
fs::canonicalize(&path).or_else(|_| absolute(&path))
99+
}

compiler/rustc_hir_analysis/src/coherence/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
133133
check_impl(tcx, impl_def_id, trait_ref);
134134
check_object_overlap(tcx, impl_def_id, trait_ref);
135135

136-
tcx.sess.time("unsafety_checking", || unsafety::check_item(tcx, impl_def_id));
137-
tcx.sess.time("orphan_checking", || tcx.ensure().orphan_check_impl(impl_def_id));
136+
unsafety::check_item(tcx, impl_def_id);
137+
tcx.ensure().orphan_check_impl(impl_def_id);
138138
}
139139

140140
builtin::check_trait(tcx, def_id);

compiler/rustc_incremental/src/persist/fs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
108108
use rustc_data_structures::svh::Svh;
109109
use rustc_data_structures::{base_n, flock};
110110
use rustc_errors::ErrorGuaranteed;
111-
use rustc_fs_util::{link_or_copy, LinkOrCopy};
111+
use rustc_fs_util::{link_or_copy, try_canonicalize, LinkOrCopy};
112112
use rustc_session::{Session, StableCrateId};
113113
use rustc_span::Symbol;
114114

@@ -223,7 +223,7 @@ pub fn prepare_session_directory(
223223
// because, on windows, long paths can cause problems;
224224
// canonicalization inserts this weird prefix that makes windows
225225
// tolerate long paths.
226-
let crate_dir = match crate_dir.canonicalize() {
226+
let crate_dir = match try_canonicalize(&crate_dir) {
227227
Ok(v) => v,
228228
Err(err) => {
229229
return Err(sess.emit_err(errors::CanonicalizePath { path: crate_dir, err }));
@@ -867,7 +867,7 @@ fn all_except_most_recent(
867867
/// before passing it to std::fs::remove_dir_all(). This will convert the path
868868
/// into the '\\?\' format, which supports much longer paths.
869869
fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
870-
let canonicalized = match std_fs::canonicalize(p) {
870+
let canonicalized = match try_canonicalize(p) {
871871
Ok(canonicalized) => canonicalized,
872872
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(()),
873873
Err(err) => return Err(err),
@@ -877,7 +877,7 @@ fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
877877
}
878878

879879
fn safe_remove_file(p: &Path) -> io::Result<()> {
880-
let canonicalized = match std_fs::canonicalize(p) {
880+
let canonicalized = match try_canonicalize(p) {
881881
Ok(canonicalized) => canonicalized,
882882
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(()),
883883
Err(err) => return Err(err),

compiler/rustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_attr = { path = "../rustc_attr" }
1616
rustc_borrowck = { path = "../rustc_borrowck" }
1717
rustc_builtin_macros = { path = "../rustc_builtin_macros" }
1818
rustc_expand = { path = "../rustc_expand" }
19+
rustc_fs_util = { path = "../rustc_fs_util" }
1920
rustc_macros = { path = "../rustc_macros" }
2021
rustc_parse = { path = "../rustc_parse" }
2122
rustc_session = { path = "../rustc_session" }

0 commit comments

Comments
 (0)