Skip to content

Commit

Permalink
Make Polonius report any found errors by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Isaac van Bakel committed Jul 21, 2023
1 parent 0a754a9 commit 5c995c7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions book/src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
4 changes: 4 additions & 0 deletions polonius-engine/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ impl<T: FactTypes> Output<T> {
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
Expand Down
22 changes: 14 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
skip_timing: bool,
verbose: bool,
graphviz_file: Option<String>,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -131,11 +131,11 @@ USAGE:
polonius [FLAGS] [OPTIONS] <fact_dirs>...
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 <algorithm> [default: Naive]
Expand Down Expand Up @@ -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")?,
Expand Down

0 comments on commit 5c995c7

Please sign in to comment.