Skip to content

Commit 9fa44a2

Browse files
authored
Remove --dry-run from Kani. (rust-lang#1943)
1 parent 6869324 commit 9fa44a2

File tree

14 files changed

+69
-110
lines changed

14 files changed

+69
-110
lines changed

kani-driver/src/args.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct KaniArgs {
6767
#[arg(
6868
long,
6969
requires("enable_unstable"),
70-
conflicts_with_all(&["visualize", "dry_run"]),
70+
conflicts_with_all(&["visualize"]),
7171
ignore_case = true,
7272
value_enum
7373
)]
@@ -89,10 +89,9 @@ pub struct KaniArgs {
8989
#[arg(long, hide_short_help = true)]
9090
pub enable_unstable: bool,
9191

92-
// Hide this since it depends on function that is a hidden option.
93-
/// Print commands instead of running them. This command uses "harness" as a place holder for
94-
/// name of the target harness.
95-
#[arg(long, hide = true, requires("enable_unstable"))]
92+
/// We no longer support dry-run. Use `--verbose` to see the commands being printed during
93+
/// Kani execution.
94+
#[arg(long, hide = true)]
9695
pub dry_run: bool,
9796

9897
/// Generate C file equivalent to inputted program.
@@ -118,11 +117,10 @@ pub struct KaniArgs {
118117

119118
/// Entry point for verification (symbol name).
120119
/// This is an unstable feature. Consider using --harness instead
121-
#[arg(long, hide = true, requires("enable_unstable"), conflicts_with("dry_run"))]
120+
#[arg(long, hide = true, requires("enable_unstable"))]
122121
pub function: Option<String>,
123122
/// Entry point for verification (proof harness)
124-
// In a dry-run, we don't have kani-metadata.json to read, so we can't use this flag
125-
#[arg(long, conflicts_with = "function", conflicts_with = "dry_run")]
123+
#[arg(long, conflicts_with = "function")]
126124
pub harness: Option<String>,
127125

128126
/// Link external C files referenced by Rust code.
@@ -448,6 +446,13 @@ impl KaniArgs {
448446
));
449447
}
450448

449+
if self.dry_run {
450+
return Err(Error::raw(
451+
ErrorKind::ValueValidation,
452+
"The `--dry-run` option is obsolete. Use --verbose instead.",
453+
));
454+
}
455+
451456
Ok(())
452457
}
453458
}
@@ -510,11 +515,11 @@ mod tests {
510515
}
511516

