@@ -13,10 +13,9 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1313 StableHashingContextProvider } ;
1414use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1515use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
16- use std :: cell :: { Ref , RefCell } ;
16+ use rustc_data_structures :: sync :: { Lrc , RwLock , ReadGuard , Lock } ;
1717use std:: env;
1818use std:: hash:: Hash ;
19- use std:: rc:: Rc ;
2019use ty:: TyCtxt ;
2120use util:: common:: { ProfileQueriesMsg , profq_msg} ;
2221
@@ -32,7 +31,7 @@ use super::prev::PreviousDepGraph;
3231
3332#[ derive( Clone ) ]
3433pub struct DepGraph {
35- data : Option < Rc < DepGraphData > > ,
34+ data : Option < Lrc < DepGraphData > > ,
3635
3736 // At the moment we are using DepNode as key here. In the future it might
3837 // be possible to use an IndexVec<DepNodeIndex, _> here. At the moment there
@@ -41,7 +40,7 @@ pub struct DepGraph {
4140 // we need to have a dep-graph to generate DepNodeIndices.
4241 // - The architecture is still in flux and it's not clear what how to best
4342 // implement things.
44- fingerprints : Rc < RefCell < FxHashMap < DepNode , Fingerprint > > >
43+ fingerprints : Lrc < Lock < FxHashMap < DepNode , Fingerprint > > >
4544}
4645
4746
@@ -71,50 +70,50 @@ struct DepGraphData {
7170 /// tracking. The `current` field is the dependency graph of only the
7271 /// current compilation session: We don't merge the previous dep-graph into
7372 /// current one anymore.
74- current : RefCell < CurrentDepGraph > ,
73+ current : Lock < CurrentDepGraph > ,
7574
7675 /// The dep-graph from the previous compilation session. It contains all
7776 /// nodes and edges as well as all fingerprints of nodes that have them.
7877 previous : PreviousDepGraph ,
7978
80- colors : RefCell < FxHashMap < DepNode , DepNodeColor > > ,
79+ colors : Lock < FxHashMap < DepNode , DepNodeColor > > ,
8180
8281 /// When we load, there may be `.o` files, cached mir, or other such
8382 /// things available to us. If we find that they are not dirty, we
8483 /// load the path to the file storing those work-products here into
8584 /// 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 > > ,
8786
8887 /// Work-products that we generate in this run.
89- work_products : RefCell < FxHashMap < WorkProductId , WorkProduct > > ,
88+ work_products : RwLock < FxHashMap < WorkProductId , WorkProduct > > ,
9089
91- dep_node_debug : RefCell < FxHashMap < DepNode , String > > ,
90+ dep_node_debug : Lock < FxHashMap < DepNode , String > > ,
9291
9392 // 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 > > ,
9594}
9695
9796impl DepGraph {
9897
9998 pub fn new ( prev_graph : PreviousDepGraph ) -> DepGraph {
10099 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 ( ) ) ,
106105 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 ( ) ) ,
109108 } ) ) ,
110- fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
109+ fingerprints : Lrc :: new ( Lock :: new ( FxHashMap ( ) ) ) ,
111110 }
112111 }
113112
114113 pub fn new_disabled ( ) -> DepGraph {
115114 DepGraph {
116115 data : None ,
117- fingerprints : Rc :: new ( RefCell :: new ( FxHashMap ( ) ) ) ,
116+ fingerprints : Lrc :: new ( Lock :: new ( FxHashMap ( ) ) ) ,
118117 }
119118 }
120119
@@ -196,8 +195,8 @@ impl DepGraph {
196195 cx : C ,
197196 arg : A ,
198197 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 )
201200 -> ( R , DepNodeIndex )
202201 where C : DepGraphSafe + StableHashingContextProvider < ContextType =HCX > ,
203202 R : HashStable < HCX > ,
@@ -384,13 +383,13 @@ impl DepGraph {
384383
385384 /// Access the map of work-products created during this run. Only
386385 /// 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 > > {
388387 self . data . as_ref ( ) . unwrap ( ) . work_products . borrow ( )
389388 }
390389
391390 /// Access the map of work-products created during the cached run. Only
392391 /// 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 > > {
394393 self . data . as_ref ( ) . unwrap ( ) . previous_work_products . borrow ( )
395394 }
396395
0 commit comments