compiler: super early exploration of instruction reordering

See comments in InstructionReordering.ts. This needs substantial iteration before landing in some form, just putting up to share for discussion.

ghstack-source-id: d5fb36a388
Pull Request resolved: https://github.com/facebook/react/pull/29579
This commit is contained in:
Joe Savona committed 2024-06-07 10:28:37 -07:00
1 parent c4b433f8cb
commit 286e0245bf
59 files changed
+875 -813

No files matched your search

@@ -41,6 +41,7 @@ import {
deadCodeElimination,
pruneMaybeThrows,
} from "../Optimization";
import { instructionReordering } from "../Optimization/InstructionReordering";
import {
CodegenFunction,
alignObjectMethodScopes,
@@ -202,6 +203,9 @@ function* runWithEnvironment(
deadCodeElimination(hir);
yield log({ kind: "hir", name: "DeadCodeElimination", value: hir });
instructionReordering(hir);
yield log({ kind: "hir", name: "InstructionReordering", value: hir });
pruneMaybeThrows(hir);
yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
@@ -737,6 +737,12 @@ class InferenceState {
* For debugging purposes, dumps the state to a plain
* object so that it can printed as JSON.
*/
inspect(): any {
return {
values: this.#values,
variables: this.#variables,
};
}
debug(): any {
const result: any = { values: {}, variables: {} };
const objects: Map<InstructionValue, number> = new Map();
@@ -493,7 +493,7 @@ function evaluateInstruction(
}
case "LoadLocal": {
const placeValue = read(constants, value.place);
if (placeValue !== null) {
if (placeValue != null) {
instr.value = placeValue;
}
return placeValue;
@@ -0,0 +1,258 @@
import {
BasicBlock,
Environment,
HIRFunction,
IdentifierId,
Instruction,
markInstructionIds,
} from "../HIR";
import {
eachInstructionValueLValue,
eachInstructionValueOperand,
eachTerminalOperand,
} from "../HIR/visitors";
import { mayAllocate } from "../ReactiveScopes/InferReactiveScopeVariables";
import { getOrInsertDefault } from "../Utils/utils";
/**
* WIP early exploration of instruction reordering. This is a fairly aggressive form and has
* some issues. The idea of what's implemented:
*
* The high-level approach is to build a dependency graph where nodes generally correspond
* either to instructions OR to particular lvalue assignments of an expresssion. So
* `Destructure [x, y] = z` creates 3 nodes: one for the instruction, and one each for x and y.
* The lvalue nodes depend on the instruction node that assigns them.
*
* We add dependency edges for all the rvalues/lvalues of each instruction. In addition, we
* implicitly add dependencies btw non-reorderable instructions (more on that criteria) to
* serialize any instruction where order might be observable.
*
* We then distinguish two types of instructions that are reorderable:
* - Primitives, JSXText, JSX elements, and globals can be *globally* reordered, ie across blocks.
* We defer emitting them until they are first used globally.
* - Array and object expressions are reorderable within basic blocks. This could likely be relaxed to be global.
* - StoreLocal, LoadLocal, and Destructure are reorderable within basic blocks. However, we serialize all
* references to each named variable (reads and writes) to ensure that we aren't changing the order of evaluation
* of variable references.
*
* The variable reordering relies on the fact that any variables that could be reassigned via a function expression
* are promoted to "context" variables and use LoadContext/StoreContext, which are not reorderable.
*
* In theory it might even be safe to do this variable reordering globally, but i want to think through that more.
*
* With the above context, the algorithm is approximately:
* - For each basic block:
* - Iterate the instructions to create the dependency graph
* - Re-emit instructions, "pulling" from all the values that are depended upon by the block's terminal.
* - Emit any remaining instructions that cannot be globally reordered, starting from later instructions first.
* - Save any globally-reorderable instructions into a global map that is shared across blocks, so they can be
* emitted by the first block that needs them.
*
* Emitting instructions is currently naive: we just iterate in the order that the dependencies were established.
* If instruction 4 depends on instructions 1, 2, and 3, we'll visit in depth-first order and emit 1, 2, 3, 4.
* That's true even if instruction 1 and 2 are simple instructions (for ex primitives) while instruction 3 has its
* own large dependency tree.
*
* ## Issues/things to explore:
*
* - An obvious improvement is to weight the nodes and emit dependencies based on weight. Alternatively, we could try to
* determine the reactive dependencies of each node, and try to emit nodes that have the same dependencies together.
* - Reordering destructure statements means that we also end up deferring the evaluation of its RHS. So i noticed some
* `const [state, setState] = useState(...)` getting moved around. But i think i might have just messed up the bit that
* ensures non-reorderable instructions (like the useState() call here) are serialized. So this should just be a simple fix,
* if i didn't already fix it (need to go back through the fixture output changes)
* - I also noticed that destructuring being moved meant that some reactive scopes ended up with less precise input, because
* the destructure moved into the reactive scope itself (so the scope depends on the rvalue of the destructure, not the lvalues).
* This is weird, i need to debug.
* - Probably more things.
*/
export function instructionReordering(fn: HIRFunction): void {
const globalDependencies: Dependencies = new Map();
for (const [, block] of fn.body.blocks) {
reorderBlock(fn.env, block, globalDependencies);
}
markInstructionIds(fn.body);
}
type Dependencies = Map<IdentifierId, Node>;
type Node = {
instruction: Instruction | null;
dependencies: Array<IdentifierId>;
depth: number | null;
};
function reorderBlock(
env: Environment,
block: BasicBlock,
globalDependencies: Dependencies
): void {
const dependencies: Dependencies = new Map();
const locals = new Map<string, IdentifierId>();
let previousIdentifier: IdentifierId | null = null;
for (const instr of block.instructions) {
const node: Node = getOrInsertDefault(
dependencies,
instr.lvalue.identifier.id,
{
instruction: instr,
dependencies: [],
depth: null,
}
);
if (getReorderingLevel(instr) === ReorderingLevel.None) {
if (previousIdentifier !== null) {
node.dependencies.push(previousIdentifier);
}
previousIdentifier = instr.lvalue.identifier.id;
}
for (const operand of eachInstructionValueOperand(instr.value)) {
if (
operand.identifier.name !== null &&
operand.identifier.name.kind === "named"
) {
const previous = locals.get(operand.identifier.name.value);
if (previous !== undefined) {
node.dependencies.push(previous);
}
locals.set(operand.identifier.name.value, instr.lvalue.identifier.id);
} else {
if (
dependencies.has(operand.identifier.id) ||
globalDependencies.has(operand.identifier.id)
) {
node.dependencies.push(operand.identifier.id);
}
}
}
dependencies.set(instr.lvalue.identifier.id, node);
for (const lvalue of eachInstructionValueLValue(instr.value)) {
const lvalueNode = getOrInsertDefault(
dependencies,
lvalue.identifier.id,
{
instruction: null,
dependencies: [],
depth: null,
}
);
lvalueNode.dependencies.push(instr.lvalue.identifier.id);
if (
lvalue.identifier.name !== null &&
lvalue.identifier.name.kind === "named"
) {
const previous = locals.get(lvalue.identifier.name.value);
if (previous !== undefined) {
node.dependencies.push(previous);
}
locals.set(lvalue.identifier.name.value, instr.lvalue.identifier.id);
}
}
}
function getDepth(env: Environment, id: IdentifierId): number {
const node = dependencies.get(id);
if (node == null) {
return 0;
}
if (node.depth !== null) {
return node.depth;
}
node.depth = 0;
let depth =
node.instruction != null && mayAllocate(env, node.instruction) ? 1 : 0;
for (const dep of node.dependencies) {
depth += getDepth(env, dep);
}
node.depth = depth;
return depth;
}
const instructions: Array<Instruction> = [];
function emit(id: IdentifierId): void {
const node = dependencies.get(id) ?? globalDependencies.get(id);
if (node == null) {
return;
}
dependencies.delete(id);
globalDependencies.delete(id);
node.dependencies.sort((a, b) => {
const aDepth = getDepth(env, a);
const bDepth = getDepth(env, b);
return bDepth - aDepth;
});
for (const dep of node.dependencies) {
emit(dep);
}
if (node.instruction !== null) {
instructions.push(node.instruction);
}
}
for (const operand of eachTerminalOperand(block.terminal)) {
emit(operand.identifier.id);
}
/**
* Gross hack: for value blocks we want the terminal operand to be emitted last, since that's its value.
* For other blocks the exact order doesn't matter, we assume instructions whose values aren't depended
* upon by the block terminal are used later, so it makes sense to order them last.
*/
const index = instructions.length;
for (const id of Array.from(dependencies.keys()).reverse()) {
const node = dependencies.get(id);
if (node == null) {
continue;
}
if (
node.instruction !== null &&
getReorderingLevel(node.instruction) === ReorderingLevel.Global &&
(block.kind === "block" || block.kind === "catch")
) {
globalDependencies.set(id, node);
} else {
emit(id);
}
}
if (block.kind !== "block" && block.kind !== "catch") {
const extra = instructions.splice(index);
instructions.splice(0, 0, ...extra);
}
block.instructions = instructions;
}
enum ReorderingLevel {
None = "none",
Local = "local",
Global = "global",
}
function getReorderingLevel(instr: Instruction): ReorderingLevel {
switch (instr.value.kind) {
case "JsxExpression":
case "JsxFragment":
case "JSXText":
case "LoadGlobal":
case "Primitive":
case "TemplateLiteral": {
return ReorderingLevel.Global;
}
/*
* For locals, a simple and robust strategy is to figure out the range of instructions where the identifier may be reassigned,
* and then allow reordering of LoadLocal instructions which occur after this range. Obviously for const, this means that all
* LoadLocals can be reordered, so a simpler thing to start with is just to only allow reordering of loads of known-consts.
*
* With this overall strategy we can allow global reordering of LoadLocals and remove the global/local reordering distinction
* (all reordering can be global).
*
* case "Destructure":
* case "StoreLocal":
* case "LoadLocal":
* {
* return ReorderingLevel.Local;
* }
*/
default: {
return ReorderingLevel.None;
}
}
}
@@ -186,7 +186,10 @@ export function isMutable({ id }: Instruction, place: Place): boolean {
return id >= range.start && id < range.end;
}
function mayAllocate(env: Environment, instruction: Instruction): boolean {
export function mayAllocate(
env: Environment,
instruction: Instruction
): boolean {
const { value } = instruction;
switch (value.kind) {
case "Destructure": {
@@ -94,6 +94,8 @@ function visit(fn: HIRFunction, fbtValues: Set<IdentifierId>): void {
operand.identifier.mutableRange.start
)
);
fbtValues.add(operand.identifier.id);
}
} else if (
isFbtJsxExpression(fbtValues, value) ||
@@ -126,6 +128,23 @@ function visit(fn: HIRFunction, fbtValues: Set<IdentifierId>): void {
*/
fbtValues.add(operand.identifier.id);
}
} else if (fbtValues.has(lvalue.identifier.id)) {
const fbtScope = lvalue.identifier.scope;
if (fbtScope === null) {
return;
}
for (const operand of eachReactiveValueOperand(value)) {
operand.identifier.scope = fbtScope;
// Expand the jsx element's range to account for its operands
fbtScope.range.start = makeInstructionId(
Math.min(
fbtScope.range.start,
operand.identifier.mutableRange.start
)
);
}
}
}
}
@@ -29,7 +29,10 @@ import {
} from "../HIR/ObjectShape";
import { eachInstructionLValue } from "../HIR/visitors";
import { assertExhaustive } from "../Utils/utils";
import { printReactiveScopeSummary } from "./PrintReactiveFunction";
import {
printReactiveFunction,
printReactiveScopeSummary,
} from "./PrintReactiveFunction";
import {
ReactiveFunctionTransform,
ReactiveFunctionVisitor,
@@ -84,9 +87,16 @@ import {
export function mergeReactiveScopesThatInvalidateTogether(
fn: ReactiveFunction
): void {
if (DEBUG) {
console.log(printReactiveFunction(fn));
}
const lastUsageVisitor = new FindLastUsageVisitor();
visitReactiveFunction(fn, lastUsageVisitor, undefined);
visitReactiveFunction(fn, new Transform(lastUsageVisitor.lastUsage), null);
if (DEBUG) {
console.log(printReactiveFunction(fn));
}
}
const DEBUG: boolean = false;
@@ -176,6 +186,7 @@ class Transform extends ReactiveFunctionTransform<ReactiveScopeDependencies | nu
}
case "instruction": {
switch (instr.instruction.value.kind) {
case "LoadGlobal":
case "ComputedLoad":
case "JSXText":
case "LoadLocal":
@@ -30,7 +30,9 @@ export function assertExhaustive(_: never, errorMsg: string): never {
throw new Error(errorMsg);
}
// Modifies @param array in place, retaining only the items where the predicate returns true.
/**
* Modifies @param array in place, retaining only the items where the predicate returns true.
*/
export function retainWhere<T>(
array: Array<T>,
predicate: (item: T) => boolean
@@ -67,19 +67,16 @@ function Component() {
}
useEffect(t1, t2);
let t3;
let t4;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = () => {
setState(someGlobal.value);
};
$[3] = t3;
} else {
t3 = $[3];
}
let t4;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t4 = [someGlobal];
$[3] = t3;
$[4] = t4;
} else {
t3 = $[3];
t4 = $[4];
}
useEffect(t3, t4);
@@ -39,60 +39,51 @@ import { useEffect, useState } from "react";
let someGlobal = {};
function Component() {
const $ = _c(7);
const $ = _c(6);
const [state, setState] = useState(someGlobal);
let t0;
let t1;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
const setGlobal = () => {
someGlobal.value = true;
};
$[0] = t0;
} else {
t0 = $[0];
}
const setGlobal = t0;
let t1;
let t2;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = () => {
t0 = () => {
setGlobal();
};
t2 = [];
t1 = [];
$[0] = t0;
$[1] = t1;
$[2] = t2;
} else {
t0 = $[0];
t1 = $[1];
t2 = $[2];
}
useEffect(t1, t2);
useEffect(t0, t1);
let t2;
let t3;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = () => {
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = () => {
setState(someGlobal.value);
};
t3 = [someGlobal];
$[2] = t2;
$[3] = t3;
} else {
t2 = $[2];
t3 = $[3];
}
let t4;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t4 = [someGlobal];
$[4] = t4;
} else {
t4 = $[4];
}
useEffect(t3, t4);
useEffect(t2, t3);
const t5 = String(state);
let t6;
if ($[5] !== t5) {
t6 = <div>{t5}</div>;
const t4 = String(state);
let t5;
if ($[4] !== t4) {
t5 = <div>{t4}</div>;
$[4] = t4;
$[5] = t5;
$[6] = t6;
} else {
t6 = $[6];
t5 = $[5];
}
return t6;
return t5;
}
export const FIXTURE_ENTRYPOINT = {
@@ -39,60 +39,51 @@ import { useEffect, useState } from "react";
let someGlobal = false;
function Component() {
const $ = _c(7);
const $ = _c(6);
const [state, setState] = useState(someGlobal);
let t0;
let t1;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
const setGlobal = () => {
someGlobal = true;
};
$[0] = t0;
} else {
t0 = $[0];
}
const setGlobal = t0;
let t1;
let t2;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = () => {
t0 = () => {
setGlobal();
};
t2 = [];
t1 = [];
$[0] = t0;
$[1] = t1;
$[2] = t2;
} else {
t0 = $[0];
t1 = $[1];
t2 = $[2];
}
useEffect(t1, t2);
useEffect(t0, t1);
let t2;
let t3;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = () => {
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = () => {
setState(someGlobal);
};
t3 = [someGlobal];
$[2] = t2;
$[3] = t3;
} else {
t2 = $[2];
t3 = $[3];
}
let t4;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t4 = [someGlobal];
$[4] = t4;
} else {
t4 = $[4];
}
useEffect(t3, t4);
useEffect(t2, t3);
const t5 = String(state);
let t6;
if ($[5] !== t5) {
t6 = <div>{t5}</div>;
const t4 = String(state);
let t5;
if ($[4] !== t4) {
t5 = <div>{t4}</div>;
$[4] = t4;
$[5] = t5;
$[6] = t6;
} else {
t6 = $[6];
t5 = $[5];
}
return t6;
return t5;
}
export const FIXTURE_ENTRYPOINT = {
@@ -54,19 +54,16 @@ function Component() {
}
useEffect(t0, t1);
let t2;
let t3;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = () => {
setState(someGlobal);
};
$[2] = t2;
} else {
t2 = $[2];
}
let t3;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = [someGlobal];
$[2] = t2;
$[3] = t3;
} else {
t2 = $[2];
t3 = $[3];
}
useEffect(t2, t3);
@@ -70,19 +70,16 @@ function Component() {
}
useEffect(t0, t1);
let t2;
let t3;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = () => {
setState(someGlobal.value);
};
$[2] = t2;
} else {
t2 = $[2];
}
let t3;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t3 = [someGlobal];
$[2] = t2;
$[3] = t3;
} else {
t2 = $[2];
t3 = $[3];
}
useEffect(t2, t3);
@@ -15,24 +15,17 @@ function component() {
```javascript
import { c as _c } from "react/compiler-runtime";
function component() {
const $ = _c(2);
const $ = _c(1);
const [x, setX] = useState(0);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (v) => setX(v);
const handler = (v) => setX(v);
t0 = <Foo handler={handler} />;
$[0] = t0;
} else {
t0 = $[0];
}
const handler = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Foo handler={handler} />;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
```
@@ -36,65 +36,45 @@ function mayMutate() {}
```javascript
import { c as _c } from "react/compiler-runtime";
function ComponentA(props) {
const $ = _c(6);
let a;
let b;
const $ = _c(2);
let t0;
if ($[0] !== props) {
a = [];
b = [];
const a = [];
const b = [];
if (b) {
a.push(props.p0);
}
if (props.p1) {
b.push(props.p2);
}
$[0] = props;
$[1] = a;
$[2] = b;
} else {
a = $[1];
b = $[2];
}
let t0;
if ($[3] !== a || $[4] !== b) {
t0 = <Foo a={a} b={b} />;
$[3] = a;
$[4] = b;
$[5] = t0;
$[0] = props;
$[1] = t0;
} else {
t0 = $[5];
t0 = $[1];
}
return t0;
}
function ComponentB(props) {
const $ = _c(6);
let a;
let b;
const $ = _c(2);
let t0;
if ($[0] !== props) {
a = [];
b = [];
const a = [];
const b = [];
if (mayMutate(b)) {
a.push(props.p0);
}
if (props.p1) {
b.push(props.p2);
}
$[0] = props;
$[1] = a;
$[2] = b;
} else {
a = $[1];
b = $[2];
}
let t0;
if ($[3] !== a || $[4] !== b) {
t0 = <Foo a={a} b={b} />;
$[3] = a;
$[4] = b;
$[5] = t0;
$[0] = props;
$[1] = t0;
} else {
t0 = $[5];
t0 = $[1];
}
return t0;
}
@@ -17,25 +17,19 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
const onEvent = () => {
console.log(42);
};
t0 = <Foo onEvent={onEvent} />;
$[0] = t0;
} else {
t0 = $[0];
}
const onEvent = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Foo onEvent={onEvent} />;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
```
@@ -27,26 +27,20 @@ import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";
function Component(props) {
const $ = _c(2);
let callback;
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
let x;
x = null;
callback = () => {
const callback = () => {
console.log(x);
};
x = {};
$[0] = callback;
} else {
callback = $[0];
}
let t0;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Stringify callback={callback} shouldInvokeFns={true} />;
$[1] = t0;
$[0] = t0;
} else {
t0 = $[1];
t0 = $[0];
}
return t0;
}
@@ -18,7 +18,7 @@ function Component() {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component() {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
let x;
@@ -27,20 +27,13 @@ function Component() {
x = 9;
};
t0 = bar(foo);
const y = bar(foo);
t0 = <Child y={y} />;
$[0] = t0;
} else {
t0 = $[0];
}
const y = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Child y={y} />;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
```
@@ -56,7 +56,7 @@ function useFragment(_arg1, _arg2) {
}
function Component(props) {
const $ = _c(15);
const $ = _c(9);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = graphql`...`;
@@ -65,67 +65,52 @@ function Component(props) {
t0 = $[0];
}
const post = useFragment(t0, props.post);
let media;
let allUrls;
let onClick;
let t1;
if ($[1] !== post) {
allUrls = [];
const allUrls = [];
const { media: t1, comments: t2, urls: t3 } = post;
media = t1 === undefined ? null : t1;
let t4;
if ($[5] !== t2) {
t4 = t2 === undefined ? [] : t2;
$[5] = t2;
$[6] = t4;
} else {
t4 = $[6];
}
const comments = t4;
const { media: t2, comments: t3, urls: t4 } = post;
const media = t2 === undefined ? null : t2;
let t5;
if ($[7] !== t3) {
if ($[3] !== t3) {
t5 = t3 === undefined ? [] : t3;
$[7] = t3;
$[8] = t5;
$[3] = t3;
$[4] = t5;
} else {
t5 = $[8];
t5 = $[4];
}
const urls = t5;
const comments = t5;
let t6;
if ($[9] !== comments.length) {
t6 = (e) => {
if ($[5] !== t4) {
t6 = t4 === undefined ? [] : t4;
$[5] = t4;
$[6] = t6;
} else {
t6 = $[6];
}
const urls = t6;
let t7;
if ($[7] !== comments.length) {
t7 = (e) => {
if (!comments.length) {
return;
}
console.log(comments.length);
};
$[9] = comments.length;
$[10] = t6;
$[7] = comments.length;
$[8] = t7;
} else {
t6 = $[10];
t7 = $[8];
}
onClick = t6;
const onClick = t7;
allUrls.push(...urls);
$[1] = post;
$[2] = media;
$[3] = allUrls;
$[4] = onClick;
} else {
media = $[2];
allUrls = $[3];
onClick = $[4];
}
let t1;
if ($[11] !== media || $[12] !== allUrls || $[13] !== onClick) {
t1 = <Stringify media={media} allUrls={allUrls} onClick={onClick} />;
$[11] = media;
$[12] = allUrls;
$[13] = onClick;
$[14] = t1;
$[1] = post;
$[2] = t1;
} else {
t1 = $[14];
t1 = $[2];
}
return t1;
}
@@ -30,17 +30,15 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(8);
const $ = _c(4);
const post = useFragment(graphql`...`, props.post);
let media;
let onClick;
let t0;
if ($[0] !== post) {
const allUrls = [];
const { media: t0, comments, urls } = post;
media = t0;
const { media, comments, urls } = post;
let t1;
if ($[3] !== comments.length) {
if ($[2] !== comments.length) {
t1 = (e) => {
if (!comments.length) {
return;
@@ -48,29 +46,19 @@ function Component(props) {
console.log(comments.length);
};
$[3] = comments.length;
$[4] = t1;
$[2] = comments.length;
$[3] = t1;
} else {
t1 = $[4];
t1 = $[3];
}
onClick = t1;
const onClick = t1;
allUrls.push(...urls);
$[0] = post;
$[1] = media;
$[2] = onClick;
} else {
media = $[1];
onClick = $[2];
}
let t0;
if ($[5] !== media || $[6] !== onClick) {
t0 = <Media media={media} onClick={onClick} />;
$[5] = media;
$[6] = onClick;
$[7] = t0;
$[0] = post;
$[1] = t0;
} else {
t0 = $[7];
t0 = $[1];
}
return t0;
}
@@ -99,42 +99,42 @@ function Component(t0) {
t2 = $[12];
}
let t3;
if ($[13] !== t2 || $[14] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[13] = t2;
$[14] = x;
if ($[13] !== a || $[14] !== b) {
t3 = [a, b];
$[13] = a;
$[14] = b;
$[15] = t3;
} else {
t3 = $[15];
}
let t4;
if ($[16] !== a || $[17] !== b) {
t4 = [a, b];
$[16] = a;
$[17] = b;
if ($[16] !== t3 || $[17] !== z) {
t4 = <ValidateMemoization inputs={t3} output={z} />;
$[16] = t3;
$[17] = z;
$[18] = t4;
} else {
t4 = $[18];
}
let t5;
if ($[19] !== t4 || $[20] !== z) {
t5 = <ValidateMemoization inputs={t4} output={z} />;
$[19] = t4;
$[20] = z;
if ($[19] !== t2 || $[20] !== x) {
t5 = <ValidateMemoization inputs={t2} output={x} />;
$[19] = t2;
$[20] = x;
$[21] = t5;
} else {
t5 = $[21];
}
let t6;
if ($[22] !== t3 || $[23] !== t5) {
if ($[22] !== t5 || $[23] !== t4) {
t6 = (
<>
{t3}
{t5}
{t4}
</>
);
$[22] = t3;
$[23] = t5;
$[22] = t5;
$[23] = t4;
$[24] = t6;
} else {
t6 = $[24];
@@ -20,7 +20,7 @@ function Foo() {
## Error
```
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:24(18:26)
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:23(17:25)
```
@@ -21,7 +21,7 @@ function Foo(props, ref) {
## Error
```
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 1:21(16:23)
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:20(16:23)
```
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
## Error
```
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 4:19(5:22)
Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 3:17(4:20)
```
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
const { value } = t0;
let t1;
if ($[0] !== value) {
if ($[0] !== t0) {
const { value } = t0;
t1 = fbt._(
"Before text{paramName}After text",
[fbt._param("paramName", value)],
{ hk: "aKEGX" },
);
$[0] = value;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
@@ -30,9 +30,10 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
const { value } = t0;
let t1;
if ($[0] !== value) {
if ($[0] !== t0) {
const { value } = t0;
t1 = fbt._(
"Before text {paramName}",
[
@@ -44,7 +45,7 @@ function Component(t0) {
],
{ hk: "3z5SVE" },
);
$[0] = value;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
const { value } = t0;
let t1;
if ($[0] !== value) {
if ($[0] !== t0) {
const { value } = t0;
t1 = fbt._(
"Before text {paramName} after text",
[fbt._param("paramName", value)],
{ hk: "26pxNm" },
);
$[0] = value;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
const { value } = t0;
let t1;
if ($[0] !== value) {
if ($[0] !== t0) {
const { value } = t0;
t1 = fbt._(
"Before text {paramName} after text",
[fbt._param("paramName", value)],
{ hk: "26pxNm" },
);
$[0] = value;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
@@ -31,15 +31,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
const { value } = t0;
let t1;
if ($[0] !== value) {
if ($[0] !== t0) {
const { value } = t0;
t1 = fbt._(
"Before text {paramName} after text more text and more and more and more and more and more and more and more and more and blah blah blah blah",
[fbt._param("paramName", value)],
{ hk: "24ZPpO" },
);
$[0] = value;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
@@ -29,10 +29,11 @@ import { c as _c } from "react/compiler-runtime";
import fbt from "fbt";
function Component(t0) {
const $ = _c(4);
const { name, data, icon } = t0;
const $ = _c(2);
let t1;
if ($[0] !== name || $[1] !== icon || $[2] !== data) {
if ($[0] !== t0) {
const { name, data, icon } = t0;
t1 = (
<Text type="body4">
{fbt._(
@@ -61,12 +62,10 @@ function Component(t0) {
)}
</Text>
);
$[0] = name;
$[1] = icon;
$[2] = data;
$[3] = t1;
$[0] = t0;
$[1] = t1;
} else {
t1 = $[3];
t1 = $[1];
}
return t1;
}
@@ -42,10 +42,10 @@ import { c as _c } from "react/compiler-runtime";
import { fbt } from "fbt";
function Component() {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
const buttonLabel = () => {
if (!someCondition) {
return fbt._("Purchase as a gift", null, { hk: "1gHj4g" });
} else {
@@ -66,23 +66,17 @@ function Component() {
}
}
};
$[0] = t0;
} else {
t0 = $[0];
}
const buttonLabel = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (
t0 = (
<View>
<Button text={buttonLabel()} />
</View>
);
$[1] = t1;
$[0] = t0;
} else {
t1 = $[1];
t0 = $[0];
}
return t1;
return t0;
}
```
@@ -82,42 +82,42 @@ function Component(t0) {
t4 = $[6];
}
let t5;
if ($[7] !== t4 || $[8] !== x) {
t5 = <ValidateMemoization inputs={t4} output={x} />;
$[7] = t4;
$[8] = x;
if ($[7] !== x || $[8] !== b) {
t5 = [x, b];
$[7] = x;
$[8] = b;
$[9] = t5;
} else {
t5 = $[9];
}
let t6;
if ($[10] !== x || $[11] !== b) {
t6 = [x, b];
$[10] = x;
$[11] = b;
if ($[10] !== t5 || $[11] !== y) {
t6 = <ValidateMemoization inputs={t5} output={y} />;
$[10] = t5;
$[11] = y;
$[12] = t6;
} else {
t6 = $[12];
}
let t7;
if ($[13] !== t6 || $[14] !== y) {
t7 = <ValidateMemoization inputs={t6} output={y} />;
$[13] = t6;
$[14] = y;
if ($[13] !== t4 || $[14] !== x) {
t7 = <ValidateMemoization inputs={t4} output={x} />;
$[13] = t4;
$[14] = x;
$[15] = t7;
} else {
t7 = $[15];
}
let t8;
if ($[16] !== t5 || $[17] !== t7) {
if ($[16] !== t7 || $[17] !== t6) {
t8 = (
<>
{t5}
{t7}
{t6}
</>
);
$[16] = t5;
$[17] = t7;
$[16] = t7;
$[17] = t6;
$[18] = t8;
} else {
t8 = $[18];
@@ -33,34 +33,26 @@ import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";
function hoisting() {
const $ = _c(3);
let onClick;
let onClick2;
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
onClick = function onClick() {
const onClick = function onClick() {
return bar.baz;
};
onClick2 = function onClick2() {
const onClick2 = function onClick2() {
return bar[baz];
};
const baz = "baz";
const bar = { baz: 1 };
$[0] = onClick;
$[1] = onClick2;
} else {
onClick = $[0];
onClick2 = $[1];
}
let t0;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (
<Stringify onClick={onClick} onClick2={onClick2} shouldInvokeFns={true} />
);
$[2] = t0;
$[0] = t0;
} else {
t0 = $[2];
t0 = $[0];
}
return t0;
}
@@ -28,24 +28,19 @@ import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";
function hoisting() {
const $ = _c(2);
let onClick;
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
onClick = function onClick(x) {
const onClick = function onClick(x) {
return x + bar.baz;
};
const bar = { baz: 1 };
$[0] = onClick;
} else {
onClick = $[0];
}
let t0;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Stringify onClick={onClick} />;
$[1] = t0;
$[0] = t0;
} else {
t0 = $[1];
t0 = $[0];
}
return t0;
}
@@ -24,69 +24,50 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(15);
const $ = _c(7);
const item = useFragment(FRAGMENT, props.item);
useFreeze(item);
let t0;
let T0;
let t1;
let T1;
if ($[0] !== item) {
const count = new MaybeMutable(item);
T1 = View;
T0 = View;
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <span>Text</span>;
$[5] = t1;
} else {
t1 = $[5];
}
t0 = maybeMutate(count);
$[0] = item;
$[1] = t0;
$[2] = T0;
$[3] = t1;
$[4] = T1;
} else {
t0 = $[1];
T0 = $[2];
}
let t1;
if ($[2] !== t0) {
t1 = <span>{t0}</span>;
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
T1 = $[4];
}
let t2;
if ($[6] !== t0) {
t2 = <span>{t0}</span>;
$[6] = t0;
$[7] = t2;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t2 = <span>Text</span>;
$[4] = t2;
} else {
t2 = $[7];
t2 = $[4];
}
let t3;
if ($[8] !== T0 || $[9] !== t1 || $[10] !== t2) {
if ($[5] !== t1) {
t3 = (
<T0>
{t1}
{t2}
</T0>
<View>
<View>
{t2}
{t1}
</View>
</View>
);
$[8] = T0;
$[9] = t1;
$[10] = t2;
$[11] = t3;
$[5] = t1;
$[6] = t3;
} else {
t3 = $[11];
t3 = $[6];
}
let t4;
if ($[12] !== T1 || $[13] !== t3) {
t4 = <T1>{t3}</T1>;
$[12] = T1;
$[13] = t3;
$[14] = t4;
} else {
t4 = $[14];
}
return t4;
return t3;
}
```
@@ -36,39 +36,29 @@ import { c as _c } from "react/compiler-runtime";
import { StaticText1 } from "shared-runtime";
function Component() {
const $ = _c(3);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <StaticText1 />;
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <StaticText1 />;
$[1] = t1;
} else {
t1 = $[1];
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t2 = (
t0 = (
<div>
Before text{t0}Middle text
Before text
<StaticText1 />
Middle text
<StaticText1>
Inner before text{t1}Inner middle text
Inner before text
<StaticText1 />
Inner middle text
<StaticText1 />
Inner after text
</StaticText1>
After text
</div>
);
$[2] = t2;
$[0] = t0;
} else {
t2 = $[2];
t0 = $[0];
}
return t2;
return t0;
}
export const FIXTURE_ENTRYPOINT = {
@@ -44,7 +44,7 @@ import { Stringify } from "shared-runtime";
// prevent scome scopes from merging, which concealed a bug with the merging logic.
// By avoiding JSX we eliminate extraneous instructions and more accurately test the merging.
function Component(props) {
const $ = _c(11);
const $ = _c(10);
const [state, setState] = useState(0);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
@@ -54,47 +54,44 @@ function Component(props) {
t0 = $[0];
}
let t1;
let t2;
if ($[1] !== state) {
t1 = { component: "span", props: { children: [state] } };
t2 = () => setState(state + 1);
$[1] = state;
$[2] = t1;
$[3] = t2;
} else {
t1 = $[2];
}
let t2;
if ($[3] !== state) {
t2 = () => setState(state + 1);
$[3] = state;
$[4] = t2;
} else {
t2 = $[4];
t2 = $[3];
}
let t3;
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t3 = ["increment"];
$[5] = t3;
$[4] = t3;
} else {
t3 = $[5];
t3 = $[4];
}
let t4;
if ($[6] !== t2) {
if ($[5] !== t2) {
t4 = {
component: "button",
props: { "data-testid": "button", onClick: t2, children: t3 },
};
$[6] = t2;
$[7] = t4;
$[5] = t2;
$[6] = t4;
} else {
t4 = $[7];
t4 = $[6];
}
let t5;
if ($[8] !== t1 || $[9] !== t4) {
if ($[7] !== t1 || $[8] !== t4) {
t5 = [t0, t1, t4];
$[8] = t1;
$[9] = t4;
$[10] = t5;
$[7] = t1;
$[8] = t4;
$[9] = t5;
} else {
t5 = $[10];
t5 = $[9];
}
return t5;
}
@@ -33,49 +33,45 @@ import { useState } from "react";
import { Stringify } from "shared-runtime";
function Component() {
const $ = _c(8);
const $ = _c(7);
const [state, setState] = useState(0);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Stringify text="Counter" />;
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] !== state) {
t1 = <span>{state}</span>;
$[1] = state;
$[2] = t1;
} else {
t1 = $[2];
}
let t2;
if ($[3] !== state) {
t2 = (
if ($[0] !== state) {
t0 = (
<button data-testid="button" onClick={() => setState(state + 1)}>
increment
</button>
);
$[3] = state;
$[4] = t2;
t1 = <span>{state}</span>;
$[0] = state;
$[1] = t0;
$[2] = t1;
} else {
t2 = $[4];
t0 = $[1];
t1 = $[2];
}
let t2;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t2 = <Stringify text="Counter" />;
$[3] = t2;
} else {
t2 = $[3];
}
let t3;
if ($[5] !== t1 || $[6] !== t2) {
if ($[4] !== t1 || $[5] !== t0) {
t3 = (
<div>
{t0}
{t1}
{t2}
{t1}
{t0}
</div>
);
$[5] = t1;
$[6] = t2;
$[7] = t3;
$[4] = t1;
$[5] = t0;
$[6] = t3;
} else {
t3 = $[7];
t3 = $[6];
}
return t3;
}
@@ -26,7 +26,7 @@ import { c as _c } from "react/compiler-runtime";
import { useState } from "react";
function Component() {
const $ = _c(6);
const $ = _c(4);
const [state, setState] = useState(0);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
@@ -39,34 +39,26 @@ function Component() {
}
const onClick = t0;
let t1;
if ($[1] !== state) {
t1 = <span>Count: {state}</span>;
$[1] = state;
$[2] = t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <button onClick={onClick}>Increment</button>;
$[1] = t1;
} else {
t1 = $[2];
t1 = $[1];
}
let t2;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t2 = <button onClick={onClick}>Increment</button>;
if ($[2] !== state) {
t2 = (
<>
<span>Count: {state}</span>
{t1}
</>
);
$[2] = state;
$[3] = t2;
} else {
t2 = $[3];
}
let t3;
if ($[4] !== t1) {
t3 = (
<>
{t1}
{t2}
</>
);
$[4] = t1;
$[5] = t3;
} else {
t3 = $[5];
}
return t3;
return t2;
}
```
@@ -36,27 +36,20 @@ const ErrorView = isForgetEnabled_Fixtures()
export default Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
t0 = (
<Foo>
<Bar />
<ErrorView />
</Foo>
);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
: (props) => (
<Foo>
@@ -36,27 +36,20 @@ const ErrorView = isForgetEnabled_Fixtures()
export const Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
t0 = (
<Foo>
<Bar />
<ErrorView />
</Foo>
);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
: (props) => (
<Foo>
@@ -38,27 +38,20 @@ const ErrorView = isForgetEnabled_Fixtures()
const Renderer = isForgetEnabled_Fixtures()
? (props) => {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <Bar />;
t0 = (
<Foo>
<Bar />
<ErrorView />
</Foo>
);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (
<Foo>
{t0}
<ErrorView />
</Foo>
);
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
return t0;
}
: (props) => (
<Foo>
@@ -18,30 +18,19 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(6);
let x;
let child;
const $ = _c(2);
let t0;
if ($[0] !== props.p0) {
x = {};
const x = {};
const y = [];
x.y = y;
child = <Component data={y} />;
const child = <Component data={y} />;
x.y.push(props.p0);
$[0] = props.p0;
$[1] = x;
$[2] = child;
} else {
x = $[1];
child = $[2];
}
let t0;
if ($[3] !== x || $[4] !== child) {
t0 = <Component data={x}>{child}</Component>;
$[3] = x;
$[4] = child;
$[5] = t0;
$[0] = props.p0;
$[1] = t0;
} else {
t0 = $[5];
t0 = $[1];
}
return t0;
}
@@ -23,42 +23,32 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(9);
let x;
let y;
const $ = _c(5);
let t0;
if ($[0] !== props.p0 || $[1] !== props.p1 || $[2] !== props.p2) {
x = [];
let x = [];
x.push(props.p0);
y = x;
const y = x;
if (props.p1) {
let t0;
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
t0 = [];
$[5] = t0;
let t1;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t1 = [];
$[4] = t1;
} else {
t0 = $[5];
t1 = $[4];
}
x = t0;
x = t1;
}
y.push(props.p2);
t0 = <Component x={x} y={y} />;
$[0] = props.p0;
$[1] = props.p1;
$[2] = props.p2;
$[3] = x;
$[4] = y;
$[3] = t0;
} else {
x = $[3];
y = $[4];
}
let t0;
if ($[6] !== x || $[7] !== y) {
t0 = <Component x={x} y={y} />;
$[6] = x;
$[7] = y;
$[8] = t0;
} else {
t0 = $[8];
t0 = $[3];
}
return t0;
}
@@ -22,39 +22,29 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(8);
let x;
let y;
const $ = _c(4);
let t0;
if ($[0] !== props.p0 || $[1] !== props.p1) {
x = [];
let x = [];
x.push(props.p0);
y = x;
let t0;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t0 = [];
$[4] = t0;
const y = x;
let t1;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t1 = [];
$[3] = t1;
} else {
t0 = $[4];
t1 = $[3];
}
x = t0;
x = t1;
y.push(props.p1);
t0 = <Component x={x} y={y} />;
$[0] = props.p0;
$[1] = props.p1;
$[2] = x;
$[3] = y;
$[2] = t0;
} else {
x = $[2];
y = $[3];
}
let t0;
if ($[5] !== x || $[6] !== y) {
t0 = <Component x={x} y={y} />;
$[5] = x;
$[6] = y;
$[7] = t0;
} else {
t0 = $[7];
t0 = $[2];
}
return t0;
}
@@ -29,30 +29,39 @@ import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";
function Component(t0) {
const $ = _c(3);
const $ = _c(5);
const { id } = t0;
let t1;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <Stringify title={undefined} />;
const t1 = id ? true : false;
let t2;
if ($[0] !== t1) {
t2 = <Stringify title={t1} />;
$[0] = t1;
} else {
t1 = $[0];
}
const t2 = id ? true : false;
let t3;
if ($[1] !== t2) {
t3 = (
<>
{t1}
<Stringify title={t2} />
</>
);
$[1] = t2;
} else {
t2 = $[1];
}
let t3;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t3 = <Stringify title={undefined} />;
$[2] = t3;
} else {
t3 = $[2];
}
return t3;
let t4;
if ($[3] !== t2) {
t4 = (
<>
{t3}
{t2}
</>
);
$[3] = t2;
$[4] = t4;
} else {
t4 = $[4];
}
return t4;
}
export const FIXTURE_ENTRYPOINT = {
@@ -35,10 +35,9 @@ import { c as _c } from "react/compiler-runtime"; // @enableAssumeHooksFollowRul
import { Stringify, identity, useHook } from "shared-runtime";
function Component(t0) {
const $ = _c(17);
const $ = _c(15);
const { index } = t0;
const data = useHook();
let T0;
let t1;
let t2;
let t3;
@@ -47,62 +46,60 @@ function Component(t0) {
const b = identity(data, index);
const c = identity(data, index);
const t4 = identity(b);
if ($[6] !== t4) {
t2 = <Stringify value={t4} />;
$[6] = t4;
$[7] = t2;
} else {
t2 = $[7];
}
const t5 = identity(a);
if ($[8] !== t5) {
t3 = <Stringify value={t5} />;
$[8] = t5;
$[9] = t3;
} else {
t3 = $[9];
}
T0 = Stringify;
t3 = identity(b);
t2 = identity(a);
t1 = identity(c);
$[0] = data;
$[1] = index;
$[2] = T0;
$[3] = t1;
$[4] = t2;
$[5] = t3;
$[2] = t1;
$[3] = t2;
$[4] = t3;
} else {
T0 = $[2];
t1 = $[3];
t2 = $[4];
t3 = $[5];
t1 = $[2];
t2 = $[3];
t3 = $[4];
}
let t4;
if ($[10] !== T0 || $[11] !== t1) {
t4 = <T0 value={t1} />;
$[10] = T0;
$[11] = t1;
$[12] = t4;
if ($[5] !== t1) {
t4 = <Stringify value={t1} />;
$[5] = t1;
$[6] = t4;
} else {
t4 = $[12];
t4 = $[6];
}
let t5;
if ($[13] !== t2 || $[14] !== t3 || $[15] !== t4) {
t5 = (
if ($[7] !== t2) {
t5 = <Stringify value={t2} />;
$[7] = t2;
$[8] = t5;
} else {
t5 = $[8];
}
let t6;
if ($[9] !== t3) {
t6 = <Stringify value={t3} />;
$[9] = t3;
$[10] = t6;
} else {
t6 = $[10];
}
let t7;
if ($[11] !== t6 || $[12] !== t5 || $[13] !== t4) {
t7 = (
<div>
{t2}
{t3}
{t6}
{t5}
{t4}
</div>
);
$[13] = t2;
$[14] = t3;
$[15] = t4;
$[16] = t5;
$[11] = t6;
$[12] = t5;
$[13] = t4;
$[14] = t7;
} else {
t5 = $[16];
t7 = $[14];
}
return t5;
return t7;
}
export const FIXTURE_ENTRYPOINT = {
@@ -17,34 +17,30 @@ function Component(listItem, thread) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(listItem, thread) {
const $ = _c(7);
const $ = _c(6);
let t0;
let t1;
let t2;
if ($[0] !== thread.threadType || $[1] !== listItem) {
const isFoo = isFooThread(thread.threadType);
t1 = useBar;
t2 = listItem;
t1 = listItem;
t0 = getBadgeText(listItem, isFoo);
$[0] = thread.threadType;
$[1] = listItem;
$[2] = t0;
$[3] = t1;
$[4] = t2;
} else {
t0 = $[2];
t1 = $[3];
t2 = $[4];
}
let t3;
if ($[5] !== t0) {
t3 = [t0];
$[5] = t0;
$[6] = t3;
let t2;
if ($[4] !== t0) {
t2 = [t0];
$[4] = t0;
$[5] = t2;
} else {
t3 = $[6];
t2 = $[5];
}
const body = t1(t2, t3);
const body = useBar(t1, t2);
return body;
}
@@ -56,33 +56,33 @@ function Component(t0) {
t2 = $[1];
}
let t3;
if ($[2] !== t2) {
t3 = <div className={t2} />;
$[2] = t2;
if ($[2] !== cond) {
t3 = cond === false && (
<div className={identity(styles.c, DISPLAY ? styles.d : {})} />
);
$[2] = cond;
$[3] = t3;
} else {
t3 = $[3];
}
let t4;
if ($[4] !== cond) {
t4 = cond === false && (
<div className={identity(styles.c, DISPLAY ? styles.d : {})} />
);
$[4] = cond;
if ($[4] !== t2) {
t4 = <div className={t2} />;
$[4] = t2;
$[5] = t4;
} else {
t4 = $[5];
}
let t5;
if ($[6] !== t3 || $[7] !== t4) {
if ($[6] !== t4 || $[7] !== t3) {
t5 = (
<>
{t3}
{t4}
{t3}
</>
);
$[6] = t3;
$[7] = t4;
$[6] = t4;
$[7] = t3;
$[8] = t5;
} else {
t5 = $[8];
@@ -24,13 +24,12 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(6);
const $ = _c(2);
const item = props.item;
let baseVideos;
let thumbnails;
let t0;
if ($[0] !== item) {
thumbnails = [];
baseVideos = getBaseVideos(item);
const thumbnails = [];
const baseVideos = getBaseVideos(item);
baseVideos.forEach((video) => {
const baseVideo = video.hasBaseVideo;
@@ -38,21 +37,12 @@ function Component(props) {
thumbnails.push({ extraVideo: true });
}
});
$[0] = item;
$[1] = baseVideos;
$[2] = thumbnails;
} else {
baseVideos = $[1];
thumbnails = $[2];
}
let t0;
if ($[3] !== baseVideos || $[4] !== thumbnails) {
t0 = <FlatList baseVideos={baseVideos} items={thumbnails} />;
$[3] = baseVideos;
$[4] = thumbnails;
$[5] = t0;
$[0] = item;
$[1] = t0;
} else {
t0 = $[5];
t0 = $[1];
}
return t0;
}
@@ -24,35 +24,26 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(6);
let x;
let y;
const $ = _c(2);
let t0;
if ($[0] !== props) {
x = [];
const x = [];
let y;
if (props.p0) {
x.push(props.p1);
y = x;
}
$[0] = props;
$[1] = x;
$[2] = y;
} else {
x = $[1];
y = $[2];
}
let t0;
if ($[3] !== x || $[4] !== y) {
t0 = (
<Component>
{x}
{y}
</Component>
);
$[3] = x;
$[4] = y;
$[5] = t0;
$[0] = props;
$[1] = t0;
} else {
t0 = $[5];
t0 = $[1];
}
return t0;
}
@@ -33,25 +33,25 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(9);
let x;
const $ = _c(7);
let y;
let t0;
if ($[0] !== props) {
x = [];
const x = [];
bb0: switch (props.p0) {
case 1: {
break bb0;
}
case true: {
x.push(props.p2);
let t0;
let t1;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t0 = [];
$[3] = t0;
t1 = [];
$[3] = t1;
} else {
t0 = $[3];
t1 = $[3];
}
y = t0;
y = t1;
}
default: {
break bb0;
@@ -60,31 +60,25 @@ function Component(props) {
y = x;
}
}
$[0] = props;
$[1] = x;
$[2] = y;
} else {
x = $[1];
y = $[2];
}
let t0;
if ($[4] !== x) {
t0 = <Component data={x} />;
$[4] = x;
$[5] = t0;
$[0] = props;
$[1] = y;
$[2] = t0;
} else {
t0 = $[5];
y = $[1];
t0 = $[2];
}
const child = t0;
y.push(props.p4);
let t1;
if ($[6] !== y || $[7] !== child) {
if ($[4] !== y || $[5] !== child) {
t1 = <Component data={y}>{child}</Component>;
$[6] = y;
$[7] = child;
$[8] = t1;
$[4] = y;
$[5] = child;
$[6] = t1;
} else {
t1 = $[8];
t1 = $[6];
}
return t1;
}
@@ -28,11 +28,11 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(8);
let x;
const $ = _c(6);
let y;
let t0;
if ($[0] !== props) {
x = [];
const x = [];
switch (props.p0) {
case true: {
x.push(props.p2);
@@ -42,31 +42,25 @@ function Component(props) {
y = x;
}
}
$[0] = props;
$[1] = x;
$[2] = y;
} else {
x = $[1];
y = $[2];
}
let t0;
if ($[3] !== x) {
t0 = <Component data={x} />;
$[3] = x;
$[4] = t0;
$[0] = props;
$[1] = y;
$[2] = t0;
} else {
t0 = $[4];
y = $[1];
t0 = $[2];
}
const child = t0;
y.push(props.p4);
let t1;
if ($[5] !== y || $[6] !== child) {
if ($[3] !== y || $[4] !== child) {
t1 = <Component data={y}>{child}</Component>;
$[5] = y;
$[6] = child;
$[7] = t1;
$[3] = y;
$[4] = child;
$[5] = t1;
} else {
t1 = $[7];
t1 = $[5];
}
return t1;
}
@@ -24,10 +24,10 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(4);
let x;
const $ = _c(2);
let t0;
if ($[0] !== props.cond) {
x = {};
const x = {};
const onChange = (e) => {
maybeMutate(x, e.target.value);
@@ -36,18 +36,11 @@ function Component(props) {
}
onChange();
$[0] = props.cond;
$[1] = x;
} else {
x = $[1];
}
let t0;
if ($[2] !== x) {
t0 = <Foo value={x} />;
$[2] = x;
$[3] = t0;
$[0] = props.cond;
$[1] = t0;
} else {
t0 = $[3];
t0 = $[1];
}
return t0;
}
@@ -21,22 +21,15 @@ function component() {
```javascript
import { c as _c } from "react/compiler-runtime";
function component() {
const $ = _c(2);
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = makeSomePrimitive();
t0 = { u: makeSomePrimitive(), v: makeSomePrimitive() };
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = { u: t0, v: makeSomePrimitive() };
$[1] = t1;
} else {
t1 = $[1];
}
const x = t1;
const x = t0;
const u = x.u;
const v = x.v;
if (u > v) {
@@ -27,42 +27,42 @@ function Component(props) {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(6);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <div />;
$[0] = t0;
} else {
t0 = $[0];
}
const dispatch = useDispatch();
useFreeze(dispatch);
let t0;
if ($[0] !== dispatch) {
t0 = () => {
let t1;
if ($[1] !== dispatch) {
t1 = () => {
dispatch({ kind: "update" });
};
$[0] = dispatch;
$[1] = t0;
$[1] = dispatch;
$[2] = t1;
} else {
t0 = $[1];
t1 = $[2];
}
const onUpdate = t0;
let t1;
const onUpdate = t1;
let t2;
if ($[2] !== onUpdate) {
t1 = () => {
let t3;
if ($[3] !== onUpdate) {
t2 = () => {
onUpdate();
};
t2 = [onUpdate];
$[2] = onUpdate;
$[3] = t1;
t3 = [onUpdate];
$[3] = onUpdate;
$[4] = t2;
} else {
t1 = $[3];
t2 = $[4];
}
useEffect(t1, t2);
let t3;
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
t3 = <div />;
$[5] = t3;
} else {
t2 = $[4];
t3 = $[5];
}
return t3;
useEffect(t2, t3);
return t0;
}
```
@@ -36,23 +36,30 @@ import { c as _c } from "react/compiler-runtime"; // @enableTransitivelyFreezeFu
function Component(props) {
const $ = _c(9);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <div />;
$[0] = t0;
} else {
t0 = $[0];
}
const item = useMutable(props.itemId);
const dispatch = useDispatch();
useFreeze(dispatch);
let t0;
if ($[0] !== dispatch) {
t0 = () => {
let t1;
if ($[1] !== dispatch) {
t1 = () => {
dispatch(createExitAction());
};
$[0] = dispatch;
$[1] = t0;
$[1] = dispatch;
$[2] = t1;
} else {
t0 = $[1];
t1 = $[2];
}
const exit = t0;
let t1;
if ($[2] !== item.value || $[3] !== exit) {
t1 = () => {
const exit = t1;
let t2;
if ($[3] !== item.value || $[4] !== exit) {
t2 = () => {
const cleanup = GlobalEventEmitter.addListener("onInput", () => {
if (item.value) {
exit();
@@ -60,32 +67,24 @@ function Component(props) {
});
return () => cleanup.remove();
};
$[2] = item.value;
$[3] = exit;
$[4] = t1;
$[3] = item.value;
$[4] = exit;
$[5] = t2;
} else {
t1 = $[4];
t2 = $[5];
}
let t2;
if ($[5] !== exit || $[6] !== item) {
t2 = [exit, item];
$[5] = exit;
$[6] = item;
$[7] = t2;
} else {
t2 = $[7];
}
useEffect(t1, t2);
maybeMutate(item);
let t3;
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
t3 = <div />;
if ($[6] !== exit || $[7] !== item) {
t3 = [exit, item];
$[6] = exit;
$[7] = item;
$[8] = t3;
} else {
t3 = $[8];
}
return t3;
useEffect(t2, t3);
maybeMutate(item);
return t0;
}
```
@@ -80,7 +80,6 @@ function Component(props) {
return t2;
}
default: {
logEvent("Invalid step");
let t1;
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
t1 = <OtherComponent data={null} />;
@@ -88,6 +87,7 @@ function Component(props) {
} else {
t1 = $[6];
}
logEvent("Invalid step");
return t1;
}
}
+14
View File
@@ -34,6 +34,7 @@ type RunnerOptions = {
watch: boolean;
filter: boolean;
update: boolean;
verbose: boolean;
};
const opts: RunnerOptions = yargs
@@ -61,10 +62,19 @@ const opts: RunnerOptions = yargs
"Only run fixtures which match the contents of testfilter.txt"
)
.default("filter", false)
.boolean("verbose")
.describe("verbose", "Enable additional logging")
.default("verbose", false)
.help("help")
.strict()
.parseSync(hideBin(process.argv));
function log(msg: string): void {
if (opts.verbose) {
console.log(msg);
}
}
/**
* Do a test run and return the test results
*/
@@ -98,16 +108,20 @@ async function runFixtures(
entries = await Promise.all(work);
} else {
log("runFixtures() start");
entries = [];
for (const [fixtureName, fixture] of fixtures) {
log(`${fixture.inputPath} start`);
let output = await runnerWorker.transformFixture(
fixture,
compilerVersion,
(filter?.debug ?? false) && isOnlyFixture,
true
);
log("...complete");
entries.push([fixtureName, output]);
}
log("runFixtures() complete");
}
return new Map(entries);