Skip to content

refactor(vm): Eliminate code duplication in UnifiedMemory using macro#549

Closed
letmehateu wants to merge 1 commit intonexus-xyz:mainfrom
letmehateu:main
Closed

refactor(vm): Eliminate code duplication in UnifiedMemory using macro#549
letmehateu wants to merge 1 commit intonexus-xyz:mainfrom
letmehateu:main

Conversation

@letmehateu
Copy link

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 the dispatch_method! macro.

Three methods contained almost identical dispatch logic:

  • addr_val_bytes() - ~40 lines
  • segment_words() - ~40 lines
  • segment_bytes() - ~40 lines

The only differences were:

  • Method name being called on the underlying store
  • Parameters passed to the method
  • Return type

This duplication made the code harder to maintain - any change to the dispatch logic required updating all three methods identically.

SashaMalysehko pushed a commit to SashaMalysehko/nexus-zkvm that referenced this pull request Dec 9, 2025
@sjudson
Copy link
Contributor

sjudson commented Dec 9, 2025

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.

@sjudson sjudson closed this Dec 9, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants