Skip to content

Commit

Permalink
Remove the borrow checking from wiggle entirely (#8702)
Browse files Browse the repository at this point in the history
* Remove the borrow checking from `wiggle` entirely

This commit is a refactoring of the `wiggle` crate which powers the
`*.witx`-based bindings generation of Wasmtime for wasip1 support.
Originally `wiggle` had a full-blown runtime borrow checker which
verified that borrows were disjoint when appropriate. In #8277 this was
removed in favor of a more coarse "either all shared or all mutable"
guarantee. It turns out that this exactly matches what the Rust type
system guarantees at compile time as well.

This commit removes all runtime borrow checking in favor of compile-time
borrow checking instead. This means that there is no longer the
possibility of a runtime error arising from borrowing errors. Current
bindings in Wasmtime needed no restructuring to work with this new API.

The source of the refactors here are all in the `wiggle` crate. Changes
include:

* The `GuestPtr` type lost its type parameter. Additionally it only
  contains a `u32` pointer now instead.
* The `GuestMemory` trait is replaced with a simple `enum` of
  possibilities.
* Helper methods on `GuestPtr` are all moved to `GuestMemory`.
* A number of abstractions were simplified now that borrow checking is
  no longer necessary.
* Generated trait methods now all take `&mut GuestMemory<'_>` as an
  argument.

These changes were then propagated to the `wasmtime-wasi` and
`wasi-common` crates in their preview0 and preview1 implementations of
WASI. All changes are just general refactors, no functional change is
intended here.

* Review comments

* Fix publishing of wiggle-macro crate

* Fix wiggle docs
  • Loading branch information
alexcrichton authored May 31, 2024
1 parent d65ccd8 commit f141165
Show file tree
Hide file tree
Showing 41 changed files with 2,131 additions and 2,590 deletions.
2 changes: 1 addition & 1 deletion crates/test-programs/artifacts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0 WITH LLVM-exception"
workspace = true

[dependencies]
wasmtime = { workspace = true, features = ['incremental-cache', 'cranelift'] }
wasmtime = { workspace = true, features = ['incremental-cache', 'cranelift', 'component-model'] }

[build-dependencies]
heck = { workspace = true }
Expand Down
Loading

0 comments on commit f141165

Please sign in to comment.