-
Notifications
You must be signed in to change notification settings - Fork 855
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: remove i64 workaround, use BigInt instead #2375
Conversation
Browsers previously didn't support the WebAssembly i64 type, so we had to work around that limitation by converting the LLVM i64 type to something else. Some people used a pair of i32 values, but we used a pointer to a stack allocated i64. Now however, all major browsers and Node.js do support WebAssembly BigInt integration so that i64 values can be passed back and forth between WebAssembly and JavaScript easily. Therefore, I think the time has come to drop support for this workaround. For more information: https://v8.dev/features/wasm-bigint (note that TinyGo has used a slightly different way of passing i64 values between JS and Wasm). For information on browser support: https://webassembly.org/roadmap/
b53bae5
to
3a1d48d
Compare
One consideration may be that Node.js only added support for i64 BigInt integration (without a flag) starting with version 16, which was released in April this year. And version 14 is still supported into 2023, a long time from now. |
I think @matthewcp and @natemoo-re are using tinygo+wasm in the browser for https://github.com/withastro/compiler . They might have an opinion on this |
Interesting concept, but ouch:
Without reviewing the code (which I can't yet, am smashed for time already) my thinking is "Which is more important, BigInt support or Node 14 support?". Do we have an idea of the existing TinyGo userbase, and if/whether this would be a major pita or not? Just from the perspective that locking out a significant qty of users isn't a good idea. However, if it's just 1 person out of a Community of 10k, then it's not the same sized problem. With a similar thought, if BigInt support would open up a lot of other optimisations and fixes, it might be worth it anyway. Either way, if this is merged, it'll need to be documented. eg "We only support Node 16 if you're outputting to wasm" or similar. 😄 |
This would be a big blocker for us. We are supporting back to |
I wonder if we could at least support this with a tinygo flag? It looked like a big PR though, so that might be a pain :(. |
Just wanted to weigh in that Astro uses TinyGo + WASM for the But due to Node's LTS schedule, we're stuck supporting To give you a sense of our community's size, Astro launched publicly in June 2021. We currently have 8.6k stars on GitHub and a Discord community with 3.6k members. Our monthly downloads on |
Ok, sounds like we shouldn't do this right now.
It's really just an optimization. Avoiding this pass makes binaries a bit smaller, hopefully (I didn't measure this but it should). Removing this pass also simplifies the compiler a bit so I would like to do it at some point.
Okay, that's useful to know! I certainly don't want to break that use case. I believe Node.js 14 also supports this, but behind a flag. Would that be acceptable once Node.js 12 is no longer supported? Otherwise we'd have to wait until 2024 until even Node.js 14 is deprecated.
Not really. IMHO it's all or nothing. I'd rather want to avoid having to maintain two wasm_exec.js files. |
Unfortunately, probably not! It would still be a pain for users. Packages can't set the flags automatically, so it'd be a user education thing. The Node ecosystem moves pretty slowly. |
Ok, thanks! Slightly off-topic but I'm wondering about some similar things. There are some upcoming features in WebAssembly that we'd like to take advantage of, eventually. |
Using BigInt doesn't give many extra optimizations, luckily. I was just hoping we could get rid of this pass, but sadly we can't. |
Cool, those seem like really, really good Discord community engagement numbers. Pretty much 1 in 4 ratio. That's bodes well for the future. 😄
Sounds reasonable, though it'll add to the maintenance burden having to do things two ways. 🤷 |
Hmm, yeah, let's just keep things as-is and re-evaluate once a really compelling new feature becomes widely supported. |
@natemoo-re Just saw this on the Astro intro page:
That's super good. It's amazing how many OSS projects get launched based on Hopefully Astro nails it, in good Community enhancing ways. 😄 |
I'd very much be in favor of this! Especially if it unblocks some major improvements that couldn't be made otherwise. I think we might even be able to compile to both and ship based on the user's Node version, but TBD on that. Always have the fallback option of a slow migration away from
Thanks for the kind words! We're so excited about how Astro's been going so far and we have so many amazing ideas to explore, but building a really solid community foundation is definitely our top priority. |
New PR, I think now is the time to finally do this: #3695 |
Browsers previously didn't support the WebAssembly i64 type, so we had
to work around that limitation by converting the LLVM i64 type to
something else. Some people used a pair of i32 values, but we used a
pointer to a stack allocated i64.
Now however, all major browsers and Node.js do support WebAssembly
BigInt integration so that i64 values can be passed back and forth
between WebAssembly and JavaScript easily. Therefore, I think the time
has come to drop support for this workaround.
For more information: https://v8.dev/features/wasm-bigint (note that
TinyGo has used a slightly different way of passing i64 values between
JS and Wasm).
For information on browser support: https://webassembly.org/roadmap/
I have tested this PR with the following steps:
tinygo test -target=wasm syscall/js
works.tinygo test -target=wasm syscall/js
passes again.Tests that currently fail (both before and after this PR) are
TestIntConversion
(partially),TestInterleavedFunctions
,TestGarbageCollection
, andTestGlobal
.Thoughts? Is there any reason why we should delay this change? I think the last browser to add support for wasm bigint was Safari 14.1.