-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler] Infer phi types, extend mutable ranges to account for Store effects #30796
Changes from all commits
c29d43a
4cfcb2e
8ac0bba
4f80cbb
f450193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {makeArray} from 'shared-runtime'; | ||
|
||
function Component(props) { | ||
const x = {}; | ||
let y; | ||
if (props.cond) { | ||
if (props.cond2) { | ||
y = [props.value]; | ||
} else { | ||
y = [props.value2]; | ||
} | ||
} else { | ||
y = []; | ||
} | ||
// This should be inferred as `<store> y` s.t. `x` can still | ||
// be independently memoized. *But* this also must properly | ||
// extend the mutable range of the array literals in the | ||
// if/else branches | ||
y.push(x); | ||
|
||
return [x, y]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{cond: true, cond2: true, value: 42}], | ||
sequentialRenders: [ | ||
{cond: true, cond2: true, value: 3.14}, | ||
{cond: true, cond2: true, value: 42}, | ||
{cond: true, cond2: true, value: 3.14}, | ||
{cond: true, cond2: false, value2: 3.14}, | ||
{cond: true, cond2: false, value2: 42}, | ||
{cond: true, cond2: false, value2: 3.14}, | ||
{cond: false}, | ||
{cond: false}, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { makeArray } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const $ = _c(3); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = {}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const x = t0; | ||
Comment on lines
+53
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we independently memoize |
||
let t1; | ||
if ($[1] !== props) { | ||
let y; | ||
if (props.cond) { | ||
if (props.cond2) { | ||
y = [props.value]; | ||
} else { | ||
y = [props.value2]; | ||
} | ||
} else { | ||
y = []; | ||
} | ||
|
||
y.push(x); | ||
Comment on lines
+63
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while recognizing that all of these arrays being assigned to |
||
|
||
t1 = [x, y]; | ||
$[1] = props; | ||
$[2] = t1; | ||
} else { | ||
t1 = $[2]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ cond: true, cond2: true, value: 42 }], | ||
sequentialRenders: [ | ||
{ cond: true, cond2: true, value: 3.14 }, | ||
{ cond: true, cond2: true, value: 42 }, | ||
{ cond: true, cond2: true, value: 3.14 }, | ||
{ cond: true, cond2: false, value2: 3.14 }, | ||
{ cond: true, cond2: false, value2: 42 }, | ||
{ cond: true, cond2: false, value2: 3.14 }, | ||
{ cond: false }, | ||
{ cond: false }, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) [{},[3.14,"[[ cyclic ref *1 ]]"]] | ||
[{},[42,"[[ cyclic ref *1 ]]"]] | ||
[{},[3.14,"[[ cyclic ref *1 ]]"]] | ||
[{},[3.14,"[[ cyclic ref *1 ]]"]] | ||
[{},[42,"[[ cyclic ref *1 ]]"]] | ||
[{},[3.14,"[[ cyclic ref *1 ]]"]] | ||
[{},["[[ cyclic ref *1 ]]"]] | ||
[{},["[[ cyclic ref *1 ]]"]] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {makeArray} from 'shared-runtime'; | ||
|
||
function Component(props) { | ||
const x = {}; | ||
let y; | ||
if (props.cond) { | ||
if (props.cond2) { | ||
y = [props.value]; | ||
} else { | ||
y = [props.value2]; | ||
} | ||
} else { | ||
y = []; | ||
} | ||
// This should be inferred as `<store> y` s.t. `x` can still | ||
// be independently memoized. *But* this also must properly | ||
// extend the mutable range of the array literals in the | ||
// if/else branches | ||
y.push(x); | ||
|
||
return [x, y]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{cond: true, cond2: true, value: 42}], | ||
sequentialRenders: [ | ||
{cond: true, cond2: true, value: 3.14}, | ||
{cond: true, cond2: true, value: 42}, | ||
{cond: true, cond2: true, value: 3.14}, | ||
{cond: true, cond2: false, value2: 3.14}, | ||
{cond: true, cond2: false, value2: 42}, | ||
{cond: true, cond2: false, value2: 3.14}, | ||
{cond: false}, | ||
{cond: false}, | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,17 @@ export const FIXTURE_ENTRYPOINT = { | |
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component(props) { | ||
const $ = _c(2); | ||
const $ = _c(3); | ||
let t0; | ||
if ($[0] !== props) { | ||
const x = {}; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = {}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const x = t0; | ||
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're now able to memoize x independently |
||
let t1; | ||
if ($[1] !== props) { | ||
let y; | ||
if (props.cond) { | ||
y = [props.value]; | ||
|
@@ -49,13 +56,13 @@ function Component(props) { | |
|
||
y.push(x); | ||
|
||
t0 = [x, y]; | ||
$[0] = props; | ||
$[1] = t0; | ||
t1 = [x, y]; | ||
$[1] = props; | ||
$[2] = t1; | ||
} else { | ||
t0 = $[1]; | ||
t1 = $[2]; | ||
} | ||
return t0; | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous logic was incorrect, checking only that the operand type kinds matched. we need to check that the types actually match