Skip to content

Commit 4faf701

Browse files
committed
Remove the QueryGetter trait.
1 parent 260cfab commit 4faf701

File tree

3 files changed

+74
-91
lines changed

3 files changed

+74
-91
lines changed

src/librustc/ty/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ macro_rules! define_queries_inner {
381381
$($(#[$attr])*
382382
#[inline(always)]
383383
pub fn $name(self, key: $K) {
384-
self.tcx.ensure_query::<queries::$name<'_>>(key)
384+
ensure_query::<queries::$name<'_>, _>(self.tcx, key)
385385
})*
386386
}
387387

@@ -459,7 +459,7 @@ macro_rules! define_queries_inner {
459459
$($(#[$attr])*
460460
#[inline(always)]
461461
pub fn $name(self, key: $K) -> $V {
462-
self.tcx.get_query::<queries::$name<'_>>(self.span, key)
462+
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key)
463463
})*
464464
}
465465

src/librustc_macros/src/query.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
489489
::rustc::dep_graph::DepKind::#name => {
490490
if <#arg as DepNodeParams<TyCtxt<'_>>>::CAN_RECONSTRUCT_QUERY_KEY {
491491
if let Some(key) = <#arg as DepNodeParams<TyCtxt<'_>>>::recover($tcx, $dep_node) {
492-
$tcx.force_query::<crate::ty::query::queries::#name<'_>>(
492+
force_query::<crate::ty::query::queries::#name<'_>, _>(
493+
$tcx,
493494
key,
494495
DUMMY_SP,
495496
*$dep_node

src/librustc_query_system/query/plumbing.rs

+70-88
Original file line numberDiff line numberDiff line change
@@ -606,105 +606,87 @@ where
606606
(result, dep_node_index)
607607
}
608608

609-
pub trait QueryGetter: QueryContext {
610-
fn get_query<Q: QueryDescription<Self>>(self, span: Span, key: Q::Key) -> Q::Value;
611-
612-
/// Ensure that either this query has all green inputs or been executed.
613-
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
614-
///
615-
/// This function is particularly useful when executing passes for their
616-
/// side-effects -- e.g., in order to report errors for erroneous programs.
617-
///
618-
/// Note: The optimization is only available during incr. comp.
619-
fn ensure_query<Q: QueryDescription<Self>>(self, key: Q::Key);
609+
#[inline(never)]
610+
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key) -> Q::Value
611+
where
612+
Q: QueryDescription<CTX>,
613+
CTX: QueryContext,
614+
{
615+
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
620616

621-
fn force_query<Q: QueryDescription<Self>>(
622-
self,
623-
key: Q::Key,
624-
span: Span,
625-
dep_node: DepNode<Self::DepKind>,
626-
);
617+
try_get_cached(
618+
tcx,
619+
Q::query_state(tcx),
620+
key,
621+
|value, index| {
622+
tcx.dep_graph().read_index(index);
623+
value.clone()
624+
},
625+
|key, lookup| try_execute_query::<Q, _>(tcx, span, key, lookup),
626+
)
627627
}
628628

