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

Create row struct #1510

Merged
merged 4 commits into from
Jul 2, 2024
Merged

Create row struct #1510

merged 4 commits into from
Jul 2, 2024

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Jul 1, 2024

No description provided.

@chriseth chriseth changed the base branch from main to refactor_row July 1, 2024 15:39
@chriseth chriseth marked this pull request as ready for review July 1, 2024 17:45
Base automatically changed from refactor_row to main July 1, 2024 17:52
pub struct Row<'a, T: FieldElement> {
/// The values in the row, zero if unknown.
values: WitnessColumnMap<CellValue<T>>,
// TODO remove this.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done in #1514

}
}

impl<'a, T: FieldElement> Row<'a, T> {
/// Creates a "fresh" row, i.e., one that is empty but initialized with the global range constraints.
pub fn fresh(fixed_data: &'a FixedData<'a, T>, row: RowIndex) -> Row<'a, T> {
WitnessColumnMap::from(
// TODO this instance could be computed exactly once (per column set) and then cloned.
Copy link
Member Author

Choose a reason for hiding this comment

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

Will do these in a subsequent PR

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.

Cool!

I think the Default implementation for ColumnMap is broken. In the current code it is only used by take() when the row is replaced anyway, but I think the semantics of Default should be to give you a valid object. Would there be another solution? I guess we could store Option<WitnessColumnMap<T>> in the row, but also kind of annoying.

enum CellValue<T: FieldElement> {
Known(T),
RangeConstraint(RangeConstraint<T>),
#[default]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, didn't know this!

Copy link
Member Author

Choose a reason for hiding this comment

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

Me neither, but fortunately, clippy does!

}
#[derive(Clone, Default, PartialEq)]
pub struct Row<'a, T: FieldElement> {
/// The values in the row, zero if unknown.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why "zero if unknown"? It explicitly stores unknown, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

True, this was an old comment.

Comment on lines +102 to +109
impl<V, T: PolynomialTypeTrait> Default for ColumnMap<V, T> {
fn default() -> Self {
ColumnMap {
values: Vec::new(),
_ptype: PhantomData,
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, but this would fail, right?

let foo: WitnessColumnMap<u8> = Default::default();
foo[&any_poly_id] = 3;

The assumption that values has an entry for every possible key is violated.

};
f.write_str(&debug_str)
self.values = WitnessColumnMap::from(
std::mem::take(&mut self.values)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this take() is why you need ColumnMap to implement Default, right?

I just went through the two calls of merge_with and I think it is a small change for it to receive other: Row<'a, T>. So then you could call other.values_into_iter(). So you can trade cloning cell2 for cloning cell1, and don't need a broken Default implementation ^^


impl<T: FieldElement> Debug for Cell<'_, T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, maybe we could have a CellValue::render() function that takes a reference to FixedData? Now this code moved to Row::render_values, but I think it belongs to CellData!

Copy link
Member Author

Choose a reason for hiding this comment

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

Will move it.

Comment on lines +449 to +459
self.get_row_mut(poly.next).value_is_known(&poly.poly_id)
}

fn get_row_mut(&self, next: bool) -> &Row<'a, T> {
match next {
false => self.current,
true => self
.next
.unwrap_or_else(|| panic!("Tried to access next row, but it is not available.")),
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.get_row_mut(poly.next).value_is_known(&poly.poly_id)
}
fn get_row_mut(&self, next: bool) -> &Row<'a, T> {
match next {
false => self.current,
true => self
.next
.unwrap_or_else(|| panic!("Tried to access next row, but it is not available.")),
}
}
self.get_row(poly.next).value_is_known(&poly.poly_id)
}

Right?

executor/src/witgen/rows.rs Outdated Show resolved Hide resolved
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.

LGTM

@georgwiese georgwiese enabled auto-merge July 2, 2024 16:17
@georgwiese georgwiese added this pull request to the merge queue Jul 2, 2024
Merged via the queue into main with commit bb44126 Jul 2, 2024
5 of 6 checks passed
@georgwiese georgwiese deleted the create_row_struct branch July 2, 2024 17:24
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.

None yet

2 participants