Docs: Add phase_9_79b_3_vm_vtable_thunks_and_pic.md\n- Plan to formalize TypeMeta+Thunk and upgrade PIC to poly\n- Diagnostics, risks, milestones, exit criteria, and Phase 10 readiness
This commit is contained in:
30
src/runtime/cache_versions.rs
Normal file
30
src/runtime/cache_versions.rs
Normal file
@ -0,0 +1,30 @@
|
||||
//! Global cache version map for vtable/PIC invalidation
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
|
||||
static CACHE_VERSIONS: Lazy<Mutex<HashMap<String, u32>>> = Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
/// Get current version for a cache label (default 0)
|
||||
pub fn get_version(label: &str) -> u32 {
|
||||
let map = CACHE_VERSIONS.lock().unwrap();
|
||||
*map.get(label).unwrap_or(&0)
|
||||
}
|
||||
|
||||
/// Bump version for a cache label
|
||||
pub fn bump_version(label: &str) {
|
||||
let mut map = CACHE_VERSIONS.lock().unwrap();
|
||||
let e = map.entry(label.to_string()).or_insert(0);
|
||||
*e = e.saturating_add(1);
|
||||
}
|
||||
|
||||
/// Convenience: bump for multiple labels
|
||||
pub fn bump_many(labels: &[String]) {
|
||||
let mut map = CACHE_VERSIONS.lock().unwrap();
|
||||
for l in labels {
|
||||
let e = map.entry(l.clone()).or_insert(0);
|
||||
*e = e.saturating_add(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ pub use plugin_config::PluginConfig;
|
||||
pub use box_registry::{BoxFactoryRegistry, BoxProvider, get_global_registry};
|
||||
pub use plugin_loader_v2::{PluginLoaderV2, get_global_loader_v2, init_global_loader_v2};
|
||||
pub use plugin_loader_unified::{PluginHost, get_global_plugin_host, init_global_plugin_host, PluginLibraryHandle, PluginBoxType, MethodHandle};
|
||||
pub mod cache_versions;
|
||||
pub use unified_registry::{get_global_unified_registry, init_global_unified_registry, register_user_defined_factory};
|
||||
pub use nyash_runtime::{NyashRuntime, NyashRuntimeBuilder};
|
||||
// pub use plugin_box::PluginBox; // legacy
|
||||
|
||||
@ -246,6 +246,16 @@ impl PluginBoxV2 {
|
||||
eprintln!("Failed to load config: {}", e);
|
||||
BidError::PluginError
|
||||
})?);
|
||||
// Bump cache versions for all box types (config reload may change method layout)
|
||||
if let Some(cfg) = self.config.as_ref() {
|
||||
let mut labels: Vec<String> = Vec::new();
|
||||
for (_lib, def) in &cfg.libraries {
|
||||
for bt in &def.boxes {
|
||||
labels.push(format!("BoxRef:{}", bt));
|
||||
}
|
||||
}
|
||||
crate::runtime::cache_versions::bump_many(&labels);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -309,6 +319,8 @@ impl PluginBoxV2 {
|
||||
finalized: std::sync::atomic::AtomicBool::new(false),
|
||||
});
|
||||
self.singletons.write().unwrap().insert((lib_name.to_string(), box_type.to_string()), handle);
|
||||
// bump version for this box type to invalidate caches
|
||||
crate::runtime::cache_versions::bump_version(&format!("BoxRef:{}", box_type));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user