diff --git a/ast/src/analyzed/mod.rs b/ast/src/analyzed/mod.rs index 5733f431de..c8c60b34b2 100644 --- a/ast/src/analyzed/mod.rs +++ b/ast/src/analyzed/mod.rs @@ -518,7 +518,7 @@ impl Analyzed { } } -impl Hash for Analyzed { +impl Hash for Analyzed { fn hash(&self, state: &mut H) { for identity in &self.identities { identity.hash(state); diff --git a/pilopt/src/lib.rs b/pilopt/src/lib.rs index 953165b353..46d952391e 100644 --- a/pilopt/src/lib.rs +++ b/pilopt/src/lib.rs @@ -23,12 +23,8 @@ use referenced_symbols::{ReferencedSymbols, SymbolReference}; pub fn optimize(mut pil_file: Analyzed) -> Analyzed { let col_count_pre = (pil_file.commitment_count(), pil_file.constant_count()); + let mut pil_hash = hash_pil_state(&pil_file); loop { - let pil_hash = { - let mut hasher = DefaultHasher::new(); - pil_file.hash(&mut hasher); - hasher.finish() - }; remove_unreferenced_definitions(&mut pil_file); remove_constant_fixed_columns(&mut pil_file); deduplicate_fixed_columns(&mut pil_file); @@ -40,14 +36,11 @@ pub fn optimize(mut pil_file: Analyzed) -> Analyzed { remove_trivial_identities(&mut pil_file); remove_duplicate_identities(&mut pil_file); - let new_hash = { - let mut hasher = DefaultHasher::new(); - pil_file.hash(&mut hasher); - hasher.finish() - }; + let new_hash = hash_pil_state(&pil_file); if pil_hash == new_hash { break; } + pil_hash = new_hash; } let col_count_post = (pil_file.commitment_count(), pil_file.constant_count()); log::info!( @@ -60,6 +53,12 @@ pub fn optimize(mut pil_file: Analyzed) -> Analyzed { pil_file } +fn hash_pil_state(pil_file: &Analyzed) -> u64 { + let mut hasher = DefaultHasher::new(); + pil_file.hash(&mut hasher); + hasher.finish() +} + /// Removes all definitions that are not referenced by an identity, public declaration /// or witness column hint. fn remove_unreferenced_definitions(pil_file: &mut Analyzed) {