Files
hakorune/tools/hako_check/rules/rule_dead_static_box.hako
nyash-codex fa3091061d trace: add execution route visibility + debug passthrough; phase2170 canaries; docs
- Add HAKO_TRACE_EXECUTION to trace executor route
  - Rust hv1_inline: stderr [trace] executor: hv1_inline (rust)
  - Hakovm dispatcher: stdout [trace] executor: hakovm (hako)
  - test_runner: trace lines for hv1_inline/core/hakovm routes
- Add HAKO_VERIFY_SHOW_LOGS and HAKO_DEBUG=1 (enables both)
  - verify_v1_inline_file() log passthrough with numeric rc extraction
  - test_runner exports via HAKO_DEBUG
- Canary expansion under phase2170 (state spec)
  - Array: push×5/10 → size, len/length alias, per‑recv/global, flow across blocks
  - Map: set dup-key non-increment, value_state get/has
  - run_all.sh: unify, remove SKIPs; all PASS
- Docs
  - ENV_VARS.md: add Debug/Tracing toggles and examples
  - PLAN.md/CURRENT_TASK.md: mark 21.7 green, add Quickstart lines

All changes gated by env vars; default behavior unchanged.
2025-11-08 23:45:29 +09:00

92 lines
3.0 KiB
Plaintext

// tools/hako_check/rules/rule_dead_static_box.hako — HC012: Dead Static Box
// Detect static boxes that are never referenced from any code path.
// Excludes Main box (entry point) and boxes referenced in calls.
static box RuleDeadStaticBoxBox {
// Local int_to_str helper (avoids using alias issues)
_itoa(n) {
local v = 0 + n
if v == 0 { return "0" }
local out = ""
local digits = "0123456789"
local tmp = ""
loop (v > 0) {
local d = v % 10
tmp = digits.substring(d, d+1) + tmp
v = v / 10
}
out = tmp
return out
}
method apply_ir(ir, path, out) {
local boxes = ir.get("boxes")
if boxes == null { return 0 }
local calls = ir.get("calls")
if calls == null { return 0 }
// Collect all box names that are referenced in calls
local referenced_boxes = new MapBox()
local ci = 0
while ci < calls.size() {
local call = calls.get(ci)
if call == null { ci = ci + 1; continue }
local to = call.get("to")
if to != null {
// Extract box name from qualified call (e.g., "Box.method/0" -> "Box")
local dot = to.indexOf(".")
if dot > 0 {
local box_name = to.substring(0, dot)
referenced_boxes.set(box_name, "1")
}
}
ci = ci + 1
}
// Check each box
local bi = 0
while bi < boxes.size() {
local box_info = boxes.get(bi)
if box_info == null { bi = bi + 1; continue }
local name = box_info.get("name")
if name == null { bi = bi + 1; continue }
local is_static = box_info.get("is_static")
// Skip Main box (entry point)
if name == "Main" { bi = bi + 1; continue }
// Only check static boxes (tolerant):
// treat missing is_static as static (scanner sets it only for static box),
// skip only when explicitly false/0
if is_static != null { if is_static == 0 { bi = bi + 1; continue } }
// Check if box is referenced - if not in map, it returns "[map/missing]" StringBox
local ref_check = referenced_boxes.get(name)
// If ref_check is null or doesn't equal "1", box is unreferenced
if ref_check == null || ref_check != "1" {
// Box is never referenced - report error
// Line precision: prefer span_line from AST intake if present.
// MapBox missing may yield a sentinel String (e.g., "0[map/missing] ...").
// Convert via string and extract leading digits; default to 1.
local line_any = box_info.get("span_line")
local line_s = ""
if line_any == null { line_s = "1" } else { line_s = "" + line_any }
// parse leading digits
local i = 0; local digits = ""
while i < line_s.length() { local ch = line_s.substring(i,i+1); if ch>="0" && ch<="9" { digits = digits + ch; i = i + 1; continue } break }
if digits == "" { digits = "1" }
out.push("[HC012] dead static box (never referenced): " + name + " :: path:" + digits)
}
bi = bi + 1
}
return out.size()
}
}
static box RuleDeadStaticBoxMain { method main(args) { return 0 } }