Skip to content

Commit ea6722a

Browse files
committed
chore: add SAFETY docs to unsafe blocks
1 parent 4e93eb9 commit ea6722a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/whir/src/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ fn prepare_evals_for_fft_unpacked<A: Copy + Send + Sync>(
144144
let block_index = i % dft_n_cols;
145145
let offset_in_block = i / dft_n_cols;
146146
let src_index = ((block_index << log_block_size) + offset_in_block) >> log_inv_rate;
147+
// SAFETY: src_index = ((block_index * block_size) + offset_in_block) >> log_inv_rate.
148+
// block_index < dft_n_cols = n_blocks (folding_factor power-of-2),
149+
// offset_in_block < block_size = full_len / n_blocks,
150+
// so the numerator < full_len, and right-shifting by log_inv_rate gives < evals.len().
147151
unsafe { *evals.get_unchecked(src_index) }
148152
})
149153
.collect()
@@ -171,10 +175,14 @@ fn prepare_evals_for_fft_packed_extension<EF: ExtensionField<PF<EF>>>(
171175
let src_index = ((block_index << log_block_size) + offset_in_block) >> log_inv_rate;
172176
let packed_src_index = src_index >> log_packing;
173177
let offset_in_packing = src_index & packing_mask;
178+
// SAFETY: src_index < evals.len() << log_packing (same argument as unpacked variant),
179+
// so packed_src_index = src_index >> log_packing < evals.len().
174180
let packed = unsafe { evals.get_unchecked(packed_src_index) };
175181
let unpacked: &[PFPacking<EF>] = packed.as_basis_coefficients_slice();
176182
EF::from_basis_coefficients_fn(|i| unsafe {
183+
// SAFETY: i < EF::D (extension degree), which equals unpacked.len() by construction.
177184
let u: &PFPacking<EF> = unpacked.get_unchecked(i);
185+
// SAFETY: offset_in_packing = src_index & packing_mask < packing width.
178186
*u.as_slice().get_unchecked(offset_in_packing)
179187
})
180188
})

0 commit comments

Comments
 (0)