@@ -2,7 +2,7 @@ use std::assert_matches;
22use std:: fmt:: Debug ;
33use std:: hash:: Hash ;
44use std:: sync:: Arc ;
5- use std:: sync:: atomic:: { AtomicBool , AtomicU32 , Ordering } ;
5+ use std:: sync:: atomic:: { AtomicPtr , AtomicU32 , Ordering } ;
66
77use rustc_data_structures:: fingerprint:: { Fingerprint , PackedFingerprint } ;
88use rustc_data_structures:: fx:: FxHashSet ;
@@ -54,8 +54,7 @@ pub enum QuerySideEffect {
5454
5555#[ derive( Clone ) ]
5656pub struct DepGraph {
57- is_in_sandbox : Arc < AtomicBool > ,
58- data : [ Option < Arc < DepGraphData > > ; 2 ] ,
57+ data : Arc < AtomicPtr < Option < DepGraphData > > > ,
5958
6059 /// This field is used for assigning DepNodeIndices when running in
6160 /// non-incremental mode. Even in non-incremental mode we make sure that
@@ -170,31 +169,26 @@ impl DepGraph {
170169 }
171170
172171 DepGraph {
173- data : [
174- Some ( Arc :: new ( DepGraphData {
175- previous_work_products : prev_work_products,
176- current,
177- previous : prev_graph,
178- colors,
179- debug_loaded_from_disk : Default :: default ( ) ,
180- } ) ) ,
181- None ,
182- ] ,
172+ data : Arc :: new ( AtomicPtr :: new ( Box :: into_raw ( Box :: new ( Some ( DepGraphData {
173+ previous_work_products : prev_work_products,
174+ current,
175+ previous : prev_graph,
176+ colors,
177+ debug_loaded_from_disk : Default :: default ( ) ,
178+ } ) ) ) ) ) ,
183179 virtual_dep_node_index : Arc :: new ( AtomicU32 :: new ( 0 ) ) ,
184- is_in_sandbox : Default :: default ( ) ,
185180 }
186181 }
187182
188183 pub fn new_disabled ( ) -> DepGraph {
189184 DepGraph {
190- data : [ None , None ] ,
185+ data : Arc :: new ( AtomicPtr :: new ( Box :: into_raw ( Box :: new ( None ) ) ) ) ,
191186 virtual_dep_node_index : Arc :: new ( AtomicU32 :: new ( 0 ) ) ,
192- is_in_sandbox : Default :: default ( ) ,
193187 }
194188 }
195189
196190 pub fn data ( & self ) -> Option < & DepGraphData > {
197- self . data [ self . is_in_sandbox . load ( Ordering :: Relaxed ) as usize ] . as_deref ( )
191+ unsafe { self . data . load ( Ordering :: Relaxed ) . as_ref_unchecked ( ) . as_ref ( ) }
198192 }
199193
200194 /// Returns `true` if we are actually building the full dep-graph, and `false` otherwise.
@@ -291,11 +285,12 @@ impl DepGraph {
291285
292286 pub fn with_sandbox ( & self , op : impl FnOnce ( ) ) {
293287 self . with_query_deserialization ( || {
294- self . is_in_sandbox . store ( true , Ordering :: Relaxed ) ;
288+ let real_graph = self . data . swap ( Box :: into_raw ( Box :: new ( None ) ) , Ordering :: Relaxed ) ;
295289
296290 op ( ) ;
297291
298- self . is_in_sandbox . store ( false , Ordering :: Relaxed ) ;
292+ let fake_graph = self . data . swap ( real_graph, Ordering :: Relaxed ) ;
293+ unsafe { drop ( Box :: from_raw ( fake_graph) ) } ;
299294 } ) ;
300295 }
301296
0 commit comments