Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ exclude = [
"tests/script-based-pre/build-cache-dirty/target/new_dep",
"tests/script-based-pre/verify_std_cmd/tmp_dir/target/kani_verify_std",
"tests/script-based-pre/kani_lib_dep",
"tests/script-based-pre/no_codegen",
"tests/script-based-pre/no_codegen_error",
]

[workspace.lints.clippy]
Expand Down
11 changes: 11 additions & 0 deletions kani-driver/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ pub struct VerificationArgs {
#[arg(long, hide_short_help = true)]
pub only_codegen: bool,

/// Run Kani without codegen. Useful for quick feedback on whether the code would compile successfully (similar to `cargo check`).
/// This feature is unstable and requires `-Z unstable-options` to be used
#[arg(long, hide_short_help = true)]
pub no_codegen: bool,

/// Specify the value used for loop unwinding in CBMC
#[arg(long)]
pub default_unwind: Option<u32>,
Expand Down Expand Up @@ -660,6 +665,12 @@ impl ValidateArgs for VerificationArgs {
UnstableFeature::UnstableOptions,
)?;

self.common_args.check_unstable(
self.no_codegen,
"--no-codegen",
UnstableFeature::UnstableOptions,
)?;

self.common_args.check_unstable(
self.jobs.is_some(),
"--jobs",
Expand Down
5 changes: 5 additions & 0 deletions kani-driver/src/call_single_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ impl KaniSession {
.map(OsString::from),
);

if self.args.no_codegen {
flags.push("-Z".into());
flags.push("no-codegen".into());
}

if let Some(seed_opt) = self.args.randomize_layout {
flags.push("-Z".into());
flags.push("randomize-layout".into());
Expand Down
9 changes: 8 additions & 1 deletion kani-driver/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::metadata::from_json;
use crate::session::KaniSession;
use crate::util::crate_name;
use crate::util::{crate_name, info_operation};
use anyhow::{Context, Result};
use kani_metadata::{
ArtifactType, ArtifactType::*, HarnessMetadata, KaniMetadata, artifact::convert_type,
Expand Down Expand Up @@ -177,6 +177,13 @@ impl Artifact {
/// be collected from the project.
pub fn cargo_project(session: &mut KaniSession, keep_going: bool) -> Result<Project> {
let outputs = session.cargo_build(keep_going)?;
if session.args.no_codegen {
info_operation(
"info:",
"Compilation succeeded up until codegen. Skipping codegen because of `--no-codegen` option. Rerun without `--no-codegen` to perform codegen.",
);
return Ok(Project::default());
}
let outdir = outputs.outdir.canonicalize()?;
// For the MIR Linker we know there is only one metadata per crate. Use that in our favor.
let metadata =
Expand Down
9 changes: 9 additions & 0 deletions tests/script-based-pre/no_codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

[package]
name = "no_codegen"
version = "0.1.0"
edition = "2024"

[dependencies]
5 changes: 5 additions & 0 deletions tests/script-based-pre/no_codegen/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: run.sh
expected: expected
exit_code: 0
1 change: 1 addition & 0 deletions tests/script-based-pre/no_codegen/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
info: Compilation succeeded up until codegen. Skipping codegen because of `--no-codegen` option. Rerun without `--no-codegen` to perform codegen.
14 changes: 14 additions & 0 deletions tests/script-based-pre/no_codegen/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

rm -rf target

# Test the behavior of the `--no-codegen` option
cargo kani --no-codegen -Zunstable-options

# Ensure no goto binaries (*.out) are generated
[[ -z $(find target -name "*.out") ]] || {
echo "ERROR: Found goto binaries (*.out) in target directory"
exit 1
}
14 changes: 14 additions & 0 deletions tests/script-based-pre/no_codegen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test checks the behavior of Kani's `--no-codegen` option

#[kani::proof]
fn main() {
let x: u8 = kani::any();
if x < 100 {
assert!(x < 101);
} else {
assert!(x > 99);
}
}
9 changes: 9 additions & 0 deletions tests/script-based-pre/no_codegen_error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

[package]
name = "no_codegen_error"
version = "0.1.0"
edition = "2024"

[dependencies]
5 changes: 5 additions & 0 deletions tests/script-based-pre/no_codegen_error/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: run.sh
expected: expected
exit_code: 1
1 change: 1 addition & 0 deletions tests/script-based-pre/no_codegen_error/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
could not compile `no_codegen_error`
8 changes: 8 additions & 0 deletions tests/script-based-pre/no_codegen_error/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

rm -rf target

# Test the behavior of the `--no-codegen` option
cargo kani --no-codegen -Zunstable-options
13 changes: 13 additions & 0 deletions tests/script-based-pre/no_codegen_error/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test checks the behavior of Kani's `--no-codegen` option when the crate
//! has compilation errors

#[kani::proof]
fn main() {
let x: i32 = 5;
// Error: different types
let y: u32 = x;
assert_eq!(y, 5);
}
Loading