1
Fork 0

Move OnDiskCache to rustc_query_impl.

This commit is contained in:
Camille GILLOT 2021-06-28 21:12:01 +02:00
parent 68511b574f
commit 81241cbf3a
14 changed files with 226 additions and 197 deletions

View file

@ -724,7 +724,7 @@ rustc_queries! {
cache_on_disk_if { true }
load_cached(tcx, id) {
let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
.on_disk_cache.as_ref()
.on_disk_cache().as_ref()
.and_then(|c| c.try_load_query_result(*tcx, id));
typeck_results.map(|x| &*tcx.arena.alloc(x))

View file

@ -1,7 +1,7 @@
//! Type context book-keeping.
use crate::arena::Arena;
use crate::dep_graph::DepGraph;
use crate::dep_graph::{DepGraph, DepNode};
use crate::hir::place::Place as HirPlace;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
@ -14,7 +14,7 @@ use crate::mir::interpret::{self, AllocId, Allocation, ConstValue, Scalar};
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
use crate::thir::Thir;
use crate::traits;
use crate::ty::query::{self, OnDiskCache, TyCtxtAt};
use crate::ty::query::{self, TyCtxtAt};
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
use crate::ty::TyKind::*;
use crate::ty::{
@ -52,8 +52,8 @@ use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
use rustc_session::lint::{Level, Lint};
use rustc_session::Limit;
use rustc_session::Session;
use rustc_span::def_id::StableCrateId;
use rustc_span::source_map::MultiSpan;
use rustc_span::def_id::{DefPathHash, StableCrateId};
use rustc_span::source_map::{MultiSpan, SourceMap};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
@ -71,6 +71,40 @@ use std::mem;
use std::ops::{Bound, Deref};
use std::sync::Arc;
pub trait OnDiskCache<'tcx> {
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
fn new(sess: &'tcx Session, data: Vec<u8>, start_pos: usize) -> Self
where
Self: Sized;
fn new_empty(source_map: &'tcx SourceMap) -> Self
where
Self: Sized;
/// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
/// session, if it still exists. This is used during incremental compilation to
/// turn a deserialized `DefPathHash` into its current `DefId`.
fn def_path_hash_to_def_id(
&self,
tcx: TyCtxt<'tcx>,
def_path_hash: DefPathHash,
) -> Option<DefId>;
/// If the given `dep_node`'s hash still exists in the current compilation,
/// and its current `DefId` is foreign, calls `store_foreign_def_id` with it.
///
/// Normally, `store_foreign_def_id_hash` can be called directly by
/// the dependency graph when we construct a `DepNode`. However,
/// when we re-use a deserialized `DepNode` from the previous compilation
/// session, we only have the `DefPathHash` available. This method is used
/// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
/// out for usage in the next compilation session.
fn register_reused_dep_node(&self, tcx: TyCtxt<'tcx>, dep_node: &DepNode);
fn store_foreign_def_id_hash(&self, def_id: DefId, hash: DefPathHash);
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;
}
/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s
/// except through the error-reporting functions on a [`tcx`][TyCtxt].
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
@ -993,7 +1027,7 @@ pub struct GlobalCtxt<'tcx> {
/// Do not access this directly. It is only meant to be used by
/// `DepGraph::try_mark_green()` and the query infrastructure.
/// This is `None` if we are not incremental compilation mode
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
pub on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
pub queries: &'tcx dyn query::QueryEngine<'tcx>,
pub query_caches: query::QueryCaches<'tcx>,
@ -1141,7 +1175,7 @@ impl<'tcx> TyCtxt<'tcx> {
resolutions: ty::ResolverOutputs,
krate: &'tcx hir::Crate<'tcx>,
dep_graph: DepGraph,
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
queries: &'tcx dyn query::QueryEngine<'tcx>,
crate_name: &str,
output_filenames: OutputFilenames,
@ -1308,10 +1342,16 @@ impl<'tcx> TyCtxt<'tcx> {
self.untracked_resolutions.cstore.encode_metadata(self)
}
// Note that this is *untracked* and should only be used within the query
// system if the result is otherwise tracked through queries
pub fn cstore_as_any(self) -> &'tcx dyn Any {
self.untracked_resolutions.cstore.as_any()
/// Note that this is *untracked* and should only be used within the query
/// system if the result is otherwise tracked through queries
pub fn cstore_untracked(self) -> &'tcx ty::CrateStoreDyn {
&*self.untracked_resolutions.cstore
}
/// Note that this is *untracked* and should only be used within the query
/// system if the result is otherwise tracked through queries
pub fn definitions_untracked(self) -> &'tcx hir::definitions::Definitions {
&self.untracked_resolutions.definitions
}
#[inline(always)]

View file

@ -59,7 +59,7 @@ pub use self::consts::{Const, ConstInt, ConstKind, InferConst, ScalarInt, Uneval
pub use self::context::{
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
CtxtInterners, DelaySpanBugEmitted, FreeRegionInfo, GeneratorInteriorTypeCause, GlobalCtxt,
Lift, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex,
Lift, OnDiskCache, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex,
};
pub use self::instance::{Instance, InstanceDef};
pub use self::list::List;

View file

@ -38,14 +38,13 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{ErrorReported, Handler};
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
use rustc_hir::lang_items::{LangItem, LanguageItems};
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
use rustc_serialize::opaque;
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
use rustc_session::utils::NativeLibKind;
use rustc_session::Limits;
@ -63,9 +62,6 @@ use std::sync::Arc;
pub(crate) use rustc_query_system::query::QueryJobId;
use rustc_query_system::query::*;
pub mod on_disk_cache;
pub use self::on_disk_cache::OnDiskCache;
#[derive(Copy, Clone)]
pub struct TyCtxtAt<'tcx> {
pub tcx: TyCtxt<'tcx>,
@ -235,28 +231,13 @@ macro_rules! define_callbacks {
}
pub trait QueryEngine<'tcx>: rustc_data_structures::sync::Sync {
fn as_any(&'tcx self) -> &'tcx dyn std::any::Any;
#[cfg(parallel_compiler)]
unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::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;
fn exec_cache_promotions(&'tcx self, tcx: TyCtxt<'tcx>);
fn try_mark_green(&'tcx self, tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool;
fn try_print_query_stack(
&'tcx self,
tcx: TyCtxt<'tcx>,
query: Option<QueryJobId<dep_graph::DepKind>>,
handler: &Handler,
num_frames: Option<usize>,
) -> usize;
$($(#[$attr])*
fn $name(
&'tcx self,

File diff suppressed because it is too large Load diff