@@ -49,7 +49,7 @@ use tracing::{debug, instrument};
4949
5050use crate :: arena:: Arena ;
5151use crate :: dep_graph:: dep_node:: make_metadata;
52- use crate :: dep_graph:: { DepGraph , DepKindVTable , DepNodeIndex } ;
52+ use crate :: dep_graph:: { DepGraph , DepNodeIndex } ;
5353use crate :: hir:: { ProjectedMaybeOwner , ProjectedOwnerInfo } ;
5454use crate :: ich:: StableHashState ;
5555use crate :: infer:: canonical:: { CanonicalParamEnvCache , CanonicalVarKind } ;
@@ -654,6 +654,38 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
654654 }
655655}
656656
657+ /// An assortment of global caches used by various parts of the compiler.
658+ ///
659+ /// The individual fields are mostly unrelated to each other, but have been grouped together to
660+ /// reduce the number of top-level fields in [`GlobalCtxt`].
661+ #[ derive( Default ) ]
662+ pub struct GlobalCaches < ' tcx > {
663+ // Internal caches for metadata decoding. No need to track deps on this.
664+ pub ty_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
665+
666+ /// Caches the results of trait selection. This cache is used
667+ /// for things that do not have to do with the parameters in scope.
668+ pub selection_cache : traits:: SelectionCache < ' tcx , ty:: TypingEnv < ' tcx > > ,
669+
670+ /// Caches the results of trait evaluation. This cache is used
671+ /// for things that do not have to do with the parameters in scope.
672+ /// Merge this with `selection_cache`?
673+ pub evaluation_cache : traits:: EvaluationCache < ' tcx , ty:: TypingEnv < ' tcx > > ,
674+
675+ /// Caches the results of goal evaluation in the new solver.
676+ new_solver_evaluation_cache : Lock < search_graph:: GlobalCache < TyCtxt < ' tcx > > > ,
677+ new_solver_canonical_param_env_cache : Lock < ty:: CanonicalParamEnvCache < TyCtxt < ' tcx > > > ,
678+
679+ pub canonical_param_env_cache : CanonicalParamEnvCache < ' tcx > ,
680+
681+ /// Caches the index of the highest bound var in clauses in a canonical binder.
682+ pub highest_var_in_clauses_cache : Lock < FxHashMap < ty:: Clauses < ' tcx > , usize > > ,
683+
684+ /// Caches the instantiation of a canonical binder given a set of args.
685+ pub clauses_cache :
686+ Lock < FxHashMap < ( ty:: Clauses < ' tcx > , & ' tcx [ ty:: GenericArg < ' tcx > ] ) , ty:: Clauses < ' tcx > > > ,
687+ }
688+
657689/// The central data structure of the compiler. It stores references
658690/// to the various **arenas** and also houses the results of the
659691/// various **compiler queries** that have been performed. See the
@@ -715,6 +747,8 @@ pub struct GlobalCtxt<'tcx> {
715747 pub incr_comp_session : Option < & ' tcx IncrCompSession > ,
716748 pub dep_graph : DepGraph ,
717749
750+ /// This duplicates `Session::prof` because this field is hot enough that accessing it via
751+ /// `self.sess.prof` is a measurable slowdown (see #161332).
718752 pub prof : SelfProfilerRef ,
719753
720754 /// Common types, pre-interned for your convenience.
@@ -733,31 +767,8 @@ pub struct GlobalCtxt<'tcx> {
733767 untracked : Untracked ,
734768
735769 pub query_system : QuerySystem < ' tcx > ,
736- pub ( crate ) dep_kind_vtables : & ' tcx [ DepKindVTable < ' tcx > ] ,
737-
738- // Internal caches for metadata decoding. No need to track deps on this.
739- pub ty_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
740-
741- /// Caches the results of trait selection. This cache is used
742- /// for things that do not have to do with the parameters in scope.
743- pub selection_cache : traits:: SelectionCache < ' tcx , ty:: TypingEnv < ' tcx > > ,
744770
745- /// Caches the results of trait evaluation. This cache is used
746- /// for things that do not have to do with the parameters in scope.
747- /// Merge this with `selection_cache`?
748- pub evaluation_cache : traits:: EvaluationCache < ' tcx , ty:: TypingEnv < ' tcx > > ,
749-
750- /// Caches the results of goal evaluation in the new solver.
751- pub new_solver_evaluation_cache : Lock < search_graph:: GlobalCache < TyCtxt < ' tcx > > > ,
752- pub new_solver_canonical_param_env_cache : Lock < ty:: CanonicalParamEnvCache < TyCtxt < ' tcx > > > ,
753-
754- pub canonical_param_env_cache : CanonicalParamEnvCache < ' tcx > ,
755-
756- /// Caches the index of the highest bound var in clauses in a canonical binder.
757- pub highest_var_in_clauses_cache : Lock < FxHashMap < ty:: Clauses < ' tcx > , usize > > ,
758- /// Caches the instantiation of a canonical binder given a set of args.
759- pub clauses_cache :
760- Lock < FxHashMap < ( ty:: Clauses < ' tcx > , & ' tcx [ ty:: GenericArg < ' tcx > ] ) , ty:: Clauses < ' tcx > > > ,
771+ pub caches : GlobalCaches < ' tcx > ,
761772
762773 /// Data layout specification for the current target.
763774 pub data_layout : TargetDataLayout ,
@@ -937,7 +948,6 @@ impl<'tcx> TyCtxt<'tcx> {
937948 untracked : Untracked ,
938949 incr_comp_session : Option < & ' tcx IncrCompSession > ,
939950 dep_graph : DepGraph ,
940- dep_kind_vtables : & ' tcx [ DepKindVTable < ' tcx > ] ,
941951 query_system : QuerySystem < ' tcx > ,
942952 hooks : crate :: hooks:: Providers ,
943953 current_gcx : CurrentGcx ,
@@ -967,15 +977,7 @@ impl<'tcx> TyCtxt<'tcx> {
967977 consts : common_consts,
968978 untracked,
969979 query_system,
970- dep_kind_vtables,
971- ty_rcache : Default :: default ( ) ,
972- selection_cache : Default :: default ( ) ,
973- evaluation_cache : Default :: default ( ) ,
974- new_solver_evaluation_cache : Default :: default ( ) ,
975- new_solver_canonical_param_env_cache : Default :: default ( ) ,
976- canonical_param_env_cache : Default :: default ( ) ,
977- highest_var_in_clauses_cache : Default :: default ( ) ,
978- clauses_cache : Default :: default ( ) ,
980+ caches : Default :: default ( ) ,
979981 data_layout,
980982 alloc_map : interpret:: AllocMap :: new ( ) ,
981983 current_gcx,
@@ -1612,7 +1614,7 @@ impl<'tcx> TyCtxt<'tcx> {
16121614 }
16131615
16141616 // Collect first to avoid holding the lock while linting.
1615- let used_features = self . sess . used_features . lock ( ) ;
1617+ let used_features = self . query_system . used_features . lock ( ) ;
16161618 let unused_features = self
16171619 . features ( )
16181620 . enabled_features_iter_stable_order ( )
0 commit comments