Conversation
Summary: Proper Branch Join
What was implemented:
1. StackState::join() method - Computes a proper lattice join:
- Resources present in EITHER branch are tracked
- Resources only marked consumed if consumed in BOTH branches
- Handles different stack structures between branches
2. Updated analyze_if - Now uses then_state.join(&else_state) instead of just then_state
3. Updated analyze_match - Uses reduce(|acc, s| acc.join(&s)) to join all arm states
4. New tests:
- test_else_branch_only_leak - Catches leaks in else branch
- test_branch_join_both_consume - No warning when both branches consume
- test_branch_join_neither_consume - Warning when drop happens after branches
…was implemented:
Changes made:
1. crates/compiler/src/resource_lint.rs:
- Added ProgramResourceAnalyzer (~500 lines) for cross-word resource tracking
- Two-pass analysis: first pass collects word resource info, second pass uses it
- Added map.set and list.push/list.prepend as known safe destinations for resources
- Updated module docs to reflect cross-word analysis capability
- Added 3 new tests for cross-word tracking
2. crates/compiler/src/lib.rs:
- Exported ProgramResourceAnalyzer
3. crates/compiler/src/main.rs:
- Updated lint_file() to use ProgramResourceAnalyzer::analyze_program() instead of per-word analysis
Cross-word analysis now detects:
- Resources returned from user-defined words (tracked as caller's responsibility)
- Multi-level call chains (e.g., wrap-chan calls make-chan calls chan.make)
- Resources safely stored in maps/lists (no false positive)
All 221+ Rust tests and 123 integration tests pass.
Pull Request Review: Trace option 2bSummaryThis PR implements Phase 2b of resource leak detection, adding cross-word analysis and proper branch joining for resource tracking. This is a significant improvement over Phase 2a, which only performed single-word analysis and used conservative (then-branch-only) state merging. Code Quality: ✅ ExcellentStrengths
Potential Issues Found🟡 Medium: Code Duplication Between AnalyzersLocation: The Recommendation: Consider refactoring to share the core logic, perhaps with a trait or a shared internal method that takes a "emit diagnostics" flag. 🟡 Medium: Potential False Negatives with
|
No description provided.