refactor(vm): Eliminate code duplication in UnifiedMemory using macro#549
Closed
letmehateu wants to merge 1 commit intonexus-xyz:mainfrom
Closed
refactor(vm): Eliminate code duplication in UnifiedMemory using macro#549letmehateu wants to merge 1 commit intonexus-xyz:mainfrom
letmehateu wants to merge 1 commit intonexus-xyz:mainfrom
Conversation
SashaMalysehko
pushed a commit
to SashaMalysehko/nexus-zkvm
that referenced
this pull request
Dec 9, 2025
Contributor
|
I think I'm going to pass on this, the macro is a bit too clunky to be worth the DRY savings. Clarity is more important. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Describe your changes.
Introduces a declarative macro to eliminate ~120 lines of duplicated code in
vm/src/memory/unified.rs. Three nearly identical methods (addr_val_bytes,segment_words,segment_bytes) are now generated using thedispatch_method!macro.Three methods contained almost identical dispatch logic:
addr_val_bytes()- ~40 linessegment_words()- ~40 linessegment_bytes()- ~40 linesThe only differences were:
This duplication made the code harder to maintain - any change to the dispatch logic required updating all three methods identically.