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

fix: support for externref #670

Merged
merged 3 commits into from
Dec 5, 2024
Merged

fix: support for externref #670

merged 3 commits into from
Dec 5, 2024

Conversation

zebp
Copy link
Collaborator

@zebp zebp commented Nov 17, 2024

Fixes #668

  1. When reference types are enabled, which is the default in Rust 1.82, wasm-bindgen will generate JS where some wasm imports that were previously functions get generated as variables due to the difference in the JS/wasm interop barrier. After we bundled with esbuild we ran into the issue where a wasm import was defined after the instance was initialized, which wasn't a problem for the pre-reference type builds since functions get automatically hoisted in JS.

  2. Previously we weren't calling wasm-bindgen's __wbindgen_start function but instead called our start function for any function with #[event(start)], but when reference types are enabled this function setups the externref table. This was causing us to change the value in the externref table for the UNDEFINED constant (index 128) to an http request causing our tests to fail. This was not fun to debug.

Copy link
Contributor

@kflansburg kflansburg left a comment

Choose a reason for hiding this comment

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

Nice!

@zebp
Copy link
Collaborator Author

zebp commented Nov 17, 2024

very very strange bug with reference types, it seems that we always get the first value passed to wasm with some options in r2 calls?

image

@zebp zebp mentioned this pull request Nov 19, 2024
@zebp zebp force-pushed the zeb/worker-build-182 branch from de71841 to 4ef0f76 Compare December 5, 2024 14:26
@zebp zebp changed the title fix: out of order variable access with reference types enabled fix: support for externref Dec 5, 2024
zebp and others added 2 commits December 5, 2024 09:40
When reference types are enabled, which is the default in Rust 1.82,
wasm-bindgen will generate JS where some wasm imports that were previously
functions get generated as variables due to the difference in the JS/wasm
interop barrier. After we bundled with esbuild we ran into the issue where a
wasm import was defined after the instance was initialized, which wasn't a
problem for the pre-reference type builds since functions get automatically
hoisted in JS.
@zebp zebp force-pushed the zeb/worker-build-182 branch from 4ef0f76 to a0a56e9 Compare December 5, 2024 14:45
@zebp zebp merged commit d13c6ac into main Dec 5, 2024
5 checks passed
@zebp zebp deleted the zeb/worker-build-182 branch December 5, 2024 17:15
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.

🐛 BUG: Error with Rust 1.82.0 in Wrangler
2 participants