Stream: wasmtime

Topic: Instance<'store>


view this post on Zulip fitzgen (he/him) (Mar 09 2020 at 20:06):

So I was thinking... since

  1. everything lives in a Store and we don't drop instances, for example, until the store is dropped at which point they're all dropped at once, and
  2. we have a bunch of sort of unknown-whether-its-totally-safe unsafe code hiding inside runtime and jit,

what do folks think of making Instance into Instance<'store> and plumbing that through everywhere, so that when you ask for a module's memory for example, you get a VMMemoryDefinition<'store> rather than a thing that contains an unsafe raw pointer. This would clean up a lot of the unsafe pointer dereferences we have internally, and we could also remove a bunch of internal refcounting, I think.

I would need to dig in a bit further to see how feasible this really is, but figured it was worth getting feedback about the idea first. +cc @Alex Crichton

view this post on Zulip Alex Crichton (Mar 10 2020 at 14:08):

Usually 'a means some sort of stack lifetime, so would that work here? I think it makes sense that conceptually everything lives as part of the same Store, but the actual lifetime I feel may be best dynamic rather than stack-based

view this post on Zulip Alex Crichton (Mar 10 2020 at 14:08):

I can't quite envision this, though, so I'm not entirely sure how it would work out

view this post on Zulip Alex Crichton (Mar 10 2020 at 14:08):

Making the raw pointers safer though would indeed be nice!

view this post on Zulip fitzgen (he/him) (Mar 10 2020 at 16:45):

yeah, I think you're right in that we wouldn't want to force Store to be on main's frame and never move or be boxed up into a structure...

we could do a "dynamic borrow" type thing where you provide the &'a Store when accessing some method to get back a &'a Instance, but this is seeming less and less appealing. It might even require dynamic checks that this is the right store, at which point we might as well just keep our refcounting.


Last updated: Dec 23 2024 at 13:07 UTC