From ce7e2c1b915a6bb93d9744e01335520f527b297c Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Thu, 18 Dec 2025 02:19:14 +0900 Subject: [PATCH] refactor(env): centralize NYASH_JOINIR_STRUCTURE_ONLY flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/config/env/joinir_flags.rs | 29 +++++++++++++++++++ .../builder/control_flow/joinir/routing.rs | 5 +--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/config/env/joinir_flags.rs b/src/config/env/joinir_flags.rs index b3f74812..78ca5ca9 100644 --- a/src/config/env/joinir_flags.rs +++ b/src/config/env/joinir_flags.rs @@ -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, + } +} diff --git a/src/mir/builder/control_flow/joinir/routing.rs b/src/mir/builder/control_flow/joinir/routing.rs index 4f659678..b6ede26b 100644 --- a/src/mir/builder/control_flow/joinir/routing.rs +++ b/src/mir/builder/control_flow/joinir/routing.rs @@ -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(