512517
#[test]
513-
fn check_dry_run_harness_conflicts() {
514-
// harness needs metadata which we don't have with dry-run
515-
let args = vec!["kani", "file.rs", "--dry-run", "--harness", "foo"];
516-
let err = StandaloneArgs::try_parse_from(args).unwrap_err();
517-
assert_eq!(err.kind(), ErrorKind::ArgumentConflict);
518+
fn check_dry_run_fails() {
519+
// We don't support --dry-run anymore but we print a friendly reminder for now.
520+
let args = vec!["kani", "file.rs", "--dry-run"];
521+
let err = StandaloneArgs::parse_from(&args).common_opts.validate_inner().unwrap_err();
522+
assert_eq!(err.kind(), ErrorKind::ValueValidation);
518523
}
519524

520525
#[test]

kani-driver/src/call_cargo.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ impl KaniSession {
121121
if !found_target {
122122
bail!("No supported targets were found.");
123123
}
124-
if self.args.dry_run {
125-
// mock an answer: mostly the same except we don't/can't expand the globs
126-
return Ok(CargoOutputs {
127-
outdir: outdir.clone(),
128-
symtabs: vec![outdir.join("*.symtab.json")],
129-
metadata: vec![outdir.join("*.kani-metadata.json")],
130-
restrictions: self.args.restrict_vtable().then_some(outdir),
131-
});
132-
}
133124

134125
Ok(CargoOutputs {
135126
outdir: outdir.clone(),

kani-driver/src/harness_runner.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ impl KaniSession {
103103
let result = self.run_cbmc(binary, harness)?;
104104

105105
// When quiet, we don't want to print anything at all.
106-
// When dry-run, we don't have real results to print.
107106
// When output is old, we also don't have real results to print.
108-
if !self.args.quiet
109-
&& !self.args.dry_run
110-
&& self.args.output_format != OutputFormat::Old
111-
{
107+
if !self.args.quiet && self.args.output_format != OutputFormat::Old {
112108
println!("{}", result.render(&self.args.output_format));
113109
}
114110

kani-driver/src/metadata.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@ use std::io::{BufReader, BufWriter};
1313

1414
use crate::session::KaniSession;
1515

16-
fn generate_mock_harness() -> HarnessMetadata {
17-
HarnessMetadata {
18-
pretty_name: String::from("harness"),
19-
mangled_name: String::from("harness"),
20-
original_file: String::from("target_file.rs"),
21-
original_start_line: 0,
22-
original_end_line: 0,
23-
unwind_value: None,
24-
}
25-
}
26-
2716
/// From either a file or a path with multiple files, output the CBMC restrictions file we should use.
2817
pub fn collect_and_link_function_pointer_restrictions(
2918
path: &Path,
@@ -127,19 +116,10 @@ fn merge_kani_metadata(files: Vec<KaniMetadata>) -> KaniMetadata {
127116
impl KaniSession {
128117
/// Reads a collection of kani-metadata.json files and merges the results.
129118
pub fn collect_kani_metadata(&self, files: &[PathBuf]) -> Result<KaniMetadata> {
130-
if self.args.dry_run {
131-
// Mock an answer
132-
Ok(KaniMetadata {
133-
proof_harnesses: vec![generate_mock_harness()],
134-
unsupported_features: vec![],
135-
test_harnesses: vec![],
136-
})
137-
} else {
138-
// TODO: one possible future improvement here would be to return some kind of Lazy
139-
// value, that only computes this metadata if it turns out we need it.
140-
let results: Result<Vec<_>, _> = files.iter().map(|x| read_kani_metadata(x)).collect();
141-
Ok(merge_kani_metadata(results?))
142-
}
119+
// TODO: one possible future improvement here would be to return some kind of Lazy
120+
// value, that only computes this metadata if it turns out we need it.
121+
let results: Result<Vec<_>, _> = files.iter().map(|x| read_kani_metadata(x)).collect();
122+
Ok(merge_kani_metadata(results?))
143123
}
144124

145125
/// Determine which function to use as entry point, based on command-line arguments and kani-metadata.

kani-driver/src/session.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum ReachabilityMode {
9595

9696
impl Drop for KaniSession {
9797
fn drop(&mut self) {
98-
if !self.args.keep_temps && !self.args.dry_run {
98+
if !self.args.keep_temps {
9999
let temporaries = self.temporaries.lock().unwrap();
100100

101101
for file in temporaries.iter() {
@@ -108,7 +108,7 @@ impl Drop for KaniSession {
108108

109109
impl KaniSession {
110110
// The below suite of helper functions for executing Commands are meant to be a common handler
111-
// for various cmdline flags like 'dry-run' and 'quiet'. These functions are temporary: in the
111+
// for various cmdline flags like 'verbose' and 'quiet'. These functions are temporary: in the
112112
// longer run we'll switch to a graph-interpreter style of constructing and executing jobs.
113113
// (In other words: higher-level data structures, rather than passing around Commands.)
114114
// (e.g. to support emitting Litani build graphs, or to better parallelize our work)
@@ -126,12 +126,8 @@ impl KaniSession {
126126
cmd.stdout(std::process::Stdio::null());
127127
cmd.stderr(std::process::Stdio::null());
128128
}
129-
if self.args.verbose || self.args.dry_run {
130-
println!("{}", render_command(&cmd).to_string_lossy());
131-
if self.args.dry_run {
132-
// Short circuit
133-
return Ok(());
134-
}
129+
if self.args.verbose {
130+
println!("[Kani] Running: `{}`", render_command(&cmd).to_string_lossy());
135131
}
136132
let result = cmd
137133
.status()
@@ -144,7 +140,7 @@ impl KaniSession {
144140

145141
/// Run a job, but only output (unless --quiet) if it fails, and fail if there's a problem.
146142
pub fn run_suppress(&self, mut cmd: Command) -> Result<()> {
147-
if self.args.quiet || self.args.debug || self.args.verbose || self.args.dry_run {
143+
if self.args.quiet || self.args.debug || self.args.verbose {
148144
return self.run_terminal(cmd);
149145
}
150146
let result = cmd
@@ -165,12 +161,12 @@ impl KaniSession {
165161

166162
/// Run a job, redirect its output to a file, and allow the caller to decide what to do with failure.
167163
pub fn run_redirect(&self, mut cmd: Command, stdout: &Path) -> Result<ExitStatus> {
168-
if self.args.verbose || self.args.dry_run {
169-
println!("{} > {}", render_command(&cmd).to_string_lossy(), stdout.display());
170-
if self.args.dry_run {
171-
// Short circuit. Difficult to mock an ExitStatus :(
172-
return Ok(<ExitStatus as std::os::unix::prelude::ExitStatusExt>::from_raw(0));
173-
}
164+
if self.args.verbose {
165+
println!(
166+
"[Kani] Running: `{} > {}`",
167+
render_command(&cmd).to_string_lossy(),
168+
stdout.display()
169+
);
174170
}
175171
let output_file = std::fs::File::create(&stdout)?;
176172
cmd.stdout(output_file);
@@ -184,11 +180,8 @@ impl KaniSession {
184180
/// NOTE: Unlike other `run_` functions, this function does not attempt to indicate
185181
/// the process exit code, you need to remember to check this yourself.
186182
pub fn run_piped(&self, mut cmd: Command) -> Result<Option<Child>> {
187-
if self.args.verbose || self.args.dry_run {
188-
println!("{}", render_command(&cmd).to_string_lossy());
189-
if self.args.dry_run {
190-
return Ok(None);
191-
}
183+
if self.args.verbose {
184+
println!("[Kani] Running: `{}`", render_command(&cmd).to_string_lossy());
192185
}
193186
// Run the process as a child process
194187
let process = cmd

tests/cargo-ui/dry-run/expected

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/cargo-ui/dry-run/src/lib.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/cargo-ui/dry-run/Cargo.toml renamed to tests/cargo-ui/verbose-cmds/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
name = "dry-run"
55
version = "0.1.0"
66
edition = "2021"
7+
description = "Check that --verbose include the commands ran by Kani"
78

89
[dependencies]
910

1011
[package.metadata.kani]
11-
flags = { dry-run=true, enable-unstable=true }
12+
flags = { verbose=true }

tests/cargo-ui/verbose-cmds/expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KANIFLAGS=
2+
RUSTC=
3+
cargo rustc
4+
Running: `goto-cc
5+
Running: `goto-instrument
6+
Checking harness dummy_harness...
7+
Running: `cbmc
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! The --verbose will print the commands executed by Kani before invoking them.
5+
6+
#[kani::proof]
7+
pub fn dummy_harness() {
8+
assert!(true);
9+
}

tests/expected/dry-run/expected

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/expected/dry-run/main.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/expected/verbose-cmds/expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Running: `goto-cc
2+
Running: `goto-instrument
3+
Running: `cbmc
4+
VERIFICATION:- SUCCESSFUL

tests/expected/verbose-cmds/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// kani-flags: --verbose
5+
6+
// `--verbose` causes Kani to print out commands before running them
7+
// In `expected` you will find substrings of these commands for easy maintenence.
8+
#[kani::proof]
9+
fn real_harness() {
10+
assert_eq!(1 + 1, 2);
11+
}

0 commit comments

Comments
 (0)