Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] handle assignments in dead code (#3212)
* wip handle assignments in dead code * Test skipped code does not cause deoptimizations * Add tests and slightly adapt logic * Some mini-optimizations Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
61b3129
commit 6106af1
Showing
13 changed files
with
97 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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 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,3 @@ | ||
module.exports = { | ||
description: 'only deoptimizes assigned variables when the assignment is included' | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/form/samples/lazy-assignment-deoptimization/_expected.js
This file contains 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,3 @@ | ||
console.log('retained'); | ||
|
||
console.log('retained'); |
This file contains 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,12 @@ | ||
const foo = { toggled: false }; | ||
const bar = { toggled: false }; | ||
|
||
if (foo.toggled) { | ||
foo.toggled = bar; | ||
} | ||
|
||
if (foo.toggled) console.log('this should be removed'); | ||
else console.log('retained'); | ||
|
||
if (bar.toggled) console.log('this should be removed'); | ||
else console.log('retained'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/assignee-is-deoptimized/_config.js
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'makes sure the assignee is deoptimized' | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/assignment-deoptimization/assignee-is-deoptimized/main.js
This file contains 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,5 @@ | ||
const flags = { updated: false }; | ||
let toBeUpdated = {}; | ||
toBeUpdated = flags; | ||
toBeUpdated.updated = true; | ||
if (!flags.updated) throw new Error('Update was not tracked'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/assignment-target-is-deoptimized/_config.js
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'makes sure the assignment target is deoptimized' | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/assignment-target-is-deoptimized/main.js
This file contains 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,3 @@ | ||
let updated = false; | ||
updated = true; | ||
if (!updated) throw new Error('Update was not tracked'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/nested-assignment/_config.js
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'tracks assigments nested in expressions that are included for other reasons' | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/nested-assignment/main.js
This file contains 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,3 @@ | ||
let updated = false; | ||
assert.ok(!updated) || (updated = true); | ||
if (!updated) throw new Error('Update was not tracked'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/assignment-deoptimization/try-catch-inclusion/_config.js
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'tracks assigments included via try-catch-deoptimization' | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/assignment-deoptimization/try-catch-inclusion/main.js
This file contains 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,6 @@ | ||
let updated = false; | ||
try { | ||
updated = true; | ||
} catch (err) {} | ||
|
||
if (!updated) throw new Error('Update was not tracked'); |