File tree 1 file changed +9
-5
lines changed
compiler/rustc_query_system/src/dep_graph
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -572,14 +572,18 @@ impl<D: Deps> EncoderState<D> {
572
572
#[ inline]
573
573
fn next_index ( & self , local : & mut LocalEncoderState ) -> DepNodeIndex {
574
574
if local. remaining_node_index == 0 {
575
- let count = 256 ;
575
+ const COUNT : u32 = 256 ;
576
576
577
- // We assume that there won't be enough active threads to overflow u64 from u32::MAX here.
578
- assert ! ( self . next_node_index. load( Ordering :: Relaxed ) <= u32 :: MAX as u64 ) ;
577
+ // We assume that there won't be enough active threads to overflow `u64` from `u32::MAX` here.
578
+ // This can exceed u32::MAX by at most `N` * `COUNT` where `N` is the thread pool count since
579
+ // `try_into().unwrap()` will make threads panic when `self.next_node_index` exceeds u32::MAX.
579
580
local. next_node_index =
580
- self . next_node_index . fetch_add ( count , Ordering :: Relaxed ) . try_into ( ) . unwrap ( ) ;
581
+ self . next_node_index . fetch_add ( COUNT as u64 , Ordering :: Relaxed ) . try_into ( ) . unwrap ( ) ;
581
582
582
- local. remaining_node_index = count as u32 ;
583
+ // Check that we'll stay within `u32`
584
+ local. next_node_index . checked_add ( COUNT ) . unwrap ( ) ;
585
+
586
+ local. remaining_node_index = COUNT ;
583
587
}
584
588
585
589
DepNodeIndex :: from_u32 ( local. next_node_index )
You can’t perform that action at this time.
0 commit comments