feat(joinir): Phase 170-4 Structure-based routing opt-in

Add NYASH_JOINIR_STRUCTURE_ONLY=1 environment variable to bypass
function name whitelist and route purely based on loop structure.

When enabled:
- Skips hardcoded function name whitelist (13 entries)
- Routes directly to pattern detection (LoopPatternContext)
- Falls back to legacy LoopBuilder if no pattern matches

This is Phase 1 of structure-based routing migration:
- Phase 1: Opt-in via env flag (this commit) 
- Phase 2: Make structure-based default (future)
- Phase 3: Remove whitelist entirely (future)

Verified:
- test_loop_return.hako → RC: 2 
- test_trim_loop.hako → RC: 3 

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-07 13:03:43 +09:00
parent 7470bebb0b
commit 7a9ebf7fc1

View File

@ -35,7 +35,18 @@ impl MirBuilder {
// Phase 195: Use unified trace // Phase 195: Use unified trace
trace::trace().routing("router", &func_name, "try_cf_loop_joinir called"); trace::trace().routing("router", &func_name, "try_cf_loop_joinir called");
// Phase 49-4 + Phase 80: Multi-target routing // Phase 170-4: Structure-based routing option
// When NYASH_JOINIR_STRUCTURE_ONLY=1, skip function name whitelist
// and route purely based on loop structure analysis
let structure_only = std::env::var("NYASH_JOINIR_STRUCTURE_ONLY")
.ok()
.as_deref()
== Some("1");
if structure_only {
trace::trace().routing("router", &func_name, "Structure-only mode enabled, skipping whitelist");
} else {
// Phase 49-4 + Phase 80: Multi-target routing (legacy whitelist)
// - Core ON なら代表2本print_tokens / ArrayExt.filterは JoinIR を優先し、失敗したら LoopBuilder へフォールバック // - Core ON なら代表2本print_tokens / ArrayExt.filterは JoinIR を優先し、失敗したら LoopBuilder へフォールバック
// - Core OFF では従来通り dev フラグで opt-in // - Core OFF では従来通り dev フラグで opt-in
// Note: Arity does NOT include implicit `me` receiver // Note: Arity does NOT include implicit `me` receiver
@ -83,6 +94,7 @@ impl MirBuilder {
if !is_target { if !is_target {
return Ok(None); return Ok(None);
} }
}
// Debug log when routing through JoinIR Frontend // Debug log when routing through JoinIR Frontend
// Phase 195: Check trace flags directly from JoinLoopTrace // Phase 195: Check trace flags directly from JoinLoopTrace