Enable MergeConsecutiveScopes by default

## Test Plan (wip) 

Sync internally, manually verify code changes and test products.
This commit is contained in:
Joe Savona
2023-10-09 16:15:30 -07:00
parent a1461016df
commit b61dba64ad
23 changed files with 179 additions and 328 deletions
@@ -217,6 +217,7 @@ export const DEFAULT_ENVIRONMENT_CONFIG: Readonly<EnvironmentConfig> = {
memoizeJsxElements: true,
validateHooksUsage: true,
enableMergeConsecutiveScopes: true,
assertValidMutableRanges: false,
bailoutOnHoleyArrays: false,
@@ -224,7 +225,6 @@ export const DEFAULT_ENVIRONMENT_CONFIG: Readonly<EnvironmentConfig> = {
enableAssumeHooksFollowRulesOfReact: false,
enableEmitFreeze: null,
enableForest: false,
enableMergeConsecutiveScopes: false,
validateFrozenLambdas: false,
validateNoSetStateInRender: false,
@@ -21,22 +21,15 @@ function Component(props) {
import { unstable_useMemoCache as useMemoCache } from "react"; // x's mutable range should extend to `mutate(y)`
function Component(props) {
const $ = useMemoCache(2);
const $ = useMemoCache(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = {};
t0 = [42, {}];
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = [42, t0];
$[1] = t1;
} else {
t1 = $[1];
}
const x = t1;
const x = t0;
const idx = foo(props.b);
const y = x.at(idx);
mutate(y);
@@ -18,17 +18,14 @@ import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(8);
let t0;
let t1;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = {};
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = [];
$[0] = t0;
$[1] = t1;
} else {
t0 = $[0];
t1 = $[1];
}
const c_2 = $[2] !== props.value;
@@ -22,22 +22,15 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function foo() {
const $ = useMemoCache(2);
const $ = useMemoCache(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = [1];
t0 = [[1]];
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = [t0];
$[1] = t1;
} else {
t1 = $[1];
}
const a = t1;
const a = t0;
const first = a.at(0);
first.set(0, 2);
return a;
@@ -19,36 +19,31 @@ function Component(props) {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(6);
const $ = useMemoCache(4);
const c_0 = $[0] !== props;
let t2;
let t1;
if (c_0) {
const x = makeFunction(props);
const c_2 = $[2] !== props.text;
let t0;
if (c_2) {
t0 = <span>{props.text}</span>;
t0 = (
<div>
<span>{props.text}</span>
</div>
);
$[2] = props.text;
$[3] = t0;
} else {
t0 = $[3];
}
const c_4 = $[4] !== t0;
let t1;
if (c_4) {
t1 = <div>{t0}</div>;
$[4] = t0;
$[5] = t1;
} else {
t1 = $[5];
}
t2 = x(t1);
t1 = x(t0);
$[0] = props;
$[1] = t2;
$[1] = t1;
} else {
t2 = $[1];
t1 = $[1];
}
const y = t2;
const y = t1;
return y;
}
@@ -23,26 +23,17 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function component(a) {
const $ = useMemoCache(4);
const $ = useMemoCache(2);
const c_0 = $[0] !== a;
let t0;
if (c_0) {
t0 = { a };
t0 = { a: { a } };
$[0] = a;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
let t1;
if (c_2) {
t1 = { a: t0 };
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
}
const z = t1;
const z = t0;
return z;
}
@@ -25,40 +25,31 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function component(a) {
const $ = useMemoCache(6);
const $ = useMemoCache(4);
const c_0 = $[0] !== a;
let t0;
if (c_0) {
t0 = { a };
t0 = { a: { a } };
$[0] = a;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
const z = t0;
const c_2 = $[2] !== z.a.a;
let t1;
if (c_2) {
t1 = { a: t0 };
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
}
const z = t1;
const c_4 = $[4] !== z.a.a;
let t2;
if (c_4) {
t2 = function () {
t1 = function () {
(function () {
console.log(z.a.a);
})();
};
$[4] = z.a.a;
$[5] = t2;
$[2] = z.a.a;
$[3] = t1;
} else {
t2 = $[5];
t1 = $[3];
}
const x = t2;
const x = t1;
return x;
}
@@ -23,38 +23,29 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function component(a) {
const $ = useMemoCache(6);
const $ = useMemoCache(4);
const c_0 = $[0] !== a;
let t0;
if (c_0) {
t0 = { a };
t0 = { a: { a } };
$[0] = a;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
const z = t0;
const c_2 = $[2] !== z.a.a;
let t1;
if (c_2) {
t1 = { a: t0 };
$[2] = t0;
t1 = function () {
console.log(z.a.a);
};
$[2] = z.a.a;
$[3] = t1;
} else {
t1 = $[3];
}
const z = t1;
const c_4 = $[4] !== z.a.a;
let t2;
if (c_4) {
t2 = function () {
console.log(z.a.a);
};
$[4] = z.a.a;
$[5] = t2;
} else {
t2 = $[5];
}
const x = t2;
const x = t1;
return x;
}
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react"; // Should print A, B, arg, original
function Component() {
const $ = useMemoCache(3);
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (o) => {
@@ -41,23 +41,16 @@ function Component() {
t0 = $[0];
}
const changeF = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = () => console.log("original");
$[1] = t1;
} else {
t1 = $[1];
}
let x;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
x = { f: t1 };
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
x = { f: () => console.log("original") };
(console.log("A"), x)[(console.log("B"), "f")](
(changeF(x), console.log("arg"), 1)
);
$[2] = x;
$[1] = x;
} else {
x = $[2];
x = $[1];
}
return x;
}
@@ -25,22 +25,19 @@ import { unstable_useMemoCache as useMemoCache } from "react";
import fbt from "fbt";
function Component(props) {
const $ = useMemoCache(2);
const $ = useMemoCache(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" });
t0 = (
<Foo
value={fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" })}
/>
);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Foo value={t0} />;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
```
@@ -29,36 +29,40 @@ import { unstable_useMemoCache as useMemoCache } from "react";
import fbt from "fbt";
function Component(t39) {
const $ = useMemoCache(6);
const $ = useMemoCache(4);
const { name, data, icon } = t39;
const c_0 = $[0] !== name;
const c_1 = $[1] !== icon;
const c_2 = $[2] !== data;
let t0;
if (c_0 || c_1 || c_2) {
t0 = fbt._(
"{item author}{icon}{=m2}",
[
fbt._param(
"item author",
t0 = (
<Text type="body4">
{fbt._(
"{item author}{icon}{=m2}",
[
fbt._param(
"item author",
<Text type="h4">{name}</Text>
),
fbt._param(
"icon",
<Text type="h4">{name}</Text>
),
fbt._param(
"icon",
icon
),
fbt._implicitParam(
"=m2",
<Text type="h4">
{fbt._("{item details}", [fbt._param("item details", data)], {
hk: "4jLfVq",
})}
</Text>
),
],
{ hk: "2HLm2j" }
icon
),
fbt._implicitParam(
"=m2",
<Text type="h4">
{fbt._("{item details}", [fbt._param("item details", data)], {
hk: "4jLfVq",
})}
</Text>
),
],
{ hk: "2HLm2j" }
)}
</Text>
);
$[0] = name;
$[1] = icon;
@@ -67,16 +71,7 @@ function Component(t39) {
} else {
t0 = $[3];
}
const c_4 = $[4] !== t0;
let t1;
if (c_4) {
t1 = <Text type="body4">{t0}</Text>;
$[4] = t0;
$[5] = t1;
} else {
t1 = $[5];
}
return t1;
return t0;
}
```
@@ -27,28 +27,25 @@ import fbt from "fbt";
import { identity } from "shared-runtime";
function Component(props) {
const $ = useMemoCache(4);
const $ = useMemoCache(2);
const c_0 = $[0] !== props.text;
let t0;
if (c_0) {
t0 = fbt._("{value}%", [fbt._param("value", <>{identity(props.text)}</>)], {
hk: "10F5Cc",
});
t0 = (
<Foo
value={fbt._(
"{value}%",
[fbt._param("value", <>{identity(props.text)}</>)],
{ hk: "10F5Cc" }
)}
/>
);
$[0] = props.text;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
let t1;
if (c_2) {
t1 = <Foo value={t0} />;
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
}
return t1;
return t0;
}
```
@@ -23,24 +23,17 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function component() {
const $ = useMemoCache(2);
let t0;
const $ = useMemoCache(1);
let x;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = function x(a) {
x = function x(a) {
a.foo();
};
$[0] = t0;
} else {
t0 = $[0];
}
let x;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
x = t0;
x = {};
$[1] = x;
$[0] = x;
} else {
x = $[1];
x = $[0];
}
return x;
}
@@ -21,7 +21,7 @@ function Component(props) {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(11);
const $ = useMemoCache(9);
let t1;
let T2;
let t3;
@@ -62,38 +62,22 @@ function Component(props) {
}
let t7;
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
t7 = <span>{t1}</span>;
t7 = (
<T5>
{t6}
<T2>
{t3}
{t0}
{t4}
<span>{t1}</span>
</T2>
</T5>
);
$[8] = t7;
} else {
t7 = $[8];
}
let t8;
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
t8 = (
<T2>
{t3}
{t0}
{t4}
{t7}
</T2>
);
$[9] = t8;
} else {
t8 = $[9];
}
let t9;
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
t9 = (
<T5>
{t6}
{t8}
</T5>
);
$[10] = t9;
} else {
t9 = $[10];
}
return t9;
return t7;
}
```
@@ -26,36 +26,34 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Foo(props) {
const $ = useMemoCache(4);
const $ = useMemoCache(3);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <>Text</>;
t0 = (
<div>
<>Text</>
</div>
);
$[0] = t0;
} else {
t0 = $[0];
}
const c_1 = $[1] !== props.greeting;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <div>{t0}</div>;
$[1] = t1;
} else {
t1 = $[1];
}
const c_2 = $[2] !== props.greeting;
let t2;
if (c_2) {
t2 = (
if (c_1) {
t1 = (
<>
Hello {props.greeting} {t1}
Hello {props.greeting} {t0}
</>
);
$[2] = props.greeting;
$[3] = t2;
$[1] = props.greeting;
$[2] = t1;
} else {
t2 = $[3];
t1 = $[2];
}
return t2;
return t1;
}
export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: ["TodoAdd"],
@@ -17,22 +17,19 @@ function Component(props) {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(2);
const $ = useMemoCache(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Foo.Bar.Baz />;
t0 = (
<Sathya.Codes.Forget>
<Foo.Bar.Baz />
</Sathya.Codes.Forget>
);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Sathya.Codes.Forget>{t0}</Sathya.Codes.Forget>;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
```
@@ -24,36 +24,18 @@ import { unstable_useMemoCache as useMemoCache } from "react";
import { RenderPropAsChild, StaticText1, StaticText2 } from "shared-runtime";
function Component(props) {
const $ = useMemoCache(6);
const $ = useMemoCache(2);
const Foo = props.showText1 ? StaticText1 : StaticText2;
const c_0 = $[0] !== Foo;
let t0;
if (c_0) {
t0 = () => <Foo key="0" />;
t0 = <RenderPropAsChild items={[() => <Foo key="0" />]} />;
$[0] = Foo;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
let t1;
if (c_2) {
t1 = [t0];
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
}
const c_4 = $[4] !== t1;
let t2;
if (c_4) {
t2 = <RenderPropAsChild items={t1} />;
$[4] = t1;
$[5] = t2;
} else {
t2 = $[5];
}
return t2;
return t0;
}
export const FIXTURE_ENTRYPOINT = {
@@ -42,7 +42,7 @@ import { unstable_useMemoCache as useMemoCache } from "react";
import { fbt } from "fbt";
function Component() {
const $ = useMemoCache(4);
const $ = useMemoCache(3);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
@@ -80,19 +80,16 @@ function Component() {
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = <Button text={t1} />;
t2 = (
<View>
<Button text={t1} />
</View>
);
$[2] = t2;
} else {
t2 = $[2];
}
let t3;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = <View>{t2}</View>;
$[3] = t3;
} else {
t3 = $[3];
}
return t3;
return t2;
}
```
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
export default Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = useMemoCache(3);
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
@@ -47,24 +47,17 @@ export default Renderer = isForgetEnabled_Fixtures()
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <ErrorView />;
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = (
<Foo>
{t0}
{t1}
</Foo>
);
$[2] = t2;
} else {
t2 = $[2];
}
return t2;
return t1;
}
: (props) => (
<Foo>
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
export const Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = useMemoCache(3);
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
@@ -47,24 +47,17 @@ export const Renderer = isForgetEnabled_Fixtures()
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <ErrorView />;
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = (
<Foo>
{t0}
{t1}
</Foo>
);
$[2] = t2;
} else {
t2 = $[2];
}
return t2;
return t1;
}
: (props) => (
<Foo>
@@ -39,7 +39,7 @@ const ErrorView = isForgetEnabled_Fixtures()
const Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = useMemoCache(3);
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
@@ -49,24 +49,17 @@ const Renderer = isForgetEnabled_Fixtures()
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <ErrorView />;
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = (
<Foo>
{t0}
{t1}
</Foo>
);
$[2] = t2;
} else {
t2 = $[2];
}
return t2;
return t1;
}
: (props) => (
<Foo>
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
import { unstable_useMemoCache as useMemoCache } from "react"; // Should print A, arg, original
function Component() {
const $ = useMemoCache(3);
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (o) => {
@@ -41,21 +41,14 @@ function Component() {
t0 = $[0];
}
const changeF = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = () => console.log("original");
$[1] = t1;
} else {
t1 = $[1];
}
let x;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
x = { f: t1 };
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
x = { f: () => console.log("original") };
(console.log("A"), x).f((changeF(x), console.log("arg"), 1));
$[2] = x;
$[1] = x;
} else {
x = $[2];
x = $[1];
}
return x;
}
@@ -26,7 +26,7 @@ function Component(props) {
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(7);
const $ = useMemoCache(6);
const dispatch = useDispatch();
useFreeze(dispatch);
const c_0 = $[0] !== dispatch;
@@ -43,31 +43,26 @@ function Component(props) {
const onUpdate = t0;
const c_2 = $[2] !== onUpdate;
let t1;
let t2;
if (c_2) {
t1 = () => {
onUpdate();
};
t2 = [onUpdate];
$[2] = onUpdate;
$[3] = t1;
$[4] = t2;
} else {
t1 = $[3];
}
const c_4 = $[4] !== onUpdate;
let t2;
if (c_4) {
t2 = [onUpdate];
$[4] = onUpdate;
$[5] = t2;
} else {
t2 = $[5];
t2 = $[4];
}
useEffect(t1, t2);
let t3;
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
t3 = <div />;
$[6] = t3;
$[5] = t3;
} else {
t3 = $[6];
t3 = $[5];
}
return t3;
}