MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / call_impl

Method call_impl

crates/wasmtime/src/runtime/component/func.rs:306–362  ·  view source on GitHub ↗
(
        &self,
        mut store: impl AsContextMut,
        params: &[Val],
        results: &mut [Val],
    )

Source from the content-addressed store, hash-verified

304 }
305
306 fn call_impl(
307 &self,
308 mut store: impl AsContextMut,
309 params: &[Val],
310 results: &mut [Val],
311 ) -> Result<()> {
312 let mut store = store.as_context_mut();
313
314 self.check_params_results(store.as_context_mut(), params, results)?;
315
316 if self.abi_async(store.0) {
317 unreachable!(
318 "async-lifted exports should have failed validation \
319 when `component-model-async` feature disabled"
320 );
321 }
322
323 // SAFETY: the chosen representations of type parameters to `call_raw`
324 // here should be generally safe to work with:
325 //
326 // * parameters use `MaybeUninit<[MaybeUninit<ValRaw>; MAX_FLAT_PARAMS]>`
327 // which represents the maximal possible number of parameters that can
328 // be passed to lifted component functions. This is modeled with
329 // `MaybeUninit` to represent how it all starts as uninitialized and
330 // thus can't be safely read during lowering.
331 //
332 // * results are modeled as `[ValRaw; MAX_FLAT_RESULTS]` which
333 // represents the maximal size of values that can be returned. Note
334 // that if the function doesn't actually have a return value then the
335 // `ValRaw` inside the array will have undefined contents. That is
336 // safe in Rust, however, due to `ValRaw` being a `union`. The
337 // contents should dynamically not be read due to the type of the
338 // function used here matching the actual lift.
339 let (_, post_return_arg) = unsafe {
340 self.call_raw(
341 store.as_context_mut(),
342 |cx, ty, dst: &mut MaybeUninit<[MaybeUninit<ValRaw>; MAX_FLAT_PARAMS]>| {
343 // SAFETY: it's safe to assume that
344 // `MaybeUninit<array-of-maybe-uninit>` is initialized because
345 // each individual element is still considered uninitialized.
346 let dst: &mut [MaybeUninit<ValRaw>] = dst.assume_init_mut();
347 Self::lower_args(cx, params, ty, dst)
348 },
349 |cx, results_ty, src: &[ValRaw; MAX_FLAT_RESULTS]| {
350 let max_flat = MAX_FLAT_RESULTS;
351 for (result, slot) in
352 Self::lift_results(cx, results_ty, src, max_flat)?.zip(results)
353 {
354 *slot = result?;
355 }
356 Ok(())
357 },
358 )?
359 };
360
361 self.post_return_impl(store, post_return_arg)
362 }
363

Callers 2

callMethod · 0.45
call_asyncMethod · 0.45

Calls 6

OkFunction · 0.85
check_params_resultsMethod · 0.80
abi_asyncMethod · 0.80
post_return_implMethod · 0.80
as_context_mutMethod · 0.45
call_rawMethod · 0.45

Tested by

no test coverage detected