Conversation
Results
Code reduction: 51 net lines removed (112 deletions, 61 insertions)
- File went from 1,894 → 1,843 lines
Key changes:
1. New simulate_word_common function (lines 440-563)
- Handles all shared operations: resource creation/consumption, basic stack ops, strand.spawn, map/list storage, user-defined words
- Takes a closure on_resource_dropped for diagnostic emission
- Returns bool indicating if word was handled
2. Simplified simulate_word_call (lines 565-569)
- Now just 4 lines: calls shared helper with no-op callback
3. Simplified analyze_word_call_with_context (lines 666-804)
- Calls shared helper, collects dropped resources, emits warnings
- Only contains pass-specific operations: strand.resume, over, rot, nip, tuck, 2dup, 3drop, pick, roll, chan.send/receive
Benefits:
- Single source of truth for resource simulation logic
- Bug fixes now only need to be applied once
- Easier to maintain and extend
- All 15 resource_lint tests pass
- No clippy warnings
#208 Results Code changes: - app.rs: -190 net lines (207 deleted, 17 added) - New stack_effects.rs: 185 lines (includes tests) - stack_art.rs: +10 lines (literal helper) - mod.rs: +1 line Net effect: The 215-line match statement is now a 15-line function that delegates to a declarative data table. Key improvements: 1. Declarative definitions - Effects defined concisely: effect(&mut m, "dup", &["x"], &["x", "x"]); effect(&mut m, "swap", &["x", "y"], &["y", "x"]); typed_effect(&mut m, "i.+", &["Int", "Int"], &["Int"]); 2. Easy to extend - Adding new effects is one line 3. Static table - Effects compiled once using LazyLock 4. Unit tests - 4 new tests for the effects module 5. Clean separation - Effects logic isolated in ir/stack_effects.rs All 67 REPL tests pass, no clippy warnings.
Code Review: Refactoring 0108This PR successfully addresses issues #207 and #208 by deduplicating word simulation logic and extracting stack effects into a data structure. The refactoring is well-executed overall with some areas for consideration. ✅ Strengths1. Excellent Deduplication in
|
Fixes Applied ┌────────────────────────┬─────────────────┬─────────────────────────────────────────────────────────────────────────┐ │ Issue │ Status │ Change │ ├────────────────────────┼─────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ Critical: dup behavior │ Fixed │ Removed push_unknown() on empty stack - now matches original first-pass │ ├────────────────────────┼─────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ Missing stack effects │ Already present │ over, rot, nip, tuck were already in stack_effects.rs │ ├────────────────────────┼─────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ Consolidate stack ops │ Done │ Moved over, rot, nip, tuck from second-pass to simulate_word_common │ └────────────────────────┴─────────────────┴─────────────────────────────────────────────────────────────────────────┘ Changes to resource_lint.rs - simulate_word_common now handles: dup, drop, swap, over, rot, nip, tuck, strand.spawn, map.set, list.push/prepend - analyze_word_call_with_context now only handles: strand.resume, 2dup, 3drop, pick, roll, chan.send/receive - nip uses the callback pattern for dropped resources (like drop does) - All 15 resource_lint tests pass The reviewer's other suggestions (extract common stack-building helper, add integration test, profile resource cloning) are "nice to have" and can be addressed in future PRs.
Code Review - PR #216: Refactoring 0108This PR successfully addresses issues #207 and #208 with well-executed refactoring. The changes demonstrate strong engineering practices and significantly improve code maintainability. ✅ StrengthsIssue #207: Resource Lint Deduplication
Issue #208: Stack Effects Extraction
🔍 Code Quality Observationsresource_lint.rs:440-613Good:
Potential Improvements:
stack_effects.rs:1-220Good:
Minor suggestions:
🛡️ Security & CorrectnessNo security concerns identified. The changes are purely internal refactoring with:
Correctness:
📊 Test CoverageExisting tests appear adequate:
Recommendation: Consider adding an integration test that verifies first-pass and second-pass produce identical stack states (excluding diagnostics). This would catch any future divergence in the shared logic. 🎯 Performance ConsiderationsLazyLock usage (stack_effects.rs:11): Excellent choice. The effects table is computed once at first access and reused. Zero runtime overhead after initialization. Resource cloning (resource_lint.rs:561-568, 547): Minor concern - resources are cloned during 📝 DocumentationWell documented overall:
Could add:
✨ Overall AssessmentThis is high-quality refactoring work:
Net change: -27 lines with dramatically improved maintainability. ✅ Recommendation: Approve with minor suggestionsThe PR successfully achieves its goals and can be merged. The minor suggestions above (edge case handling, potential integration test) can be addressed in follow-up PRs if desired. Great work addressing technical debt while maintaining code quality! 🎉 |
#207
#208