1
1
//! Type context book-keeping.
2
2
3
3
use crate :: arena:: Arena ;
4
- use crate :: dep_graph:: DepGraph ;
4
+ use crate :: dep_graph:: { DepGraph , DepNode } ;
5
5
use crate :: hir:: place:: Place as HirPlace ;
6
6
use crate :: ich:: { NodeIdHashingMode , StableHashingContext } ;
7
7
use crate :: infer:: canonical:: { Canonical , CanonicalVarInfo , CanonicalVarInfos } ;
@@ -14,7 +14,7 @@ use crate::mir::interpret::{self, AllocId, Allocation, ConstValue, Scalar};
14
14
use crate :: mir:: { Body , Field , Local , Place , PlaceElem , ProjectionKind , Promoted } ;
15
15
use crate :: thir:: Thir ;
16
16
use crate :: traits;
17
- use crate :: ty:: query:: { self , OnDiskCache , TyCtxtAt } ;
17
+ use crate :: ty:: query:: { self , TyCtxtAt } ;
18
18
use crate :: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , Subst , SubstsRef , UserSubsts } ;
19
19
use crate :: ty:: TyKind :: * ;
20
20
use crate :: ty:: {
@@ -52,8 +52,8 @@ use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
52
52
use rustc_session:: lint:: { Level , Lint } ;
53
53
use rustc_session:: Limit ;
54
54
use 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 } ;
57
57
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
58
58
use rustc_span:: { Span , DUMMY_SP } ;
59
59
use rustc_target:: abi:: { Layout , TargetDataLayout , VariantIdx } ;
@@ -71,6 +71,40 @@ use std::mem;
71
71
use std:: ops:: { Bound , Deref } ;
72
72
use std:: sync:: Arc ;
73
73
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
+
74
108
/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s
75
109
/// except through the error-reporting functions on a [`tcx`][TyCtxt].
76
110
#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
@@ -993,7 +1027,7 @@ pub struct GlobalCtxt<'tcx> {
993
1027
/// Do not access this directly. It is only meant to be used by
994
1028
/// `DepGraph::try_mark_green()` and the query infrastructure.
995
1029
/// 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 > > ,
997
1031
998
1032
pub queries : & ' tcx dyn query:: QueryEngine < ' tcx > ,
999
1033
pub query_caches : query:: QueryCaches < ' tcx > ,
@@ -1141,7 +1175,7 @@ impl<'tcx> TyCtxt<'tcx> {
1141
1175
resolutions : ty:: ResolverOutputs ,
1142
1176
krate : & ' tcx hir:: Crate < ' tcx > ,
1143
1177
dep_graph : DepGraph ,
1144
- on_disk_cache : Option < query :: OnDiskCache < ' tcx > > ,
1178
+ on_disk_cache : Option < & ' tcx dyn OnDiskCache < ' tcx > > ,
1145
1179
queries : & ' tcx dyn query:: QueryEngine < ' tcx > ,
1146
1180
crate_name : & str ,
1147
1181
output_filenames : OutputFilenames ,
@@ -1308,10 +1342,16 @@ impl<'tcx> TyCtxt<'tcx> {
1308
1342
self . untracked_resolutions . cstore . encode_metadata ( self )
1309
1343
}
1310
1344
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
1315
1355
}
1316
1356
1317
1357
#[ inline( always) ]
0 commit comments