@@ -13,10 +13,9 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
13
13
StableHashingContextProvider } ;
14
14
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
15
15
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
16
- use std :: cell :: { Ref , RefCell } ;
16
+ use rustc_data_structures :: sync :: { Lrc , RwLock , ReadGuard , Lock } ;
17
17
use std:: env;
18
18
use std:: hash:: Hash ;
19
- use std:: rc:: Rc ;
20
19
use ty:: TyCtxt ;
21
20
use util:: common:: { ProfileQueriesMsg , profq_msg} ;
22
21
@@ -32,7 +31,7 @@ use super::prev::PreviousDepGraph;
32
31
33
32
#[ derive( Clone ) ]
34
33
pub struct DepGraph {
35
- data : Option < Rc < DepGraphData > > ,
34
+ data : Option < Lrc < DepGraphData > > ,
36
35
37
36
// At the moment we are using DepNode as key here. In the future it might
38
37
// be possible to use an IndexVec<DepNodeIndex, _> here. At the moment there
@@ -41,7 +40,7 @@ pub struct DepGraph {
41
40
// we need to have a dep-graph to generate DepNodeIndices.
42
41
// - The architecture is still in flux and it's not clear what how to best
43
42
// implement things.
44
- fingerprints : Rc < RefCell < FxHashMap < DepNode , Fingerprint > > >
43
+ fingerprints : Lrc < Lock < FxHashMap < DepNode , Fingerprint > > >
45
44
}
46
45
47
46
@@ -71,50 +70,50 @@ struct DepGraphData {
71
70
/// tracking. The `current` field is the dependency graph of only the
72
71
/// current compilation session: We don't merge the previous dep-graph into
73
72
/// current one anymore.
74
- current : RefCell < CurrentDepGraph > ,
73
+ current : Lock < CurrentDepGraph > ,
75
74
76
75
/// The dep-graph from the previous compilation session. It contains all
77
76
/// nodes and edges as well as all fingerprints of nodes that have them.
78
77
previous : PreviousDepGraph ,
79
78
80
- colors : RefCell < FxHashMap < DepNode , DepNodeColor > > ,
79
+ colors : Lock < FxHashMap < DepNode , DepNodeColor > > ,
81
80
82
81
/// When we load, there may be `.o` files, cached mir, or other such
83
82
/// things available to us. If we find that they are not dirty, we
84
83
/// load the path to the file storing those work-products here into
85
84
/// this map. We can later look for and extract that data.
86
- previous_work_products : RefCell < FxHashMap < WorkProductId , WorkProduct > > ,
85
+ previous_work_products : RwLock < FxHashMap < WorkProductId , WorkProduct > > ,
87
86
88
87
/// Work-products that we generate in this run.
89
- work_products : RefCell < FxHashMap < WorkProductId , WorkProduct > > ,
88
+ work_products : RwLock < FxHashMap < WorkProductId , WorkProduct > > ,
90
89
91
- dep_node_debug : RefCell < FxHashMap < DepNode , String > > ,
90
+ dep_node_debug : Lock < FxHashMap < DepNode , String > > ,
92
91
93
92
// Used for testing, only populated when -Zquery-dep-graph is specified.
94
- loaded_from_cache : RefCell < FxHashMap < DepNodeIndex , bool > > ,
93
+ loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
95
94
}
96
95
97
96
impl DepGraph {
98
97
99
98
pub fn new ( prev_graph : PreviousDepGraph ) -> DepGraph {
100
99
DepGraph {
101
- data : Some ( Rc :: new ( DepGraphData {
102
- previous_work_products : RefCell :: new ( FxHashMap ( ) ) ,
103
- work_products : RefCell :: new ( FxHashMap ( ) ) ,
104
- dep_node_debug : RefCell :: new ( FxHashMap ( ) ) ,
105
- current : RefCell :: new ( CurrentDepGraph :: new ( ) ) ,
100
+ data : Some ( Lrc :: new ( DepGraphData {
101
+ previous_work_products : RwLock :: new ( FxHashMap ( ) ) ,
102
+ work_products : RwLock :: new ( FxHashMap ( ) ) ,
103
+ dep_node_debug : Lock :: new ( FxHashMap ( ) ) ,
104
+ current : Lock :: new ( CurrentDepGraph :: new ( ) ) ,
106
105
previous : prev_graph,
107
- colors : RefCell :: new ( FxHashMap ( ) ) ,
108
- loaded_from_cache : RefCell :: new ( FxHashMap ( ) ) ,
106
+ colors : Lock :: new ( FxHashMap ( ) ) ,
107
+ loaded_from_cache : Lock :: new ( FxHashMap ( ) ) ,
109
108
} ) ) ,
110
- fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
109
+ fingerprints : Lrc :: new ( Lock :: new ( FxHashMap ( ) ) ) ,
111
110
}
112
111
}
113
112
114
113
pub fn new_disabled ( ) -> DepGraph {
115
114
DepGraph {
116
115
data : None ,
117
- fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
116
+ fingerprints : Lrc :: new ( Lock :: new ( FxHashMap ( ) ) ) ,
118
117
}
119
118
}
120
119
@@ -196,8 +195,8 @@ impl DepGraph {
196
195
cx : C ,
197
196
arg : A ,
198
197
task : fn ( C , A ) -> R ,
199
- push : fn ( & RefCell < CurrentDepGraph > , DepNode ) ,
200
- pop : fn ( & RefCell < CurrentDepGraph > , DepNode ) -> DepNodeIndex )
198
+ push : fn ( & Lock < CurrentDepGraph > , DepNode ) ,
199
+ pop : fn ( & Lock < CurrentDepGraph > , DepNode ) -> DepNodeIndex )
201
200
-> ( R , DepNodeIndex )
202
201
where C : DepGraphSafe + StableHashingContextProvider < ContextType =HCX > ,
203
202
R : HashStable < HCX > ,
@@ -384,13 +383,13 @@ impl DepGraph {
384
383
385
384
/// Access the map of work-products created during this run. Only
386
385
/// used during saving of the dep-graph.
387
- pub fn work_products ( & self ) -> Ref < FxHashMap < WorkProductId , WorkProduct > > {
386
+ pub fn work_products ( & self ) -> ReadGuard < FxHashMap < WorkProductId , WorkProduct > > {
388
387
self . data . as_ref ( ) . unwrap ( ) . work_products . borrow ( )
389
388
}
390
389
391
390
/// Access the map of work-products created during the cached run. Only
392
391
/// used during saving of the dep-graph.
393
- pub fn previous_work_products ( & self ) -> Ref < FxHashMap < WorkProductId , WorkProduct > > {
392
+ pub fn previous_work_products ( & self ) -> ReadGuard < FxHashMap < WorkProductId , WorkProduct > > {
394
393
self . data . as_ref ( ) . unwrap ( ) . previous_work_products . borrow ( )
395
394
}
396
395
0 commit comments