mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[be] Stabilize block ids
ghstack-source-id: 83aedf9f086ccb4819655eab803f25f944b75c7b Pull Request resolved: https://github.com/facebook/react-forget/pull/2851
This commit is contained in:
@@ -66,6 +66,7 @@ import {
|
||||
import { alignMethodCallScopes } from "../ReactiveScopes/AlignMethodCallScopes";
|
||||
import { alignReactiveScopesToBlockScopesHIR } from "../ReactiveScopes/AlignReactiveScopesToBlockScopesHIR";
|
||||
import { pruneAlwaysInvalidatingScopes } from "../ReactiveScopes/PruneAlwaysInvalidatingScopes";
|
||||
import { stabilizeBlockIds } from "../ReactiveScopes/StabilizeBlockIds";
|
||||
import { eliminateRedundantPhi, enterSSA, leaveSSA } from "../SSA";
|
||||
import { inferTypes } from "../TypeInference";
|
||||
import {
|
||||
@@ -366,6 +367,13 @@ function* runWithEnvironment(
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
stabilizeBlockIds(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
name: "StabilizeBlockIds",
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
const uniqueIdentifiers = renameVariables(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
BlockId,
|
||||
ReactiveFunction,
|
||||
ReactiveScopeBlock,
|
||||
ReactiveTerminalStatement,
|
||||
makeBlockId,
|
||||
} from "../HIR";
|
||||
import { getOrInsertDefault } from "../Utils/utils";
|
||||
import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
|
||||
|
||||
export function stabilizeBlockIds(fn: ReactiveFunction): void {
|
||||
const referenced: Set<BlockId> = new Set();
|
||||
visitReactiveFunction(fn, new CollectReferencedLabels(), referenced);
|
||||
|
||||
const mappings = new Map<BlockId, BlockId>();
|
||||
for (const blockId of referenced) {
|
||||
mappings.set(blockId, makeBlockId(mappings.size));
|
||||
}
|
||||
|
||||
visitReactiveFunction(fn, new RewriteBlockIds(), mappings);
|
||||
}
|
||||
|
||||
class CollectReferencedLabels extends ReactiveFunctionVisitor<Set<BlockId>> {
|
||||
override visitScope(scope: ReactiveScopeBlock, state: Set<BlockId>): void {
|
||||
const { earlyReturnValue } = scope.scope;
|
||||
if (earlyReturnValue != null) {
|
||||
state.add(earlyReturnValue.label);
|
||||
}
|
||||
this.traverseScope(scope, state);
|
||||
}
|
||||
override visitTerminal(
|
||||
stmt: ReactiveTerminalStatement,
|
||||
state: Set<BlockId>
|
||||
): void {
|
||||
if (stmt.label != null) {
|
||||
if (!stmt.label.implicit) {
|
||||
state.add(stmt.label.id);
|
||||
}
|
||||
}
|
||||
this.traverseTerminal(stmt, state);
|
||||
}
|
||||
}
|
||||
|
||||
class RewriteBlockIds extends ReactiveFunctionVisitor<Map<BlockId, BlockId>> {
|
||||
override visitScope(
|
||||
scope: ReactiveScopeBlock,
|
||||
state: Map<BlockId, BlockId>
|
||||
): void {
|
||||
const { earlyReturnValue } = scope.scope;
|
||||
if (earlyReturnValue != null) {
|
||||
const rewrittenId = getOrInsertDefault(
|
||||
state,
|
||||
earlyReturnValue.label,
|
||||
state.size
|
||||
);
|
||||
earlyReturnValue.label = makeBlockId(rewrittenId);
|
||||
}
|
||||
this.traverseScope(scope, state);
|
||||
}
|
||||
override visitTerminal(
|
||||
stmt: ReactiveTerminalStatement,
|
||||
state: Map<BlockId, BlockId>
|
||||
): void {
|
||||
if (stmt.label != null) {
|
||||
const rewrittenId = getOrInsertDefault(state, stmt.label.id, state.size);
|
||||
stmt.label.id = makeBlockId(rewrittenId);
|
||||
}
|
||||
|
||||
const terminal = stmt.terminal;
|
||||
if (terminal.kind === "break" || terminal.kind === "continue") {
|
||||
const rewrittenId = getOrInsertDefault(
|
||||
state,
|
||||
terminal.target,
|
||||
state.size
|
||||
);
|
||||
terminal.target = makeBlockId(rewrittenId);
|
||||
}
|
||||
this.traverseTerminal(stmt, state);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ export { pruneTemporaryLValues as pruneUnusedLValues } from "./PruneTemporaryLVa
|
||||
export { pruneUnusedLabels } from "./PruneUnusedLabels";
|
||||
export { pruneUnusedScopes } from "./PruneUnusedScopes";
|
||||
export { renameVariables } from "./RenameVariables";
|
||||
export { stabilizeBlockIds } from "./StabilizeBlockIds";
|
||||
export {
|
||||
ReactiveFunctionTransform,
|
||||
eachReactiveValueOperand,
|
||||
|
||||
+2
-2
@@ -28,14 +28,14 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
```javascript
|
||||
function useHook(a, b) {
|
||||
bb1: switch (a) {
|
||||
bb0: switch (a) {
|
||||
case 1: {
|
||||
if (b == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(b);
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
return;
|
||||
|
||||
+2
-2
@@ -44,10 +44,10 @@ function Component(props) {
|
||||
t1 = $[1];
|
||||
}
|
||||
const handlers = t1;
|
||||
bb2: switch (props.test) {
|
||||
bb0: switch (props.test) {
|
||||
case true: {
|
||||
console.log(handlers.value);
|
||||
break bb2;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,10 +25,10 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
```javascript
|
||||
function foo(a, b, c) {
|
||||
bb1: if (a) {
|
||||
bb0: if (a) {
|
||||
while (b) {
|
||||
if (c) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -39,9 +39,9 @@ function Component(props) {
|
||||
if ($[0] !== props) {
|
||||
a = [];
|
||||
a.push(props.a);
|
||||
bb1: {
|
||||
bb0: {
|
||||
if (props.b) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
a.push(props.c);
|
||||
|
||||
+6
-6
@@ -76,12 +76,12 @@ function ComponentA(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
a_DEBUG = [];
|
||||
a_DEBUG.push(props.a);
|
||||
if (props.b) {
|
||||
t0 = null;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
a_DEBUG.push(props.d);
|
||||
@@ -130,13 +130,13 @@ function ComponentC(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
a = [];
|
||||
a.push(props.a);
|
||||
if (props.b) {
|
||||
a.push(props.c);
|
||||
t0 = null;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
a.push(props.d);
|
||||
@@ -163,13 +163,13 @@ function ComponentD(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
a = [];
|
||||
a.push(props.a);
|
||||
if (props.b) {
|
||||
a.push(props.c);
|
||||
t0 = a;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
a.push(props.d);
|
||||
|
||||
+5
-5
@@ -49,23 +49,23 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let x = 0;
|
||||
bb1: if (props.a) {
|
||||
bb0: if (props.a) {
|
||||
x = 1;
|
||||
} else {
|
||||
if (props.b) {
|
||||
} else {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x = 3;
|
||||
}
|
||||
bb10: bb12: switch (props.c) {
|
||||
bb1: bb2: switch (props.c) {
|
||||
case "a": {
|
||||
x = 4;
|
||||
break bb12;
|
||||
break bb2;
|
||||
}
|
||||
case "b": {
|
||||
break bb10;
|
||||
break bb1;
|
||||
}
|
||||
case "c": {
|
||||
}
|
||||
|
||||
+4
-4
@@ -35,7 +35,7 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb12: {
|
||||
bb0: {
|
||||
const x = [];
|
||||
if (props.cond) {
|
||||
x.push(props.a);
|
||||
@@ -51,11 +51,11 @@ function Component(props) {
|
||||
const y = t1;
|
||||
x.push(y);
|
||||
t0 = x;
|
||||
break bb12;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t0 = x;
|
||||
break bb12;
|
||||
break bb0;
|
||||
} else {
|
||||
let t1;
|
||||
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
@@ -65,7 +65,7 @@ function Component(props) {
|
||||
t1 = $[4];
|
||||
}
|
||||
t0 = t1;
|
||||
break bb12;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
$[0] = props;
|
||||
|
||||
+2
-2
@@ -73,12 +73,12 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb9: {
|
||||
bb0: {
|
||||
const x = [];
|
||||
if (ENABLE_FEATURE) {
|
||||
x.push(42);
|
||||
t0 = x;
|
||||
break bb9;
|
||||
break bb0;
|
||||
} else {
|
||||
console.log("fallthrough");
|
||||
}
|
||||
|
||||
+3
-3
@@ -49,12 +49,12 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb9: {
|
||||
bb0: {
|
||||
const x = [];
|
||||
if (props.cond) {
|
||||
x.push(props.a);
|
||||
t0 = x;
|
||||
break bb9;
|
||||
break bb0;
|
||||
} else {
|
||||
let t1;
|
||||
if ($[2] !== props.b) {
|
||||
@@ -65,7 +65,7 @@ function Component(props) {
|
||||
t1 = $[3];
|
||||
}
|
||||
t0 = t1;
|
||||
break bb9;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
$[0] = props;
|
||||
|
||||
+2
-2
@@ -27,10 +27,10 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function foo(a, b, c) {
|
||||
let x;
|
||||
bb1: {
|
||||
bb0: {
|
||||
if (a) {
|
||||
x = b;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x = c;
|
||||
|
||||
+2
-2
@@ -31,10 +31,10 @@ function foo(a, b, c, d) {
|
||||
let y;
|
||||
if ($[0] !== a || $[1] !== b || $[2] !== c || $[3] !== d) {
|
||||
y = [];
|
||||
bb1: if (a) {
|
||||
bb0: if (a) {
|
||||
if (b) {
|
||||
y.push(c);
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
y.push(d);
|
||||
|
||||
+2
-2
@@ -35,9 +35,9 @@ function useHook(end) {
|
||||
log = [];
|
||||
for (let i = 0; i < end + 1; i++) {
|
||||
log.push(`${i} @A`);
|
||||
bb6: {
|
||||
bb0: {
|
||||
if (i === end) {
|
||||
break bb6;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
log.push(`${i} @B`);
|
||||
|
||||
+2
-2
@@ -41,9 +41,9 @@ function useHook(cond) {
|
||||
switch (CONST_STRING0) {
|
||||
case CONST_STRING0: {
|
||||
log.push(`@A`);
|
||||
bb3: {
|
||||
bb0: {
|
||||
if (cond) {
|
||||
break bb3;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
log.push(`@B`);
|
||||
|
||||
+3
-3
@@ -33,16 +33,16 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb9: {
|
||||
bb0: {
|
||||
const object = makeObject_Primitives();
|
||||
if (props.cond) {
|
||||
object.value = 1;
|
||||
t0 = object;
|
||||
break bb9;
|
||||
break bb0;
|
||||
} else {
|
||||
object.value = props.value;
|
||||
t0 = object;
|
||||
break bb9;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
$[0] = props;
|
||||
|
||||
+3
-3
@@ -35,12 +35,12 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] !== props) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb12: {
|
||||
bb0: {
|
||||
const x = [];
|
||||
if (props.cond) {
|
||||
x.push(props.a);
|
||||
t0 = x;
|
||||
break bb12;
|
||||
break bb0;
|
||||
} else {
|
||||
let t1;
|
||||
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
@@ -52,7 +52,7 @@ function Component(props) {
|
||||
y = t1;
|
||||
if (props.b) {
|
||||
t0 = undefined;
|
||||
break bb12;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ function Component(t0) {
|
||||
const $ = useMemoCache(2);
|
||||
const { propA, propB } = t0;
|
||||
let t1;
|
||||
bb6: {
|
||||
bb0: {
|
||||
if (propA) {
|
||||
let t2;
|
||||
if ($[0] !== propB.x.y) {
|
||||
@@ -43,7 +43,7 @@ function Component(t0) {
|
||||
t2 = $[1];
|
||||
}
|
||||
t1 = t2;
|
||||
break bb6;
|
||||
break bb0;
|
||||
}
|
||||
t1 = undefined;
|
||||
}
|
||||
|
||||
+2
-2
@@ -55,10 +55,10 @@ function Component(props) {
|
||||
const c = [a];
|
||||
|
||||
let x;
|
||||
bb1: switch (c[0][0]) {
|
||||
bb0: switch (c[0][0]) {
|
||||
case true: {
|
||||
x = 1;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
x = 2;
|
||||
|
||||
+3
-3
@@ -47,14 +47,14 @@ import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(2);
|
||||
let x;
|
||||
bb1: switch (props.cond) {
|
||||
bb0: switch (props.cond) {
|
||||
case true: {
|
||||
x = 1;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case false: {
|
||||
x = 2;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
x = 3;
|
||||
|
||||
+2
-2
@@ -48,10 +48,10 @@ function Component(t0) {
|
||||
const $ = useMemoCache(2);
|
||||
const { value } = t0;
|
||||
let x;
|
||||
bb1: switch (GLOBAL) {
|
||||
bb0: switch (GLOBAL) {
|
||||
case value: {
|
||||
x = 1;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
x = 2;
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ function foo(a, b, c) {
|
||||
t0 = $[3];
|
||||
}
|
||||
const y = t0;
|
||||
bb3: switch (b) {
|
||||
bb0: switch (b) {
|
||||
case 0: {
|
||||
if ($[4] !== b) {
|
||||
x = [];
|
||||
@@ -72,7 +72,7 @@ function foo(a, b, c) {
|
||||
} else {
|
||||
x = $[5];
|
||||
}
|
||||
break bb3;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
if ($[6] !== c) {
|
||||
|
||||
+2
-2
@@ -36,9 +36,9 @@ function useFoo(t0) {
|
||||
let x;
|
||||
if ($[0] !== objIsNull || $[1] !== obj) {
|
||||
x = [];
|
||||
bb1: {
|
||||
bb0: {
|
||||
if (objIsNull) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
} else {
|
||||
x.push(obj.a);
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,11 +35,11 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== objIsNull || $[1] !== obj) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb9: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (objIsNull) {
|
||||
t1 = undefined;
|
||||
break bb9;
|
||||
break bb0;
|
||||
} else {
|
||||
x.push(obj.a);
|
||||
}
|
||||
|
||||
+3
-3
@@ -44,14 +44,14 @@ function useCondDepInSwitch(props, other) {
|
||||
let x;
|
||||
if ($[0] !== other || $[1] !== props.a.b) {
|
||||
x = {};
|
||||
bb1: switch (identity(other)) {
|
||||
bb0: switch (identity(other)) {
|
||||
case 1: {
|
||||
x.a = props.a.b;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
x.b = props.a.b;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
x.c = props.a.b;
|
||||
|
||||
+3
-3
@@ -43,14 +43,14 @@ function useCondDepInSwitchMissingCase(props, other) {
|
||||
let x;
|
||||
if ($[0] !== other || $[1] !== props) {
|
||||
x = {};
|
||||
bb1: switch (identity(other)) {
|
||||
bb0: switch (identity(other)) {
|
||||
case 1: {
|
||||
x.a = props.a.b;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
x.b = 42;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
x.c = props.a.b;
|
||||
|
||||
+2
-2
@@ -40,10 +40,10 @@ function useCondDepInSwitchMissingDefault(props, other) {
|
||||
let x;
|
||||
if ($[0] !== other || $[1] !== props) {
|
||||
x = {};
|
||||
bb1: switch (identity(other)) {
|
||||
bb0: switch (identity(other)) {
|
||||
case 1: {
|
||||
x.a = props.a.b;
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
x.b = props.a.b;
|
||||
|
||||
+2
-2
@@ -38,9 +38,9 @@ function useFoo(t0) {
|
||||
let x;
|
||||
if ($[0] !== objIsNull || $[1] !== obj) {
|
||||
x = [];
|
||||
bb1: {
|
||||
bb0: {
|
||||
if (objIsNull) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x.push(obj.a);
|
||||
|
||||
+2
-2
@@ -44,9 +44,9 @@ function useFoo(t0) {
|
||||
let x;
|
||||
if ($[0] !== cond || $[1] !== input) {
|
||||
x = [];
|
||||
bb1: {
|
||||
bb0: {
|
||||
if (cond) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
let t1;
|
||||
if ($[3] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -46,12 +46,12 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== cond || $[1] !== hasAB || $[2] !== input) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb11: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (cond) {
|
||||
if (!hasAB) {
|
||||
t1 = null;
|
||||
break bb11;
|
||||
break bb0;
|
||||
}
|
||||
let t2;
|
||||
if ($[5] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -47,12 +47,12 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== cond || $[1] !== hasAB || $[2] !== input) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb12: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (cond) {
|
||||
if (!hasAB) {
|
||||
t1 = null;
|
||||
break bb12;
|
||||
break bb0;
|
||||
} else {
|
||||
let t2;
|
||||
if ($[5] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -37,11 +37,11 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== objIsNull || $[1] !== obj) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (objIsNull) {
|
||||
t1 = undefined;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x.push(obj.b);
|
||||
|
||||
+2
-2
@@ -43,11 +43,11 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== cond || $[1] !== input) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (cond) {
|
||||
t1 = null;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
let t2;
|
||||
if ($[4] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ function useFoo(t0) {
|
||||
let x;
|
||||
if ($[0] !== cond || $[1] !== input) {
|
||||
x = [];
|
||||
bb1: if (cond) {
|
||||
break bb1;
|
||||
bb0: if (cond) {
|
||||
break bb0;
|
||||
} else {
|
||||
let t1;
|
||||
if ($[3] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -40,8 +40,8 @@ function useFoo(t0) {
|
||||
let x;
|
||||
if ($[0] !== cond || $[1] !== input.a.b) {
|
||||
x = [];
|
||||
bb1: if (cond) {
|
||||
break bb1;
|
||||
bb0: if (cond) {
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x.push(input.a.b);
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== hasAB || $[1] !== input.a || $[2] !== returnNull) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb11: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (!hasAB) {
|
||||
let t2;
|
||||
@@ -51,7 +51,7 @@ function useFoo(t0) {
|
||||
x.push(t2);
|
||||
if (!returnNull) {
|
||||
t1 = null;
|
||||
break bb11;
|
||||
break bb0;
|
||||
}
|
||||
} else {
|
||||
let t2;
|
||||
|
||||
+2
-2
@@ -47,7 +47,7 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== cond1 || $[1] !== cond2 || $[2] !== input.a.b) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb12: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (cond1) {
|
||||
if (!cond2) {
|
||||
@@ -61,7 +61,7 @@ function useFoo(t0) {
|
||||
}
|
||||
x.push(t2);
|
||||
t1 = null;
|
||||
break bb12;
|
||||
break bb0;
|
||||
} else {
|
||||
let t2;
|
||||
if ($[7] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ function useFoo(t0) {
|
||||
let t1;
|
||||
if ($[0] !== inputHasABC || $[1] !== input.a || $[2] !== inputHasAB) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb11: {
|
||||
bb0: {
|
||||
x = [];
|
||||
if (!inputHasABC) {
|
||||
let t2;
|
||||
@@ -52,7 +52,7 @@ function useFoo(t0) {
|
||||
x.push(t2);
|
||||
if (!inputHasAB) {
|
||||
t1 = null;
|
||||
break bb11;
|
||||
break bb0;
|
||||
}
|
||||
let t3;
|
||||
if ($[7] !== input.a.b) {
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ function Component() {
|
||||
let t2;
|
||||
if ($[0] !== items) {
|
||||
t2 = Symbol.for("react.early_return_sentinel");
|
||||
bb15: {
|
||||
bb0: {
|
||||
let t3;
|
||||
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t3 = (t4) => {
|
||||
@@ -72,7 +72,7 @@ function Component() {
|
||||
t4 = $[5];
|
||||
}
|
||||
t2 = t4;
|
||||
break bb15;
|
||||
break bb0;
|
||||
}
|
||||
let t4;
|
||||
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
|
||||
+2
-2
@@ -43,12 +43,12 @@ function Component(props) {
|
||||
let t1;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb8: {
|
||||
bb0: {
|
||||
const object = makeObject_Primitives();
|
||||
const cond = makeObject_Primitives();
|
||||
if (!cond) {
|
||||
t1 = null;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t0 = (
|
||||
|
||||
+3
-3
@@ -37,15 +37,15 @@ import { useMemo } from "react";
|
||||
const checkforTouchEvents = true;
|
||||
function useSupportsTouchEvent() {
|
||||
let t0;
|
||||
bb15: {
|
||||
bb0: {
|
||||
if (checkforTouchEvents) {
|
||||
try {
|
||||
document.createEvent("TouchEvent");
|
||||
t0 = true;
|
||||
break bb15;
|
||||
break bb0;
|
||||
} catch {
|
||||
t0 = false;
|
||||
break bb15;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
t0 = undefined;
|
||||
|
||||
+2
-2
@@ -51,12 +51,12 @@ function Component(props) {
|
||||
let t2;
|
||||
if ($[0] !== props) {
|
||||
t2 = Symbol.for("react.early_return_sentinel");
|
||||
bb11: {
|
||||
bb0: {
|
||||
t0 = toJSON(props);
|
||||
const propsString = t0;
|
||||
if (propsString.length <= 2) {
|
||||
t2 = null;
|
||||
break bb11;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t1 = identity(propsString);
|
||||
|
||||
+2
-2
@@ -52,10 +52,10 @@ function Component(t0) {
|
||||
const $ = useMemoCache(7);
|
||||
const { value } = t0;
|
||||
let t1;
|
||||
bb13: {
|
||||
bb0: {
|
||||
if (value == null) {
|
||||
t1 = null;
|
||||
break bb13;
|
||||
break bb0;
|
||||
}
|
||||
try {
|
||||
let t3;
|
||||
|
||||
+3
-3
@@ -43,12 +43,12 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
if (props.cond) {
|
||||
bb3: switch (props.test) {
|
||||
bb0: switch (props.test) {
|
||||
case 0: {
|
||||
break bb3;
|
||||
break bb0;
|
||||
}
|
||||
case 1: {
|
||||
break bb3;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,12 +34,12 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
```javascript
|
||||
function foo() {
|
||||
bb1: switch (1) {
|
||||
bb0: switch (1) {
|
||||
case 1: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 2: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
}
|
||||
|
||||
+3
-3
@@ -38,9 +38,9 @@ function Component(props) {
|
||||
let y;
|
||||
if ($[0] !== props) {
|
||||
x = [];
|
||||
bb1: switch (props.p0) {
|
||||
bb0: switch (props.p0) {
|
||||
case 1: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case true: {
|
||||
x.push(props.p2);
|
||||
@@ -54,7 +54,7 @@ function Component(props) {
|
||||
y = t0;
|
||||
}
|
||||
default: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case false: {
|
||||
y = x;
|
||||
|
||||
+3
-3
@@ -42,16 +42,16 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
```javascript
|
||||
function foo(x) {
|
||||
bb1: switch (x) {
|
||||
bb0: switch (x) {
|
||||
case 0: {
|
||||
}
|
||||
case 1: {
|
||||
}
|
||||
case 2: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 3: {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
case 4: {
|
||||
}
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { mutate, setProperty, throwErrorWithMessageIf } from "shared-runtime";
|
||||
|
||||
function useFoo({ value, cond }) {
|
||||
let y = [value];
|
||||
let x = { cond };
|
||||
|
||||
try {
|
||||
mutate(x);
|
||||
throwErrorWithMessageIf(x.cond, "error");
|
||||
} catch {
|
||||
setProperty(x, "henderson");
|
||||
return x;
|
||||
}
|
||||
setProperty(x, "nevada");
|
||||
y.push(x);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 4, cond: true }],
|
||||
sequentialRenders: [
|
||||
{ value: 4, cond: true },
|
||||
{ value: 5, cond: true },
|
||||
{ value: 5, cond: false },
|
||||
],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { mutate, setProperty, throwErrorWithMessageIf } from "shared-runtime";
|
||||
|
||||
function useFoo(t0) {
|
||||
const $ = useMemoCache(3);
|
||||
const { value, cond } = t0;
|
||||
let t1;
|
||||
if ($[0] !== value || $[1] !== cond) {
|
||||
t1 = Symbol.for("react.early_return_sentinel");
|
||||
bb0: {
|
||||
const y = [value];
|
||||
const x = { cond };
|
||||
try {
|
||||
mutate(x);
|
||||
throwErrorWithMessageIf(x.cond, "error");
|
||||
} catch {
|
||||
setProperty(x, "henderson");
|
||||
t1 = x;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
setProperty(x, "nevada");
|
||||
y.push(x);
|
||||
|
||||
t1 = y;
|
||||
break bb0;
|
||||
}
|
||||
$[0] = value;
|
||||
$[1] = cond;
|
||||
$[2] = t1;
|
||||
} else {
|
||||
t1 = $[2];
|
||||
}
|
||||
if (t1 !== Symbol.for("react.early_return_sentinel")) {
|
||||
return t1;
|
||||
}
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 4, cond: true }],
|
||||
sequentialRenders: [
|
||||
{ value: 4, cond: true },
|
||||
{ value: 5, cond: true },
|
||||
{ value: 5, cond: false },
|
||||
],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) {"cond":true,"wat0":"joe","wat1":"henderson"}
|
||||
{"cond":true,"wat0":"joe","wat1":"henderson"}
|
||||
[5,{"cond":false,"wat0":"joe","wat1":"nevada"}]
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { mutate, setProperty, throwErrorWithMessageIf } from "shared-runtime";
|
||||
|
||||
function useFoo({ value, cond }) {
|
||||
let y = [value];
|
||||
let x = { cond };
|
||||
|
||||
try {
|
||||
mutate(x);
|
||||
throwErrorWithMessageIf(x.cond, "error");
|
||||
} catch {
|
||||
setProperty(x, "henderson");
|
||||
return x;
|
||||
}
|
||||
setProperty(x, "nevada");
|
||||
y.push(x);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 4, cond: true }],
|
||||
sequentialRenders: [
|
||||
{ value: 4, cond: true },
|
||||
{ value: 5, cond: true },
|
||||
{ value: 5, cond: false },
|
||||
],
|
||||
};
|
||||
+3
-3
@@ -34,7 +34,7 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] !== props.y || $[1] !== props.e) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb19: {
|
||||
bb0: {
|
||||
try {
|
||||
const y = [];
|
||||
y.push(props.y);
|
||||
@@ -43,11 +43,11 @@ function Component(props) {
|
||||
const e = t1;
|
||||
e.push(props.e);
|
||||
t0 = e;
|
||||
break bb19;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t0 = null;
|
||||
break bb19;
|
||||
break bb0;
|
||||
}
|
||||
$[0] = props.y;
|
||||
$[1] = props.e;
|
||||
|
||||
+3
-3
@@ -35,7 +35,7 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb12: {
|
||||
bb0: {
|
||||
const x = [];
|
||||
try {
|
||||
throwInput(x);
|
||||
@@ -43,11 +43,11 @@ function Component(props) {
|
||||
const e = t1;
|
||||
e.push(null);
|
||||
t0 = e;
|
||||
break bb12;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t0 = x;
|
||||
break bb12;
|
||||
break bb0;
|
||||
}
|
||||
$[0] = t0;
|
||||
} else {
|
||||
|
||||
+3
-3
@@ -37,19 +37,19 @@ function Component(props) {
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = Symbol.for("react.early_return_sentinel");
|
||||
bb26: {
|
||||
bb0: {
|
||||
x = [];
|
||||
try {
|
||||
const y = shallowCopy({});
|
||||
if (y == null) {
|
||||
t0 = undefined;
|
||||
break bb26;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
x.push(throwInput(y));
|
||||
} catch {
|
||||
t0 = null;
|
||||
break bb26;
|
||||
break bb0;
|
||||
}
|
||||
}
|
||||
$[0] = x;
|
||||
|
||||
+2
-2
@@ -38,11 +38,11 @@ function useHook(cond) {
|
||||
let log;
|
||||
if ($[0] !== cond) {
|
||||
log = [];
|
||||
bb1: switch (CONST_STRING0) {
|
||||
bb0: switch (CONST_STRING0) {
|
||||
case CONST_STRING0: {
|
||||
log.push(`@A`);
|
||||
if (cond) {
|
||||
break bb1;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
log.push(`@B`);
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(4);
|
||||
let t0;
|
||||
bb7: {
|
||||
bb0: {
|
||||
if (props.cond) {
|
||||
let t1;
|
||||
if ($[0] !== props.a) {
|
||||
@@ -32,7 +32,7 @@ function Component(props) {
|
||||
t1 = $[1];
|
||||
}
|
||||
t0 = t1;
|
||||
break bb7;
|
||||
break bb0;
|
||||
}
|
||||
let t1;
|
||||
if ($[2] !== props.b) {
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function component(a, b) {
|
||||
const $ = useMemoCache(2);
|
||||
let t0;
|
||||
bb6: {
|
||||
bb0: {
|
||||
if (a) {
|
||||
let t1;
|
||||
if ($[0] !== b) {
|
||||
@@ -37,7 +37,7 @@ function component(a, b) {
|
||||
t1 = $[1];
|
||||
}
|
||||
t0 = t1;
|
||||
break bb6;
|
||||
break bb0;
|
||||
}
|
||||
t0 = undefined;
|
||||
}
|
||||
|
||||
+4
-4
@@ -28,14 +28,14 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let t0;
|
||||
bb10: {
|
||||
bb2: {
|
||||
bb0: {
|
||||
bb1: {
|
||||
if (props.cond) {
|
||||
break bb2;
|
||||
break bb1;
|
||||
}
|
||||
|
||||
t0 = props.a;
|
||||
break bb10;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
t0 = props.b;
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ import { useMemo, unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(3);
|
||||
let t0;
|
||||
bb9: {
|
||||
bb0: {
|
||||
let y;
|
||||
if ($[0] !== props) {
|
||||
y = [];
|
||||
@@ -43,7 +43,7 @@ function Component(props) {
|
||||
}
|
||||
if (props.cond2) {
|
||||
t0 = y;
|
||||
break bb9;
|
||||
break bb0;
|
||||
}
|
||||
|
||||
y.push(props.b);
|
||||
|
||||
+2
-2
@@ -29,10 +29,10 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let t0;
|
||||
bb8: switch (props.key) {
|
||||
bb0: switch (props.key) {
|
||||
case "key": {
|
||||
t0 = props.value;
|
||||
break bb8;
|
||||
break bb0;
|
||||
}
|
||||
default: {
|
||||
t0 = props.defaultValue;
|
||||
|
||||
+4
-4
@@ -35,16 +35,16 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let t0;
|
||||
bb10: {
|
||||
bb0: {
|
||||
let y;
|
||||
bb2: switch (props.switch) {
|
||||
bb1: switch (props.switch) {
|
||||
case "foo": {
|
||||
t0 = "foo";
|
||||
break bb10;
|
||||
break bb0;
|
||||
}
|
||||
case "bar": {
|
||||
y = "bar";
|
||||
break bb2;
|
||||
break bb1;
|
||||
}
|
||||
default: {
|
||||
y = props.y;
|
||||
|
||||
@@ -157,6 +157,12 @@ export function throwInput(x: Object): never {
|
||||
throw x;
|
||||
}
|
||||
|
||||
export function throwErrorWithMessageIf(cond: boolean, message: string): void {
|
||||
if (cond) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function logValue<T>(value: T): void {
|
||||
console.log(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user