Refine normalized bridge direct path and env guard
This commit is contained in:
38
src/mir/join_ir/normalized/dev_env.rs
Normal file
38
src/mir/join_ir/normalized/dev_env.rs
Normal file
@ -0,0 +1,38 @@
|
||||
#![cfg(feature = "normalized_dev")]
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// RAII guard for normalized_dev env toggling (NYASH_JOINIR_NORMALIZED_DEV_RUN).
|
||||
/// 汚染防止のため tests/runner の両方で再利用できるようにここに置く。
|
||||
pub struct NormalizedDevEnvGuard {
|
||||
_lock: std::sync::MutexGuard<'static, ()>,
|
||||
prev: Option<String>,
|
||||
}
|
||||
|
||||
static NORMALIZED_ENV_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
||||
|
||||
impl NormalizedDevEnvGuard {
|
||||
pub fn new(enabled: bool) -> Self {
|
||||
let lock = NORMALIZED_ENV_LOCK
|
||||
.lock()
|
||||
.expect("normalized env mutex poisoned");
|
||||
let prev = std::env::var("NYASH_JOINIR_NORMALIZED_DEV_RUN").ok();
|
||||
if enabled {
|
||||
std::env::set_var("NYASH_JOINIR_NORMALIZED_DEV_RUN", "1");
|
||||
} else {
|
||||
std::env::remove_var("NYASH_JOINIR_NORMALIZED_DEV_RUN");
|
||||
}
|
||||
Self { _lock: lock, prev }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for NormalizedDevEnvGuard {
|
||||
fn drop(&mut self) {
|
||||
if let Some(prev) = &self.prev {
|
||||
std::env::set_var("NYASH_JOINIR_NORMALIZED_DEV_RUN", prev);
|
||||
} else {
|
||||
std::env::remove_var("NYASH_JOINIR_NORMALIZED_DEV_RUN");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,11 @@ pub(crate) enum NormalizedDevShape {
|
||||
JsonparserAtoiMini,
|
||||
}
|
||||
|
||||
/// 直接 Normalized→MIR ブリッジで扱う shape を返す(dev 限定)。
|
||||
pub(crate) fn direct_shapes(module: &JoinModule) -> Vec<NormalizedDevShape> {
|
||||
supported_shapes(module)
|
||||
}
|
||||
|
||||
pub(crate) fn supported_shapes(module: &JoinModule) -> Vec<NormalizedDevShape> {
|
||||
let mut shapes = Vec::new();
|
||||
if is_jsonparser_atoi_mini(module) {
|
||||
@ -27,6 +32,11 @@ pub(crate) fn supported_shapes(module: &JoinModule) -> Vec<NormalizedDevShape> {
|
||||
shapes
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn is_direct_supported(module: &JoinModule) -> bool {
|
||||
!direct_shapes(module).is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn is_pattern1_mini(module: &JoinModule) -> bool {
|
||||
module.is_structured() && find_loop_step(module).is_some()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user