8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use dep_graph:: { DepGraph , DepNode , DepTrackingMap , DepTrackingMapConfig } ;
11
+ use dep_graph:: { DepNode , DepTrackingMapConfig } ;
12
12
use hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , LOCAL_CRATE } ;
13
13
use hir:: def:: Def ;
14
14
use hir;
@@ -27,9 +27,11 @@ use ty::fast_reject::SimplifiedType;
27
27
use util:: nodemap:: { DefIdSet , NodeSet } ;
28
28
29
29
use rustc_data_structures:: indexed_vec:: IndexVec ;
30
+ use rustc_data_structures:: fx:: FxHashMap ;
30
31
use std:: cell:: { RefCell , RefMut } ;
31
32
use std:: fmt:: Debug ;
32
33
use std:: hash:: Hash ;
34
+ use std:: marker:: PhantomData ;
33
35
use std:: mem;
34
36
use std:: collections:: BTreeMap ;
35
37
use std:: ops:: Deref ;
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {
180
182
}
181
183
}
182
184
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
+
183
199
pub struct CycleError < ' a , ' tcx : ' a > {
184
200
span : Span ,
185
201
cycle : RefMut < ' a , [ ( Span , Query < ' tcx > ) ] > ,
@@ -463,13 +479,12 @@ macro_rules! define_maps {
463
479
}
464
480
465
481
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>>)
468
483
-> Self {
469
484
Maps {
470
485
providers,
471
486
query_stack: RefCell :: new( vec![ ] ) ,
472
- $( $name: RefCell :: new( DepTrackingMap :: new( dep_graph . clone ( ) ) ) ) ,*
487
+ $( $name: RefCell :: new( QueryMap :: new( ) ) ) ,*
473
488
}
474
489
}
475
490
}
@@ -521,7 +536,7 @@ macro_rules! define_maps {
521
536
key,
522
537
span) ;
523
538
524
- if let Some ( result) = tcx. maps. $name. borrow( ) . get( & key) {
539
+ if let Some ( result) = tcx. maps. $name. borrow( ) . map . get( & key) {
525
540
return Ok ( f( result) ) ;
526
541
}
527
542
@@ -539,21 +554,19 @@ macro_rules! define_maps {
539
554
provider( tcx. global_tcx( ) , key)
540
555
} ) ?;
541
556
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) ) )
543
558
}
544
559
545
560
pub fn try_get( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K)
546
561
-> 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) ) ;
547
566
Self :: try_get_with( tcx, span, key, Clone :: clone)
548
567
}
549
568
550
569
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( ) ;
557
570
match Self :: try_get_with( tcx, span, key, |_| ( ) ) {
558
571
Ok ( ( ) ) => { }
559
572
Err ( e) => tcx. report_cycle( e)
@@ -644,7 +657,7 @@ macro_rules! define_map_struct {
644
657
tcx: $tcx,
645
658
input: $input,
646
659
output: ( $( $output) *
647
- $( #[ $attr] ) * $( $pub) * $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>, )
660
+ $( #[ $attr] ) * $( $pub) * $name: RefCell <QueryMap <queries:: $name<$tcx>>>, )
648
661
}
649
662
} ;
650
663
0 commit comments