-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Remove redundant fields from QueryStackFrame
#153907
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,14 @@ | ||
| use std::fmt::Debug; | ||
|
|
||
| use rustc_span::def_id::DefId; | ||
|
|
||
| use crate::dep_graph::DepKind; | ||
| use crate::queries::TaggedQueryKey; | ||
|
|
||
| /// Description of a frame in the query stack. | ||
| /// | ||
| /// This is mostly used in case of cycles for error reporting. | ||
| #[derive(Clone, Debug)] | ||
| pub struct QueryStackFrame<'tcx> { | ||
| /// The query and key of the query method call that this stack frame | ||
| /// corresponds to. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the frame is just a tagged key now, then the whole separate notion of "frame" no longer makes sense, and the structure can be removed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. And
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to leave the potential removal of QueryStackFrame to another PR, because it will have wider effects on other code, and because it's not yet clear to me that replacing |
||
| /// | ||
| /// Code that doesn't care about the specific key can still use this to | ||
| /// check which query it's for, or obtain the query's name. | ||
| pub tagged_key: TaggedQueryKey<'tcx>, | ||
| pub dep_kind: DepKind, | ||
| pub def_id: Option<DefId>, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| use std::io::Write; | ||
| use std::iter; | ||
| use std::ops::ControlFlow; | ||
| use std::sync::Arc; | ||
| use std::{iter, mem}; | ||
|
|
||
| use rustc_data_structures::fx::{FxHashMap, FxHashSet}; | ||
| use rustc_errors::{Diag, DiagCtxtHandle}; | ||
| use rustc_hir::def::DefKind; | ||
| use rustc_middle::queries::TaggedQueryKey; | ||
| use rustc_middle::query::{ | ||
| CycleError, QueryJob, QueryJobId, QueryLatch, QueryStackFrame, QueryWaiter, | ||
| }; | ||
|
|
@@ -88,8 +89,8 @@ pub(crate) fn find_cycle_in_stack<'tcx>( | |
| panic!("did not find a cycle") | ||
| } | ||
|
|
||
| /// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id` and returns | ||
| /// information about it. | ||
| /// Finds the query job closest to the root that is for the same query method as `id` | ||
| /// (but not necessarily the same query key), and returns information about it. | ||
| #[cold] | ||
| #[inline(never)] | ||
| pub(crate) fn find_dep_kind_root<'tcx>( | ||
|
|
@@ -99,12 +100,14 @@ pub(crate) fn find_dep_kind_root<'tcx>( | |
| ) -> (Span, String, usize) { | ||
| let mut depth = 1; | ||
| let mut info = &job_map.map[&id]; | ||
| let dep_kind = info.frame.dep_kind; | ||
| // Two query stack frames are for the same query method if they have the same | ||
| // `TaggedQueryKey` discriminant. | ||
| let expected_query = mem::discriminant::<TaggedQueryKey<'tcx>>(&info.frame.tagged_key); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's worth adding a method to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was doing that in an earlier draft, until I realised that there is no code that truly needs to obtain a DepKind from a TaggedQueryKey. So when I realised that this code could use I think both approaches are pretty close. If we had other call sites that really needed the DepKind, then I would probably not use |
||
| let mut last_info = info; | ||
|
|
||
| while let Some(id) = info.job.parent { | ||
| info = &job_map.map[&id]; | ||
| if info.frame.dep_kind == dep_kind { | ||
| if mem::discriminant(&info.frame.tagged_key) == expected_query { | ||
| depth += 1; | ||
| last_info = info; | ||
| } | ||
|
|
@@ -420,8 +423,8 @@ pub fn print_query_stack<'tcx>( | |
| if Some(count_printed) < limit_frames || limit_frames.is_none() { | ||
| // Only print to stderr as many stack frames as `num_frames` when present. | ||
| dcx.struct_failure_note(format!( | ||
| "#{} [{:?}] {}", | ||
| count_printed, query_info.frame.dep_kind, description | ||
| "#{count_printed} [{query_name}] {description}", | ||
| query_name = query_info.frame.tagged_key.query_name(), | ||
| )) | ||
| .with_span(query_info.job.span) | ||
| .emit(); | ||
|
|
@@ -431,8 +434,8 @@ pub fn print_query_stack<'tcx>( | |
| if let Some(ref mut file) = file { | ||
| let _ = writeln!( | ||
| file, | ||
| "#{} [{:?}] {}", | ||
| count_total, query_info.frame.dep_kind, description | ||
| "#{count_total} [{query_name}] {description}", | ||
| query_name = query_info.frame.tagged_key.query_name(), | ||
| ); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning to make
descriptionreturn a(name, description)pair to avoid more of these large matches.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, and in that case we could hoist the
tcx.sess.verbose_internals()check out of the macro-defined method, and let callers deal with it instead (probably via a helper method).That would let
print_query_stackavoid printing the query name twice when verbose-internals is enabled.