Expand description
Resource Leak Detection (Phase 2a)
Data flow analysis to detect resource leaks within single word definitions. Tracks resources (weave handles, channels) through stack operations and control flow to ensure proper cleanup.
§Architecture
-
Resource Tagging: Values from resource-creating words are tagged with their creation location.
-
Stack Simulation: Abstract interpretation tracks tagged values through stack operations (dup, swap, drop, etc.).
-
Control Flow: If/else and match branches must handle resources consistently - either all consume or all preserve.
-
Escape Analysis: Resources returned from a word are the caller’s responsibility - no warning emitted.
§Known Limitations
-
strand.resumecompletion not tracked: Whenstrand.resumereturns false, the weave completed and handle is consumed. We can’t determine this statically, so we assume the handle remains active. Use pattern-based lint rules to catch unchecked resume results. -
Unknown word effects: User-defined words and FFI calls have unknown stack effects. We conservatively leave the stack unchanged, which may cause false negatives if those words consume or create resources.
-
Cross-word analysis is basic: Resources returned from user-defined words are tracked via
ProgramResourceAnalyzer, but external/FFI words with unknown effects are treated conservatively (no stack change assumed).
Structs§
- Branch
Merge Result - Result of merging two branch states
- Inconsistent
Resource - A resource handled differently in different branches
- Program
Resource Analyzer - Program-wide resource analyzer for cross-word analysis
- Resource
Analyzer - The resource leak analyzer (single-word analysis)
- Stack
State - State of the abstract stack during analysis
- Tracked
Resource - A tracked resource with its origin
- Word
Resource Info - Information about a word’s resource behavior
Enums§
- Resource
Kind - Identifies a resource type for tracking
- Stack
Value - A value on the abstract stack - either a resource or unknown