feat(phase21.5): MirBuilder optimization prep + crate EXE infrastructure

Phase 21.5 optimization readiness - C-level performance target:
- MirBuilder: JsonFrag purify toggle (HAKO_MIR_BUILDER_JSONFRAG_PURIFY=1)
- Normalizer: extended f64 canonicalization + dedupe improvements
- loop_opts_adapter: JsonFrag path refinement for crate EXE compatibility

Infrastructure improvements:
- provider_registry: add diagnostics + ring-1 providers (array/console/map/path)
- mir_interpreter: add normalization/purify feature gates
- tools/selfhost_exe_stageb.sh: new end-to-end Stage-B→crate EXE pipeline
- tools/perf/microbench.sh: performance measurement tooling

Smoke tests (phase2100):
- Extend timeout 15s→120s for heavy crate EXE builds
- Add stageb_loop_jsonfrag_crate_exe_canary_vm.sh (target test)
- Add s3_backend_selector_crate_exe_vm_parity_return42_canary_vm.sh

Documentation:
- ENV_VARS.md: add Phase 21.5 optimization toggles
- README updates: clarify crate backend strategy
- phase215-optimization.md: new optimization roadmap

This commit sets the stage for Phase 21.5 critical optimization:
achieving C-level performance to decide hakorune's future viability.
This commit is contained in:
nyash-codex
2025-11-11 02:07:12 +09:00
parent ece91306b7
commit 07a254fc0d
49 changed files with 905 additions and 167 deletions

View File

@ -4,5 +4,6 @@
pub mod env;
pub mod nyash_toml_v2;
pub mod provider_env;
pub use nyash_toml_v2::{BoxTypeConfig, LibraryDefinition, MethodDefinition, NyashConfigV2};

View File

@ -0,0 +1,47 @@
//! Provider-related environment readers (centralized)
//!
//! Minimizes scattered `std::env::var` calls across the runtime by
//! providing a small typed surface for provider selection knobs.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProviderPolicy {
/// Current default: prefer plugin/dynamic providers by priority; use ring-1 as fallback
StrictPluginFirst,
/// Prefer ring-1 (static/core-ro) for stability/CI; fall back to plugin if unavailable
SafeCoreFirst,
/// Alias to SafeCoreFirst for future extension
StaticPreferred,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FileBoxMode { Auto, CoreRo, PluginOnly }
/// Read global provider policy (affects Auto mode only)
pub fn provider_policy_from_env() -> ProviderPolicy {
match std::env::var("HAKO_PROVIDER_POLICY").unwrap_or_else(|_| "strict-plugin-first".to_string()).as_str() {
"safe-core-first" => ProviderPolicy::SafeCoreFirst,
"static-preferred" => ProviderPolicy::StaticPreferred,
_ => ProviderPolicy::StrictPluginFirst,
}
}
/// Read FileBox mode from environment variables
pub fn filebox_mode_from_env() -> FileBoxMode {
match std::env::var("NYASH_FILEBOX_MODE").unwrap_or_else(|_| "auto".to_string()).as_str() {
"core-ro" => FileBoxMode::CoreRo,
"plugin-only" => FileBoxMode::PluginOnly,
_ => {
if std::env::var("NYASH_DISABLE_PLUGINS").as_deref() == Ok("1") {
FileBoxMode::CoreRo
} else { FileBoxMode::Auto }
}
}
}
/// Allow core-ro fallback override even if Fail-Fast is ON when:
/// - JSON-only pipeline is active (quiet structured I/O), or
/// - Explicit NYASH_FILEBOX_ALLOW_FALLBACK=1 is set.
pub fn allow_filebox_fallback_override(quiet_pipe: bool) -> bool {
quiet_pipe || crate::config::env::env_bool("NYASH_FILEBOX_ALLOW_FALLBACK")
}