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(