diff --git a/compiler/forget/src/CompilerPipeline.ts b/compiler/forget/src/CompilerPipeline.ts index 75c1381aaa..3532f92eef 100644 --- a/compiler/forget/src/CompilerPipeline.ts +++ b/compiler/forget/src/CompilerPipeline.ts @@ -23,6 +23,7 @@ import { printReactiveFunction, propagateScopeDependencies, pruneUnusedLabels, + pruneUnusedScopes, } from "./ReactiveScopes"; import { eliminateRedundantPhi, enterSSA, leaveSSA } from "./SSA"; import { logHIRFunction } from "./Utils/logger"; @@ -69,6 +70,7 @@ export default function ( pruneUnusedLabels(reactiveFunction); flattenReactiveLoops(reactiveFunction); propagateScopeDependencies(reactiveFunction); + pruneUnusedScopes(reactiveFunction); const scopes = printReactiveFunction(reactiveFunction); const ast = codegenReactiveFunction(reactiveFunction); diff --git a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts index d444d9f7bb..9434866701 100644 --- a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -166,8 +166,12 @@ function codegenReactiveScope( ) ); } + let firstOutputIndex: number | null = null; for (const output of scope.outputs) { const index = cx.nextCacheIndex; + if (firstOutputIndex === null) { + firstOutputIndex = index; + } // TODO @josephsavona: ensure change and temp variables have non-conflicting names output.name ??= `t${index}`; @@ -194,16 +198,34 @@ function codegenReactiveScope( ) ); } - const testCondition = - (changeIdentifiers as Array).reduce( - (acc: t.Expression | null, ident: t.Expression) => { - if (acc == null) { - return ident; - } - return t.logicalExpression("||", acc, ident); - }, - null as t.Expression | null - ) ?? t.booleanLiteral(true); // TODO @josephsavona handle case of empty dependencies + invariant( + firstOutputIndex !== null, + "Expected scope '@%s' to have at least one output", + scope.id + ); + let testCondition = (changeIdentifiers as Array).reduce( + (acc: t.Expression | null, ident: t.Expression) => { + if (acc == null) { + return ident; + } + return t.logicalExpression("||", acc, ident); + }, + null as t.Expression | null + ); + if (testCondition === null) { + testCondition = t.binaryExpression( + "===", + t.memberExpression( + t.identifier("$"), + t.numericLiteral(firstOutputIndex), + true + ), + t.callExpression( + t.memberExpression(t.identifier("Symbol"), t.identifier("for")), + [t.stringLiteral("react.memo_cache_sentinel")] + ) + ); + } const computationBlock = codegenBlock(cx, block); computationBlock.body.push(...cacheStoreStatements); diff --git a/compiler/forget/src/ReactiveScopes/PruneUnusedScopes.ts b/compiler/forget/src/ReactiveScopes/PruneUnusedScopes.ts new file mode 100644 index 0000000000..fe5e38387e --- /dev/null +++ b/compiler/forget/src/ReactiveScopes/PruneUnusedScopes.ts @@ -0,0 +1,52 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { ReactiveBlock, ReactiveFunction } from "../HIR/HIR"; +import { assertExhaustive } from "../Utils/utils"; +import { mapTerminalBlocks } from "./visitors"; + +/** + * Converts scopes without outputs into regular blocks. + */ +export function pruneUnusedScopes(fn: ReactiveFunction): void { + fn.body = visitBlock(fn.body); +} + +function visitBlock(block: ReactiveBlock): ReactiveBlock { + let nextBlock: ReactiveBlock | null = null; + for (let i = 0; i < block.length; i++) { + const stmt = block[i]!; + switch (stmt.kind) { + case "terminal": { + mapTerminalBlocks(stmt.terminal, visitBlock); + break; + } + case "instruction": { + break; + } + case "scope": { + stmt.instructions = visitBlock(stmt.instructions); + if (stmt.scope.outputs.size === 0) { + nextBlock ??= block.slice(0, i); + nextBlock.push(...stmt.instructions); + continue; + } + break; + } + default: { + assertExhaustive( + stmt, + `Unexpected statement kind '${(stmt as any).kind}'` + ); + } + } + if (nextBlock !== null) { + nextBlock.push(stmt); + } + } + return nextBlock ?? block; +} diff --git a/compiler/forget/src/ReactiveScopes/index.ts b/compiler/forget/src/ReactiveScopes/index.ts index 3fcfa28bdd..8491e3b914 100644 --- a/compiler/forget/src/ReactiveScopes/index.ts +++ b/compiler/forget/src/ReactiveScopes/index.ts @@ -13,3 +13,4 @@ export { inferReactiveScopeVariables } from "./InferReactiveScopeVariables"; export { printReactiveFunction } from "./PrintReactiveFunction"; export { propagateScopeDependencies } from "./PropagateScopeDependencies"; export { pruneUnusedLabels } from "./PruneUnusedLabels"; +export { pruneUnusedScopes } from "./PruneUnusedScopes"; diff --git a/compiler/forget/src/ReactiveScopes/visitors.ts b/compiler/forget/src/ReactiveScopes/visitors.ts new file mode 100644 index 0000000000..c46c3a7c7d --- /dev/null +++ b/compiler/forget/src/ReactiveScopes/visitors.ts @@ -0,0 +1,52 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { ReactiveBlock, ReactiveTerminal } from "../HIR/HIR"; +import { assertExhaustive } from "../Utils/utils"; + +export function mapTerminalBlocks( + terminal: ReactiveTerminal, + fn: (block: ReactiveBlock) => ReactiveBlock +): void { + switch (terminal.kind) { + case "break": + case "continue": + case "return": + case "throw": { + break; + } + case "for": { + terminal.loop = fn(terminal.loop); + break; + } + case "while": { + terminal.loop = fn(terminal.loop); + break; + } + case "if": { + terminal.consequent = fn(terminal.consequent); + if (terminal.alternate !== null) { + terminal.alternate = fn(terminal.alternate); + } + break; + } + case "switch": { + for (const case_ of terminal.cases) { + if (case_.block !== undefined) { + case_.block = fn(case_.block); + } + } + break; + } + default: { + assertExhaustive( + terminal, + `Unexpected terminal kind '${(terminal as any).kind}'` + ); + } + } +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md index f8b8b37698..ab354c4b22 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md @@ -43,15 +43,13 @@ bb1: function Component( props, ) { - scope @0 [1:7] deps=[read props$3.a, read props$3.b, read props$3.d, read props$3.c] out=[] { - [1] Const mutate a$4_@0[1:7] = Array [] - [2] Call mutate a$4_@0.push(read props$3.a) - if (read props$3.b) { - [6] Call mutate a$4_@0.push(read props$3.d) - return freeze a$4_@0 - } - [4] Call mutate a$4_@0.push(read props$3.c) + [1] Const mutate a$4_@0[1:7] = Array [] + [2] Call mutate a$4_@0.push(read props$3.a) + if (read props$3.b) { + [6] Call mutate a$4_@0.push(read props$3.d) + return freeze a$4_@0 } + [4] Call mutate a$4_@0.push(read props$3.c) } ``` @@ -60,27 +58,14 @@ function Component( ```javascript function Component$0(props$3) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== props$3.a; - const c_1 = $[1] !== props$3.b; - const c_2 = $[2] !== props$3.d; - const c_3 = $[3] !== props$3.c; - if (c_0 || c_1 || c_2 || c_3) { - const a$4 = []; - a$4.push(props$3.a); - - if (props$3.b) { - a$4.push(props$3.d); - return a$4; - } - - a$4.push(props$3.c); - $[0] = props$3.a; - $[1] = props$3.b; - $[2] = props$3.d; - $[3] = props$3.c; - } else { + const a$4 = []; + a$4.push(props$3.a); + if (props$3.b) { + a$4.push(props$3.d); + return a$4; } + + a$4.push(props$3.c); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md index 1bfec4ea09..bec0c01fec 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md @@ -31,14 +31,12 @@ bb0: ``` function component( ) { - scope @0 [1:7] deps=[] out=[] { - [1] Const mutate z$5_@0[1:7] = Array [] - [2] Const mutate y$6_@0:TObject[1:7] = Object { } - [3] Reassign mutate y$6_@0.z[1:7] = read z$5_@0 - [4] Const mutate x$7_@0:TObject[1:7] = Object { } - [5] Reassign mutate x$7_@0.y[1:7] = read y$6_@0:TObject - [6] Call mutate mutate$4:TFunction(mutate x$7_@0.y.z) - } + [1] Const mutate z$5_@0[1:7] = Array [] + [2] Const mutate y$6_@0:TObject[1:7] = Object { } + [3] Reassign mutate y$6_@0.z[1:7] = read z$5_@0 + [4] Const mutate x$7_@0:TObject[1:7] = Object { } + [5] Reassign mutate x$7_@0.y[1:7] = read y$6_@0:TObject + [6] Call mutate mutate$4:TFunction(mutate x$7_@0.y.z) return } @@ -48,15 +46,12 @@ function component( ```javascript function component$0() { - if (true) { - const z$5 = []; - const y$6 = {}; - y$6.z = z$5; - const x$7 = {}; - x$7.y = y$6; - mutate$4(x$7.y.z); - } else { - } + const z$5 = []; + const y$6 = {}; + y$6.z = z$5; + const x$7 = {}; + x$7.y = y$6; + mutate$4(x$7.y.z); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md index b1167bf4d6..f503b73597 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md @@ -52,7 +52,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let z$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { z$4 = []; $[0] = z$4; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md index 83308f069f..e391fd7876 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md @@ -76,11 +76,9 @@ function g( a, ) { [1] Const mutate $5:TPrimitive = 1 - scope @0 [0:5] deps=[] out=[] { - [2] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c + read $5:TPrimitive - [3] Const mutate $6:TPrimitive = 2 - [4] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c * read $6:TPrimitive - } + [2] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c + read $5:TPrimitive + [3] Const mutate $6:TPrimitive = 2 + [4] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c * read $6:TPrimitive return } @@ -90,11 +88,8 @@ function g( ```javascript function g$0(a$4) { - if (true) { - a$4.c.b = a$4.b.c + 1; - a$4.c.b = a$4.b.c * 2; - } else { - } + a$4.c.b = a$4.b.c + 1; + a$4.c.b = a$4.b.c * 2; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md index ec62da2830..8f9472bbd7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md @@ -49,8 +49,8 @@ bb0: [5] Const mutate _$13_@1 = JSX [6] Call mutate foo$4:TFunction(mutate b$11_@0:TObject) [7] Const mutate $14:TPrimitive = "div" - [8] Const mutate t5$15_@2 = JSX - [9] Return read t5$15_@2 + [8] Const mutate t4$15_@2 = JSX + [9] Return read t4$15_@2 ``` ## Reactive Scopes @@ -64,9 +64,7 @@ function Component( [2] Const mutate b$11_@0:TObject[1:7] = Object { } [3] Call mutate foo$4:TFunction(mutate a$10_@0, mutate b$11_@0:TObject) [4] Const mutate $12:TPrimitive = "div" - scope @1 [5:6] deps=[freeze a$10_@0] out=[] { - [5] Const mutate _$13_@1 = JSX - } + [5] Const mutate _$13_@1 = JSX [6] Call mutate foo$4:TFunction(mutate b$11_@0:TObject) } [7] Const mutate $14:TPrimitive = "div" @@ -85,18 +83,12 @@ function Component$0(props$9) { const $ = React.useMemoCache(); let a$10; let b$11; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$10 = []; b$11 = {}; foo$4(a$10, b$11); - const c_2 = $[2] !== a$10; - if (c_2) { - const _$13 =
; - - $[2] = a$10; - } else { - } + const _$13 =
; foo$4(b$11); $[0] = a$10; @@ -106,20 +98,20 @@ function Component$0(props$9) { b$11 = $[1]; } - const c_3 = $[3] !== a$10; - const c_4 = $[4] !== b$11; - let t5$15; + const c_2 = $[2] !== a$10; + const c_3 = $[3] !== b$11; + let t4$15; - if (c_3 || c_4) { - t5$15 =
; - $[3] = a$10; - $[4] = b$11; - $[5] = t5$15; + if (c_2 || c_3) { + t4$15 =
; + $[2] = a$10; + $[3] = b$11; + $[4] = t4$15; } else { - t5$15 = $[5]; + t4$15 = $[4]; } - return t5$15; + return t4$15; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md index 408ec8b06f..43813732c8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md @@ -374,15 +374,13 @@ bb1: function Component( props, ) { - scope @0 [1:7] deps=[read props$3.a, read props$3.b, read props$3.d, read props$3.c] out=[] { - [1] Const mutate a$4_@0[1:7] = Array [] - [2] Call mutate a$4_@0.push(read props$3.a) - if (read props$3.b) { - [6] Call mutate a$4_@0.push(read props$3.d) - return freeze a$4_@0 - } - [4] Call mutate a$4_@0.push(read props$3.c) + [1] Const mutate a$4_@0[1:7] = Array [] + [2] Call mutate a$4_@0.push(read props$3.a) + if (read props$3.b) { + [6] Call mutate a$4_@0.push(read props$3.d) + return freeze a$4_@0 } + [4] Call mutate a$4_@0.push(read props$3.c) } ``` @@ -391,27 +389,14 @@ function Component( ```javascript function Component$0(props$3) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== props$3.a; - const c_1 = $[1] !== props$3.b; - const c_2 = $[2] !== props$3.d; - const c_3 = $[3] !== props$3.c; - if (c_0 || c_1 || c_2 || c_3) { - const a$4 = []; - a$4.push(props$3.a); - - if (props$3.b) { - a$4.push(props$3.d); - return a$4; - } - - a$4.push(props$3.c); - $[0] = props$3.a; - $[1] = props$3.b; - $[2] = props$3.d; - $[3] = props$3.c; - } else { + const a$4 = []; + a$4.push(props$3.a); + if (props$3.b) { + a$4.push(props$3.d); + return a$4; } + + a$4.push(props$3.c); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md index 4584a93f7e..e4e1bb0b7a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md @@ -49,8 +49,8 @@ bb0: [5] Const mutate _$13_@1 = JSX [6] New mutate Foo$4(mutate b$11_@0:TObject) [7] Const mutate $14:TPrimitive = "div" - [8] Const mutate t5$15_@2 = JSX - [9] Return read t5$15_@2 + [8] Const mutate t4$15_@2 = JSX + [9] Return read t4$15_@2 ``` ## Reactive Scopes @@ -64,9 +64,7 @@ function Component( [2] Const mutate b$11_@0:TObject[1:7] = Object { } [3] New mutate Foo$4(mutate a$10_@0, mutate b$11_@0:TObject) [4] Const mutate $12:TPrimitive = "div" - scope @1 [5:6] deps=[freeze a$10_@0] out=[] { - [5] Const mutate _$13_@1 = JSX - } + [5] Const mutate _$13_@1 = JSX [6] New mutate Foo$4(mutate b$11_@0:TObject) } [7] Const mutate $14:TPrimitive = "div" @@ -85,18 +83,12 @@ function Component$0(props$9) { const $ = React.useMemoCache(); let a$10; let b$11; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$10 = []; b$11 = {}; new Foo$4(a$10, b$11); - const c_2 = $[2] !== a$10; - if (c_2) { - const _$13 =
; - - $[2] = a$10; - } else { - } + const _$13 =
; new Foo$4(b$11); $[0] = a$10; @@ -106,20 +98,20 @@ function Component$0(props$9) { b$11 = $[1]; } - const c_3 = $[3] !== a$10; - const c_4 = $[4] !== b$11; - let t5$15; + const c_2 = $[2] !== a$10; + const c_3 = $[3] !== b$11; + let t4$15; - if (c_3 || c_4) { - t5$15 =
; - $[3] = a$10; - $[4] = b$11; - $[5] = t5$15; + if (c_2 || c_3) { + t4$15 =
; + $[2] = a$10; + $[3] = b$11; + $[4] = t4$15; } else { - t5$15 = $[5]; + t4$15 = $[4]; } - return t5$15; + return t4$15; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md b/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md index 6a8fcd8bec..60a4daa58a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md @@ -57,14 +57,12 @@ function foo( } [3] Const mutate $9:TPrimitive = "div" [4] JSX {freeze x$8_@0} - scope @1 [5:12] deps=[read x$8_@0, read b$7] out=[] { - [5] Const mutate y$10_@1[5:12] = Array [] - if (read x$8_@0.length) { - [7] Call mutate y$10_@1.push(read x$8_@0) - } - if (read b$7) { - [10] Call mutate y$10_@1.push(read b$7) - } + [5] Const mutate y$10_@1[5:12] = Array [] + if (read x$8_@0.length) { + [7] Call mutate y$10_@1.push(read x$8_@0) + } + if (read b$7) { + [10] Call mutate y$10_@1.push(read b$7) } return } @@ -88,23 +86,14 @@ function foo$0(a$6, b$7) { }
{x$8}
; - const c_2 = $[2] !== x$8; - const c_3 = $[3] !== b$7; + const y$10 = []; - if (c_2 || c_3) { - const y$10 = []; + if (x$8.length) { + y$10.push(x$8); + } - if (x$8.length) { - y$10.push(x$8); - } - - if (b$7) { - y$10.push(b$7); - } - - $[2] = x$8; - $[3] = b$7; - } else { + if (b$7) { + y$10.push(b$7); } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md b/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md index 08bfa271c2..dc440be7e6 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md @@ -52,19 +52,17 @@ function foo( y, z, ) { - scope @0 [1:10] deps=[read z$8, read x$6, read y$7] out=[] { - [1] Const mutate items$9_@0[1:10] = Array [read z$8] - [2] Call mutate items$9_@0.push(read x$6) - scope @1 [3:7] deps=[read x$6, read y$7] out=[items2$10_@1] { - [3] Const mutate items2$10_@1[3:7] = Array [] - if (read x$6) { - [5] Call mutate items2$10_@1.push(read y$7) - } - } - if (read y$7) { - [8] Call mutate items$9_@0.push(read x$6) + [1] Const mutate items$9_@0[1:10] = Array [read z$8] + [2] Call mutate items$9_@0.push(read x$6) + scope @1 [3:7] deps=[read x$6, read y$7] out=[items2$10_@1] { + [3] Const mutate items2$10_@1[3:7] = Array [] + if (read x$6) { + [5] Call mutate items2$10_@1.push(read y$7) } } + if (read y$7) { + [8] Call mutate items$9_@0.push(read x$6) + } return freeze items2$10_@1 } @@ -75,38 +73,27 @@ function foo( ```javascript function foo$0(x$6, y$7, z$8) { const $ = React.useMemoCache(); - const c_0 = $[0] !== z$8; - const c_1 = $[1] !== x$6; - const c_2 = $[2] !== y$7; - if (c_0 || c_1 || c_2) { - const items$9 = [z$8]; - items$9.push(x$6); - const c_3 = $[3] !== x$6; - const c_4 = $[4] !== y$7; - let items2$10; + const items$9 = [z$8]; + items$9.push(x$6); + const c_0 = $[0] !== x$6; + const c_1 = $[1] !== y$7; + let items2$10; + if (c_0 || c_1) { + items2$10 = []; - if (c_3 || c_4) { - items2$10 = []; - - if (x$6) { - items2$10.push(y$7); - } - - $[3] = x$6; - $[4] = y$7; - $[5] = items2$10; - } else { - items2$10 = $[5]; + if (x$6) { + items2$10.push(y$7); } - if (y$7) { - items$9.push(x$6); - } - - $[0] = z$8; - $[1] = x$6; - $[2] = y$7; + $[0] = x$6; + $[1] = y$7; + $[2] = items2$10; } else { + items2$10 = $[2]; + } + + if (y$7) { + items$9.push(x$6); } return items2$10; diff --git a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md index c7f6eca50b..88247e997b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md @@ -56,14 +56,12 @@ function foo( b, c, ) { - scope @0 [1:8] deps=[read a$7, read b$8, read c$9] out=[] { - [1] Const mutate x$10_@0[1:8] = Array [] - if (read a$7) { - if (read b$8) { - if (read c$9) { - [5] Const mutate $11:TPrimitive = 0 - [6] Call mutate x$10_@0.push(read $11:TPrimitive) - } + [1] Const mutate x$10_@0[1:8] = Array [] + if (read a$7) { + if (read b$8) { + if (read c$9) { + [5] Const mutate $11:TPrimitive = 0 + [6] Call mutate x$10_@0.push(read $11:TPrimitive) } } } @@ -80,25 +78,13 @@ function foo( ```javascript function foo$0(a$7, b$8, c$9) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== a$7; - const c_1 = $[1] !== b$8; - const c_2 = $[2] !== c$9; - if (c_0 || c_1 || c_2) { - const x$10 = []; - - if (a$7) { - if (b$8) { - if (c$9) { - x$10.push(0); - } + const x$10 = []; + if (a$7) { + if (b$8) { + if (c$9) { + x$10.push(0); } } - - $[0] = a$7; - $[1] = b$8; - $[2] = c$9; - } else { } if (a$7.length) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md index 24358e3c87..59c100efcd 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md @@ -47,7 +47,7 @@ function Component( function Component$0() { const $ = React.useMemoCache(); let a$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$5 = []; $[0] = a$5; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md index a1b5b6913b..a8538c0731 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md @@ -109,7 +109,7 @@ function Component( function Component$0(props$10) { const $ = React.useMemoCache(); let x$11; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$11 = []; $[0] = x$11; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md index 7f823b29eb..e19cf748f1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md @@ -48,7 +48,7 @@ function Component( function Component$0() { const $ = React.useMemoCache(); let a$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$4 = []; $[0] = a$4; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md index acee1dbbae..668911db0e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md @@ -40,12 +40,10 @@ function foo( b, c, ) { - scope @0 [1:6] deps=[read a$5, read b$6, read c$7] out=[] { - [1] Const mutate y$8_@0[1:6] = Array [] - if (read a$5) { - if (read b$6) { - [4] Call mutate y$8_@0.push(read c$7) - } + [1] Const mutate y$8_@0[1:6] = Array [] + if (read a$5) { + if (read b$6) { + [4] Call mutate y$8_@0.push(read c$7) } } return @@ -57,23 +55,11 @@ function foo( ```javascript function foo$0(a$5, b$6, c$7) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== a$5; - const c_1 = $[1] !== b$6; - const c_2 = $[2] !== c$7; - if (c_0 || c_1 || c_2) { - const y$8 = []; - - if (a$5) { - if (b$6) { - y$8.push(c$7); - } + const y$8 = []; + if (a$5) { + if (b$6) { + y$8.push(c$7); } - - $[0] = a$5; - $[1] = b$6; - $[2] = c$7; - } else { } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md index 3adea1d4f9..f8b024c0ee 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md @@ -67,7 +67,7 @@ function Foo( function Foo$0(props$13) { const $ = React.useMemoCache(); let t0$20; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0$20 = <>Text; $[0] = t0$20; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md index 2a08c2b369..0c19c459ee 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md @@ -66,7 +66,7 @@ function And( function And$0() { const $ = React.useMemoCache(); let t0$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0$5 = f$1(); $[0] = t0$5; } else { @@ -142,7 +142,7 @@ function Or( function Or$0() { const $ = React.useMemoCache(); let t0$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0$5 = f$1(); $[0] = t0$5; } else { @@ -223,7 +223,7 @@ function QuestionQuestion( function QuestionQuestion$0(props$8) { const $ = React.useMemoCache(); let t0$9; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0$9 = f$2(); $[0] = t0$9; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md index 2ad5900810..6e53357704 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md @@ -139,37 +139,35 @@ bb13: function Component( props, ) { - scope @0 [1:23] deps=[] out=[] { - [1] Let mutate a$18_@0[1:23] = Object { } - [2] Let mutate b$20_@0[1:23] = Object { } - [3] Let mutate c$22_@0[1:23] = Object { } - [4] Let mutate d$24_@0[1:23] = Object { } - while ( - [6] Const mutate $17:TPrimitive = true - read $17:TPrimitive - ) { - [8] Const mutate z$19_@0[1:23] = read a$18_@0 - [9] Reassign mutate a$18_@0[1:23] = read b$20_@0 - [10] Reassign mutate b$20_@0[1:23] = read c$22_@0 - [11] Reassign mutate c$22_@0[1:23] = read d$24_@0 - [12] Reassign mutate d$24_@0[1:23] = read z$19_@0 - [13] Call mutate mutate$7:TFunction(mutate a$18_@0, mutate b$20_@0) - [14] Const mutate $29_@0[1:23] = Call mutate cond$8:TFunction(mutate a$18_@0) - if (read $29_@0) { - break - } + [1] Let mutate a$18_@0[1:23] = Object { } + [2] Let mutate b$20_@0[1:23] = Object { } + [3] Let mutate c$22_@0[1:23] = Object { } + [4] Let mutate d$24_@0[1:23] = Object { } + while ( + [6] Const mutate $17:TPrimitive = true + read $17:TPrimitive + ) { + [8] Const mutate z$19_@0[1:23] = read a$18_@0 + [9] Reassign mutate a$18_@0[1:23] = read b$20_@0 + [10] Reassign mutate b$20_@0[1:23] = read c$22_@0 + [11] Reassign mutate c$22_@0[1:23] = read d$24_@0 + [12] Reassign mutate d$24_@0[1:23] = read z$19_@0 + [13] Call mutate mutate$7:TFunction(mutate a$18_@0, mutate b$20_@0) + [14] Const mutate $29_@0[1:23] = Call mutate cond$8:TFunction(mutate a$18_@0) + if (read $29_@0) { + break } - if (read a$18_@0) { - } - if (read b$20_@0) { - } - if (read c$22_@0) { - } - if (read d$24_@0) { - } - [21] Const mutate $34:TPrimitive = null - [22] Call mutate mutate$7:TFunction(mutate d$24_@0, read $34:TPrimitive) } + if (read a$18_@0) { + } + if (read b$20_@0) { + } + if (read c$22_@0) { + } + if (read d$24_@0) { + } + [21] Const mutate $34:TPrimitive = null + [22] Call mutate mutate$7:TFunction(mutate d$24_@0, read $34:TPrimitive) return } @@ -179,39 +177,36 @@ function Component( ```javascript function Component$0(props$12) { - if (true) { - let a$18 = {}; - let b$20 = {}; - let c$22 = {}; - let d$24 = {}; - while (true) { - const z$19 = a$18; - a$18 = b$20; - b$20 = c$22; - c$22 = d$24; - d$24 = z$19; - mutate$7(a$18, b$20); + let a$18 = {}; + let b$20 = {}; + let c$22 = {}; + let d$24 = {}; + while (true) { + const z$19 = a$18; + a$18 = b$20; + b$20 = c$22; + c$22 = d$24; + d$24 = z$19; + mutate$7(a$18, b$20); - if (cond$8(a$18)) { - break; - } + if (cond$8(a$18)) { + break; } - - if (a$18) { - } - - if (b$20) { - } - - if (c$22) { - } - - if (d$24) { - } - - mutate$7(d$24, null); - } else { } + + if (a$18) { + } + + if (b$20) { + } + + if (c$22) { + } + + if (d$24) { + } + + mutate$7(d$24, null); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md index 11c5cb77f5..d5c3b4d32b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md @@ -100,28 +100,26 @@ function Component( scope @0 [1:2] deps=[] out=[a$11_@0] { [1] Const mutate a$11_@0:TObject = Object { } } - scope @1 [2:15] deps=[read a$11_@0:TObject] out=[] { - [2] Const mutate b$12_@1[2:15] = Array [read a$11_@0:TObject] - scope @2 [3:4] deps=[] out=[c$13_@2] { - [3] Const mutate c$13_@2:TObject = Object { } - } - [4] Const mutate d$14_@1:TObject[2:15] = Object { c: read c$13_@2:TObject } - [5] Const mutate x$15_@1:TObject[2:15] = Object { } - [6] Reassign mutate x$15_@1.b[2:15] = read b$12_@1 - [7] Const mutate y$16_@1[2:15] = Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, mutate d$14_@1:TObject) - if (read a$11_@0:TObject) { - } - if (read b$12_@1) { - } - if (read c$13_@2:TObject) { - } - if (read d$14_@1:TObject) { - } - if (read y$16_@1) { - } - [13] Const mutate $17:TPrimitive = null - [14] Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, read $17:TPrimitive) + [2] Const mutate b$12_@1[2:15] = Array [read a$11_@0:TObject] + scope @2 [3:4] deps=[] out=[c$13_@2] { + [3] Const mutate c$13_@2:TObject = Object { } } + [4] Const mutate d$14_@1:TObject[2:15] = Object { c: read c$13_@2:TObject } + [5] Const mutate x$15_@1:TObject[2:15] = Object { } + [6] Reassign mutate x$15_@1.b[2:15] = read b$12_@1 + [7] Const mutate y$16_@1[2:15] = Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, mutate d$14_@1:TObject) + if (read a$11_@0:TObject) { + } + if (read b$12_@1) { + } + if (read c$13_@2:TObject) { + } + if (read d$14_@1:TObject) { + } + if (read y$16_@1) { + } + [13] Const mutate $17:TPrimitive = null + [14] Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, read $17:TPrimitive) return } @@ -133,52 +131,46 @@ function Component( function Component$0(props$10) { const $ = React.useMemoCache(); let a$11; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$11 = {}; $[0] = a$11; } else { a$11 = $[0]; } - const c_1 = $[1] !== a$11; + const b$12 = [a$11]; + let c$13; - if (c_1) { - const b$12 = [a$11]; - let c$13; - - if (true) { - c$13 = {}; - $[2] = c$13; - } else { - c$13 = $[2]; - } - - const d$14 = { - c: c$13, - }; - const x$15 = {}; - x$15.b = b$12; - const y$16 = mutate$8(x$15, d$14); - - if (a$11) { - } - - if (b$12) { - } - - if (c$13) { - } - - if (d$14) { - } - - if (y$16) { - } - - mutate$8(x$15, null); - $[1] = a$11; + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { + c$13 = {}; + $[1] = c$13; } else { + c$13 = $[1]; } + + const d$14 = { + c: c$13, + }; + const x$15 = {}; + x$15.b = b$12; + const y$16 = mutate$8(x$15, d$14); + + if (a$11) { + } + + if (b$12) { + } + + if (c$13) { + } + + if (d$14) { + } + + if (y$16) { + } + + mutate$8(x$15, null); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md index faf7606a5b..5a5f15346c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md @@ -126,34 +126,32 @@ bb13: function Component( props, ) { - scope @0 [1:18] deps=[] out=[] { - [1] Const mutate a$12_@0:TObject[1:18] = Object { } - [2] Const mutate b$13_@0:TObject[1:18] = Object { } - scope @1 [3:4] deps=[] out=[c$14_@1] { - [3] Const mutate c$14_@1:TObject = Object { } - } - [4] Const mutate d$15_@0:TObject[1:18] = Object { } - while ( - [6] Const mutate $16:TPrimitive = true - read $16:TPrimitive - ) { - [8] Call mutate mutate$6:TFunction(mutate a$12_@0:TObject, mutate b$13_@0:TObject) - [9] Const mutate $21_@0[1:18] = Call mutate cond$7:TFunction(mutate a$12_@0:TObject) - if (read $21_@0) { - break - } - } - if (read a$12_@0:TObject) { - } - if (read b$13_@0:TObject) { - } - if (read c$14_@1:TObject) { - } - if (read d$15_@0:TObject) { - } - [16] Const mutate $28:TPrimitive = null - [17] Call mutate mutate$6:TFunction(mutate d$15_@0:TObject, read $28:TPrimitive) + [1] Const mutate a$12_@0:TObject[1:18] = Object { } + [2] Const mutate b$13_@0:TObject[1:18] = Object { } + scope @1 [3:4] deps=[] out=[c$14_@1] { + [3] Const mutate c$14_@1:TObject = Object { } } + [4] Const mutate d$15_@0:TObject[1:18] = Object { } + while ( + [6] Const mutate $16:TPrimitive = true + read $16:TPrimitive + ) { + [8] Call mutate mutate$6:TFunction(mutate a$12_@0:TObject, mutate b$13_@0:TObject) + [9] Const mutate $21_@0[1:18] = Call mutate cond$7:TFunction(mutate a$12_@0:TObject) + if (read $21_@0) { + break + } + } + if (read a$12_@0:TObject) { + } + if (read b$13_@0:TObject) { + } + if (read c$14_@1:TObject) { + } + if (read d$15_@0:TObject) { + } + [16] Const mutate $28:TPrimitive = null + [17] Call mutate mutate$6:TFunction(mutate d$15_@0:TObject, read $28:TPrimitive) return } @@ -164,43 +162,39 @@ function Component( ```javascript function Component$0(props$11) { const $ = React.useMemoCache(); - if (true) { - const a$12 = {}; - const b$13 = {}; - let c$14; - - if (true) { - c$14 = {}; - $[0] = c$14; - } else { - c$14 = $[0]; - } - - const d$15 = {}; - - while (true) { - mutate$6(a$12, b$13); - - if (cond$7(a$12)) { - break; - } - } - - if (a$12) { - } - - if (b$13) { - } - - if (c$14) { - } - - if (d$15) { - } - - mutate$6(d$15, null); + const a$12 = {}; + const b$13 = {}; + let c$14; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + c$14 = {}; + $[0] = c$14; } else { + c$14 = $[0]; } + + const d$15 = {}; + + while (true) { + mutate$6(a$12, b$13); + + if (cond$7(a$12)) { + break; + } + } + + if (a$12) { + } + + if (b$13) { + } + + if (c$14) { + } + + if (d$15) { + } + + mutate$6(d$15, null); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md index 0b8e7cc94f..17c229a6ad 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md @@ -37,14 +37,12 @@ function foo( b, c, ) { - scope @0 [1:6] deps=[read a$6, read b$7] out=[] { - [1] Const mutate x$9_@0[1:6] = Array [] - [2] Const mutate y$10_@0[1:6] = Array [] - if (read x$9_@0) { - } - [4] Call mutate y$10_@0.push(read a$6) - [5] Call mutate x$9_@0.push(read b$7) + [1] Const mutate x$9_@0[1:6] = Array [] + [2] Const mutate y$10_@0[1:6] = Array [] + if (read x$9_@0) { } + [4] Call mutate y$10_@0.push(read a$6) + [5] Call mutate x$9_@0.push(read b$7) return } @@ -54,22 +52,13 @@ function foo( ```javascript function foo$0(a$6, b$7, c$8) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== a$6; - const c_1 = $[1] !== b$7; - if (c_0 || c_1) { - const x$9 = []; - const y$10 = []; - - if (x$9) { - } - - y$10.push(a$6); - x$9.push(b$7); - $[0] = a$6; - $[1] = b$7; - } else { + const x$9 = []; + const y$10 = []; + if (x$9) { } + + y$10.push(a$6); + x$9.push(b$7); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md index 036f6504cd..5d7e91787f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md @@ -29,12 +29,10 @@ function foo( a, b, ) { - scope @0 [1:5] deps=[read a$5, read b$6] out=[] { - [1] Const mutate x$7_@0[1:5] = Array [] - [2] Const mutate y$8_@0[1:5] = Array [] - [3] Call mutate x$7_@0.push(read a$5) - [4] Call mutate y$8_@0.push(read b$6) - } + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@0[1:5] = Array [] + [3] Call mutate x$7_@0.push(read a$5) + [4] Call mutate y$8_@0.push(read b$6) return } @@ -44,18 +42,10 @@ function foo( ```javascript function foo$0(a$5, b$6) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== a$5; - const c_1 = $[1] !== b$6; - if (c_0 || c_1) { - const x$7 = []; - const y$8 = []; - x$7.push(a$5); - y$8.push(b$6); - $[0] = a$5; - $[1] = b$6; - } else { - } + const x$7 = []; + const y$8 = []; + x$7.push(a$5); + y$8.push(b$6); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md index 9964de234d..e81d70c5ed 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md @@ -29,14 +29,10 @@ function foo( a, b, ) { - scope @0 [1:5] deps=[read b$6, read a$5] out=[] { - [1] Const mutate x$7_@0[1:5] = Array [] - scope @1 [2:4] deps=[read b$6] out=[] { - [2] Const mutate y$8_@1[2:4] = Array [] - [3] Call mutate y$8_@1.push(read b$6) - } - [4] Call mutate x$7_@0.push(read a$5) - } + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@1[2:4] = Array [] + [3] Call mutate y$8_@1.push(read b$6) + [4] Call mutate x$7_@0.push(read a$5) return } @@ -46,25 +42,10 @@ function foo( ```javascript function foo$0(a$5, b$6) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== b$6; - const c_1 = $[1] !== a$5; - if (c_0 || c_1) { - const x$7 = []; - const c_2 = $[2] !== b$6; - - if (c_2) { - const y$8 = []; - y$8.push(b$6); - $[2] = b$6; - } else { - } - - x$7.push(a$5); - $[0] = b$6; - $[1] = a$5; - } else { - } + const x$7 = []; + const y$8 = []; + y$8.push(b$6); + x$7.push(a$5); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md index 223fe2b9b1..d69d9df00c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md @@ -41,15 +41,13 @@ function foo( b, c, ) { - scope @0 [1:8] deps=[read c$8, read b$7, read a$6] out=[] { - [1] Const mutate x$9_@0[1:8] = Array [] - [2] Const mutate y$10_@0[1:8] = Array [] - while ( - read c$8 - ) { - [5] Call mutate y$10_@0.push(read b$7) - [6] Call mutate x$9_@0.push(read a$6) - } + [1] Const mutate x$9_@0[1:8] = Array [] + [2] Const mutate y$10_@0[1:8] = Array [] + while ( + read c$8 + ) { + [5] Call mutate y$10_@0.push(read b$7) + [6] Call mutate x$9_@0.push(read a$6) } return } @@ -60,23 +58,11 @@ function foo( ```javascript function foo$0(a$6, b$7, c$8) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== c$8; - const c_1 = $[1] !== b$7; - const c_2 = $[2] !== a$6; - if (c_0 || c_1 || c_2) { - const x$9 = []; - const y$10 = []; - - while (c$8) { - y$10.push(b$7); - x$9.push(a$6); - } - - $[0] = c$8; - $[1] = b$7; - $[2] = a$6; - } else { + const x$9 = []; + const y$10 = []; + while (c$8) { + y$10.push(b$7); + x$9.push(a$6); } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md index 0836998d40..5e8e225b2c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md @@ -51,11 +51,11 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$4 = {}; let y$5; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { y$5 = []; const z$6 = {}; y$5.push(z$6); diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md index 65bf827851..226453889a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md @@ -35,8 +35,8 @@ bb1: predecessor blocks: bb2 bb0 [7] Const mutate _$12_@1 = JSX [8] Call read y$8.push(read props$6.p2) - [9] Const mutate t6$15_@2 = JSX - [10] Return read t6$15_@2 + [9] Const mutate t5$15_@2 = JSX + [10] Return read t5$15_@2 ``` ## Reactive Scopes @@ -53,9 +53,7 @@ function Component( [5] Reassign mutate x$7_@0[1:7] = Array [] } } - scope @1 [7:8] deps=[freeze x$7_@0] out=[] { - [7] Const mutate _$12_@1 = JSX - } + [7] Const mutate _$12_@1 = JSX [8] Call read y$8.push(read props$6.p2) scope @2 [9:10] deps=[read x$7_@0, read y$8] out=[$15_@2] { [9] Const mutate $15_@2 = JSX @@ -89,30 +87,23 @@ function Component$0(props$6) { x$7 = $[2]; } - const c_3 = $[3] !== x$7; - - if (c_3) { - const _$12 = ; - - $[3] = x$7; - } else { - } + const _$12 = ; y$8.push(props$6.p2); - const c_4 = $[4] !== x$7; - const c_5 = $[5] !== y$8; - let t6$15; + const c_3 = $[3] !== x$7; + const c_4 = $[4] !== y$8; + let t5$15; - if (c_4 || c_5) { - t6$15 = ; - $[4] = x$7; - $[5] = y$8; - $[6] = t6$15; + if (c_3 || c_4) { + t5$15 = ; + $[3] = x$7; + $[4] = y$8; + $[5] = t5$15; } else { - t6$15 = $[6]; + t5$15 = $[5]; } - return t6$15; + return t5$15; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md index 2ee1e0947c..d57c004ec9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md @@ -27,8 +27,8 @@ bb0: [4] Const mutate x$9_@1 = Array [] [5] Const mutate _$10_@2 = JSX [6] Call mutate y$8_@0.push(read props$6.p1) - [7] Const mutate t7$11_@3 = JSX - [8] Return read t7$11_@3 + [7] Const mutate t6$11_@3 = JSX + [8] Return read t6$11_@3 ``` ## Reactive Scopes @@ -44,9 +44,7 @@ function Component( scope @1 [4:5] deps=[] out=[x$9_@1] { [4] Const mutate x$9_@1 = Array [] } - scope @2 [5:6] deps=[freeze x$9_@1] out=[] { - [5] Const mutate _$10_@2 = JSX - } + [5] Const mutate _$10_@2 = JSX [6] Call mutate y$8_@0.push(read props$6.p1) } scope @3 [7:8] deps=[read x$9_@1, freeze y$8_@0] out=[$11_@3] { @@ -71,21 +69,14 @@ function Component$0(props$6) { y$8 = x$7; let x$9; - if (true) { + if ($[3] === Symbol.for("react.memo_cache_sentinel")) { x$9 = []; $[3] = x$9; } else { x$9 = $[3]; } - const c_4 = $[4] !== x$9; - - if (c_4) { - const _$10 = ; - - $[4] = x$9; - } else { - } + const _$10 = ; y$8.push(props$6.p1); $[0] = props$6.p0; @@ -95,20 +86,20 @@ function Component$0(props$6) { y$8 = $[2]; } - const c_5 = $[5] !== x$9; - const c_6 = $[6] !== y$8; - let t7$11; + const c_4 = $[4] !== x$9; + const c_5 = $[5] !== y$8; + let t6$11; - if (c_5 || c_6) { - t7$11 = ; - $[5] = x$9; - $[6] = y$8; - $[7] = t7$11; + if (c_4 || c_5) { + t6$11 = ; + $[4] = x$9; + $[5] = y$8; + $[6] = t6$11; } else { - t7$11 = $[7]; + t6$11 = $[6]; } - return t7$11; + return t6$11; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md index 29c4e6cc4f..ed88bc2df3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md @@ -58,9 +58,7 @@ bb0: ``` function foo( ) { - scope @0 [1:2] deps=[] out=[] { - [1] Const mutate a$5_@0:TObject = Object { } - } + [1] Const mutate a$5_@0:TObject = Object { } scope @1 [2:8] deps=[] out=[c$10_@1] { [2] Const mutate b$6_@1:TObject[2:8] = Object { } [3] Const mutate c$7_@1:TObject[2:8] = Object { } @@ -79,14 +77,9 @@ function foo( ```javascript function foo$0() { const $ = React.useMemoCache(); - if (true) { - const a$5 = {}; - } else { - } - + const a$5 = {}; let c$10; - - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const b$6 = {}; const c$7 = {}; const a$8 = b$6; diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md index 40c4671785..a319cf386f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md @@ -75,7 +75,7 @@ function foo$0(x$8, y$9) { let t2$14; - if (true) { + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { t2$14 = [y$9 * 10]; $[2] = t2$14; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md index 2087fab9df..737e69e017 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md @@ -45,7 +45,7 @@ function Component$0(props$5) { const a$6 = 1; const b$7 = 2; let x$8; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$8 = [a$6, b$7]; $[0] = x$8; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md index bc29bd4296..dc0a28821c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md @@ -59,8 +59,8 @@ bb1: predecessor blocks: bb2 bb0 [9] Call mutate foo$4:TFunction(read a$11_@0, mutate b$12_@0:TObject) [10] Const mutate $19:TPrimitive = "div" - [11] Const mutate t6$20_@3 = JSX - [12] Return read t6$20_@3 + [11] Const mutate t5$20_@3 = JSX + [12] Return read t5$20_@3 ``` ## Reactive Scopes @@ -78,9 +78,7 @@ function Component( } if (read $13_@1) { [6] Const mutate $14:TPrimitive = "div" - scope @2 [7:8] deps=[freeze a$11_@0] out=[] { - [7] Const mutate _$15_@2 = JSX - } + [7] Const mutate _$15_@2 = JSX } [9] Call mutate foo$4:TFunction(read a$11_@0, mutate b$12_@0:TObject) } @@ -100,13 +98,13 @@ function Component$0(props$10) { const $ = React.useMemoCache(); let a$11; let b$12; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$11 = []; b$12 = {}; foo$4(a$11, b$12); let t2$13; - if (true) { + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { t2$13 = foo$4(); $[2] = t2$13; } else { @@ -114,14 +112,7 @@ function Component$0(props$10) { } if (t2$13) { - const c_3 = $[3] !== a$11; - - if (c_3) { - const _$15 =
; - - $[3] = a$11; - } else { - } + const _$15 =
; } foo$4(a$11, b$12); @@ -132,20 +123,20 @@ function Component$0(props$10) { b$12 = $[1]; } - const c_4 = $[4] !== a$11; - const c_5 = $[5] !== b$12; - let t6$20; + const c_3 = $[3] !== a$11; + const c_4 = $[4] !== b$12; + let t5$20; - if (c_4 || c_5) { - t6$20 =
; - $[4] = a$11; - $[5] = b$12; - $[6] = t6$20; + if (c_3 || c_4) { + t5$20 =
; + $[3] = a$11; + $[4] = b$12; + $[5] = t5$20; } else { - t6$20 = $[6]; + t5$20 = $[5]; } - return t6$20; + return t5$20; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md index ecaa45017c..00a9e96439 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md @@ -49,8 +49,8 @@ bb0: [5] Const mutate _$13_@1 = JSX [6] Call mutate foo$4:TFunction(read a$10_@0, mutate b$11_@0:TObject) [7] Const mutate $14:TPrimitive = "div" - [8] Const mutate t5$15_@2 = JSX - [9] Return read t5$15_@2 + [8] Const mutate t4$15_@2 = JSX + [9] Return read t4$15_@2 ``` ## Reactive Scopes @@ -64,9 +64,7 @@ function Component( [2] Const mutate b$11_@0:TObject[1:7] = Object { } [3] Call mutate foo$4:TFunction(mutate a$10_@0, mutate b$11_@0:TObject) [4] Const mutate $12:TPrimitive = "div" - scope @1 [5:6] deps=[freeze a$10_@0] out=[] { - [5] Const mutate _$13_@1 = JSX - } + [5] Const mutate _$13_@1 = JSX [6] Call mutate foo$4:TFunction(read a$10_@0, mutate b$11_@0:TObject) } [7] Const mutate $14:TPrimitive = "div" @@ -85,18 +83,12 @@ function Component$0(props$9) { const $ = React.useMemoCache(); let a$10; let b$11; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$10 = []; b$11 = {}; foo$4(a$10, b$11); - const c_2 = $[2] !== a$10; - if (c_2) { - const _$13 =
; - - $[2] = a$10; - } else { - } + const _$13 =
; foo$4(a$10, b$11); $[0] = a$10; @@ -106,20 +98,20 @@ function Component$0(props$9) { b$11 = $[1]; } - const c_3 = $[3] !== a$10; - const c_4 = $[4] !== b$11; - let t5$15; + const c_2 = $[2] !== a$10; + const c_3 = $[3] !== b$11; + let t4$15; - if (c_3 || c_4) { - t5$15 =
; - $[3] = a$10; - $[4] = b$11; - $[5] = t5$15; + if (c_2 || c_3) { + t4$15 =
; + $[2] = a$10; + $[3] = b$11; + $[4] = t4$15; } else { - t5$15 = $[5]; + t4$15 = $[4]; } - return t5$15; + return t4$15; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md index 96dd669d3b..2840d13e17 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md @@ -76,7 +76,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$7 = 1; const y$8 = 2; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md index 0112c87c2e..6f1ef97d26 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md @@ -59,7 +59,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$5 = 1; const y$6 = 2; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md index 723714b463..212d9c28a5 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md @@ -46,9 +46,7 @@ bb2: function foo( cond, ) { - scope @0 [1:2] deps=[] out=[] { - [1] Const mutate items$5_@0 = Array [] - } + [1] Const mutate items$5_@0 = Array [] } ``` @@ -57,10 +55,7 @@ function foo( ```javascript function foo$0(cond$4) { - if (true) { - const items$5 = []; - } else { - } + const items$5 = []; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md index 296d569752..5b0f7ea58d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md @@ -72,7 +72,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$6; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$6 = 1; for (const i$7 = 0; i$7 < 10; i$7) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md index 6455540177..f33849d38d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md @@ -76,7 +76,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$7 = 1; for (let i$8 = 0; i$8 < 10; i$8 = i$8 + 1, i$8) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md index 9f61e81e71..5831eb1b1d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md @@ -44,14 +44,12 @@ function foo( b, c, ) { - scope @0 [1:8] deps=[read a$5, read b$6, read c$7] out=[] { - [1] Const mutate x$8_@0[1:8] = read a$5 - if (read b$6) { - if (read c$7) { - [4] Reassign mutate x$8_@0[1:8] = read c$7 - } - [6] read x$8_@0 + [1] Const mutate x$8_@0[1:8] = read a$5 + if (read b$6) { + if (read c$7) { + [4] Reassign mutate x$8_@0[1:8] = read c$7 } + [6] read x$8_@0 } return } @@ -62,25 +60,13 @@ function foo( ```javascript function foo$0(a$5, b$6, c$7) { - const $ = React.useMemoCache(); - const c_0 = $[0] !== a$5; - const c_1 = $[1] !== b$6; - const c_2 = $[2] !== c$7; - if (c_0 || c_1 || c_2) { - const x$8 = a$5; - - if (b$6) { - if (c$7) { - x$8 = c$7; - } - - x$8; + const x$8 = a$5; + if (b$6) { + if (c$7) { + x$8 = c$7; } - $[0] = a$5; - $[1] = b$6; - $[2] = c$7; - } else { + x$8; } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md index 6d86df9188..8fc9c80d62 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md @@ -68,7 +68,7 @@ function Component( function Component$0(props$6) { const $ = React.useMemoCache(); let c$9; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a$7 = []; const b$8 = {}; c$9 = new Foo$5(a$7, b$8); diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md index 28b34ee5e4..4f9d05e8e8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md @@ -71,7 +71,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$6; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$6 = 1; let y$7 = 2; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md index 6a8a976f3a..c1d66e099d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md @@ -45,7 +45,7 @@ function Component$0(props$5) { const a$6 = 1; const b$7 = 2; let x$8; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$8 = { a: a$6, b: b$7, diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md index fff573da00..91677488f9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md @@ -75,7 +75,7 @@ function foo$0(a$5) { if (a$5) { let y$7; - if (true) { + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { y$7 = {}; $[2] = y$7; } else { @@ -86,7 +86,7 @@ function foo$0(a$5) { } else { let z$8; - if (true) { + if ($[3] === Symbol.for("react.memo_cache_sentinel")) { z$8 = {}; $[3] = z$8; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md index a12459b363..f47e963968 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md @@ -80,7 +80,7 @@ function foo$0(a$6) { } else { let z$9; - if (true) { + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { z$9 = {}; $[2] = z$9; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md index ee9d1062e3..b178687f5f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md @@ -50,7 +50,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let y$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a$5 = {}; const x$6 = a$5; y$7 = {}; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md index c735c95d29..3c542a9fec 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md @@ -46,7 +46,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$4 = []; $[0] = x$4; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md index a3076dc2c2..4b80c3bdd3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md @@ -45,7 +45,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let y$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x$4 = []; y$5 = {}; y$5.x = x$4; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md index ae2b61e49a..caf3562f38 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md @@ -50,7 +50,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let y$6; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a$5 = {}; y$6 = a$5; const x$7 = []; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md index 43c242a1bf..4495bced5a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md @@ -45,7 +45,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let y$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x$4 = []; y$5 = {}; y$5.x = x$4; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md index f3c7564413..7cd141438a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md @@ -44,7 +44,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$3; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$3 = []; $[0] = x$3; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md index b051310aef..22edeb277e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md @@ -54,7 +54,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$4 = 1; if (x$4 === 1) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md index 4f3648a606..70a20404e0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md @@ -68,7 +68,7 @@ function foo$0() { const $ = React.useMemoCache(); const y$5 = 2; let y$8; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { y$8 = undefined; if (y$5 > 1) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md index e7fbc0e184..16ad0a7c29 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md @@ -102,7 +102,7 @@ function foo$0() { const $ = React.useMemoCache(); const x$10 = 1; let x$16; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$16 = undefined; bb1: switch (x$10) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md index 74daa3b3b4..298fd2c7c1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md @@ -53,7 +53,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$4 = 1; if (x$4 === 1) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md index 7ca584a42b..64f04e3ee5 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md @@ -61,7 +61,7 @@ function foo( function foo$0() { const $ = React.useMemoCache(); let x$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$5 = 1; while (x$5 < 10) { diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md index f48373744c..6a516076f7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md @@ -69,9 +69,7 @@ function Component( case read $12:TPrimitive: { [6] Call mutate x$9_@1.push(read props$8.p2) [7] Call mutate x$9_@1.push(read props$8.p3) - scope @2 [8:9] deps=[] out=[] { - [8] Const mutate y$13_@2 = Array [] - } + [8] Const mutate y$13_@2 = Array [] } case read $11:TPrimitive: { [10] Reassign mutate y$10_@1:TPrimitive[1:12] = read x$9_@1 @@ -107,11 +105,7 @@ function Component$0(props$8) { case true: { x$9.push(props$8.p2); x$9.push(props$8.p3); - - if (true) { - const y$13 = []; - } else { - } + const y$13 = []; } case false: { diff --git a/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md b/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md index 0778a152a9..d82370f934 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md @@ -37,16 +37,14 @@ bb0: ``` function component( ) { - scope @0 [1:9] deps=[] out=[] { - [1] Const mutate x$6_@0:TObject[1:9] = Object { } - [2] Const mutate p$7_@0:TObject[1:9] = Object { } - [3] Const mutate q$8_@0:TObject[1:9] = Object { } - [4] Const mutate y$9_@0:TObject[1:9] = Object { } - [5] Reassign mutate x$6_@0.y[1:9] = read y$9_@0:TObject - [6] Reassign mutate p$7_@0.y[1:9] = read x$6_@0.y - [7] Reassign mutate q$8_@0.y[1:9] = read p$7_@0.y - [8] Call mutate mutate$5:TFunction(mutate q$8_@0:TObject) - } + [1] Const mutate x$6_@0:TObject[1:9] = Object { } + [2] Const mutate p$7_@0:TObject[1:9] = Object { } + [3] Const mutate q$8_@0:TObject[1:9] = Object { } + [4] Const mutate y$9_@0:TObject[1:9] = Object { } + [5] Reassign mutate x$6_@0.y[1:9] = read y$9_@0:TObject + [6] Reassign mutate p$7_@0.y[1:9] = read x$6_@0.y + [7] Reassign mutate q$8_@0.y[1:9] = read p$7_@0.y + [8] Call mutate mutate$5:TFunction(mutate q$8_@0:TObject) return } @@ -56,17 +54,14 @@ function component( ```javascript function component$0() { - if (true) { - const x$6 = {}; - const p$7 = {}; - const q$8 = {}; - const y$9 = {}; - x$6.y = y$9; - p$7.y = x$6.y; - q$8.y = p$7.y; - mutate$5(q$8); - } else { - } + const x$6 = {}; + const p$7 = {}; + const q$8 = {}; + const y$9 = {}; + x$6.y = y$9; + p$7.y = x$6.y; + q$8.y = p$7.y; + mutate$5(q$8); } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md index 12c1195d6c..5828952e8c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md @@ -34,9 +34,7 @@ function component( ) { [1] Const mutate $7:TPrimitive = Binary read a$5:TPrimitive > read b$6:TPrimitive if (read $7:TPrimitive) { - scope @0 [3:4] deps=[] out=[] { - [3] Const mutate m$8_@0:TObject = Object { } - } + [3] Const mutate m$8_@0:TObject = Object { } } return } @@ -48,10 +46,7 @@ function component( ```javascript function component$0(a$5, b$6) { if (a$5 > b$6) { - if (true) { - const m$8 = {}; - } else { - } + const m$8 = {}; } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md index b7cdd51d5e..e209113e31 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md @@ -42,9 +42,7 @@ function component( } [3] Const mutate $9:TPrimitive = Binary read a$7_@0:TPrimitive > read b$8_@1:TPrimitive if (read $9:TPrimitive) { - scope @2 [5:6] deps=[] out=[] { - [5] Const mutate m$10_@2:TObject = Object { } - } + [5] Const mutate m$10_@2:TObject = Object { } } return } @@ -57,7 +55,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let a$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { a$7 = some$2(); $[0] = a$7; } else { @@ -66,7 +64,7 @@ function component$0() { let b$8; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { b$8 = someOther$4(); $[1] = b$8; } else { @@ -74,10 +72,7 @@ function component$0() { } if (a$7 > b$8) { - if (true) { - const m$10 = {}; - } else { - } + const m$10 = {}; } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md index 297abfb7f5..0f06c4868f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md @@ -40,7 +40,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let x$5; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$5 = { t: 1, }; diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md index 2ddc19a314..e3d43d61e9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md @@ -65,7 +65,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let t0$10; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0$10 = makeSomePrimitive$2(); $[0] = t0$10; } else { @@ -74,7 +74,7 @@ function component$0() { let t1$11; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { t1$11 = makeSomePrimitive$2(); $[1] = t1$11; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md index 828dec3456..3d95311bd0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md @@ -46,11 +46,11 @@ function component( function component$0() { const $ = React.useMemoCache(); let x$4; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$4 = {}; let q$5; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { q$5 = {}; $[1] = q$5; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md index 0a3718cd4d..52fcdd7014 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md @@ -63,7 +63,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let p$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { p$7 = makePrimitive$2(); $[0] = p$7; } else { @@ -73,7 +73,7 @@ function component$0() { p$7 + p$7; let o$8; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { o$8 = {}; $[1] = o$8; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md index 54b928b15e..6a65fc3b1d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md @@ -45,13 +45,9 @@ function component( } [3] Const mutate $9:TPrimitive = Binary read x$7_@0:TPrimitive > read y$8_@1:TPrimitive if (read $9:TPrimitive) { - scope @2 [5:6] deps=[] out=[] { - [5] Const mutate z$10_@2:TObject = Object { } - } - } - scope @3 [7:8] deps=[] out=[] { - [7] Const mutate z$12_@3 = Call mutate foo$2:TFunction() + [5] Const mutate z$10_@2:TObject = Object { } } + [7] Const mutate z$12_@3 = Call mutate foo$2:TFunction() return } @@ -63,7 +59,7 @@ function component( function component$0() { const $ = React.useMemoCache(); let x$7; - if (true) { + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$7 = foo$2(); $[0] = x$7; } else { @@ -72,7 +68,7 @@ function component$0() { let y$8; - if (true) { + if ($[1] === Symbol.for("react.memo_cache_sentinel")) { y$8 = foo$2(); $[1] = y$8; } else { @@ -80,16 +76,10 @@ function component$0() { } if (x$7 > y$8) { - if (true) { - const z$10 = {}; - } else { - } + const z$10 = {}; } - if (true) { - const z$12 = foo$2(); - } else { - } + const z$12 = foo$2(); } ```