Skip to content

Commit fda814b

Browse files
committed
move autoharness compiler flags to kani_compiler_flags
1 parent 84cd134 commit fda814b

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

kani-driver/src/autoharness/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::args::autoharness_args::{
99
};
1010
use crate::args::common::UnstableFeature;
1111
use crate::call_cbmc::VerificationStatus;
12-
use crate::call_single_file::to_rustc_arg;
1312
use crate::harness_runner::HarnessResult;
1413
use crate::list::collect_metadata::process_metadata;
1514
use crate::list::output::output_list_results;
@@ -151,23 +150,21 @@ fn print_skipped_table(table: &mut PrettyTable) {
151150
impl KaniSession {
152151
/// Enable autoharness mode.
153152
pub fn enable_autoharness(&mut self) {
154-
self.auto_harness = true;
153+
self.autoharness_compiler_flags = Some(vec![]);
155154
self.args.common_args.unstable_features.enable_feature(UnstableFeature::FunctionContracts);
156155
self.args.common_args.unstable_features.enable_feature(UnstableFeature::LoopContracts);
157156
}
158157

159158
/// Add the compiler arguments specific to the `autoharness` subcommand.
160-
/// TODO: this should really be appending onto the `kani_compiler_flags()` output instead of `pkg_args`.
161-
/// It doesn't affect functionality since autoharness doesn't examine dependencies, but would still be better practice.
162159
pub fn add_auto_harness_args(&mut self, included: &[String], excluded: &[String]) {
160+
let mut args = vec![];
163161
for func in included {
164-
self.pkg_args
165-
.push(to_rustc_arg(vec![format!("--autoharness-include-function {}", func)]));
162+
args.push(format!("--autoharness-include-function {}", func));
166163
}
167164
for func in excluded {
168-
self.pkg_args
169-
.push(to_rustc_arg(vec![format!("--autoharness-exclude-function {}", func)]));
165+
args.push(format!("--autoharness-exclude-function {}", func));
170166
}
167+
self.autoharness_compiler_flags = Some(args);
171168
}
172169

173170
/// Add global harness timeout and loop unwinding bounds if not provided.

kani-driver/src/call_cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ crate-type = ["lib"]
194194
// If you are adding a new `kani-compiler` argument, you likely want to put it `kani_compiler_flags()` instead,
195195
// unless there a reason it shouldn't be passed to dependencies.
196196
// (Note that at the time of writing, passing the other compiler args to dependencies is a no-op, since `--reachability=None` skips codegen anyway.)
197-
self.pkg_args.push(self.reachability_arg());
197+
let pkg_args = vec!["--".into(), self.reachability_arg()];
198198

199199
let mut found_target = false;
200200
let packages = self.packages_to_verify(&self.args, &metadata)?;
@@ -206,7 +206,7 @@ crate-type = ["lib"]
206206
cmd.args(&cargo_args)
207207
.args(vec!["-p", &package.id.to_string()])
208208
.args(verification_target.to_args())
209-
.args(&self.pkg_args)
209+
.args(&pkg_args)
210210
.env("RUSTC", &self.kani_compiler)
211211
// Use CARGO_ENCODED_RUSTFLAGS instead of RUSTFLAGS is preferred. See
212212
// https://doc.rust-lang.org/cargo/reference/environment-variables.html

kani-driver/src/call_single_file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ impl KaniSession {
151151
flags.push("--no-assert-contracts".into());
152152
}
153153

154+
if let Some(args) = self.autoharness_compiler_flags.clone() {
155+
flags.extend(args);
156+
}
157+
154158
flags.extend(self.args.common_args.unstable_features.as_arguments().map(str::to_string));
155159

156160
flags

kani-driver/src/harness_runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ impl KaniSession {
298298
self.show_coverage_summary()?;
299299
}
300300

301-
if self.auto_harness {
301+
if self.autoharness_compiler_flags.is_some() {
302302
self.print_autoharness_summary(automatic)?;
303303
}
304304

305-
if failing > 0 && !self.auto_harness {
305+
if failing > 0 && self.autoharness_compiler_flags.is_none() {
306306
// Failure exit code without additional error message
307307
drop(self);
308308
std::process::exit(1);

kani-driver/src/session.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ pub struct KaniSession {
3131
/// The common command-line arguments
3232
pub args: VerificationArgs,
3333

34-
/// Automatically verify functions in the crate, in addition to running manual harnesses.
35-
pub auto_harness: bool,
36-
37-
/// The arguments that will be passed only to the target package, not its dependencies.
38-
pub pkg_args: Vec<String>,
34+
/// The autoharness-specific compiler arguments.
35+
/// Invariant: this field is_some() iff the autoharness subcommand is enabled.
36+
pub autoharness_compiler_flags: Option<Vec<String>>,
3937

4038
/// Include all publicly-visible symbols in the generated goto binary, not just those reachable from
4139
/// a proof harness. Useful when attempting to verify things that were not annotated with kani
@@ -71,8 +69,7 @@ impl KaniSession {
7169

7270
Ok(KaniSession {
7371
args,
74-
auto_harness: false,
75-
pkg_args: vec!["--".to_string()],
72+
autoharness_compiler_flags: None,
7673
codegen_tests: false,
7774
kani_compiler: install.kani_compiler()?,
7875
kani_lib_c: install.kani_lib_c()?,
@@ -101,7 +98,7 @@ impl KaniSession {
10198
pub fn reachability_mode(&self) -> ReachabilityMode {
10299
if self.codegen_tests {
103100
ReachabilityMode::Tests
104-
} else if self.auto_harness {
101+
} else if self.autoharness_compiler_flags.is_some() {
105102
ReachabilityMode::AllFns
106103
} else {
107104
ReachabilityMode::ProofHarnesses

0 commit comments

Comments
 (0)