@@ -43,7 +43,7 @@ use std::cell::RefCell;
43
43
use std:: cmp:: max;
44
44
use std:: marker:: PhantomData ;
45
45
use std:: sync:: Arc ;
46
- use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
46
+ use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
47
47
use std:: { iter, mem, u64} ;
48
48
49
49
use rustc_data_structures:: fingerprint:: { Fingerprint , PackedFingerprint } ;
@@ -544,7 +544,7 @@ struct LocalEncoderResult {
544
544
}
545
545
546
546
struct EncoderState < D : Deps > {
547
- next_node_index : AtomicU64 ,
547
+ next_node_index : AtomicU32 ,
548
548
previous : Arc < SerializedDepGraph > ,
549
549
file : Lock < Option < FileEncoder > > ,
550
550
local : WorkerLocal < RefCell < LocalEncoderState > > ,
@@ -556,7 +556,7 @@ impl<D: Deps> EncoderState<D> {
556
556
fn new ( encoder : FileEncoder , record_stats : bool , previous : Arc < SerializedDepGraph > ) -> Self {
557
557
Self {
558
558
previous,
559
- next_node_index : AtomicU64 :: new ( 0 ) ,
559
+ next_node_index : AtomicU32 :: new ( 0 ) ,
560
560
stats : record_stats. then ( || Lock :: new ( FxHashMap :: default ( ) ) ) ,
561
561
file : Lock :: new ( Some ( encoder) ) ,
562
562
local : WorkerLocal :: new ( |_| {
@@ -578,11 +578,10 @@ impl<D: Deps> EncoderState<D> {
578
578
if local. remaining_node_index == 0 {
579
579
const COUNT : u32 = 256 ;
580
580
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 ( ) ;
586
585
587
586
// Check that we'll stay within `u32`
588
587
local. next_node_index . checked_add ( COUNT ) . unwrap ( ) ;
@@ -714,7 +713,7 @@ impl<D: Deps> EncoderState<D> {
714
713
715
714
fn finish ( & self , profiler : & SelfProfilerRef , current : & CurrentDepGraph < D > ) -> FileEncodeResult {
716
715
// 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 ) ;
718
717
719
718
let results = broadcast ( |_| {
720
719
let mut local = self . local . borrow_mut ( ) ;
0 commit comments