-
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.
Update on "compiler: Represent pruned scopes instead of inlining"
There are a few places where we want to check whether a value actually got memoized, and we currently have to infer this based on values that "should" have a scope and whether a corresponding scope actually exists. This PR adds a new ReactiveStatement variant to model a reactive scope block that was pruned for some reason, and updates all the passes that prune scopes to instead produce this new variant. [ghstack-poisoned]
- Loading branch information
Showing
64 changed files
with
2,566 additions
and
1,002 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
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
28 changes: 28 additions & 0 deletions
28
...ompiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.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,28 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useReducer } from "react"; | ||
|
||
function Foo() { | ||
let [state, setState] = useReducer({ foo: 1 }); | ||
state.foo = 1; | ||
return state; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
3 | function Foo() { | ||
4 | let [state, setState] = useReducer({ foo: 1 }); | ||
> 5 | state.foo = 1; | ||
| ^^^^^ InvalidReact: Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead (5:5) | ||
6 | return state; | ||
7 | } | ||
8 | | ||
``` | ||
7 changes: 7 additions & 0 deletions
7
...el-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.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,7 @@ | ||
import { useReducer } from "react"; | ||
|
||
function Foo() { | ||
let [state, setState] = useReducer({ foo: 1 }); | ||
state.foo = 1; | ||
return state; | ||
} |
57 changes: 57 additions & 0 deletions
57
...ts__/fixtures/compiler/useReducer-returned-dispatcher-is-non-reactive.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,57 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useReducer } from "react"; | ||
|
||
function f() { | ||
const [state, dispatch] = useReducer(); | ||
|
||
const onClick = () => { | ||
dispatch(); | ||
}; | ||
|
||
return <div onClick={onClick} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: f, | ||
params: [], | ||
isComponent: true, | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useReducer } from "react"; | ||
|
||
function f() { | ||
const $ = _c(1); | ||
const [state, dispatch] = useReducer(); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
const onClick = () => { | ||
dispatch(); | ||
}; | ||
|
||
t0 = <div onClick={onClick} />; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: f, | ||
params: [], | ||
isComponent: true, | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div></div> |
17 changes: 17 additions & 0 deletions
17
...ompiler/src/__tests__/fixtures/compiler/useReducer-returned-dispatcher-is-non-reactive.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,17 @@ | ||
import { useReducer } from "react"; | ||
|
||
function f() { | ||
const [state, dispatch] = useReducer(); | ||
|
||
const onClick = () => { | ||
dispatch(); | ||
}; | ||
|
||
return <div onClick={onClick} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: f, | ||
params: [], | ||
isComponent: true, | ||
}; |
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
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
Oops, something went wrong.