Skip to content

Commit 99ea78b

Browse files
committed
Remove spurious comments about the need for quantifiers
None of the (three) cases where we previously claimed a need for quantifiers actually require them.
1 parent 9e522b6 commit 99ea78b

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,14 +3222,16 @@ pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
32223222
/// initialization state.
32233223
///
32243224
/// This is used for contracts only.
3225-
///
3226-
/// FIXME: Change this once we add support to quantifiers.
32273225
#[allow(dead_code)]
32283226
#[allow(unused_variables)]
32293227
fn check_copy_untyped<T>(src: *const T, dst: *mut T, count: usize) -> bool {
32303228
#[cfg(kani)]
32313229
if count > 0 {
3230+
// Inspect a non-deterministically chosen byte in the copy.
32323231
let byte = kani::any_where(|sz: &usize| *sz < size_of::<T>());
3232+
// Instead of checking each of the `count`-many copies, non-deterministically pick one of
3233+
// them and check it. Using quantifiers would not add value as we can rely on the solver to
3234+
// pick an uninitialized element if such an element exists.
32333235
let elem = kani::any_where(|val: &usize| *val < count);
32343236
let src_data = src as *const u8;
32353237
let dst_data = unsafe { dst.add(elem) } as *const u8;

library/core/src/ptr/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,9 +2242,8 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
22422242
}
22432243
22442244
// Checking if the answer should indeed be usize::MAX when a % stride != 0
2245-
// requires computing gcd(a, stride), which is too expensive without
2246-
// quantifiers (https://model-checking.github.io/kani/rfc/rfcs/0010-quantifiers.html).
2247-
// This should be updated once quantifiers are available.
2245+
// requires computing gcd(a, stride), which could be done using cttz as the implementation
2246+
// does.
22482247
if (a % stride != 0 && *result == usize::MAX) {
22492248
return true;
22502249
}
@@ -2275,12 +2274,8 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
22752274
/// Implementation of this function shall not panic. Ever.
22762275
#[safety::requires(m.is_power_of_two())]
22772276
#[safety::requires(x < m)]
2278-
// TODO: add ensures contract to check that the answer is indeed correct
2279-
// This will require quantifiers (https://model-checking.github.io/kani/rfc/rfcs/0010-quantifiers.html)
2280-
// so that we can add a precondition that gcd(x, m) = 1 like so:
2281-
// ∀d, d > 0 ∧ x % d = 0 ∧ m % d = 0 → d = 1
2282-
// With this precondition, we can then write this postcondition to check the correctness of the answer:
2283-
// #[safety::ensures(|result| wrapping_mul(*result, x) % m == 1)]
2277+
#[safety::requires(x % 2 != 0)]
2278+
#[safety::ensures(|result| wrapping_mul(*result, x) % m == 1)]
22842279
#[inline]
22852280
const unsafe fn mod_inv(x: usize, m: usize) -> usize {
22862281
/// Multiplicative modular inverse table modulo 2⁴ = 16.

library/core/src/ptr/non_null.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,9 @@ impl<T: PointeeSized> NonNull<T> {
14341434
if (align % stride == 0) && (self.pointer.addr() % stride != 0) {
14351435
return *result == usize::MAX;
14361436
}
1437-
// Checking if the answer should indeed be usize::MAX when align % stride != 0
1438-
// requires computing gcd(a, stride), which is too expensive without
1439-
// quantifiers (https://model-checking.github.io/kani/rfc/rfcs/0010-quantifiers.html).
1440-
// This should be updated once quantifiers are available.
1437+
// Checking if the answer should indeed be usize::MAX when a % stride != 0 requires
1438+
// computing gcd(align, stride), which could be done using cttz as the implementation of
1439+
// ptr::align_offset does.
14411440
if (align % stride != 0 && *result == usize::MAX) {
14421441
return true;
14431442
}

0 commit comments

Comments
 (0)