@@ -43,7 +43,7 @@ use std::cell::RefCell;
4343use std:: cmp:: max;
4444use std:: marker:: PhantomData ;
4545use std:: sync:: Arc ;
46- use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
46+ use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
4747use std:: { iter, mem, u64} ;
4848
4949use rustc_data_structures:: fingerprint:: { Fingerprint , PackedFingerprint } ;
@@ -544,7 +544,7 @@ struct LocalEncoderResult {
544544}
545545
546546struct EncoderState < D : Deps > {
547- next_node_index : AtomicU64 ,
547+ next_node_index : AtomicU32 ,
548548 previous : Arc < SerializedDepGraph > ,
549549 file : Lock < Option < FileEncoder > > ,
550550 local : WorkerLocal < RefCell < LocalEncoderState > > ,
@@ -556,7 +556,7 @@ impl<D: Deps> EncoderState<D> {
556556 fn new ( encoder : FileEncoder , record_stats : bool , previous : Arc < SerializedDepGraph > ) -> Self {
557557 Self {
558558 previous,
559- next_node_index : AtomicU64 :: new ( 0 ) ,
559+ next_node_index : AtomicU32 :: new ( 0 ) ,
560560 stats : record_stats. then ( || Lock :: new ( FxHashMap :: default ( ) ) ) ,
561561 file : Lock :: new ( Some ( encoder) ) ,
562562 local : WorkerLocal :: new ( |_| {
@@ -578,11 +578,10 @@ impl<D: Deps> EncoderState<D> {
578578 if local. remaining_node_index == 0 {
579579 const COUNT : u32 = 256 ;
580580
581- // We assume that there won't be enough active threads to overflow `u64` from `u32::MAX` here.
582- // This can exceed u32::MAX by at most `N` * `COUNT` where `N` is the thread pool count since
583- // `try_into().unwrap()` will make threads panic when `self.next_node_index` exceeds u32::MAX.
584- local. next_node_index =
585- self . next_node_index . fetch_add ( COUNT as u64 , Ordering :: Relaxed ) . try_into ( ) . unwrap ( ) ;
581+ local. next_node_index = self
582+ . next_node_index
583+ . fetch_update ( Ordering :: Relaxed , Ordering :: Relaxed , |v| v. checked_add ( COUNT ) )
584+ . unwrap ( ) ;
586585
587586 // Check that we'll stay within `u32`
588587 local. next_node_index . checked_add ( COUNT ) . unwrap ( ) ;
@@ -714,7 +713,7 @@ impl<D: Deps> EncoderState<D> {
714713
715714 fn finish ( & self , profiler : & SelfProfilerRef , current : & CurrentDepGraph < D > ) -> FileEncodeResult {
716715 // Prevent more indices from being allocated.
717- self . next_node_index . store ( u32:: MAX as u64 + 1 , Ordering :: SeqCst ) ;
716+ self . next_node_index . store ( u32:: MAX , Ordering :: SeqCst ) ;
718717
719718 let results = broadcast ( |_| {
720719 let mut local = self . local . borrow_mut ( ) ;
0 commit comments