-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Bump WebKit (oven-sh/WebKit#525 preview): save and restore generator locals in bulk #40667
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
4
commits into
main
Choose a base branch
from
farm/5b4dca44/webkit-525-generator-bulk-locals
base: main
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05a9da3
Bump WebKit (oven-sh/WebKit#525 preview): save and restore generator …
robobun 05f48ac
jsc-stress: name runNoJIT/runFTLNoCJIT runs, cache wide generators in…
robobun ab6a938
Follow the option rename in the oven-sh/WebKit#525 head
robobun 7411b2f
Update the bytecode portability snapshot for the new generator save/r…
robobun 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
174 changes: 174 additions & 0 deletions
174
test/js/bun/jsc-stress/fixtures/generator-save-restore-locals.js
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,174 @@ | ||
| //@ runDefault | ||
| //@ runDefault("--useGeneratorBulkSaveRestore=0") | ||
| //@ runDefault("--useJIT=0") | ||
| //@ runDefault("--useDFGJIT=0") | ||
| //@ runDefault("--useConcurrentJIT=0", "--thresholdForJITAfterWarmUp=10", "--thresholdForOptimizeAfterWarmUp=20", "--thresholdForFTLOptimizeAfterWarmUp=50") | ||
|
|
||
| function shouldBe(actual, expected) { | ||
| if (actual !== expected) | ||
| throw new Error(`bad value: ${actual}, expected ${expected}`); | ||
| } | ||
|
|
||
| // Mixed-type locals, resumed with next/throw. | ||
| function* mixed() { | ||
| let a = 1, b = 2.5, c = "s", d = { v: 3 }, e; | ||
| try { | ||
| a += yield a; | ||
| b += yield b; | ||
| e = yield c + d.v; | ||
| } catch (error) { | ||
| return [a, b, c, d.v, e, error]; | ||
| } | ||
| return [a, b, c, d.v, e]; | ||
| } | ||
| { | ||
| let iterator = mixed(); | ||
| shouldBe(iterator.next().value, 1); | ||
| shouldBe(iterator.next(10).value, 2.5); | ||
| shouldBe(iterator.next(0.5).value, "s3"); | ||
| shouldBe(JSON.stringify(iterator.throw("boom").value), '[11,3,"s",3,null,"boom"]'); | ||
| } | ||
|
|
||
| // Live sets of various sizes: 70 needs an out-of-line bit vector, 300 needs wide operands. | ||
| function makeWide(count) { | ||
| let declarations = []; | ||
| let names = []; | ||
| for (let i = 0; i < count; ++i) { | ||
| declarations.push(`let v${i} = ${i};`); | ||
| names.push(`v${i}`); | ||
| } | ||
| return new Function(` | ||
| return function* wide() { | ||
| ${declarations.join("\n")} | ||
| yield 0; | ||
| ${names.map((name) => `${name} += 1;`).join("\n")} | ||
| yield 1; | ||
| return ${names.join(" + ")}; | ||
| }`)(); | ||
| } | ||
| for (let count of [3, 9, 70, 300]) { | ||
| let wide = makeWide(count); | ||
| let expected = 0; | ||
| for (let i = 0; i < count; ++i) | ||
| expected += i + 1; | ||
| for (let round = 0; round < 3; ++round) { | ||
| let iterator = wide(); | ||
| shouldBe(iterator.next().value, 0); | ||
| shouldBe(iterator.next().value, 1); | ||
| shouldBe(iterator.next().value, expected); | ||
| } | ||
| } | ||
|
|
||
| // Locals under TDZ hold the empty value across a yield. | ||
| function* tdz(flag) { | ||
| yield 1; | ||
| if (flag) { | ||
| let later = 5; | ||
| yield later; | ||
| } | ||
| let after = 7; | ||
| yield after; | ||
| { | ||
| yield 2; | ||
| let x = 9; | ||
| yield x; | ||
| } | ||
| } | ||
| { | ||
| let iterator = tdz(false); | ||
| shouldBe(iterator.next().value, 1); | ||
| shouldBe(iterator.next().value, 7); | ||
| shouldBe(iterator.next().value, 2); | ||
| shouldBe(iterator.next().value, 9); | ||
| } | ||
|
|
||
| // Saved locals share the lexical environment with captured variables. | ||
| function* captured() { | ||
| let counter = 0; | ||
| let local = 100; | ||
| const bump = () => ++counter; | ||
| yield bump(); | ||
| local += counter; | ||
| yield bump() + local; | ||
| return [counter, local]; | ||
| } | ||
| { | ||
| let iterator = captured(); | ||
| shouldBe(iterator.next().value, 1); | ||
| shouldBe(iterator.next().value, 103); | ||
| shouldBe(JSON.stringify(iterator.next().value), "[2,101]"); | ||
| } | ||
|
|
||
| // Nothing live across the yields. | ||
| function* empty() { | ||
| yield 1; | ||
| yield 2; | ||
| } | ||
| { | ||
| let iterator = empty(); | ||
| shouldBe(iterator.next().value, 1); | ||
| shouldBe(iterator.next().value, 2); | ||
| shouldBe(iterator.next().done, true); | ||
| } | ||
|
|
||
| // Async function, async generator, and yield*. | ||
| async function asyncFunction(promise) { | ||
| let a = 1, b = [1, 2, 3], c = "x"; | ||
| a += await promise; | ||
| for (const v of b) | ||
| c += await v; | ||
| return a + c; | ||
| } | ||
| async function* asyncGenerator() { | ||
| let accumulator = 0; | ||
| for (let i = 0; i < 3; ++i) { | ||
| accumulator += await i; | ||
| yield accumulator; | ||
| } | ||
| yield* empty(); | ||
| return accumulator; | ||
| } | ||
| function* delegating() { | ||
| return yield* mixed(); | ||
| } | ||
| let asyncDone = false; | ||
| (async () => { | ||
| shouldBe(await asyncFunction(Promise.resolve(10)), "11x123"); | ||
| let values = []; | ||
| for await (const value of asyncGenerator()) | ||
| values.push(value); | ||
| shouldBe(JSON.stringify(values), "[0,1,3,1,2]"); | ||
| asyncDone = true; | ||
| })(); | ||
| { | ||
| let iterator = delegating(); | ||
| iterator.next(); | ||
| iterator.next(1); | ||
| iterator.next(1); | ||
| shouldBe(JSON.stringify(iterator.next().value), '[2,3.5,"s",3,null]'); | ||
| } | ||
|
|
||
| // Tier up with int32 locals, then resume with double and string values. | ||
| function* counting(count, start) { | ||
| let i = 0, accumulator = start, object = { f: 1 }; | ||
| while (i < count) { | ||
| accumulator = accumulator + object.f; | ||
| yield accumulator; | ||
| ++i; | ||
| } | ||
| return accumulator; | ||
| } | ||
| function drive(start, count) { | ||
| let iterator = counting(count, start); | ||
| let last; | ||
| for (let result = iterator.next(); !result.done; result = iterator.next()) | ||
| last = result.value; | ||
| return last; | ||
| } | ||
| for (let i = 0; i < testLoopCount; ++i) | ||
| shouldBe(drive(0, 10), 10); | ||
| shouldBe(drive(0.5, 10), 10.5); | ||
| shouldBe(drive("s", 3), "s111"); | ||
|
|
||
| drainMicrotasks(); | ||
| shouldBe(asyncDone, true); |
Oops, something went wrong.
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.