refactor: De-couple Chips from a specific ExecutionRecord, part II#37
Closed
huitseeker wants to merge 3 commits into
Closed
refactor: De-couple Chips from a specific ExecutionRecord, part II#37huitseeker wants to merge 3 commits into
huitseeker wants to merge 3 commits into
Conversation
Previously: #9 This applies the same logic to output events in `generate_trace`. ```rust // implemented on the chip trait WithEvents<'a> { type InputEvents : 'a; type OutputEvents: 'a; } // implemented on the record trait EventLens<T: for <'a> WithEvent<'a>> { fn events<'a>(&'a self) -> <T as WithEvents<'a>>::InputEvents; } // implemented on the record trait EventMutLens<T: for <'a> WithEvent<'a>> { fn events<'a>(&'a mut self, events: <T as WithEvents<'a>>::OutputEvents); } ``` Now, one would wish that this would be a bit more ergonomic in Rust, because we do have anonymous cartesian products of arbitrary arity (tuples), but we do not have anonymous coproducts - either crate notwithstanding. ```rust pub enum DivRemEvent<'a> { ByteLookupEvent(&'a ByteLookupEvent), MulEvent(&'a AluEvent), LtEvent(&'a AluEvent), } impl<'a> WithEvents<'a> for DivRemChip { type InputEvents = &'a [AluEvent]; type OutputEvents = [DivRemEvent<'a>]; } impl EventMutLens<DivRemChip> for ExecutionRecord { fn add_events(&mut self, events: <DivRemChip as crate::air::WithEvents<'_>>::OutputEvents) { for event in events { match event { DivRemEvent::ByteLookupEvent(e) => self.add_byte_lookup_event(*e), DivRemEvent::MulEvent(e) => self.add_mul_event(*e), DivRemEvent::LtEvent(e) => self.add_lt_event(*e), } } } } ```
96d407d to
c644068
Compare
c644068 to
6300ea1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously: #9
This applies the same logic to output events in
generate_trace.General approach
Now, one would wish that this would be a bit more ergonomic in Rust, because we do have anonymous cartesian products of arbitrary arity (tuples), but we do not have anonymous coproducts - either crate notwithstanding.
DivRemChip Example