mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
run_pass fn
This commit is contained in:
parent
ed8da36a92
commit
865d8a7bc9
2 changed files with 63 additions and 57 deletions
|
|
@ -76,71 +76,77 @@ 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 {
|
||||||
println!("Starting a round of {}", pass.name());
|
println!("Starting a round of {}", pass.name());
|
||||||
let mut changes = Changes::default();
|
let mut changes = Changes::default();
|
||||||
|
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
if invalidated_files.contains(file) {
|
if invalidated_files.contains(file) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
let file_display = file.path.display();
|
|
||||||
|
|
||||||
let mut change = file.try_change(&mut changes)?;
|
|
||||||
|
|
||||||
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 {});
|
|
||||||
|
|
||||||
match has_made_change {
|
|
||||||
ProcessState::Changed | ProcessState::FileInvalidated => {
|
|
||||||
let result = prettyplease::unparse(&krate);
|
|
||||||
|
|
||||||
change.write(&result)?;
|
|
||||||
|
|
||||||
let after = self.build.build()?;
|
|
||||||
|
|
||||||
println!("{file_display}: After {}: {after}", pass.name());
|
|
||||||
|
|
||||||
if after.reproduces_issue() {
|
|
||||||
change.commit();
|
|
||||||
} else {
|
|
||||||
change.rollback()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if has_made_change == ProcessState::FileInvalidated {
|
|
||||||
invalidated_files.insert(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ProcessState::NoChange => {
|
|
||||||
println!("{file_display}: After {}: no change", pass.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !changes.had_changes() {
|
let file_display = file.path.display();
|
||||||
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")?;
|
|
||||||
refresh_and_try_again = true;
|
|
||||||
println!("Refreshing files for {}", pass.name());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Finished {}", pass.name());
|
let mut change = file.try_change(&mut changes)?;
|
||||||
break 'pass;
|
|
||||||
} else {
|
let mut krate = syn::parse_file(change.before_content())
|
||||||
refresh_and_try_again = false;
|
.with_context(|| format!("parsing file {file_display}"))?;
|
||||||
|
|
||||||
|
let has_made_change = pass.process_file(&mut krate, file, &mut ProcessChecker {});
|
||||||
|
|
||||||
|
match has_made_change {
|
||||||
|
ProcessState::Changed | ProcessState::FileInvalidated => {
|
||||||
|
let result = prettyplease::unparse(&krate);
|
||||||
|
|
||||||
|
change.write(&result)?;
|
||||||
|
|
||||||
|
let after = self.build.build()?;
|
||||||
|
|
||||||
|
println!("{file_display}: After {}: {after}", pass.name());
|
||||||
|
|
||||||
|
if after.reproduces_issue() {
|
||||||
|
change.commit();
|
||||||
|
} else {
|
||||||
|
change.rollback()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_made_change == ProcessState::FileInvalidated {
|
||||||
|
invalidated_files.insert(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ProcessState::NoChange => {
|
||||||
|
println!("{file_display}: After {}: no change", pass.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !changes.had_changes() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Finished {}", pass.name());
|
||||||
|
break 'pass;
|
||||||
|
} else {
|
||||||
|
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