88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use dep_graph:: { DepGraph , DepNode , DepTrackingMap , DepTrackingMapConfig } ;
11+ use dep_graph:: { DepNode , DepTrackingMapConfig } ;
1212use hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , LOCAL_CRATE } ;
1313use hir:: def:: Def ;
1414use hir;
@@ -27,9 +27,11 @@ use ty::fast_reject::SimplifiedType;
2727use util:: nodemap:: { DefIdSet , NodeSet } ;
2828
2929use rustc_data_structures:: indexed_vec:: IndexVec ;
30+ use rustc_data_structures:: fx:: FxHashMap ;
3031use std:: cell:: { RefCell , RefMut } ;
3132use std:: fmt:: Debug ;
3233use std:: hash:: Hash ;
34+ use std:: marker:: PhantomData ;
3335use std:: mem;
3436use std:: collections:: BTreeMap ;
3537use std:: ops:: Deref ;
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {
180182 }
181183}
182184
185+ struct QueryMap < D : QueryDescription > {
186+ phantom : PhantomData < D > ,
187+ map : FxHashMap < D :: Key , D :: Value > ,
188+ }
189+
190+ impl < M : QueryDescription > QueryMap < M > {
191+ fn new ( ) -> QueryMap < M > {
192+ QueryMap {
193+ phantom : PhantomData ,
194+ map : FxHashMap ( ) ,
195+ }
196+ }
197+ }
198+
183199pub struct CycleError < ' a , ' tcx : ' a > {
184200 span : Span ,
185201 cycle : RefMut < ' a , [ ( Span , Query < ' tcx > ) ] > ,
@@ -463,13 +479,12 @@ macro_rules! define_maps {
463479 }
464480
465481 impl <$tcx> Maps <$tcx> {
466- pub fn new( dep_graph: DepGraph ,
467- providers: IndexVec <CrateNum , Providers <$tcx>>)
482+ pub fn new( providers: IndexVec <CrateNum , Providers <$tcx>>)
468483 -> Self {
469484 Maps {
470485 providers,
471486 query_stack: RefCell :: new( vec![ ] ) ,
472- $( $name: RefCell :: new( DepTrackingMap :: new( dep_graph . clone ( ) ) ) ) ,*
487+ $( $name: RefCell :: new( QueryMap :: new( ) ) ) ,*
473488 }
474489 }
475490 }
@@ -521,7 +536,7 @@ macro_rules! define_maps {
521536 key,
522537 span) ;
523538
524- if let Some ( result) = tcx. maps. $name. borrow( ) . get( & key) {
539+ if let Some ( result) = tcx. maps. $name. borrow( ) . map . get( & key) {
525540 return Ok ( f( result) ) ;
526541 }
527542
@@ -539,21 +554,19 @@ macro_rules! define_maps {
539554 provider( tcx. global_tcx( ) , key)
540555 } ) ?;
541556
542- Ok ( f( tcx. maps. $name. borrow_mut( ) . entry( key) . or_insert( result) ) )
557+ Ok ( f( tcx. maps. $name. borrow_mut( ) . map . entry( key) . or_insert( result) ) )
543558 }
544559
545560 pub fn try_get( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K)
546561 -> Result <$V, CycleError <' a, $tcx>> {
562+ // We register the `read` here, but not in `force`, since
563+ // `force` does not give access to the value produced (and thus
564+ // we actually don't read it).
565+ tcx. dep_graph. read( Self :: to_dep_node( & key) ) ;
547566 Self :: try_get_with( tcx, span, key, Clone :: clone)
548567 }
549568
550569 pub fn force( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K) {
551- // FIXME(eddyb) Move away from using `DepTrackingMap`
552- // so we don't have to explicitly ignore a false edge:
553- // we can't observe a value dependency, only side-effects,
554- // through `force`, and once everything has been updated,
555- // perhaps only diagnostics, if those, will remain.
556- let _ignore = tcx. dep_graph. in_ignore( ) ;
557570 match Self :: try_get_with( tcx, span, key, |_| ( ) ) {
558571 Ok ( ( ) ) => { }
559572 Err ( e) => tcx. report_cycle( e)
@@ -644,7 +657,7 @@ macro_rules! define_map_struct {
644657 tcx: $tcx,
645658 input: $input,
646659 output: ( $( $output) *
647- $( #[ $attr] ) * $( $pub) * $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>, )
660+ $( #[ $attr] ) * $( $pub) * $name: RefCell <QueryMap <queries:: $name<$tcx>>>, )
648661 }
649662 } ;
650663
0 commit comments