refactor(env): centralize NYASH_JOINIR_STRUCTURE_ONLY flag

Moved NYASH_JOINIR_STRUCTURE_ONLY environment variable handling
from inline std::env::var() in routing.rs to a centralized helper
function in src/config/env/joinir_flags.rs.

Changes:
- Added joinir_structure_only_enabled() helper function
- Replaced direct env::var() call in routing.rs with helper
- Maintains existing behavior: default ON, NYASH_JOINIR_STRUCTURE_ONLY=0/off to disable
- Follows env module centralization pattern (Box Theory: separation of concerns)

Testing:
- cargo test --lib: 1126 passed 
- Regression: Phase 107 VM smoke 
- Phase 113/114 maintained 

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-18 02:19:14 +09:00
parent 80be814fa4
commit ce7e2c1b91
2 changed files with 30 additions and 4 deletions

View File

@ -183,3 +183,32 @@ pub fn loopform_normalize() -> bool {
pub fn is_joinir_debug() -> bool {
std::env::var("HAKO_JOINIR_DEBUG").is_ok() || std::env::var("NYASH_JOINIR_DEBUG").is_ok()
}
/// JoinIR structure-only routing mode (Phase 196+).
///
/// When enabled (default), routes loops based purely on structure analysis,
/// skipping the legacy function name whitelist.
///
/// - Default: ON (structure_only = true) - all loops use JoinIR patterns
/// - To revert to whitelist-only: `NYASH_JOINIR_STRUCTURE_ONLY=0` or `=off`
///
/// # Compatibility
///
/// - `NYASH_JOINIR_STRUCTURE_ONLY=0` or `=off` → false
/// - Any other value (including unset) → true
///
/// # Usage
///
/// ```rust
/// if joinir_structure_only_enabled() {
/// // Route all loops through JoinIR pattern analysis
/// } else {
/// // Use legacy whitelist routing
/// }
/// ```
pub fn joinir_structure_only_enabled() -> bool {
match std::env::var("NYASH_JOINIR_STRUCTURE_ONLY").ok().as_deref() {
Some("0") | Some("off") => false,
_ => true,
}
}

View File

@ -183,10 +183,7 @@ impl MirBuilder {
// Phase 196: Default to structure-first routing now that LoopBuilder is removed.
// - Default: ON (structure_only = true) to allow JoinIR patterns to run for all loops.
// - To revert to the previous whitelist-only behavior, set NYASH_JOINIR_STRUCTURE_ONLY=0.
let structure_only = match std::env::var("NYASH_JOINIR_STRUCTURE_ONLY").ok().as_deref() {
Some("0") | Some("off") => false,
_ => true,
};
let structure_only = crate::config::env::joinir_structure_only_enabled();
if structure_only {
trace::trace().routing(