bytecodealliance / bytecodealliance/wasmtime

Create a `DefinedInstance` internal newtype

Open
#11,317 0 comments 0 reactions 0 assignees View on GitHub
wasmtime:unsafe-code
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
121

Description

A `DefinedInstance` is exactly like `Instance` but it only provides access to defined tables/memories/globals/etc...

This would allow us to make splitting a mutable store borrow into multiple mutable (defined!) instance borrows safe because you couldn't access the imported entities that could alias defined items from another instance that could also be mutably borrowed. That is, this method (and any others we might eventually add like it) would no longer need to be `unsafe` as long as it yielded `DefinedInstance`s instead of `Instance`s:

https://github.com/bytecodealliance/wasmtime/blob/eb54a90ece02e4ac5a26e81809944496f6e65604/crates/wasmtime/src/runtime/store.rs#L1308-L1332

To cut down on code duplication, we would probably want an `Instance` to deref to a `DefinedInstance` or something like that. Probably `Instance` would be a newtype of `DefinedInstance` that has methods for accessing imported items and anything that accesses that stuff, and then it also derefs to its inner `DefinedInstance`.

cc @alexcrichton

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.