diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index cac203b5d442..abf9dc59e454 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -24,9 +24,9 @@ use core::{ }; use wasmtime_core::slab::{Id as SlabId, Slab}; use wasmtime_environ::{ - EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes, TypeTrace, - Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType, - collections::{HashSet, PrimaryMap, SecondaryMap, TryClone as _, Vec}, + EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes, + PanicOnOom as _, TypeTrace, Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType, + collections::{HashSet, PrimaryMap, SecondaryMap, TryClone, Vec}, iter_entity_range, packed_option::{PackedOption, ReservedValue}, }; @@ -273,15 +273,21 @@ impl Debug for RegisteredType { impl Clone for RegisteredType { fn clone(&self) -> Self { + self.try_clone().panic_on_oom() + } +} + +impl TryClone for RegisteredType { + fn try_clone(&self) -> Result { self.engine.signatures().debug_assert_contains(self.index); - self.entry.incref("RegisteredType::clone"); - RegisteredType { + self.entry.incref("RegisteredType::try_clone"); + Ok(RegisteredType { engine: self.engine.clone(), entry: self.entry.clone(), ty: self.ty.clone(), index: self.index, layout: self.layout.clone(), - } + }) } } @@ -457,6 +463,12 @@ impl RegisteredType { #[derive(Clone)] struct RecGroupEntry(Arc); +impl TryClone for RecGroupEntry { + fn try_clone(&self) -> Result { + Ok(self.clone()) + } +} + impl Debug for RecGroupEntry { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { struct FormatAsPtr<'a, P>(&'a P);