mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-16 17:25:03 +01:00
run_pass fn
This commit is contained in:
parent
ed8da36a92
commit
865d8a7bc9
2 changed files with 63 additions and 57 deletions
|
|
@ -76,9 +76,16 @@ impl Minimizer {
|
||||||
"Initial build must reproduce issue"
|
"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();
|
let mut invalidated_files = HashSet::new();
|
||||||
|
|
||||||
for mut pass in passes {
|
|
||||||
let mut refresh_and_try_again = false;
|
let mut refresh_and_try_again = false;
|
||||||
|
|
||||||
'pass: loop {
|
'pass: loop {
|
||||||
|
|
@ -97,8 +104,7 @@ impl Minimizer {
|
||||||
let mut krate = syn::parse_file(change.before_content())
|
let mut krate = syn::parse_file(change.before_content())
|
||||||
.with_context(|| format!("parsing file {file_display}"))?;
|
.with_context(|| format!("parsing file {file_display}"))?;
|
||||||
|
|
||||||
let has_made_change =
|
let has_made_change = pass.process_file(&mut krate, file, &mut ProcessChecker {});
|
||||||
pass.process_file(&mut krate, file, &mut ProcessChecker {});
|
|
||||||
|
|
||||||
match has_made_change {
|
match has_made_change {
|
||||||
ProcessState::Changed | ProcessState::FileInvalidated => {
|
ProcessState::Changed | ProcessState::FileInvalidated => {
|
||||||
|
|
@ -130,6 +136,7 @@ impl Minimizer {
|
||||||
if !refresh_and_try_again && invalidated_files.len() > 0 {
|
if !refresh_and_try_again && invalidated_files.len() > 0 {
|
||||||
// A few files have been invalidated, let's refresh and try these again.
|
// A few files have been invalidated, let's refresh and try these again.
|
||||||
pass.refresh_state().context("refreshing state for pass")?;
|
pass.refresh_state().context("refreshing state for pass")?;
|
||||||
|
invalidated_files.clear();
|
||||||
refresh_and_try_again = true;
|
refresh_and_try_again = true;
|
||||||
println!("Refreshing files for {}", pass.name());
|
println!("Refreshing files for {}", pass.name());
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -141,7 +148,6 @@ impl Minimizer {
|
||||||
refresh_and_try_again = false;
|
refresh_and_try_again = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ impl Processor for DeleteUnusedFunctions {
|
||||||
fn refresh_state(&mut self) -> Result<()> {
|
fn refresh_state(&mut self) -> Result<()> {
|
||||||
let (diags, _) = self.build.get_diags().context("getting diagnostics")?;
|
let (diags, _) = self.build.get_diags().context("getting diagnostics")?;
|
||||||
self.diags = diags;
|
self.diags = diags;
|
||||||
self.invalid = HashSet::new();
|
self.invalid.clear();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue