@@ -14,9 +14,9 @@ use dep_graph::DepGraph;
1414use errors:: DiagnosticBuilder ;
1515use session:: Session ;
1616use middle;
17- use hir:: { TraitCandidate , HirId } ;
17+ use hir:: { TraitCandidate , HirId , ItemLocalId } ;
1818use hir:: def:: { Def , Export } ;
19- use hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
19+ use hir:: def_id:: { CrateNum , DefId , DefIndex , LOCAL_CRATE } ;
2020use hir:: map as hir_map;
2121use hir:: map:: DefPathHash ;
2222use lint:: { self , Lint } ;
@@ -817,10 +817,10 @@ pub struct GlobalCtxt<'tcx> {
817817
818818 /// Map indicating what traits are in scope for places where this
819819 /// is relevant; generated by resolve.
820- trait_map : FxHashMap < HirId , Rc < Vec < TraitCandidate > > > ,
820+ trait_map : FxHashMap < DefIndex , Rc < FxHashMap < ItemLocalId , Rc < Vec < TraitCandidate > > > > > ,
821821
822822 /// Export map produced by name resolution.
823- export_map : FxHashMap < HirId , Rc < Vec < Export > > > ,
823+ export_map : FxHashMap < DefId , Rc < Vec < Export > > > ,
824824
825825 named_region_map : NamedRegionMap ,
826826
@@ -837,11 +837,11 @@ pub struct GlobalCtxt<'tcx> {
837837 // Records the free variables refrenced by every closure
838838 // expression. Do not track deps for this, just recompute it from
839839 // scratch every time.
840- freevars : FxHashMap < HirId , Rc < Vec < hir:: Freevar > > > ,
840+ freevars : FxHashMap < DefId , Rc < Vec < hir:: Freevar > > > ,
841841
842- maybe_unused_trait_imports : FxHashSet < HirId > ,
842+ maybe_unused_trait_imports : FxHashSet < DefId > ,
843843
844- maybe_unused_extern_crates : Vec < ( HirId , Span ) > ,
844+ maybe_unused_extern_crates : Vec < ( DefId , Span ) > ,
845845
846846 // Internal cache for metadata decoding. No need to track deps on this.
847847 pub rcache : RefCell < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
@@ -1032,6 +1032,35 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10321032 None
10331033 } ;
10341034
1035+ let mut trait_map = FxHashMap ( ) ;
1036+ for ( k, v) in resolutions. trait_map {
1037+ let hir_id = hir. node_to_hir_id ( k) ;
1038+ let map = trait_map. entry ( hir_id. owner )
1039+ . or_insert_with ( || Rc :: new ( FxHashMap ( ) ) ) ;
1040+ Rc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , Rc :: new ( v) ) ;
1041+ }
1042+ let mut defs = FxHashMap ( ) ;
1043+ for ( k, v) in named_region_map. defs {
1044+ let hir_id = hir. node_to_hir_id ( k) ;
1045+ let map = defs. entry ( hir_id. owner )
1046+ . or_insert_with ( || Rc :: new ( FxHashMap ( ) ) ) ;
1047+ Rc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , v) ;
1048+ }
1049+ let mut late_bound = FxHashMap ( ) ;
1050+ for k in named_region_map. late_bound {
1051+ let hir_id = hir. node_to_hir_id ( k) ;
1052+ let map = late_bound. entry ( hir_id. owner )
1053+ . or_insert_with ( || Rc :: new ( FxHashSet ( ) ) ) ;
1054+ Rc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id ) ;
1055+ }
1056+ let mut object_lifetime_defaults = FxHashMap ( ) ;
1057+ for ( k, v) in named_region_map. object_lifetime_defaults {
1058+ let hir_id = hir. node_to_hir_id ( k) ;
1059+ let map = object_lifetime_defaults. entry ( hir_id. owner )
1060+ . or_insert_with ( || Rc :: new ( FxHashMap ( ) ) ) ;
1061+ Rc :: get_mut ( map) . unwrap ( ) . insert ( hir_id. local_id , Rc :: new ( v) ) ;
1062+ }
1063+
10351064 tls:: enter_global ( GlobalCtxt {
10361065 sess : s,
10371066 trans_trait_caches : traits:: trans:: TransTraitCaches :: new ( dep_graph. clone ( ) ) ,
@@ -1040,40 +1069,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10401069 dep_graph : dep_graph. clone ( ) ,
10411070 types : common_types,
10421071 named_region_map : NamedRegionMap {
1043- defs :
1044- named_region_map. defs
1045- . into_iter ( )
1046- . map ( |( k, v) | ( hir. node_to_hir_id ( k) , v) )
1047- . collect ( ) ,
1048- late_bound :
1049- named_region_map. late_bound
1050- . into_iter ( )
1051- . map ( |k| hir. node_to_hir_id ( k) )
1052- . collect ( ) ,
1053- object_lifetime_defaults :
1054- named_region_map. object_lifetime_defaults
1055- . into_iter ( )
1056- . map ( |( k, v) | ( hir. node_to_hir_id ( k) , Rc :: new ( v) ) )
1057- . collect ( ) ,
1072+ defs,
1073+ late_bound,
1074+ object_lifetime_defaults,
10581075 } ,
1059- trait_map : resolutions. trait_map . into_iter ( ) . map ( |( k, v) | {
1060- ( hir. node_to_hir_id ( k) , Rc :: new ( v) )
1061- } ) . collect ( ) ,
1076+ trait_map,
10621077 export_map : resolutions. export_map . into_iter ( ) . map ( |( k, v) | {
1063- ( hir . node_to_hir_id ( k ) , Rc :: new ( v) )
1078+ ( k , Rc :: new ( v) )
10641079 } ) . collect ( ) ,
10651080 freevars : resolutions. freevars . into_iter ( ) . map ( |( k, v) | {
1066- ( hir. node_to_hir_id ( k) , Rc :: new ( v) )
1081+ ( hir. local_def_id ( k) , Rc :: new ( v) )
10671082 } ) . collect ( ) ,
10681083 maybe_unused_trait_imports :
10691084 resolutions. maybe_unused_trait_imports
10701085 . into_iter ( )
1071- . map ( |id| hir. node_to_hir_id ( id) )
1086+ . map ( |id| hir. local_def_id ( id) )
10721087 . collect ( ) ,
10731088 maybe_unused_extern_crates :
10741089 resolutions. maybe_unused_extern_crates
10751090 . into_iter ( )
1076- . map ( |( id, sp) | ( hir. node_to_hir_id ( id) , sp) )
1091+ . map ( |( id, sp) | ( hir. local_def_id ( id) , sp) )
10771092 . collect ( ) ,
10781093 hir,
10791094 def_path_hash_to_def_id,
@@ -1967,6 +1982,29 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
19671982 let ( level, src) = self . lint_level_at_node ( lint, id) ;
19681983 lint:: struct_lint_level ( self . sess , lint, level, src, None , msg)
19691984 }
1985+
1986+ pub fn in_scope_traits ( self , id : HirId ) -> Option < Rc < Vec < TraitCandidate > > > {
1987+ self . in_scope_traits_map ( id. owner )
1988+ . and_then ( |map| map. get ( & id. local_id ) . cloned ( ) )
1989+ }
1990+
1991+ pub fn named_region ( self , id : HirId ) -> Option < resolve_lifetime:: Region > {
1992+ self . named_region_map ( id. owner )
1993+ . and_then ( |map| map. get ( & id. local_id ) . cloned ( ) )
1994+ }
1995+
1996+ pub fn is_late_bound ( self , id : HirId ) -> bool {
1997+ self . is_late_bound_map ( id. owner )
1998+ . map ( |set| set. contains ( & id. local_id ) )
1999+ . unwrap_or ( false )
2000+ }
2001+
2002+ pub fn object_lifetime_defaults ( self , id : HirId )
2003+ -> Option < Rc < Vec < ObjectLifetimeDefault > > >
2004+ {
2005+ self . object_lifetime_defaults_map ( id. owner )
2006+ . and_then ( |map| map. get ( & id. local_id ) . cloned ( ) )
2007+ }
19702008}
19712009
19722010pub trait InternAs < T : ?Sized , R > {
@@ -2014,20 +2052,24 @@ impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
20142052}
20152053
20162054struct NamedRegionMap {
2017- defs : FxHashMap < HirId , resolve_lifetime:: Region > ,
2018- late_bound : FxHashSet < HirId > ,
2019- object_lifetime_defaults : FxHashMap < HirId , Rc < Vec < ObjectLifetimeDefault > > > ,
2055+ defs : FxHashMap < DefIndex , Rc < FxHashMap < ItemLocalId , resolve_lifetime:: Region > > > ,
2056+ late_bound : FxHashMap < DefIndex , Rc < FxHashSet < ItemLocalId > > > ,
2057+ object_lifetime_defaults :
2058+ FxHashMap <
2059+ DefIndex ,
2060+ Rc < FxHashMap < ItemLocalId , Rc < Vec < ObjectLifetimeDefault > > > > ,
2061+ > ,
20202062}
20212063
20222064pub fn provide ( providers : & mut ty:: maps:: Providers ) {
20232065 // FIXME(#44234) - almost all of these queries have no sub-queries and
20242066 // therefore no actual inputs, they're just reading tables calculated in
20252067 // resolve! Does this work? Unsure! That's what the issue is about
2026- providers. in_scope_traits = |tcx, id| tcx. gcx . trait_map . get ( & id) . cloned ( ) ;
2068+ providers. in_scope_traits_map = |tcx, id| tcx. gcx . trait_map . get ( & id) . cloned ( ) ;
20272069 providers. module_exports = |tcx, id| tcx. gcx . export_map . get ( & id) . cloned ( ) ;
2028- providers. named_region = |tcx, id| tcx. gcx . named_region_map . defs . get ( & id) . cloned ( ) ;
2029- providers. is_late_bound = |tcx, id| tcx. gcx . named_region_map . late_bound . contains ( & id) ;
2030- providers. object_lifetime_defaults = |tcx, id| {
2070+ providers. named_region_map = |tcx, id| tcx. gcx . named_region_map . defs . get ( & id) . cloned ( ) ;
2071+ providers. is_late_bound_map = |tcx, id| tcx. gcx . named_region_map . late_bound . get ( & id) . cloned ( ) ;
2072+ providers. object_lifetime_defaults_map = |tcx, id| {
20312073 tcx. gcx . named_region_map . object_lifetime_defaults . get ( & id) . cloned ( )
20322074 } ;
20332075 providers. crate_name = |tcx, id| {
0 commit comments