@@ -2,7 +2,6 @@ use crate::{Tunables, WasmResult, error::OutOfMemory, wasm_unsupported};
22use alloc:: borrow:: Cow ;
33use alloc:: boxed:: Box ;
44use core:: { fmt, ops:: Range } ;
5- use cranelift_entity:: entity_impl;
65use serde_derive:: { Deserialize , Serialize } ;
76use smallvec:: SmallVec ;
87use wasmtime_core:: alloc:: { TryClone , TryCollect as _} ;
@@ -1536,67 +1535,80 @@ impl TypeTrace for WasmRecGroup {
15361535 }
15371536}
15381537
1538+ macro_rules! entity_impl_with_try_clone {
1539+ ( $ty: ident ) => {
1540+ cranelift_entity:: entity_impl!( $ty) ;
1541+
1542+ impl TryClone for $ty {
1543+ #[ inline]
1544+ fn try_clone( & self ) -> Result <Self , $crate:: error:: OutOfMemory > {
1545+ Ok ( * self )
1546+ }
1547+ }
1548+ } ;
1549+ }
1550+
15391551/// Index type of a function (imported or defined) inside the WebAssembly module.
15401552#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15411553pub struct FuncIndex ( u32 ) ;
1542- entity_impl ! ( FuncIndex ) ;
1554+ entity_impl_with_try_clone ! ( FuncIndex ) ;
15431555
15441556/// Index type of a defined function inside the WebAssembly module.
15451557#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15461558pub struct DefinedFuncIndex ( u32 ) ;
1547- entity_impl ! ( DefinedFuncIndex ) ;
1559+ entity_impl_with_try_clone ! ( DefinedFuncIndex ) ;
15481560
15491561/// Index type of a defined table inside the WebAssembly module.
15501562#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15511563pub struct DefinedTableIndex ( u32 ) ;
1552- entity_impl ! ( DefinedTableIndex ) ;
1564+ entity_impl_with_try_clone ! ( DefinedTableIndex ) ;
15531565
15541566/// Index type of a defined memory inside the WebAssembly module.
15551567#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15561568pub struct DefinedMemoryIndex ( u32 ) ;
1557- entity_impl ! ( DefinedMemoryIndex ) ;
1569+ entity_impl_with_try_clone ! ( DefinedMemoryIndex ) ;
15581570
15591571/// Index type of a defined memory inside the WebAssembly module.
15601572#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15611573pub struct OwnedMemoryIndex ( u32 ) ;
1562- entity_impl ! ( OwnedMemoryIndex ) ;
1574+ entity_impl_with_try_clone ! ( OwnedMemoryIndex ) ;
15631575
15641576/// Index type of a defined global inside the WebAssembly module.
15651577#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15661578pub struct DefinedGlobalIndex ( u32 ) ;
1567- entity_impl ! ( DefinedGlobalIndex ) ;
1579+ entity_impl_with_try_clone ! ( DefinedGlobalIndex ) ;
15681580
15691581/// Index type of a table (imported or defined) inside the WebAssembly module.
15701582#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15711583pub struct TableIndex ( u32 ) ;
1572- entity_impl ! ( TableIndex ) ;
1584+ entity_impl_with_try_clone ! ( TableIndex ) ;
15731585
15741586/// Index type of a global variable (imported or defined) inside the WebAssembly module.
15751587#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15761588pub struct GlobalIndex ( u32 ) ;
1577- entity_impl ! ( GlobalIndex ) ;
1589+ entity_impl_with_try_clone ! ( GlobalIndex ) ;
15781590
15791591/// Index type of a linear memory (imported or defined) inside the WebAssembly module.
15801592#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15811593pub struct MemoryIndex ( u32 ) ;
1582- entity_impl ! ( MemoryIndex ) ;
1594+ entity_impl_with_try_clone ! ( MemoryIndex ) ;
15831595
15841596/// Index type of a canonicalized recursive type group inside a WebAssembly
15851597/// module (as opposed to canonicalized within the whole engine).
15861598#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15871599pub struct ModuleInternedRecGroupIndex ( u32 ) ;
1588- entity_impl ! ( ModuleInternedRecGroupIndex ) ;
1600+ entity_impl_with_try_clone ! ( ModuleInternedRecGroupIndex ) ;
15891601
15901602/// Index type of a canonicalized recursive type group inside the whole engine
15911603/// (as opposed to canonicalized within just a single Wasm module).
15921604#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15931605pub struct EngineInternedRecGroupIndex ( u32 ) ;
1594- entity_impl ! ( EngineInternedRecGroupIndex ) ;
1606+ entity_impl_with_try_clone ! ( EngineInternedRecGroupIndex ) ;
15951607
15961608/// Index type of a type (imported or defined) inside the WebAssembly module.
15971609#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
15981610pub struct TypeIndex ( u32 ) ;
1599- entity_impl ! ( TypeIndex ) ;
1611+ entity_impl_with_try_clone ! ( TypeIndex ) ;
16001612
16011613/// A canonicalized type index referencing a type within a single recursion
16021614/// group from another type within that same recursion group.
@@ -1605,7 +1617,7 @@ entity_impl!(TypeIndex);
16051617/// groups.
16061618#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16071619pub struct RecGroupRelativeTypeIndex ( u32 ) ;
1608- entity_impl ! ( RecGroupRelativeTypeIndex ) ;
1620+ entity_impl_with_try_clone ! ( RecGroupRelativeTypeIndex ) ;
16091621
16101622/// A canonicalized type index for a type within a single WebAssembly module.
16111623///
@@ -1616,7 +1628,7 @@ entity_impl!(RecGroupRelativeTypeIndex);
16161628/// involve entities defined in different modules).
16171629#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16181630pub struct ModuleInternedTypeIndex ( u32 ) ;
1619- entity_impl ! ( ModuleInternedTypeIndex ) ;
1631+ entity_impl_with_try_clone ! ( ModuleInternedTypeIndex ) ;
16201632
16211633/// A canonicalized type index into an engine's shared type registry.
16221634///
@@ -1628,7 +1640,7 @@ entity_impl!(ModuleInternedTypeIndex);
16281640#[ repr( transparent) ] // Used directly by JIT code.
16291641#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16301642pub struct VMSharedTypeIndex ( u32 ) ;
1631- entity_impl ! ( VMSharedTypeIndex ) ;
1643+ entity_impl_with_try_clone ! ( VMSharedTypeIndex ) ;
16321644
16331645impl VMSharedTypeIndex {
16341646 /// Create a new `VMSharedTypeIndex`.
@@ -1659,30 +1671,30 @@ impl Default for VMSharedTypeIndex {
16591671/// Index type of a passive data segment inside the WebAssembly module.
16601672#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16611673pub struct DataIndex ( u32 ) ;
1662- entity_impl ! ( DataIndex ) ;
1674+ entity_impl_with_try_clone ! ( DataIndex ) ;
16631675
16641676/// Index type of a passive element segment inside the WebAssembly module.
16651677#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16661678pub struct ElemIndex ( u32 ) ;
1667- entity_impl ! ( ElemIndex ) ;
1679+ entity_impl_with_try_clone ! ( ElemIndex ) ;
16681680
16691681/// Index type of a defined tag inside the WebAssembly module.
16701682#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16711683pub struct DefinedTagIndex ( u32 ) ;
1672- entity_impl ! ( DefinedTagIndex ) ;
1684+ entity_impl_with_try_clone ! ( DefinedTagIndex ) ;
16731685
16741686/// Index type of an event inside the WebAssembly module.
16751687#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16761688pub struct TagIndex ( u32 ) ;
1677- entity_impl ! ( TagIndex ) ;
1689+ entity_impl_with_try_clone ! ( TagIndex ) ;
16781690
16791691/// Index into the global list of modules found within an entire component.
16801692///
16811693/// Module translations are saved on the side to get fully compiled after
16821694/// the original component has finished being translated.
16831695#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
16841696pub struct StaticModuleIndex ( u32 ) ;
1685- entity_impl ! ( StaticModuleIndex ) ;
1697+ entity_impl_with_try_clone ! ( StaticModuleIndex ) ;
16861698
16871699/// An index of an entity.
16881700#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord , Debug , Serialize , Deserialize ) ]
0 commit comments