-
Notifications
You must be signed in to change notification settings - Fork 58
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
Document wasm abi quirks #663
Conversation
|
||
In "padded direct" mode, every transitive scalar field is passed through as an argument just like "direct", however _padding is passed through as well_. | ||
|
||
`MyStruct` above contains 3 bytes of padding between the two fields. In "padded direct" mode, this would be invoked as `wasm.takes_struct(a, 0, 0, 0, b)`, with each 0 subbing in for padding. The LLVM IR would look something like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my
It seems like it would be clean and less error-prone for there to be an ABI that passed all the transitive scalars, but without these padding arguments that don't do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! But there are also some downsides of direct passing for large structs where indirect passing is nicer.
It would be really nice if there were ways to manipulate the wasm stack whilst indirect passing so you don't have to heap allocate.
An optimization we could do is have a shared parameter-passing mini allocator for Diplomat.
```llvm | ||
; Edited from IR produced by rustc with (default) -Zwasm-c-abi=legacy | ||
%MyStruct = type { i8, [3 x i8], i32 } | ||
define dso_local void @takes_struct(%MyStruct %0) unnamed_addr #0 { ... } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion (optional): consider including the WebAssembly Text (WAT) of the exported function signature, or at least mention how this IR is translated to WebAssembly Text. As a reader of this document, I feel fairly comfortable with WebAssembly Text but not as much in LLVM IR.
For example, one thing that confuses me is that this signature seems to take 5 integers, but 4 of them are i8
s, and i8
is not a type in Wasm. Only i32
and i64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new section on parameter types (previously, the "u64" section) explains this
docs/wasm_abi_quirks.md
Outdated
|
||
## u64 | ||
|
||
While all "normal" scalar parameters in wasm are regular Number types, `u64` translates to a `BigInt`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a browser engine thing, not a WebAssembly or Rust thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a JS thing, not a browser thing, but I'll rephrase this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to the top of the file
58bbfa0
to
0d21fe4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
Related: #661
I've done all this research, we should document it so that it can be easily referenced.