-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wit-bindgen] provide more control over type ownership #6648
Merged
Conversation
This file contains 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
This replaces the `duplicate_if_necessary` parameter to `wasmtime::component::bindgen` with a new `ownership` parameter which provides finer-grained control over whether and how generated types own their fields. The default is `Ownership::Owning`, which means types own their fields regardless of how they are used in functions. These types passed by reference when used as parameters to guest-exported functions. Note that this also affects how unnamed types (e.g. `list<list<string>>`) are passed: using a reference only at the top level (e.g. `&[Vec<String>]` instead of `&[&[&str]]`, which is more difficult to construct when using non-`'static` data). The other option is `Ownership::Borrowing`, which includes a `duplicate_if_necessary` field, providing the same code generation strategy as was used prior to this change. If we're happy with this approach, I'll open another PR in the `wit-bindgen` repo to match. This also fixes a bug that caused named types to be considered owned and/or borrowed when they shouldn't have been due to having fields with unnamed types which were owned and/or borrowed in unrelated interfaces. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
alexcrichton
approved these changes
Jun 27, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
dicej
added a commit
to dicej/wit-bindgen
that referenced
this pull request
Jun 27, 2023
This is the guest version of bytecodealliance/wasmtime#6648. This replaces the duplicate_if_necessary parameter to the Rust binding generator with a new ownership parameter which provides finer-grained control over whether and how generated types own their fields. The default is `Ownership::Owning`, which means types own their fields regardless of how they are used in functions. These types are passed by reference when used as parameters to guest-exported functions. Note that this also affects how unnamed types (e.g. `list<list<string>>`) are passed: using a reference only at the top level (e.g. `&[Vec<String>]` instead of `&[&[&str]]`, which is more difficult to construct when using non-'static data). The other option is `Ownership::Borrowing`, which includes a `duplicate_if_necessary` field, providing the same code generation strategy as was used prior to this change. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
alexcrichton
pushed a commit
to bytecodealliance/wit-bindgen
that referenced
this pull request
Jun 28, 2023
* provide more control over type ownership This is the guest version of bytecodealliance/wasmtime#6648. This replaces the duplicate_if_necessary parameter to the Rust binding generator with a new ownership parameter which provides finer-grained control over whether and how generated types own their fields. The default is `Ownership::Owning`, which means types own their fields regardless of how they are used in functions. These types are passed by reference when used as parameters to guest-exported functions. Note that this also affects how unnamed types (e.g. `list<list<string>>`) are passed: using a reference only at the top level (e.g. `&[Vec<String>]` instead of `&[&[&str]]`, which is more difficult to construct when using non-'static data). The other option is `Ownership::Borrowing`, which includes a `duplicate_if_necessary` field, providing the same code generation strategy as was used prior to this change. Signed-off-by: Joel Dice <joel.dice@fermyon.com> * fix tests Signed-off-by: Joel Dice <joel.dice@fermyon.com> * fix tests, part 2 Signed-off-by: Joel Dice <joel.dice@fermyon.com> --------- Signed-off-by: Joel Dice <joel.dice@fermyon.com>
rvolosatovs
pushed a commit
to bytecodealliance/wrpc
that referenced
this pull request
May 23, 2024
* provide more control over type ownership This is the guest version of bytecodealliance/wasmtime#6648. This replaces the duplicate_if_necessary parameter to the Rust binding generator with a new ownership parameter which provides finer-grained control over whether and how generated types own their fields. The default is `Ownership::Owning`, which means types own their fields regardless of how they are used in functions. These types are passed by reference when used as parameters to guest-exported functions. Note that this also affects how unnamed types (e.g. `list<list<string>>`) are passed: using a reference only at the top level (e.g. `&[Vec<String>]` instead of `&[&[&str]]`, which is more difficult to construct when using non-'static data). The other option is `Ownership::Borrowing`, which includes a `duplicate_if_necessary` field, providing the same code generation strategy as was used prior to this change. Signed-off-by: Joel Dice <joel.dice@fermyon.com> * fix tests Signed-off-by: Joel Dice <joel.dice@fermyon.com> * fix tests, part 2 Signed-off-by: Joel Dice <joel.dice@fermyon.com> --------- Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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 replaces the
duplicate_if_necessary
parameter towasmtime::component::bindgen
with a newownership
parameter which provides finer-grained control over whether and how generated types own their fields.The default is
Ownership::Owning
, which means types own their fields regardless of how they are used in functions. These types are passed by reference when used as parameters to guest-exported functions. Note that this also affects how unnamed types (e.g.list<list<string>>
) are passed: using a reference only at the top level (e.g.&[Vec<String>]
instead of&[&[&str]]
, which is more difficult to construct when using non-'static
data).The other option is
Ownership::Borrowing
, which includes aduplicate_if_necessary
field, providing the same code generation strategy as was used prior to this change.If we're happy with this approach, I'll open another PR in the
wit-bindgen
repo to match.This also fixes a bug that caused named types to be considered owned and/or borrowed when they shouldn't have been due to having fields with unnamed types which were owned and/or borrowed in unrelated interfaces.