-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Don't enable shared memory by default with Wasm atomics #147225
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_ssa |
This comment has been minimized.
This comment has been minimized.
6f67cc5
to
5b809b3
Compare
Should the |
AFAIK it already does: rust/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs Lines 20 to 32 in 1e1a394
|
That is missing the |
These commits modify compiler targets. |
Its interesting that so many flags were overlapping then. |
@bors: r+ |
This prepares us for a future where LLVM eventually stabilizes the atomics target feature, in which case we don't want to inflate atomics with threads. Otherwise users would be stuck with shared memory even when they don't want it/need it.
Context
Currently the atomics target features is unstable and can't be used without re-building Std with it (
-Zbuild-std
).Enabling the atomics target feature automatically enables shared memory.
Shared memory is required to actually allow multi-threading.
However, shared memory comes with a performance overhead when atomic instructions aren't able to be lowered to regular memory access instructions or when interacting with certain Web APIs.
So it is very undesirable to enable shared memory by default for the majority of users.
While it is possible to use atomics without shared memory, the question remains what use-case this scenario has.
The only one I can think of would involve multiple memories, where the main memory remains un-shared but a second shared memory exists. While Rust doesn't support multiple memories, it might be possible with inline assembly (#136382).
So alternatively, we might consider not enabling atomics by default even when LLVM does. In which case everything would remain the same.
This will break current Web multi-threading users. To address this they can add the following
RUSTFLAGS
:We could add a new experimental flag that enables the right linker arguments for users, but I feel that's not in Rusts scope. Or like suggested before: a Rust-only
threads
target feature.Addresses #77839.
r? @alexcrichton