Skip to content

Commit fd7418e

Browse files
authored
Implement TryClone for RegisteredType and RecGroupEntry in the types registry (#12619)
* Implement `TryClone` for `RegisteredType` and `RecGroupEntry` in the types registry * review feedback
1 parent 735bc9c commit fd7418e

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

crates/wasmtime/src/runtime/type_registry.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use core::{
2424
};
2525
use wasmtime_core::slab::{Id as SlabId, Slab};
2626
use wasmtime_environ::{
27-
EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes, TypeTrace,
28-
Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType,
29-
collections::{HashSet, PrimaryMap, SecondaryMap, TryClone as _, Vec},
27+
EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes,
28+
PanicOnOom as _, TypeTrace, Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType,
29+
collections::{HashSet, PrimaryMap, SecondaryMap, TryClone, Vec},
3030
iter_entity_range,
3131
packed_option::{PackedOption, ReservedValue},
3232
};
@@ -273,15 +273,21 @@ impl Debug for RegisteredType {
273273

274274
impl Clone for RegisteredType {
275275
fn clone(&self) -> Self {
276+
self.try_clone().panic_on_oom()
277+
}
278+
}
279+
280+
impl TryClone for RegisteredType {
281+
fn try_clone(&self) -> Result<Self, OutOfMemory> {
276282
self.engine.signatures().debug_assert_contains(self.index);
277-
self.entry.incref("RegisteredType::clone");
278-
RegisteredType {
283+
self.entry.incref("RegisteredType::try_clone");
284+
Ok(RegisteredType {
279285
engine: self.engine.clone(),
280286
entry: self.entry.clone(),
281287
ty: self.ty.clone(),
282288
index: self.index,
283289
layout: self.layout.clone(),
284-
}
290+
})
285291
}
286292
}
287293

@@ -457,6 +463,12 @@ impl RegisteredType {
457463
#[derive(Clone)]
458464
struct RecGroupEntry(Arc<RecGroupEntryInner>);
459465

466+
impl TryClone for RecGroupEntry {
467+
fn try_clone(&self) -> Result<Self, OutOfMemory> {
468+
Ok(self.clone())
469+
}
470+
}
471+
460472
impl Debug for RecGroupEntry {
461473
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
462474
struct FormatAsPtr<'a, P>(&'a P);

0 commit comments

Comments
 (0)