-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix(49198): Added missing definition for Atomics.waitAsync and es2022 sharedmemory file #49204
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
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
src/lib/es2022.sharedmemory.d.ts
Outdated
* Waits asynchronously on a shared memory location and returns a Promise | ||
* @see wait | ||
*/ | ||
waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedArray
can beInt32Array
too, right? At least according to MDN.- waitAsync is only available on Chrome-based browsers, not Firefox or Safari. Even though it's stage 3, I'm not super happy about adding it since for browser features outside the standard we require at least two implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are right! Should I adjust for other functions also ? like wait
method also expects Int32Array
or BigInt64Array
I don't know what would be better.
Only changing this one or all other methods...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR/ Issue comes from an Issue from a lib that uses Deno. In deno there are no type def. for this method, thought that I could help that issue by adjusting this.
We should wait for Firefox or Safari to implement this in order to proceed with this pull request correct ? I think this makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. It's stage 3 in the TC39 standard process, so I think it's appropriate to merge. I'm more unhappy that browser authors are lagging the standards process (though Typescript is certainly guilty of doing the same from time to time).
src/lib/es2022.sharedmemory.d.ts
Outdated
* Until this atomic operation completes, any other read or write operation against the array | ||
* will block. | ||
*/ | ||
add(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of duplicating these declarations, you should /// <reference lib="es2020.sharedmemory" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface Atomics {
/**
* A non-blocking, asynchronous version of wait and usable on the main thread.
* Waits asynchronously on a shared memory location and returns a Promise
* @see wait
*/
waitAsync(typedArray: BigInt64Array | Int32Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> };
}
Like the code above ? I looked how they added at
array method in 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether you need to reference es2020.sharedmemory. You need to add a test that
- Specifies
// @lib: es2022.sharedmemory
- Uses both Atomics.waitAsync and Atomics.wait to make sure both are available.
Look at $ts/tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts for an example of a test that does (1).
You'll probably want to put the test in tests/cases/conformance/es2022.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test like the code below:
// @target: esnext
// @lib: es2022.sharedmemory
// @noemit: true
// @strict: true
const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024);
const int32 = new Int32Array(sab);
Atomics.wait(int32, 0, 0);
await Atomics.waitAsync(int32, 0, 0);
I'm not sure what does // @noemit: true
mean/do.
I've looked some other examples like tests/cases/conformance/es2020/constructBigint.ts
and tests/cases/conformance/generators/generatorReturnTypeInference.ts
and none of them had this decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for some reason the CI started breaking 😢 perhaps I did something wrong in src/lib/es2022.d.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, just needs a test now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait. es2022.sharedmemory needs to be added to the list of libs (I think in program.ts?) and the new baselines need to be added after the test passes.
I searched for occurencies of es2020.sharedmemory and there was missing es2022.sharedmemory declaration in commandLineParser |
Co-authored-by: Eyal Halpern Shalev <[email protected]>
Well, the error has changed to indicate missing baselines. Run |
Ah. You need to $ gulp runtests --t=es2022SharedMemory first. Actually, |
Awesome! gulp runtests --t=es2022SharedMemory showed the errors and I have adjusted them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except for one small grammar change to the jsdoc.
Also reactJsxReactResolvedNodeNext.tsx is failing -- I guess that it was broken on main, so I recommend merging from main + re-running tests + re-accepting baselines. |
reactJsxReactResolvedNodeNext.tsx still broken =( |
what was wrong ? if I may ask. |
I think there were two related tests -- reactJsxResolvedNodeNext and reactJsxResolvedNodeNextEsm -- and you had only updated one baseline. I updated the other one. |
Fixes #
This issues relates to #49198
I was not able to try the code sample to be sure about the return value of waitAsync when async flag is true. Perhaps Eyal-Shalev could help me in this one :)