Skip to content

provide more control over type ownership#598

Merged
alexcrichton merged 3 commits intobytecodealliance:mainfrom
dicej:type-ownership
Jun 28, 2023
Merged

provide more control over type ownership#598
alexcrichton merged 3 commits intobytecodealliance:mainfrom
dicej:type-ownership

Conversation

@dicej
Copy link
Collaborator

@dicej dicej commented 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.

dicej added 2 commits June 27, 2023 14:43
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>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej
Copy link
Collaborator Author

dicej commented Jun 27, 2023

CI and I just aren't getting along today. I can't repro the Linux failure. I'll see if I can repro the Windows one tomorrow.
Nevermind; fixed now.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@alexcrichton alexcrichton merged commit c28cdd6 into bytecodealliance:main Jun 28, 2023
@dicej dicej deleted the type-ownership branch June 28, 2023 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants