rust-lang / rust-lang/rust-bindgen
Attempt to correct wasm32 ABI in bindgen
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
So rust has this issue where it doesn't match the calling convention of clang when targeting wasm32. The only difference appears to be when passing large heterogeneous aggregate types, where clang will indirect the value but rustc will still pass it by value.
Hacking a fix together in rustc would be possible (see https://github.com/rust-lang/rust/pull/79998), but it was proposed that as long as we are doing hacks, why not do the hack here in bindgen. In particular, when emitting fn foo(val: T), bindgen can instead emit &T for the argument.
The relevant logic is present in rustc here (https://github.com/rust-lang/rust/blob/fa416394275d2468d104b8f72ac31b1ddf7ee52e/compiler/rustc_target/src/abi/call/wasm32.rs#L32-L41) but I'm not sure how I would port it to bindgen. I got this far at least to verify that the stragety works:
index 0d93c491..ee3c588d 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3497,7 +3497,12 @@ impl TryToRustTy for Type {
{
Ok(ty)
} else {
- utils::build_path(item, ctx)
+ let path = utils::build_path(item, ctx)?;
+ if ctx.is_target_wasm32_not_emscripten() /* && check_size_here */ {
+ Ok(quote!(&#path))
+ } else {
+ Ok(path)
+ }
}
}
TypeKind::Comp(ref info) => {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/codegen/mod.rs at TryToRustTy for Type and read the linked rustc_target/src/abi/call/wasm32.rs logic. Determine how bindgen can identify large heterogeneous aggregates for wasm32 targets other than emscripten, then verify that generated parameters use references only for those cases while other targets and types retain their existing signatures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100