Stream: wasmtime

Topic: Non-generic Linker


view this post on Zulip Olexiy Kulchitskiy (Sep 29 2023 at 11:20):

Is there a way to create an instance of Linker without generic parameters? If not, then does it make sense to introduce some UntypedLinker struct that will implement From/Into<Linker>?

Context
I have a task to improve performance by reusing the same linker between different Wasmtime Instances (we have a lot of func_wrap calls there =) ).
The issue is that Linkers may have different T params in our case (some of which may even capture non-static references), thus we're unable to store them in some sort of a shared, reusable cache.

The ability to make some UntypedLinker from Linker and Linker from UntypedLinker (under unsafe context) would really help us. Especially, given the fact that does not really need it (at least on the level of struct fields)

Note: I know that mem::transmute should, probably, work here, but it looks pretty dangerous to me)

view this post on Zulip Alex Crichton (Sep 29 2023 at 13:35):

It's not currently possible to do this today, and it's definitely not safe to do in general. The main problem with this is that functions are given Caller<T> and that T is the same as the Linker<T>.

From a technical perspective if none of your functions use the Caller<T>, however, then it would be possible to provide a non-generic linker. That way the underlying type in the store would be erased. That would require a fair bit of implementation work in Wasmtime, however.

One solution I'd recommend is to perhaps store your state as an enum, but dealing with non-'static state can be tricky with that.

view this post on Zulip Olexiy Kulchitskiy (Sep 29 2023 at 14:51):

@Alex Crichton thanks for quick reply)


Last updated: Dec 23 2024 at 13:07 UTC