629-
impl<CTX> QueryGetter for CTX
629+
/// Ensure that either this query has all green inputs or been executed.
630+
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
631+
///
632+
/// This function is particularly useful when executing passes for their
633+
/// side-effects -- e.g., in order to report errors for erroneous programs.
634+
///
635+
/// Note: The optimization is only available during incr. comp.
636+
pub fn ensure_query<Q, CTX>(tcx: CTX, key: Q::Key)
630637
where
638+
Q: QueryDescription<CTX>,
631639
CTX: QueryContext,
632640
{
633-
#[inline(never)]
634-
fn get_query<Q: QueryDescription<Self>>(self, span: Span, key: Q::Key) -> Q::Value {
635-
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
636-
637-
try_get_cached(
638-
self,
639-
Q::query_state(self),
640-
key,
641-
|value, index| {
642-
self.dep_graph().read_index(index);
643-
value.clone()
644-
},
645-
|key, lookup| try_execute_query::<Q, _>(self, span, key, lookup),
646-
)
641+
if Q::EVAL_ALWAYS {
642+
let _ = get_query::<Q, _>(tcx, DUMMY_SP, key);
643+
return;
647644
}
648645

649-
/// Ensure that either this query has all green inputs or been executed.
650-
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
651-
///
652-
/// This function is particularly useful when executing passes for their
653-
/// side-effects -- e.g., in order to report errors for erroneous programs.
654-
///
655-
/// Note: The optimization is only available during incr. comp.
656-
fn ensure_query<Q: QueryDescription<Self>>(self, key: Q::Key) {
657-
if Q::EVAL_ALWAYS {
658-
let _ = self.get_query::<Q>(DUMMY_SP, key);
659-
return;
660-
}
646+
// Ensuring an anonymous query makes no sense
647+
assert!(!Q::ANON);
661648

662-
// Ensuring an anonymous query makes no sense
663-
assert!(!Q::ANON);
664-
665-
let dep_node = Q::to_dep_node(self, &key);
649+
let dep_node = Q::to_dep_node(tcx, &key);
666650

667-
match self.dep_graph().try_mark_green_and_read(self, &dep_node) {
668-
None => {
669-
// A None return from `try_mark_green_and_read` means that this is either
670-
// a new dep node or that the dep node has already been marked red.
671-
// Either way, we can't call `dep_graph.read()` as we don't have the
672-
// DepNodeIndex. We must invoke the query itself. The performance cost
673-
// this introduces should be negligible as we'll immediately hit the
674-
// in-memory cache, or another query down the line will.
675-
let _ = self.get_query::<Q>(DUMMY_SP, key);
676-
}
677-
Some((_, dep_node_index)) => {
678-
self.profiler().query_cache_hit(dep_node_index.into());
679-
}
651+
match tcx.dep_graph().try_mark_green_and_read(tcx, &dep_node) {
652+
None => {
653+
// A None return from `try_mark_green_and_read` means that this is either
654+
// a new dep node or that the dep node has already been marked red.
655+
// Either way, we can't call `dep_graph.read()` as we don't have the
656+
// DepNodeIndex. We must invoke the query itself. The performance cost
657+
// this introduces should be negligible as we'll immediately hit the
658+
// in-memory cache, or another query down the line will.
659+
let _ = get_query::<Q, _>(tcx, DUMMY_SP, key);
660+
}
661+
Some((_, dep_node_index)) => {
662+
tcx.profiler().query_cache_hit(dep_node_index.into());
680663
}
681664
}
665+
}
682666

683-
fn force_query<Q: QueryDescription<Self>>(
684-
self,
685-
key: Q::Key,
686-
span: Span,
687-
dep_node: DepNode<Self::DepKind>,
688-
) {
689-
// We may be concurrently trying both execute and force a query.
690-
// Ensure that only one of them runs the query.
691-
692-
try_get_cached(
693-
self,
694-
Q::query_state(self),
695-
key,
696-
|_, _| {
697-
// Cache hit, do nothing
698-
},
699-
|key, lookup| {
700-
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
701-
TryGetJob::NotYetStarted(job) => job,
702-
TryGetJob::Cycle(_) => return,
703-
#[cfg(parallel_compiler)]
704-
TryGetJob::JobCompleted(_) => return,
705-
};
706-
force_query_with_job::<Q, _>(self, key, job, dep_node);
707-
},
708-
);
709-
}
667+
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, span: Span, dep_node: DepNode<CTX::DepKind>)
668+
where
669+
Q: QueryDescription<CTX>,
670+
CTX: QueryContext,
671+
{
672+
// We may be concurrently trying both execute and force a query.
673+
// Ensure that only one of them runs the query.
674+
675+
try_get_cached(
676+
tcx,
677+
Q::query_state(tcx),
678+
key,
679+
|_, _| {
680+
// Cache hit, do nothing
681+
},
682+
|key, lookup| {
683+
let job = match JobOwner::try_start::<Q>(tcx, span, &key, lookup) {
684+
TryGetJob::NotYetStarted(job) => job,
685+
TryGetJob::Cycle(_) => return,
686+
#[cfg(parallel_compiler)]
687+
TryGetJob::JobCompleted(_) => return,
688+
};
689+
force_query_with_job::<Q, _>(tcx, key, job, dep_node);
690+
},
691+
);
710692
}

0 commit comments

Comments
 (0)