dicej opened PR #6648 from dicej:type-ownership
to bytecodealliance:main
:
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 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.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
dicej requested alexcrichton for a review on PR #6648.
dicej requested wasmtime-core-reviewers for a review on PR #6648.
dicej updated PR #6648.
dicej edited PR #6648:
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.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton submitted PR review:
Looks good to me, thanks!
alexcrichton merged PR #6648.
Last updated: Dec 23 2024 at 12:05 UTC