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

Don't generate *Param and *Result types in Rust by default #547

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

alexcrichton
Copy link
Member

Previously when a single WIT type was used in a "borrowed" position, or a parameter to an import, and an "owned" position then the type would have two copies of its definition generated if it internally contained a list. This was intended to signify that for import parameters ownership wasn't necessary so borrowed values could be passed in.

In practice though I don't think this was the right default to have. This surprisingly generates two types when one might expect one and otherwise if a type if received from an export and expected to be passed to an import then it's not easy to do so since it must be converted to the borrowed type.

This commit moves the preexisting behavior of generating duplicate types behind a new duplicate_if_necessary option. The default behavior is to no longer generate two types, but instead just one. Imports now generate their types with a & in front if it's otherwise owned internally to signify that ownership isn't required.

Closes #535

Previously when a single WIT type was used in a "borrowed" position, or
a parameter to an import, and an "owned" position then the type would
have two copies of its definition generated if it internally contained a
list. This was intended to signify that for import parameters ownership
wasn't necessary so borrowed values could be passed in.

In practice though I don't think this was the right default to have.
This surprisingly generates two types when one might expect one and
otherwise if a type if received from an export and expected to be
passed to an import then it's not easy to do so since it must be
converted to the borrowed type.

This commit moves the preexisting behavior of generating duplicate types
behind a new `duplicate_if_necessary` option. The default behavior is to
no longer generate two types, but instead just one. Imports now generate
their types with a `&` in front if it's otherwise owned internally to
signify that ownership isn't required.

Closes bytecodealliance#535
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My experience so far is that this is a better default. Thanks!

@pchickey pchickey merged commit 1be6d2e into bytecodealliance:main Mar 28, 2023
@philpax
Copy link
Contributor

philpax commented Mar 28, 2023

Fantastic, thank you - I'm looking forward to trying this out!

@alexcrichton alexcrichton deleted the no-two-names branch March 28, 2023 21:17
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Apr 10, 2023
This commit is a mirror of bytecodealliance/wit-bindgen#547 into the
`bindgen!` macro for Wasmtime. The new default is to generate only one
Rust type per WIT type input, regardless of if the representation can be
slightly more optimal in niche cases with more borrows. This should make
the macro easier to work with in the limit ideally.

Closes bytecodealliance#6124
alexcrichton added a commit to bytecodealliance/wasmtime that referenced this pull request Apr 10, 2023
This commit is a mirror of bytecodealliance/wit-bindgen#547 into the
`bindgen!` macro for Wasmtime. The new default is to generate only one
Rust type per WIT type input, regardless of if the representation can be
slightly more optimal in niche cases with more borrows. This should make
the macro easier to work with in the limit ideally.

Closes #6124
brendandburns pushed a commit to brendandburns/wasmtime that referenced this pull request Apr 13, 2023
…ance#6189)

This commit is a mirror of bytecodealliance/wit-bindgen#547 into the
`bindgen!` macro for Wasmtime. The new default is to generate only one
Rust type per WIT type input, regardless of if the representation can be
slightly more optimal in niche cases with more borrows. This should make
the macro easier to work with in the limit ideally.

Closes bytecodealliance#6124
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.

Offer option to disable generation/use of borrowed types for Rust
3 participants