feat(hako_check): Phase 153 - Dead code detection revival (JoinIR version)
Implement comprehensive dead code detection for hako_check with JoinIR integration, following Phase 133/134/152 box-based modularity pattern. ## Key Achievements 1. **Comprehensive Inventory** (`phase153_hako_check_inventory.md`): - Documented current hako_check architecture (872 lines) - Analyzed existing HC011/HC012 rules - Confirmed JoinIR-only pipeline (Phase 124) - Identified Phase 153 opportunities 2. **DeadCodeAnalyzerBox** (`rule_dead_code.hako`): - Unified HC019 rule (570+ lines) - Method-level + box-level dead code detection - DFS reachability from entrypoints - Text-based analysis (no MIR JSON dependency for MVP) - Heuristic-based false positive reduction 3. **CLI Integration** (`cli.hako`): - Added `--dead-code` flag for comprehensive mode - Added `--rules dead_code` for selective execution - Compatible with --format (text/json-lsp/dot) 4. **Test Infrastructure**: - HC019_dead_code test directory (ng/ok/expected.json) - `hako_check_deadcode_smoke.sh` with 4 test cases ## Technical Details - **Input**: Analysis IR (MapBox with methods/calls/boxes/entrypoints) - **Output**: HC019 diagnostics - **Algorithm**: Graph-based DFS reachability - **Pattern**: Box-based modular architecture - **No ENV vars**: CLI flags only ## Files Modified - NEW: docs/development/current/main/phase153_hako_check_inventory.md - NEW: tools/hako_check/rules/rule_dead_code.hako - MOD: tools/hako_check/cli.hako - NEW: tools/hako_check/tests/HC019_dead_code/ - NEW: tools/hako_check_deadcode_smoke.sh - MOD: CURRENT_TASK.md ## Next Steps - Phase 154+: MIR CFG integration for block-level detection - Phase 160+: Integration with .hako JoinIR/MIR migration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -17,6 +17,7 @@ using tools.hako_check.rules.rule_arity_mismatch as RuleArityMismatchBox
|
||||
using tools.hako_check.rules.rule_stage3_gate as RuleStage3GateBox
|
||||
using tools.hako_check.rules.rule_brace_heuristics as RuleBraceHeuristicsBox
|
||||
using tools.hako_check.rules.rule_analyzer_io_safety as RuleAnalyzerIoSafetyBox
|
||||
using tools.hako_check.rules.rule_dead_code as DeadCodeAnalyzerBox
|
||||
using tools.hako_check.render.graphviz as GraphvizRenderBox
|
||||
using tools.hako_parser.parser_core as HakoParserCoreBox
|
||||
|
||||
@ -43,11 +44,13 @@ static box HakoAnalyzerBox {
|
||||
// optional filters
|
||||
local rules_only = null // ArrayBox of keys
|
||||
local rules_skip = null // ArrayBox of keys
|
||||
local dead_code_mode = 0 // Phase 153: --dead-code flag
|
||||
// Support inline sources: --source-file <path> <text>. Also accept --debug and --format anywhere.
|
||||
while i < args.size() {
|
||||
local p = args.get(i)
|
||||
// handle options
|
||||
if p == "--debug" { debug = 1; i = i + 1; continue }
|
||||
if p == "--dead-code" { dead_code_mode = 1; i = i + 1; continue }
|
||||
if p == "--no-ast" { no_ast = 1; i = i + 1; continue }
|
||||
if p == "--force-ast" { no_ast = 0; i = i + 1; continue }
|
||||
if p == "--format" {
|
||||
@ -219,6 +222,17 @@ static box HakoAnalyzerBox {
|
||||
local added = after_n - before_n
|
||||
print("[hako_check/HC015] file=" + p + " added=" + me._itoa(added) + " total_out=" + me._itoa(after_n))
|
||||
}
|
||||
// Phase 153: HC019 Dead Code Analyzer (comprehensive)
|
||||
before_n = out.size()
|
||||
if dead_code_mode == 1 || me._rule_enabled(rules_only, rules_skip, "dead_code") == 1 {
|
||||
me._log_stderr("[rule/exec] HC019 (dead_code) " + p)
|
||||
DeadCodeAnalyzerBox.apply_ir(ir, p, out)
|
||||
}
|
||||
if debug == 1 {
|
||||
local after_n = out.size()
|
||||
local added = after_n - before_n
|
||||
print("[hako_check/HC019] file=" + p + " added=" + me._itoa(added) + " total_out=" + me._itoa(after_n))
|
||||
}
|
||||
// suppression: HC012(dead box) > HC011(unreachable method)
|
||||
local filtered = me._suppress_overlap(out)
|
||||
// flush (text only)
|
||||
@ -568,6 +582,7 @@ static box HakoAnalyzerBox {
|
||||
// Rules that need IR
|
||||
if k == "dead_methods" { return 1 }
|
||||
if k == "dead_static_box" { return 1 }
|
||||
if k == "dead_code" { return 1 }
|
||||
if k == "duplicate_method" { return 1 }
|
||||
if k == "missing_entrypoint" { return 1 }
|
||||
if k == "arity_mismatch" { return 1 }
|
||||
|
||||
Reference in New Issue
Block a user