From 29ae930632c7bafeb144dac28c8f83cf267f404d Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 18 Feb 2026 12:08:53 -0800 Subject: [PATCH 1/2] Implement `TryClone` for `RegisteredType` and `RecGroupEntry` in the types registry --- crates/wasmtime/src/runtime/type_registry.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index cac203b5d442..3c0e2387ee7a 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -26,7 +26,7 @@ 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}, + collections::{HashSet, PrimaryMap, SecondaryMap, TryClone, Vec}, iter_entity_range, packed_option::{PackedOption, ReservedValue}, }; @@ -285,6 +285,12 @@ impl Clone for RegisteredType { } } +impl TryClone for RegisteredType { + fn try_clone(&self) -> Result { + Ok(self.clone()) + } +} + impl Drop for RegisteredType { fn drop(&mut self) { self.engine.signatures().debug_assert_contains(self.index); @@ -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); From c56f7da1c0440ee491aee3d6b004576c2ee538f1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 19 Feb 2026 08:16:23 -0800 Subject: [PATCH 2/2] review feedback --- crates/wasmtime/src/runtime/type_registry.rs | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index 3c0e2387ee7a..abf9dc59e454 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -24,8 +24,8 @@ use core::{ }; use wasmtime_core::slab::{Id as SlabId, Slab}; use wasmtime_environ::{ - EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes, TypeTrace, - Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType, + 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,21 +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(), - } - } -} - -impl TryClone for RegisteredType { - fn try_clone(&self) -> Result { - Ok(self.clone()) + }) } }