-
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][hir-rewrite] Stop hoisting PropertyLoads out of function d…
…ecls ghstack-source-id: da8ae28a969cd027c076e36a9a815665a3af5754 Pull Request resolved: #31066
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
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
75 changes: 75 additions & 0 deletions
75
...te-scope-deps-hir-fork/function-expression-dependencies-not-hoistable.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,75 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enablePropagateDepsInHIR | ||
|
||
import {makeArray, identity, useIdentity} from 'shared-runtime'; | ||
|
||
function useFoo(a) { | ||
const fn = () => a.b.c; | ||
useIdentity(); | ||
const x = makeArray(); | ||
x.push(identity(a?.b.c)); | ||
return [fn, x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {b: {c: 4}}], | ||
}; | ||
|
||
``` | ||
## Code | ||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
|
||
import { makeArray, identity, useIdentity } from "shared-runtime"; | ||
|
||
function useFoo(a) { | ||
const $ = _c(7); | ||
let t0; | ||
if ($[0] !== a) { | ||
t0 = () => a.b.c; | ||
$[0] = a; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const fn = t0; | ||
useIdentity(); | ||
let x; | ||
if ($[2] !== a?.b.c) { | ||
x = makeArray(); | ||
x.push(identity(a?.b.c)); | ||
$[2] = a?.b.c; | ||
$[3] = x; | ||
} else { | ||
x = $[3]; | ||
} | ||
let t1; | ||
if ($[4] !== fn || $[5] !== x) { | ||
t1 = [fn, x]; | ||
$[4] = fn; | ||
$[5] = x; | ||
$[6] = t1; | ||
} else { | ||
t1 = $[6]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, { b: { c: 4 } }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) ["[[ function params=0 ]]",[null]] | ||
["[[ function params=0 ]]",[4]] |
17 changes: 17 additions & 0 deletions
17
.../compiler/propagate-scope-deps-hir-fork/function-expression-dependencies-not-hoistable.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,17 @@ | ||
// @enablePropagateDepsInHIR | ||
|
||
import {makeArray, identity, useIdentity} from 'shared-runtime'; | ||
|
||
function useFoo(a) { | ||
const fn = () => a.b.c; | ||
useIdentity(); | ||
const x = makeArray(); | ||
x.push(identity(a?.b.c)); | ||
return [fn, x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {b: {c: 4}}], | ||
}; |