-
Notifications
You must be signed in to change notification settings - Fork 216
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
parking_lot_core 0.8.1 wasm link issue #269
Comments
https://github.com/Amanieu/parking_lot/compare/0.8.0...0.8.1?w=1#diff-f8a0a8b9353ddc2e1efd135d75ec0668f64e2674c15e9b1cda089cbd69f60372 shows no difference in the parking implementation between v0.8.0 and v0.8.1 that could explain this. Does this still happen with LTO enabled? |
I tested it now with |
I suspect this is related to Does |
The parking_lot algorithm itself need to know the current time for fair locks but the single-threaded wasm option shouldn't need this as there are no other threads against which it needs to be fair. |
Interesting! Is there a way to tell parking_lot that it is compiling for a single-threaded target, so that it does not require the |
It should compile for a single-threaded target by default. Multi-threading requires the bulk memory wasm proposal and atomic instructions. Both of which are not supported for the WASM MVP that is targeted by default. In addition it requires all parts of the program to be compiled with multi-threading support I believe, but libstd isn't by default. |
I suspect that the only reason parking_lot 0.8.0 worked and 0.8.1 doesn't is because some subtle failure of rustc to elide unused code (using instant). For my use-case ("pure wasm" = no instant) we would need cfg-blocks around all uses of the For example: #[cfg(feature = "instant")]
unsafe fn park_until(&self, timeout: Instant) -> bool { ... } This would be a very intrusive change to the parking_lot code base, disabling all uses of times ( (Using Another alternative is that I create a new wrapper crate around parking_lot which exposes only what I need ( This solution is not very attractive though, as it would require third-party-dependencies to also switch to my new wrapper crate. Ideally |
Why do you need locking primitives in a single threaded environment? |
Great question! Say you have a library that may or may not be used from a multithreaded context, so the library uses The answer is: it used to be possible, but with parking_lot_core 0.8.1 it no longer is. So who's responsibility is it to fix this? The app can do a work-around by adding The library could add feature flags around all uses of The third place to fix this is in parking_lot itself, by stating "parking_lot supports pure wasm32 contexts". I think this is the route that is the best. In summary: Either we say "parking_lot should work for pure wasm32 targets" and work towards that, OR we say "if you use |
That makes sense. I got the imoression that your code needed it directly and your code was targeting single threaded wasm only :) |
Isn't it related to this?
if let Some(left) = timeout.checked_duration_since(Instant::now()) { |
That one is only used when wasm atomics are enabled, which aren't by default. |
Sorry, I misread some of the comments, it feels like the source and the solution have already been found. |
Works around Amanieu/parking_lot#269 where later versions of `parking_lot` were pulling in an undefined `env::now` symbol failing to be used in `wasm32-unknown-unknown` target (when not targetting web environments). Replaced for now with just `std::sync::Mutex`, though we could optionally use `parking_lot` on non-wasm32 and use just "unsafe" single-threaded access for wasm32-unknown-unknown. Do want that core issue in parking_lot to be resolved, or at least clarified if non-web wasm32 is a target or not. But at least this solves our problems for now in our own crate.
Works around Amanieu/parking_lot#269 where later versions of `parking_lot` were pulling in an undefined `env::now` symbol failing to be used in `wasm32-unknown-unknown` target (when not targetting web environments). Replaced for now with just `std::sync::Mutex`, though we could optionally use `parking_lot` on non-wasm32 and use just "unsafe" single-threaded access for wasm32-unknown-unknown. Do want that core issue in parking_lot to be resolved, or at least clarified if non-web wasm32 is a target or not. But at least this solves our problems for now in our own crate.
Would indeed be great to clarify if non-web |
I'm happy to accept any PRs to support |
Yeah For now we haven't run into that many dependencies that we use in |
Works around Amanieu/parking_lot#269 where later versions of `parking_lot` were pulling in an undefined `env::now` symbol failing to be used in `wasm32-unknown-unknown` target (when not targetting web environments). Replaced for now with just `std::sync::Mutex`, though we could optionally use `parking_lot` on non-wasm32 and use just "unsafe" single-threaded access for wasm32-unknown-unknown. Do want that core issue in parking_lot to be resolved, or at least clarified if non-web wasm32 is a target or not. But at least this solves our problems for now in our own crate.
Temporary workaround for a mis-compilation: Amanieu/parking_lot#269
This replaces the use of parking_lot::Mutex with just plain std::sync::Mutex due to Amanieu/parking_lot#269 and honestly the use parking_lot was a bit of overkill here anyways. This also introduces a `wasm-web` feature that can be enabled to enable additional features in chrono and ring to allow tame-oauth to function a wasm web (browser) context. We don't assume the user is in a web context based on targetting wasm32-unknown-unknown, hence the feature.
swc_atoms: - Use `string_cache` with `parking_lot` patch applied. wasm: - Pin `parking_lot_core` to `=0.8.0` to workaround Amanieu/parking_lot#269.
This recently popped up again, as https://lib.rs/crates/string_cache just got an update, adding |
My temporary workaround is to add the following to my Cargo.toml file. [target.'cfg(target_arch = "wasm32")'.dependencies]
parking_lot_core = "=0.8.0" |
Hey folks 👋 I just wanna jump and and provide some context because I am the person that has originally added and also removed the While you can lock To fix the issue add [features]
# `instant/wasm-bindgen` makes sure it will use `js_sys` for getting the system time
# `instant/inaccurate` uses `Date.now()` instead of `performance.now()`
default = ["instant/wasm-bindgen", "instant/inaccurate"]
[dependencies]
instant = "0.1.12" Hope this helps. |
@d3lm That only works for WASM for the web, for running WASM outside of a browser (for example with wasmtime, wasmer, wasm3, wawm etc) as far as I know the only solution is to still unfortunately lock parking lot to before |
@d3lm that unfortunately won’t help me in my scenario because I’m not using the wasm file exclusively in a browser and when I do I’m not using wasm-bindgen. My code is also single threaded… a dependency of a dependency started depending on parking_lot and it broke the wasm interface because parking_lot introduced an import. I think there should at least be a way for us to manually provide a function to parking_lot that allows it to get the time rather than it adding its own wasm import. That way we can control the wasm interface. |
@repi Oh I see, it's true that this will not work if you run it outside the browser nor with Node.js (target nodejs). I am personally not so familiar with wasmtime as the host, but does it also provide some time function similar to |
@dsherret Yes I agree, there seems to be an issue that it's not eliminating all the code which should be eliminated because |
Does anyone actually use the timeout API on |
@Amanieu you can't really use it on pure |
@Amanieu But we can't remove the dependency on |
Oh I see, you mean the |
I was thinking of just having |
Yep thats a good idea. |
@Amanieu 🙌 |
fix: bump parking_lot to 0.12 in order to not create wasm export parking_lot 0.11 was using parking_lot_core 0.8 which was creating a wasm export when targeting wasm: Amanieu/parking_lot#269 This bumps to parking_lot 0.12, which uses parking_lot_core 0.9 which doesn't have the issue where it creates the wasm export.
fix: bump parking_lot to 0.12 in order to not create wasm export parking_lot 0.11 was using parking_lot_core 0.8 which was creating a wasm export when targeting wasm: Amanieu/parking_lot#269 This bumps to parking_lot 0.12, which uses parking_lot_core 0.9 which doesn't have the issue where it creates the wasm export.
303: Bump parking_lot packages r=jonas-schievink a=eliascodes This is motivated by recent changes to `parking_lot` affecting `wasm32-unknown-unknown` targets (see Amanieu/parking_lot#269 if interested). My project depends on `parking_lot` via `salsa`, which is why I'm facing this issue. TLDR is that `parking_lot` released a new version that provides a fix for the above. I'm hoping that version can be included in a future version of `salsa`. For reference, here's the relevant part of the changelog: https://github.com/Amanieu/parking_lot/blob/HEAD/CHANGELOG.md#parking_lot-0120-parking_lot_core-090-lock_api-046-2022-01-28 I belive the only changes that might affect APIs used by `salsa` are in PRs Amanieu/parking_lot#313 and https://github.com/Amanieu/parking_lot/pull/344/files, but I'm unfamiliar with the internals of either project so could easily be wrong. I can build and test successfully locally with these bumps. Let me know if there's anything else I can do to help this over the line. Co-authored-by: Elias Malik <elias0789@gmail.com>
Starting with parking_lot_core 0.8.1, when compiling to wasm there is now a depdendency on "env".
This means one can no longer use parking_lot from within a wasm runtime, such as
wasmtime
.When compiling for the web, one can address this problem with
parking_lot = { version = "0.11", features = ["wasm-bindgen"] }
, but this does not work for non-web wasm runtimes.Reproduce
Cargo.toml
:main.rs
:Using
wasm2wat
:(with
parking_lot_core = "=0.8.0"
there is noimport "env"
)The text was updated successfully, but these errors were encountered: