Skip to content

Commit 6e39f24

Browse files
committed
Clarify how TreeNodeIndex could exhaust its u64 encoding and panic
1 parent cf6f16a commit 6e39f24

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

compiler/rustc_data_structures/src/tree_node_index.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ impl TreeNodeIndex {
7171
/// bitstring.
7272
pub fn branch(self, i: u64, n: u64) -> TreeNodeIndex {
7373
debug_assert!(i < n, "i = {i} should be less than n = {n}");
74-
// `branch_num != 0` per debug assertion above
74+
// `n != 0` per debug assertion above
7575
let bits = ceil_ilog2(n);
76-
7776
let trailing_zeros = self.0.trailing_zeros();
77+
78+
// For this panic to happen there has to be a recursive function that isn't a query and
79+
// uses par_join or par_slice recursively.
80+
// Each query starts with a fresh binary tree, so we can expect this to never happen.
81+
// That is unless someone writes 64 nested par_join calls or something equivalent.
7882
let allocated_shift = trailing_zeros.checked_sub(bits).expect(
7983
"TreeNodeIndex's free bits have been exhausted, make sure recursion is used carefully",
8084
);
85+
8186
// Using wrapping operations for optimization, as edge cases are unreachable:
8287
// - `trailing_zeros < 64` as we are guaranteed at least one bit is set
8388
// - `allocated_shift == trailing_zeros - bits <= trailing_zeros < 64`

0 commit comments

Comments
 (0)