Document formatter error shrinking (#5915)

## Summary

**Don't minimize files that don't match in the first place** This adds a
sanity check to the minimizer script that the
input matches the condition (e.g. unstable formatting). Otherwise we run
through all checks with the whole file, which is extremely slow. It's
more reasonable for downstream usage to write an empty string to the
output file instead.
This commit is contained in:
konsti 2023-07-21 11:32:12 +02:00 committed by GitHub
parent 03018896de
commit b56e8ad696
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -422,9 +422,18 @@ fn run() -> Result<()> {
let loop_start = Instant::now();
let mut stats = HashMap::new();
let mut num_iterations = 0;
// normalize line endings for the remove newline dependent rules
// Normalize line endings for the remove newline dependent rules
let mut input = fs::read_to_string(args.input_file)?.replace('\r', "");
// This can happen e.g. when main changed between collecting the errors list and running this
// script
if !is_failing(&input, &args.output_file, &command_args, &pattern)? {
println!("Input doesn't match");
fs::write(&args.output_file, "")?;
return Ok(());
}
let mut num_iterations = 0;
let mut last_strategy_and_idx = None;
loop {
let start = Instant::now();
@ -461,9 +470,10 @@ fn run() -> Result<()> {
println!("Strategies taken: {stats:?}");
println!(
"Done with {num_iterations} iterations in {:.2}s. Find your minimized example in {}",
"Done with {num_iterations} iterations in {:.2}s. Find your minimized example in {}:\n---\n{}\n---\n",
loop_start.elapsed().as_secs_f32(),
args.output_file.display()
args.output_file.display(),
input
);
Ok(())