From 87dd3def59e729f7be0a0e69cd4e7adc5ea37dcb Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 28 Mar 2022 15:59:37 +0200 Subject: [PATCH 1/6] Only output DepKind in dump-dep-graph. When printing the whole DepNode, the output file is simply too massive to be actually useful for profiling. This trimmed down version mixes a lot of information together, but it also allows to ask questions such that "why does this query ever access HIR?". --- .../rustc_incremental/src/assert_dep_graph.rs | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 60b48e9bc8a01..2d06c9d8ec92c 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -241,7 +241,7 @@ fn dump_graph(query: &DepGraphQuery) { let targets = node_set(&query, &edge_filter.target); filter_nodes(&query, &sources, &targets) } - Err(_) => query.nodes().into_iter().collect(), + Err(_) => query.nodes().into_iter().map(|n| n.kind).collect(), }; let edges = filter_edges(&query, &nodes); @@ -264,33 +264,33 @@ fn dump_graph(query: &DepGraphQuery) { } #[allow(missing_docs)] -pub struct GraphvizDepGraph<'q>(FxHashSet<&'q DepNode>, Vec<(&'q DepNode, &'q DepNode)>); +pub struct GraphvizDepGraph(FxHashSet, Vec<(DepKind, DepKind)>); -impl<'a, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> { - type Node = &'q DepNode; - type Edge = (&'q DepNode, &'q DepNode); - fn nodes(&self) -> dot::Nodes<'_, &'q DepNode> { +impl<'a> dot::GraphWalk<'a> for GraphvizDepGraph { + type Node = DepKind; + type Edge = (DepKind, DepKind); + fn nodes(&self) -> dot::Nodes<'_, DepKind> { let nodes: Vec<_> = self.0.iter().cloned().collect(); nodes.into() } - fn edges(&self) -> dot::Edges<'_, (&'q DepNode, &'q DepNode)> { + fn edges(&self) -> dot::Edges<'_, (DepKind, DepKind)> { self.1[..].into() } - fn source(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode { + fn source(&self, edge: &(DepKind, DepKind)) -> DepKind { edge.0 } - fn target(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode { + fn target(&self, edge: &(DepKind, DepKind)) -> DepKind { edge.1 } } -impl<'a, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> { - type Node = &'q DepNode; - type Edge = (&'q DepNode, &'q DepNode); +impl<'a> dot::Labeller<'a> for GraphvizDepGraph { + type Node = DepKind; + type Edge = (DepKind, DepKind); fn graph_id(&self) -> dot::Id<'_> { dot::Id::new("DependencyGraph").unwrap() } - fn node_id(&self, n: &&'q DepNode) -> dot::Id<'_> { + fn node_id(&self, n: &DepKind) -> dot::Id<'_> { let s: String = format!("{:?}", n) .chars() .map(|c| if c == '_' || c.is_alphanumeric() { c } else { '_' }) @@ -298,7 +298,7 @@ impl<'a, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> { debug!("n={:?} s={:?}", n, s); dot::Id::new(s).unwrap() } - fn node_label(&self, n: &&'q DepNode) -> dot::LabelText<'_> { + fn node_label(&self, n: &DepKind) -> dot::LabelText<'_> { dot::LabelText::label(format!("{:?}", n)) } } @@ -323,7 +323,7 @@ fn filter_nodes<'q>( query: &'q DepGraphQuery, sources: &Option>, targets: &Option>, -) -> FxHashSet<&'q DepNode> { +) -> FxHashSet { if let Some(sources) = sources { if let Some(targets) = targets { walk_between(query, sources, targets) @@ -333,7 +333,7 @@ fn filter_nodes<'q>( } else if let Some(targets) = targets { walk_nodes(query, targets, INCOMING) } else { - query.nodes().into_iter().collect() + query.nodes().into_iter().map(|n| n.kind).collect() } } @@ -341,17 +341,17 @@ fn walk_nodes<'q>( query: &'q DepGraphQuery, starts: &FxHashSet<&'q DepNode>, direction: Direction, -) -> FxHashSet<&'q DepNode> { +) -> FxHashSet { let mut set = FxHashSet::default(); for &start in starts { debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING); - if set.insert(start) { + if set.insert(start.kind) { let mut stack = vec![query.indices[start]]; while let Some(index) = stack.pop() { for (_, edge) in query.graph.adjacent_edges(index, direction) { let neighbor_index = edge.source_or_target(direction); let neighbor = query.graph.node_data(neighbor_index); - if set.insert(neighbor) { + if set.insert(neighbor.kind) { stack.push(neighbor_index); } } @@ -365,7 +365,7 @@ fn walk_between<'q>( query: &'q DepGraphQuery, sources: &FxHashSet<&'q DepNode>, targets: &FxHashSet<&'q DepNode>, -) -> FxHashSet<&'q DepNode> { +) -> FxHashSet { // This is a bit tricky. We want to include a node only if it is: // (a) reachable from a source and (b) will reach a target. And we // have to be careful about cycles etc. Luckily efficiency is not @@ -396,6 +396,7 @@ fn walk_between<'q>( let index = query.indices[n]; node_states[index.0] == State::Included }) + .map(|n| n.kind) .collect(); fn recurse(query: &DepGraphQuery, node_states: &mut [State], node: NodeIndex) -> bool { @@ -433,11 +434,13 @@ fn walk_between<'q>( fn filter_edges<'q>( query: &'q DepGraphQuery, - nodes: &FxHashSet<&'q DepNode>, -) -> Vec<(&'q DepNode, &'q DepNode)> { - query + nodes: &FxHashSet, +) -> Vec<(DepKind, DepKind)> { + let uniq: FxHashSet<_> = query .edges() .into_iter() - .filter(|&(source, target)| nodes.contains(source) && nodes.contains(target)) - .collect() + .map(|(s, t)| (s.kind, t.kind)) + .filter(|(source, target)| nodes.contains(source) && nodes.contains(target)) + .collect(); + uniq.into_iter().collect() } From 5078b053b5e011b1ab706cbf37d2d576c2b7f83a Mon Sep 17 00:00:00 2001 From: Takayuki Maeda <41065217+TaKO8Ki@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:16:56 +0900 Subject: [PATCH 2/6] remove an unnecessary format arg --- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 9e5fb674772d5..5de6adcfc79eb 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1484,7 +1484,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.span_suggestion_hidden( return_span, "use `.collect()` to allocate the iterator", - format!("{}{}", snippet, ".collect::>()"), + format!("{snippet}.collect::>()"), Applicability::MaybeIncorrect, ); } From be4b72f8810268c2748aeb1e547674770f8d26dc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 20 Apr 2022 07:04:50 -0700 Subject: [PATCH 3/6] Update books --- src/doc/book | 2 +- src/doc/embedded-book | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index 765318b844569..de0dbffc5812f 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 765318b844569a642ceef7bf1adab9639cbf6af3 +Subproject commit de0dbffc5812fd885700874e8d258dd334733ac4 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index a6de8b6e3ea5d..f7cefbb995eec 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit a6de8b6e3ea5d4f0de8b7b9a7e5c1405dc2c2ddb +Subproject commit f7cefbb995eec8c6148f213235e9e2e03268e775 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index c2a98d9fc5d29..44a80e8d8bfc5 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit c2a98d9fc5d29c481d42052fbeccfde15ed03116 +Subproject commit 44a80e8d8bfc5881c9bd69a2cb3a570776ee4181 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index eeb5a83c15b6a..043e60f4f1916 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit eeb5a83c15b6ae60df3e4f19207376b22c6fbc4c +Subproject commit 043e60f4f191651e9f8bf52fa32df14defbb23d9 From 437468daf7d3931ad69e619a1bc5d32134c4ce01 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 21 Apr 2022 04:03:13 +0100 Subject: [PATCH 4/6] typeck: remove unnecessary fluent attr Specifying "suggestion" as the attribute for the only suggestion is unnecessary, it's the default of the derive. Signed-off-by: David Wood --- compiler/rustc_typeck/src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 1088be5f56657..fc08171d2f4c2 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -134,7 +134,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> { #[primary_span] #[label] pub span: Span, - #[suggestion_verbose(message = "suggestion", code = "{ty}")] + #[suggestion_verbose(code = "{ty}")] pub opt_sugg: Option<(Span, Applicability)>, } From f79d5e9458cd889027e804b2d20e99f8c9d110a0 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 21 Apr 2022 04:22:18 +0100 Subject: [PATCH 5/6] macros: update doc comment for diagnostic derive The documentation comment for this derive is out-of-date, it should have been updated in #95512. Signed-off-by: David Wood --- .../rustc_macros/src/session_diagnostic.rs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs index 46f698f6f9b81..ff7506979fc34 100644 --- a/compiler/rustc_macros/src/session_diagnostic.rs +++ b/compiler/rustc_macros/src/session_diagnostic.rs @@ -16,20 +16,27 @@ use std::collections::{BTreeSet, HashMap}; /// # extern crate rust_middle; /// # use rustc_middle::ty::Ty; /// #[derive(SessionDiagnostic)] -/// #[error(code = "E0505", slug = "move-out-of-borrow-error")] +/// #[error(code = "E0505", slug = "borrowck-move-out-of-borrow")] /// pub struct MoveOutOfBorrowError<'tcx> { /// pub name: Ident, /// pub ty: Ty<'tcx>, /// #[primary_span] -/// #[label = "cannot move out of borrow"] +/// #[label] /// pub span: Span, -/// #[label = "`{ty}` first borrowed here"] -/// pub other_span: Span, -/// #[suggestion(message = "consider cloning here", code = "{name}.clone()")] -/// pub opt_sugg: Option<(Span, Applicability)> +/// #[label = "first-borrow-label"] +/// pub first_borrow_span: Span, +/// #[suggestion(code = "{name}.clone()")] +/// pub clone_sugg: Option<(Span, Applicability)> /// } /// ``` /// +/// ```fluent +/// move-out-of-borrow = cannot move out of {$name} because it is borrowed +/// .label = cannot move out of borrow +/// .first-borrow-label = `{$ty}` first borrowed here +/// .suggestion = consider cloning here +/// ``` +/// /// Then, later, to emit the error: /// /// ```ignore (pseudo-rust) @@ -37,10 +44,13 @@ use std::collections::{BTreeSet, HashMap}; /// expected, /// actual, /// span, -/// other_span, -/// opt_sugg: Some(suggestion, Applicability::MachineApplicable), +/// first_borrow_span, +/// clone_sugg: Some(suggestion, Applicability::MachineApplicable), /// }); /// ``` +/// +/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`: +/// pub fn session_diagnostic_derive(s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { // Names for the diagnostic we build and the session we build it from. let diag = format_ident!("diag"); From 8fa20e01a5f85e8152b1a771e06d743b4e3d0017 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Thu, 21 Apr 2022 16:46:03 +0100 Subject: [PATCH 6/6] Remove redundant `format!`s --- compiler/rustc_resolve/src/diagnostics.rs | 2 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_typeck/src/check/fn_ctxt/checks.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 899980a4c0887..9bbecf104e55e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1014,7 +1014,7 @@ impl<'a> Resolver<'a> { } ResolutionError::InvalidAsmSym => { let mut err = self.session.struct_span_err(span, "invalid `sym` operand"); - err.span_label(span, &format!("is a local variable")); + err.span_label(span, "is a local variable"); err.help("`sym` operands must refer to either a function or a static"); err } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 591bad70840a4..7635ad9bd87bf 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1696,7 +1696,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { "invalid lifetime parameter name: `{}`", param.ident, ) - .span_label(param.ident.span, format!("'static is a reserved lifetime name")) + .span_label(param.ident.span, "'static is a reserved lifetime name") .emit(); continue; } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 80f6190732ac2..616aa11f00a6b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -968,9 +968,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { SuggestionText::Remove(plural) => { Some(format!("remove the extra argument{}", if plural { "s" } else { "" })) } - SuggestionText::Swap => Some(format!("swap these arguments")), - SuggestionText::Reorder => Some(format!("reorder these arguments")), - SuggestionText::DidYouMean => Some(format!("did you mean")), + SuggestionText::Swap => Some("swap these arguments".to_string()), + SuggestionText::Reorder => Some("reorder these arguments".to_string()), + SuggestionText::DidYouMean => Some("did you mean".to_string()), }; if let Some(suggestion_text) = suggestion_text { let source_map = self.sess().source_map();