@samitouri / QOS-React-2 / commits / cedaee5b03

Codegen for scopes without dependencies

Completes a todo for the `if` condition of scopes without any inputs. In this case since there are no inputs we can check for changes, we check if the first _output_ cache slot is set to the sentinel. For this to work we need to ensure that all scopes have at least one output, which isn't currently the case. Dead code can produce output-less sentinels. So this PR also adds a pass to find scopes w/o any outputs and convert them to regular blocks. We could in theory also just delete them, but for now let's be more conservative. This is something we'd want to highlight as a diagnostic in an IDE, though existing dead code linters would almost certainly find this case too.

Joe Savona committed Dec 20, 2022 at 11:06 UTC cedaee5b03e94ee5f41f3683dd61d8e917fe29a2
67 files changed +598 -742
compiler/forget/src/CompilerPipeline.ts
+2
@@ -23,6 +23,7 @@ import {
23 printReactiveFunction,
24 propagateScopeDependencies,
25 pruneUnusedLabels,
26 + pruneUnusedScopes,
27 } from "./ReactiveScopes";
28 import { eliminateRedundantPhi, enterSSA, leaveSSA } from "./SSA";
29 import { logHIRFunction } from "./Utils/logger";
@@ -69,6 +70,7 @@ export default function (
70 pruneUnusedLabels(reactiveFunction);
71 flattenReactiveLoops(reactiveFunction);
72 propagateScopeDependencies(reactiveFunction);
73 + pruneUnusedScopes(reactiveFunction);
74 const scopes = printReactiveFunction(reactiveFunction);
75 const ast = codegenReactiveFunction(reactiveFunction);
76
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+32 -10
@@ -166,8 +166,12 @@ function codegenReactiveScope(
166 )
167 );
168 }
169 + let firstOutputIndex: number | null = null;
170 for (const output of scope.outputs) {
171 const index = cx.nextCacheIndex;
172 + if (firstOutputIndex === null) {
173 + firstOutputIndex = index;
174 + }
175
176 // TODO @josephsavona: ensure change and temp variables have non-conflicting names
177 output.name ??= `t${index}`;
@@ -194,16 +198,34 @@ function codegenReactiveScope(
198 )
199 );
200 }
197 - const testCondition =
198 - (changeIdentifiers as Array<t.Expression>).reduce(
199 - (acc: t.Expression | null, ident: t.Expression) => {
200 - if (acc == null) {
201 - return ident;
202 - }
203 - return t.logicalExpression("||", acc, ident);
204 - },
205 - null as t.Expression | null
206 - ) ?? t.booleanLiteral(true); // TODO @josephsavona handle case of empty dependencies
201 + invariant(
202 + firstOutputIndex !== null,
203 + "Expected scope '@%s' to have at least one output",
204 + scope.id
205 + );
206 + let testCondition = (changeIdentifiers as Array<t.Expression>).reduce(
207 + (acc: t.Expression | null, ident: t.Expression) => {
208 + if (acc == null) {
209 + return ident;
210 + }
211 + return t.logicalExpression("||", acc, ident);
212 + },
213 + null as t.Expression | null
214 + );
215 + if (testCondition === null) {
216 + testCondition = t.binaryExpression(
217 + "===",
218 + t.memberExpression(
219 + t.identifier("$"),
220 + t.numericLiteral(firstOutputIndex),
221 + true
222 + ),
223 + t.callExpression(
224 + t.memberExpression(t.identifier("Symbol"), t.identifier("for")),
225 + [t.stringLiteral("react.memo_cache_sentinel")]
226 + )
227 + );
228 + }
229
230 const computationBlock = codegenBlock(cx, block);
231 computationBlock.body.push(...cacheStoreStatements);
compiler/forget/src/ReactiveScopes/PruneUnusedScopes.ts new
+52
@@ -0,0 +1,52 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + */
7 +
8 +import { ReactiveBlock, ReactiveFunction } from "../HIR/HIR";
9 +import { assertExhaustive } from "../Utils/utils";
10 +import { mapTerminalBlocks } from "./visitors";
11 +
12 +/**
13 + * Converts scopes without outputs into regular blocks.
14 + */
15 +export function pruneUnusedScopes(fn: ReactiveFunction): void {
16 + fn.body = visitBlock(fn.body);
17 +}
18 +
19 +function visitBlock(block: ReactiveBlock): ReactiveBlock {
20 + let nextBlock: ReactiveBlock | null = null;
21 + for (let i = 0; i < block.length; i++) {
22 + const stmt = block[i]!;
23 + switch (stmt.kind) {
24 + case "terminal": {
25 + mapTerminalBlocks(stmt.terminal, visitBlock);
26 + break;
27 + }
28 + case "instruction": {
29 + break;
30 + }
31 + case "scope": {
32 + stmt.instructions = visitBlock(stmt.instructions);
33 + if (stmt.scope.outputs.size === 0) {
34 + nextBlock ??= block.slice(0, i);
35 + nextBlock.push(...stmt.instructions);
36 + continue;
37 + }
38 + break;
39 + }
40 + default: {
41 + assertExhaustive(
42 + stmt,
43 + `Unexpected statement kind '${(stmt as any).kind}'`
44 + );
45 + }
46 + }
47 + if (nextBlock !== null) {
48 + nextBlock.push(stmt);
49 + }
50 + }
51 + return nextBlock ?? block;
52 +}
compiler/forget/src/ReactiveScopes/index.ts
+1
@@ -13,3 +13,4 @@ export { inferReactiveScopeVariables } from "./InferReactiveScopeVariables";
13 export { printReactiveFunction } from "./PrintReactiveFunction";
14 export { propagateScopeDependencies } from "./PropagateScopeDependencies";
15 export { pruneUnusedLabels } from "./PruneUnusedLabels";
16 +export { pruneUnusedScopes } from "./PruneUnusedScopes";
compiler/forget/src/ReactiveScopes/visitors.ts new
+52
@@ -0,0 +1,52 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + */
7 +
8 +import { ReactiveBlock, ReactiveTerminal } from "../HIR/HIR";
9 +import { assertExhaustive } from "../Utils/utils";
10 +
11 +export function mapTerminalBlocks(
12 + terminal: ReactiveTerminal,
13 + fn: (block: ReactiveBlock) => ReactiveBlock
14 +): void {
15 + switch (terminal.kind) {
16 + case "break":
17 + case "continue":
18 + case "return":
19 + case "throw": {
20 + break;
21 + }
22 + case "for": {
23 + terminal.loop = fn(terminal.loop);
24 + break;
25 + }
26 + case "while": {
27 + terminal.loop = fn(terminal.loop);
28 + break;
29 + }
30 + case "if": {
31 + terminal.consequent = fn(terminal.consequent);
32 + if (terminal.alternate !== null) {
33 + terminal.alternate = fn(terminal.alternate);
34 + }
35 + break;
36 + }
37 + case "switch": {
38 + for (const case_ of terminal.cases) {
39 + if (case_.block !== undefined) {
40 + case_.block = fn(case_.block);
41 + }
42 + }
43 + break;
44 + }
45 + default: {
46 + assertExhaustive(
47 + terminal,
48 + `Unexpected terminal kind '${(terminal as any).kind}'`
49 + );
50 + }
51 + }
52 +}
compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md
+13 -28
@@ -43,15 +43,13 @@ bb1:
43 function Component(
44 props,
45 ) {
46 - scope @0 [1:7] deps=[read props$3.a, read props$3.b, read props$3.d, read props$3.c] out=[] {
47 - [1] Const mutate a$4_@0[1:7] = Array []
48 - [2] Call mutate a$4_@0.push(read props$3.a)
49 - if (read props$3.b) {
50 - [6] Call mutate a$4_@0.push(read props$3.d)
51 - return freeze a$4_@0
52 - }
53 - [4] Call mutate a$4_@0.push(read props$3.c)
46 + [1] Const mutate a$4_@0[1:7] = Array []
47 + [2] Call mutate a$4_@0.push(read props$3.a)
48 + if (read props$3.b) {
49 + [6] Call mutate a$4_@0.push(read props$3.d)
50 + return freeze a$4_@0
51 }
52 + [4] Call mutate a$4_@0.push(read props$3.c)
53 }
54
55 ```
@@ -60,27 +58,14 @@ function Component(
58
59 ```javascript
60 function Component$0(props$3) {
63 - const $ = React.useMemoCache();
64 - const c_0 = $[0] !== props$3.a;
65 - const c_1 = $[1] !== props$3.b;
66 - const c_2 = $[2] !== props$3.d;
67 - const c_3 = $[3] !== props$3.c;
68 - if (c_0 || c_1 || c_2 || c_3) {
69 - const a$4 = [];
70 - a$4.push(props$3.a);
71 -
72 - if (props$3.b) {
73 - a$4.push(props$3.d);
74 - return a$4;
75 - }
76 -
77 - a$4.push(props$3.c);
78 - $[0] = props$3.a;
79 - $[1] = props$3.b;
80 - $[2] = props$3.d;
81 - $[3] = props$3.c;
82 - } else {
61 + const a$4 = [];
62 + a$4.push(props$3.a);
63 + if (props$3.b) {
64 + a$4.push(props$3.d);
65 + return a$4;
66 }
67 +
68 + a$4.push(props$3.c);
69 }
70
71 ```
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md
+12 -17
@@ -31,14 +31,12 @@ bb0:
31 ```
32 function component(
33 ) {
34 - scope @0 [1:7] deps=[] out=[] {
35 - [1] Const mutate z$5_@0[1:7] = Array []
36 - [2] Const mutate y$6_@0:TObject[1:7] = Object { }
37 - [3] Reassign mutate y$6_@0.z[1:7] = read z$5_@0
38 - [4] Const mutate x$7_@0:TObject[1:7] = Object { }
39 - [5] Reassign mutate x$7_@0.y[1:7] = read y$6_@0:TObject
40 - [6] Call mutate mutate$4:TFunction(mutate x$7_@0.y.z)
41 - }
34 + [1] Const mutate z$5_@0[1:7] = Array []
35 + [2] Const mutate y$6_@0:TObject[1:7] = Object { }
36 + [3] Reassign mutate y$6_@0.z[1:7] = read z$5_@0
37 + [4] Const mutate x$7_@0:TObject[1:7] = Object { }
38 + [5] Reassign mutate x$7_@0.y[1:7] = read y$6_@0:TObject
39 + [6] Call mutate mutate$4:TFunction(mutate x$7_@0.y.z)
40 return
41 }
42
@@ -48,15 +46,12 @@ function component(
46
47 ```javascript
48 function component$0() {
51 - if (true) {
52 - const z$5 = [];
53 - const y$6 = {};
54 - y$6.z = z$5;
55 - const x$7 = {};
56 - x$7.y = y$6;
57 - mutate$4(x$7.y.z);
58 - } else {
59 - }
49 + const z$5 = [];
50 + const y$6 = {};
51 + y$6.z = z$5;
52 + const x$7 = {};
53 + x$7.y = y$6;
54 + mutate$4(x$7.y.z);
55 }
56
57 ```
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md
+1 -1
@@ -52,7 +52,7 @@ function component(
52 function component$0() {
53 const $ = React.useMemoCache();
54 let z$4;
55 - if (true) {
55 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
56 z$4 = [];
57 $[0] = z$4;
58 } else {
compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md
+5 -10
@@ -76,11 +76,9 @@ function g(
76 a,
77 ) {
78 [1] Const mutate $5:TPrimitive = 1
79 - scope @0 [0:5] deps=[] out=[] {
80 - [2] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c + read $5:TPrimitive
81 - [3] Const mutate $6:TPrimitive = 2
82 - [4] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c * read $6:TPrimitive
83 - }
79 + [2] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c + read $5:TPrimitive
80 + [3] Const mutate $6:TPrimitive = 2
81 + [4] Reassign mutate a$4_@0.b.c[0:5] = Binary read a$4_@0.b.c * read $6:TPrimitive
82 return
83 }
84
@@ -90,11 +88,8 @@ function g(
88
89 ```javascript
90 function g$0(a$4) {
93 - if (true) {
94 - a$4.c.b = a$4.b.c + 1;
95 - a$4.c.b = a$4.b.c * 2;
96 - } else {
97 - }
91 + a$4.c.b = a$4.b.c + 1;
92 + a$4.c.b = a$4.b.c * 2;
93 }
94
95 ```
compiler/forget/src/__tests__/fixtures/hir/call.expect.md
+15 -23
@@ -49,8 +49,8 @@ bb0:
49 [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
50 [6] Call mutate foo$4:TFunction(mutate b$11_@0:TObject)
51 [7] Const mutate $14:TPrimitive = "div"
52 - [8] Const mutate t5$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 - [9] Return read t5$15_@2
52 + [8] Const mutate t4$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 + [9] Return read t4$15_@2
54 ```
55
56 ## Reactive Scopes
@@ -64,9 +64,7 @@ function Component(
64 [2] Const mutate b$11_@0:TObject[1:7] = Object { }
65 [3] Call mutate foo$4:TFunction(mutate a$10_@0, mutate b$11_@0:TObject)
66 [4] Const mutate $12:TPrimitive = "div"
67 - scope @1 [5:6] deps=[freeze a$10_@0] out=[] {
68 - [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
69 - }
67 + [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
68 [6] Call mutate foo$4:TFunction(mutate b$11_@0:TObject)
69 }
70 [7] Const mutate $14:TPrimitive = "div"
@@ -85,18 +83,12 @@ function Component$0(props$9) {
83 const $ = React.useMemoCache();
84 let a$10;
85 let b$11;
88 - if (true) {
86 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
87 a$10 = [];
88 b$11 = {};
89 foo$4(a$10, b$11);
92 - const c_2 = $[2] !== a$10;
90
94 - if (c_2) {
95 - const _$13 = <div a={a$10}></div>;
96 -
97 - $[2] = a$10;
98 - } else {
99 - }
91 + const _$13 = <div a={a$10}></div>;
92
93 foo$4(b$11);
94 $[0] = a$10;
@@ -106,20 +98,20 @@ function Component$0(props$9) {
98 b$11 = $[1];
99 }
100
109 - const c_3 = $[3] !== a$10;
110 - const c_4 = $[4] !== b$11;
111 - let t5$15;
101 + const c_2 = $[2] !== a$10;
102 + const c_3 = $[3] !== b$11;
103 + let t4$15;
104
113 - if (c_3 || c_4) {
114 - t5$15 = <div a={a$10} b={b$11}></div>;
115 - $[3] = a$10;
116 - $[4] = b$11;
117 - $[5] = t5$15;
105 + if (c_2 || c_3) {
106 + t4$15 = <div a={a$10} b={b$11}></div>;
107 + $[2] = a$10;
108 + $[3] = b$11;
109 + $[4] = t4$15;
110 } else {
119 - t5$15 = $[5];
111 + t4$15 = $[4];
112 }
113
122 - return t5$15;
114 + return t4$15;
115 }
116
117 ```
compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md
+13 -28
@@ -374,15 +374,13 @@ bb1:
374 function Component(
375 props,
376 ) {
377 - scope @0 [1:7] deps=[read props$3.a, read props$3.b, read props$3.d, read props$3.c] out=[] {
378 - [1] Const mutate a$4_@0[1:7] = Array []
379 - [2] Call mutate a$4_@0.push(read props$3.a)
380 - if (read props$3.b) {
381 - [6] Call mutate a$4_@0.push(read props$3.d)
382 - return freeze a$4_@0
383 - }
384 - [4] Call mutate a$4_@0.push(read props$3.c)
377 + [1] Const mutate a$4_@0[1:7] = Array []
378 + [2] Call mutate a$4_@0.push(read props$3.a)
379 + if (read props$3.b) {
380 + [6] Call mutate a$4_@0.push(read props$3.d)
381 + return freeze a$4_@0
382 }
383 + [4] Call mutate a$4_@0.push(read props$3.c)
384 }
385
386 ```
@@ -391,27 +389,14 @@ function Component(
389
390 ```javascript
391 function Component$0(props$3) {
394 - const $ = React.useMemoCache();
395 - const c_0 = $[0] !== props$3.a;
396 - const c_1 = $[1] !== props$3.b;
397 - const c_2 = $[2] !== props$3.d;
398 - const c_3 = $[3] !== props$3.c;
399 - if (c_0 || c_1 || c_2 || c_3) {
400 - const a$4 = [];
401 - a$4.push(props$3.a);
402 -
403 - if (props$3.b) {
404 - a$4.push(props$3.d);
405 - return a$4;
406 - }
407 -
408 - a$4.push(props$3.c);
409 - $[0] = props$3.a;
410 - $[1] = props$3.b;
411 - $[2] = props$3.d;
412 - $[3] = props$3.c;
413 - } else {
392 + const a$4 = [];
393 + a$4.push(props$3.a);
394 + if (props$3.b) {
395 + a$4.push(props$3.d);
396 + return a$4;
397 }
398 +
399 + a$4.push(props$3.c);
400 }
401
402 ```
compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md
+15 -23
@@ -49,8 +49,8 @@ bb0:
49 [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
50 [6] New mutate Foo$4(mutate b$11_@0:TObject)
51 [7] Const mutate $14:TPrimitive = "div"
52 - [8] Const mutate t5$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 - [9] Return read t5$15_@2
52 + [8] Const mutate t4$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 + [9] Return read t4$15_@2
54 ```
55
56 ## Reactive Scopes
@@ -64,9 +64,7 @@ function Component(
64 [2] Const mutate b$11_@0:TObject[1:7] = Object { }
65 [3] New mutate Foo$4(mutate a$10_@0, mutate b$11_@0:TObject)
66 [4] Const mutate $12:TPrimitive = "div"
67 - scope @1 [5:6] deps=[freeze a$10_@0] out=[] {
68 - [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
69 - }
67 + [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
68 [6] New mutate Foo$4(mutate b$11_@0:TObject)
69 }
70 [7] Const mutate $14:TPrimitive = "div"
@@ -85,18 +83,12 @@ function Component$0(props$9) {
83 const $ = React.useMemoCache();
84 let a$10;
85 let b$11;
88 - if (true) {
86 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
87 a$10 = [];
88 b$11 = {};
89 new Foo$4(a$10, b$11);
92 - const c_2 = $[2] !== a$10;
90
94 - if (c_2) {
95 - const _$13 = <div a={a$10}></div>;
96 -
97 - $[2] = a$10;
98 - } else {
99 - }
91 + const _$13 = <div a={a$10}></div>;
92
93 new Foo$4(b$11);
94 $[0] = a$10;
@@ -106,20 +98,20 @@ function Component$0(props$9) {
98 b$11 = $[1];
99 }
100
109 - const c_3 = $[3] !== a$10;
110 - const c_4 = $[4] !== b$11;
111 - let t5$15;
101 + const c_2 = $[2] !== a$10;
102 + const c_3 = $[3] !== b$11;
103 + let t4$15;
104
113 - if (c_3 || c_4) {
114 - t5$15 = <div a={a$10} b={b$11}></div>;
115 - $[3] = a$10;
116 - $[4] = b$11;
117 - $[5] = t5$15;
105 + if (c_2 || c_3) {
106 + t4$15 = <div a={a$10} b={b$11}></div>;
107 + $[2] = a$10;
108 + $[3] = b$11;
109 + $[4] = t4$15;
110 } else {
119 - t5$15 = $[5];
111 + t4$15 = $[4];
112 }
113
122 - return t5$15;
114 + return t4$15;
115 }
116
117 ```
compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md
+12 -23
@@ -57,14 +57,12 @@ function foo(
57 }
58 [3] Const mutate $9:TPrimitive = "div"
59 [4] JSX <read $9:TPrimitive>{freeze x$8_@0}</read $9:TPrimitive>
60 - scope @1 [5:12] deps=[read x$8_@0, read b$7] out=[] {
61 - [5] Const mutate y$10_@1[5:12] = Array []
62 - if (read x$8_@0.length) {
63 - [7] Call mutate y$10_@1.push(read x$8_@0)
64 - }
65 - if (read b$7) {
66 - [10] Call mutate y$10_@1.push(read b$7)
67 - }
60 + [5] Const mutate y$10_@1[5:12] = Array []
61 + if (read x$8_@0.length) {
62 + [7] Call mutate y$10_@1.push(read x$8_@0)
63 + }
64 + if (read b$7) {
65 + [10] Call mutate y$10_@1.push(read b$7)
66 }
67 return
68 }
@@ -88,23 +86,14 @@ function foo$0(a$6, b$7) {
86 }
87
88 <div>{x$8}</div>;
91 - const c_2 = $[2] !== x$8;
92 - const c_3 = $[3] !== b$7;
93 -
94 - if (c_2 || c_3) {
95 - const y$10 = [];
89 + const y$10 = [];
90
97 - if (x$8.length) {
98 - y$10.push(x$8);
99 - }
100 -
101 - if (b$7) {
102 - y$10.push(b$7);
103 - }
91 + if (x$8.length) {
92 + y$10.push(x$8);
93 + }
94
105 - $[2] = x$8;
106 - $[3] = b$7;
107 - } else {
95 + if (b$7) {
96 + y$10.push(b$7);
97 }
98 }
99
compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md
+27 -40
@@ -52,19 +52,17 @@ function foo(
52 y,
53 z,
54 ) {
55 - scope @0 [1:10] deps=[read z$8, read x$6, read y$7] out=[] {
56 - [1] Const mutate items$9_@0[1:10] = Array [read z$8]
57 - [2] Call mutate items$9_@0.push(read x$6)
58 - scope @1 [3:7] deps=[read x$6, read y$7] out=[items2$10_@1] {
59 - [3] Const mutate items2$10_@1[3:7] = Array []
60 - if (read x$6) {
61 - [5] Call mutate items2$10_@1.push(read y$7)
62 - }
63 - }
64 - if (read y$7) {
65 - [8] Call mutate items$9_@0.push(read x$6)
55 + [1] Const mutate items$9_@0[1:10] = Array [read z$8]
56 + [2] Call mutate items$9_@0.push(read x$6)
57 + scope @1 [3:7] deps=[read x$6, read y$7] out=[items2$10_@1] {
58 + [3] Const mutate items2$10_@1[3:7] = Array []
59 + if (read x$6) {
60 + [5] Call mutate items2$10_@1.push(read y$7)
61 }
62 }
63 + if (read y$7) {
64 + [8] Call mutate items$9_@0.push(read x$6)
65 + }
66 return freeze items2$10_@1
67 }
68
@@ -75,38 +73,27 @@ function foo(
73 ```javascript
74 function foo$0(x$6, y$7, z$8) {
75 const $ = React.useMemoCache();
78 - const c_0 = $[0] !== z$8;
79 - const c_1 = $[1] !== x$6;
80 - const c_2 = $[2] !== y$7;
81 - if (c_0 || c_1 || c_2) {
82 - const items$9 = [z$8];
83 - items$9.push(x$6);
84 - const c_3 = $[3] !== x$6;
85 - const c_4 = $[4] !== y$7;
86 - let items2$10;
87 -
88 - if (c_3 || c_4) {
89 - items2$10 = [];
90 -
91 - if (x$6) {
92 - items2$10.push(y$7);
93 - }
94 -
95 - $[3] = x$6;
96 - $[4] = y$7;
97 - $[5] = items2$10;
98 - } else {
99 - items2$10 = $[5];
76 + const items$9 = [z$8];
77 + items$9.push(x$6);
78 + const c_0 = $[0] !== x$6;
79 + const c_1 = $[1] !== y$7;
80 + let items2$10;
81 + if (c_0 || c_1) {
82 + items2$10 = [];
83 +
84 + if (x$6) {
85 + items2$10.push(y$7);
86 }
87
102 - if (y$7) {
103 - items$9.push(x$6);
104 - }
105 -
106 - $[0] = z$8;
107 - $[1] = x$6;
108 - $[2] = y$7;
88 + $[0] = x$6;
89 + $[1] = y$7;
90 + $[2] = items2$10;
91 } else {
92 + items2$10 = $[2];
93 + }
94 +
95 + if (y$7) {
96 + items$9.push(x$6);
97 }
98
99 return items2$10;
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md
+11 -25
@@ -56,14 +56,12 @@ function foo(
56 b,
57 c,
58 ) {
59 - scope @0 [1:8] deps=[read a$7, read b$8, read c$9] out=[] {
60 - [1] Const mutate x$10_@0[1:8] = Array []
61 - if (read a$7) {
62 - if (read b$8) {
63 - if (read c$9) {
64 - [5] Const mutate $11:TPrimitive = 0
65 - [6] Call mutate x$10_@0.push(read $11:TPrimitive)
66 - }
59 + [1] Const mutate x$10_@0[1:8] = Array []
60 + if (read a$7) {
61 + if (read b$8) {
62 + if (read c$9) {
63 + [5] Const mutate $11:TPrimitive = 0
64 + [6] Call mutate x$10_@0.push(read $11:TPrimitive)
65 }
66 }
67 }
@@ -80,25 +78,13 @@ function foo(
78
79 ```javascript
80 function foo$0(a$7, b$8, c$9) {
83 - const $ = React.useMemoCache();
84 - const c_0 = $[0] !== a$7;
85 - const c_1 = $[1] !== b$8;
86 - const c_2 = $[2] !== c$9;
87 - if (c_0 || c_1 || c_2) {
88 - const x$10 = [];
89 -
90 - if (a$7) {
91 - if (b$8) {
92 - if (c$9) {
93 - x$10.push(0);
94 - }
81 + const x$10 = [];
82 + if (a$7) {
83 + if (b$8) {
84 + if (c$9) {
85 + x$10.push(0);
86 }
87 }
97 -
98 - $[0] = a$7;
99 - $[1] = b$8;
100 - $[2] = c$9;
101 - } else {
88 }
89
90 if (a$7.length) {
compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md
+1 -1
@@ -47,7 +47,7 @@ function Component(
47 function Component$0() {
48 const $ = React.useMemoCache();
49 let a$5;
50 - if (true) {
50 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
51 a$5 = [];
52 $[0] = a$5;
53 } else {
compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md
+1 -1
@@ -109,7 +109,7 @@ function Component(
109 function Component$0(props$10) {
110 const $ = React.useMemoCache();
111 let x$11;
112 - if (true) {
112 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
113 x$11 = [];
114 $[0] = x$11;
115 } else {
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md
+1 -1
@@ -48,7 +48,7 @@ function Component(
48 function Component$0() {
49 const $ = React.useMemoCache();
50 let a$4;
51 - if (true) {
51 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
52 a$4 = [];
53 $[0] = a$4;
54 } else {
compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md
+8 -22
@@ -40,12 +40,10 @@ function foo(
40 b,
41 c,
42 ) {
43 - scope @0 [1:6] deps=[read a$5, read b$6, read c$7] out=[] {
44 - [1] Const mutate y$8_@0[1:6] = Array []
45 - if (read a$5) {
46 - if (read b$6) {
47 - [4] Call mutate y$8_@0.push(read c$7)
48 - }
43 + [1] Const mutate y$8_@0[1:6] = Array []
44 + if (read a$5) {
45 + if (read b$6) {
46 + [4] Call mutate y$8_@0.push(read c$7)
47 }
48 }
49 return
@@ -57,23 +55,11 @@ function foo(
55
56 ```javascript
57 function foo$0(a$5, b$6, c$7) {
60 - const $ = React.useMemoCache();
61 - const c_0 = $[0] !== a$5;
62 - const c_1 = $[1] !== b$6;
63 - const c_2 = $[2] !== c$7;
64 - if (c_0 || c_1 || c_2) {
65 - const y$8 = [];
66 -
67 - if (a$5) {
68 - if (b$6) {
69 - y$8.push(c$7);
70 - }
58 + const y$8 = [];
59 + if (a$5) {
60 + if (b$6) {
61 + y$8.push(c$7);
62 }
72 -
73 - $[0] = a$5;
74 - $[1] = b$6;
75 - $[2] = c$7;
76 - } else {
63 }
64 }
65
compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md
+1 -1
@@ -67,7 +67,7 @@ function Foo(
67 function Foo$0(props$13) {
68 const $ = React.useMemoCache();
69 let t0$20;
70 - if (true) {
70 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
71 t0$20 = <>Text</>;
72 $[0] = t0$20;
73 } else {
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
+3 -3
@@ -66,7 +66,7 @@ function And(
66 function And$0() {
67 const $ = React.useMemoCache();
68 let t0$5;
69 - if (true) {
69 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
70 t0$5 = f$1();
71 $[0] = t0$5;
72 } else {
@@ -142,7 +142,7 @@ function Or(
142 function Or$0() {
143 const $ = React.useMemoCache();
144 let t0$5;
145 - if (true) {
145 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
146 t0$5 = f$1();
147 $[0] = t0$5;
148 } else {
@@ -223,7 +223,7 @@ function QuestionQuestion(
223 function QuestionQuestion$0(props$8) {
224 const $ = React.useMemoCache();
225 let t0$9;
226 - if (true) {
226 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
227 t0$9 = f$2();
228 $[0] = t0$9;
229 } else {
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
+51 -56
@@ -139,37 +139,35 @@ bb13:
139 function Component(
140 props,
141 ) {
142 - scope @0 [1:23] deps=[] out=[] {
143 - [1] Let mutate a$18_@0[1:23] = Object { }
144 - [2] Let mutate b$20_@0[1:23] = Object { }
145 - [3] Let mutate c$22_@0[1:23] = Object { }
146 - [4] Let mutate d$24_@0[1:23] = Object { }
147 - while (
148 - [6] Const mutate $17:TPrimitive = true
149 - read $17:TPrimitive
150 - ) {
151 - [8] Const mutate z$19_@0[1:23] = read a$18_@0
152 - [9] Reassign mutate a$18_@0[1:23] = read b$20_@0
153 - [10] Reassign mutate b$20_@0[1:23] = read c$22_@0
154 - [11] Reassign mutate c$22_@0[1:23] = read d$24_@0
155 - [12] Reassign mutate d$24_@0[1:23] = read z$19_@0
156 - [13] Call mutate mutate$7:TFunction(mutate a$18_@0, mutate b$20_@0)
157 - [14] Const mutate $29_@0[1:23] = Call mutate cond$8:TFunction(mutate a$18_@0)
158 - if (read $29_@0) {
159 - break
160 - }
161 - }
162 - if (read a$18_@0) {
163 - }
164 - if (read b$20_@0) {
165 - }
166 - if (read c$22_@0) {
167 - }
168 - if (read d$24_@0) {
142 + [1] Let mutate a$18_@0[1:23] = Object { }
143 + [2] Let mutate b$20_@0[1:23] = Object { }
144 + [3] Let mutate c$22_@0[1:23] = Object { }
145 + [4] Let mutate d$24_@0[1:23] = Object { }
146 + while (
147 + [6] Const mutate $17:TPrimitive = true
148 + read $17:TPrimitive
149 + ) {
150 + [8] Const mutate z$19_@0[1:23] = read a$18_@0
151 + [9] Reassign mutate a$18_@0[1:23] = read b$20_@0
152 + [10] Reassign mutate b$20_@0[1:23] = read c$22_@0
153 + [11] Reassign mutate c$22_@0[1:23] = read d$24_@0
154 + [12] Reassign mutate d$24_@0[1:23] = read z$19_@0
155 + [13] Call mutate mutate$7:TFunction(mutate a$18_@0, mutate b$20_@0)
156 + [14] Const mutate $29_@0[1:23] = Call mutate cond$8:TFunction(mutate a$18_@0)
157 + if (read $29_@0) {
158 + break
159 }
170 - [21] Const mutate $34:TPrimitive = null
171 - [22] Call mutate mutate$7:TFunction(mutate d$24_@0, read $34:TPrimitive)
160 }
161 + if (read a$18_@0) {
162 + }
163 + if (read b$20_@0) {
164 + }
165 + if (read c$22_@0) {
166 + }
167 + if (read d$24_@0) {
168 + }
169 + [21] Const mutate $34:TPrimitive = null
170 + [22] Call mutate mutate$7:TFunction(mutate d$24_@0, read $34:TPrimitive)
171 return
172 }
173
@@ -179,39 +177,36 @@ function Component(
177
178 ```javascript
179 function Component$0(props$12) {
182 - if (true) {
183 - let a$18 = {};
184 - let b$20 = {};
185 - let c$22 = {};
186 - let d$24 = {};
187 - while (true) {
188 - const z$19 = a$18;
189 - a$18 = b$20;
190 - b$20 = c$22;
191 - c$22 = d$24;
192 - d$24 = z$19;
193 - mutate$7(a$18, b$20);
194 -
195 - if (cond$8(a$18)) {
196 - break;
197 - }
198 - }
199 -
200 - if (a$18) {
180 + let a$18 = {};
181 + let b$20 = {};
182 + let c$22 = {};
183 + let d$24 = {};
184 + while (true) {
185 + const z$19 = a$18;
186 + a$18 = b$20;
187 + b$20 = c$22;
188 + c$22 = d$24;
189 + d$24 = z$19;
190 + mutate$7(a$18, b$20);
191 +
192 + if (cond$8(a$18)) {
193 + break;
194 }
195 + }
196
203 - if (b$20) {
204 - }
197 + if (a$18) {
198 + }
199
206 - if (c$22) {
207 - }
200 + if (b$20) {
201 + }
202
209 - if (d$24) {
210 - }
203 + if (c$22) {
204 + }
205
212 - mutate$7(d$24, null);
213 - } else {
206 + if (d$24) {
207 }
208 +
209 + mutate$7(d$24, null);
210 }
211
212 ```
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+45 -53
@@ -100,28 +100,26 @@ function Component(
100 scope @0 [1:2] deps=[] out=[a$11_@0] {
101 [1] Const mutate a$11_@0:TObject = Object { }
102 }
103 - scope @1 [2:15] deps=[read a$11_@0:TObject] out=[] {
104 - [2] Const mutate b$12_@1[2:15] = Array [read a$11_@0:TObject]
105 - scope @2 [3:4] deps=[] out=[c$13_@2] {
106 - [3] Const mutate c$13_@2:TObject = Object { }
107 - }
108 - [4] Const mutate d$14_@1:TObject[2:15] = Object { c: read c$13_@2:TObject }
109 - [5] Const mutate x$15_@1:TObject[2:15] = Object { }
110 - [6] Reassign mutate x$15_@1.b[2:15] = read b$12_@1
111 - [7] Const mutate y$16_@1[2:15] = Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, mutate d$14_@1:TObject)
112 - if (read a$11_@0:TObject) {
113 - }
114 - if (read b$12_@1) {
115 - }
116 - if (read c$13_@2:TObject) {
117 - }
118 - if (read d$14_@1:TObject) {
119 - }
120 - if (read y$16_@1) {
121 - }
122 - [13] Const mutate $17:TPrimitive = null
123 - [14] Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, read $17:TPrimitive)
103 + [2] Const mutate b$12_@1[2:15] = Array [read a$11_@0:TObject]
104 + scope @2 [3:4] deps=[] out=[c$13_@2] {
105 + [3] Const mutate c$13_@2:TObject = Object { }
106 + }
107 + [4] Const mutate d$14_@1:TObject[2:15] = Object { c: read c$13_@2:TObject }
108 + [5] Const mutate x$15_@1:TObject[2:15] = Object { }
109 + [6] Reassign mutate x$15_@1.b[2:15] = read b$12_@1
110 + [7] Const mutate y$16_@1[2:15] = Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, mutate d$14_@1:TObject)
111 + if (read a$11_@0:TObject) {
112 }
113 + if (read b$12_@1) {
114 + }
115 + if (read c$13_@2:TObject) {
116 + }
117 + if (read d$14_@1:TObject) {
118 + }
119 + if (read y$16_@1) {
120 + }
121 + [13] Const mutate $17:TPrimitive = null
122 + [14] Call mutate mutate$8:TFunction(mutate x$15_@1:TObject, read $17:TPrimitive)
123 return
124 }
125
@@ -133,52 +131,46 @@ function Component(
131 function Component$0(props$10) {
132 const $ = React.useMemoCache();
133 let a$11;
136 - if (true) {
134 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
135 a$11 = {};
136 $[0] = a$11;
137 } else {
138 a$11 = $[0];
139 }
140
143 - const c_1 = $[1] !== a$11;
144 -
145 - if (c_1) {
146 - const b$12 = [a$11];
147 - let c$13;
148 -
149 - if (true) {
150 - c$13 = {};
151 - $[2] = c$13;
152 - } else {
153 - c$13 = $[2];
154 - }
141 + const b$12 = [a$11];
142 + let c$13;
143
156 - const d$14 = {
157 - c: c$13,
158 - };
159 - const x$15 = {};
160 - x$15.b = b$12;
161 - const y$16 = mutate$8(x$15, d$14);
144 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
145 + c$13 = {};
146 + $[1] = c$13;
147 + } else {
148 + c$13 = $[1];
149 + }
150
163 - if (a$11) {
164 - }
151 + const d$14 = {
152 + c: c$13,
153 + };
154 + const x$15 = {};
155 + x$15.b = b$12;
156 + const y$16 = mutate$8(x$15, d$14);
157
166 - if (b$12) {
167 - }
158 + if (a$11) {
159 + }
160
169 - if (c$13) {
170 - }
161 + if (b$12) {
162 + }
163
172 - if (d$14) {
173 - }
164 + if (c$13) {
165 + }
166
175 - if (y$16) {
176 - }
167 + if (d$14) {
168 + }
169
178 - mutate$8(x$15, null);
179 - $[1] = a$11;
180 - } else {
170 + if (y$16) {
171 }
172 +
173 + mutate$8(x$15, null);
174 }
175
176 ```
compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md
+48 -54
@@ -126,34 +126,32 @@ bb13:
126 function Component(
127 props,
128 ) {
129 - scope @0 [1:18] deps=[] out=[] {
130 - [1] Const mutate a$12_@0:TObject[1:18] = Object { }
131 - [2] Const mutate b$13_@0:TObject[1:18] = Object { }
132 - scope @1 [3:4] deps=[] out=[c$14_@1] {
133 - [3] Const mutate c$14_@1:TObject = Object { }
134 - }
135 - [4] Const mutate d$15_@0:TObject[1:18] = Object { }
136 - while (
137 - [6] Const mutate $16:TPrimitive = true
138 - read $16:TPrimitive
139 - ) {
140 - [8] Call mutate mutate$6:TFunction(mutate a$12_@0:TObject, mutate b$13_@0:TObject)
141 - [9] Const mutate $21_@0[1:18] = Call mutate cond$7:TFunction(mutate a$12_@0:TObject)
142 - if (read $21_@0) {
143 - break
144 - }
145 - }
146 - if (read a$12_@0:TObject) {
147 - }
148 - if (read b$13_@0:TObject) {
149 - }
150 - if (read c$14_@1:TObject) {
151 - }
152 - if (read d$15_@0:TObject) {
129 + [1] Const mutate a$12_@0:TObject[1:18] = Object { }
130 + [2] Const mutate b$13_@0:TObject[1:18] = Object { }
131 + scope @1 [3:4] deps=[] out=[c$14_@1] {
132 + [3] Const mutate c$14_@1:TObject = Object { }
133 + }
134 + [4] Const mutate d$15_@0:TObject[1:18] = Object { }
135 + while (
136 + [6] Const mutate $16:TPrimitive = true
137 + read $16:TPrimitive
138 + ) {
139 + [8] Call mutate mutate$6:TFunction(mutate a$12_@0:TObject, mutate b$13_@0:TObject)
140 + [9] Const mutate $21_@0[1:18] = Call mutate cond$7:TFunction(mutate a$12_@0:TObject)
141 + if (read $21_@0) {
142 + break
143 }
154 - [16] Const mutate $28:TPrimitive = null
155 - [17] Call mutate mutate$6:TFunction(mutate d$15_@0:TObject, read $28:TPrimitive)
144 }
145 + if (read a$12_@0:TObject) {
146 + }
147 + if (read b$13_@0:TObject) {
148 + }
149 + if (read c$14_@1:TObject) {
150 + }
151 + if (read d$15_@0:TObject) {
152 + }
153 + [16] Const mutate $28:TPrimitive = null
154 + [17] Call mutate mutate$6:TFunction(mutate d$15_@0:TObject, read $28:TPrimitive)
155 return
156 }
157
@@ -164,43 +162,39 @@ function Component(
162 ```javascript
163 function Component$0(props$11) {
164 const $ = React.useMemoCache();
167 - if (true) {
168 - const a$12 = {};
169 - const b$13 = {};
170 - let c$14;
171 -
172 - if (true) {
173 - c$14 = {};
174 - $[0] = c$14;
175 - } else {
176 - c$14 = $[0];
177 - }
178 -
179 - const d$15 = {};
165 + const a$12 = {};
166 + const b$13 = {};
167 + let c$14;
168 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
169 + c$14 = {};
170 + $[0] = c$14;
171 + } else {
172 + c$14 = $[0];
173 + }
174
181 - while (true) {
182 - mutate$6(a$12, b$13);
175 + const d$15 = {};
176
184 - if (cond$7(a$12)) {
185 - break;
186 - }
187 - }
177 + while (true) {
178 + mutate$6(a$12, b$13);
179
189 - if (a$12) {
180 + if (cond$7(a$12)) {
181 + break;
182 }
183 + }
184
192 - if (b$13) {
193 - }
185 + if (a$12) {
186 + }
187
195 - if (c$14) {
196 - }
188 + if (b$13) {
189 + }
190
198 - if (d$15) {
199 - }
191 + if (c$14) {
192 + }
193
201 - mutate$6(d$15, null);
202 - } else {
194 + if (d$15) {
195 }
196 +
197 + mutate$6(d$15, null);
198 }
199
200 ```
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md
+11 -22
@@ -37,14 +37,12 @@ function foo(
37 b,
38 c,
39 ) {
40 - scope @0 [1:6] deps=[read a$6, read b$7] out=[] {
41 - [1] Const mutate x$9_@0[1:6] = Array []
42 - [2] Const mutate y$10_@0[1:6] = Array []
43 - if (read x$9_@0) {
44 - }
45 - [4] Call mutate y$10_@0.push(read a$6)
46 - [5] Call mutate x$9_@0.push(read b$7)
40 + [1] Const mutate x$9_@0[1:6] = Array []
41 + [2] Const mutate y$10_@0[1:6] = Array []
42 + if (read x$9_@0) {
43 }
44 + [4] Call mutate y$10_@0.push(read a$6)
45 + [5] Call mutate x$9_@0.push(read b$7)
46 return
47 }
48
@@ -54,22 +52,13 @@ function foo(
52
53 ```javascript
54 function foo$0(a$6, b$7, c$8) {
57 - const $ = React.useMemoCache();
58 - const c_0 = $[0] !== a$6;
59 - const c_1 = $[1] !== b$7;
60 - if (c_0 || c_1) {
61 - const x$9 = [];
62 - const y$10 = [];
63 -
64 - if (x$9) {
65 - }
66 -
67 - y$10.push(a$6);
68 - x$9.push(b$7);
69 - $[0] = a$6;
70 - $[1] = b$7;
71 - } else {
55 + const x$9 = [];
56 + const y$10 = [];
57 + if (x$9) {
58 }
59 +
60 + y$10.push(a$6);
61 + x$9.push(b$7);
62 }
63
64 ```
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md
+8 -18
@@ -29,12 +29,10 @@ function foo(
29 a,
30 b,
31 ) {
32 - scope @0 [1:5] deps=[read a$5, read b$6] out=[] {
33 - [1] Const mutate x$7_@0[1:5] = Array []
34 - [2] Const mutate y$8_@0[1:5] = Array []
35 - [3] Call mutate x$7_@0.push(read a$5)
36 - [4] Call mutate y$8_@0.push(read b$6)
37 - }
32 + [1] Const mutate x$7_@0[1:5] = Array []
33 + [2] Const mutate y$8_@0[1:5] = Array []
34 + [3] Call mutate x$7_@0.push(read a$5)
35 + [4] Call mutate y$8_@0.push(read b$6)
36 return
37 }
38
@@ -44,18 +42,10 @@ function foo(
42
43 ```javascript
44 function foo$0(a$5, b$6) {
47 - const $ = React.useMemoCache();
48 - const c_0 = $[0] !== a$5;
49 - const c_1 = $[1] !== b$6;
50 - if (c_0 || c_1) {
51 - const x$7 = [];
52 - const y$8 = [];
53 - x$7.push(a$5);
54 - y$8.push(b$6);
55 - $[0] = a$5;
56 - $[1] = b$6;
57 - } else {
58 - }
45 + const x$7 = [];
46 + const y$8 = [];
47 + x$7.push(a$5);
48 + y$8.push(b$6);
49 }
50
51 ```
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md
+8 -27
@@ -29,14 +29,10 @@ function foo(
29 a,
30 b,
31 ) {
32 - scope @0 [1:5] deps=[read b$6, read a$5] out=[] {
33 - [1] Const mutate x$7_@0[1:5] = Array []
34 - scope @1 [2:4] deps=[read b$6] out=[] {
35 - [2] Const mutate y$8_@1[2:4] = Array []
36 - [3] Call mutate y$8_@1.push(read b$6)
37 - }
38 - [4] Call mutate x$7_@0.push(read a$5)
39 - }
32 + [1] Const mutate x$7_@0[1:5] = Array []
33 + [2] Const mutate y$8_@1[2:4] = Array []
34 + [3] Call mutate y$8_@1.push(read b$6)
35 + [4] Call mutate x$7_@0.push(read a$5)
36 return
37 }
38
@@ -46,25 +42,10 @@ function foo(
42
43 ```javascript
44 function foo$0(a$5, b$6) {
49 - const $ = React.useMemoCache();
50 - const c_0 = $[0] !== b$6;
51 - const c_1 = $[1] !== a$5;
52 - if (c_0 || c_1) {
53 - const x$7 = [];
54 - const c_2 = $[2] !== b$6;
55 -
56 - if (c_2) {
57 - const y$8 = [];
58 - y$8.push(b$6);
59 - $[2] = b$6;
60 - } else {
61 - }
62 -
63 - x$7.push(a$5);
64 - $[0] = b$6;
65 - $[1] = a$5;
66 - } else {
67 - }
45 + const x$7 = [];
46 + const y$8 = [];
47 + y$8.push(b$6);
48 + x$7.push(a$5);
49 }
50
51 ```
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md
+12 -26
@@ -41,15 +41,13 @@ function foo(
41 b,
42 c,
43 ) {
44 - scope @0 [1:8] deps=[read c$8, read b$7, read a$6] out=[] {
45 - [1] Const mutate x$9_@0[1:8] = Array []
46 - [2] Const mutate y$10_@0[1:8] = Array []
47 - while (
48 - read c$8
49 - ) {
50 - [5] Call mutate y$10_@0.push(read b$7)
51 - [6] Call mutate x$9_@0.push(read a$6)
52 - }
44 + [1] Const mutate x$9_@0[1:8] = Array []
45 + [2] Const mutate y$10_@0[1:8] = Array []
46 + while (
47 + read c$8
48 + ) {
49 + [5] Call mutate y$10_@0.push(read b$7)
50 + [6] Call mutate x$9_@0.push(read a$6)
51 }
52 return
53 }
@@ -60,23 +58,11 @@ function foo(
58
59 ```javascript
60 function foo$0(a$6, b$7, c$8) {
63 - const $ = React.useMemoCache();
64 - const c_0 = $[0] !== c$8;
65 - const c_1 = $[1] !== b$7;
66 - const c_2 = $[2] !== a$6;
67 - if (c_0 || c_1 || c_2) {
68 - const x$9 = [];
69 - const y$10 = [];
70 -
71 - while (c$8) {
72 - y$10.push(b$7);
73 - x$9.push(a$6);
74 - }
75 -
76 - $[0] = c$8;
77 - $[1] = b$7;
78 - $[2] = a$6;
79 - } else {
61 + const x$9 = [];
62 + const y$10 = [];
63 + while (c$8) {
64 + y$10.push(b$7);
65 + x$9.push(a$6);
66 }
67 }
68
compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md
+2 -2
@@ -51,11 +51,11 @@ function foo(
51 function foo$0() {
52 const $ = React.useMemoCache();
53 let x$4;
54 - if (true) {
54 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
55 x$4 = {};
56 let y$5;
57
58 - if (true) {
58 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
59 y$5 = [];
60 const z$6 = {};
61 y$5.push(z$6);
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
+14 -23
@@ -35,8 +35,8 @@ bb1:
35 predecessor blocks: bb2 bb0
36 [7] Const mutate _$12_@1 = JSX <read Component$0 x={freeze x$7_@0} ></read Component$0>
37 [8] Call read y$8.push(read props$6.p2)
38 - [9] Const mutate t6$15_@2 = JSX <read Component$0 x={read x$7_@0} y={read y$8} ></read Component$0>
39 - [10] Return read t6$15_@2
38 + [9] Const mutate t5$15_@2 = JSX <read Component$0 x={read x$7_@0} y={read y$8} ></read Component$0>
39 + [10] Return read t5$15_@2
40 ```
41
42 ## Reactive Scopes
@@ -53,9 +53,7 @@ function Component(
53 [5] Reassign mutate x$7_@0[1:7] = Array []
54 }
55 }
56 - scope @1 [7:8] deps=[freeze x$7_@0] out=[] {
57 - [7] Const mutate _$12_@1 = JSX <read Component$0 x={freeze x$7_@0} ></read Component$0>
58 - }
56 + [7] Const mutate _$12_@1 = JSX <read Component$0 x={freeze x$7_@0} ></read Component$0>
57 [8] Call read y$8.push(read props$6.p2)
58 scope @2 [9:10] deps=[read x$7_@0, read y$8] out=[$15_@2] {
59 [9] Const mutate $15_@2 = JSX <read Component$0 x={read x$7_@0} y={read y$8} ></read Component$0>
@@ -89,30 +87,23 @@ function Component$0(props$6) {
87 x$7 = $[2];
88 }
89
92 - const c_3 = $[3] !== x$7;
90 + const _$12 = <Component$0 x={x$7}></Component$0>;
91
94 - if (c_3) {
95 - const _$12 = <Component$0 x={x$7}></Component$0>;
92 + y$8.push(props$6.p2);
93 + const c_3 = $[3] !== x$7;
94 + const c_4 = $[4] !== y$8;
95 + let t5$15;
96
97 + if (c_3 || c_4) {
98 + t5$15 = <Component$0 x={x$7} y={y$8}></Component$0>;
99 $[3] = x$7;
100 + $[4] = y$8;
101 + $[5] = t5$15;
102 } else {
103 + t5$15 = $[5];
104 }
105
101 - y$8.push(props$6.p2);
102 - const c_4 = $[4] !== x$7;
103 - const c_5 = $[5] !== y$8;
104 - let t6$15;
105 -
106 - if (c_4 || c_5) {
107 - t6$15 = <Component$0 x={x$7} y={y$8}></Component$0>;
108 - $[4] = x$7;
109 - $[5] = y$8;
110 - $[6] = t6$15;
111 - } else {
112 - t6$15 = $[6];
113 - }
114 -
115 - return t6$15;
106 + return t5$15;
107 }
108
109 ```
compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md
+15 -24
@@ -27,8 +27,8 @@ bb0:
27 [4] Const mutate x$9_@1 = Array []
28 [5] Const mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
29 [6] Call mutate y$8_@0.push(read props$6.p1)
30 - [7] Const mutate t7$11_@3 = JSX <read Component$0 x={read x$9_@1} y={freeze y$8_@0} ></read Component$0>
31 - [8] Return read t7$11_@3
30 + [7] Const mutate t6$11_@3 = JSX <read Component$0 x={read x$9_@1} y={freeze y$8_@0} ></read Component$0>
31 + [8] Return read t6$11_@3
32 ```
33
34 ## Reactive Scopes
@@ -44,9 +44,7 @@ function Component(
44 scope @1 [4:5] deps=[] out=[x$9_@1] {
45 [4] Const mutate x$9_@1 = Array []
46 }
47 - scope @2 [5:6] deps=[freeze x$9_@1] out=[] {
48 - [5] Const mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
49 - }
47 + [5] Const mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
48 [6] Call mutate y$8_@0.push(read props$6.p1)
49 }
50 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) {
69 y$8 = x$7;
70 let x$9;
71
74 - if (true) {
72 + if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
73 x$9 = [];
74 $[3] = x$9;
75 } else {
76 x$9 = $[3];
77 }
78
81 - const c_4 = $[4] !== x$9;
82 -
83 - if (c_4) {
84 - const _$10 = <Component$0 x={x$9}></Component$0>;
85 -
86 - $[4] = x$9;
87 - } else {
88 - }
79 + const _$10 = <Component$0 x={x$9}></Component$0>;
80
81 y$8.push(props$6.p1);
82 $[0] = props$6.p0;
@@ -95,20 +86,20 @@ function Component$0(props$6) {
86 y$8 = $[2];
87 }
88
98 - const c_5 = $[5] !== x$9;
99 - const c_6 = $[6] !== y$8;
100 - let t7$11;
89 + const c_4 = $[4] !== x$9;
90 + const c_5 = $[5] !== y$8;
91 + let t6$11;
92
102 - if (c_5 || c_6) {
103 - t7$11 = <Component$0 x={x$9} y={y$8}></Component$0>;
104 - $[5] = x$9;
105 - $[6] = y$8;
106 - $[7] = t7$11;
93 + if (c_4 || c_5) {
94 + t6$11 = <Component$0 x={x$9} y={y$8}></Component$0>;
95 + $[4] = x$9;
96 + $[5] = y$8;
97 + $[6] = t6$11;
98 } else {
108 - t7$11 = $[7];
99 + t6$11 = $[6];
100 }
101
111 - return t7$11;
102 + return t6$11;
103 }
104
105 ```
compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md
+3 -10
@@ -58,9 +58,7 @@ bb0:
58 ```
59 function foo(
60 ) {
61 - scope @0 [1:2] deps=[] out=[] {
62 - [1] Const mutate a$5_@0:TObject = Object { }
63 - }
61 + [1] Const mutate a$5_@0:TObject = Object { }
62 scope @1 [2:8] deps=[] out=[c$10_@1] {
63 [2] Const mutate b$6_@1:TObject[2:8] = Object { }
64 [3] Const mutate c$7_@1:TObject[2:8] = Object { }
@@ -79,14 +77,9 @@ function foo(
77 ```javascript
78 function foo$0() {
79 const $ = React.useMemoCache();
82 - if (true) {
83 - const a$5 = {};
84 - } else {
85 - }
86 -
80 + const a$5 = {};
81 let c$10;
88 -
89 - if (true) {
82 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
83 const b$6 = {};
84 const c$7 = {};
85 const a$8 = b$6;
compiler/forget/src/__tests__/fixtures/hir/simple.expect.md
+1 -1
@@ -75,7 +75,7 @@ function foo$0(x$8, y$9) {
75
76 let t2$14;
77
78 - if (true) {
78 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
79 t2$14 = [y$9 * 10];
80 $[2] = t2$14;
81 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md
+1 -1
@@ -45,7 +45,7 @@ function Component$0(props$5) {
45 const a$6 = 1;
46 const b$7 = 2;
47 let x$8;
48 - if (true) {
48 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
49 x$8 = [a$6, b$7];
50 $[0] = x$8;
51 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md
+16 -25
@@ -59,8 +59,8 @@ bb1:
59 predecessor blocks: bb2 bb0
60 [9] Call mutate foo$4:TFunction(read a$11_@0, mutate b$12_@0:TObject)
61 [10] Const mutate $19:TPrimitive = "div"
62 - [11] Const mutate t6$20_@3 = JSX <read $19:TPrimitive a={freeze a$11_@0} b={freeze b$12_@0:TObject} ></read $19:TPrimitive>
63 - [12] Return read t6$20_@3
62 + [11] Const mutate t5$20_@3 = JSX <read $19:TPrimitive a={freeze a$11_@0} b={freeze b$12_@0:TObject} ></read $19:TPrimitive>
63 + [12] Return read t5$20_@3
64 ```
65
66 ## Reactive Scopes
@@ -78,9 +78,7 @@ function Component(
78 }
79 if (read $13_@1) {
80 [6] Const mutate $14:TPrimitive = "div"
81 - scope @2 [7:8] deps=[freeze a$11_@0] out=[] {
82 - [7] Const mutate _$15_@2 = JSX <read $14:TPrimitive a={freeze a$11_@0} ></read $14:TPrimitive>
83 - }
81 + [7] Const mutate _$15_@2 = JSX <read $14:TPrimitive a={freeze a$11_@0} ></read $14:TPrimitive>
82 }
83 [9] Call mutate foo$4:TFunction(read a$11_@0, mutate b$12_@0:TObject)
84 }
@@ -100,13 +98,13 @@ function Component$0(props$10) {
98 const $ = React.useMemoCache();
99 let a$11;
100 let b$12;
103 - if (true) {
101 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
102 a$11 = [];
103 b$12 = {};
104 foo$4(a$11, b$12);
105 let t2$13;
106
109 - if (true) {
107 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
108 t2$13 = foo$4();
109 $[2] = t2$13;
110 } else {
@@ -114,14 +112,7 @@ function Component$0(props$10) {
112 }
113
114 if (t2$13) {
117 - const c_3 = $[3] !== a$11;
118 -
119 - if (c_3) {
120 - const _$15 = <div a={a$11}></div>;
121 -
122 - $[3] = a$11;
123 - } else {
124 - }
115 + const _$15 = <div a={a$11}></div>;
116 }
117
118 foo$4(a$11, b$12);
@@ -132,20 +123,20 @@ function Component$0(props$10) {
123 b$12 = $[1];
124 }
125
135 - const c_4 = $[4] !== a$11;
136 - const c_5 = $[5] !== b$12;
137 - let t6$20;
126 + const c_3 = $[3] !== a$11;
127 + const c_4 = $[4] !== b$12;
128 + let t5$20;
129
139 - if (c_4 || c_5) {
140 - t6$20 = <div a={a$11} b={b$12}></div>;
141 - $[4] = a$11;
142 - $[5] = b$12;
143 - $[6] = t6$20;
130 + if (c_3 || c_4) {
131 + t5$20 = <div a={a$11} b={b$12}></div>;
132 + $[3] = a$11;
133 + $[4] = b$12;
134 + $[5] = t5$20;
135 } else {
145 - t6$20 = $[6];
136 + t5$20 = $[5];
137 }
138
148 - return t6$20;
139 + return t5$20;
140 }
141
142 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md
+15 -23
@@ -49,8 +49,8 @@ bb0:
49 [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
50 [6] Call mutate foo$4:TFunction(read a$10_@0, mutate b$11_@0:TObject)
51 [7] Const mutate $14:TPrimitive = "div"
52 - [8] Const mutate t5$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 - [9] Return read t5$15_@2
52 + [8] Const mutate t4$15_@2 = JSX <read $14:TPrimitive a={read a$10_@0} b={freeze b$11_@0:TObject} ></read $14:TPrimitive>
53 + [9] Return read t4$15_@2
54 ```
55
56 ## Reactive Scopes
@@ -64,9 +64,7 @@ function Component(
64 [2] Const mutate b$11_@0:TObject[1:7] = Object { }
65 [3] Call mutate foo$4:TFunction(mutate a$10_@0, mutate b$11_@0:TObject)
66 [4] Const mutate $12:TPrimitive = "div"
67 - scope @1 [5:6] deps=[freeze a$10_@0] out=[] {
68 - [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
69 - }
67 + [5] Const mutate _$13_@1 = JSX <read $12:TPrimitive a={freeze a$10_@0} ></read $12:TPrimitive>
68 [6] Call mutate foo$4:TFunction(read a$10_@0, mutate b$11_@0:TObject)
69 }
70 [7] Const mutate $14:TPrimitive = "div"
@@ -85,18 +83,12 @@ function Component$0(props$9) {
83 const $ = React.useMemoCache();
84 let a$10;
85 let b$11;
88 - if (true) {
86 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
87 a$10 = [];
88 b$11 = {};
89 foo$4(a$10, b$11);
92 - const c_2 = $[2] !== a$10;
90
94 - if (c_2) {
95 - const _$13 = <div a={a$10}></div>;
96 -
97 - $[2] = a$10;
98 - } else {
99 - }
91 + const _$13 = <div a={a$10}></div>;
92
93 foo$4(a$10, b$11);
94 $[0] = a$10;
@@ -106,20 +98,20 @@ function Component$0(props$9) {
98 b$11 = $[1];
99 }
100
109 - const c_3 = $[3] !== a$10;
110 - const c_4 = $[4] !== b$11;
111 - let t5$15;
101 + const c_2 = $[2] !== a$10;
102 + const c_3 = $[3] !== b$11;
103 + let t4$15;
104
113 - if (c_3 || c_4) {
114 - t5$15 = <div a={a$10} b={b$11}></div>;
115 - $[3] = a$10;
116 - $[4] = b$11;
117 - $[5] = t5$15;
105 + if (c_2 || c_3) {
106 + t4$15 = <div a={a$10} b={b$11}></div>;
107 + $[2] = a$10;
108 + $[3] = b$11;
109 + $[4] = t4$15;
110 } else {
119 - t5$15 = $[5];
111 + t4$15 = $[4];
112 }
113
122 - return t5$15;
114 + return t4$15;
115 }
116
117 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+1 -1
@@ -76,7 +76,7 @@ function foo(
76 function foo$0() {
77 const $ = React.useMemoCache();
78 let x$7;
79 - if (true) {
79 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
80 x$7 = 1;
81 const y$8 = 2;
82
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+1 -1
@@ -59,7 +59,7 @@ function foo(
59 function foo$0() {
60 const $ = React.useMemoCache();
61 let x$5;
62 - if (true) {
62 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
63 x$5 = 1;
64 const y$6 = 2;
65
compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md
+2 -7
@@ -46,9 +46,7 @@ bb2:
46 function foo(
47 cond,
48 ) {
49 - scope @0 [1:2] deps=[] out=[] {
50 - [1] Const mutate items$5_@0 = Array []
51 - }
49 + [1] Const mutate items$5_@0 = Array []
50 }
51
52 ```
@@ -57,10 +55,7 @@ function foo(
55
56 ```javascript
57 function foo$0(cond$4) {
60 - if (true) {
61 - const items$5 = [];
62 - } else {
63 - }
58 + const items$5 = [];
59 }
60
61 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md
+1 -1
@@ -72,7 +72,7 @@ function foo(
72 function foo$0() {
73 const $ = React.useMemoCache();
74 let x$6;
75 - if (true) {
75 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
76 x$6 = 1;
77
78 for (const i$7 = 0; i$7 < 10; i$7) {
compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md
+1 -1
@@ -76,7 +76,7 @@ function foo(
76 function foo$0() {
77 const $ = React.useMemoCache();
78 let x$7;
79 - if (true) {
79 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
80 x$7 = 1;
81
82 for (let i$8 = 0; i$8 < 10; i$8 = i$8 + 1, i$8) {
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md
+10 -24
@@ -44,14 +44,12 @@ function foo(
44 b,
45 c,
46 ) {
47 - scope @0 [1:8] deps=[read a$5, read b$6, read c$7] out=[] {
48 - [1] Const mutate x$8_@0[1:8] = read a$5
49 - if (read b$6) {
50 - if (read c$7) {
51 - [4] Reassign mutate x$8_@0[1:8] = read c$7
52 - }
53 - [6] read x$8_@0
47 + [1] Const mutate x$8_@0[1:8] = read a$5
48 + if (read b$6) {
49 + if (read c$7) {
50 + [4] Reassign mutate x$8_@0[1:8] = read c$7
51 }
52 + [6] read x$8_@0
53 }
54 return
55 }
@@ -62,25 +60,13 @@ function foo(
60
61 ```javascript
62 function foo$0(a$5, b$6, c$7) {
65 - const $ = React.useMemoCache();
66 - const c_0 = $[0] !== a$5;
67 - const c_1 = $[1] !== b$6;
68 - const c_2 = $[2] !== c$7;
69 - if (c_0 || c_1 || c_2) {
70 - const x$8 = a$5;
71 -
72 - if (b$6) {
73 - if (c$7) {
74 - x$8 = c$7;
75 - }
76 -
77 - x$8;
63 + const x$8 = a$5;
64 + if (b$6) {
65 + if (c$7) {
66 + x$8 = c$7;
67 }
68
80 - $[0] = a$5;
81 - $[1] = b$6;
82 - $[2] = c$7;
83 - } else {
69 + x$8;
70 }
71 }
72
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md
+1 -1
@@ -68,7 +68,7 @@ function Component(
68 function Component$0(props$6) {
69 const $ = React.useMemoCache();
70 let c$9;
71 - if (true) {
71 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
72 const a$7 = [];
73 const b$8 = {};
74 c$9 = new Foo$5(a$7, b$8);
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+1 -1
@@ -71,7 +71,7 @@ function foo(
71 function foo$0() {
72 const $ = React.useMemoCache();
73 let x$6;
74 - if (true) {
74 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
75 x$6 = 1;
76 let y$7 = 2;
77
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md
+1 -1
@@ -45,7 +45,7 @@ function Component$0(props$5) {
45 const a$6 = 1;
46 const b$7 = 2;
47 let x$8;
48 - if (true) {
48 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
49 x$8 = {
50 a: a$6,
51 b: b$7,
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md
+2 -2
@@ -75,7 +75,7 @@ function foo$0(a$5) {
75 if (a$5) {
76 let y$7;
77
78 - if (true) {
78 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
79 y$7 = {};
80 $[2] = y$7;
81 } else {
@@ -86,7 +86,7 @@ function foo$0(a$5) {
86 } else {
87 let z$8;
88
89 - if (true) {
89 + if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
90 z$8 = {};
91 $[3] = z$8;
92 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md
+1 -1
@@ -80,7 +80,7 @@ function foo$0(a$6) {
80 } else {
81 let z$9;
82
83 - if (true) {
83 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
84 z$9 = {};
85 $[2] = z$9;
86 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md
+1 -1
@@ -50,7 +50,7 @@ function foo(
50 function foo$0() {
51 const $ = React.useMemoCache();
52 let y$7;
53 - if (true) {
53 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
54 const a$5 = {};
55 const x$6 = a$5;
56 y$7 = {};
compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md
+1 -1
@@ -46,7 +46,7 @@ function foo(
46 function foo$0() {
47 const $ = React.useMemoCache();
48 let x$4;
49 - if (true) {
49 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
50 x$4 = [];
51 $[0] = x$4;
52 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md
+1 -1
@@ -45,7 +45,7 @@ function foo(
45 function foo$0() {
46 const $ = React.useMemoCache();
47 let y$5;
48 - if (true) {
48 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
49 const x$4 = [];
50 y$5 = {};
51 y$5.x = x$4;
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md
+1 -1
@@ -50,7 +50,7 @@ function foo(
50 function foo$0() {
51 const $ = React.useMemoCache();
52 let y$6;
53 - if (true) {
53 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
54 const a$5 = {};
55 y$6 = a$5;
56 const x$7 = [];
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md
+1 -1
@@ -45,7 +45,7 @@ function foo(
45 function foo$0() {
46 const $ = React.useMemoCache();
47 let y$5;
48 - if (true) {
48 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
49 const x$4 = [];
50 y$5 = {};
51 y$5.x = x$4;
compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md
+1 -1
@@ -44,7 +44,7 @@ function foo(
44 function foo$0() {
45 const $ = React.useMemoCache();
46 let x$3;
47 - if (true) {
47 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
48 x$3 = [];
49 $[0] = x$3;
50 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md
+1 -1
@@ -54,7 +54,7 @@ function foo(
54 function foo$0() {
55 const $ = React.useMemoCache();
56 let x$4;
57 - if (true) {
57 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
58 x$4 = 1;
59
60 if (x$4 === 1) {
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+1 -1
@@ -68,7 +68,7 @@ function foo$0() {
68 const $ = React.useMemoCache();
69 const y$5 = 2;
70 let y$8;
71 - if (true) {
71 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
72 y$8 = undefined;
73
74 if (y$5 > 1) {
compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md
+1 -1
@@ -102,7 +102,7 @@ function foo$0() {
102 const $ = React.useMemoCache();
103 const x$10 = 1;
104 let x$16;
105 - if (true) {
105 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
106 x$16 = undefined;
107
108 bb1: switch (x$10) {
compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md
+1 -1
@@ -53,7 +53,7 @@ function foo(
53 function foo$0() {
54 const $ = React.useMemoCache();
55 let x$4;
56 - if (true) {
56 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
57 x$4 = 1;
58
59 if (x$4 === 1) {
compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md
+1 -1
@@ -61,7 +61,7 @@ function foo(
61 function foo$0() {
62 const $ = React.useMemoCache();
63 let x$5;
64 - if (true) {
64 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
65 x$5 = 1;
66
67 while (x$5 < 10) {
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+2 -8
@@ -69,9 +69,7 @@ function Component(
69 case read $12:TPrimitive: {
70 [6] Call mutate x$9_@1.push(read props$8.p2)
71 [7] Call mutate x$9_@1.push(read props$8.p3)
72 - scope @2 [8:9] deps=[] out=[] {
73 - [8] Const mutate y$13_@2 = Array []
74 - }
72 + [8] Const mutate y$13_@2 = Array []
73 }
74 case read $11:TPrimitive: {
75 [10] Reassign mutate y$10_@1:TPrimitive[1:12] = read x$9_@1
@@ -107,11 +105,7 @@ function Component$0(props$8) {
105 case true: {
106 x$9.push(props$8.p2);
107 x$9.push(props$8.p3);
110 -
111 - if (true) {
112 - const y$13 = [];
113 - } else {
114 - }
108 + const y$13 = [];
109 }
110
111 case false: {
compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md
+16 -21
@@ -37,16 +37,14 @@ bb0:
37 ```
38 function component(
39 ) {
40 - scope @0 [1:9] deps=[] out=[] {
41 - [1] Const mutate x$6_@0:TObject[1:9] = Object { }
42 - [2] Const mutate p$7_@0:TObject[1:9] = Object { }
43 - [3] Const mutate q$8_@0:TObject[1:9] = Object { }
44 - [4] Const mutate y$9_@0:TObject[1:9] = Object { }
45 - [5] Reassign mutate x$6_@0.y[1:9] = read y$9_@0:TObject
46 - [6] Reassign mutate p$7_@0.y[1:9] = read x$6_@0.y
47 - [7] Reassign mutate q$8_@0.y[1:9] = read p$7_@0.y
48 - [8] Call mutate mutate$5:TFunction(mutate q$8_@0:TObject)
49 - }
40 + [1] Const mutate x$6_@0:TObject[1:9] = Object { }
41 + [2] Const mutate p$7_@0:TObject[1:9] = Object { }
42 + [3] Const mutate q$8_@0:TObject[1:9] = Object { }
43 + [4] Const mutate y$9_@0:TObject[1:9] = Object { }
44 + [5] Reassign mutate x$6_@0.y[1:9] = read y$9_@0:TObject
45 + [6] Reassign mutate p$7_@0.y[1:9] = read x$6_@0.y
46 + [7] Reassign mutate q$8_@0.y[1:9] = read p$7_@0.y
47 + [8] Call mutate mutate$5:TFunction(mutate q$8_@0:TObject)
48 return
49 }
50
@@ -56,17 +54,14 @@ function component(
54
55 ```javascript
56 function component$0() {
59 - if (true) {
60 - const x$6 = {};
61 - const p$7 = {};
62 - const q$8 = {};
63 - const y$9 = {};
64 - x$6.y = y$9;
65 - p$7.y = x$6.y;
66 - q$8.y = p$7.y;
67 - mutate$5(q$8);
68 - } else {
69 - }
57 + const x$6 = {};
58 + const p$7 = {};
59 + const q$8 = {};
60 + const y$9 = {};
61 + x$6.y = y$9;
62 + p$7.y = x$6.y;
63 + q$8.y = p$7.y;
64 + mutate$5(q$8);
65 }
66
67 ```
compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md
+2 -7
@@ -34,9 +34,7 @@ function component(
34 ) {
35 [1] Const mutate $7:TPrimitive = Binary read a$5:TPrimitive > read b$6:TPrimitive
36 if (read $7:TPrimitive) {
37 - scope @0 [3:4] deps=[] out=[] {
38 - [3] Const mutate m$8_@0:TObject = Object { }
39 - }
37 + [3] Const mutate m$8_@0:TObject = Object { }
38 }
39 return
40 }
@@ -48,10 +46,7 @@ function component(
46 ```javascript
47 function component$0(a$5, b$6) {
48 if (a$5 > b$6) {
51 - if (true) {
52 - const m$8 = {};
53 - } else {
54 - }
49 + const m$8 = {};
50 }
51 }
52
compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md
+4 -9
@@ -42,9 +42,7 @@ function component(
42 }
43 [3] Const mutate $9:TPrimitive = Binary read a$7_@0:TPrimitive > read b$8_@1:TPrimitive
44 if (read $9:TPrimitive) {
45 - scope @2 [5:6] deps=[] out=[] {
46 - [5] Const mutate m$10_@2:TObject = Object { }
47 - }
45 + [5] Const mutate m$10_@2:TObject = Object { }
46 }
47 return
48 }
@@ -57,7 +55,7 @@ function component(
55 function component$0() {
56 const $ = React.useMemoCache();
57 let a$7;
60 - if (true) {
58 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
59 a$7 = some$2();
60 $[0] = a$7;
61 } else {
@@ -66,7 +64,7 @@ function component$0() {
64
65 let b$8;
66
69 - if (true) {
67 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
68 b$8 = someOther$4();
69 $[1] = b$8;
70 } else {
@@ -74,10 +72,7 @@ function component$0() {
72 }
73
74 if (a$7 > b$8) {
77 - if (true) {
78 - const m$10 = {};
79 - } else {
80 - }
75 + const m$10 = {};
76 }
77 }
78
compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md
+1 -1
@@ -40,7 +40,7 @@ function component(
40 function component$0() {
41 const $ = React.useMemoCache();
42 let x$5;
43 - if (true) {
43 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
44 x$5 = {
45 t: 1,
46 };
compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md
+2 -2
@@ -65,7 +65,7 @@ function component(
65 function component$0() {
66 const $ = React.useMemoCache();
67 let t0$10;
68 - if (true) {
68 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
69 t0$10 = makeSomePrimitive$2();
70 $[0] = t0$10;
71 } else {
@@ -74,7 +74,7 @@ function component$0() {
74
75 let t1$11;
76
77 - if (true) {
77 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
78 t1$11 = makeSomePrimitive$2();
79 $[1] = t1$11;
80 } else {
compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md
+2 -2
@@ -46,11 +46,11 @@ function component(
46 function component$0() {
47 const $ = React.useMemoCache();
48 let x$4;
49 - if (true) {
49 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
50 x$4 = {};
51 let q$5;
52
53 - if (true) {
53 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
54 q$5 = {};
55 $[1] = q$5;
56 } else {
compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md
+2 -2
@@ -63,7 +63,7 @@ function component(
63 function component$0() {
64 const $ = React.useMemoCache();
65 let p$7;
66 - if (true) {
66 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
67 p$7 = makePrimitive$2();
68 $[0] = p$7;
69 } else {
@@ -73,7 +73,7 @@ function component$0() {
73 p$7 + p$7;
74 let o$8;
75
76 - if (true) {
76 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
77 o$8 = {};
78 $[1] = o$8;
79 } else {
compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md
+6 -16
@@ -45,13 +45,9 @@ function component(
45 }
46 [3] Const mutate $9:TPrimitive = Binary read x$7_@0:TPrimitive > read y$8_@1:TPrimitive
47 if (read $9:TPrimitive) {
48 - scope @2 [5:6] deps=[] out=[] {
49 - [5] Const mutate z$10_@2:TObject = Object { }
50 - }
51 - }
52 - scope @3 [7:8] deps=[] out=[] {
53 - [7] Const mutate z$12_@3 = Call mutate foo$2:TFunction()
48 + [5] Const mutate z$10_@2:TObject = Object { }
49 }
50 + [7] Const mutate z$12_@3 = Call mutate foo$2:TFunction()
51 return
52 }
53
@@ -63,7 +59,7 @@ function component(
59 function component$0() {
60 const $ = React.useMemoCache();
61 let x$7;
66 - if (true) {
62 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
63 x$7 = foo$2();
64 $[0] = x$7;
65 } else {
@@ -72,7 +68,7 @@ function component$0() {
68
69 let y$8;
70
75 - if (true) {
71 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
72 y$8 = foo$2();
73 $[1] = y$8;
74 } else {
@@ -80,16 +76,10 @@ function component$0() {
76 }
77
78 if (x$7 > y$8) {
83 - if (true) {
84 - const z$10 = {};
85 - } else {
86 - }
79 + const z$10 = {};
80 }
81
89 - if (true) {
90 - const z$12 = foo$2();
91 - } else {
92 - }
82 + const z$12 = foo$2();
83 }
84
85 ```