@@ -118,7 +118,6 @@ pub struct FuncEnvironment<'module_environment> {
118118 #[ cfg( feature = "gc" ) ]
119119 gc_heap_bound : Option < ir:: GlobalValue > ,
120120
121- #[ cfg( feature = "wmemcheck" ) ]
122121 translation : & ' module_environment ModuleTranslation < ' module_environment > ,
123122
124123 /// Heaps implementing WebAssembly linear memories.
@@ -224,7 +223,6 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
224223 // functions should consume at least some fuel.
225224 fuel_consumed : 1 ,
226225
227- #[ cfg( feature = "wmemcheck" ) ]
228226 translation,
229227
230228 stack_limit_at_function_entry : None ,
@@ -1321,26 +1319,34 @@ impl<'a, 'func, 'module_env> Call<'a, 'func, 'module_env> {
13211319 . vmctx_vmfunction_import_wasm_call ( callee_index) ,
13221320 )
13231321 . unwrap ( ) ;
1324- let func_addr = self
1325- . builder
1326- . ins ( )
1327- . load ( pointer_type, mem_flags, base, body_offset) ;
13281322
13291323 // First append the callee vmctx address.
13301324 let vmctx_offset =
13311325 i32:: try_from ( self . env . offsets . vmctx_vmfunction_import_vmctx ( callee_index) ) . unwrap ( ) ;
1332- let vmctx = self
1326+ let callee_vmctx = self
13331327 . builder
13341328 . ins ( )
13351329 . load ( pointer_type, mem_flags, base, vmctx_offset) ;
1336- real_call_args. push ( vmctx ) ;
1330+ real_call_args. push ( callee_vmctx ) ;
13371331 real_call_args. push ( caller_vmctx) ;
13381332
13391333 // Then append the regular call arguments.
13401334 real_call_args. extend_from_slice ( call_args) ;
13411335
1342- // Finally, make the indirect call!
1343- Ok ( self . indirect_call_inst ( sig_ref, func_addr, & real_call_args) )
1336+ // If we statically know the imported function (e.g. this is a
1337+ // component-to-component call where we statically know both components)
1338+ // then we can actually still make a direct call (although we do have to
1339+ // pass the callee's vmctx that we just loaded, not our own). Otherwise,
1340+ // we really do an indirect call.
1341+ if self . env . translation . known_imported_functions [ callee_index] . is_some ( ) {
1342+ Ok ( self . direct_call_inst ( callee, & real_call_args) )
1343+ } else {
1344+ let func_addr = self
1345+ . builder
1346+ . ins ( )
1347+ . load ( pointer_type, mem_flags, base, body_offset) ;
1348+ Ok ( self . indirect_call_inst ( sig_ref, func_addr, & real_call_args) )
1349+ }
13441350 }
13451351
13461352 /// Do an indirect call through the given funcref table.
@@ -1514,6 +1520,9 @@ impl<'a, 'func, 'module_env> Call<'a, 'func, 'module_env> {
15141520 | WasmHeapType :: ConcreteArray ( _)
15151521 | WasmHeapType :: Struct
15161522 | WasmHeapType :: ConcreteStruct ( _)
1523+ | WasmHeapType :: Exn
1524+ | WasmHeapType :: ConcreteExn ( _)
1525+ | WasmHeapType :: NoExn
15171526 | WasmHeapType :: None => {
15181527 unreachable ! ( )
15191528 }
@@ -1741,7 +1750,7 @@ impl<'module_environment> TargetEnvironment for FuncEnvironment<'module_environm
17411750 fn reference_type ( & self , wasm_ty : WasmHeapType ) -> ( ir:: Type , bool ) {
17421751 let ty = crate :: reference_type ( wasm_ty, self . pointer_type ( ) ) ;
17431752 let needs_stack_map = match wasm_ty. top ( ) {
1744- WasmHeapTopType :: Extern | WasmHeapTopType :: Any => true ,
1753+ WasmHeapTopType :: Extern | WasmHeapTopType :: Any | WasmHeapTopType :: Exn => true ,
17451754 WasmHeapTopType :: Func => false ,
17461755 WasmHeapTopType :: Cont => todo ! ( ) , // FIXME: #10248 stack switching support.
17471756 } ;
@@ -1838,7 +1847,7 @@ impl FuncEnvironment<'_> {
18381847 let heap_ty = table. ref_type . heap_type ;
18391848 match heap_ty. top ( ) {
18401849 // GC-managed types.
1841- WasmHeapTopType :: Any | WasmHeapTopType :: Extern => {
1850+ WasmHeapTopType :: Any | WasmHeapTopType :: Extern | WasmHeapTopType :: Exn => {
18421851 let ( src, flags) = table_data. prepare_table_addr ( self , builder, index) ;
18431852 gc:: gc_compiler ( self ) ?. translate_read_gc_reference (
18441853 self ,
@@ -1872,7 +1881,7 @@ impl FuncEnvironment<'_> {
18721881 let heap_ty = table. ref_type . heap_type ;
18731882 match heap_ty. top ( ) {
18741883 // GC-managed types.
1875- WasmHeapTopType :: Any | WasmHeapTopType :: Extern => {
1884+ WasmHeapTopType :: Any | WasmHeapTopType :: Extern | WasmHeapTopType :: Exn => {
18761885 let ( dst, flags) = table_data. prepare_table_addr ( self , builder, index) ;
18771886 gc:: gc_compiler ( self ) ?. translate_write_gc_reference (
18781887 self ,
@@ -2254,7 +2263,9 @@ impl FuncEnvironment<'_> {
22542263 Ok ( match ht. top ( ) {
22552264 WasmHeapTopType :: Func => pos. ins ( ) . iconst ( self . pointer_type ( ) , 0 ) ,
22562265 // NB: null GC references don't need to be in stack maps.
2257- WasmHeapTopType :: Any | WasmHeapTopType :: Extern => pos. ins ( ) . iconst ( types:: I32 , 0 ) ,
2266+ WasmHeapTopType :: Any | WasmHeapTopType :: Extern | WasmHeapTopType :: Exn => {
2267+ pos. ins ( ) . iconst ( types:: I32 , 0 )
2268+ }
22582269 WasmHeapTopType :: Cont => todo ! ( ) , // FIXME: #10248 stack switching support.
22592270 } )
22602271 }
@@ -2646,7 +2657,8 @@ impl FuncEnvironment<'_> {
26462657 // wasm module (e.g. imports or libcalls) are either encoded through
26472658 // the `vmcontext` as relative jumps (hence no relocations) or
26482659 // they're libcalls with absolute relocations.
2649- colocated : self . module . defined_func_index ( index) . is_some ( ) ,
2660+ colocated : self . module . defined_func_index ( index) . is_some ( )
2661+ || self . translation . known_imported_functions [ index] . is_some ( ) ,
26502662 } ) )
26512663 }
26522664
0 commit comments