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

Add async variants of Atomics.wait #3504

Merged
merged 6 commits into from Jul 5, 2023
Merged

Add async variants of Atomics.wait #3504

merged 6 commits into from Jul 5, 2023

Conversation

allsey87
Copy link
Contributor

@allsey87 allsey87 commented Jul 4, 2023

Atomics.waitAsync now has reasonable support in most browsers with Firefox being the notable exception, however they have a bug report for implementing it.

I used the binding for Atomics.wait as a reference and one thing that seems off to me is that the typed_array argument for the bigint varieties of these functions take an Int32Array, instead of a BigInt64Array/BigUint64Array. It seems to me that the most correct thing to do here is two make further variants of this function, e.g., add the *_biguint variants, which also take u64 as their value argument. If there is a consensus on this, I can add the variants and we can rename this PR to something like "Clean up Atomics.wait and Atomics.waitAsync".

@allsey87
Copy link
Contributor Author

allsey87 commented Jul 4, 2023

Actually, at least according to the docs that I can find, BigUintArray is not supported, only BigIntArray. In which case, a clean up is definitely needed and the comments should be adjusted since they currently suggest that BigUintArray is possible (even though the type signature only accepts Int32Array).

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

I don't know what happened here, but I would argue that the current wait_bigint functions are just wrong, they should take a BigInt64Array instead of a Int32Array.

But I think we don't need to add to that any further.
Also we could definitely remove the documentation around BigUint64Array.

crates/js-sys/src/lib.rs Outdated Show resolved Hide resolved
crates/js-sys/src/lib.rs Outdated Show resolved Hide resolved
@daxpedda daxpedda added the waiting for author Waiting for author to respond label Jul 5, 2023
@daxpedda daxpedda self-assigned this Jul 5, 2023
@allsey87 allsey87 requested a review from daxpedda July 5, 2023 12:38
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Thanks!

@daxpedda
Copy link
Collaborator

daxpedda commented Jul 5, 2023

I was thinking about using this here:

#[wasm_bindgen(static_method_of = Atomics, js_name = waitAsync)]
fn wait_async(buf: &js_sys::Int32Array, index: i32, value: i32) -> WaitAsyncResult;

But it wouldn't help much because we need the binding to detect support anyway. We also want to have the custom return type to avoid the overhead of Reflect, something we won't add in js-sys because we don't do this in general there.

@daxpedda daxpedda merged commit e36b616 into rustwasm:main Jul 5, 2023
25 checks passed
@allsey87
Copy link
Contributor Author

allsey87 commented Jul 5, 2023

But it wouldn't help much because we need the binding to detect support anyway. We also want to have the custom return type to avoid the overhead of Reflect, something we won't add in js-sys because we don't do this in general there.

Yep, I was thinking that/stumbled across that when I was checking whether waitAsync was already implemented.

Regarding the non-async variants of wait, shall I put together a PR that fixes type_array for the _bigint variants? It would be a breaking change, although I guess no one is using this API...

@daxpedda
Copy link
Collaborator

daxpedda commented Jul 5, 2023

Regarding the non-async variants of wait, shall I put together a PR that fixes type_array for the _bigint variants? It would be a breaking change, although I guess no one is using this API...

Personally I would be fine with it because it looks like a broken API to me, so this is more like fixing a bug then a compatibility issue.

But I can't make that call myself.
Cc @Liamolucko, @hamza1311.

@hamza1311
Copy link
Collaborator

I'm fine with such breaking changes. It won't be the first time we made breaking changes to API that no one is/should be using (as an example, removing interface types comes to mind)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Waiting for author to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants