* Implement lowered-then-lifted functions This commit is a few features bundled into one, culminating in the implementation of lowered-then-lifted functions for the component model. It's probably not going to be used all that often but this is possible within a valid component so Wasmtime needs to do something relatively reasonable. The main things implemented in this commit are: * Component instances are now assigned a `RuntimeComponentInstanceIndex` to differentiate each one. This will be used in the future to detect fusion (one instance lowering a function from another instance). For now it's used to allocate separate `VMComponentFlags` for each internal component instance. * The `CoreExport<FuncIndex>` of lowered functions was changed to a `CoreDef` since technically a lowered function can use another lowered function as the callee. This ended up being not too difficult to plumb through as everything else was already in place. * A need arose to compile host-to-wasm trampolines which weren't already present. Currently wasm in a component is always entered through a host-to-wasm trampoline but core wasm modules are the source of all the trampolines. In the case of a lowered-then-lifted function there may not actually be any core wasm modules, so component objects now contain necessary trampolines not otherwise provided by the core wasm objects. This feature required splitting a new function into the `Compiler` trait for creating a host-to-wasm trampoline. After doing this core wasm compilation was also updated to leverage this which further enabled compiling trampolines in parallel as opposed to the previous synchronous compilation. * Review comments
86 lines
1.7 KiB
Plaintext
86 lines
1.7 KiB
Plaintext
;; basic function lifting
|
|
(component
|
|
(core module $m
|
|
(func (export ""))
|
|
)
|
|
(core instance $i (instantiate $m))
|
|
|
|
(func (export "thunk")
|
|
(canon lift (core func $i ""))
|
|
)
|
|
)
|
|
|
|
;; use an aliased type
|
|
(component $c
|
|
(core module $m
|
|
(func (export ""))
|
|
)
|
|
(core instance $i (instantiate $m))
|
|
|
|
(type $to_alias (func))
|
|
(alias outer $c $to_alias (type $alias))
|
|
|
|
(func (export "thunk") (type $alias)
|
|
(canon lift (core func $i ""))
|
|
)
|
|
)
|
|
|
|
;; test out some various canonical abi
|
|
(component $c
|
|
(core module $m
|
|
(func (export "") (param i32 i32))
|
|
(memory (export "memory") 1)
|
|
(func (export "realloc") (param i32 i32 i32 i32) (result i32)
|
|
unreachable)
|
|
)
|
|
(core instance $i (instantiate $m))
|
|
|
|
(func (export "thunk") (param string)
|
|
(canon lift
|
|
(core func $i "")
|
|
(memory $i "memory")
|
|
(realloc (func $i "realloc"))
|
|
)
|
|
)
|
|
|
|
(func (export "thunk8") (param string)
|
|
(canon lift
|
|
(core func $i "")
|
|
string-encoding=utf8
|
|
(memory $i "memory")
|
|
(realloc (func $i "realloc"))
|
|
)
|
|
)
|
|
|
|
(func (export "thunk16") (param string)
|
|
(canon lift
|
|
(core func $i "")
|
|
string-encoding=utf16
|
|
(memory $i "memory")
|
|
(realloc (func $i "realloc"))
|
|
)
|
|
)
|
|
|
|
(func (export "thunklatin16") (param string)
|
|
(canon lift
|
|
(core func $i "")
|
|
string-encoding=latin1+utf16
|
|
(memory $i "memory")
|
|
(realloc (func $i "realloc"))
|
|
)
|
|
)
|
|
)
|
|
|
|
;; lower something then immediately lift it
|
|
(component $c
|
|
(import "host-return-two" (func $f (result u32)))
|
|
|
|
(core func $f_lower
|
|
(canon lower (func $f))
|
|
)
|
|
(func $f2 (result s32)
|
|
(canon lift (core func $f_lower))
|
|
)
|
|
(export "f" (func $f2))
|
|
)
|