Skip to content

Commit

Permalink
improvemnts
Browse files Browse the repository at this point in the history
  • Loading branch information
gzanitti committed Dec 20, 2024
1 parent 8568981 commit 7361bac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<T: FieldElement> Analyzed<T> {
}
}

impl<T: FieldElement> Hash for Analyzed<T> {
impl<T: Hash> Hash for Analyzed<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
for identity in &self.identities {
identity.hash(state);
Expand Down
19 changes: 9 additions & 10 deletions pilopt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ use referenced_symbols::{ReferencedSymbols, SymbolReference};

pub fn optimize<T: FieldElement>(mut pil_file: Analyzed<T>) -> Analyzed<T> {
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);
Expand All @@ -40,14 +36,11 @@ pub fn optimize<T: FieldElement>(mut pil_file: Analyzed<T>) -> Analyzed<T> {
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!(
Expand All @@ -60,6 +53,12 @@ pub fn optimize<T: FieldElement>(mut pil_file: Analyzed<T>) -> Analyzed<T> {
pil_file
}

fn hash_pil_state<T: Hash>(pil_file: &Analyzed<T>) -> 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<T: FieldElement>(pil_file: &mut Analyzed<T>) {
Expand Down

0 comments on commit 7361bac

Please sign in to comment.