diff options
| author | Joshua Nelson <jnelson@cloudflare.com> | 2022-08-23 22:24:39 -0500 |
|---|---|---|
| committer | Joshua Nelson <jnelson@cloudflare.com> | 2022-09-01 18:42:30 -0500 |
| commit | 70f20ac40ea95f4bba330858750e81f4ab2b8b3a (patch) | |
| tree | ff3a0cab22264fe2b5e0002675961fa1e74388cf /compiler/rustc_query_impl | |
| parent | 375d78012f2e7bdeba942eeb2a85115d1b1a98cb (diff) | |
| download | rust-70f20ac40ea95f4bba330858750e81f4ab2b8b3a.tar.gz rust-70f20ac40ea95f4bba330858750e81f4ab2b8b3a.zip | |
Move `force_with_dep_node` outside the giant macro
Diffstat (limited to 'compiler/rustc_query_impl')
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index e0707eee8ba..7c6b898751a 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -10,10 +10,11 @@ use rustc_errors::{Diagnostic, Handler}; use rustc_middle::dep_graph::{self, DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex}; use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_query_system::dep_graph::HasDepContext; +use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext}; use rustc_query_system::ich::StableHashingContext; use rustc_query_system::query::{ - QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, + force_query, QueryContext, QueryDescription, QueryJobId, QueryMap, QuerySideEffects, + QueryStackFrame, }; use std::any::Any; use std::num::NonZeroU64; @@ -315,6 +316,27 @@ pub(crate) fn try_load_from_on_disk_cache<'tcx, K, V>( } } +pub(crate) fn force_from_dep_node<'tcx, Q>( + tcx: TyCtxt<'tcx>, + // dep_node: rustc_query_system::dep_graph::DepNode<CTX::DepKind>, + dep_node: DepNode, + recover: fn(TyCtxt<'tcx>, DepNode) -> Option<Q::Key>, +) -> bool +where + Q: QueryDescription<QueryCtxt<'tcx>>, + Q::Key: DepNodeParams<TyCtxt<'tcx>>, +{ + if let Some(key) = recover(tcx, dep_node) { + #[cfg(debug_assertions)] + let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered(); + let tcx = QueryCtxt::from_tcx(tcx); + force_query::<Q, _>(tcx, key, dep_node); + true + } else { + false + } +} + // NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros // invoked by `rustc_query_append`. macro_rules! define_queries { @@ -385,7 +407,7 @@ macro_rules! define_queries { use super::*; use rustc_middle::dep_graph::DepNode; use rustc_query_system::dep_graph::DepNodeParams; - use rustc_query_system::query::{force_query, QueryDescription}; + use rustc_query_system::query::QueryDescription; use rustc_query_system::dep_graph::FingerprintStyle; // We use this for most things when incr. comp. is turned off. @@ -462,23 +484,11 @@ macro_rules! define_queries { <<queries::$name<'_> as QueryConfig>::Key as DepNodeParams<TyCtxt<'_>>>::recover(tcx, &dep_node) } - fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool { - if let Some(key) = recover(tcx, dep_node) { - #[cfg(debug_assertions)] - let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered(); - let tcx = QueryCtxt::from_tcx(tcx); - force_query::<queries::$name<'_>, _>(tcx, key, dep_node); - true - } else { - false - } - } - DepKindStruct { is_anon, is_eval_always, fingerprint_style, - force_from_dep_node: Some(force_from_dep_node), + force_from_dep_node: Some(|tcx, dep_node| $crate::plumbing::force_from_dep_node::<queries::$name<'_>>(tcx, dep_node, recover)), try_load_from_on_disk_cache: Some(|tcx, key| $crate::plumbing::try_load_from_on_disk_cache(tcx, key, recover, queries::$name::cache_on_disk, TyCtxt::$name)), } })* |
