Repository navigation
Remove the borrow checking from wiggle entirely - #8702
Merged
alexcrichton merged 4 commits intoMay 31, 2024
Merged
Conversation
pchickey
approved these changes
May 29, 2024
pchickey
left a comment
Contributor
There was a problem hiding this comment.
We sure did spend turn a lot of CPU cycles into heat by dynamically checking a property that was statically provable all these years, didnt we
| TokenStream::from(quote! { #code #metadata }) | ||
| let mut ret = quote! { #code #metadata }; | ||
|
|
||
| if std::env::var("WIGGLE_DEBUG_BINDGEN").is_ok() { |
Contributor
There was a problem hiding this comment.
Wish I had done this years ago
Member
Author
There was a problem hiding this comment.
I should wrap this up in a helper as well since I'm starting to litter this all over the macros I work on...
Contributor
|
to be fair to ourselves, when we thought embedders might provide functions that involve multiple concurrent outstanding borrows it all made a bit more sense :) |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
May 30, 2024
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 bytecodealliance#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.
alexcrichton
force-pushed
the
wiggle-no-borrow-checking
branch
from
May 31, 2024 14:48
5be87d5 to
0130672
Compare
alexcrichton
enabled auto-merge
May 31, 2024 14:48
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
May 31, 2024
alexcrichton
enabled auto-merge
May 31, 2024 16:06
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
May 31, 2024
Contributor
|
I'm so glad we're able to do this now, thank you!! |
alexcrichton
enabled auto-merge
May 31, 2024 17:14
dmartin
added a commit
to dmartin/wasmtime
that referenced
this pull request
Jul 24, 2025
These variants were related to the runtime borrow checker, and are no longer constructed anywhere since bytecodealliance#8277 (for `BorrowCheckerOutOfHandles`) and bytecodealliance#8702 (for `PtrBorrowed`).
bongjunj
pushed a commit
to prosyslab/wasmtime
that referenced
this pull request
Oct 20, 2025
These variants were related to the runtime borrow checker, and are no longer constructed anywhere since bytecodealliance#8277 (for `BorrowCheckerOutOfHandles`) and bytecodealliance#8702 (for `PtrBorrowed`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit is a refactoring of the
wigglecrate which powers the*.witx-based bindings generation of Wasmtime for wasip1 support. Originallywigglehad 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
wigglecrate. Changes include:GuestPtrtype lost its type parameter. Additionally it only contains au32pointer now instead.GuestMemorytrait is replaced with a simpleenumof possibilities.GuestPtrare all moved toGuestMemory.&mut GuestMemory<'_>as an argument.These changes were then propagated to the
wasmtime-wasiandwasi-commoncrates in their preview0 and preview1 implementations of WASI. All changes are just general refactors, no functional change is intended here.