Move OnDiskCache to rustc_query_impl.
This commit is contained in:
parent
68511b574f
commit
81241cbf3a
14 changed files with 226 additions and 197 deletions
|
@ -2,9 +2,8 @@
|
|||
//! generate the actual methods on tcx which find and execute the provider,
|
||||
//! manage the caches, and so forth.
|
||||
|
||||
use super::queries;
|
||||
use crate::{on_disk_cache, queries, Queries};
|
||||
use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
|
||||
use rustc_middle::ty::query::on_disk_cache;
|
||||
use rustc_middle::ty::tls::{self, ImplicitCtxt};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_query_system::dep_graph::HasDepContext;
|
||||
|
@ -12,14 +11,16 @@ use rustc_query_system::query::{QueryContext, QueryDescription, QueryJobId, Quer
|
|||
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_data_structures::thin_vec::ThinVec;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_errors::{Diagnostic, Handler};
|
||||
use rustc_serialize::opaque;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct QueryCtxt<'tcx> {
|
||||
pub tcx: TyCtxt<'tcx>,
|
||||
pub queries: &'tcx super::Queries<'tcx>,
|
||||
pub queries: &'tcx Queries<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
|
||||
|
@ -83,14 +84,15 @@ impl QueryContext for QueryCtxt<'tcx> {
|
|||
|
||||
// Interactions with on_disk_cache
|
||||
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
|
||||
self.on_disk_cache
|
||||
self.queries
|
||||
.on_disk_cache
|
||||
.as_ref()
|
||||
.map(|c| c.load_diagnostics(**self, prev_dep_node_index))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
|
||||
if let Some(c) = self.on_disk_cache.as_ref() {
|
||||
if let Some(c) = self.queries.on_disk_cache.as_ref() {
|
||||
c.store_diagnostics(dep_node_index, diagnostics)
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +102,7 @@ impl QueryContext for QueryCtxt<'tcx> {
|
|||
dep_node_index: DepNodeIndex,
|
||||
diagnostics: ThinVec<Diagnostic>,
|
||||
) {
|
||||
if let Some(c) = self.on_disk_cache.as_ref() {
|
||||
if let Some(c) = self.queries.on_disk_cache.as_ref() {
|
||||
c.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +139,22 @@ impl QueryContext for QueryCtxt<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> QueryCtxt<'tcx> {
|
||||
#[inline]
|
||||
pub fn from_tcx(tcx: TyCtxt<'tcx>) -> Self {
|
||||
let queries = tcx.queries.as_any();
|
||||
let queries = unsafe {
|
||||
let queries = std::mem::transmute::<&dyn Any, &dyn Any>(queries);
|
||||
let queries = queries.downcast_ref().unwrap();
|
||||
let queries = std::mem::transmute::<&Queries<'_>, &Queries<'_>>(queries);
|
||||
queries
|
||||
};
|
||||
QueryCtxt { tcx, queries }
|
||||
}
|
||||
|
||||
crate fn on_disk_cache(self) -> Option<&'tcx on_disk_cache::OnDiskCache<'tcx>> {
|
||||
self.queries.on_disk_cache.as_ref()
|
||||
}
|
||||
|
||||
pub(super) fn encode_query_results(
|
||||
self,
|
||||
encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>,
|
||||
|
@ -158,6 +176,15 @@ impl<'tcx> QueryCtxt<'tcx> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn try_print_query_stack(
|
||||
self,
|
||||
query: Option<QueryJobId<DepKind>>,
|
||||
handler: &Handler,
|
||||
num_frames: Option<usize>,
|
||||
) -> usize {
|
||||
rustc_query_system::query::print_query_stack(self, query, handler, num_frames)
|
||||
}
|
||||
}
|
||||
|
||||
/// This struct stores metadata about each Query.
|
||||
|
@ -462,6 +489,8 @@ macro_rules! define_queries_struct {
|
|||
local_providers: Box<Providers>,
|
||||
extern_providers: Box<Providers>,
|
||||
|
||||
pub on_disk_cache: Option<OnDiskCache<$tcx>>,
|
||||
|
||||
$($(#[$attr])* $name: QueryState<
|
||||
crate::dep_graph::DepKind,
|
||||
query_keys::$name<$tcx>,
|
||||
|
@ -472,10 +501,12 @@ macro_rules! define_queries_struct {
|
|||
pub fn new(
|
||||
local_providers: Providers,
|
||||
extern_providers: Providers,
|
||||
on_disk_cache: Option<OnDiskCache<$tcx>>,
|
||||
) -> Self {
|
||||
Queries {
|
||||
local_providers: Box::new(local_providers),
|
||||
extern_providers: Box::new(extern_providers),
|
||||
on_disk_cache,
|
||||
$($name: Default::default()),*
|
||||
}
|
||||
}
|
||||
|
@ -501,43 +532,22 @@ macro_rules! define_queries_struct {
|
|||
}
|
||||
|
||||
impl QueryEngine<'tcx> for Queries<'tcx> {
|
||||
fn as_any(&'tcx self) -> &'tcx dyn std::any::Any {
|
||||
let this = unsafe { std::mem::transmute::<&Queries<'_>, &Queries<'_>>(self) };
|
||||
this as _
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::Registry) {
|
||||
let tcx = QueryCtxt { tcx, queries: self };
|
||||
rustc_query_system::query::deadlock(tcx, registry)
|
||||
}
|
||||
|
||||
fn encode_query_results(
|
||||
&'tcx self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>,
|
||||
query_result_index: &mut on_disk_cache::EncodedQueryResultIndex,
|
||||
) -> opaque::FileEncodeResult {
|
||||
let tcx = QueryCtxt { tcx, queries: self };
|
||||
tcx.encode_query_results(encoder, query_result_index)
|
||||
}
|
||||
|
||||
fn exec_cache_promotions(&'tcx self, tcx: TyCtxt<'tcx>) {
|
||||
let tcx = QueryCtxt { tcx, queries: self };
|
||||
tcx.dep_graph.exec_cache_promotions(tcx)
|
||||
}
|
||||
|
||||
fn try_mark_green(&'tcx self, tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool {
|
||||
let qcx = QueryCtxt { tcx, queries: self };
|
||||
tcx.dep_graph.try_mark_green(qcx, dep_node).is_some()
|
||||
}
|
||||
|
||||
fn try_print_query_stack(
|
||||
&'tcx self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
query: Option<QueryJobId<dep_graph::DepKind>>,
|
||||
handler: &Handler,
|
||||
num_frames: Option<usize>,
|
||||
) -> usize {
|
||||
let qcx = QueryCtxt { tcx, queries: self };
|
||||
rustc_query_system::query::print_query_stack(qcx, query, handler, num_frames)
|
||||
}
|
||||
|
||||
$($(#[$attr])*
|
||||
#[inline(always)]
|
||||
fn $name(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue