Skip to content

Commit 5f20865

Browse files
authored
make cast and flat_types publicly accessible (#1597)
1 parent 1e3af2d commit 5f20865

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

crates/core/src/abi.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
26562656
}
26572657
}
26582658

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

26622665
match (from, to) {
@@ -2712,11 +2715,18 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
27122715
}
27132716
}
27142717

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

0 commit comments

Comments
 (0)