Skip to content

Commit aeab281

Browse files
committed
Tweak index chunk allocation
1 parent c43a6f0 commit aeab281

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

compiler/rustc_query_system/src/dep_graph/serialized.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -572,14 +572,18 @@ impl<D: Deps> EncoderState<D> {
572572
#[inline]
573573
fn next_index(&self, local: &mut LocalEncoderState) -> DepNodeIndex {
574574
if local.remaining_node_index == 0 {
575-
let count = 256;
575+
const COUNT: u32 = 256;
576576

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.
579580
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();
581582

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;
583587
}
584588

585589
DepNodeIndex::from_u32(local.next_node_index)

0 commit comments

Comments
 (0)