You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Refactor how Rust handles ownership
This commit is the next in a long line of refactors to try to model how
the Rust generator handles ownership. The Rust generator has an
`ownership` knob for deciding how to render types. The Rust generator
additionally models ownership of resources/lists in params/results of
imports/exports. Putting all of this together has led to many attempts
to wrangle this in a form that's understandable but every time a bug
comes up I feel like I don't understand what's going on. I've made
another attempt in this commit.
Here the goal is to centralize knowledge about types as much as
possible. Instead of being spread out over a few methods everything is
hopefully now centralized in a single type and a single "main method".
All other little pieces stem from these two and are modeled to be
relatively simple compared to the "main method". Whether or not this
stands the test of time we'll see.
This does change generated code in some situations as can be seen by the
test that was updated. Nothing major should be changed, but a few more
borrows are now required in places which probably should have been
borrows before.
More comments are found in the code about specific changes made here.
* Fix unsoundness in generated Rust code
This commit fixes an soundness issue in the Rust code generator's generated
code. Previously unsound code was generated when:
* An import had a parameter
* That had either a list or a variant of an aggregate where:
* Where one field was a `list<T>` or `string`
* And another field was an owned resource
In this situation the Rust generator uses an "owned" type for the argument,
such as `MyStruct`. This is done to reflect how ownership of the resource in
the argument is lost when the function is called. The problem with this,
however, is that the rest of bindings generation assumes that imported
arguments are all "borrowed" meaning that raw pointers from lists/strings can
be passed through to the canonical ABI. This is not the case here because the
argument is owned, meaning that the generated code would record an argument to
be passed to the canonical ABI and then promptly deallocate the argument.
The fix here is preceded by a refactoring to how Rust manages owned types to
make the fix possible. The general idea for the fix though is that while `x:
MyStruct` is the argument to the function all references internally are through
`&x` to ensure that it remains rooted as an argument, preserving all pointers
to lists and such. This unfortunately means that ownership can no longer model
movement of resources and instead interior mutability must be used (since we
have to move out of `&Resource<T>` since everything is borrowed). Fixing that,
however, is probably not worth the complexity at this time.
Closes#817Closesbytecodealliance/wasmtime#7951
0 commit comments