@@ -70,7 +70,8 @@ use core::ptr::NonNull;
7070#[ cfg( feature = "threads" ) ]
7171use core:: time:: Duration ;
7272use wasmtime_environ:: {
73- DataIndex , DefinedMemoryIndex , ElemIndex , FuncIndex , MemoryIndex , TableIndex , Trap ,
73+ DataIndex , DefinedMemoryIndex , DefinedTableIndex , ElemIndex , FuncIndex , MemoryIndex ,
74+ TableIndex , Trap ,
7475} ;
7576#[ cfg( feature = "wmemcheck" ) ]
7677use wasmtime_wmemcheck:: AccessError :: {
@@ -223,20 +224,19 @@ unsafe impl HostResultHasUnwindSentinel for Option<AllocationSize> {
223224unsafe fn table_grow_func_ref (
224225 store : & mut dyn VMStore ,
225226 mut instance : Pin < & mut Instance > ,
226- table_index : u32 ,
227+ defined_table_index : u32 ,
227228 delta : u64 ,
228229 init_value : * mut u8 ,
229230) -> Result < Option < AllocationSize > > {
230- let table_index = TableIndex :: from_u32 ( table_index) ;
231-
232- let element = match instance. as_mut ( ) . table_element_type ( table_index) {
233- TableElementType :: Func => NonNull :: new ( init_value. cast :: < VMFuncRef > ( ) ) . into ( ) ,
234- TableElementType :: GcRef => unreachable ! ( ) ,
235- TableElementType :: Cont => unreachable ! ( ) ,
236- } ;
237-
231+ let defined_table_index = DefinedTableIndex :: from_u32 ( defined_table_index) ;
232+ let table_index = instance. env_module ( ) . table_index ( defined_table_index) ;
233+ debug_assert ! ( matches!(
234+ instance. as_mut( ) . table_element_type( table_index) ,
235+ TableElementType :: Func ,
236+ ) ) ;
237+ let element = NonNull :: new ( init_value. cast :: < VMFuncRef > ( ) ) . into ( ) ;
238238 let result = instance
239- . table_grow ( store, table_index , delta, element) ?
239+ . defined_table_grow ( store, defined_table_index , delta, element) ?
240240 . map ( AllocationSize ) ;
241241 Ok ( result)
242242}
@@ -246,27 +246,28 @@ unsafe fn table_grow_func_ref(
246246unsafe fn table_grow_gc_ref (
247247 store : & mut dyn VMStore ,
248248 mut instance : Pin < & mut Instance > ,
249- table_index : u32 ,
249+ defined_table_index : u32 ,
250250 delta : u64 ,
251251 init_value : u32 ,
252252) -> Result < Option < AllocationSize > > {
253- let table_index = TableIndex :: from_u32 ( table_index) ;
254-
255- let element = match instance. as_mut ( ) . table_element_type ( table_index) {
256- TableElementType :: Func => unreachable ! ( ) ,
257- TableElementType :: GcRef => VMGcRef :: from_raw_u32 ( init_value)
258- . map ( |r| {
259- store
260- . store_opaque_mut ( )
261- . unwrap_gc_store_mut ( )
262- . clone_gc_ref ( & r)
263- } )
264- . into ( ) ,
265- TableElementType :: Cont => unreachable ! ( ) ,
266- } ;
253+ let defined_table_index = DefinedTableIndex :: from_u32 ( defined_table_index) ;
254+ let table_index = instance. env_module ( ) . table_index ( defined_table_index) ;
255+ debug_assert ! ( matches!(
256+ instance. as_mut( ) . table_element_type( table_index) ,
257+ TableElementType :: GcRef ,
258+ ) ) ;
259+
260+ let element = VMGcRef :: from_raw_u32 ( init_value)
261+ . map ( |r| {
262+ store
263+ . store_opaque_mut ( )
264+ . unwrap_gc_store_mut ( )
265+ . clone_gc_ref ( & r)
266+ } )
267+ . into ( ) ;
267268
268269 let result = instance
269- . table_grow ( store, table_index , delta, element) ?
270+ . defined_table_grow ( store, defined_table_index , delta, element) ?
270271 . map ( AllocationSize ) ;
271272 Ok ( result)
272273}
@@ -275,24 +276,22 @@ unsafe fn table_grow_gc_ref(
275276unsafe fn table_grow_cont_obj (
276277 store : & mut dyn VMStore ,
277278 mut instance : Pin < & mut Instance > ,
278- table_index : u32 ,
279+ defined_table_index : u32 ,
279280 delta : u64 ,
280281 // The following two values together form the initial Option<VMContObj>.
281282 // A None value is indicated by the pointer being null.
282283 init_value_contref : * mut u8 ,
283284 init_value_revision : u64 ,
284285) -> Result < Option < AllocationSize > > {
285- let init_value = VMContObj :: from_raw_parts ( init_value_contref, init_value_revision) ;
286-
287- let table_index = TableIndex :: from_u32 ( table_index) ;
288-
289- let element = match instance. as_mut ( ) . table_element_type ( table_index) {
290- TableElementType :: Cont => init_value. into ( ) ,
291- _ => panic ! ( "Wrong table growing function" ) ,
292- } ;
293-
286+ let defined_table_index = DefinedTableIndex :: from_u32 ( defined_table_index) ;
287+ let table_index = instance. env_module ( ) . table_index ( defined_table_index) ;
288+ debug_assert ! ( matches!(
289+ instance. as_mut( ) . table_element_type( table_index) ,
290+ TableElementType :: Cont ,
291+ ) ) ;
292+ let element = VMContObj :: from_raw_parts ( init_value_contref, init_value_revision) . into ( ) ;
294293 let result = instance
295- . table_grow ( store, table_index , delta, element) ?
294+ . defined_table_grow ( store, defined_table_index , delta, element) ?
296295 . map ( AllocationSize ) ;
297296 Ok ( result)
298297}
0 commit comments