Repository navigation
[JSC] The control flow profiler's basic blocks and function ranges match the text #828
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
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
aef14d2
[JSC] The control flow profiler's basic blocks and function ranges ma…
dylan-conway dd69957
Give a basic block that is part of an expression its own end instead …
dylan-conway 88185ad
Test each control flow profiler change on its own and leave the funct…
dylan-conway eede189
Make a part of an expression a gap in the basic blocks around it, kee…
dylan-conway 6caea36
Declare the basic block of a static field when the class is evaluated…
dylan-conway f6ba728
Look up the basic block of the computed field, not the one around it,…
dylan-conway c2c53d4
Keep the parse mode of a function range in FunctionHasExecutedCache, …
dylan-conway 368280a
Give FunctionHasExecutedCache the parse mode of every range, not only…
dylan-conway 5426125
Give the empty finally of a try with a return in a derived constructo…
dylan-conway e0cf9ae
Have the parse mode in the key of FunctionHasExecutedCache, so that a…
dylan-conway bd30236
Say which ranges have a basic block before they run where it is decid…
dylan-conway 3b1ea22
Nest the basic blocks of statements as the source does, with nothing …
dylan-conway 2e56a0b
Give the block the parser has around a function declaration in an if …
dylan-conway f59bbe0
Test what is after each kind of loop, a label, a finally and an else …
dylan-conway 5302573
Test what is between the last clause of a switch and its brace, after…
dylan-conway 984d4a2
Have what is after a statement go up to the end of its list, with tha…
dylan-conway 0d1cda9
Have the end offset of a block be after its brace, as that of any sta…
dylan-conway 2607907
Have a do while statement start at its do, and test the end offset of…
dylan-conway f00d5af
Find the gaps of a basic block in one sorted list of basic blocks and…
dylan-conway bd957c3
Have the basic block of a program with no token start at its end, as …
dylan-conway 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
15 changes: 15 additions & 0 deletions
15
JSTests/controlFlowProfiler/arrowfunction-expression-body.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,15 @@ | ||
| var basicBlockExecutionCount = $vm.basicBlockExecutionCount; | ||
|
|
||
| load("./driver/driver.js"); | ||
|
|
||
| function foo() { return 1; } | ||
|
|
||
| // An expression that is the body of an arrow function is the end of it. | ||
| function testLastCharacter() { | ||
| let f = () => foo(); | ||
| f(); | ||
| f(); | ||
| } | ||
| testLastCharacter(); | ||
| assert(basicBlockExecutionCount(testLastCharacter, "foo()") === 2, "the body runs per call"); | ||
| assert(basicBlockExecutionCount(testLastCharacter, ");\n f();") === 2, "and so does its last character"); |
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,50 @@ | ||
| var basicBlockExecutionCount = $vm.basicBlockExecutionCount; | ||
|
|
||
| load("./driver/driver.js"); | ||
|
|
||
| function foo() { } | ||
|
|
||
| function testBreakNotTaken(n) { | ||
| for (let i = 0; i < n; i++) { | ||
| if (i > n) | ||
| break; | ||
| foo(); | ||
| } | ||
| } | ||
| testBreakNotTaken(3); | ||
| checkBasicBlock(testBreakNotTaken, "break", ShouldNotHaveExecuted); | ||
| assert(basicBlockExecutionCount(testBreakNotTaken, "foo()") === 3, "what follows the if runs each time"); | ||
|
|
||
| function testBreakTaken(n) { | ||
| for (let i = 0; i < n; i++) { | ||
| if (i === 1) | ||
| break; | ||
| foo(); | ||
| } | ||
| } | ||
| testBreakTaken(3); | ||
| assert(basicBlockExecutionCount(testBreakTaken, "break") === 1, "break runs once"); | ||
| assert(basicBlockExecutionCount(testBreakTaken, "foo()") === 1, "what follows the if runs until then"); | ||
|
|
||
| function testContinue(n) { | ||
| for (let i = 0; i < n; i++) { | ||
| if (i % 2) | ||
| continue; | ||
| foo(); | ||
| } | ||
| } | ||
| testContinue(5); | ||
| assert(basicBlockExecutionCount(testContinue, "continue") === 2, "continue runs for the odd ones"); | ||
| assert(basicBlockExecutionCount(testContinue, "foo()") === 3, "what follows the if runs for the even ones"); | ||
|
|
||
| function testContinueNotTaken(n) { | ||
| for (let i = 0; i < n; i++) { | ||
| if (i > n) { | ||
| continue; | ||
| } | ||
| foo(); | ||
| } | ||
| } | ||
| testContinueNotTaken(2); | ||
| checkBasicBlock(testContinueNotTaken, "continue", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testContinueNotTaken, "foo()", ShouldHaveExecuted); |
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,103 @@ | ||
| var basicBlockExecutionCount = $vm.basicBlockExecutionCount; | ||
|
|
||
| load("./driver/driver.js"); | ||
|
|
||
| function foo() { return 1; } | ||
| function bar() { return 2; } | ||
| function key() { return "k"; } | ||
|
|
||
| function testNeverConstructed() { | ||
| class A { | ||
| a = foo(); | ||
| static b = bar(); | ||
| } | ||
| return A; | ||
| } | ||
| testNeverConstructed(); | ||
| checkBasicBlock(testNeverConstructed, "class A", ShouldHaveExecuted); | ||
| checkBasicBlock(testNeverConstructed, "a = foo", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testNeverConstructed, "foo()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testNeverConstructed, "static b", ShouldHaveExecuted); | ||
| checkBasicBlock(testNeverConstructed, "bar()", ShouldHaveExecuted); | ||
| checkBasicBlock(testNeverConstructed, "return A", ShouldHaveExecuted); | ||
|
|
||
| function testCounts(times) { | ||
| class A { | ||
| a = foo(); | ||
| [key()] = bar(); | ||
| static c = foo(); | ||
| } | ||
| for (let i = 0; i < times; i++) | ||
| new A; | ||
| } | ||
| testCounts(3); | ||
| assert(basicBlockExecutionCount(testCounts, "class A") === 1, "the class is evaluated once"); | ||
| assert(basicBlockExecutionCount(testCounts, "a = foo") === 3, "a field is initialized once per instance"); | ||
| assert(basicBlockExecutionCount(testCounts, "key()") === 1, "a computed key is evaluated once"); | ||
| assert(basicBlockExecutionCount(testCounts, "bar()") === 3, "the value of a computed field is evaluated once per instance"); | ||
| assert(basicBlockExecutionCount(testCounts, "static c") === 1, "a static field is initialized once"); | ||
| assert(basicBlockExecutionCount(testCounts, "for (") === 1, "what follows the class runs once"); | ||
|
|
||
| function testBranchInField(x) { | ||
| class A { | ||
| a = x ? foo() : bar(); | ||
| } | ||
| return new A; | ||
| } | ||
| testBranchInField(true); | ||
| checkBasicBlock(testBranchInField, "foo()", ShouldHaveExecuted); | ||
| checkBasicBlock(testBranchInField, "bar()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testBranchInField, "return new A", ShouldHaveExecuted); | ||
|
|
||
| function testStaticBlock(x) { | ||
| class A { | ||
| static { | ||
| if (x) | ||
| foo(); | ||
| else | ||
| bar(); | ||
| } | ||
| } | ||
| return A; | ||
| } | ||
| testStaticBlock(true); | ||
| checkBasicBlock(testStaticBlock, "static {", ShouldHaveExecuted); | ||
| checkBasicBlock(testStaticBlock, "if (x)", ShouldHaveExecuted); | ||
| checkBasicBlock(testStaticBlock, "foo()", ShouldHaveExecuted); | ||
| checkBasicBlock(testStaticBlock, "bar()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testStaticBlock, "return A", ShouldHaveExecuted); | ||
|
|
||
| // What follows a field in the file is not the field, however far it is. | ||
| function testFarFromField() { | ||
| class A { | ||
| a = foo(); | ||
| } | ||
| new A; | ||
| new A; | ||
| function never() { | ||
| // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
| bar(); | ||
| } | ||
| return A; | ||
| } | ||
| testFarFromField(); | ||
| checkBasicBlock(testFarFromField, "bar()", ShouldNotHaveExecuted); | ||
| assert(basicBlockExecutionCount(testFarFromField, "return A") === 1, "what follows the class runs once"); | ||
|
|
||
| function testFieldAfterAccessor() { | ||
| class A { | ||
| get b() { return 1; } | ||
| a = foo(); | ||
| } | ||
| return A; | ||
| } | ||
| testFieldAfterAccessor(); | ||
| checkBasicBlock(testFieldAfterAccessor, "foo()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testFieldAfterAccessor, "return A", ShouldHaveExecuted); | ||
|
|
||
| function testSkippedClass(x) { | ||
| x ??= class { a = foo(); }; | ||
| bar(); | ||
| } | ||
| testSkippedClass(1); | ||
| checkBasicBlock(testSkippedClass, "bar()", ShouldHaveExecuted); |
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,10 @@ | ||
| function f(){g();g();g();g();g();g();g();g();} | ||
| function g() { } | ||
|
|
||
| load("./driver/driver.js"); | ||
|
|
||
| // Its constructor is in a text of the engine's own, and the offsets of that text are not offsets into this file. | ||
| class NeverConstructed { } | ||
|
|
||
| f(); | ||
| checkBasicBlock(f, "g()", ShouldHaveExecuted); | ||
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,68 @@ | ||
| var basicBlockExecutionCount = $vm.basicBlockExecutionCount; | ||
|
|
||
| load("./driver/driver.js"); | ||
|
|
||
| function foo() { } | ||
| function bar() { } | ||
|
|
||
| function testDoWhile(n) { | ||
| let i = 0; | ||
| do { | ||
| foo(); | ||
| i++; | ||
| } while (i < n); | ||
| bar(); | ||
| } | ||
| testDoWhile(3); | ||
| assert(basicBlockExecutionCount(testDoWhile, "let i") === 1, "what precedes the loop runs once"); | ||
| assert(basicBlockExecutionCount(testDoWhile, "foo()") === 3, "the body runs each time"); | ||
| assert(basicBlockExecutionCount(testDoWhile, "i < n") === 3, "the condition runs each time"); | ||
| assert(basicBlockExecutionCount(testDoWhile, "bar()") === 1, "what follows the loop runs once"); | ||
|
|
||
| function testDoWhileBreak() { | ||
| do { | ||
| foo(); | ||
| if (true) | ||
| break; | ||
| bar(); | ||
| } while (true); | ||
| foo(); | ||
| } | ||
| testDoWhileBreak(); | ||
| checkBasicBlock(testDoWhileBreak, "bar()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testDoWhileBreak, "while (true)", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testDoWhileBreak, "foo();\n}", ShouldHaveExecuted); | ||
|
|
||
| function testLabeledBlock(x) { | ||
| label: { | ||
| if (x) | ||
| break label; | ||
| foo(); | ||
| } | ||
| bar(); | ||
| } | ||
| testLabeledBlock(true); | ||
| checkBasicBlock(testLabeledBlock, "break label", ShouldHaveExecuted); | ||
| checkBasicBlock(testLabeledBlock, "foo()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testLabeledBlock, "bar()", ShouldHaveExecuted); | ||
|
|
||
| function testNestedLabels(x) { | ||
| outer: inner: for (;;) { | ||
| if (x) | ||
| break outer; | ||
| foo(); | ||
| break inner; | ||
| } | ||
| bar(); | ||
| } | ||
| testNestedLabels(true); | ||
| checkBasicBlock(testNestedLabels, "break outer", ShouldHaveExecuted); | ||
| checkBasicBlock(testNestedLabels, "foo()", ShouldNotHaveExecuted); | ||
| checkBasicBlock(testNestedLabels, "bar()", ShouldHaveExecuted); | ||
|
|
||
| function testLabeledFunction() { | ||
| label: function labeled() { } | ||
| bar(); | ||
| } | ||
| testLabeledFunction(); | ||
| checkBasicBlock(testLabeledFunction, "bar()", ShouldHaveExecuted); |
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,16 @@ | ||
| load("./driver/driver.js"); | ||
|
|
||
| function foo() { } | ||
|
|
||
| // Calling a generator does not run its body. | ||
| function* neverResumed() { | ||
| foo(); | ||
| } | ||
| neverResumed(); | ||
| checkBasicBlock(neverResumed, "foo()", ShouldNotHaveExecuted); | ||
|
|
||
| function* resumed() { | ||
| foo(); | ||
| } | ||
| resumed().next(); | ||
| checkBasicBlock(resumed, "foo()", ShouldHaveExecuted); | ||
|
dylan-conway marked this conversation as resolved.
Resolved
|
||
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.