Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define different function for concrete playback (no user impact) #2407

Merged
merged 5 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions library/kani/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ pub use futures::block_on;
/// ```
#[inline(never)]
#[rustc_diagnostic_item = "KaniAssume"]
pub fn assume(_cond: bool) {
if cfg!(feature = "concrete_playback") {
assert!(_cond, "kani::assume should always hold");
}
#[cfg(not(feature = "concrete_playback"))]
pub fn assume(cond: bool) {
let _ = cond;
}

#[inline(never)]
#[rustc_diagnostic_item = "KaniAssume"]
#[cfg(feature = "concrete_playback")]
pub fn assume(cond: bool) {
assert!(cond, "`kani::assume` should always hold");
}

/// Creates an assertion of the specified condition and message.
Expand All @@ -63,12 +69,19 @@ pub fn assume(_cond: bool) {
/// let y = !x;
/// kani::assert(x || y, "ORing a boolean variable with its negation must be true")
/// ```
#[cfg(not(feature = "concrete_playback"))]
#[inline(never)]
#[rustc_diagnostic_item = "KaniAssert"]
pub const fn assert(cond: bool, msg: &'static str) {
let _ = cond;
let _ = msg;
}

#[cfg(feature = "concrete_playback")]
#[inline(never)]
#[rustc_diagnostic_item = "KaniAssert"]
pub const fn assert(_cond: bool, _msg: &'static str) {
if cfg!(feature = "concrete_playback") {
assert!(_cond, "{}", _msg);
}
pub const fn assert(cond: bool, msg: &'static str) {
assert!(cond, "{}", msg);
}

/// Creates a cover property with the specified condition and message.
Expand Down Expand Up @@ -153,15 +166,17 @@ pub fn any_where<T: Arbitrary, F: FnOnce(&T) -> bool>(f: F) -> T {
///
/// Note that SIZE_T must be equal the size of type T in bytes.
#[inline(never)]
#[cfg(not(feature = "concrete_playback"))]
pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
#[cfg(feature = "concrete_playback")]
return concrete_playback::any_raw_internal::<T, SIZE_T>();

#[cfg(not(feature = "concrete_playback"))]
#[allow(unreachable_code)]
any_raw_inner::<T>()
}

#[inline(never)]
#[cfg(feature = "concrete_playback")]
pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
concrete_playback::any_raw_internal::<T, SIZE_T>()
}

/// This low-level function returns nondet bytes of size T.
#[rustc_diagnostic_item = "KaniAnyRaw"]
#[inline(never)]
Expand Down