-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Fix merging of queues states in InferReferenceEffects
Fixes a bug found by mofeiZ in #29878. When we merge queues states, if the new state does not introduce changes relative to the queued state we should use the queued state, not the new state. ghstack-source-id: cb931b77f82a118fc6e434f2cd7f6368f9add3d4 Pull Request resolved: #29879
- Loading branch information
1 parent
195d5bb
commit af17497
Showing
3 changed files
with
83 additions
and
2 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
61 changes: 61 additions & 0 deletions
61
...-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.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,61 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { arrayPush } from "shared-runtime"; | ||
|
||
function Foo(cond) { | ||
let x = null; | ||
if (cond) { | ||
x = []; | ||
} else { | ||
} | ||
// Here, x = phi(x$null, x$[]) does not receive the correct ValueKind | ||
arrayPush(x, 2); | ||
|
||
return x; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ cond: true }], | ||
sequentialRenders: [{ cond: true }, { cond: true }], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { arrayPush } from "shared-runtime"; | ||
|
||
function Foo(cond) { | ||
const $ = _c(2); | ||
let x; | ||
if ($[0] !== cond) { | ||
x = null; | ||
if (cond) { | ||
x = []; | ||
} | ||
|
||
arrayPush(x, 2); | ||
$[0] = cond; | ||
$[1] = x; | ||
} else { | ||
x = $[1]; | ||
} | ||
return x; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ cond: true }], | ||
sequentialRenders: [{ cond: true }, { cond: true }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [2] | ||
[2] |
19 changes: 19 additions & 0 deletions
19
...ages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.ts
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,19 @@ | ||
import { arrayPush } from "shared-runtime"; | ||
|
||
function Foo(cond) { | ||
let x = null; | ||
if (cond) { | ||
x = []; | ||
} else { | ||
} | ||
// Here, x = phi(x$null, x$[]) does not receive the correct ValueKind | ||
arrayPush(x, 2); | ||
|
||
return x; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ cond: true }], | ||
sequentialRenders: [{ cond: true }, { cond: true }], | ||
}; |