refactor: extract get_module_wrapper helper in InitiaModuleStorage#249
refactor: extract get_module_wrapper helper in InitiaModuleStorage#249
Conversation
Centralizes the repeated preamble (ModuleId construction + checksum fetch + cache lookup) shared by all 6 ModuleStorage trait methods into a single private helper, reducing boilerplate by ~30 lines. All 11 storage crate tests pass with no behavioral changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdded an inherent helper Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant IMS as InitiaModuleStorage
participant BS as BaseStorage
participant MC as ModuleCache
Caller->>IMS: request module (address, name)
IMS->>IMS: construct ModuleId
IMS->>BS: fetch checksum(module_id)
alt checksum found
BS-->>IMS: checksum
IMS->>MC: get_module_or_build_with(module_id, checksum, context)
MC-->>IMS: ModuleWrapper
IMS-->>Caller: Ok(Some(module_id, checksum, wrapper))
else checksum missing
BS-->>IMS: None
IMS-->>Caller: Ok(None)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/storage/src/module_storage.rs (1)
194-208: Reuseget_module_wrapperin dependency traversal too.This removes the duplication from the trait methods, but Lines 331-343 still inline the same
ModuleId+ checksum + cache lookup sequence. Pulling that path onto this helper would keep module resolution behavior aligned in one place.♻️ Possible follow-up
let (dependency_id, dependency_checksum, dependency) = module_cache_with_context .get_module_wrapper(addr, name)? .ok_or_else(|| module_linker_error!(addr, name))?;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/storage/src/module_storage.rs` around lines 194 - 208, The dependency traversal duplicates the ModuleId + checksum + cache lookup logic; refactor to call the existing get_module_wrapper(&self, address, module_name) helper from the traversal code (replace the inline ModuleId::new(...), fetch_checksum(...), and module_cache.get_module_or_build_with(...) sequence). Unwrap the Option with ok_or_else(|| module_linker_error!(addr, name)) to return the linker error when missing, e.g. let (dependency_id, dependency_checksum, dependency) = self.get_module_wrapper(addr, name)? .ok_or_else(|| module_linker_error!(addr, name))?; ensuring you use the same checksum and ModuleWrapper types as before so resolution behavior stays centralized in get_module_wrapper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/storage/src/module_storage.rs`:
- Around line 194-208: The dependency traversal duplicates the ModuleId +
checksum + cache lookup logic; refactor to call the existing
get_module_wrapper(&self, address, module_name) helper from the traversal code
(replace the inline ModuleId::new(...), fetch_checksum(...), and
module_cache.get_module_or_build_with(...) sequence). Unwrap the Option with
ok_or_else(|| module_linker_error!(addr, name)) to return the linker error when
missing, e.g. let (dependency_id, dependency_checksum, dependency) =
self.get_module_wrapper(addr, name)? .ok_or_else(|| module_linker_error!(addr,
name))?; ensuring you use the same checksum and ModuleWrapper types as before so
resolution behavior stays centralized in get_module_wrapper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dec26092-17c6-4d65-a46b-82bec7dfd258
📒 Files selected for processing (1)
crates/storage/src/module_storage.rs
Per CodeRabbit review, apply the same helper to visit_dependencies_and_verify, removing another instance of the inlined ModuleId + checksum + cache lookup pattern. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/storage/src/module_storage.rs (1)
191-193: Clarify the helper’sNonevsErrcontract.The wording here blurs two different outcomes: missing module data returns
Ok(None), while deserialization/checksum failures still bubble up asErr. Tightening the comment would make the helper’s behavior clearer for future callers.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/storage/src/module_storage.rs` around lines 191 - 193, Update the documentation for the helper that "Resolves a module by address and name" to explicitly state its Result contract: document that when the module checksum or stored data is missing the function returns Ok(None), when the module is successfully found and built it returns Ok(Some(module)), and when deserialization or checksum validation fails the function returns Err(...) propagating the underlying error; mention the exact behavior for checksum lookup, cache build, and deserialization so callers of this helper (the resolve-by-address-and-name helper in module_storage.rs) can unambiguously handle Ok(None) vs Err.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/storage/src/module_storage.rs`:
- Around line 191-193: Update the documentation for the helper that "Resolves a
module by address and name" to explicitly state its Result contract: document
that when the module checksum or stored data is missing the function returns
Ok(None), when the module is successfully found and built it returns
Ok(Some(module)), and when deserialization or checksum validation fails the
function returns Err(...) propagating the underlying error; mention the exact
behavior for checksum lookup, cache build, and deserialization so callers of
this helper (the resolve-by-address-and-name helper in module_storage.rs) can
unambiguously handle Ok(None) vs Err.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 93ee28b5-3cc0-4ec4-81b8-eebf654076e0
📒 Files selected for processing (1)
crates/storage/src/module_storage.rs
Per CodeRabbit review, explicitly document Ok(Some), Ok(None), and Err semantics in the helper's doc comment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
ModuleStoragetrait methods into a singleget_module_wrapperprivate helperDetails
Every
ModuleStoragetrait method inInitiaModuleStoragerepeated:The new
get_module_wrapperreturnsOption<(ModuleId, Checksum, ModuleWrapper)>— the tuple includes all three becausefetch_verified_moduleneedsidandchecksumfor dependency verification. Other methods destructure with(_, _, module).Test plan
cargo check -p initia-move-storagepassescargo test -p initia-move-storage— all 11 tests pass🤖 Generated with Claude Code
Summary by CodeRabbit