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

Function lower_then_lift

tests/all/component_model/func.rs:2734–2845  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2732
2733#[test]
2734fn lower_then_lift() -> Result<()> {
2735 // First test simple integers when the import/export ABI happen to line up
2736 let component = r#"
2737(component $c
2738 (import "f" (func $f (result u32)))
2739
2740 (core func $f_lower
2741 (canon lower (func $f))
2742 )
2743 (func $f2 (result s32)
2744 (canon lift (core func $f_lower))
2745 )
2746 (export "f2" (func $f2))
2747)
2748 "#;
2749
2750 let engine = super::engine();
2751 let component = Component::new(&engine, component)?;
2752 let mut store = Store::new(&engine, ());
2753 let mut linker = Linker::new(&engine);
2754 linker.root().func_wrap("f", |_, _: ()| Ok((2u32,)))?;
2755 let instance = linker.instantiate(&mut store, &component)?;
2756
2757 let f = instance.get_typed_func::<(), (i32,)>(&mut store, "f2")?;
2758 assert_eq!(f.call(&mut store, ())?, (2,));
2759
2760 // First test strings when the import/export ABI happen to line up
2761 let component = format!(
2762 r#"
2763(component $c
2764 (import "s" (func $f (param "a" string)))
2765
2766 (core module $libc
2767 (memory (export "memory") 1)
2768 {REALLOC_AND_FREE}
2769 )
2770 (core instance $libc (instantiate $libc))
2771
2772 (core func $f_lower
2773 (canon lower (func $f) (memory $libc "memory"))
2774 )
2775 (func $f2 (param "a" string)
2776 (canon lift (core func $f_lower)
2777 (memory $libc "memory")
2778 (realloc (func $libc "realloc"))
2779 )
2780 )
2781 (export "f" (func $f2))
2782)
2783 "#
2784 );
2785
2786 let component = Component::new(&engine, component)?;
2787 let mut store = Store::new(&engine, ());
2788 linker
2789 .root()
2790 .func_wrap("s", |store: StoreContextMut<'_, ()>, (x,): (WasmStr,)| {
2791 assert_eq!(x.to_str(&store)?, "hello");

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
engineFunction · 0.50
newFunction · 0.50
func_wrapMethod · 0.45
rootMethod · 0.45
instantiateMethod · 0.45
callMethod · 0.45
unwrapMethod · 0.45
errMethod · 0.45

Tested by

no test coverage detected