forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Fix for consecutive DCE'd branches with phis
This is an optimized version of @asmjmp0's fix in facebook#31940. When we merge consecutive blocks we need to take care to rewrite later phis whose operands will now be different blocks due to merging. Rather than iterate all the blocks on each merge as in facebook#31940, we can do a single iteration over all the phis at the end to fix them up.
- Loading branch information
1 parent
0de1233
commit ce62ebf
Showing
3 changed files
with
83 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
.../__tests__/fixtures/compiler/repro-missing-phi-after-dce-merge-scopes.expect.md
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,52 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component() { | ||
let v3, v4, acc; | ||
v3 = false; | ||
v4 = v3; | ||
acc = v3; | ||
if (acc) { | ||
acc = true; | ||
v3 = acc; | ||
} | ||
if (acc) { | ||
v3 = v4; | ||
} | ||
v4 = v3; | ||
return [acc, v3, v4]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = [false, false, false]; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [false,false,false] |
20 changes: 20 additions & 0 deletions
20
...eact-compiler/src/__tests__/fixtures/compiler/repro-missing-phi-after-dce-merge-scopes.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,20 @@ | ||
function Component() { | ||
let v3, v4, acc; | ||
v3 = false; | ||
v4 = v3; | ||
acc = v3; | ||
if (acc) { | ||
acc = true; | ||
v3 = acc; | ||
} | ||
if (acc) { | ||
v3 = v4; | ||
} | ||
v4 = v3; | ||
return [acc, v3, v4]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; |