Skip to content

Commit 3897395

Browse files
committed
Move Query to rustc_query_system.
Rename it to QueryStackFrame and document a bit.
1 parent 0144d6a commit 3897395

File tree

6 files changed

+140
-138
lines changed

6 files changed

+140
-138
lines changed

compiler/rustc_query_impl/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern crate rustc_middle;
1717
extern crate tracing;
1818

1919
use rustc_data_structures::fingerprint::Fingerprint;
20-
use rustc_data_structures::fx::FxHashMap;
2120
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2221
use rustc_errors::{Diagnostic, Handler, Level};
2322
use rustc_hir::def_id::CrateNum;

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use super::{queries, Query};
5+
use super::queries;
66
use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeExt, DepNodeIndex, SerializedDepNodeIndex};
77
use rustc_middle::ty::query::on_disk_cache;
88
use rustc_middle::ty::tls::{self, ImplicitCtxt};
99
use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_query_system::dep_graph::HasDepContext;
11-
use rustc_query_system::query::{CycleError, QueryJobId, QueryJobInfo};
12-
use rustc_query_system::query::{QueryContext, QueryDescription};
11+
use rustc_query_system::query::{CycleError, QueryJobId};
12+
use rustc_query_system::query::{QueryContext, QueryDescription, QueryMap, QueryStackFrame};
1313

14-
use rustc_data_structures::fx::FxHashMap;
1514
use rustc_data_structures::sync::Lock;
1615
use rustc_data_structures::thin_vec::ThinVec;
1716
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder};
@@ -45,8 +44,6 @@ impl HasDepContext for QueryCtxt<'tcx> {
4544
}
4645

4746
impl QueryContext for QueryCtxt<'tcx> {
48-
type Query = Query;
49-
5047
fn def_path_str(&self, def_id: DefId) -> String {
5148
self.tcx.def_path_str(def_id)
5249
}
@@ -55,10 +52,7 @@ impl QueryContext for QueryCtxt<'tcx> {
5552
tls::with_related_context(**self, |icx| icx.query)
5653
}
5754

58-
fn try_collect_active_jobs(
59-
&self,
60-
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self::DepKind, Self::Query>>>
61-
{
55+
fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>> {
6256
self.queries.try_collect_active_jobs(**self)
6357
}
6458

@@ -185,11 +179,11 @@ impl<'tcx> QueryCtxt<'tcx> {
185179
#[cold]
186180
pub(super) fn report_cycle(
187181
self,
188-
CycleError { usage, cycle: stack }: CycleError<Query>,
182+
CycleError { usage, cycle: stack }: CycleError,
189183
) -> DiagnosticBuilder<'tcx> {
190184
assert!(!stack.is_empty());
191185

192-
let fix_span = |span: Span, query: &Query| {
186+
let fix_span = |span: Span, query: &QueryStackFrame| {
193187
self.sess.source_map().guess_head_span(query.default_span(span))
194188
};
195189

@@ -371,17 +365,12 @@ macro_rules! define_queries {
371365
input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
372366
}
373367

374-
#[derive(Clone, Debug)]
375-
pub struct Query {
376-
pub name: &'static str,
377-
hash: Fingerprint,
378-
description: String,
379-
span: Option<Span>,
380-
}
368+
mod make_query {
369+
use super::*;
381370

382-
impl Query {
371+
// Create an eponymous constructor for each query.
383372
$(#[allow(nonstandard_style)] $(#[$attr])*
384-
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> Self {
373+
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
385374
let kind = dep_graph::DepKind::$name;
386375
let name = stringify!($name);
387376
let description = ty::print::with_forced_impl_filename_line(
@@ -408,22 +397,8 @@ macro_rules! define_queries {
408397
hasher.finish()
409398
};
410399

411-
Self { name, description, span, hash }
400+
QueryStackFrame::new(name, description, span, hash)
412401
})*
413-
414-
// FIXME(eddyb) Get more valid `Span`s on queries.
415-
pub fn default_span(&self, span: Span) -> Span {
416-
if !span.is_dummy() {
417-
return span;
418-
}
419-
self.span.unwrap_or(span)
420-
}
421-
}
422-
423-
impl<'a> HashStable<StableHashingContext<'a>> for Query {
424-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
425-
self.hash.hash_stable(hcx, hasher)
426-
}
427402
}
428403

429404
#[allow(nonstandard_style)]
@@ -450,7 +425,7 @@ macro_rules! define_queries {
450425
type Cache = query_storage::$name<$tcx>;
451426

452427
#[inline(always)]
453-
fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, Query, Self::Key>
428+
fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, Self::Key>
454429
where QueryCtxt<$tcx>: 'a
455430
{
456431
&tcx.queries.$name
@@ -484,7 +459,7 @@ macro_rules! define_queries {
484459

485460
fn handle_cycle_error(
486461
tcx: QueryCtxt<'tcx>,
487-
error: CycleError<Query>
462+
error: CycleError,
488463
) -> Self::Value {
489464
handle_cycle_error!([$($modifiers)*][tcx, error])
490465
}
@@ -587,7 +562,6 @@ macro_rules! define_queries_struct {
587562

588563
$($(#[$attr])* $name: QueryState<
589564
crate::dep_graph::DepKind,
590-
Query,
591565
query_keys::$name<$tcx>,
592566
>,)*
593567
}
@@ -607,15 +581,15 @@ macro_rules! define_queries_struct {
607581
pub(crate) fn try_collect_active_jobs(
608582
&$tcx self,
609583
tcx: TyCtxt<$tcx>,
610-
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<crate::dep_graph::DepKind, Query>>> {
584+
) -> Option<QueryMap<crate::dep_graph::DepKind>> {
611585
let tcx = QueryCtxt { tcx, queries: self };
612-
let mut jobs = FxHashMap::default();
586+
let mut jobs = QueryMap::default();
613587

614588
$(
615589
self.$name.try_collect_active_jobs(
616590
tcx,
617591
dep_graph::DepKind::$name,
618-
Query::$name,
592+
make_query::$name,
619593
&mut jobs,
620594
)?;
621595
)*

compiler/rustc_query_system/src/query/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
2727
pub compute: fn(CTX, K) -> V,
2828

2929
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
30-
pub handle_cycle_error: fn(CTX, CycleError<CTX::Query>) -> V,
30+
pub handle_cycle_error: fn(CTX, CycleError) -> V,
3131
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
3232
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
3333
}
@@ -52,7 +52,7 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
5252
(self.hash_result)(hcx, value)
5353
}
5454

55-
pub(crate) fn handle_cycle_error(&self, tcx: CTX, error: CycleError<CTX::Query>) -> V {
55+
pub(crate) fn handle_cycle_error(&self, tcx: CTX, error: CycleError) -> V {
5656
(self.handle_cycle_error)(tcx, error)
5757
}
5858

@@ -73,7 +73,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
7373
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
7474

7575
// Don't use this method to access query results, instead use the methods on TyCtxt
76-
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX::DepKind, CTX::Query, Self::Key>
76+
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX::DepKind, Self::Key>
7777
where
7878
CTX: 'a;
7979

@@ -90,7 +90,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
9090
result: &Self::Value,
9191
) -> Option<Fingerprint>;
9292

93-
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX::Query>) -> Self::Value;
93+
fn handle_cycle_error(tcx: CTX, error: CycleError) -> Self::Value;
9494
}
9595

9696
pub trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {

0 commit comments

Comments
 (0)