Stream: wasmtime

Topic: any way to get the `Store` from a vmctx?


view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:45):

implementing Func::wrap support for reference types right now, and WasmTy::{load,store} need to take a &Store argument to pass in/receive ExternRefs to/from Wasm, which means that the trampoline in impl_into_func! needs to get a Store from ... somewhere? presumably from either the callee_vmctx or caller_vmctx?

cc @Alex Crichton

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:46):

hm... so the only guaranteed non-null value is caller_vmctx (the first one)

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:46):

ah, host_state()?

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:46):

nah that probably doesn't have a Store

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:46):

er or it might

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:47):

just above trampoline, in shim:

debug_assert!(state.is::<(F, Weak<StoreInner>)>());

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:47):

ah yeah no nvmd looks like it's there

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:47):

thanks

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:47):

so yeah that looks to be it

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:47):

but I'd avoid upgrading the Weak unelss an ExternRef is actually used

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:48):

either way is fine though

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:48):

good call

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:51):

ah hm, that's actually a little funky -- are you thinking that WasmTy::{load,store} should instead take a &dyn Fn() -> &Store or a &Weak<StoreInner>? because we don't know at the call site what the T: WasmTy is and whether it will use the store or not

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:51):

@Alex Crichton

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:51):

either way I think is fine

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:51):

ExternRef stores a weak anyway, right?

view this post on Zulip Alex Crichton (Jun 12 2020 at 17:52):

it's an internal trait FWIW (the mehtods at least) so it's fine to do whatever works best

view this post on Zulip fitzgen (he/him) (Jun 12 2020 at 17:52):

ah yeah, so I guess it is only WasmTy::load that really needs it


Last updated: Oct 23 2024 at 20:03 UTC