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

Eliminate a source of code bloat in the kani library #2033

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 17 additions & 9 deletions library/kani/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,7 @@ pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
#[inline(never)]
#[allow(dead_code)]
fn any_raw_inner<T>() -> T {
// while we could use `unreachable!()` or `panic!()` as the body of this
// function, both cause Kani to produce a warning on any program that uses
// kani::any() (see https://github.com/model-checking/kani/issues/2010).
// This function is handled via a hook anyway, so we just need to put a body
// that rustc does not complain about. An infinite loop works out nicely.
#[allow(clippy::empty_loop)]
loop {}
__kani_dummy_never()
}

/// Function used to generate panic with a static message as this is the only one currently
Expand All @@ -154,8 +148,22 @@ fn any_raw_inner<T>() -> T {
#[inline(never)]
#[rustc_diagnostic_item = "KaniPanic"]
#[doc(hidden)]
pub const fn panic(message: &'static str) -> ! {
panic!("{}", message)
pub const fn panic(_message: &'static str) -> ! {
__kani_dummy_never()
}

/// This is a dummy function that is intended to be called from functions with
/// `rustc_diagnostic_item`, i.e. that have kani hooks, to make sure they
/// compile.
/// While we could use `unreachable!()` or `panic!()` as the body of this
/// function, both cause Kani to produce a warning on missing `caller_location`
/// intrinsic (see https://github.com/model-checking/kani/issues/2010) and
/// produce unnecessarily large MIR. This function is handled via a hook
/// anyway, so we just need to put a body that rustc does not complain about. An
/// infinite loop works out nicely.
const fn __kani_dummy_never() -> ! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[doc(hidden)] for things we don't want customer-facing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for a private function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. Nevermind then :)

#[allow(clippy::empty_loop)]
loop {}
}

/// A macro to check if a condition is satisfiable at a specific location in the
Expand Down