Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pilopt: optimize until fixpoint #2225

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ast/src/parsed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ impl<R> Children<Expression<R>> for EnumVariant<Expression<R>> {
}
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(
Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema, Hash,
)]
pub struct TraitImplementation<Expr> {
pub name: SymbolPath,
pub source_ref: SourceRef,
Expand Down
21 changes: 15 additions & 6 deletions pilopt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ 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 = 0;
remove_unreferenced_definitions(&mut pil_file);
gzanitti marked this conversation as resolved.
Show resolved Hide resolved
while pil_hash != hash_pil_state(&pil_file) {
pil_hash = hash_pil_state(&pil_file);
loop {
let pil_hash = hash_pil_state(&pil_file);
remove_unreferenced_definitions(&mut pil_file);
remove_constant_fixed_columns(&mut pil_file);
deduplicate_fixed_columns(&mut pil_file);
simplify_identities(&mut pil_file);
Expand All @@ -35,8 +34,12 @@ pub fn optimize<T: FieldElement>(mut pil_file: Analyzed<T>) -> Analyzed<T> {
simplify_identities(&mut pil_file);
remove_trivial_identities(&mut pil_file);
remove_duplicate_identities(&mut pil_file);
remove_unreferenced_definitions(&mut pil_file);

if pil_hash == hash_pil_state(&pil_file) {
break;
}
}

let col_count_post = (pil_file.commitment_count(), pil_file.constant_count());
log::info!(
"Removed {} witness and {} fixed columns. Total count now: {} witness and {} fixed columns.",
Expand All @@ -55,7 +58,9 @@ fn hash_pil_state<T: FieldElement>(pil: &Analyzed<T>) -> u64 {
identity.hash(&mut hasher);
}

for (key, value) in pil.definitions.iter().sorted() {
let mut keys: Vec<_> = pil.definitions.keys().collect();
keys.sort();
for key in keys {
gzanitti marked this conversation as resolved.
Show resolved Hide resolved
key.hash(&mut hasher);
if let Some(v) = &pil.definitions[key].1 {
v.hash(&mut hasher);
Expand All @@ -80,6 +85,10 @@ fn hash_pil_state<T: FieldElement>(pil: &Analyzed<T>) -> u64 {
pil.public_declarations[key].hash(&mut hasher);
}

gzanitti marked this conversation as resolved.
Show resolved Hide resolved
for _impl in &pil.trait_impls {
_impl.hash(&mut hasher);
}

hasher.finish()
}

Expand Down
Loading