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

Add support for i128 and u128 #4222

Merged
merged 12 commits into from
Nov 11, 2024
Merged

Add support for i128 and u128 #4222

merged 12 commits into from
Nov 11, 2024

Conversation

RunDevelopment
Copy link
Contributor

@RunDevelopment RunDevelopment commented Oct 24, 2024

Fixes #2822

This adds WASM ABI support for i128 and u128. Both are split into 2 u64 and passed as such in the ABI.

The following types can now be used in argument and return positions: i128, u128, Option<i128>, and Option<u128>. Return positions can also use Result<i128, E> and Result<u128, E>.

It's important to note that Result<Option<i128>, E> is not supported. This is because the WasmAbi trait supports at most 4 primitives, but Result<Option<i128>, E> would require 5 primitives (2 for i128, 1 for the option tag, 1 for the result tag, and 1 for the error variant value). Future Result<Option<T>, E> ABI optimizations (either combining the result and option tag into one primitive, or raising the number of supported primitives to 5) will make Result<Option<i128>, E> possible, but this should be a separate PR IMO.


Related to #4201.

@daxpedda
Copy link
Collaborator

daxpedda commented Nov 9, 2024

Converting to draft until #4246 is resolved.

@daxpedda daxpedda marked this pull request as draft November 9, 2024 20:30
@RunDevelopment
Copy link
Contributor Author

Converting to draft until #4246 is resolved.

Either that, or I just use BigInt(value) everywhere for now. If we decide to bigint literals in #4246 later, I can just make another PR to change it later. Grepping for BigInt( isn't hard.

@daxpedda
Copy link
Collaborator

Converting to draft until #4246 is resolved.

Either that, or I just use BigInt(value) everywhere for now. If we decide to bigint literals in #4246 later, I can just make another PR to change it later. Grepping for BigInt( isn't hard.

Yep, please go ahead and just use the constructor!

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Great, thank you!

Just some nits and a changelog entry missing.

tests/wasm/optional_primitives.js Outdated Show resolved Hide resolved
tests/wasm/optional_primitives.js Show resolved Hide resolved
@RunDevelopment RunDevelopment marked this pull request as ready for review November 11, 2024 12:13
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Thanks!

@daxpedda daxpedda merged commit df9893b into rustwasm:main Nov 11, 2024
41 checks passed
@RunDevelopment RunDevelopment deleted the int128 branch November 11, 2024 14:19
TylerJang27 pushed a commit to TylerJang27/wasm-bindgen that referenced this pull request Nov 18, 2024
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.

Implement WASM ABI conversion for u128 and i128
3 participants