Skip to content

Commit

Permalink
Assume properties may be read on a yield in DeadPropertyAssignmentsEl…
Browse files Browse the repository at this point in the history
…imination

DeadPropertyAssignments is a function-local optimization, so it doesn't try to guess whether a property is read outside a function or not.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191676794
  • Loading branch information
lauraharker committed Apr 6, 2018
1 parent 32f4e76 commit 65b6843
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ private boolean visitNode(Node n, Node parent) {
}
return true;
case CALL:
case YIELD:
if (ASSUME_CONSTRUCTORS_HAVENT_ESCAPED && isConstructor && !NodeUtil.referencesThis(n)
&& NodeUtil.getEnclosingType(n, Token.TRY) == null) {
// this.x properties are okay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,54 @@ public void testCall() {
" doSomething(this.c);",
" this.c = 30;",
"}"));

// TODO(b/77600088): a.b.c = 20 is dead because of a.b.c = 25.
testSame(
lines(
"var foo = function() {",
" a.b.c = 20;",
" doSomething(a.b.c = 25);", // this should actually deaden "a.b.c = 20". oh well
" a.b.c = 30;",
"}"));
}

public void testYield() {
// Assume that properties may be read during a yield
testSame(
lines(
"var foo = function*() {",
" a.b.c = 20;",
" yield;",
" a.b.c = 30;",
"}"));

testSame(
lines(
"/** @constructor */",
"var foo = function*() {",
" this.c = 20;",
" yield;",
" this.c = 30;",
"}"));

testSame(
lines(
"var obj = {",
" *gen() {",
" this.c = 20;",
" yield;",
" this.c = 30;",
" }",
"}"));

// TODO(b/77600088): a.b.c = 20 is dead because of a.b.c = 25, and should be eliminated.
testSame(
lines(
"var foo = function*() {",
" a.b.c = 20;",
" yield a.b.c = 25;",
" a.b.c = 30;",
"}"));
}

public void testUnknownLookup() {
Expand Down

0 comments on commit 65b6843

Please sign in to comment.