-
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] bugfix for hoistable deps for nested functions
`PropertyPathRegistry` is responsible for uniqueing identifier and property paths. This is necessary for the hoistability CFG merging logic which takes unions and intersections of these nodes to determine a basic block's hoistable reads, as a function of its neighbors. We also depend on this to merge optional chained and non-optional chained property paths This fixes a small bug in #31066 in which we create a new registry for nested functions. Now, we use the same registry for a component / hook and all its inner functions '
- Loading branch information
Showing
4 changed files
with
138 additions
and
39 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
61 changes: 61 additions & 0 deletions
61
...sts__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.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 | ||
// @enablePropagateDepsInHIR | ||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({data}) { | ||
return ( | ||
<Stringify foo={() => data.a.d} bar={data.a?.b.c} shouldInvokeFns={true} /> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{data: {a: null}}], | ||
sequentialRenders: [{data: {a: {b: {c: 4}}}}], | ||
}; | ||
|
||
``` | ||
## Code | ||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
import { Stringify } from "shared-runtime"; | ||
|
||
function Foo(t0) { | ||
const $ = _c(5); | ||
const { data } = t0; | ||
let t1; | ||
if ($[0] !== data.a.d) { | ||
t1 = () => data.a.d; | ||
$[0] = data.a.d; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
const t2 = data.a?.b.c; | ||
let t3; | ||
if ($[2] !== t1 || $[3] !== t2) { | ||
t3 = <Stringify foo={t1} bar={t2} shouldInvokeFns={true} />; | ||
$[2] = t1; | ||
$[3] = t2; | ||
$[4] = t3; | ||
} else { | ||
t3 = $[4]; | ||
} | ||
return t3; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ data: { a: null } }], | ||
sequentialRenders: [{ data: { a: { b: { c: 4 } } } }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>{"foo":{"kind":"Function"},"bar":4,"shouldInvokeFns":true}</div> |
14 changes: 14 additions & 0 deletions
14
...ompiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.tsx
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,14 @@ | ||
// @enablePropagateDepsInHIR | ||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({data}) { | ||
return ( | ||
<Stringify foo={() => data.a.d} bar={data.a?.b.c} shouldInvokeFns={true} /> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{data: {a: null}}], | ||
sequentialRenders: [{data: {a: {b: {c: 4}}}}], | ||
}; |