-
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] More complete validation against locals being r…
…eassigned after render" Summary: This diff extends the existing work on validating against locals being reassigned after render, by propagating the reassignment "effect" into the lvalues of instructions when the rvalue operands include values known to cause reassignments. In particular, this "closes the loop" for function definitions and function calls: a function that returns a function that reassigns will be considered to also perform reassignments, but previous to this we didn't consider the result of a `Call` of a function that reassigns to itself be a value that reassigns. This causes a number of new bailouts in test cases, all of which appear to me to be legit. [ghstack-poisoned]
- Loading branch information
Showing
4 changed files
with
116 additions
and
48 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
47 changes: 0 additions & 47 deletions
47
...tures/compiler/error.dont-memoize-array-with-capturing-map-after-hook.expect.md
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
...tures/compiler/repro-dont-memoize-array-with-capturing-map-after-hook.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,91 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {useEffect, useState} from 'react'; | ||
import {mutate} from 'shared-runtime'; | ||
|
||
function Component(props) { | ||
const x = [{...props.value}]; | ||
useEffect(() => {}, []); | ||
const onClick = () => { | ||
console.log(x.length); | ||
}; | ||
let y; | ||
return ( | ||
<div onClick={onClick}> | ||
{x.map(item => { | ||
y = item; | ||
return <span key={item.id}>{item.text}</span>; | ||
})} | ||
{mutate(y)} | ||
</div> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{value: {id: 0, text: 'Hello!'}}], | ||
isComponent: true, | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useEffect, useState } from "react"; | ||
import { mutate } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const $ = _c(5); | ||
const x = [{ ...props.value }]; | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = []; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
useEffect(_temp, t0); | ||
const onClick = () => { | ||
console.log(x.length); | ||
}; | ||
|
||
let y; | ||
|
||
const t1 = x.map((item) => { | ||
y = item; | ||
return <span key={item.id}>{item.text}</span>; | ||
}); | ||
const t2 = mutate(y); | ||
let t3; | ||
if ($[1] !== onClick || $[2] !== t1 || $[3] !== t2) { | ||
t3 = ( | ||
<div onClick={onClick}> | ||
{t1} | ||
{t2} | ||
</div> | ||
); | ||
$[1] = onClick; | ||
$[2] = t1; | ||
$[3] = t2; | ||
$[4] = t3; | ||
} else { | ||
t3 = $[4]; | ||
} | ||
return t3; | ||
} | ||
function _temp() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ value: { id: 0, text: "Hello!" } }], | ||
isComponent: true, | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div><span>Hello!</span></div> |
File renamed without changes.