dillon1000/react

Commit

[patch][dce] Patch dce to have separate mark and sweep phases

--- 

Previously, our logic was something like: 

```js 

fixed-point-loop { 

foreach instruction { 

mark referenced identifiers 

// assume that usages are always visited before declarations 

if (instruction is decl) { 

prune(instruction); 

} 

} 

foreach instruction { 

if not referenced { 

delete(instruction); 

} 

} 

``` 

This contained a bug, as not all usages of a variable are guaranteed to be 
visited before its declaration. 

```js 

// input 

let x = 0; 

while(x < 10) { 

x += 2; 

} 

return x; 

// hir 

entry: 

x$0 = 0 

goto loop-test 

loop-test: 

x$1 = phi(x$0, x$2) 

if ... goto loop-body else goto fallthrough 

loop-body: 

x$2 = x$1 ... 

goto loop-test 

fallthrough: 

return x$1 

``` 

In this example,`x$2` is defined by `loop-body` and used by `loop-test`. 
Similarly, `x$1` is defined by `loop-test` and used by `loop-body`. 

--- 

TODO: trying to come up with more test fixtures
Browse files
Changed paths3 files
First-parent comparison
M compiler/packages/babel-plugin-react-forget/src/Optimization/DeadCodeElimination.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-dce-circular-reference.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-dce-circular-reference.js Added
Patch

Files changed

Rendering syntax-highlighted changes…