Expose native implementation identity for verified host fast paths

This commit is contained in:
2026-10-22 19:02:27 +08:00
parent ae821aea2e
commit e511e393d9
5 changed files with 54 additions and 3 deletions
+9 -1
View File
@@ -222,7 +222,7 @@ impl CallSignature {
}
}
pub trait NativeCallable: fmt::Debug + Send + Sync + 'static {
pub trait NativeCallable: fmt::Debug + Send + Sync + std::any::Any {
/// Immutable resolved types; referenced definitions must be traced by the
/// payload. ContextNativeFunction snapshots and traces them automatically.
fn signature(&self) -> Option<CallSignature> {
@@ -453,6 +453,14 @@ pub struct ContextNativeFunction {
}
impl ContextNativeFunction {
/// Borrow the concrete host implementation for intrinsic dispatch checks.
/// Function identity or a mutable class-table slot alone is not proof that
/// its current payload still implements a host intrinsic.
pub fn implementation<T: NativeCallable>(&self) -> Option<&T> {
let implementation: &dyn std::any::Any = self.callable.as_ref();
implementation.downcast_ref()
}
pub fn new(
name: &'static str,
callable: impl NativeCallable,