Skip to content

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

Merged
merged 16 commits into from
Jun 7, 2022

Conversation

Grubba27
Copy link
Contributor

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 :)

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 21, 2022
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@ghost
Copy link

ghost commented May 21, 2022

CLA assistant check
All CLA requirements met.

* 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"> };
Copy link
Member

Choose a reason for hiding this comment

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

  1. typedArray can be Int32Array too, right? At least according to MDN.
  2. 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.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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 :)

Copy link
Member

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).

* 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;
Copy link
Member

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" />

Copy link
Contributor Author

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

Copy link
Member

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

  1. Specifies // @lib: es2022.sharedmemory
  2. 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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

@sandersn sandersn self-assigned this May 31, 2022
Copy link
Member

@sandersn sandersn left a 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.

Copy link
Member

@sandersn sandersn left a 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.

@Grubba27
Copy link
Contributor Author

Grubba27 commented Jun 2, 2022

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
but still wont pass in tests 😢 maybe I'm looking in the wrong place ?

@sandersn
Copy link
Member

sandersn commented Jun 2, 2022

Well, the error has changed to indicate missing baselines. Run gulp baseline-accept and commit the resulting files. Then I can see what errors you're getting.

@Grubba27
Copy link
Contributor Author

Grubba27 commented Jun 2, 2022

Captura de Tela 2022-06-02 às 20 38 12
tried the command but it did not changed nothing 😭
the screenshot above shows how this I'm in the repo as it is here on github.
I have deleted the folder and installed everthing again and tried again and still does not updates other files running gulp baseline-accept

@sandersn
Copy link
Member

sandersn commented Jun 3, 2022

Ah. You need to

$ gulp runtests --t=es2022SharedMemory

first. Actually, gulp runtests-parallel to get all the test failures, in case there's more than one.

@Grubba27
Copy link
Contributor Author

Grubba27 commented Jun 3, 2022

Awesome! gulp runtests --t=es2022SharedMemory showed the errors and I have adjusted them.
Also I had commited the new base lines is that all right ?

Copy link
Member

@sandersn sandersn left a 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.

@sandersn
Copy link
Member

sandersn commented Jun 6, 2022

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.

@sandersn
Copy link
Member

sandersn commented Jun 6, 2022

reactJsxReactResolvedNodeNext.tsx still broken =(
I'll try checking out the branch locally.

@Grubba27
Copy link
Contributor Author

Grubba27 commented Jun 6, 2022

what was wrong ? if I may ask.

@sandersn
Copy link
Member

sandersn commented Jun 7, 2022

I think there were two related tests -- reactJsxResolvedNodeNext and reactJsxResolvedNodeNextEsm -- and you had only updated one baseline. I updated the other one.

@sandersn sandersn merged commit 4c50601 into microsoft:main Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants