Skip to content
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

Rollup of 8 pull requests #109538

Merged
merged 23 commits into from Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2d927cc
Explain the "no-error" io::Error case
workingjubilee Jan 17, 2023
e7c8af4
Remove issue number for `link_cfg`
clubby789 Feb 28, 2023
c6cba68
Add check for errant {{produces}} marker.
ehuss Mar 1, 2023
15450b1
Fix the ffi_unwind_calls lint documentation
ehuss Mar 1, 2023
ab2508a
Collect all matching messages for a lint.
ehuss Mar 1, 2023
4f7cd3d
Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canoni…
Zoxc Mar 16, 2023
0f32fd8
Remove irrelevant docs on error kinds
workingjubilee Mar 17, 2023
1f67949
Lint ambiguous glob re-exports
jieyouxu Mar 19, 2023
b0dc15c
Reduce output spam
Zoxc Feb 6, 2023
f60d2eb
Add `-Z time-passes-format` to allow specifying a JSON output for `-Z…
Zoxc Feb 6, 2023
6c57dda
Remove `unique` and move `VerboseTimingGuard` fields into a new struct
Zoxc Mar 21, 2023
20f3f43
Fixes #109436: add parentheses properly
mu001999 Mar 22, 2023
825f088
Move useless_anynous_reexport lint into unused_imports
GuillaumeGomez Mar 22, 2023
e03b13c
Update anonymous-reexport UI test
GuillaumeGomez Mar 22, 2023
2580348
Use span_look_ahead instead of next_point
mu001999 Mar 23, 2023
aeabe34
Rollup merge of #106964 - workingjubilee:crouching-ioerror-hidden-doc…
matthiaskrgr Mar 23, 2023
acd7f87
Rollup merge of #107718 - Zoxc:z-time, r=nnethercote
matthiaskrgr Mar 23, 2023
bacf059
Rollup merge of #107880 - jieyouxu:issue-107563, r=petrochenkov
matthiaskrgr Mar 23, 2023
5a017d3
Rollup merge of #108549 - clubby789:fix-link-cfg-issue, r=eholk
matthiaskrgr Mar 23, 2023
fc5516b
Rollup merge of #108588 - ehuss:lint-docs-produces, r=eholk
matthiaskrgr Mar 23, 2023
2a39cf5
Rollup merge of #109231 - Zoxc:fs-non-canon, r=eholk
matthiaskrgr Mar 23, 2023
dddede4
Rollup merge of #109472 - MU001999:patch-3, r=eholk
matthiaskrgr Mar 23, 2023
3961ef5
Rollup merge of #109487 - GuillaumeGomez:move-useless-reexport-check,…
matthiaskrgr Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock
Expand Up @@ -4523,6 +4523,7 @@ dependencies = [
"rustc_index",
"rustc_macros",
"rustc_serialize",
"serde_json",
"smallvec",
"stable_deref_trait",
"stacker",
Expand Down Expand Up @@ -4826,6 +4827,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_expand",
"rustc_fs_util",
"rustc_hir",
"rustc_hir_analysis",
"rustc_hir_typeck",
Expand Down Expand Up @@ -4950,6 +4952,7 @@ dependencies = [
"rustc_errors",
"rustc_expand",
"rustc_feature",
"rustc_fs_util",
"rustc_hir",
"rustc_hir_pretty",
"rustc_index",
Expand Down Expand Up @@ -5335,6 +5338,7 @@ dependencies = [
"rustc_abi",
"rustc_data_structures",
"rustc_feature",
"rustc_fs_util",
"rustc_index",
"rustc_macros",
"rustc_serialize",
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/lib.rs
Expand Up @@ -361,12 +361,12 @@ impl CodegenBackend for LlvmCodegenBackend {
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess);

sess.time("llvm_dump_timing_file", || {
if sess.opts.unstable_opts.llvm_time_trace {
if sess.opts.unstable_opts.llvm_time_trace {
sess.time("llvm_dump_timing_file", || {
let file_name = outputs.with_extension("llvm_timings.json");
llvm_util::time_trace_profiler_finish(&file_name);
}
});
});
}

Ok((codegen_results, work_products))
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Expand Up @@ -786,6 +786,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
total_codegen_time,
start_rss.unwrap(),
end_rss,
tcx.sess.opts.unstable_opts.time_passes_format,
);
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/Cargo.toml
Expand Up @@ -21,6 +21,7 @@ rustc-hash = "1.1.0"
rustc_index = { path = "../rustc_index", package = "rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
serde_json = "1.0.59"
smallvec = { version = "1.8.1", features = [
"const_generics",
"union",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/graph/scc/tests.rs
Expand Up @@ -56,7 +56,7 @@ fn test_three_sccs() {
assert_eq!(sccs.scc(1), 0);
assert_eq!(sccs.scc(2), 0);
assert_eq!(sccs.scc(3), 2);
assert_eq!(sccs.successors(0), &[]);
assert_eq!(sccs.successors(0), &[] as &[usize]);
assert_eq!(sccs.successors(1), &[0]);
assert_eq!(sccs.successors(2), &[0]);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test_find_state_2() {
assert_eq!(sccs.scc(2), 0);
assert_eq!(sccs.scc(3), 0);
assert_eq!(sccs.scc(4), 0);
assert_eq!(sccs.successors(0), &[]);
assert_eq!(sccs.successors(0), &[] as &[usize]);
}

#[test]
Expand All @@ -138,7 +138,7 @@ fn test_find_state_3() {
assert_eq!(sccs.scc(3), 0);
assert_eq!(sccs.scc(4), 0);
assert_eq!(sccs.scc(5), 1);
assert_eq!(sccs.successors(0), &[]);
assert_eq!(sccs.successors(0), &[] as &[usize]);
assert_eq!(sccs.successors(1), &[0]);
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/graph/vec_graph/tests.rs
Expand Up @@ -27,11 +27,11 @@ fn successors() {
let graph = create_graph();
assert_eq!(graph.successors(0), &[1]);
assert_eq!(graph.successors(1), &[2, 3]);
assert_eq!(graph.successors(2), &[]);
assert_eq!(graph.successors(2), &[] as &[usize]);
assert_eq!(graph.successors(3), &[4]);
assert_eq!(graph.successors(4), &[]);
assert_eq!(graph.successors(4), &[] as &[usize]);
assert_eq!(graph.successors(5), &[1]);
assert_eq!(graph.successors(6), &[]);
assert_eq!(graph.successors(6), &[] as &[usize]);
}

#[test]
Expand Down
72 changes: 58 additions & 14 deletions compiler/rustc_data_structures/src/profiling.rs
Expand Up @@ -97,6 +97,7 @@ use std::time::{Duration, Instant};
pub use measureme::EventId;
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
use parking_lot::RwLock;
use serde_json::json;
use smallvec::SmallVec;

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

/// Which format to use for `-Z time-passes`
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
pub enum TimePassesFormat {
/// Emit human readable text
Text,
/// Emit structured JSON
Json,
}

/// A reference to the SelfProfiler. It can be cloned and sent across thread
/// boundaries at will.
#[derive(Clone)]
Expand All @@ -158,14 +168,14 @@ pub struct SelfProfilerRef {
// actually enabled.
event_filter_mask: EventFilter,

// Print verbose generic activities to stderr?
print_verbose_generic_activities: bool,
// Print verbose generic activities to stderr.
print_verbose_generic_activities: Option<TimePassesFormat>,
}

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

VerboseTimingGuard::start(message, self.generic_activity(event_label))
VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label))
}

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

VerboseTimingGuard::start(message, self.generic_activity_with_arg(event_label, event_arg))
VerboseTimingGuard::start(
message_and_format,
self.generic_activity_with_arg(event_label, event_arg),
)
}

/// Start profiling a generic activity. Profiling continues until the
Expand Down Expand Up @@ -703,17 +717,32 @@ impl<'a> TimingGuard<'a> {
}
}

struct VerboseInfo {
start_time: Instant,
start_rss: Option<usize>,
message: String,
format: TimePassesFormat,
}

#[must_use]
pub struct VerboseTimingGuard<'a> {
start_and_message: Option<(Instant, Option<usize>, String)>,
info: Option<VerboseInfo>,
_guard: TimingGuard<'a>,
}

impl<'a> VerboseTimingGuard<'a> {
pub fn start(message: Option<String>, _guard: TimingGuard<'a>) -> Self {
pub fn start(
message_and_format: Option<(String, TimePassesFormat)>,
_guard: TimingGuard<'a>,
) -> Self {
VerboseTimingGuard {
_guard,
start_and_message: message.map(|msg| (Instant::now(), get_resident_set_size(), msg)),
info: message_and_format.map(|(message, format)| VerboseInfo {
start_time: Instant::now(),
start_rss: get_resident_set_size(),
message,
format,
}),
}
}

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

impl Drop for VerboseTimingGuard<'_> {
fn drop(&mut self) {
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
if let Some(info) = &self.info {
let end_rss = get_resident_set_size();
let dur = start_time.elapsed();
print_time_passes_entry(message, dur, start_rss, end_rss);
let dur = info.start_time.elapsed();
print_time_passes_entry(&info.message, dur, info.start_rss, end_rss, info.format);
}
}
}
Expand All @@ -739,7 +768,22 @@ pub fn print_time_passes_entry(
dur: Duration,
start_rss: Option<usize>,
end_rss: Option<usize>,
format: TimePassesFormat,
) {
match format {
TimePassesFormat::Json => {
let json = json!({
"pass": what,
"time": dur.as_secs_f64(),
"rss_start": start_rss,
"rss_end": end_rss,
});
eprintln!("time: {}", json.to_string());
return;
}
TimePassesFormat::Text => (),
}

// Print the pass if its duration is greater than 5 ms, or it changed the
// measured RSS.
let is_notable = || {
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Expand Up @@ -20,7 +20,9 @@ pub extern crate rustc_plugin_impl as plugin;

use rustc_ast as ast;
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
};
use rustc_data_structures::sync::SeqCst;
use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{
Expand Down Expand Up @@ -161,7 +163,7 @@ pub trait Callbacks {

#[derive(Default)]
pub struct TimePassesCallbacks {
time_passes: bool,
time_passes: Option<TimePassesFormat>,
}

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

if callbacks.time_passes {
if let Some(format) = callbacks.time_passes {
let end_rss = get_resident_set_size();
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss);
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format);
}

process::exit(exit_code)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -160,6 +160,8 @@ declare_features! (
(active, intrinsics, "1.0.0", None, None),
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
(active, lang_items, "1.0.0", None, None),
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
(active, link_cfg, "1.14.0", None, None),
/// Allows the `multiple_supertrait_upcastable` lint.
(active, multiple_supertrait_upcastable, "1.69.0", None, None),
/// Allows using `#[omit_gdb_pretty_printer_section]`.
Expand Down Expand Up @@ -432,8 +434,6 @@ declare_features! (
(active, large_assignments, "1.52.0", Some(83518), None),
/// Allows `if/while p && let q = r && ...` chains.
(active, let_chains, "1.37.0", Some(53667), None),
/// Allows `#[link(..., cfg(..))]`.
(active, link_cfg, "1.14.0", Some(37406), None),
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
(active, lint_reasons, "1.31.0", Some(54503), None),
/// Give access to additional metadata about declarative macro meta-variables.
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_fs_util/src/lib.rs
@@ -1,10 +1,11 @@
#![feature(absolute_path)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

use std::ffi::CString;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::path::{absolute, Path, PathBuf};

// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
// verbatim paths under the hood to non-verbatim paths! This manifests itself as
Expand Down Expand Up @@ -91,3 +92,8 @@ pub fn path_to_c_string(p: &Path) -> CString {
pub fn path_to_c_string(p: &Path) -> CString {
CString::new(p.to_str().unwrap()).unwrap()
}

#[inline]
pub fn try_canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
fs::canonicalize(&path).or_else(|_| absolute(&path))
}
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/coherence/mod.rs
Expand Up @@ -133,8 +133,8 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
check_impl(tcx, impl_def_id, trait_ref);
check_object_overlap(tcx, impl_def_id, trait_ref);

tcx.sess.time("unsafety_checking", || unsafety::check_item(tcx, impl_def_id));
tcx.sess.time("orphan_checking", || tcx.ensure().orphan_check_impl(impl_def_id));
unsafety::check_item(tcx, impl_def_id);
tcx.ensure().orphan_check_impl(impl_def_id);
}

builtin::check_trait(tcx, def_id);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_incremental/src/persist/fs.rs
Expand Up @@ -108,7 +108,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::svh::Svh;
use rustc_data_structures::{base_n, flock};
use rustc_errors::ErrorGuaranteed;
use rustc_fs_util::{link_or_copy, LinkOrCopy};
use rustc_fs_util::{link_or_copy, try_canonicalize, LinkOrCopy};
use rustc_session::{Session, StableCrateId};
use rustc_span::Symbol;

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

fn safe_remove_file(p: &Path) -> io::Result<()> {
let canonicalized = match std_fs::canonicalize(p) {
let canonicalized = match try_canonicalize(p) {
Ok(canonicalized) => canonicalized,
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(()),
Err(err) => return Err(err),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/Cargo.toml
Expand Up @@ -16,6 +16,7 @@ rustc_attr = { path = "../rustc_attr" }
rustc_borrowck = { path = "../rustc_borrowck" }
rustc_builtin_macros = { path = "../rustc_builtin_macros" }
rustc_expand = { path = "../rustc_expand" }
rustc_fs_util = { path = "../rustc_fs_util" }
rustc_macros = { path = "../rustc_macros" }
rustc_parse = { path = "../rustc_parse" }
rustc_session = { path = "../rustc_session" }
Expand Down