Repository navigation
Bump WebKit (oven-sh/WebKit#977 preview): a function-typed field that holds a promise's resolve is read without a test #47683
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
Open
robobun
wants to merge
2
commits into
aot-follow-up-1031
Choose a base branch
from
robobun/a72f4800/promise-resolving-functions
base: aot-follow-up-1031
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...el/field-writers/reject-of-a-promise-stored-in-a-function-field-is-read-without-a-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // The reject function that `new Promise` hands its executor, stored into a field typed as a function: the field holds its declared type from birth, and a read of it is one load. | ||
| // The loop reads the field 160,000 times. Without the fact each read tests the object first: 160,000 branches more. | ||
| // COUNT: branches <= 420000 | ||
| class Call { | ||
| reject!: (reason: Error) => void; | ||
| promise: Promise<number>; | ||
| constructor() { | ||
| this.promise = new Promise<number>((_resolve, reject) => { | ||
| this.reject = reject; | ||
| }); | ||
| } | ||
| } | ||
| export function fail(list: Call[], reason: Error): void { | ||
| for (let j = 0; j < list.length; j++) list[j]!.reject(reason); | ||
| } | ||
| const list: Call[] = []; | ||
| for (let i = 0; i < 16; i++) list.push(new Call()); | ||
| const reason = new Error("batch failed"); | ||
| for (let turn = 0; turn < 10000; turn++) fail(list, reason); | ||
| let failures = 0; | ||
| for (const result of await Promise.allSettled(list.map(c => c.promise))) { | ||
| if (result.status === "rejected" && result.reason.message === "batch failed") failures++; | ||
| } | ||
| console.log(failures); |
25 changes: 25 additions & 0 deletions
25
...ot/parallel/field-writers/resolve-of-a-promise-stored-in-a-field-that-may-be-undefined.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // The same field without the `!`: declared as the function or undefined, and undefined until the executor runs. What the executor stores is a function, so the slot keeps its declared type. | ||
| // The loop reads the field 160,000 times. Without the fact each read tests the object first: 160,000 branches more. | ||
| // COUNT: branches <= 750000 | ||
| class Call { | ||
| resolve: ((v: number) => void) | undefined = undefined; | ||
| promise: Promise<number>; | ||
| constructor() { | ||
| this.promise = new Promise<number>(r => { | ||
| this.resolve = r; | ||
| }); | ||
| } | ||
| } | ||
| export function settle(list: Call[], values: number[]): void { | ||
| for (let j = 0; j < list.length; j++) list[j]!.resolve!(values[j]!); | ||
| } | ||
| const list: Call[] = []; | ||
| const values: number[] = []; | ||
| for (let i = 0; i < 16; i++) { | ||
| list.push(new Call()); | ||
| values.push(i); | ||
| } | ||
| for (let turn = 0; turn < 10000; turn++) settle(list, values); | ||
| let sum = 0; | ||
| for (const v of await Promise.all(list.map(c => c.promise))) sum += v; | ||
| console.log(sum); |
26 changes: 26 additions & 0 deletions
26
...l/field-writers/resolve-of-a-promise-stored-in-a-function-field-is-read-without-a-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // The resolve function that `new Promise` hands its executor is stored into a field typed as a function. Flow knows it is a function, so the field holds its declared type | ||
| // from birth: a read of it is one load, with no test of the object in front. The batching pattern: each pending call keeps its resolve, and one settle loop calls them all. | ||
| // The loop reads the field 160,000 times. Without the fact each read tests the object first: 160,000 branches more. | ||
| // COUNT: branches <= 750000 | ||
| class Call { | ||
| resolve!: (v: number) => void; | ||
| promise: Promise<number>; | ||
| constructor() { | ||
| this.promise = new Promise<number>(r => { | ||
| this.resolve = r; | ||
| }); | ||
| } | ||
| } | ||
| export function settle(list: Call[], values: number[]): void { | ||
| for (let j = 0; j < list.length; j++) list[j]!.resolve(values[j]!); | ||
| } | ||
| const list: Call[] = []; | ||
| const values: number[] = []; | ||
| for (let i = 0; i < 16; i++) { | ||
| list.push(new Call()); | ||
| values.push(i); | ||
| } | ||
| for (let turn = 0; turn < 10000; turn++) settle(list, values); | ||
| let sum = 0; | ||
| for (const v of await Promise.all(list.map(c => c.promise))) sum += v; | ||
| console.log(sum); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.