//! Implementation of the side table for `funcref`s in the GC heap.
//!
//! The actual `VMFuncRef`s are kept in a side table, rather than inside the GC
//! heap, for the same reasons that an `externref`'s host data is kept in a side
//! table. We cannot trust any data coming from the GC heap, but `VMFuncRef`s
//! contain raw pointers, so if we stored `VMFuncRef`s inside the GC heap, we
//! wouldn't be able to use the raw pointers from any `VMFuncRef` we got out of
//! the heap. And that means we wouldn't be able to, for example, call a
//! `funcref` we got from inside the GC heap.
use crate::{
hash_map::HashMap,
type_registry::TypeRegistry,
vm::{SendSyncPtr, VMFuncRef},
};
use wasmtime_core::{
alloc::PanicOnOom,
slab::{Id, Slab},
};
use wasmtime_environ::VMSharedTypeIndex;
/// An identifier into the `FuncRefTable`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct FuncRefTableId(Id);
impl FuncRefTableId {
/// Convert this `FuncRefTableId` into its raw `u32` ID.
pub fn into_raw(self) -> u32 {
self.0.into_raw()
}
/// Create a `FuncRefTableId` from a raw `u32` ID.
pub fn from_raw(raw: u32) -> Self {
Self(Id::from_raw(raw))
}
}
/// Side table mapping `FuncRefTableId`s that can be stored in the GC heap to
/// raw `VMFuncRef`s.
#[derive(Default)]
pub struct FuncRefTable {
interned: HashMap