Skip to content

Commit

Permalink
Remove redundant Span in QueryJobInfo
Browse files Browse the repository at this point in the history
Previously, `QueryJobInfo` was composed of two parts: a `QueryInfo` and
a `QueryJob`. However, both `QueryInfo` and `QueryJob` have a `span`
field, which seem to be the same. So, the `span` was recorded twice.

Now, `QueryJobInfo` is composed of a `QueryStackFrame` (the other field
of `QueryInfo`) and a `QueryJob`. So, now, the `span` is only recorded
once.
  • Loading branch information
camelid committed Sep 1, 2021
1 parent ad3407f commit 4553a4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions compiler/rustc_query_system/src/query/job.rs
Expand Up @@ -61,7 +61,7 @@ where
}

fn query(self, map: &QueryMap<D>) -> QueryStackFrame {
map.get(&self).unwrap().info.query.clone()
map.get(&self).unwrap().query.clone()
}

#[cfg(parallel_compiler)]
Expand All @@ -81,7 +81,7 @@ where
}

pub struct QueryJobInfo<D> {
pub info: QueryInfo,
pub query: QueryStackFrame,
pub job: QueryJob<D>,
}

Expand Down Expand Up @@ -155,7 +155,7 @@ where

while let Some(job) = current_job {
let info = query_map.get(&job).unwrap();
cycle.push(info.info.clone());
cycle.push(QueryInfo { span: info.job.span, query: info.query.clone() });

if job == *self {
cycle.reverse();
Expand All @@ -170,7 +170,7 @@ where
.job
.parent
.as_ref()
.map(|parent| (info.info.span, parent.query(&query_map)));
.map(|parent| (info.job.span, parent.query(&query_map)));
return CycleError { usage, cycle };
}

Expand Down Expand Up @@ -649,13 +649,10 @@ pub fn print_query_stack<CTX: QueryContext>(
};
let mut diag = Diagnostic::new(
Level::FailureNote,
&format!(
"#{} [{}] {}",
i, query_info.info.query.name, query_info.info.query.description
),
&format!("#{} [{}] {}", i, query_info.query.name, query_info.query.description),
);
diag.span =
tcx.dep_context().sess().source_map().guess_head_span(query_info.info.span).into();
tcx.dep_context().sess().source_map().guess_head_span(query_info.job.span).into();
handler.force_print_diagnostic(diag);

current_query = query_info.job.parent;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_system/src/query/plumbing.rs
Expand Up @@ -130,8 +130,8 @@ where
for (k, v) in shard.active.iter() {
if let QueryResult::Started(ref job) = *v {
let id = QueryJobId::new(job.id, shard_id, kind);
let info = QueryInfo { span: job.span, query: make_query(tcx, k.clone()) };
jobs.insert(id, QueryJobInfo { info, job: job.clone() });
let query = make_query(tcx, k.clone());
jobs.insert(id, QueryJobInfo { query, job: job.clone() });
}
}
}
Expand Down

0 comments on commit 4553a4b

Please sign in to comment.