Skip to main content

seqc/
resource_lint.rs

1//! Resource Leak Detection (Phase 2a)
2//!
3//! Data flow analysis to detect resource leaks within single word definitions.
4//! Tracks resources (weave handles, channels) through stack operations and
5//! control flow to ensure proper cleanup.
6//!
7//! # Architecture
8//!
9//! 1. **Resource Tagging**: Values from resource-creating words are tagged
10//!    with their creation location.
11//!
12//! 2. **Stack Simulation**: Abstract interpretation tracks tagged values
13//!    through stack operations (dup, swap, drop, etc.).
14//!
15//! 3. **Control Flow**: If/else and match branches must handle resources
16//!    consistently - either all consume or all preserve.
17//!
18//! 4. **Escape Analysis**: Resources returned from a word are the caller's
19//!    responsibility - no warning emitted.
20//!
21//! # Known Limitations
22//!
23//! - **`strand.resume` completion not tracked**: When `strand.resume` returns
24//!   false, the weave completed and handle is consumed. We can't determine this
25//!   statically, so we assume the handle remains active. Use pattern-based lint
26//!   rules to catch unchecked resume results.
27//!
28//! - **Unknown word effects**: User-defined words and FFI calls have unknown
29//!   stack effects. We conservatively leave the stack unchanged, which may
30//!   cause false negatives if those words consume or create resources.
31//!
32//! - **Cross-word analysis is basic**: Resources returned from user-defined
33//!   words are tracked via `ProgramResourceAnalyzer`, but external/FFI words
34//!   with unknown effects are treated conservatively (no stack change assumed).
35
36mod program;
37mod state;
38mod word;
39
40#[cfg(test)]
41mod tests;
42
43pub use program::ProgramResourceAnalyzer;
44pub use word::ResourceAnalyzer;