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

Mark snippets and the bundler target's main file as having side effects #1224

Merged
merged 1 commit into from
Mar 19, 2023

Conversation

Liamolucko
Copy link
Contributor

This is a less extreme version of #1208, which only marks snippets and the main file on the bundler target as having side effects instead of all files.

This means that the JS shim file which contains the vast majority of the JS code is still properly marked as having no side effects, allowing bundlers to get rid of things like unused new TextEncoder calls which could theoretically have side effects but don't.

Fixes #972
Fixes rustwasm/wasm-bindgen#3276

This is a less extreme version of rustwasm#1208, which only marks snippets and the main file on the bundler target as having side effects instead of all files.

This means that the shim file which contains the vast majority of the JS code is still properly marked as having no side effects, allowing bundlers to get rid of things like unused `new TextEncoder` calls which could theoretically have side effects but don't.

Fixes rustwasm#972.
@cryptoquick
Copy link

I tried testing out your branch, but unfortunately I ran into this issue here: #650 (comment)

It's unrelated to what's solved here, but if I can solve that, I can test if this resolves rustwasm/wasm-bindgen#3306 and #1230.

@Menci
Copy link

Menci commented Feb 27, 2023

I think only bundler target's sideEffects should be set to the entry file. web target should keep false.

@Liamolucko
Copy link
Contributor Author

I think only bundler target's sideEffects should be set to the entry file. web target should keep false.

It's already effectively false for the entry file. On the web target, sideEffects is set to ["./snippets/*"], which means that only the files inside of snippets are treated as though they have side effects. Everything else, including the entry file, is treated as though sideEffects is set to false.

The reason why snippets are marked as having side effects is because they're arbitrary user code; we've got no idea what they do, and we don't want to assume that they have no side effects and cause them to break.

@martinxyz
Copy link

I've tested this branch (after a merge with master) and it fixed the issue for me.

@Sytten
Copy link

Sytten commented Mar 14, 2023

What's missing to move this forward? It's an annoying bug right now

@Liamolucko
Copy link
Contributor Author

What's missing to move this forward? It's an annoying bug right now

It's just waiting on a review from @drager.

Copy link
Member

@drager drager left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@drager drager merged commit 777e8ca into rustwasm:master Mar 19, 2023
@Liamolucko Liamolucko deleted the side-effects branch March 19, 2023 08:21
@stephanemagnenat
Copy link

Thank you for doing that!

@cryptoquick
Copy link

Thanks! 🙏

tkmcmaster added a commit to FamilySearch/pewpew that referenced this pull request Apr 26, 2023
* Fixed the HDR Histogram build for webpack

- rustwasm/wasm-bindgen#3276 (comment)
- rustwasm/wasm-pack#1224

* Updated Viewer dependencies
sandydoo added a commit to sandydoo/flux that referenced this pull request Apr 20, 2024
- Bump wasm-bindgen to 0.2.91.
- Enable side effects for the wasm module to prevent webpack from
  removing code and breaking the build.
  See rustwasm/wasm-pack#1224.
- Build flux-next's wasm package in Nix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants