Skip to content
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
merged 2 commits into from
Jun 27, 2023

Commits on Jun 27, 2023

  1. [wit-bindgen] provide more control over type ownership

    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>
    dicej committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    3c37fc9 View commit details
    Browse the repository at this point in the history
  2. fix test breakage

    Signed-off-by: Joel Dice <joel.dice@fermyon.com>
    dicej committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    c2110e8 View commit details
    Browse the repository at this point in the history