-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update on "[compiler] Add lowerContextAccess pass"
*This is only for internal profiling, not intended to ship.* This pass is intended to be used with #30407. This pass synthesizes selector functions by collecting immediately destructured context acesses. We bailout for other types of context access. This pass lowers context access to use a selector function by passing the synthesized selector function as the second argument. [ghstack-poisoned]
- Loading branch information
Showing
39 changed files
with
658 additions
and
330 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
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
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
27 changes: 0 additions & 27 deletions
27
...in-react-compiler/src/__tests__/fixtures/compiler/error.idx-outlining.expect.md
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.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,36 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
let b = 1; | ||
|
||
export default function MyApp() { | ||
const fn = () => { | ||
b = 2; | ||
}; | ||
return foo(fn); | ||
} | ||
|
||
function foo(fn) {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: MyApp, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
3 | export default function MyApp() { | ||
4 | const fn = () => { | ||
> 5 | b = 2; | ||
| ^ InvalidReact: Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) (5:5) | ||
6 | }; | ||
7 | return foo(fn); | ||
8 | } | ||
``` | ||
15 changes: 15 additions & 0 deletions
15
...bel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.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,15 @@ | ||
let b = 1; | ||
|
||
export default function MyApp() { | ||
const fn = () => { | ||
b = 2; | ||
}; | ||
return foo(fn); | ||
} | ||
|
||
function foo(fn) {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: MyApp, | ||
params: [], | ||
}; |
64 changes: 64 additions & 0 deletions
64
...lugin-react-compiler/src/__tests__/fixtures/compiler/idx-no-outlining.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,64 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @customMacros(idx) | ||
import idx from 'idx'; | ||
|
||
function Component(props) { | ||
// the lambda should not be outlined | ||
const groupName = idx(props, _ => _.group.label); | ||
return <div>{groupName}</div>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @customMacros(idx) | ||
|
||
function Component(props) { | ||
var _ref2; | ||
const $ = _c(4); | ||
let t0; | ||
if ($[0] !== props) { | ||
var _ref; | ||
|
||
t0 = | ||
(_ref = props) != null | ||
? (_ref = _ref.group) != null | ||
? _ref.label | ||
: _ref | ||
: _ref; | ||
$[0] = props; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const groupName = t0; | ||
let t1; | ||
if ($[2] !== groupName) { | ||
t1 = <div>{groupName}</div>; | ||
$[2] = groupName; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div></div> |
1 change: 1 addition & 0 deletions
1
.../fixtures/compiler/error.idx-outlining.js → ...s__/fixtures/compiler/idx-no-outlining.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @customMacros(idx) | ||
import idx from 'idx'; | ||
|
||
function Component(props) { | ||
|
46 changes: 46 additions & 0 deletions
46
...act-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.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,46 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
let b = 1; | ||
|
||
export default function MyApp() { | ||
const fn = () => { | ||
b = 2; | ||
}; | ||
return useFoo(fn); | ||
} | ||
|
||
function useFoo(fn) {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: MyApp, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
let b = 1; | ||
|
||
export default function MyApp() { | ||
const fn = _temp; | ||
return useFoo(fn); | ||
} | ||
function _temp() { | ||
b = 2; | ||
} | ||
|
||
function useFoo(fn) {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: MyApp, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) |
Oops, something went wrong.