From 7a4f5052f1e7e1575f4d4edc14e0d9f01363c58e Mon Sep 17 00:00:00 2001 From: nyash-dev Date: Sat, 6 Sep 2025 13:07:57 +0900 Subject: [PATCH] jit: P3 jit-direct-only hardening; stub JitManager; guard VM/JIT identical tests under jit-only --- src/jit/manager.rs | 29 +++++++++++++++++++++++++ src/tests/identical_exec.rs | 2 +- src/tests/identical_exec_collections.rs | 3 +-- src/tests/identical_exec_instance.rs | 2 +- src/tests/identical_exec_string.rs | 3 +-- src/tests/typebox_tlv_diff.rs | 2 +- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/jit/manager.rs b/src/jit/manager.rs index b9beae02..af8d1cf8 100644 --- a/src/jit/manager.rs +++ b/src/jit/manager.rs @@ -1,9 +1,37 @@ +#[cfg(feature = "jit-direct-only")] +pub struct JitManager; + +#[cfg(feature = "jit-direct-only")] +impl JitManager { + pub fn new(_threshold: u32) -> Self { Self } + pub fn set_threshold(&mut self, _t: u32) {} + pub fn record_entry(&mut self, _func: &str) {} + pub fn should_jit(&self, _func: &str) -> bool { false } + pub fn mark_compiled(&mut self, _func: &str, _handle: u64) {} + pub fn maybe_compile(&mut self, _func: &str, _mir: &crate::mir::MirFunction) -> bool { false } + pub fn is_compiled(&self, _func: &str) -> bool { false } + pub fn handle_of(&self, _func: &str) -> Option { None } + pub fn sites(&self) -> usize { 0 } + pub fn compiled_count(&self) -> usize { 0 } + pub fn total_hits(&self) -> u64 { 0 } + pub fn exec_ok_count(&self) -> u64 { 0 } + pub fn exec_trap_count(&self) -> u64 { 0 } + pub fn record_lower_stats(&mut self, _func: &str, _phi_total: u64, _phi_b1: u64, _ret_bool_hint: bool) {} + pub fn per_function_stats(&self) -> Vec<(String, u64, u64, u64, u32, bool, u64)> { Vec::new() } + pub fn top_hits(&self, _n: usize) -> Vec<(String, u32, bool, u64)> { Vec::new() } + pub fn print_summary(&self) {} + pub fn maybe_dispatch(&mut self, _func: &str, _argc: usize) -> bool { false } + pub fn execute_compiled(&mut self, _func: &str, _ret_ty: &crate::mir::MirType, _args: &[crate::backend::vm::VMValue]) -> Option { None } +} + +#[cfg(not(feature = "jit-direct-only"))] use std::collections::HashMap; /// Minimal JIT manager skeleton for Phase 10_a /// - Tracks per-function entry counts /// - Decides when a function should be JIT-compiled (threshold) /// - Records compiled functions for stats +#[cfg(not(feature = "jit-direct-only"))] pub struct JitManager { threshold: u32, hits: HashMap, @@ -17,6 +45,7 @@ pub struct JitManager { func_ret_bool_hint: HashMap, } +#[cfg(not(feature = "jit-direct-only"))] impl JitManager { pub fn new(threshold: u32) -> Self { Self { threshold, hits: HashMap::new(), compiled: HashMap::new(), engine: crate::jit::engine::JitEngine::new(), exec_ok: 0, exec_trap: 0, func_phi_total: HashMap::new(), func_phi_b1: HashMap::new(), func_ret_bool_hint: HashMap::new() } diff --git a/src/tests/identical_exec.rs b/src/tests/identical_exec.rs index 5144052c..57eb85b6 100644 --- a/src/tests/identical_exec.rs +++ b/src/tests/identical_exec.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test, not(feature = "jit-direct-only")))] mod tests { use crate::mir::{MirModule, MirFunction, FunctionSignature}; use crate::mir::{BasicBlockId, MirInstruction, ConstValue, EffectMask, MirType, BinaryOp}; diff --git a/src/tests/identical_exec_collections.rs b/src/tests/identical_exec_collections.rs index 39ecedf4..905a2a37 100644 --- a/src/tests/identical_exec_collections.rs +++ b/src/tests/identical_exec_collections.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test, not(feature = "jit-direct-only")))] mod tests { use crate::backend::VM; use crate::mir::{MirModule, MirFunction, FunctionSignature, BasicBlockId, MirInstruction, ConstValue, EffectMask, MirType, ValueId}; @@ -72,4 +72,3 @@ mod tests { assert_eq!(vm_s, jit_s, "VM and JIT results should match for collection ops"); } } - diff --git a/src/tests/identical_exec_instance.rs b/src/tests/identical_exec_instance.rs index 7809f22f..f1a2a35a 100644 --- a/src/tests/identical_exec_instance.rs +++ b/src/tests/identical_exec_instance.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test, not(feature = "jit-direct-only")))] mod tests { use std::sync::{Arc, RwLock}; use std::collections::HashMap; diff --git a/src/tests/identical_exec_string.rs b/src/tests/identical_exec_string.rs index 3063465a..9892351a 100644 --- a/src/tests/identical_exec_string.rs +++ b/src/tests/identical_exec_string.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test, not(feature = "jit-direct-only")))] mod tests { use crate::backend::VM; use crate::mir::{MirModule, MirFunction, FunctionSignature, BasicBlockId, MirInstruction, ConstValue, EffectMask, MirType}; @@ -37,4 +37,3 @@ mod tests { assert_eq!(vm_s, jit_s, "VM and JIT results should match for String.len"); } } - diff --git a/src/tests/typebox_tlv_diff.rs b/src/tests/typebox_tlv_diff.rs index 9d749510..8072a734 100644 --- a/src/tests/typebox_tlv_diff.rs +++ b/src/tests/typebox_tlv_diff.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test, not(feature = "jit-direct-only")))] mod tests { use std::env; use crate::box_trait::{NyashBox, StringBox, IntegerBox};