From 5c995c7d3deb92b39dc34f02cfb3af01b3aefe3a Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Wed, 19 Jul 2023 17:29:11 +0200 Subject: [PATCH] Make Polonius report any found errors by default It's a bit confusing that running Polonius on some Rust code that you know has a borrow error doesn't seem to actually do anything - it gives the impression that no analysis is performed by default. Of course, analysis *is* performed by default, but errors aren't reported unless you opt in (which begs the question of what exactly the tool is meant to be doing when you run it!) This changes the behaviour to print error tuples by default if any are found, for a better experience. The old behaviour can be re-enabled by using `--no-show-tuples` to suppress tuple output even if errors are present. --- README.md | 8 ++++---- book/src/getting_started.md | 8 ++++---- polonius-engine/src/output/mod.rs | 4 ++++ src/cli.rs | 22 ++++++++++++++-------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index de8c15f21a6..3e301855c53 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ slower) -- these are the exact rules described in [the blogpost][post]. You can also use `-a LocationInsensitive` to use a location insensitive analysis (faster, but may yield spurious errors). -By default, `cargo run` just prints timing. If you also want to see -the results, try `--show-tuples` (which will show errors) and maybe -`-v` (to show more intermediate computations). You can supply `--help` -to get more docs. +By default, `cargo run` will print any errors found, but otherwise +just prints timing. If you also want to see successful results, try +`--show-tuples` and maybe `-v` (to show more intermediate computations). +You can supply `--help` to get more docs. ### How to generate your own inputs diff --git a/book/src/getting_started.md b/book/src/getting_started.md index 1a3520c94d9..f4c6cec6fc6 100644 --- a/book/src/getting_started.md +++ b/book/src/getting_started.md @@ -19,9 +19,9 @@ slower) -- these are the exact rules described in [the blogpost][post]. You can also use `-a LocationInsensitive` to use a location insensitive analysis (faster, but may yield spurious errors). -By default, `cargo run` just prints timing. If you also want to see -the results, try `--show-tuples` (which will show errors) and maybe -`-v` (to show more intermediate computations). You can supply `--help` -to get more docs. +By default, `cargo run` will print any errors found, but otherwise +just prints timing. If you also want to see successful results, try +`--show-tuples` and maybe `-v` (to show more intermediate computations). +You can supply `--help` to get more docs. [post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/ diff --git a/polonius-engine/src/output/mod.rs b/polonius-engine/src/output/mod.rs index b840e4bec83..cd37aeaa1f6 100644 --- a/polonius-engine/src/output/mod.rs +++ b/polonius-engine/src/output/mod.rs @@ -514,6 +514,10 @@ impl Output { None => Cow::Owned(BTreeMap::default()), } } + + pub fn has_errors(&self) -> bool { + !(self.errors.is_empty() && self.move_errors.is_empty() && self.subset_errors.is_empty()) + } } /// Compares errors reported by Naive implementation with the errors diff --git a/src/cli.rs b/src/cli.rs index 2d1e23ce947..e43e3650a8c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,7 +22,7 @@ const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); #[derive(Debug)] pub struct Options { algorithm: Algorithm, - show_tuples: bool, + show_tuples: Option, skip_timing: bool, verbose: bool, graphviz_file: Option, @@ -81,7 +81,7 @@ pub fn main(opt: Options) -> Result<(), Error> { let millis = f64::from(duration.subsec_nanos()) * 0.000_000_001_f64; println!("Time: {:0.3}s", seconds + millis); } - if opt.show_tuples { + if opt.show_tuples.unwrap_or_else(|| output.has_errors()) { dump::dump_output(&output, &output_directory, tables) .expect("Failed to write output"); } @@ -131,11 +131,11 @@ USAGE: polonius [FLAGS] [OPTIONS] ... FLAGS: - -h, --help Prints help information - --show-tuples Show output tuples on stdout - --skip-timing Do not display timing results - -V, --version Prints version information - -v, --verbose Show intermediate output tuples and not just errors + -h, --help Prints help information + --[no-]show-tuples Show output tuples on stdout, or suppress errors + --skip-timing Do not display timing results + -V, --version Prints version information + -v, --verbose Show intermediate output tuples and not just errors OPTIONS: -a [default: Naive] @@ -163,7 +163,13 @@ ARGS: // 2) parse args let options = Options { algorithm: arg_from_str(&mut args, "-a")?.unwrap_or(Algorithm::Naive), - show_tuples: args.contains("--show-tuples"), + show_tuples: if args.contains("--show-tuples") { + Some(true) + } else if args.contains("--no-show-tuples") { + Some(false) + } else { + None + }, skip_timing: args.contains("--skip-timing"), verbose: args.contains(["-v", "--verbose"]), graphviz_file: arg_from_str(&mut args, "--graphviz-file")?,