WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reanalyze: make optional args analysis liveness-aware
Optional argument analysis now only considers calls from live code when
determining which optional arguments are unused. This prevents false
positives when a function is only called from dead code.
Changes:
- Add pos_from to optional_arg_call to track caller binding position
- Add is_live predicate to compute_optional_args_state
- Two-pass solve: first compute deadness, then optional args with liveness
- Add Decl.isLive helper to simplify repeated liveness checks
- Update ARCHITECTURE.md to document the two-pass approach
Signed-Off-By: Cristiano Calcagno <[email protected]>
**Algorithm** (two-pass for liveness-aware optional args):
162
+
163
+
**Pass 1: Core deadness resolution**
159
164
1. Build file dependency order (roots to leaves)
160
165
2. Sort declarations by dependency order
161
166
3. For each declaration, resolve references recursively
162
167
4. Determine dead/live status based on reference count
163
168
5. Collect issues for dead declarations
164
169
165
-
**Key property**: Pure function - immutable in, immutable out. No side effects.
170
+
**Pass 2: Liveness-aware optional args analysis**
171
+
1. Use `Decl.isLive` to build an `is_live` predicate from Pass 1 results
172
+
2. Compute optional args state via `CrossFileItems.compute_optional_args_state`, filtering out calls from dead code
173
+
3. Collect optional args issues only for live declarations
174
+
4. Merge optional args issues into the final result
175
+
176
+
This two-pass approach ensures that optional argument warnings (e.g., "argument X is never used") only consider calls from live code, preventing false positives when a function is only called from dead code.
177
+
178
+
**Key property**: Pure functions - immutable in, immutable out. No side effects.
0 commit comments