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

Remove async-trait in bindgen #9867

Merged

Conversation

ifsheldon
Copy link
Contributor

Closes #9823

I ran cargo test -p wasmtime-wasi and all tests passed, so now I'd like to go through the whole CI.

There are only 2 cases remaining unresolved due to the use of dyn objects, i.e., wasmtime::runtime::store::CallHookHandler and wasmtime::runtime::limits::ResourceLimiterAsync, but they are related to the runtime, so I don't think they are very relevant to the issue and I left them unchanged.

@ifsheldon ifsheldon requested review from a team as code owners December 19, 2024 17:32
@ifsheldon ifsheldon requested review from dicej and removed request for a team December 19, 2024 17:32
@github-actions github-actions bot added wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself labels Dec 19, 2024
Copy link
Contributor

@dicej dicej left a comment

Choose a reason for hiding this comment

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

Thanks for this!

LGTM overall, but see my inline comment about avoiding the trait-variant dependency, which would address the cargo vet CI failure.

The other CI failure should be easy to fix: just run BINDGEN_TEST_BLESS=1 cargo test -p wasmtime-component-macro --test expanded.

@@ -313,6 +315,7 @@ tracing = "0.1.26"
bitflags = "2.0"
thiserror = "1.0.43"
async-trait = "0.1.71"
trait-variant = "0.1.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

Per this section of the contributing docs, the bar for adding new dependencies to Wasmtime is a bit higher than for other projects (hence the cargo vet CI failure), so we need to make sure this one is worth including.

From what I can tell, it's only being used to annotate wasmtime-wit-bindgen-generated traits. Given that we're generating those traits anyway, I wonder if we should modify the generator to emit a -> impl Future<Output = T> + Send return type directly rather than rely on trait-variant to transform the code it just generated. That would avoid the extra dependency and remove a layer of abstraction. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would strongly recommend adding trait-variant because:

  1. it is maintained officially by the Rust project, so the code quality is reassured.
  2. this is the recommended way to add Send bound by the Rust announcement about async fn in traits
  3. in the announcement, it's said future version of trait-variant will support dyn trait object. Using trait-variant will enable dyn object support in the future without the need to modify bindgen
  4. compared to writing -> impl Future<Output = T> + Send ourselves, it's better to leave async fn signatures for users to debug when users have IDEs like RustRover that can expand proc_macro layer by layer. So when they want to debug, they actually see #[trait_variant::make] and async fn instead of fn ... -> impl Future<Output = T> + Send
  5. from my perspective, the use of #[trait_variant::make] is sort of a marker indicating better support of async fn in traits is needed, which may benefit contributions.

In general, I think trait-variant is a better solution than async-trait when we take the future evolution of Rust into account.

PS: replacing async-trait with trait-variant is a breaking change because:

  • traits by async-trait support dyn trait object while traits with trait-variant for now do not
  • when implementing async traits, users need to remove #[async_trait::async_trait] on the impl blocks

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining! I hadn't realized trait-variant was a rust-lang project and that it has official status. I'll add a commit to tell cargo vet to trust that crate.

And yes, I realize the removal of async-trait will be a breaking change in any case.

This exempts the `trait-variant` crate from vetting since it is published and
maintained by the rust-lang organization and is officially recommended by the
Rust project.

Signed-off-by: Joel Dice <[email protected]>
@dicej dicej added this pull request to the merge queue Dec 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 20, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Dec 20, 2024
Merged via the queue into bytecodealliance:main with commit d0a5599 Dec 20, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bindgen improvement: Remove the use of async_trait
3 participants