11//! Type context book-keeping.
22
33use crate :: arena:: Arena ;
4- use crate :: dep_graph:: DepGraph ;
4+ use crate :: dep_graph:: { DepGraph , DepNode } ;
55use crate :: hir:: place:: Place as HirPlace ;
66use crate :: ich:: { NodeIdHashingMode , StableHashingContext } ;
77use crate :: infer:: canonical:: { Canonical , CanonicalVarInfo , CanonicalVarInfos } ;
@@ -14,7 +14,7 @@ use crate::mir::interpret::{self, AllocId, Allocation, ConstValue, Scalar};
1414use crate :: mir:: { Body , Field , Local , Place , PlaceElem , ProjectionKind , Promoted } ;
1515use crate :: thir:: Thir ;
1616use crate :: traits;
17- use crate :: ty:: query:: { self , OnDiskCache , TyCtxtAt } ;
17+ use crate :: ty:: query:: { self , TyCtxtAt } ;
1818use crate :: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , Subst , SubstsRef , UserSubsts } ;
1919use crate :: ty:: TyKind :: * ;
2020use crate :: ty:: {
@@ -52,8 +52,8 @@ use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
5252use rustc_session:: lint:: { Level , Lint } ;
5353use rustc_session:: Limit ;
5454use rustc_session:: Session ;
55- use rustc_span:: def_id:: StableCrateId ;
56- use rustc_span:: source_map:: MultiSpan ;
55+ use rustc_span:: def_id:: { DefPathHash , StableCrateId } ;
56+ use rustc_span:: source_map:: { MultiSpan , SourceMap } ;
5757use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
5858use rustc_span:: { Span , DUMMY_SP } ;
5959use rustc_target:: abi:: { Layout , TargetDataLayout , VariantIdx } ;
@@ -71,6 +71,40 @@ use std::mem;
7171use std:: ops:: { Bound , Deref } ;
7272use std:: sync:: Arc ;
7373
74+ pub trait OnDiskCache < ' tcx > : rustc_data_structures:: sync:: Sync {
75+ /// Creates a new `OnDiskCache` instance from the serialized data in `data`.
76+ fn new ( sess : & ' tcx Session , data : Vec < u8 > , start_pos : usize ) -> Self
77+ where
78+ Self : Sized ;
79+
80+ fn new_empty ( source_map : & ' tcx SourceMap ) -> Self
81+ where
82+ Self : Sized ;
83+
84+ /// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
85+ /// session, if it still exists. This is used during incremental compilation to
86+ /// turn a deserialized `DefPathHash` into its current `DefId`.
87+ fn def_path_hash_to_def_id (
88+ & self ,
89+ tcx : TyCtxt < ' tcx > ,
90+ def_path_hash : DefPathHash ,
91+ ) -> Option < DefId > ;
92+
93+ /// If the given `dep_node`'s hash still exists in the current compilation,
94+ /// and its current `DefId` is foreign, calls `store_foreign_def_id` with it.
95+ ///
96+ /// Normally, `store_foreign_def_id_hash` can be called directly by
97+ /// the dependency graph when we construct a `DepNode`. However,
98+ /// when we re-use a deserialized `DepNode` from the previous compilation
99+ /// session, we only have the `DefPathHash` available. This method is used
100+ /// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
101+ /// out for usage in the next compilation session.
102+ fn register_reused_dep_node ( & self , tcx : TyCtxt < ' tcx > , dep_node : & DepNode ) ;
103+ fn store_foreign_def_id_hash ( & self , def_id : DefId , hash : DefPathHash ) ;
104+
105+ fn serialize ( & self , tcx : TyCtxt < ' tcx > , encoder : & mut FileEncoder ) -> FileEncodeResult ;
106+ }
107+
74108/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s
75109/// except through the error-reporting functions on a [`tcx`][TyCtxt].
76110#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
@@ -993,7 +1027,7 @@ pub struct GlobalCtxt<'tcx> {
9931027 /// Do not access this directly. It is only meant to be used by
9941028 /// `DepGraph::try_mark_green()` and the query infrastructure.
9951029 /// This is `None` if we are not incremental compilation mode
996- pub on_disk_cache : Option < OnDiskCache < ' tcx > > ,
1030+ pub on_disk_cache : Option < & ' tcx dyn OnDiskCache < ' tcx > > ,
9971031
9981032 pub queries : & ' tcx dyn query:: QueryEngine < ' tcx > ,
9991033 pub query_caches : query:: QueryCaches < ' tcx > ,
@@ -1141,7 +1175,7 @@ impl<'tcx> TyCtxt<'tcx> {
11411175 resolutions : ty:: ResolverOutputs ,
11421176 krate : & ' tcx hir:: Crate < ' tcx > ,
11431177 dep_graph : DepGraph ,
1144- on_disk_cache : Option < query :: OnDiskCache < ' tcx > > ,
1178+ on_disk_cache : Option < & ' tcx dyn OnDiskCache < ' tcx > > ,
11451179 queries : & ' tcx dyn query:: QueryEngine < ' tcx > ,
11461180 crate_name : & str ,
11471181 output_filenames : OutputFilenames ,
@@ -1308,10 +1342,16 @@ impl<'tcx> TyCtxt<'tcx> {
13081342 self . untracked_resolutions . cstore . encode_metadata ( self )
13091343 }
13101344
1311- // Note that this is *untracked* and should only be used within the query
1312- // system if the result is otherwise tracked through queries
1313- pub fn cstore_as_any ( self ) -> & ' tcx dyn Any {
1314- self . untracked_resolutions . cstore . as_any ( )
1345+ /// Note that this is *untracked* and should only be used within the query
1346+ /// system if the result is otherwise tracked through queries
1347+ pub fn cstore_untracked ( self ) -> & ' tcx ty:: CrateStoreDyn {
1348+ & * self . untracked_resolutions . cstore
1349+ }
1350+
1351+ /// Note that this is *untracked* and should only be used within the query
1352+ /// system if the result is otherwise tracked through queries
1353+ pub fn definitions_untracked ( self ) -> & ' tcx hir:: definitions:: Definitions {
1354+ & self . untracked_resolutions . definitions
13151355 }
13161356
13171357 #[ inline( always) ]
0 commit comments