Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions crates/core/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
}
}

fn cast(from: WasmType, to: WasmType) -> Bitcast {
/// Returns the [`Bitcast`] required to move a value of flat type
/// `from` into flat type `to` under the canonical ABI's unification
/// rules. Panics if the pair isn't a legal bitcast per the spec.
pub fn cast(from: WasmType, to: WasmType) -> Bitcast {
use WasmType::*;

match (from, to) {
Expand Down Expand Up @@ -2712,11 +2715,18 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
}
}

/// Flatten types in a given type
/// Flatten a component-level type into its canonical-ABI wasm-type
/// sequence, or return `None` if the result would exceed `max_params`.
///
/// It is sometimes necessary to restrict the number of max parameters dynamically,
/// for example during an async guest import call (flat params are limited to 4)
fn flat_types(resolve: &Resolve, ty: &Type, max_params: Option<usize>) -> Option<Vec<WasmType>> {
/// `max_params` defaults to [`Resolve::MAX_FLAT_PARAMS`] (16). It is
/// sometimes necessary to restrict the cap dynamically — for example
/// during an async guest-import call, where flat params are limited
/// to 4.
pub fn flat_types(
resolve: &Resolve,
ty: &Type,
max_params: Option<usize>,
) -> Option<Vec<WasmType>> {
let max_params = max_params.unwrap_or(MAX_FLAT_PARAMS);
let mut storage = iter::repeat_n(WasmType::I32, max_params).collect::<Vec<_>>();
let mut flat = FlatTypes::new(storage.as_mut_slice());
Expand Down
Loading