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

Extract expressionizer and fix optimizer. #2056

Merged
merged 9 commits into from
Nov 11, 2024
Merged

Extract expressionizer and fix optimizer. #2056

merged 9 commits into from
Nov 11, 2024

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Nov 7, 2024

No description provided.

@chriseth chriseth changed the title Extract expressionizer. Extract expressionizer and fix optimizer. Nov 7, 2024
This was referenced Nov 7, 2024
Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes #2051, nice!

I reviewed everything but the first commit (the diff is pretty big, also when comparing the old condenser with the expressionizer file, but I believe you that you just moved code...). I have a few comments on how I think we can simplify the code a bit.

Comment on lines +303 to +307
let ((_, array_start), symbol_name) = self
.poly_id_to_name
.range(..=(poly_id.ptype, poly_id.id))
.last()
.unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand this right:

  • poly_id_to_name would have an entry for the array, but not each element
  • This code finds it's PolyID.id (which would that of the first element), assuming a consecutive ordering of the IDs of an array.

I think this deserves a comment :)

}

struct Expressionizer<'a> {
poly_id_to_name: &'a BTreeMap<(PolynomialType, u64), String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(PolynomialType, u64) is essentially PolyID, except that it stores the type first, which makes the range thing work, right? In that case, could we just change PolyID to store the type first?

But on a higher-level note, why don't we have something like array_elements: BTreeMap<PolyID, (String, usize)> (if a polynomial is an array element, maps it to the array name and index) instead? That would get rid of the poly_id_to_name.range(...).last() thing below, which seems kinda hacky...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially since, in my understanding, the array_elements map would not change during the condenser run, would it? I feel like this could simplify some code further.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about changing PolyID but decided against because it's too fragile. We would need a static assert here to prevent other changes to PolyID from breaking the assumptions here.

I don't want to store an element for every single array element because I wanted to avoid performance problems coming from using large arrays.

The condenser run can actually add new arrays any time and we need to be able to handle them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about changing PolyID but decided against because it's too fragile. We would need a static assert here to prevent other changes to PolyID from breaking the assumptions here.

Agreed.

The condenser run can actually add new arrays any time and we need to be able to handle them.

Right, I didn't see that Condenser::new_column (the only place that changes Condenser::poly_id_to_name) can actually add arrays of columns as well.

I don't want to store an element for every single array element because I wanted to avoid performance problems coming from using large arrays.

We are only talking about arrays of columns, aren't we? So at most, they will be in the 1000s, because otherwise we'd have other problems, right?

@chriseth
Copy link
Member Author

chriseth commented Nov 8, 2024

Added some comments.

Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I still find the poly_id_to_name.range() thing spooky and I'm not convinced having an entry per array element would be a performance issue. But if you want to keep it like that, I have one more comment I'd find helpful :)

}

struct Expressionizer<'a> {
poly_id_to_name: &'a BTreeMap<(PolynomialType, u64), String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about changing PolyID but decided against because it's too fragile. We would need a static assert here to prevent other changes to PolyID from breaking the assumptions here.

Agreed.

The condenser run can actually add new arrays any time and we need to be able to handle them.

Right, I didn't see that Condenser::new_column (the only place that changes Condenser::poly_id_to_name) can actually add arrays of columns as well.

I don't want to store an element for every single array element because I wanted to avoid performance problems coming from using large arrays.

We are only talking about arrays of columns, aren't we? So at most, they will be in the 1000s, because otherwise we'd have other problems, right?

pil-analyzer/src/expressionizer.rs Show resolved Hide resolved
@chriseth chriseth enabled auto-merge November 11, 2024 11:02
@chriseth chriseth added this pull request to the merge queue Nov 11, 2024
Merged via the queue into main with commit 2219cf3 Nov 11, 2024
14 checks passed
@chriseth chriseth deleted the expressionizer branch November 11, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants