Conversation
First step of SharedComm decomposition: extract the 11 motor mode methods (motor_mode, set_motor_mode, transition, armed/running/ old_routine/stepper_sine + setters) into a dedicated MotorState trait. SharedComm now requires MotorState as a super-trait. SharedState and TestShared implement MotorState separately. Callers using SharedComm as a trait bound get MotorState methods automatically; callers using concrete types need MotorState imported. This is the pilot for the sub-trait pattern described in SHAREDCOMM_AUDIT.md — validates the approach before extracting IsrTiming and MainControl.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR extracts motor-mode APIs into a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
There was a problem hiding this comment.
Sorry @kaidokert, you have reached your weekly rate limit of 1500000 diff characters.
Please try again later or upgrade to continue using Sourcery
❌ 2 Tests Failed:
View the full list of 2 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Code Review
This pull request refactors the SharedComm trait by decomposing it into sub-traits, specifically introducing the MotorState trait to handle motor mode state transitions. The changes are applied to the test implementation, the trait definitions, and the hardware-backed SharedState. A significant issue was identified in the SharedState implementation of MotorState: it fails to override convenience setters like set_armed, which leads to the use of non-atomic default implementations. This could introduce race conditions, so these methods should delegate to the existing atomic inherent methods in SharedState.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rm32/src/shared_comm.rs (1)
22-26: ⚡ Quick winCapture mode once in default
transition()to avoid double-read drift.Line 23 and Line 24 read
motor_mode()separately. Snapshotting once makes the default path deterministic and slightly cheaper.Suggested diff
fn transition(&self, event: MotorEvent) { - let new = self.motor_mode().transition(event); - if new != self.motor_mode() { + let current = self.motor_mode(); + let new = current.transition(event); + if new != current { self.set_motor_mode(new); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@rm32/src/shared_comm.rs` around lines 22 - 26, The default transition() reads motor_mode() twice which can drift or be non-deterministic; capture the current mode once into a local (e.g., let current = self.motor_mode()), call current.transition(event) (or use current to derive new), compare new != current, and only then call self.set_motor_mode(new); update the transition() method to use these symbols (transition, motor_mode, set_motor_mode) so the motor mode is snapshotted once.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@rm32/src/shared_comm.rs`:
- Around line 22-26: The default transition() reads motor_mode() twice which can
drift or be non-deterministic; capture the current mode once into a local (e.g.,
let current = self.motor_mode()), call current.transition(event) (or use current
to derive new), compare new != current, and only then call
self.set_motor_mode(new); update the transition() method to use these symbols
(transition, motor_mode, set_motor_mode) so the motor mode is snapshotted once.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0a3ee150-6acd-43ea-a4bf-94046e01c18b
📒 Files selected for processing (4)
rm32/src/control/shared_impl.rsrm32/src/control/tests.rsrm32/src/shared_comm.rsrm32/src/shared_state.rs
The trait default implementations use non-atomic load+store. SharedState has atomic fetch_update inherent methods for set_armed, set_running, set_old_routine, set_stepper_sine. Override the trait methods to delegate to those, preventing race conditions when accessed through the MotorState trait.
Summary
First step of SharedComm decomposition (SHAREDCOMM_AUDIT.md):
Extract the 11 motor mode methods into a dedicated
MotorStatetrait:motor_mode(),set_motor_mode()— required (2 methods)transition()— default impl using MotorEventarmed(),running(),old_routine(),stepper_sine()— derived gettersset_armed(),set_running(),set_old_routine(),set_stepper_sine()— convenience settersSharedComm: MotorState— super-trait requirement, so all existingSharedCommcallers get MotorState methods automatically.SharedState and TestShared implement MotorState in separate impl blocks.
This validates the sub-trait pattern before extracting IsrTiming and
MainControl in subsequent PRs.
Test plan
Summary by CodeRabbit