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>
2.3 KiB
2.3 KiB
Function Values, Captures, and Events
Status: Behavior summary(現仕様サマリ兼設計ノート)
Note: 関数値 / キャプチャ / イベントに関する現行挙動の要約です。詳細仕様はdocs/reference/language/や関連アーキテクチャドキュメントを正として参照してください。
Summary of current behavior and guidelines.
- Function values: created via
function(...) { ... }produce aFunctionBoxwith captured environment (by-ref for locals viaRefCellBox, by-value for globals/statics) and optional weakme. - Assignment cell reflection: assigning to a variable or field bound to
RefCellBoxupdates the inner value instead of replacing the cell. this → me: inside methods,thisis bound asmefor field/method access. External code should preferme.- Parent:: syntax: parser groundwork exists for
Parent::methodreferences; calling from child uses from-call lowering. ?(propagate):expr ?lowers toisOk/getValuebranching and returns early with the Result on error.peek: tokenized and parsed; desugars to if-else chain in VM.
Event APIs
- P2PBox.on/onOnce/off: handlers now accept both
MethodBoxandFunctionBox.MethodBoxhandlers invoke the bound method on receive with arguments(intent, from).FunctionBoxhandlers execute the function body with params bound from(intent, from)(excess args ignored).
Notes
- RefCell-backed locals captured by closures will reflect assignments (
x = ...) in the outer scope. - For plugin-backed boxes, assignment and argument passing uses share semantics to preserve identity.
MIR/VM call unification (Phase 12)
- MIR
Call: accepts either a function name (String) or aFunctionBoxvalue.- If the callee is a String, VM performs a named-function dispatch (existing path).
- If the callee is a
FunctionBox(BoxRef), VM runs it via the interpreter helper with captures/meinjected and proper return propagation.
- Lambda immediate calls are still directly lowered inline for P1 compatibility.
- Lambda→FunctionBox: Lambda expressions now lower to a
NewClosureMIR instruction that constructs aFunctionBoxvalue (minimal: captures currently omitted). This enables MIR-only pipelines to construct and call function values.