run_pass fn

This commit is contained in:
nora 2022-12-17 23:16:56 +01:00
parent ed8da36a92
commit 865d8a7bc9
2 changed files with 63 additions and 57 deletions

View file

@ -76,9 +76,16 @@ impl Minimizer {
"Initial build must reproduce issue"
);
for mut pass in passes {
self.run_pass(&mut *pass)?;
}
Ok(())
}
fn run_pass(&mut self, pass: &mut dyn Processor) -> Result<()> {
let mut invalidated_files = HashSet::new();
for mut pass in passes {
let mut refresh_and_try_again = false;
'pass: loop {
@ -97,8 +104,7 @@ impl Minimizer {
let mut krate = syn::parse_file(change.before_content())
.with_context(|| format!("parsing file {file_display}"))?;
let has_made_change =
pass.process_file(&mut krate, file, &mut ProcessChecker {});
let has_made_change = pass.process_file(&mut krate, file, &mut ProcessChecker {});
match has_made_change {
ProcessState::Changed | ProcessState::FileInvalidated => {
@ -130,6 +136,7 @@ impl Minimizer {
if !refresh_and_try_again && invalidated_files.len() > 0 {
// A few files have been invalidated, let's refresh and try these again.
pass.refresh_state().context("refreshing state for pass")?;
invalidated_files.clear();
refresh_and_try_again = true;
println!("Refreshing files for {}", pass.name());
continue;
@ -141,7 +148,6 @@ impl Minimizer {
refresh_and_try_again = false;
}
}
}
Ok(())
}

View file

@ -112,7 +112,7 @@ impl Processor for DeleteUnusedFunctions {
fn refresh_state(&mut self) -> Result<()> {
let (diags, _) = self.build.get_diags().context("getting diagnostics")?;
self.diags = diags;
self.invalid = HashSet::new();
self.invalid.clear();
Ok(())
}