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

Wasm compilation of int #59936

Closed
lukehutch opened this issue Jan 18, 2025 · 2 comments
Closed

Wasm compilation of int #59936

lukehutch opened this issue Jan 18, 2025 · 2 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. type-question A question about expected behavior or functionality

Comments

@lukehutch
Copy link

When compiling Dart to wasm, numeric types are compiled as JSNumber:

https://dart.dev/interop/js-interop/js-types

However, wasm has two different native types 64-bit numerical types, i64 and f64:

https://webassembly.github.io/gc/core/syntax/types.html

When Dart is compiled to native code, int is compiled as a 64-bit int, rather than a Javascript-compatible 52-bit integer type packed into a number.

Why does Dart not compile int to i64 on wasm? In other words, why is there not a WASMi64 type and a WASMf64 type, rather than just JSNumber?

@dart-github-bot
Copy link
Collaborator

Summary: Dart's Wasm compilation uses JSNumber for int, unlike native compilation which uses 64-bit ints. The user requests i64 and f64 Wasm types instead.

@dart-github-bot dart-github-bot added area-dart2wasm Issues for the dart2wasm compiler. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-question A question about expected behavior or functionality labels Jan 18, 2025
@mraleph
Copy link
Member

mraleph commented Jan 18, 2025

When compiling Dart to wasm, numeric types are compiled as JSNumber:

That's not true. When compiling Dart to Wasm numerics are represented in the same way as on native runtime: unboxed int and double are represented as i64 and f64 values respectively.

JSNumber represents a JS number - like its name indicates.

@mraleph mraleph closed this as completed Jan 18, 2025
@mraleph mraleph removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

3 participants