-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][hir] Only hoist always-accessed PropertyLoads from functio…
…n decls ghstack-source-id: 32e551e45a9d48085dd2a7ab3cc5efc112808900 Pull Request resolved: #31066
- Loading branch information
Showing
23 changed files
with
1,020 additions
and
12 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
80 changes: 80 additions & 0 deletions
80
...-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.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,80 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enablePropagateDepsInHIR | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({a, shouldReadA}) { | ||
return ( | ||
<Stringify | ||
fn={() => { | ||
if (shouldReadA) return a.b.c; | ||
return null; | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{a: null, shouldReadA: true}], | ||
sequentialRenders: [ | ||
{a: null, shouldReadA: true}, | ||
{a: null, shouldReadA: false}, | ||
{a: {b: {c: 4}}, shouldReadA: true}, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
|
||
import { Stringify } from "shared-runtime"; | ||
|
||
function Foo(t0) { | ||
const $ = _c(3); | ||
const { a, shouldReadA } = t0; | ||
let t1; | ||
if ($[0] !== shouldReadA || $[1] !== a) { | ||
t1 = ( | ||
<Stringify | ||
fn={() => { | ||
if (shouldReadA) { | ||
return a.b.c; | ||
} | ||
return null; | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
$[0] = shouldReadA; | ||
$[1] = a; | ||
$[2] = t1; | ||
} else { | ||
t1 = $[2]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ a: null, shouldReadA: true }], | ||
sequentialRenders: [ | ||
{ a: null, shouldReadA: true }, | ||
{ a: null, shouldReadA: false }, | ||
{ a: { b: { c: 4 } }, shouldReadA: true }, | ||
], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]] | ||
<div>{"fn":{"kind":"Function","result":null},"shouldInvokeFns":true}</div> | ||
<div>{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}</div> |
25 changes: 25 additions & 0 deletions
25
...agate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.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,25 @@ | ||
// @enablePropagateDepsInHIR | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({a, shouldReadA}) { | ||
return ( | ||
<Stringify | ||
fn={() => { | ||
if (shouldReadA) return a.b.c; | ||
return null; | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{a: null, shouldReadA: true}], | ||
sequentialRenders: [ | ||
{a: null, shouldReadA: true}, | ||
{a: null, shouldReadA: false}, | ||
{a: {b: {c: 4}}, shouldReadA: true}, | ||
], | ||
}; |
51 changes: 51 additions & 0 deletions
51
...ps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.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,51 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enablePropagateDepsInHIR | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function useFoo(a) { | ||
return <Stringify fn={() => a.b.c} shouldInvokeFns={true} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{a: null}], | ||
sequentialRenders: [{a: null}, {a: {b: {c: 4}}}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
|
||
import { Stringify } from "shared-runtime"; | ||
|
||
function useFoo(a) { | ||
const $ = _c(2); | ||
let t0; | ||
if ($[0] !== a) { | ||
t0 = <Stringify fn={() => a.b.c} shouldInvokeFns={true} />; | ||
$[0] = a; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{ a: null }], | ||
sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]] | ||
[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]] |
13 changes: 13 additions & 0 deletions
13
...opagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.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,13 @@ | ||
// @enablePropagateDepsInHIR | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function useFoo(a) { | ||
return <Stringify fn={() => a.b.c} shouldInvokeFns={true} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{a: null}], | ||
sequentialRenders: [{a: null}, {a: {b: {c: 4}}}], | ||
}; |
Oops, something went wrong.