@@ -18,7 +18,9 @@ use core::future::Future;
1818use core:: mem:: { self , MaybeUninit } ;
1919use core:: ptr:: NonNull ;
2020use serde:: { Deserialize , Serialize } ;
21- use wasmtime_environ:: { FuncIndex , VMSharedTypeIndex } ;
21+ use wasmtime_environ:: {
22+ FuncIndex , VMSharedTypeIndex , packed_option:: PackedOption , packed_option:: ReservedValue ,
23+ } ;
2224
2325/// A reference to the abstract `nofunc` heap value.
2426///
@@ -112,6 +114,19 @@ pub struct WasmFuncOrigin {
112114 pub index : FuncIndex ,
113115}
114116
117+ impl ReservedValue for WasmFuncOrigin {
118+ fn reserved_value ( ) -> Self {
119+ WasmFuncOrigin {
120+ instance : InstanceId :: reserved_value ( ) ,
121+ index : FuncIndex :: reserved_value ( ) ,
122+ }
123+ }
124+
125+ fn is_reserved_value ( & self ) -> bool {
126+ self . instance . is_reserved_value ( ) && self . index . is_reserved_value ( )
127+ }
128+ }
129+
115130/// A WebAssembly function which can be called.
116131///
117132/// This type typically represents an exported function from a WebAssembly
@@ -294,14 +309,14 @@ pub struct Func {
294309 /// This field is populated when a [`Func`] is generated from a known instance
295310 /// (i.e. exported Wasm functions), and is usually `None` for internal
296311 /// Wasm functions and host functions.
297- origin : Option < WasmFuncOrigin > ,
312+ origin : PackedOption < WasmFuncOrigin > ,
298313}
299314
300315// Double-check that the C representation in `extern.h` matches our in-Rust
301316// representation here in terms of size/alignment/etc.
302317const _: ( ) = {
303318 #[ repr( C ) ]
304- struct C ( u64 , * mut u8 , ( u32 , u32 , u32 ) ) ;
319+ struct C ( u64 , * mut u8 , ( u32 , u32 ) ) ;
305320 assert ! ( core:: mem:: size_of:: <C >( ) == core:: mem:: size_of:: <Func >( ) ) ;
306321 assert ! ( core:: mem:: align_of:: <C >( ) == core:: mem:: align_of:: <Func >( ) ) ;
307322 assert ! ( core:: mem:: offset_of!( Func , store) == 0 ) ;
@@ -566,7 +581,7 @@ impl Func {
566581 Func {
567582 store,
568583 unsafe_func_ref : func_ref. into ( ) ,
569- origin : None ,
584+ origin : PackedOption :: default ( ) ,
570585 }
571586 }
572587
@@ -1035,7 +1050,7 @@ impl Func {
10351050 } ,
10361051 unsafe { params_and_returns. as_ref ( ) } ,
10371052 & self . ty ( & store) ,
1038- self . origin . clone ( ) ,
1053+ self . origin . expand ( ) ,
10391054 & mut store,
10401055 )
10411056 }
@@ -1536,12 +1551,12 @@ impl Func {
15361551
15371552 /// Set the origin of this function.
15381553 pub ( crate ) fn set_origin ( & mut self , origin : WasmFuncOrigin ) {
1539- self . origin = Some ( origin) ;
1554+ self . origin = PackedOption :: from ( origin) ;
15401555 }
15411556
15421557 // Get the origin of this function
15431558 pub ( crate ) fn origin ( & self ) -> Option < WasmFuncOrigin > {
1544- self . origin
1559+ self . origin . expand ( )
15451560 }
15461561}
15471562
0 commit comments