Repository navigation
Fetch a candidate's MIR with the provider that serves its body kind #4848
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
Merged
feliperodri
merged 2 commits into
model-checking:main
from
feliperodri:fix-4839-comptime-intrinsic-mir
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/script-based-pre/autoharness_comptime_intrinsic/check.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright Kani Contributors | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| kani autoharness -Z autoharness --only-codegen --output-format=terse comptime.rs |
45 changes: 45 additions & 0 deletions
45
tests/script-based-pre/autoharness_comptime_intrinsic/comptime.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| //! A `#[rustc_comptime]` function's body is a const context, which `optimized_mir` refuses to | ||
| //! serve while `is_mir_available` still reports `true`. The const-block precondition search added | ||
| //! in #4820 fetched it that way and aborted the whole run on any crate declaring one -- `core` | ||
| //! declares 27: https://github.com/model-checking/kani/issues/4839 | ||
| //! | ||
| //! rustc also rejects any call to a comptime function outside a const item, static or const | ||
| //! block, so autoharness skips all of them ("Can only be called at compile time") rather than | ||
| //! verifying a harness rustc would not accept. The three shapes below are the ones `core` has; | ||
| //! `guarded_const_fn` keeps the const-block precondition search covered. | ||
|
|
||
| #![feature(intrinsics, rustc_attrs)] | ||
|
|
||
| // Body-less, declared exactly as `core::intrinsics::size_of` is. | ||
| #[rustc_nounwind] | ||
| #[rustc_intrinsic] | ||
| #[rustc_comptime] | ||
| pub fn size_of<T>() -> usize; | ||
|
|
||
| // With a body, as `core::any::TypeId::trait_info_of` is. | ||
| #[rustc_comptime] | ||
| pub fn with_body(x: u32) -> u32 { | ||
| x + 1 | ||
| } | ||
|
|
||
| // With a body, and a const-block precondition on a const generic parameter. | ||
| #[rustc_comptime] | ||
| pub fn guarded<const N: usize>() -> usize { | ||
| const { assert!(N >= 4) }; | ||
| N | ||
| } | ||
|
|
||
| // A plain `const fn` with the same precondition: not a const *context*, so it is served by | ||
| // `optimized_mir`. Kept here so that a future change to how the body is fetched cannot lose the | ||
| // detection for the shape `core::escape` uses, which is why #4820 exists. | ||
| pub const fn guarded_const_fn<const N: usize>(x: u8) -> u8 { | ||
| const { assert!(N >= 4) }; | ||
| x | ||
| } | ||
|
|
||
| pub fn plain(x: u8) -> u8 { | ||
| x | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
tests/script-based-pre/autoharness_comptime_intrinsic/config.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright Kani Contributors | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| script: check.sh | ||
| expected: expected |
5 changes: 5 additions & 0 deletions
5
tests/script-based-pre/autoharness_comptime_intrinsic/expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| | comptime | plain | | ||
| | comptime | guarded | Can only be called at compile time | ||
| | comptime | guarded_const_fn | Generic Function: the function has a `const {}` block that may constrain its const generic parameter(s), and the value autoharness substitutes (2) is not guaranteed to satisfy it | | ||
| | comptime | size_of | Can only be called at compile time | ||
| | comptime | with_body | Can only be called at compile time |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.