@@ -30,10 +30,12 @@ use middle::traits;
30
30
use middle:: ty:: { self , TraitRef , Ty , TypeAndMut } ;
31
31
use middle:: ty:: { TyS , TypeVariants } ;
32
32
use middle:: ty:: { AdtDef , ClosureSubsts , ExistentialBounds , Region } ;
33
- use middle:: ty:: { FreevarMap , GenericPredicates } ;
33
+ use middle:: ty:: { FreevarMap } ;
34
34
use middle:: ty:: { BareFnTy , InferTy , ParamTy , ProjectionTy , TraitTy } ;
35
35
use middle:: ty:: { TyVar , TyVid , IntVar , IntVid , FloatVar , FloatVid } ;
36
36
use middle:: ty:: TypeVariants :: * ;
37
+ use middle:: ty:: maps;
38
+ use util:: common:: MemoizationMap ;
37
39
use util:: nodemap:: { NodeMap , NodeSet , DefIdMap , DefIdSet } ;
38
40
use util:: nodemap:: FnvHashMap ;
39
41
@@ -248,57 +250,78 @@ pub struct ctxt<'tcx> {
248
250
pub tables : RefCell < Tables < ' tcx > > ,
249
251
250
252
/// Maps from a trait item to the trait item "descriptor"
251
- pub impl_or_trait_items : RefCell < DefIdMap < ty :: ImplOrTraitItem < ' tcx > > > ,
253
+ pub impl_or_trait_items : RefCell < DepTrackingMap < maps :: ImplOrTraitItems < ' tcx > > > ,
252
254
253
255
/// Maps from a trait def-id to a list of the def-ids of its trait items
254
- pub trait_item_def_ids : RefCell < DefIdMap < Rc < Vec < ty :: ImplOrTraitItemId > > > > ,
256
+ pub trait_item_def_ids : RefCell < DepTrackingMap < maps :: TraitItemDefIds < ' tcx > > > ,
255
257
256
- /// A cache for the trait_items() routine
257
- pub trait_items_cache : RefCell < DefIdMap < Rc < Vec < ty:: ImplOrTraitItem < ' tcx > > > > > ,
258
+ /// A cache for the trait_items() routine; note that the routine
259
+ /// itself pushes the `TraitItems` dependency node. This cache is
260
+ /// "encapsulated" and thus does not need to be itself tracked.
261
+ trait_items_cache : RefCell < DefIdMap < Rc < Vec < ty:: ImplOrTraitItem < ' tcx > > > > > ,
258
262
259
- pub impl_trait_refs : RefCell < DefIdMap < Option < TraitRef < ' tcx > > > > ,
260
- pub trait_defs : RefCell < DefIdMap < & ' tcx ty :: TraitDef < ' tcx > > > ,
261
- pub adt_defs : RefCell < DefIdMap < ty :: AdtDefMaster < ' tcx > > > ,
263
+ pub impl_trait_refs : RefCell < DepTrackingMap < maps :: ImplTraitRefs < ' tcx > > > ,
264
+ pub trait_defs : RefCell < DepTrackingMap < maps :: TraitDefs < ' tcx > > > ,
265
+ pub adt_defs : RefCell < DepTrackingMap < maps :: AdtDefs < ' tcx > > > ,
262
266
263
267
/// Maps from the def-id of an item (trait/struct/enum/fn) to its
264
268
/// associated predicates.
265
- pub predicates : RefCell < DefIdMap < GenericPredicates < ' tcx > > > ,
269
+ pub predicates : RefCell < DepTrackingMap < maps :: Predicates < ' tcx > > > ,
266
270
267
271
/// Maps from the def-id of a trait to the list of
268
272
/// super-predicates. This is a subset of the full list of
269
273
/// predicates. We store these in a separate map because we must
270
274
/// evaluate them even during type conversion, often before the
271
275
/// full predicates are available (note that supertraits have
272
276
/// additional acyclicity requirements).
273
- pub super_predicates : RefCell < DefIdMap < GenericPredicates < ' tcx > > > ,
277
+ pub super_predicates : RefCell < DepTrackingMap < maps :: Predicates < ' tcx > > > ,
274
278
275
279
pub map : ast_map:: Map < ' tcx > ,
280
+
281
+ // Records the free variables refrenced by every closure
282
+ // expression. Do not track deps for this, just recompute it from
283
+ // scratch every time.
276
284
pub freevars : RefCell < FreevarMap > ,
277
- pub tcache : RefCell < DefIdMap < ty:: TypeScheme < ' tcx > > > ,
285
+
286
+ // Records the type of every item.
287
+ pub tcache : RefCell < DepTrackingMap < maps:: Tcache < ' tcx > > > ,
288
+
289
+ // Internal cache for metadata decoding. No need to track deps on this.
278
290
pub rcache : RefCell < FnvHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
291
+
292
+ // Cache for the type-contents routine. FIXME -- track deps?
279
293
pub tc_cache : RefCell < FnvHashMap < Ty < ' tcx > , ty:: contents:: TypeContents > > ,
294
+
295
+ // Cache for various types within a method body and so forth.
296
+ //
297
+ // FIXME this should be made local to typeck, but it is currently used by one lint
280
298
pub ast_ty_to_ty_cache : RefCell < NodeMap < Ty < ' tcx > > > ,
299
+
300
+ // FIXME no dep tracking, but we should be able to remove this
281
301
pub ty_param_defs : RefCell < NodeMap < ty:: TypeParameterDef < ' tcx > > > ,
302
+
303
+ // FIXME dep tracking -- should be harmless enough
282
304
pub normalized_cache : RefCell < FnvHashMap < Ty < ' tcx > , Ty < ' tcx > > > ,
305
+
283
306
pub lang_items : middle:: lang_items:: LanguageItems ,
284
307
285
308
/// Maps from def-id of a type or region parameter to its
286
309
/// (inferred) variance.
287
- pub item_variance_map : RefCell < DefIdMap < Rc < ty :: ItemVariances > > > ,
310
+ pub item_variance_map : RefCell < DepTrackingMap < maps :: ItemVariances < ' tcx > > > ,
288
311
289
312
/// True if the variance has been computed yet; false otherwise.
290
313
pub variance_computed : Cell < bool > ,
291
314
292
315
/// Maps a DefId of a type to a list of its inherent impls.
293
316
/// Contains implementations of methods that are inherent to a type.
294
317
/// Methods in these implementations don't need to be exported.
295
- pub inherent_impls : RefCell < DefIdMap < Rc < Vec < DefId > > > > ,
318
+ pub inherent_impls : RefCell < DepTrackingMap < maps :: InherentImpls < ' tcx > > > ,
296
319
297
320
/// Maps a DefId of an impl to a list of its items.
298
321
/// Note that this contains all of the impls that we know about,
299
322
/// including ones in other crates. It's not clear that this is the best
300
323
/// way to do it.
301
- pub impl_items : RefCell < DefIdMap < Vec < ty :: ImplOrTraitItemId > > > ,
324
+ pub impl_items : RefCell < DepTrackingMap < maps :: ImplItems < ' tcx > > > ,
302
325
303
326
/// Set of used unsafe nodes (functions or blocks). Unsafe nodes not
304
327
/// present in this set can be warned about.
@@ -312,6 +335,7 @@ pub struct ctxt<'tcx> {
312
335
/// The set of external nominal types whose implementations have been read.
313
336
/// This is used for lazy resolution of methods.
314
337
pub populated_external_types : RefCell < DefIdSet > ,
338
+
315
339
/// The set of external primitive types whose implementations have been read.
316
340
/// FIXME(arielb1): why is this separate from populated_external_types?
317
341
pub populated_external_primitive_impls : RefCell < DefIdSet > ,
@@ -347,7 +371,9 @@ pub struct ctxt<'tcx> {
347
371
pub fulfilled_predicates : RefCell < traits:: FulfilledPredicates < ' tcx > > ,
348
372
349
373
/// Caches the representation hints for struct definitions.
350
- pub repr_hint_cache : RefCell < DefIdMap < Rc < Vec < attr:: ReprAttr > > > > ,
374
+ ///
375
+ /// This is encapsulated by the `ReprHints` task and hence is not tracked.
376
+ repr_hint_cache : RefCell < DefIdMap < Rc < Vec < attr:: ReprAttr > > > > ,
351
377
352
378
/// Maps Expr NodeId's to their constant qualification.
353
379
pub const_qualif_map : RefCell < NodeMap < middle:: check_const:: ConstQualif > > ,
@@ -499,31 +525,31 @@ impl<'tcx> ctxt<'tcx> {
499
525
named_region_map : named_region_map,
500
526
region_maps : region_maps,
501
527
free_region_maps : RefCell :: new ( FnvHashMap ( ) ) ,
502
- item_variance_map : RefCell :: new ( DefIdMap ( ) ) ,
528
+ item_variance_map : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
503
529
variance_computed : Cell :: new ( false ) ,
504
530
sess : s,
505
531
def_map : def_map,
506
532
tables : RefCell :: new ( Tables :: empty ( ) ) ,
507
- impl_trait_refs : RefCell :: new ( DefIdMap ( ) ) ,
508
- trait_defs : RefCell :: new ( DefIdMap ( ) ) ,
509
- adt_defs : RefCell :: new ( DefIdMap ( ) ) ,
510
- predicates : RefCell :: new ( DefIdMap ( ) ) ,
511
- super_predicates : RefCell :: new ( DefIdMap ( ) ) ,
533
+ impl_trait_refs : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
534
+ trait_defs : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
535
+ adt_defs : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
536
+ predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
537
+ super_predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
512
538
fulfilled_predicates : RefCell :: new ( traits:: FulfilledPredicates :: new ( ) ) ,
513
539
map : map,
514
540
freevars : RefCell :: new ( freevars) ,
515
- tcache : RefCell :: new ( DefIdMap ( ) ) ,
541
+ tcache : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
516
542
rcache : RefCell :: new ( FnvHashMap ( ) ) ,
517
543
tc_cache : RefCell :: new ( FnvHashMap ( ) ) ,
518
544
ast_ty_to_ty_cache : RefCell :: new ( NodeMap ( ) ) ,
519
- impl_or_trait_items : RefCell :: new ( DefIdMap ( ) ) ,
520
- trait_item_def_ids : RefCell :: new ( DefIdMap ( ) ) ,
545
+ impl_or_trait_items : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
546
+ trait_item_def_ids : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
521
547
trait_items_cache : RefCell :: new ( DefIdMap ( ) ) ,
522
548
ty_param_defs : RefCell :: new ( NodeMap ( ) ) ,
523
549
normalized_cache : RefCell :: new ( FnvHashMap ( ) ) ,
524
550
lang_items : lang_items,
525
- inherent_impls : RefCell :: new ( DefIdMap ( ) ) ,
526
- impl_items : RefCell :: new ( DefIdMap ( ) ) ,
551
+ inherent_impls : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
552
+ impl_items : RefCell :: new ( DepTrackingMap :: new ( dep_graph . clone ( ) ) ) ,
527
553
used_unsafe : RefCell :: new ( NodeSet ( ) ) ,
528
554
used_mut_nodes : RefCell :: new ( NodeSet ( ) ) ,
529
555
populated_external_types : RefCell :: new ( DefIdSet ( ) ) ,
@@ -1004,4 +1030,38 @@ impl<'tcx> ctxt<'tcx> {
1004
1030
pub fn mk_param_from_def ( & self , def : & ty:: TypeParameterDef ) -> Ty < ' tcx > {
1005
1031
self . mk_param ( def. space , def. index , def. name )
1006
1032
}
1033
+
1034
+ pub fn trait_items ( & self , trait_did : DefId ) -> Rc < Vec < ty:: ImplOrTraitItem < ' tcx > > > {
1035
+ // since this is cached, pushing a dep-node for the
1036
+ // computation yields the correct dependencies.
1037
+ let _task = self . dep_graph . in_task ( DepNode :: TraitItems ( trait_did) ) ;
1038
+
1039
+ let mut trait_items = self . trait_items_cache . borrow_mut ( ) ;
1040
+ match trait_items. get ( & trait_did) . cloned ( ) {
1041
+ Some ( trait_items) => trait_items,
1042
+ None => {
1043
+ let def_ids = self . trait_item_def_ids ( trait_did) ;
1044
+ let items: Rc < Vec < _ > > =
1045
+ Rc :: new ( def_ids. iter ( )
1046
+ . map ( |d| self . impl_or_trait_item ( d. def_id ( ) ) )
1047
+ . collect ( ) ) ;
1048
+ trait_items. insert ( trait_did, items. clone ( ) ) ;
1049
+ items
1050
+ }
1051
+ }
1052
+ }
1053
+
1054
+ /// Obtain the representation annotation for a struct definition.
1055
+ pub fn lookup_repr_hints ( & self , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
1056
+ let _task = self . dep_graph . in_task ( DepNode :: ReprHints ( did) ) ;
1057
+ self . repr_hint_cache . memoize ( did, || {
1058
+ Rc :: new ( if did. is_local ( ) {
1059
+ self . get_attrs ( did) . iter ( ) . flat_map ( |meta| {
1060
+ attr:: find_repr_attrs ( self . sess . diagnostic ( ) , meta) . into_iter ( )
1061
+ } ) . collect ( )
1062
+ } else {
1063
+ self . sess . cstore . repr_attrs ( did)
1064
+ } )
1065
+ } )
1066
+ }
1007
1067
}
0 commit comments