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

Correctly handle padding in JS2 #660

Merged
merged 9 commits into from
Aug 27, 2024

Conversation

Manishearth
Copy link
Contributor

@Manishearth Manishearth commented Aug 27, 2024

This PR:

It also generally cleans up the padding code and makes it reusable.

This fixes rust-diplomat#656 but not rust-diplomat#657

The scalarpair struct part of the second test happens to pass since rust-diplomat#657
is only relevant for argument passing
We hit too_many_arguments, but type_name can be moved into the context
(where it belongs)
@Manishearth
Copy link
Contributor Author

Forgot to handle end-padding .Done now.


assertValue() {
let functionCleanupArena = new diplomatRuntime.CleanupArena();
wasm.ScalarPairWithPadding_assert_value(...this._intoFFI());
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: the WASM ABI expects a padding zero for every byte, not just for every i32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The padding fields can have different sizes, ranging from i8 to i32, based on the preceding field. That's what the first half of this PR fixes.

Comment on lines +222 to +234
// There's no padding needed
(0 | 1, _) => ForcePaddingStatus::NoForce,
// Non-structs don't care
_ if !matches!(&field.ty, &hir::Type::Struct(_)) => ForcePaddingStatus::NoForce,
// 2-field struct contained in 2-field struct, caller decides
(2, 2) => {
needs_force_padding = true;
ForcePaddingStatus::PassThrough
}
// Outer struct has > 3 fields, always pad
(2, 3..) => ForcePaddingStatus::Force,
// Larger fields will always have padding anyway
_ => ForcePaddingStatus::NoForce
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought: Wow, very specific rules. I trust this is the result of your research

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah

tool/src/js/layout.rs Show resolved Hide resolved
tool/src/js/layout.rs Outdated Show resolved Hide resolved
@Manishearth Manishearth merged commit f6cb561 into rust-diplomat:main Aug 27, 2024
16 checks passed
@Manishearth Manishearth deleted the js-padding-scalar branch August 27, 2024 17:13
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.

Rust Wasm ABI treats two-field structs like scalars and doesn't require padding _intoFFI padding
2 participants