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

Run LeaveSSA prior to analyzing reactive scopes

Reorders LeaveSSA so that it runs before we begin evaluating reactive scopes. Note that reactive scopes must span the full construction of each variable — for variables with a phi, this must span the declaration and all assignments of the phi operands. And that's exactly what the new LeaveSSA does! LeaveSSA removes phi nodes and ensure that all versions of a variable which flow into a phi have been assigned a single canonical identifier (with an appropriate mutable range). This PR includes this and some related changes: * Reorders the pass * Changes hir-test to print the final HIR, eg just prior to codegen * Teaches LeaveSSA to update the mutable range of the canonical identifiers it assigns, based on the min/max of the variables assigned.

Joseph Savona committed Dec 9, 2022 at 07:39 UTC d03c5bc0a0a3ffa16f6c9cf4834bbe2212c3d11c
62 files changed +657 -524
compiler/forget/packages/playground/components/Editor/Output.tsx
+8 -8
@@ -87,6 +87,9 @@ function compile(source: string): CompilerOutput | CompilerError {
87 inferMutableRanges(ir);
88 const inferMutableRangesOutput = printHIR(ir.body);
89
90 + leaveSSA(ir);
91 + const leaveSSAOutput = printHIR(ir.body);
92 +
93 inferReactiveScopeVariables(ir);
94 const inferReactiveScopeVariablesOutput = printHIR(ir.body);
95
@@ -96,9 +99,6 @@ function compile(source: string): CompilerOutput | CompilerError {
99 inferReactiveScopeDependencies(ir);
100 const inferReactiveScopeDependenciesOutput = printHIR(ir.body);
101
99 - leaveSSA(ir);
100 - const leaveSSAOutput = printHIR(ir.body);
101 -
102 codegen(ir);
103 const ast = codegen(ir);
104 const generated = generate(
@@ -183,6 +183,11 @@ function Output({ store, setTabsOpen, tabsOpen }: Props) {
183 output={compilerOutput.inferMutableRangesOutput}
184 ></TextTabContent>
185 ),
186 + LeaveSSA: (
187 + <TextTabContent
188 + output={compilerOutput.leaveSSAOutput}
189 + ></TextTabContent>
190 + ),
191 InferReactiveScopeVariables: (
192 <TextTabContent
193 output={compilerOutput.inferReactiveScopeVariablesOutput}
@@ -198,11 +203,6 @@ function Output({ store, setTabsOpen, tabsOpen }: Props) {
203 output={compilerOutput.inferReactiveScopeDependenciesOutput}
204 ></TextTabContent>
205 ),
201 - LeaveSSA: (
202 - <TextTabContent
203 - output={compilerOutput.leaveSSAOutput}
204 - ></TextTabContent>
205 - ),
206 JS: <TextTabContent output={compilerOutput.codegenOutput} />,
207 SourceMap: (
208 <>
compiler/forget/src/HIR/InferReactiveScopeVariables.ts
+5 -4
@@ -5,6 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 +import invariant from "invariant";
9 import DisjointSet from "./DisjointSet";
10 import {
11 HIRFunction,
@@ -68,10 +69,10 @@ export function inferReactiveScopeVariables(fn: HIRFunction) {
69 // that mutate together.
70 const scopeIdentifiers = new DisjointSet<Identifier>();
71 for (const [_, block] of fn.body.blocks) {
71 - for (const phi of block.phis) {
72 - const operands: Array<Identifier> = [phi.id, ...phi.operands.values()];
73 - scopeIdentifiers.union(operands);
74 - }
72 + invariant(
73 + block.phis.size === 0,
74 + "Expected phis to be cleared by LeaveSSA pass"
75 + );
76
77 for (const instr of block.instructions) {
78 const operands: Array<Identifier> = [];
compiler/forget/src/HIR/LeaveSSA.ts
+44 -6
@@ -11,8 +11,11 @@ import {
11 HIRFunction,
12 Identifier,
13 Instruction,
14 + InstructionId,
15 InstructionKind,
16 + makeInstructionId,
17 Phi,
18 + Place,
19 } from "./HIR";
20 import { eachInstructionValueOperand, eachTerminalOperand } from "./visitors";
21
@@ -28,6 +31,7 @@ export function leaveSSA(fn: HIRFunction) {
31 // Maps identifiers that appear as a phi or phi operand to a single canonical identifier
32 // for all instances.
33 const variableMapping: Map<Identifier, Identifier> = new Map();
34 + const hasDeclaration: Set<Identifier> = new Set();
35
36 for (const [, block] of fn.body.blocks) {
37 // Identifiers (from phis) that *may* need a new `let` declaration created. If the original
@@ -78,13 +82,28 @@ export function leaveSSA(fn: HIRFunction) {
82 canonicalId = operand;
83 }
84 }
85 + canonicalId.mutableRange.start = Math.min(
86 + canonicalId.mutableRange.start,
87 + terminal.id
88 + ) as InstructionId;
89 variableMapping.set(phi.id, canonicalId);
82 - needsDeclaration.add(canonicalId);
90 + if (!hasDeclaration.has(canonicalId)) {
91 + needsDeclaration.add(canonicalId);
92 + }
93 }
94 +
95 // all versions of the variable need to be remapped to the canonical id
96 + // also extend the mutable range of the canonical id based on the min/max
97 + // of the ranges of its operands
98 + let start = canonicalId.mutableRange.start as number;
99 + let end = canonicalId.mutableRange.end as number;
100 for (const [, operand] of phi.operands) {
101 + start = Math.min(start, operand.mutableRange.start);
102 + end = Math.max(end, operand.mutableRange.end);
103 variableMapping.set(operand, canonicalId);
104 }
105 + canonicalId.mutableRange.start = makeInstructionId(start);
106 + canonicalId.mutableRange.end = makeInstructionId(end);
107 }
108
109 // Visit instructions and rewrite identifiers based on the variable mapping
@@ -92,9 +111,7 @@ export function leaveSSA(fn: HIRFunction) {
111 for (const instr of block.instructions) {
112 const { lvalue, value } = instr;
113 if (lvalue !== null) {
95 - lvalue.place.identifier =
96 - variableMapping.get(lvalue.place.identifier) ??
97 - lvalue.place.identifier;
114 + updatePlace(lvalue.place, variableMapping);
115 if (lvalue.place.memberPath === null) {
116 if (!variableMapping.has(lvalue.place.identifier)) {
117 // This variable does not flow into a phi, therefore there
@@ -109,11 +126,11 @@ export function leaveSSA(fn: HIRFunction) {
126 // reassign the variable in the first place.
127 needsDeclaration.delete(lvalue.place.identifier);
128 }
129 + hasDeclaration.add(lvalue.place.identifier);
130 }
131 }
132 for (const operand of eachInstructionValueOperand(value)) {
115 - operand.identifier =
116 - variableMapping.get(operand.identifier) ?? operand.identifier;
133 + updatePlace(operand, variableMapping);
134 }
135 }
136
@@ -151,3 +168,24 @@ export function leaveSSA(fn: HIRFunction) {
168 block.phis.clear();
169 }
170 }
171 +
172 +function updatePlace(
173 + place: Place,
174 + variableMapping: Map<Identifier, Identifier>
175 +) {
176 + const prevIdentifier = place.identifier;
177 + const nextIdentifier = variableMapping.get(prevIdentifier);
178 + if (nextIdentifier === undefined || nextIdentifier === prevIdentifier) {
179 + return;
180 + }
181 + nextIdentifier.mutableRange.start = makeInstructionId(
182 + Math.min(
183 + nextIdentifier.mutableRange.start,
184 + prevIdentifier.mutableRange.start
185 + )
186 + );
187 + nextIdentifier.mutableRange.end = makeInstructionId(
188 + Math.max(nextIdentifier.mutableRange.end, prevIdentifier.mutableRange.end)
189 + );
190 + place.identifier = nextIdentifier;
191 +}
compiler/forget/src/HIR/Pipeline.ts
+3 -3
@@ -51,6 +51,9 @@ export default function (
51 if (flags.inferMutableRanges) {
52 inferMutableRanges(ir);
53 }
54 + if (flags.leaveSSA) {
55 + leaveSSA(ir);
56 + }
57 if (flags.inferReactiveScopeVariables) {
58 inferReactiveScopeVariables(ir);
59 }
@@ -60,9 +63,6 @@ export default function (
63 if (flags.inferReactiveScopeDependencies) {
64 inferReactiveScopeDependencies(ir);
65 }
63 - if (flags.leaveSSA) {
64 - leaveSSA(ir);
65 - }
66 if (flags.codegen) {
67 return {
68 ast: codegen(ir),
compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md
+4 -4
@@ -15,8 +15,8 @@ function f() {
15
16 ```
17 bb0:
18 - [1] Let mutate x$4_@0 = 1
19 - [2] Reassign mutate x$5_@1 = 2
18 + [1] Const mutate x$4_@0 = 1
19 + [2] Const mutate x$5_@1 = 2
20 [3] Const mutate $6_@2 = Binary read x$5_@1 + read x$5_@1
21 [4] Const mutate $7_@3 = Binary read $6_@2 + read x$5_@1
22 [5] Return read $7_@3
@@ -35,8 +35,8 @@ flowchart TB
35 %% Basic Blocks
36 subgraph bb0
37 bb0_instrs["
38 - [1] Let mutate x$4_@0 = 1
39 - [2] Reassign mutate x$5_@1 = 2
38 + [1] Const mutate x$4_@0 = 1
39 + [2] Const mutate x$5_@1 = 2
40 [3] Const mutate $6_@2 = Binary read x$5_@1 + read x$5_@1
41 [4] Const mutate $7_@3 = Binary read $6_@2 + read x$5_@1
42 "]
compiler/forget/src/__tests__/fixtures/hir/_bug_inverted-if-else.expect.md
+10 -11
@@ -20,23 +20,22 @@ function foo(a, b, c) {
20
21 ```
22 bb0:
23 - [1] Let mutate x$8_@0 = null
23 + [1] Const mutate x$8_@0 = null
24 [2] If (read a$5) then:bb3 else:bb2 fallthrough=bb2
25 bb3:
26 predecessor blocks: bb0
27 - [3] Reassign mutate x$9_@1[3:6] = read b$6
27 + [3] Const mutate x$9_@1 = read b$6
28 [4] Goto bb1
29 bb2:
30 predecessor blocks: bb0
31 - [5] Reassign mutate x$10_@1[3:6] = read c$7
31 + [5] Const mutate x$10_@2 = read c$7
32 [6] Goto bb1
33 bb1:
34 predecessor blocks: bb3 bb2
35 - x$11_@1[3:6]: phi(bb3: x$9_@1, bb2: x$10_@1)
36 - [7] Return read x$11_@1
37 -scope1 [3:6]:
35 + [7] Return read x$11
36 +scope1 [3:4]:
37 - read b$6
39 - - read a$5
38 +scope2 [5:6]:
39 - read c$7
40 ```
41
@@ -47,24 +46,24 @@ flowchart TB
46 %% Basic Blocks
47 subgraph bb0
48 bb0_instrs["
50 - [1] Let mutate x$8_@0 = null
49 + [1] Const mutate x$8_@0 = null
50 "]
51 bb0_instrs --> bb0_terminal(["If (read a$5)"])
52 end
53 subgraph bb3
54 bb3_instrs["
56 - [3] Reassign mutate x$9_@1[3:6] = read b$6
55 + [3] Const mutate x$9_@1 = read b$6
56 "]
57 bb3_instrs --> bb3_terminal(["Goto"])
58 end
59 subgraph bb2
60 bb2_instrs["
62 - [5] Reassign mutate x$10_@1[3:6] = read c$7
61 + [5] Const mutate x$10_@2 = read c$7
62 "]
63 bb2_instrs --> bb2_terminal(["Goto"])
64 end
65 subgraph bb1
67 - bb1_terminal(["Return read x$11_@1"])
66 + bb1_terminal(["Return read x$11"])
67 end
68
69 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md
+18 -21
@@ -33,24 +33,21 @@ bb0:
33 [4] While test=bb1 loop=bb3 fallthrough=bb2
34 bb1:
35 predecessor blocks: bb0 bb3
36 - a$12_@0[0:12]: phi(bb0: a$8_@0, bb3: a$15_@0)
37 - b$14_@0[0:12]: phi(bb0: b$9_@0, bb3: b$17_@0)
38 - c$16_@0[0:12]: phi(bb0: c$10_@0, bb3: c$18_@0)
36 [5] If (read cond$7) then:bb3 else:bb2 fallthrough=bb2
37 bb3:
38 predecessor blocks: bb1
42 - [6] Let mutate z$13_@0[0:12] = read a$12_@0
43 - [7] Reassign mutate a$15_@0[0:12] = read b$14_@0
44 - [8] Reassign mutate b$17_@0[0:12] = read c$16_@0
45 - [9] Reassign mutate c$18_@0[0:12] = read z$13_@0
46 - [10] Call mutate mutate$6_@0(mutate a$15_@0, mutate b$17_@0)
39 + [6] Const mutate z$13_@0[0:12] = read a$8_@0
40 + [7] Reassign mutate a$8_@0[0:12] = read b$9_@0
41 + [8] Reassign mutate b$9_@0[0:12] = read c$10_@0
42 + [9] Reassign mutate c$10_@0[0:12] = read z$13_@0
43 + [10] Call mutate mutate$6_@0(mutate a$8_@0, mutate b$9_@0)
44 [11] Goto(Continue) bb1
45 bb2:
46 predecessor blocks: bb1
50 - [12] read a$12_@0
51 - [13] read b$14_@0
52 - [14] read c$16_@0
53 - [15] Return freeze a$12_@0
47 + [12] read a$8_@0
48 + [13] read b$9_@0
49 + [14] read c$10_@0
50 + [15] Return freeze a$8_@0
51
52 ```
53
@@ -72,21 +69,21 @@ flowchart TB
69 end
70 subgraph bb3
71 bb3_instrs["
75 - [6] Let mutate z$13_@0[0:12] = read a$12_@0
76 - [7] Reassign mutate a$15_@0[0:12] = read b$14_@0
77 - [8] Reassign mutate b$17_@0[0:12] = read c$16_@0
78 - [9] Reassign mutate c$18_@0[0:12] = read z$13_@0
79 - [10] Call mutate mutate$6_@0(mutate a$15_@0, mutate b$17_@0)
72 + [6] Const mutate z$13_@0[0:12] = read a$8_@0
73 + [7] Reassign mutate a$8_@0[0:12] = read b$9_@0
74 + [8] Reassign mutate b$9_@0[0:12] = read c$10_@0
75 + [9] Reassign mutate c$10_@0[0:12] = read z$13_@0
76 + [10] Call mutate mutate$6_@0(mutate a$8_@0, mutate b$9_@0)
77 "]
78 bb3_instrs --> bb3_terminal(["Goto"])
79 end
80 subgraph bb2
81 bb2_instrs["
85 - [12] read a$12_@0
86 - [13] read b$14_@0
87 - [14] read c$16_@0
82 + [12] read a$8_@0
83 + [13] read b$9_@0
84 + [14] read c$10_@0
85 "]
89 - bb2_instrs --> bb2_terminal(["Return freeze a$12_@0"])
86 + bb2_instrs --> bb2_terminal(["Return freeze a$8_@0"])
87 end
88
89 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md
+8 -8
@@ -20,13 +20,13 @@ function g(a) {
20
21 ```
22 bb0:
23 - [1] Let mutate x$5_@0 = 1
23 + [1] Const mutate x$5_@0 = 1
24 [2] Const mutate $6_@1 = 1
25 - [3] Reassign mutate x$7_@2 = Binary read x$5_@0 + read $6_@1
25 + [3] Const mutate x$7_@2 = Binary read x$5_@0 + read $6_@1
26 [4] Const mutate $8_@3 = 1
27 - [5] Reassign mutate x$9_@4 = Binary read x$7_@2 + read $8_@3
27 + [5] Const mutate x$9_@4 = Binary read x$7_@2 + read $8_@3
28 [6] Const mutate $10_@5 = 1
29 - [7] Reassign mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5
29 + [7] Const mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5
30 [8] Return
31 scope2 [3:4]:
32 - read x$5_@0
@@ -46,13 +46,13 @@ flowchart TB
46 %% Basic Blocks
47 subgraph bb0
48 bb0_instrs["
49 - [1] Let mutate x$5_@0 = 1
49 + [1] Const mutate x$5_@0 = 1
50 [2] Const mutate $6_@1 = 1
51 - [3] Reassign mutate x$7_@2 = Binary read x$5_@0 + read $6_@1
51 + [3] Const mutate x$7_@2 = Binary read x$5_@0 + read $6_@1
52 [4] Const mutate $8_@3 = 1
53 - [5] Reassign mutate x$9_@4 = Binary read x$7_@2 + read $8_@3
53 + [5] Const mutate x$9_@4 = Binary read x$7_@2 + read $8_@3
54 [6] Const mutate $10_@5 = 1
55 - [7] Reassign mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5
55 + [7] Const mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5
56 "]
57 bb0_instrs --> bb0_terminal(["Return"])
58 end
compiler/forget/src/__tests__/fixtures/hir/call.expect.md
+2 -2
@@ -50,7 +50,7 @@ bb0:
50 [2] Const mutate b$11_@0[0:7] = Object { }
51 [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0)
52 [4] Const mutate $12_@1 = "div"
53 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
53 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
54 [6] Call mutate foo$4_@0(mutate b$11_@0)
55 [7] Const mutate $14_@3 = "div"
56 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
@@ -74,7 +74,7 @@ flowchart TB
74 [2] Const mutate b$11_@0[0:7] = Object { }
75 [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0)
76 [4] Const mutate $12_@1 = 'div'
77 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
77 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
78 [6] Call mutate foo$4_@0(mutate b$11_@0)
79 [7] Const mutate $14_@3 = 'div'
80 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+6 -5
@@ -49,6 +49,7 @@ bb3:
49 predecessor blocks: bb1
50 [9] Const mutate $34_@6 = null
51 [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6
52 + [11] Let mutate $37_@3[0:19] = undefined
53 [11] If (read $36_@3) then:bb8 else:bb9 fallthrough=bb7
54 bb8:
55 predecessor blocks: bb3
@@ -56,12 +57,11 @@ bb8:
57 [13] Goto bb7
58 bb9:
59 predecessor blocks: bb3
59 - [14] Const mutate $39_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
60 + [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
61 [15] Goto bb7
62 bb7:
63 predecessor blocks: bb8 bb9
63 - $40_@3[0:19]: phi(bb8: $37_@3, bb9: $39_@3)
64 - [16] If (read $40_@3) then:bb5 else:bb4 fallthrough=bb4
64 + [16] If (read $37_@3) then:bb5 else:bb4 fallthrough=bb4
65 bb5:
66 predecessor blocks: bb7
67 [17] Goto(Continue) bb1
@@ -117,6 +117,7 @@ flowchart TB
117 bb3_instrs["
118 [9] Const mutate $34_@6 = null
119 [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6
120 + [11] Let mutate $37_@3[0:19] = undefined
121 "]
122 bb3_instrs --> bb3_terminal(["If (read $36_@3)"])
123 end
@@ -128,12 +129,12 @@ flowchart TB
129 end
130 subgraph bb9
131 bb9_instrs["
131 - [14] Const mutate $39_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
132 + [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
133 "]
134 bb9_instrs --> bb9_terminal(["Goto"])
135 end
136 subgraph bb7
136 - bb7_terminal(["If (read $40_@3)"])
137 + bb7_terminal(["If (read $37_@3)"])
138 end
139 subgraph bb5
140 bb5_terminal(["Goto"])
compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md
+2 -2
@@ -50,7 +50,7 @@ bb0:
50 [2] Const mutate b$11_@0[0:7] = Object { }
51 [3] New mutate Foo$4_@0(mutate a$10_@0, mutate b$11_@0)
52 [4] Const mutate $12_@1 = "div"
53 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
53 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
54 [6] New mutate Foo$4_@0(mutate b$11_@0)
55 [7] Const mutate $14_@3 = "div"
56 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
@@ -74,7 +74,7 @@ flowchart TB
74 [2] Const mutate b$11_@0[0:7] = Object { }
75 [3] New mutate Foo$4_@0(mutate a$10_@0, mutate b$11_@0)
76 [4] Const mutate $12_@1 = 'div'
77 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
77 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
78 [6] New mutate Foo$4_@0(mutate b$11_@0)
79 [7] Const mutate $14_@3 = 'div'
80 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md
+2 -2
@@ -23,7 +23,7 @@ function foo(a, b, c) {
23
24 ```
25 bb0:
26 - [1] Let mutate x$10_@0[1:8] = Array []
26 + [1] Const mutate x$10_@0[1:8] = Array []
27 [2] If (read a$7) then:bb2 else:bb1 fallthrough=bb1
28 bb2:
29 predecessor blocks: bb0
@@ -59,7 +59,7 @@ flowchart TB
59 %% Basic Blocks
60 subgraph bb0
61 bb0_instrs["
62 - [1] Let mutate x$10_@0[1:8] = Array []
62 + [1] Const mutate x$10_@0[1:8] = Array []
63 "]
64 bb0_instrs --> bb0_terminal(["If (read a$7)"])
65 end
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md
+18 -16
@@ -28,29 +28,30 @@ function call(x) {}
28 bb0:
29 [1] Const mutate cond$8_@0 = read props$7.cond
30 [2] Const mutate x$9_@1 = read props$7.x
31 - [3] Let mutate a$10_@2 = undefined
31 + [3] Const mutate a$10_@2 = undefined
32 + [4] Let mutate a$11_@3[4:9] = undefined
33 [4] If (read cond$8_@0) then:bb2 else:bb3 fallthrough=bb1
34 bb2:
35 predecessor blocks: bb0
35 - [5] Reassign mutate a$11_@3[5:8] = read x$9_@1
36 + [5] Reassign mutate a$11_@3[4:9] = read x$9_@1
37 [6] Goto bb1
38 bb3:
39 predecessor blocks: bb0
39 - [7] Reassign mutate a$12_@3[5:8] = Array []
40 + [7] Reassign mutate a$11_@3[4:9] = Array []
41 [8] Goto bb1
42 bb1:
43 predecessor blocks: bb2 bb3
43 - a$14_@3[5:8]: phi(bb2: a$11_@3, bb3: a$12_@3)
44 - [9] Call read useFreeze$5(freeze a$14_@3)
45 - [10] Call read useFreeze$5(read a$14_@3)
46 - [11] Call mutate call$6_@4(read a$14_@3)
47 - [12] Return read a$14_@3
44 + [9] Call read useFreeze$5(freeze a$11_@3)
45 + [10] Call read useFreeze$5(read a$11_@3)
46 + [11] Call mutate call$6_@4(read a$11_@3)
47 + [12] Return read a$11_@3
48 scope0 [1:2]:
49 - read props$7.cond
50 scope1 [2:3]:
51 - read props$7.x
52 -scope3 [5:8]:
52 +scope3 [4:9]:
53 - read x$9_@1
54 + - read cond$8_@0
55 ```
56
57 ### CFG
@@ -62,29 +63,30 @@ flowchart TB
63 bb0_instrs["
64 [1] Const mutate cond$8_@0 = read props$7.cond
65 [2] Const mutate x$9_@1 = read props$7.x
65 - [3] Let mutate a$10_@2 = undefined
66 + [3] Const mutate a$10_@2 = undefined
67 + [4] Let mutate a$11_@3[4:9] = undefined
68 "]
69 bb0_instrs --> bb0_terminal(["If (read cond$8_@0)"])
70 end
71 subgraph bb2
72 bb2_instrs["
71 - [5] Reassign mutate a$11_@3[5:8] = read x$9_@1
73 + [5] Reassign mutate a$11_@3[4:9] = read x$9_@1
74 "]
75 bb2_instrs --> bb2_terminal(["Goto"])
76 end
77 subgraph bb3
78 bb3_instrs["
77 - [7] Reassign mutate a$12_@3[5:8] = Array []
79 + [7] Reassign mutate a$11_@3[4:9] = Array []
80 "]
81 bb3_instrs --> bb3_terminal(["Goto"])
82 end
83 subgraph bb1
84 bb1_instrs["
83 - [9] Call read useFreeze$5(freeze a$14_@3)
84 - [10] Call read useFreeze$5(read a$14_@3)
85 - [11] Call mutate call$6_@4(read a$14_@3)
85 + [9] Call read useFreeze$5(freeze a$11_@3)
86 + [10] Call read useFreeze$5(read a$11_@3)
87 + [11] Call mutate call$6_@4(read a$11_@3)
88 "]
87 - bb1_instrs --> bb1_terminal(["Return read a$14_@3"])
89 + bb1_instrs --> bb1_terminal(["Return read a$11_@3"])
90 end
91
92 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md
+2 -2
@@ -18,7 +18,7 @@ function foo(a, b, c) {
18
19 ```
20 bb0:
21 - [1] Let mutate y$8_@0[1:6] = Array []
21 + [1] Const mutate y$8_@0[1:6] = Array []
22 [2] If (read a$5) then:bb3 else:bb1 fallthrough=bb1
23 bb3:
24 predecessor blocks: bb0
@@ -43,7 +43,7 @@ flowchart TB
43 %% Basic Blocks
44 subgraph bb0
45 bb0_instrs["
46 - [1] Let mutate y$8_@0[1:6] = Array []
46 + [1] Const mutate y$8_@0[1:6] = Array []
47 "]
48 bb0_instrs --> bb0_terminal(["If (read a$5)"])
49 end
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
+24 -21
@@ -24,19 +24,19 @@ function g() {}
24 ```
25 bb0:
26 [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
27 + [2] Let mutate $6_@1[0:7] = undefined
28 [2] If (read $5_@0) then:bb2 else:bb3 fallthrough=bb1
29 bb2:
30 predecessor blocks: bb0
30 - [3] Const mutate $6_@1[0:6] = Call mutate g$4_@1()
31 + [3] Const mutate $6_@1[0:7] = Call mutate g$4_@1()
32 [4] Goto bb1
33 bb3:
34 predecessor blocks: bb0
34 - [5] Const mutate $7_@1[0:6] = read $5_@0
35 + [5] Const mutate $6_@1[0:7] = read $5_@0
36 [6] Goto bb1
37 bb1:
38 predecessor blocks: bb2 bb3
38 - $8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1)
39 - [7] Return freeze $8_@1
39 + [7] Return freeze $6_@1
40
41 ```
42
@@ -48,23 +48,24 @@ flowchart TB
48 subgraph bb0
49 bb0_instrs["
50 [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
51 + [2] Let mutate $6_@1[0:7] = undefined
52 "]
53 bb0_instrs --> bb0_terminal(["If (read $5_@0)"])
54 end
55 subgraph bb2
56 bb2_instrs["
56 - [3] Const mutate $6_@1[0:6] = Call mutate g$4_@1()
57 + [3] Const mutate $6_@1[0:7] = Call mutate g$4_@1()
58 "]
59 bb2_instrs --> bb2_terminal(["Goto"])
60 end
61 subgraph bb3
62 bb3_instrs["
62 - [5] Const mutate $7_@1[0:6] = read $5_@0
63 + [5] Const mutate $6_@1[0:7] = read $5_@0
64 "]
65 bb3_instrs --> bb3_terminal(["Goto"])
66 end
67 subgraph bb1
67 - bb1_terminal(["Return freeze $8_@1"])
68 + bb1_terminal(["Return freeze $6_@1"])
69 end
70
71 %% Jumps
@@ -92,19 +93,19 @@ function And$0() {
93 ```
94 bb0:
95 [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
96 + [2] Let mutate $6_@1[0:7] = undefined
97 [2] If (read $5_@0) then:bb2 else:bb3 fallthrough=bb1
98 bb2:
99 predecessor blocks: bb0
98 - [3] Const mutate $6_@1[0:6] = read $5_@0
100 + [3] Const mutate $6_@1[0:7] = read $5_@0
101 [4] Goto bb1
102 bb3:
103 predecessor blocks: bb0
102 - [5] Const mutate $7_@1[0:6] = Call mutate g$4_@1()
104 + [5] Const mutate $6_@1[0:7] = Call mutate g$4_@1()
105 [6] Goto bb1
106 bb1:
107 predecessor blocks: bb2 bb3
106 - $8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1)
107 - [7] Return freeze $8_@1
108 + [7] Return freeze $6_@1
109
110 ```
111
@@ -116,23 +117,24 @@ flowchart TB
117 subgraph bb0
118 bb0_instrs["
119 [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
120 + [2] Let mutate $6_@1[0:7] = undefined
121 "]
122 bb0_instrs --> bb0_terminal(["If (read $5_@0)"])
123 end
124 subgraph bb2
125 bb2_instrs["
124 - [3] Const mutate $6_@1[0:6] = read $5_@0
126 + [3] Const mutate $6_@1[0:7] = read $5_@0
127 "]
128 bb2_instrs --> bb2_terminal(["Goto"])
129 end
130 subgraph bb3
131 bb3_instrs["
130 - [5] Const mutate $7_@1[0:6] = Call mutate g$4_@1()
132 + [5] Const mutate $6_@1[0:7] = Call mutate g$4_@1()
133 "]
134 bb3_instrs --> bb3_terminal(["Goto"])
135 end
136 subgraph bb1
135 - bb1_terminal(["Return freeze $8_@1"])
137 + bb1_terminal(["Return freeze $6_@1"])
138 end
139
140 %% Jumps
@@ -162,19 +164,19 @@ bb0:
164 [1] Const mutate $9_@0[0:2] = Call mutate f$2_@0()
165 [2] Const mutate $10_@1 = null
166 [3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1
167 + [4] Let mutate $12_@3[0:9] = undefined
168 [4] If (read $11_@2) then:bb2 else:bb3 fallthrough=bb1
169 bb2:
170 predecessor blocks: bb0
168 - [5] Const mutate $12_@3[0:8] = read $9_@0
171 + [5] Const mutate $12_@3[0:9] = read $9_@0
172 [6] Goto bb1
173 bb3:
174 predecessor blocks: bb0
172 - [7] Const mutate $13_@3[0:8] = Call mutate g$7_@3()
175 + [7] Const mutate $12_@3[0:9] = Call mutate g$7_@3()
176 [8] Goto bb1
177 bb1:
178 predecessor blocks: bb2 bb3
176 - $14_@3[0:8]: phi(bb2: $12_@3, bb3: $13_@3)
177 - [9] Return freeze $14_@3
179 + [9] Return freeze $12_@3
180 scope2 [3:4]:
181 - read $9_@0
182 - read $10_@1
@@ -190,23 +192,24 @@ flowchart TB
192 [1] Const mutate $9_@0[0:2] = Call mutate f$2_@0()
193 [2] Const mutate $10_@1 = null
194 [3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1
195 + [4] Let mutate $12_@3[0:9] = undefined
196 "]
197 bb0_instrs --> bb0_terminal(["If (read $11_@2)"])
198 end
199 subgraph bb2
200 bb2_instrs["
198 - [5] Const mutate $12_@3[0:8] = read $9_@0
201 + [5] Const mutate $12_@3[0:9] = read $9_@0
202 "]
203 bb2_instrs --> bb2_terminal(["Goto"])
204 end
205 subgraph bb3
206 bb3_instrs["
204 - [7] Const mutate $13_@3[0:8] = Call mutate g$7_@3()
207 + [7] Const mutate $12_@3[0:9] = Call mutate g$7_@3()
208 "]
209 bb3_instrs --> bb3_terminal(["Goto"])
210 end
211 subgraph bb1
209 - bb1_terminal(["Return freeze $14_@3"])
212 + bb1_terminal(["Return freeze $12_@3"])
213 end
214
215 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
+32 -40
@@ -97,52 +97,44 @@ function cond$0(x$2) {}
97
98 ```
99 bb0:
100 - [1] Let mutate a$13_@0[0:23] = Object { }
101 - [2] Let mutate b$14_@0[0:23] = Object { }
102 - [3] Let mutate c$15_@0[0:23] = Object { }
103 - [4] Let mutate d$16_@0[0:23] = Object { }
100 + [1] Let mutate a$18_@0[0:23] = Object { }
101 + [2] Let mutate b$20_@0[0:23] = Object { }
102 + [3] Let mutate c$22_@0[0:23] = Object { }
103 + [4] Let mutate d$24_@0[0:23] = Object { }
104 [5] While test=bb1 loop=bb3 fallthrough=bb2
105 bb1:
106 predecessor blocks: bb0 bb4
107 - a$18_@0[0:23]: phi(bb0: a$13_@0, bb4: a$21_@0)
108 - b$20_@0[0:23]: phi(bb0: b$14_@0, bb4: b$23_@0)
109 - c$22_@0[0:23]: phi(bb0: c$15_@0, bb4: c$25_@0)
110 - d$24_@0[0:23]: phi(bb0: d$16_@0, bb4: d$26_@0)
107 [6] Const mutate $17_@1[6:8] = true
108 [7] If (read $17_@1) then:bb3 else:bb2 fallthrough=bb2
109 bb3:
110 predecessor blocks: bb1
115 - [8] Let mutate z$19_@0[0:23] = read a$18_@0
116 - [9] Reassign mutate a$21_@0[0:23] = read b$20_@0
117 - [10] Reassign mutate b$23_@0[0:23] = read c$22_@0
118 - [11] Reassign mutate c$25_@0[0:23] = read d$24_@0
119 - [12] Reassign mutate d$26_@0[0:23] = read z$19_@0
120 - [13] Call mutate mutate$7_@0(mutate a$21_@0, mutate b$23_@0)
121 - [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$21_@0)
111 + [8] Const mutate z$19_@0[0:23] = read a$18_@0
112 + [9] Reassign mutate a$18_@0[0:23] = read b$20_@0
113 + [10] Reassign mutate b$20_@0[0:23] = read c$22_@0
114 + [11] Reassign mutate c$22_@0[0:23] = read d$24_@0
115 + [12] Reassign mutate d$24_@0[0:23] = read z$19_@0
116 + [13] Call mutate mutate$7_@0(mutate a$18_@0, mutate b$20_@0)
117 + [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$18_@0)
118 [15] If (read $29_@0) then:bb2 else:bb4 fallthrough=bb4
119 bb4:
120 predecessor blocks: bb3
121 [16] Goto(Continue) bb1
122 bb2:
123 predecessor blocks: bb3 bb1
128 - a$30_@0[0:23]: phi(bb3: a$21_@0, bb1: a$18_@0)
129 - b$31_@0[0:23]: phi(bb3: b$23_@0, bb1: b$20_@0)
130 - c$32_@0[0:23]: phi(bb3: c$25_@0, bb1: c$22_@0)
131 - d$33_@0[0:23]: phi(bb3: d$26_@0, bb1: d$24_@0)
132 - [17] If (read a$30_@0) then:bb7 else:bb7 fallthrough=bb7
124 + [17] If (read a$18_@0) then:bb7 else:bb7 fallthrough=bb7
125 bb7:
126 predecessor blocks: bb2
135 - [18] If (read b$31_@0) then:bb9 else:bb9 fallthrough=bb9
127 + [18] If (read b$20_@0) then:bb9 else:bb9 fallthrough=bb9
128 bb9:
129 predecessor blocks: bb7
138 - [19] If (read c$32_@0) then:bb11 else:bb11 fallthrough=bb11
130 + [19] If (read c$22_@0) then:bb11 else:bb11 fallthrough=bb11
131 bb11:
132 predecessor blocks: bb9
141 - [20] If (read d$33_@0) then:bb13 else:bb13 fallthrough=bb13
133 + [20] If (read d$24_@0) then:bb13 else:bb13 fallthrough=bb13
134 bb13:
135 predecessor blocks: bb11
136 [21] Const mutate $34_@2 = null
145 - [22] Call mutate mutate$7_@0(mutate d$33_@0, read $34_@2)
137 + [22] Call mutate mutate$7_@0(mutate d$24_@0, read $34_@2)
138 [23] Return
139
140 ```
@@ -154,10 +146,10 @@ flowchart TB
146 %% Basic Blocks
147 subgraph bb0
148 bb0_instrs["
157 - [1] Let mutate a$13_@0[0:23] = Object { }
158 - [2] Let mutate b$14_@0[0:23] = Object { }
159 - [3] Let mutate c$15_@0[0:23] = Object { }
160 - [4] Let mutate d$16_@0[0:23] = Object { }
149 + [1] Let mutate a$18_@0[0:23] = Object { }
150 + [2] Let mutate b$20_@0[0:23] = Object { }
151 + [3] Let mutate c$22_@0[0:23] = Object { }
152 + [4] Let mutate d$24_@0[0:23] = Object { }
153 "]
154 bb0_instrs --> bb0_terminal(["While"])
155 end
@@ -169,13 +161,13 @@ flowchart TB
161 end
162 subgraph bb3
163 bb3_instrs["
172 - [8] Let mutate z$19_@0[0:23] = read a$18_@0
173 - [9] Reassign mutate a$21_@0[0:23] = read b$20_@0
174 - [10] Reassign mutate b$23_@0[0:23] = read c$22_@0
175 - [11] Reassign mutate c$25_@0[0:23] = read d$24_@0
176 - [12] Reassign mutate d$26_@0[0:23] = read z$19_@0
177 - [13] Call mutate mutate$7_@0(mutate a$21_@0, mutate b$23_@0)
178 - [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$21_@0)
164 + [8] Const mutate z$19_@0[0:23] = read a$18_@0
165 + [9] Reassign mutate a$18_@0[0:23] = read b$20_@0
166 + [10] Reassign mutate b$20_@0[0:23] = read c$22_@0
167 + [11] Reassign mutate c$22_@0[0:23] = read d$24_@0
168 + [12] Reassign mutate d$24_@0[0:23] = read z$19_@0
169 + [13] Call mutate mutate$7_@0(mutate a$18_@0, mutate b$20_@0)
170 + [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$18_@0)
171 "]
172 bb3_instrs --> bb3_terminal(["If (read $29_@0)"])
173 end
@@ -183,21 +175,21 @@ flowchart TB
175 bb4_terminal(["Goto"])
176 end
177 subgraph bb2
186 - bb2_terminal(["If (read a$30_@0)"])
178 + bb2_terminal(["If (read a$18_@0)"])
179 end
180 subgraph bb7
189 - bb7_terminal(["If (read b$31_@0)"])
181 + bb7_terminal(["If (read b$20_@0)"])
182 end
183 subgraph bb9
192 - bb9_terminal(["If (read c$32_@0)"])
184 + bb9_terminal(["If (read c$22_@0)"])
185 end
186 subgraph bb11
195 - bb11_terminal(["If (read d$33_@0)"])
187 + bb11_terminal(["If (read d$24_@0)"])
188 end
189 subgraph bb13
190 bb13_instrs["
191 [21] Const mutate $34_@2 = null
200 - [22] Call mutate mutate$7_@0(mutate d$33_@0, read $34_@2)
192 + [22] Call mutate mutate$7_@0(mutate d$24_@0, read $34_@2)
193 "]
194 bb13_instrs --> bb13_terminal(["Return"])
195 end
compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md
+8 -8
@@ -92,10 +92,10 @@ function cond$0() {}
92
93 ```
94 bb0:
95 - [1] Let mutate a$12_@0[0:18] = Object { }
96 - [2] Let mutate b$13_@0[0:18] = Object { }
97 - [3] Let mutate c$14_@1 = Object { }
98 - [4] Let mutate d$15_@0[0:18] = Object { }
95 + [1] Const mutate a$12_@0[0:18] = Object { }
96 + [2] Const mutate b$13_@0[0:18] = Object { }
97 + [3] Const mutate c$14_@1 = Object { }
98 + [4] Const mutate d$15_@0[0:18] = Object { }
99 [5] While test=bb1 loop=bb3 fallthrough=bb2
100 bb1:
101 predecessor blocks: bb0 bb4
@@ -136,10 +136,10 @@ flowchart TB
136 %% Basic Blocks
137 subgraph bb0
138 bb0_instrs["
139 - [1] Let mutate a$12_@0[0:18] = Object { }
140 - [2] Let mutate b$13_@0[0:18] = Object { }
141 - [3] Let mutate c$14_@1 = Object { }
142 - [4] Let mutate d$15_@0[0:18] = Object { }
139 + [1] Const mutate a$12_@0[0:18] = Object { }
140 + [2] Const mutate b$13_@0[0:18] = Object { }
141 + [3] Const mutate c$14_@1 = Object { }
142 + [4] Const mutate d$15_@0[0:18] = Object { }
143 "]
144 bb0_instrs --> bb0_terminal(["While"])
145 end
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md
+4 -4
@@ -15,8 +15,8 @@ function foo(a, b) {
15
16 ```
17 bb0:
18 - [1] Let mutate x$7_@0[1:5] = Array []
19 - [2] Let mutate y$8_@0[1:5] = Array []
18 + [1] Const mutate x$7_@0[1:5] = Array []
19 + [2] Const mutate y$8_@0[1:5] = Array []
20 [3] Call mutate x$7_@0.push(read a$5)
21 [4] Call mutate y$8_@0.push(read b$6)
22 [5] Return
@@ -32,8 +32,8 @@ flowchart TB
32 %% Basic Blocks
33 subgraph bb0
34 bb0_instrs["
35 - [1] Let mutate x$7_@0[1:5] = Array []
36 - [2] Let mutate y$8_@0[1:5] = Array []
35 + [1] Const mutate x$7_@0[1:5] = Array []
36 + [2] Const mutate y$8_@0[1:5] = Array []
37 [3] Call mutate x$7_@0.push(read a$5)
38 [4] Call mutate y$8_@0.push(read b$6)
39 "]
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md
+4 -4
@@ -15,8 +15,8 @@ function foo(a, b) {
15
16 ```
17 bb0:
18 - [1] Let mutate x$7_@0[1:5] = Array []
19 - [2] Let mutate y$8_@1[2:4] = Array []
18 + [1] Const mutate x$7_@0[1:5] = Array []
19 + [2] Const mutate y$8_@1[2:4] = Array []
20 [3] Call mutate y$8_@1.push(read b$6)
21 [4] Call mutate x$7_@0.push(read a$5)
22 [5] Return
@@ -32,8 +32,8 @@ flowchart TB
32 %% Basic Blocks
33 subgraph bb0
34 bb0_instrs["
35 - [1] Let mutate x$7_@0[1:5] = Array []
36 - [2] Let mutate y$8_@1[2:4] = Array []
35 + [1] Const mutate x$7_@0[1:5] = Array []
36 + [2] Const mutate y$8_@1[2:4] = Array []
37 [3] Call mutate y$8_@1.push(read b$6)
38 [4] Call mutate x$7_@0.push(read a$5)
39 "]
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md
+4 -4
@@ -21,11 +21,11 @@ function foo(a, b, c) {
21
22 ```
23 bb0:
24 - [1] Let mutate x$11_@0[1:11] = Array []
24 + [1] Const mutate x$11_@0[1:11] = Array []
25 [2] If (read a$8) then:bb2 else:bb1 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [3] Let mutate y$12_@1[3:7] = Array []
28 + [3] Const mutate y$12_@1[3:7] = Array []
29 [4] If (read b$9) then:bb4 else:bb3 fallthrough=bb3
30 bb4:
31 predecessor blocks: bb2
@@ -57,13 +57,13 @@ flowchart TB
57 %% Basic Blocks
58 subgraph bb0
59 bb0_instrs["
60 - [1] Let mutate x$11_@0[1:11] = Array []
60 + [1] Const mutate x$11_@0[1:11] = Array []
61 "]
62 bb0_instrs --> bb0_terminal(["If (read a$8)"])
63 end
64 subgraph bb2
65 bb2_instrs["
66 - [3] Let mutate y$12_@1[3:7] = Array []
66 + [3] Const mutate y$12_@1[3:7] = Array []
67 "]
68 bb2_instrs --> bb2_terminal(["If (read b$9)"])
69 end
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md
+4 -4
@@ -17,8 +17,8 @@ function foo(a, b, c) {
17
18 ```
19 bb0:
20 - [1] Let mutate x$9_@0[1:8] = Array []
21 - [2] Let mutate y$10_@0[1:8] = Array []
20 + [1] Const mutate x$9_@0[1:8] = Array []
21 + [2] Const mutate y$10_@0[1:8] = Array []
22 [3] While test=bb1 loop=bb3 fallthrough=bb2
23 bb1:
24 predecessor blocks: bb0 bb3
@@ -44,8 +44,8 @@ flowchart TB
44 %% Basic Blocks
45 subgraph bb0
46 bb0_instrs["
47 - [1] Let mutate x$9_@0[1:8] = Array []
48 - [2] Let mutate y$10_@0[1:8] = Array []
47 + [1] Const mutate x$9_@0[1:8] = Array []
48 + [2] Const mutate y$10_@0[1:8] = Array []
49 "]
50 bb0_instrs --> bb0_terminal(["While"])
51 end
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md
+4 -4
@@ -21,11 +21,11 @@ function foo(a, b, c) {
21
22 ```
23 bb0:
24 - [1] Let mutate x$9_@0[1:9] = Array []
24 + [1] Const mutate x$9_@0[1:9] = Array []
25 [2] If (read a$6) then:bb2 else:bb1 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [3] Let mutate y$10_@0[1:9] = Array []
28 + [3] Const mutate y$10_@0[1:9] = Array []
29 [4] If (read b$7) then:bb4 else:bb3 fallthrough=bb3
30 bb4:
31 predecessor blocks: bb2
@@ -51,13 +51,13 @@ flowchart TB
51 %% Basic Blocks
52 subgraph bb0
53 bb0_instrs["
54 - [1] Let mutate x$9_@0[1:9] = Array []
54 + [1] Const mutate x$9_@0[1:9] = Array []
55 "]
56 bb0_instrs --> bb0_terminal(["If (read a$6)"])
57 end
58 subgraph bb2
59 bb2_instrs["
60 - [3] Let mutate y$10_@0[1:9] = Array []
60 + [3] Const mutate y$10_@0[1:9] = Array []
61 "]
62 bb2_instrs --> bb2_terminal(["If (read b$7)"])
63 end
compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md
+6 -6
@@ -18,9 +18,9 @@ function foo() {
18
19 ```
20 bb0:
21 - [1] Let mutate x$4_@0[1:6] = Object { }
22 - [2] Let mutate y$5_@1[2:5] = Array []
23 - [3] Let mutate z$6_@1[2:5] = Object { }
21 + [1] Const mutate x$4_@0[1:6] = Object { }
22 + [2] Const mutate y$5_@1[2:5] = Array []
23 + [3] Const mutate z$6_@1[2:5] = Object { }
24 [4] Call mutate y$5_@1.push(mutate z$6_@1)
25 [5] Reassign mutate x$4_@0.y[1:6] = read y$5_@1
26 [6] Return freeze x$4_@0
@@ -35,9 +35,9 @@ flowchart TB
35 %% Basic Blocks
36 subgraph bb0
37 bb0_instrs["
38 - [1] Let mutate x$4_@0[1:6] = Object { }
39 - [2] Let mutate y$5_@1[2:5] = Array []
40 - [3] Let mutate z$6_@1[2:5] = Object { }
38 + [1] Const mutate x$4_@0[1:6] = Object { }
39 + [2] Const mutate y$5_@1[2:5] = Array []
40 + [3] Const mutate z$6_@1[2:5] = Object { }
41 [4] Call mutate y$5_@1.push(mutate z$6_@1)
42 [5] Reassign mutate x$4_@0.y[1:6] = read y$5_@1
43 "]
compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md
+2 -2
@@ -19,7 +19,7 @@ function f(a, b) {
19
20 ```
21 bb0:
22 - [1] Let mutate x$10_@0[1:8] = Array []
22 + [1] Const mutate x$10_@0[1:8] = Array []
23 [2] Const mutate $11_@1 = 1
24 [3] Const mutate $12_@2 = Binary read a$8.length === read $11_@1
25 [4] If (read $12_@2) then:bb2 else:bb1 fallthrough=bb1
@@ -53,7 +53,7 @@ flowchart TB
53 %% Basic Blocks
54 subgraph bb0
55 bb0_instrs["
56 - [1] Let mutate x$10_@0[1:8] = Array []
56 + [1] Const mutate x$10_@0[1:8] = Array []
57 [2] Const mutate $11_@1 = 1
58 [3] Const mutate $12_@2 = Binary read a$8.length === read $11_@1
59 "]
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
+10 -9
@@ -25,28 +25,29 @@ function Component(props) {
25 bb0:
26 [1] Let mutate x$7_@0[1:7] = Array []
27 [2] Call mutate x$7_@0.push(read props$6.p0)
28 - [3] Let mutate y$8_@0[1:7] = read x$7_@0
28 + [3] Const mutate y$8_@0[1:7] = read x$7_@0
29 [4] If (read props$6.p1) then:bb2 else:bb1 fallthrough=bb1
30 bb2:
31 predecessor blocks: bb0
32 - [5] Reassign mutate x$9_@0[1:7] = Array []
32 + [5] Reassign mutate x$7_@0[1:7] = Array []
33 [6] Goto bb1
34 bb1:
35 predecessor blocks: bb2 bb0
36 - x$11_@0[1:7]: phi(bb2: x$9_@0, bb0: x$7_@0)
37 - [7] Let mutate _$12_@1 = JSX <read Component$0 x={freeze x$11_@0} ></read Component$0>
36 + [7] Const mutate _$12_@1 = JSX <read Component$0 x={freeze x$7_@0} ></read Component$0>
37 [8] Call read y$8_@0.push(read props$6.p2)
39 - [9] Const mutate $15_@2 = JSX <read Component$0 x={read x$11_@0} y={read y$8_@0} ></read Component$0>
38 + [9] Const mutate $15_@2 = JSX <read Component$0 x={read x$7_@0} y={read y$8_@0} ></read Component$0>
39 [10] Return read $15_@2
40 scope0 [1:7]:
41 - read props$6.p0
42 - read props$6.p1
43 scope1 [7:8]:
44 - read Component$0
45 + - freeze x$7_@0
46 - read y$8_@0.push
47 - read props$6.p2
48 scope2 [9:10]:
49 - read Component$0
50 + - read x$7_@0
51 - read y$8_@0
52 ```
53
@@ -59,21 +60,21 @@ flowchart TB
60 bb0_instrs["
61 [1] Let mutate x$7_@0[1:7] = Array []
62 [2] Call mutate x$7_@0.push(read props$6.p0)
62 - [3] Let mutate y$8_@0[1:7] = read x$7_@0
63 + [3] Const mutate y$8_@0[1:7] = read x$7_@0
64 "]
65 bb0_instrs --> bb0_terminal(["If (read props$6.p1)"])
66 end
67 subgraph bb2
68 bb2_instrs["
68 - [5] Reassign mutate x$9_@0[1:7] = Array []
69 + [5] Reassign mutate x$7_@0[1:7] = Array []
70 "]
71 bb2_instrs --> bb2_terminal(["Goto"])
72 end
73 subgraph bb1
74 bb1_instrs["
74 - [7] Let mutate _$12_@1 = JSX <read Component$0 x={freeze x$11_@0} ></read Component$0>
75 + [7] Const mutate _$12_@1 = JSX <read Component$0 x={freeze x$7_@0} ></read Component$0>
76 [8] Call read y$8_@0.push(read props$6.p2)
76 - [9] Const mutate $15_@2 = JSX <read Component$0 x={read x$11_@0} y={read y$8_@0} ></read Component$0>
77 + [9] Const mutate $15_@2 = JSX <read Component$0 x={read x$7_@0} y={read y$8_@0} ></read Component$0>
78 "]
79 bb1_instrs --> bb1_terminal(["Return read $15_@2"])
80 end
compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md
+16 -14
@@ -34,7 +34,7 @@ function foo(a, b, c) {
34
35 ```
36 bb0:
37 - [1] Let mutate x$16_@0[1:5] = Array []
37 + [1] Const mutate x$16_@0[1:5] = Array []
38 [2] If (read a$13) then:bb2 else:bb1 fallthrough=bb1
39 bb2:
40 predecessor blocks: bb0
@@ -43,30 +43,30 @@ bb2:
43 bb1:
44 predecessor blocks: bb2 bb0
45 [5] Const mutate $17_@1 = "div"
46 - [6] Let mutate y$19_@2 = JSX <read $17_@1>{freeze x$16_@0}</read $17_@1>
46 + [6] Const mutate y$19_@2 = JSX <read $17_@1>{freeze x$16_@0}</read $17_@1>
47 [7] Const mutate $20_@3 = 0
48 + [8] Let mutate x$22_@4[8:15] = undefined
49 [8] Switch (read b$14)
50 Case read $20_@3: bb5
51 Default: bb4
52 Fallthrough: bb3
53 bb5:
54 predecessor blocks: bb1
54 - [9] Reassign mutate x$22_@4[9:14] = Array []
55 + [9] Reassign mutate x$22_@4[8:15] = Array []
56 [10] Call mutate x$22_@4.push(read b$14)
57 [11] Goto bb3
58 bb4:
59 predecessor blocks: bb1
59 - [12] Reassign mutate x$23_@4[9:14] = Array []
60 - [13] Call mutate x$23_@4.push(read c$15)
60 + [12] Reassign mutate x$22_@4[8:15] = Array []
61 + [13] Call mutate x$22_@4.push(read c$15)
62 [14] Goto bb3
63 bb3:
64 predecessor blocks: bb5 bb4
64 - x$30_@4[9:14]: phi(bb5: x$22_@4, bb4: x$23_@4)
65 [15] Const mutate $25_@5 = "div"
66 [16] Const mutate $26_@6 = "\n "
67 [17] Const mutate $27_@7 = "\n "
68 [18] Const mutate $28_@8 = "\n "
69 - [19] Const mutate $31_@9 = JSX <read $25_@5>{read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$30_@4}{read $28_@8}</read $25_@5>
69 + [19] Const mutate $31_@9 = JSX <read $25_@5>{read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$22_@4}{read $28_@8}</read $25_@5>
70 [20] Return read $31_@9
71 scope0 [1:5]:
72 - read a$13
@@ -74,7 +74,7 @@ scope0 [1:5]:
74 scope2 [6:7]:
75 - read $17_@1
76 - freeze x$16_@0
77 -scope4 [9:14]:
77 +scope4 [8:15]:
78 - read c$15
79 - read b$14
80 - read b$14
@@ -83,6 +83,7 @@ scope9 [19:20]:
83 - read $26_@6
84 - read y$19_@2
85 - read $27_@7
86 + - freeze x$22_@4
87 - read $28_@8
88 ```
89
@@ -93,7 +94,7 @@ flowchart TB
94 %% Basic Blocks
95 subgraph bb0
96 bb0_instrs["
96 - [1] Let mutate x$16_@0[1:5] = Array []
97 + [1] Const mutate x$16_@0[1:5] = Array []
98 "]
99 bb0_instrs --> bb0_terminal(["If (read a$13)"])
100 end
@@ -106,22 +107,23 @@ flowchart TB
107 subgraph bb1
108 bb1_instrs["
109 [5] Const mutate $17_@1 = 'div'
109 - [6] Let mutate y$19_@2 = JSX <read $17_@1>{freeze x$16_@0}</read $17_@1>
110 + [6] Const mutate y$19_@2 = JSX <read $17_@1>{freeze x$16_@0}</read $17_@1>
111 [7] Const mutate $20_@3 = 0
112 + [8] Let mutate x$22_@4[8:15] = undefined
113 "]
114 bb1_instrs --> bb1_terminal(["Switch (read b$14)"])
115 end
116 subgraph bb5
117 bb5_instrs["
116 - [9] Reassign mutate x$22_@4[9:14] = Array []
118 + [9] Reassign mutate x$22_@4[8:15] = Array []
119 [10] Call mutate x$22_@4.push(read b$14)
120 "]
121 bb5_instrs --> bb5_terminal(["Goto"])
122 end
123 subgraph bb4
124 bb4_instrs["
123 - [12] Reassign mutate x$23_@4[9:14] = Array []
124 - [13] Call mutate x$23_@4.push(read c$15)
125 + [12] Reassign mutate x$22_@4[8:15] = Array []
126 + [13] Call mutate x$22_@4.push(read c$15)
127 "]
128 bb4_instrs --> bb4_terminal(["Goto"])
129 end
@@ -131,7 +133,7 @@ flowchart TB
133 [16] Const mutate $26_@6 = '\n '
134 [17] Const mutate $27_@7 = '\n '
135 [18] Const mutate $28_@8 = '\n '
134 - [19] Const mutate $31_@9 = JSX <read $25_@5>{read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$30_@4}{read $28_@8}</read $25_@5>
136 + [19] Const mutate $31_@9 = JSX <read $25_@5>{read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$22_@4}{read $28_@8}</read $25_@5>
137 "]
138 bb3_instrs --> bb3_terminal(["Return read $31_@9"])
139 end
compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md
+8 -8
@@ -21,11 +21,11 @@ function Component(props) {
21
22 ```
23 bb0:
24 - [1] Let mutate x$7_@0[1:7] = Array []
24 + [1] Const mutate x$7_@0[1:7] = Array []
25 [2] Call mutate x$7_@0.push(read props$6.p0)
26 - [3] Let mutate y$8_@0[1:7] = read x$7_@0
27 - [4] Reassign mutate x$9_@1 = Array []
28 - [5] Let mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
26 + [3] Const mutate y$8_@0[1:7] = read x$7_@0
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 $11_@3 = JSX <read Component$0 x={read x$9_@1} y={freeze y$8_@0} ></read Component$0>
31 [8] Return read $11_@3
@@ -48,11 +48,11 @@ flowchart TB
48 %% Basic Blocks
49 subgraph bb0
50 bb0_instrs["
51 - [1] Let mutate x$7_@0[1:7] = Array []
51 + [1] Const mutate x$7_@0[1:7] = Array []
52 [2] Call mutate x$7_@0.push(read props$6.p0)
53 - [3] Let mutate y$8_@0[1:7] = read x$7_@0
54 - [4] Reassign mutate x$9_@1 = Array []
55 - [5] Let mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
53 + [3] Const mutate y$8_@0[1:7] = read x$7_@0
54 + [4] Const mutate x$9_@1 = Array []
55 + [5] Const mutate _$10_@2 = JSX <read Component$0 x={freeze x$9_@1} ></read Component$0>
56 [6] Call mutate y$8_@0.push(read props$6.p1)
57 [7] Const mutate $11_@3 = JSX <read Component$0 x={read x$9_@1} y={freeze y$8_@0} ></read Component$0>
58 "]
compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md
+31 -28
@@ -36,54 +36,56 @@ function Component(props) {
36
37 ```
38 bb0:
39 - [1] Let mutate x$7_@0 = undefined
39 + [1] Const mutate x$7_@0 = undefined
40 + [2] Let mutate x$11_@1[2:18] = undefined
41 [2] If (read props$6.cond) then:bb2 else:bb10 fallthrough=bb1
42 bb2:
43 predecessor blocks: bb0
43 - [3] Const mutate $8_@1 = 2
44 - [4] Const mutate $9_@2 = 1
45 - [5] Const mutate $10_@3 = 0
44 + [3] Const mutate $8_@2 = 2
45 + [4] Const mutate $9_@3 = 1
46 + [5] Const mutate $10_@4 = 0
47 [6] Switch (read props$6.test)
47 - Case read $10_@3: bb8
48 - Case read $9_@2: bb6
49 - Case read $8_@1: bb4
48 + Case read $10_@4: bb8
49 + Case read $9_@3: bb6
50 + Case read $8_@2: bb4
51 Default: bb4
52 Fallthrough: bb1
53 bb8:
54 predecessor blocks: bb2
54 - [7] Reassign mutate x$11_@4[7:17] = read props$6.v0
55 + [7] Reassign mutate x$11_@1[2:18] = read props$6.v0
56 [8] Goto bb1
57 bb6:
58 predecessor blocks: bb2
58 - [9] Reassign mutate x$12_@4[7:17] = read props$6.v1
59 + [9] Reassign mutate x$11_@1[2:18] = read props$6.v1
60 [10] Goto bb1
61 bb4:
62 predecessor blocks: bb2
62 - [11] Reassign mutate x$13_@4[7:17] = read props$6.v2
63 + [11] Reassign mutate x$11_@1[2:18] = read props$6.v2
64 [12] Goto bb1
65 bb10:
66 predecessor blocks: bb0
67 [13] If (read props$6.cond2) then:bb12 else:bb13 fallthrough=bb1
68 bb12:
69 predecessor blocks: bb10
69 - [14] Reassign mutate x$14_@4[7:17] = read props$6.b
70 + [14] Reassign mutate x$11_@1[2:18] = read props$6.b
71 [15] Goto bb1
72 bb13:
73 predecessor blocks: bb10
73 - [16] Reassign mutate x$15_@4[7:17] = read props$6.c
74 + [16] Reassign mutate x$11_@1[2:18] = read props$6.c
75 [17] Goto bb1
76 bb1:
77 predecessor blocks: bb8 bb6 bb4 bb12 bb13
77 - x$16_@4[7:17]: phi(bb8: x$11_@4, bb6: x$12_@4, bb4: x$13_@4, bb12: x$14_@4, bb13: x$15_@4)
78 - [18] read x$16_@4
78 + [18] read x$11_@1
79 [19] Return
80 -scope4 [7:17]:
80 +scope1 [2:18]:
81 - read props$6.v2
82 - read props$6.v1
83 - read props$6.v0
84 - read props$6.test
85 - read props$6.b
86 - read props$6.c
87 + - read props$6.cond2
88 + - read props$6.cond
89 ```
90
91 ### CFG
@@ -93,33 +95,34 @@ flowchart TB
95 %% Basic Blocks
96 subgraph bb0
97 bb0_instrs["
96 - [1] Let mutate x$7_@0 = undefined
98 + [1] Const mutate x$7_@0 = undefined
99 + [2] Let mutate x$11_@1[2:18] = undefined
100 "]
101 bb0_instrs --> bb0_terminal(["If (read props$6.cond)"])
102 end
103 subgraph bb2
104 bb2_instrs["
102 - [3] Const mutate $8_@1 = 2
103 - [4] Const mutate $9_@2 = 1
104 - [5] Const mutate $10_@3 = 0
105 + [3] Const mutate $8_@2 = 2
106 + [4] Const mutate $9_@3 = 1
107 + [5] Const mutate $10_@4 = 0
108 "]
109 bb2_instrs --> bb2_terminal(["Switch (read props$6.test)"])
110 end
111 subgraph bb8
112 bb8_instrs["
110 - [7] Reassign mutate x$11_@4[7:17] = read props$6.v0
113 + [7] Reassign mutate x$11_@1[2:18] = read props$6.v0
114 "]
115 bb8_instrs --> bb8_terminal(["Goto"])
116 end
117 subgraph bb6
118 bb6_instrs["
116 - [9] Reassign mutate x$12_@4[7:17] = read props$6.v1
119 + [9] Reassign mutate x$11_@1[2:18] = read props$6.v1
120 "]
121 bb6_instrs --> bb6_terminal(["Goto"])
122 end
123 subgraph bb4
124 bb4_instrs["
122 - [11] Reassign mutate x$13_@4[7:17] = read props$6.v2
125 + [11] Reassign mutate x$11_@1[2:18] = read props$6.v2
126 "]
127 bb4_instrs --> bb4_terminal(["Goto"])
128 end
@@ -128,19 +131,19 @@ flowchart TB
131 end
132 subgraph bb12
133 bb12_instrs["
131 - [14] Reassign mutate x$14_@4[7:17] = read props$6.b
134 + [14] Reassign mutate x$11_@1[2:18] = read props$6.b
135 "]
136 bb12_instrs --> bb12_terminal(["Goto"])
137 end
138 subgraph bb13
139 bb13_instrs["
137 - [16] Reassign mutate x$15_@4[7:17] = read props$6.c
140 + [16] Reassign mutate x$11_@1[2:18] = read props$6.c
141 "]
142 bb13_instrs --> bb13_terminal(["Goto"])
143 end
144 subgraph bb1
145 bb1_instrs["
143 - [18] read x$16_@4
146 + [18] read x$11_@1
147 "]
148 bb1_instrs --> bb1_terminal(["Return"])
149 end
@@ -149,9 +152,9 @@ flowchart TB
152 bb0_terminal -- "then" --> bb2
153 bb0_terminal -- "else" --> bb10
154 bb0_terminal -- "fallthrough" --> bb1
152 - bb2_terminal -- "read $10_@3" --> bb8
153 - bb2_terminal -- "read $9_@2" --> bb6
154 - bb2_terminal -- "read $8_@1" --> bb4
155 + bb2_terminal -- "read $10_@4" --> bb8
156 + bb2_terminal -- "read $9_@3" --> bb6
157 + bb2_terminal -- "read $8_@2" --> bb4
158 bb2_terminal -- "default" --> bb4
159 bb2_terminal -- "fallthrough" --> bb1
160 bb8_terminal --> bb1
compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md
+12 -12
@@ -47,12 +47,12 @@ function mutate$0() {}
47
48 ```
49 bb0:
50 - [1] Let mutate a$5_@0 = Object { }
51 - [2] Let mutate b$6_@1[0:8] = Object { }
52 - [3] Let mutate c$7_@1[0:8] = Object { }
53 - [4] Reassign mutate a$8_@1[0:8] = read b$6_@1
54 - [5] Reassign mutate b$9_@1[0:8] = read c$7_@1
55 - [6] Reassign mutate c$10_@1[0:8] = read a$8_@1
50 + [1] Const mutate a$5_@0 = Object { }
51 + [2] Const mutate b$6_@1[0:8] = Object { }
52 + [3] Const mutate c$7_@1[0:8] = Object { }
53 + [4] Const mutate a$8_@1[0:8] = read b$6_@1
54 + [5] Const mutate b$9_@1[0:8] = read c$7_@1
55 + [6] Const mutate c$10_@1[0:8] = read a$8_@1
56 [7] Call mutate mutate$4_@1(mutate a$8_@1, mutate b$9_@1)
57 [8] Return freeze c$10_@1
58
@@ -65,12 +65,12 @@ flowchart TB
65 %% Basic Blocks
66 subgraph bb0
67 bb0_instrs["
68 - [1] Let mutate a$5_@0 = Object { }
69 - [2] Let mutate b$6_@1[0:8] = Object { }
70 - [3] Let mutate c$7_@1[0:8] = Object { }
71 - [4] Reassign mutate a$8_@1[0:8] = read b$6_@1
72 - [5] Reassign mutate b$9_@1[0:8] = read c$7_@1
73 - [6] Reassign mutate c$10_@1[0:8] = read a$8_@1
68 + [1] Const mutate a$5_@0 = Object { }
69 + [2] Const mutate b$6_@1[0:8] = Object { }
70 + [3] Const mutate c$7_@1[0:8] = Object { }
71 + [4] Const mutate a$8_@1[0:8] = read b$6_@1
72 + [5] Const mutate b$9_@1[0:8] = read c$7_@1
73 + [6] Const mutate c$10_@1[0:8] = read a$8_@1
74 [7] Call mutate mutate$4_@1(mutate a$8_@1, mutate b$9_@1)
75 "]
76 bb0_instrs --> bb0_terminal(["Return freeze c$10_@1"])
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md
+2 -2
@@ -57,7 +57,7 @@ bb0:
57 bb2:
58 predecessor blocks: bb0
59 [6] Const mutate $14_@1 = "div"
60 - [7] Let mutate _$15_@2 = JSX <read $14_@1 a={freeze a$11_@0} ></read $14_@1>
60 + [7] Const mutate _$15_@2 = JSX <read $14_@1 a={freeze a$11_@0} ></read $14_@1>
61 [8] Goto bb1
62 bb1:
63 predecessor blocks: bb2 bb0
@@ -90,7 +90,7 @@ flowchart TB
90 subgraph bb2
91 bb2_instrs["
92 [6] Const mutate $14_@1 = 'div'
93 - [7] Let mutate _$15_@2 = JSX <read $14_@1 a={freeze a$11_@0} ></read $14_@1>
93 + [7] Const mutate _$15_@2 = JSX <read $14_@1 a={freeze a$11_@0} ></read $14_@1>
94 "]
95 bb2_instrs --> bb2_terminal(["Goto"])
96 end
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md
+2 -2
@@ -50,7 +50,7 @@ bb0:
50 [2] Const mutate b$11_@0[0:7] = Object { }
51 [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0)
52 [4] Const mutate $12_@1 = "div"
53 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
53 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
54 [6] Call mutate foo$4_@0(read a$10_@0, mutate b$11_@0)
55 [7] Const mutate $14_@3 = "div"
56 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
@@ -74,7 +74,7 @@ flowchart TB
74 [2] Const mutate b$11_@0[0:7] = Object { }
75 [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0)
76 [4] Const mutate $12_@1 = 'div'
77 - [5] Let mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
77 + [5] Const mutate _$13_@2 = JSX <read $12_@1 a={freeze a$10_@0} ></read $12_@1>
78 [6] Call mutate foo$4_@0(read a$10_@0, mutate b$11_@0)
79 [7] Const mutate $14_@3 = 'div'
80 [8] Const mutate $15_@4 = JSX <read $14_@3 a={read a$10_@0} b={freeze b$11_@0} ></read $14_@3>
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+12 -12
@@ -21,29 +21,28 @@ function foo() {
21
22 ```
23 bb0:
24 - [1] Let mutate x$7_@0[1:14] = 1
25 - [2] Let mutate y$8_@1 = 2
24 + [1] Let mutate x$7_@0[1:8] = 1
25 + [2] Const mutate y$8_@1 = 2
26 [3] Const mutate $9_@2 = 2
27 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2
28 [5] If (read $10_@3) then:bb2 else:bb1 fallthrough=bb1
29 bb2:
30 predecessor blocks: bb0
31 - [6] Reassign mutate x$11_@0[1:14] = 3
31 + [6] Reassign mutate x$7_@0[1:8] = 3
32 [7] Goto bb1
33 bb1:
34 predecessor blocks: bb2 bb0
35 - x$17_@0[1:14]: phi(bb2: x$11_@0, bb0: x$7_@0)
35 [8] Const mutate $12_@4 = 3
36 [9] Const mutate $14_@5 = Binary read y$8_@1 === read $12_@4
37 + [10] Let mutate x$15_@6[1:14] = undefined
38 [10] If (read $14_@5) then:bb4 else:bb3 fallthrough=bb3
39 bb4:
40 predecessor blocks: bb1
41 - [11] Reassign mutate x$15_@0[1:14] = 5
41 + [11] Reassign mutate x$15_@6[1:14] = 5
42 [12] Goto bb3
43 bb3:
44 predecessor blocks: bb4 bb1
45 - x$16_@0[1:14]: phi(bb4: x$15_@0, bb1: x$17_@0)
46 - [13] Reassign mutate y$18_@0[1:14] = read x$16_@0
45 + [13] Const mutate y$18_@6[1:14] = read x$15_@6
46 [14] Return
47 scope3 [4:5]:
48 - read y$8_@1
@@ -60,8 +59,8 @@ flowchart TB
59 %% Basic Blocks
60 subgraph bb0
61 bb0_instrs["
63 - [1] Let mutate x$7_@0[1:14] = 1
64 - [2] Let mutate y$8_@1 = 2
62 + [1] Let mutate x$7_@0[1:8] = 1
63 + [2] Const mutate y$8_@1 = 2
64 [3] Const mutate $9_@2 = 2
65 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2
66 "]
@@ -69,7 +68,7 @@ flowchart TB
68 end
69 subgraph bb2
70 bb2_instrs["
72 - [6] Reassign mutate x$11_@0[1:14] = 3
71 + [6] Reassign mutate x$7_@0[1:8] = 3
72 "]
73 bb2_instrs --> bb2_terminal(["Goto"])
74 end
@@ -77,18 +76,19 @@ flowchart TB
76 bb1_instrs["
77 [8] Const mutate $12_@4 = 3
78 [9] Const mutate $14_@5 = Binary read y$8_@1 === read $12_@4
79 + [10] Let mutate x$15_@6[1:14] = undefined
80 "]
81 bb1_instrs --> bb1_terminal(["If (read $14_@5)"])
82 end
83 subgraph bb4
84 bb4_instrs["
85 - [11] Reassign mutate x$15_@0[1:14] = 5
85 + [11] Reassign mutate x$15_@6[1:14] = 5
86 "]
87 bb4_instrs --> bb4_terminal(["Goto"])
88 end
89 subgraph bb3
90 bb3_instrs["
91 - [13] Reassign mutate y$18_@0[1:14] = read x$16_@0
91 + [13] Const mutate y$18_@6[1:14] = read x$15_@6
92 "]
93 bb3_instrs --> bb3_terminal(["Return"])
94 end
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+6 -7
@@ -19,18 +19,17 @@ function foo() {
19 ```
20 bb0:
21 [1] Let mutate x$5_@0[1:9] = 1
22 - [2] Let mutate y$6_@1 = 2
22 + [2] Const mutate y$6_@1 = 2
23 [3] Const mutate $7_@2 = 2
24 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2
25 [5] If (read $8_@3) then:bb2 else:bb1 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [6] Reassign mutate x$9_@0[1:9] = 3
28 + [6] Reassign mutate x$5_@0[1:9] = 3
29 [7] Goto bb1
30 bb1:
31 predecessor blocks: bb2 bb0
32 - x$10_@0[1:9]: phi(bb2: x$9_@0, bb0: x$5_@0)
33 - [8] Reassign mutate y$11_@0[1:9] = read x$10_@0
32 + [8] Const mutate y$11_@0[1:9] = read x$5_@0
33 [9] Return
34 scope3 [4:5]:
35 - read y$6_@1
@@ -45,7 +44,7 @@ flowchart TB
44 subgraph bb0
45 bb0_instrs["
46 [1] Let mutate x$5_@0[1:9] = 1
48 - [2] Let mutate y$6_@1 = 2
47 + [2] Const mutate y$6_@1 = 2
48 [3] Const mutate $7_@2 = 2
49 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2
50 "]
@@ -53,13 +52,13 @@ flowchart TB
52 end
53 subgraph bb2
54 bb2_instrs["
56 - [6] Reassign mutate x$9_@0[1:9] = 3
55 + [6] Reassign mutate x$5_@0[1:9] = 3
56 "]
57 bb2_instrs --> bb2_terminal(["Goto"])
58 end
59 subgraph bb1
60 bb1_instrs["
62 - [8] Reassign mutate y$11_@0[1:9] = read x$10_@0
61 + [8] Const mutate y$11_@0[1:9] = read x$5_@0
62 "]
63 bb1_instrs --> bb1_terminal(["Return"])
64 end
compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md
+6 -6
@@ -19,18 +19,18 @@ function foo(cond) {
19
20 ```
21 bb0:
22 - [1] Let mutate items$5_@0 = Array []
22 + [1] Const mutate items$5_@0 = Array []
23 [2] Goto bb1
24 bb1:
25 predecessor blocks: bb0 bb4
26 [3] If (read items$5_@0) then:bb3 else:bb2 fallthrough=bb2
27 bb3:
28 predecessor blocks: bb1
29 - [4] Let mutate y$7_@1 = 0
29 + [4] Const mutate y$7_@1 = 0
30 [5] If (read cond$4) then:bb5 else:bb4 fallthrough=bb4
31 bb5:
32 predecessor blocks: bb3
33 - [6] Reassign mutate y$9_@2 = 1
33 + [6] Const mutate y$9_@2 = 1
34 [7] Goto bb4
35 bb4:
36 predecessor blocks: bb5 bb3
@@ -48,7 +48,7 @@ flowchart TB
48 %% Basic Blocks
49 subgraph bb0
50 bb0_instrs["
51 - [1] Let mutate items$5_@0 = Array []
51 + [1] Const mutate items$5_@0 = Array []
52 "]
53 bb0_instrs --> bb0_terminal(["Goto"])
54 end
@@ -57,13 +57,13 @@ flowchart TB
57 end
58 subgraph bb3
59 bb3_instrs["
60 - [4] Let mutate y$7_@1 = 0
60 + [4] Const mutate y$7_@1 = 0
61 "]
62 bb3_instrs --> bb3_terminal(["If (read cond$4)"])
63 end
64 subgraph bb5
65 bb5_instrs["
66 - [6] Reassign mutate y$9_@2 = 1
66 + [6] Const mutate y$9_@2 = 1
67 "]
68 bb5_instrs --> bb5_terminal(["Goto"])
69 end
compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md
+6 -7
@@ -20,18 +20,17 @@ bb0:
20 [2] For init=bb3 test=bb1 loop=bb5 update=bb4 fallthrough=bb2
21 bb3:
22 predecessor blocks: bb0
23 - [3] Let mutate i$8_@1[3:13] = 0
23 + [3] Const mutate i$8_@1[3:13] = 0
24 [4] Goto bb1
25 bb1:
26 predecessor blocks: bb3 bb4
27 - x$13_@0[1:13]: phi(bb3: x$7_@0, bb4: x$14_@0)
27 [5] Const mutate $9_@2 = 10
28 [6] Const mutate $11_@3[6:8] = Binary read i$8_@1 < read $9_@2
29 [7] If (read $11_@3) then:bb5 else:bb2 fallthrough=bb2
30 bb5:
31 predecessor blocks: bb1
32 [8] Const mutate $12_@4 = 1
34 - [9] Reassign mutate x$14_@0[1:13] = Binary read x$13_@0 + read $12_@4
33 + [9] Reassign mutate x$7_@0[1:13] = Binary read x$7_@0 + read $12_@4
34 [10] Goto(Continue) bb4
35 bb4:
36 predecessor blocks: bb5
@@ -39,7 +38,7 @@ bb4:
38 [12] Goto bb1
39 bb2:
40 predecessor blocks: bb1
42 - [13] Return read x$13_@0
41 + [13] Return read x$7_@0
42 scope3 [6:8]:
43 - read $9_@2
44 ```
@@ -57,7 +56,7 @@ flowchart TB
56 end
57 subgraph bb3
58 bb3_instrs["
60 - [3] Let mutate i$8_@1[3:13] = 0
59 + [3] Const mutate i$8_@1[3:13] = 0
60 "]
61 bb3_instrs --> bb3_terminal(["Goto"])
62 end
@@ -71,7 +70,7 @@ flowchart TB
70 subgraph bb5
71 bb5_instrs["
72 [8] Const mutate $12_@4 = 1
74 - [9] Reassign mutate x$14_@0[1:13] = Binary read x$13_@0 + read $12_@4
73 + [9] Reassign mutate x$7_@0[1:13] = Binary read x$7_@0 + read $12_@4
74 "]
75 bb5_instrs --> bb5_terminal(["Goto"])
76 end
@@ -82,7 +81,7 @@ flowchart TB
81 bb4_instrs --> bb4_terminal(["Goto"])
82 end
83 subgraph bb2
85 - bb2_terminal(["Return read x$13_@0"])
84 + bb2_terminal(["Return read x$7_@0"])
85 end
86
87 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md
+8 -8
@@ -19,16 +19,16 @@ function foo() {
19
20 ```
21 bb0:
22 - [1] Let mutate x$5_@0 = 1
23 - [2] Let mutate y$6_@1 = 2
22 + [1] Const mutate x$5_@0 = 1
23 + [2] Const mutate y$6_@1 = 2
24 [3] If (read y$6_@1) then:bb2 else:bb3 fallthrough=bb1
25 bb2:
26 predecessor blocks: bb0
27 - [4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
27 + [4] Const mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
28 [5] Goto bb1
29 bb3:
30 predecessor blocks: bb0
31 - [6] Let mutate z$8_@3 = read x$5_@0
31 + [6] Const mutate z$8_@3 = read x$5_@0
32 [7] Goto bb1
33 bb1:
34 predecessor blocks: bb2 bb3
@@ -47,20 +47,20 @@ flowchart TB
47 %% Basic Blocks
48 subgraph bb0
49 bb0_instrs["
50 - [1] Let mutate x$5_@0 = 1
51 - [2] Let mutate y$6_@1 = 2
50 + [1] Const mutate x$5_@0 = 1
51 + [2] Const mutate y$6_@1 = 2
52 "]
53 bb0_instrs --> bb0_terminal(["If (read y$6_@1)"])
54 end
55 subgraph bb2
56 bb2_instrs["
57 - [4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
57 + [4] Const mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
58 "]
59 bb2_instrs --> bb2_terminal(["Goto"])
60 end
61 subgraph bb3
62 bb3_instrs["
63 - [6] Let mutate z$8_@3 = read x$5_@0
63 + [6] Const mutate z$8_@3 = read x$5_@0
64 "]
65 bb3_instrs --> bb3_terminal(["Goto"])
66 end
compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md
+24 -25
@@ -28,25 +28,25 @@ function foo(a, b, c, d) {
28
29 ```
30 bb0:
31 - [1] Let mutate x$13_@0 = 0
31 + [1] Const mutate x$13_@0 = 0
32 [2] Const mutate $14_@1 = true
33 + [3] Let mutate x$18_@2[3:20] = undefined
34 [3] If (read $14_@1) then:bb2 else:bb6 fallthrough=bb1
35 bb2:
36 predecessor blocks: bb0
36 - [4] Const mutate $15_@2 = true
37 - [5] If (read $15_@2) then:bb4 else:bb5 fallthrough=bb3
37 + [4] Const mutate $15_@3 = true
38 + [5] If (read $15_@3) then:bb4 else:bb5 fallthrough=bb3
39 bb4:
40 predecessor blocks: bb2
40 - [6] Reassign mutate x$16_@3[6:17] = read a$9
41 + [6] Reassign mutate x$18_@2[3:20] = read a$9
42 [7] Goto bb3
43 bb5:
44 predecessor blocks: bb2
44 - [8] Reassign mutate x$17_@3[6:17] = read b$10
45 + [8] Reassign mutate x$18_@2[3:20] = read b$10
46 [9] Goto bb3
47 bb3:
48 predecessor blocks: bb4 bb5
48 - x$18_@3[6:17]: phi(bb4: x$16_@3, bb5: x$17_@3)
49 - [10] read x$18_@3
49 + [10] read x$18_@2
50 [11] Goto bb1
51 bb6:
52 predecessor blocks: bb0
@@ -54,28 +54,26 @@ bb6:
54 [13] If (read $19_@4) then:bb8 else:bb9 fallthrough=bb7
55 bb8:
56 predecessor blocks: bb6
57 - [14] Reassign mutate x$20_@3[6:17] = read c$11
57 + [14] Reassign mutate x$18_@2[3:20] = read c$11
58 [15] Goto bb7
59 bb9:
60 predecessor blocks: bb6
61 - [16] Reassign mutate x$21_@3[6:17] = read d$12
61 + [16] Reassign mutate x$18_@2[3:20] = read d$12
62 [17] Goto bb7
63 bb7:
64 predecessor blocks: bb8 bb9
65 - x$22_@3[6:17]: phi(bb8: x$20_@3, bb9: x$21_@3)
66 - [18] read x$22_@3
65 + [18] read x$18_@2
66 [19] Goto bb1
67 bb1:
68 predecessor blocks: bb3 bb7
70 - x$23_@3[6:17]: phi(bb3: x$18_@3, bb7: x$22_@3)
71 - [20] read x$23_@3
69 + [20] read x$18_@2
70 [21] Return
73 -scope3 [6:17]:
71 +scope2 [3:20]:
72 - read a$9
73 - read b$10
76 - - read $15_@2
74 - read c$11
75 - read d$12
76 + - read $14_@1
77 ```
78
79 ### CFG
@@ -85,32 +83,33 @@ flowchart TB
83 %% Basic Blocks
84 subgraph bb0
85 bb0_instrs["
88 - [1] Let mutate x$13_@0 = 0
86 + [1] Const mutate x$13_@0 = 0
87 [2] Const mutate $14_@1 = true
88 + [3] Let mutate x$18_@2[3:20] = undefined
89 "]
90 bb0_instrs --> bb0_terminal(["If (read $14_@1)"])
91 end
92 subgraph bb2
93 bb2_instrs["
95 - [4] Const mutate $15_@2 = true
94 + [4] Const mutate $15_@3 = true
95 "]
97 - bb2_instrs --> bb2_terminal(["If (read $15_@2)"])
96 + bb2_instrs --> bb2_terminal(["If (read $15_@3)"])
97 end
98 subgraph bb4
99 bb4_instrs["
101 - [6] Reassign mutate x$16_@3[6:17] = read a$9
100 + [6] Reassign mutate x$18_@2[3:20] = read a$9
101 "]
102 bb4_instrs --> bb4_terminal(["Goto"])
103 end
104 subgraph bb5
105 bb5_instrs["
107 - [8] Reassign mutate x$17_@3[6:17] = read b$10
106 + [8] Reassign mutate x$18_@2[3:20] = read b$10
107 "]
108 bb5_instrs --> bb5_terminal(["Goto"])
109 end
110 subgraph bb3
111 bb3_instrs["
113 - [10] read x$18_@3
112 + [10] read x$18_@2
113 "]
114 bb3_instrs --> bb3_terminal(["Goto"])
115 end
@@ -122,25 +121,25 @@ flowchart TB
121 end
122 subgraph bb8
123 bb8_instrs["
125 - [14] Reassign mutate x$20_@3[6:17] = read c$11
124 + [14] Reassign mutate x$18_@2[3:20] = read c$11
125 "]
126 bb8_instrs --> bb8_terminal(["Goto"])
127 end
128 subgraph bb9
129 bb9_instrs["
131 - [16] Reassign mutate x$21_@3[6:17] = read d$12
130 + [16] Reassign mutate x$18_@2[3:20] = read d$12
131 "]
132 bb9_instrs --> bb9_terminal(["Goto"])
133 end
134 subgraph bb7
135 bb7_instrs["
137 - [18] read x$22_@3
136 + [18] read x$18_@2
137 "]
138 bb7_instrs --> bb7_terminal(["Goto"])
139 end
140 subgraph bb1
141 bb1_instrs["
143 - [20] read x$23_@3
142 + [20] read x$18_@2
143 "]
144 bb1_instrs --> bb1_terminal(["Return"])
145 end
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md
+2 -2
@@ -21,7 +21,7 @@ function foo(a, b, c) {
21
22 ```
23 bb0:
24 - [1] Let mutate x$9_@0 = 0
24 + [1] Const mutate x$9_@0 = 0
25 [2] While test=bb1 loop=bb3 fallthrough=bb2
26 bb1:
27 predecessor blocks: bb0 bb5
@@ -63,7 +63,7 @@ flowchart TB
63 %% Basic Blocks
64 subgraph bb0
65 bb0_instrs["
66 - [1] Let mutate x$9_@0 = 0
66 + [1] Const mutate x$9_@0 = 0
67 "]
68 bb0_instrs --> bb0_terminal(["While"])
69 end
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md new
+99
@@ -0,0 +1,99 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function foo(a, b, c) {
6 + let x = a;
7 + if (b) {
8 + if (c) {
9 + x = c;
10 + }
11 + x;
12 + }
13 +}
14 +
15 +```
16 +
17 +## HIR
18 +
19 +```
20 +bb0:
21 + [1] Const mutate x$8_@0[1:8] = read a$5
22 + [2] If (read b$6) then:bb2 else:bb1 fallthrough=bb1
23 +bb2:
24 + predecessor blocks: bb0
25 + [3] If (read c$7) then:bb4 else:bb3 fallthrough=bb3
26 +bb4:
27 + predecessor blocks: bb2
28 + [4] Reassign mutate x$8_@0[1:8] = read c$7
29 + [5] Goto bb3
30 +bb3:
31 + predecessor blocks: bb4 bb2
32 + [6] read x$8_@0
33 + [7] Goto bb1
34 +bb1:
35 + predecessor blocks: bb3 bb0
36 + [8] Return
37 +scope0 [1:8]:
38 + - read a$5
39 + - read c$7
40 + - read c$7
41 + - read b$6
42 +```
43 +
44 +### CFG
45 +
46 +```mermaid
47 +flowchart TB
48 + %% Basic Blocks
49 + subgraph bb0
50 + bb0_instrs["
51 + [1] Const mutate x$8_@0[1:8] = read a$5
52 + "]
53 + bb0_instrs --> bb0_terminal(["If (read b$6)"])
54 + end
55 + subgraph bb2
56 + bb2_terminal(["If (read c$7)"])
57 + end
58 + subgraph bb4
59 + bb4_instrs["
60 + [4] Reassign mutate x$8_@0[1:8] = read c$7
61 + "]
62 + bb4_instrs --> bb4_terminal(["Goto"])
63 + end
64 + subgraph bb3
65 + bb3_instrs["
66 + [6] read x$8_@0
67 + "]
68 + bb3_instrs --> bb3_terminal(["Goto"])
69 + end
70 + subgraph bb1
71 + bb1_terminal(["Return"])
72 + end
73 +
74 + %% Jumps
75 + bb0_terminal -- "then" --> bb2
76 + bb0_terminal -- "else" --> bb1
77 + bb2_terminal -- "then" --> bb4
78 + bb2_terminal -- "else" --> bb3
79 + bb4_terminal --> bb3
80 + bb3_terminal --> bb1
81 +
82 +```
83 +
84 +## Code
85 +
86 +```javascript
87 +function foo$0(a$5, b$6, c$7) {
88 + const x$8 = a$5;
89 + bb1: if (b$6) {
90 + bb3: if (c$7) {
91 + x$8 = c$7;
92 + }
93 +
94 + x$8;
95 + }
96 +}
97 +
98 +```
99 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js new
+9
@@ -0,0 +1,9 @@
1 +function foo(a, b, c) {
2 + let x = a;
3 + if (b) {
4 + if (c) {
5 + x = c;
6 + }
7 + x;
8 + }
9 +}
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md
+6 -7
@@ -24,19 +24,18 @@ bb0:
24 [2] If (read a$7) then:bb2 else:bb3 fallthrough=bb1
25 bb2:
26 predecessor blocks: bb0
27 - [3] Reassign mutate x$13_@0[1:8] = read b$8
27 + [3] Reassign mutate x$12_@0[1:8] = read b$8
28 [4] Goto bb1
29 bb3:
30 predecessor blocks: bb0
31 [5] If (read c$9) then:bb5 else:bb1 fallthrough=bb1
32 bb5:
33 predecessor blocks: bb3
34 - [6] Reassign mutate x$14_@0[1:8] = read d$10
34 + [6] Reassign mutate x$12_@0[1:8] = read d$10
35 [7] Goto bb1
36 bb1:
37 predecessor blocks: bb2 bb5 bb3
38 - x$15_@0[1:8]: phi(bb2: x$13_@0, bb5: x$14_@0, bb3: x$12_@0)
39 - [8] Return read x$15_@0
38 + [8] Return read x$12_@0
39 scope0 [1:8]:
40 - read b$8
41 - read d$10
@@ -57,7 +56,7 @@ flowchart TB
56 end
57 subgraph bb2
58 bb2_instrs["
60 - [3] Reassign mutate x$13_@0[1:8] = read b$8
59 + [3] Reassign mutate x$12_@0[1:8] = read b$8
60 "]
61 bb2_instrs --> bb2_terminal(["Goto"])
62 end
@@ -66,12 +65,12 @@ flowchart TB
65 end
66 subgraph bb5
67 bb5_instrs["
69 - [6] Reassign mutate x$14_@0[1:8] = read d$10
68 + [6] Reassign mutate x$12_@0[1:8] = read d$10
69 "]
70 bb5_instrs --> bb5_terminal(["Goto"])
71 end
72 subgraph bb1
74 - bb1_terminal(["Return read x$15_@0"])
73 + bb1_terminal(["Return read x$12_@0"])
74 end
75
76 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md
+2 -2
@@ -46,7 +46,7 @@ function Foo$0() {}
46 bb0:
47 [1] Const mutate a$7_@0[0:4] = Array []
48 [2] Const mutate b$8_@0[0:4] = Object { }
49 - [3] Let mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0)
49 + [3] Const mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0)
50 [4] Return freeze c$9_@0
51
52 ```
@@ -60,7 +60,7 @@ flowchart TB
60 bb0_instrs["
61 [1] Const mutate a$7_@0[0:4] = Array []
62 [2] Const mutate b$8_@0[0:4] = Object { }
63 - [3] Let mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0)
63 + [3] Const mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0)
64 "]
65 bb0_instrs --> bb0_terminal(["Return freeze c$9_@0"])
66 end
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+15 -16
@@ -25,24 +25,23 @@ bb0:
25 [1] Let mutate x$6_@0[1:10] = 1
26 [2] Let mutate y$7_@0[1:10] = 2
27 [3] Const mutate $8_@2 = 1
28 - [4] Const mutate $9_@3 = Binary read x$6_@0 > read $8_@2
29 - [5] If (read $9_@3) then:bb2 else:bb3 fallthrough=bb1
28 + [4] Const mutate $9_@0[1:10] = Binary read x$6_@0 > read $8_@2
29 + [5] If (read $9_@0) then:bb2 else:bb3 fallthrough=bb1
30 bb2:
31 predecessor blocks: bb0
32 - [6] Reassign mutate x$10_@0[1:10] = 2
32 + [6] Reassign mutate x$6_@0[1:10] = 2
33 [7] Goto bb1
34 bb3:
35 predecessor blocks: bb0
36 - [8] Reassign mutate y$11_@0[1:10] = 3
36 + [8] Reassign mutate y$7_@0[1:10] = 3
37 [9] Goto bb1
38 bb1:
39 predecessor blocks: bb2 bb3
40 - x$12_@0[1:10]: phi(bb2: x$10_@0, bb3: x$6_@0)
41 - y$13_@0[1:10]: phi(bb2: y$7_@0, bb3: y$11_@0)
42 - [10] Let mutate t$14_@4 = Object { x: read x$12_@0, y: read y$13_@0 }
43 - [11] Return freeze t$14_@4
44 -scope3 [4:5]:
45 - - read $8_@2
40 + [10] Const mutate t$14_@3 = Object { x: read x$6_@0, y: read y$7_@0 }
41 + [11] Return freeze t$14_@3
42 +scope3 [10:11]:
43 + - read x$6_@0
44 + - read y$7_@0
45 ```
46
47 ### CFG
@@ -55,27 +54,27 @@ flowchart TB
54 [1] Let mutate x$6_@0[1:10] = 1
55 [2] Let mutate y$7_@0[1:10] = 2
56 [3] Const mutate $8_@2 = 1
58 - [4] Const mutate $9_@3 = Binary read x$6_@0 > read $8_@2
57 + [4] Const mutate $9_@0[1:10] = Binary read x$6_@0 > read $8_@2
58 "]
60 - bb0_instrs --> bb0_terminal(["If (read $9_@3)"])
59 + bb0_instrs --> bb0_terminal(["If (read $9_@0)"])
60 end
61 subgraph bb2
62 bb2_instrs["
64 - [6] Reassign mutate x$10_@0[1:10] = 2
63 + [6] Reassign mutate x$6_@0[1:10] = 2
64 "]
65 bb2_instrs --> bb2_terminal(["Goto"])
66 end
67 subgraph bb3
68 bb3_instrs["
70 - [8] Reassign mutate y$11_@0[1:10] = 3
69 + [8] Reassign mutate y$7_@0[1:10] = 3
70 "]
71 bb3_instrs --> bb3_terminal(["Goto"])
72 end
73 subgraph bb1
74 bb1_instrs["
76 - [10] Let mutate t$14_@4 = Object { x: read x$12_@0, y: read y$13_@0 }
75 + [10] Const mutate t$14_@3 = Object { x: read x$6_@0, y: read y$7_@0 }
76 "]
78 - bb1_instrs --> bb1_terminal(["Return freeze t$14_@4"])
77 + bb1_instrs --> bb1_terminal(["Return freeze t$14_@3"])
78 end
79
80 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md
+4 -4
@@ -27,12 +27,12 @@ bb0:
27 [3] If (read a$7) then:bb2 else:bb3 fallthrough=bb1
28 bb2:
29 predecessor blocks: bb0
30 - [4] Let mutate y$10_@0[0:11] = Object { }
30 + [4] Const mutate y$10_@0[0:11] = Object { }
31 [5] Reassign mutate x$9_@0.y[0:11] = read y$10_@0
32 [6] Goto bb1
33 bb3:
34 predecessor blocks: bb0
35 - [7] Let mutate z$11_@0[0:11] = Object { }
35 + [7] Const mutate z$11_@0[0:11] = Object { }
36 [8] Reassign mutate x$9_@0.z[0:11] = read z$11_@0
37 [9] Goto bb1
38 bb1:
@@ -56,14 +56,14 @@ flowchart TB
56 end
57 subgraph bb2
58 bb2_instrs["
59 - [4] Let mutate y$10_@0[0:11] = Object { }
59 + [4] Const mutate y$10_@0[0:11] = Object { }
60 [5] Reassign mutate x$9_@0.y[0:11] = read y$10_@0
61 "]
62 bb2_instrs --> bb2_terminal(["Goto"])
63 end
64 subgraph bb3
65 bb3_instrs["
66 - [7] Let mutate z$11_@0[0:11] = Object { }
66 + [7] Const mutate z$11_@0[0:11] = Object { }
67 [8] Reassign mutate x$9_@0.z[0:11] = read z$11_@0
68 "]
69 bb3_instrs --> bb3_terminal(["Goto"])
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md
+4 -4
@@ -24,12 +24,12 @@ bb0:
24 [2] If (read a$5) then:bb2 else:bb3 fallthrough=bb1
25 bb2:
26 predecessor blocks: bb0
27 - [3] Let mutate y$7_@1 = Object { }
27 + [3] Const mutate y$7_@1 = Object { }
28 [4] Reassign mutate x$6_@0.y[1:9] = read y$7_@1
29 [5] Goto bb1
30 bb3:
31 predecessor blocks: bb0
32 - [6] Let mutate z$8_@2 = Object { }
32 + [6] Const mutate z$8_@2 = Object { }
33 [7] Reassign mutate x$6_@0.z[1:9] = read z$8_@2
34 [8] Goto bb1
35 bb1:
@@ -56,14 +56,14 @@ flowchart TB
56 end
57 subgraph bb2
58 bb2_instrs["
59 - [3] Let mutate y$7_@1 = Object { }
59 + [3] Const mutate y$7_@1 = Object { }
60 [4] Reassign mutate x$6_@0.y[1:9] = read y$7_@1
61 "]
62 bb2_instrs --> bb2_terminal(["Goto"])
63 end
64 subgraph bb3
65 bb3_instrs["
66 - [6] Let mutate z$8_@2 = Object { }
66 + [6] Const mutate z$8_@2 = Object { }
67 [7] Reassign mutate x$6_@0.z[1:9] = read z$8_@2
68 "]
69 bb3_instrs --> bb3_terminal(["Goto"])
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md
+4 -4
@@ -25,12 +25,12 @@ bb0:
25 [2] If (read a$6) then:bb2 else:bb3 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [3] Let mutate y$8_@0[0:10] = Object { }
28 + [3] Const mutate y$8_@0[0:10] = Object { }
29 [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0
30 [5] Goto bb1
31 bb3:
32 predecessor blocks: bb0
33 - [6] Let mutate z$9_@0[0:10] = Object { }
33 + [6] Const mutate z$9_@0[0:10] = Object { }
34 [7] Reassign mutate x$7_@0.z[0:10] = read z$9_@0
35 [8] Goto bb1
36 bb1:
@@ -53,14 +53,14 @@ flowchart TB
53 end
54 subgraph bb2
55 bb2_instrs["
56 - [3] Let mutate y$8_@0[0:10] = Object { }
56 + [3] Const mutate y$8_@0[0:10] = Object { }
57 [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0
58 "]
59 bb2_instrs --> bb2_terminal(["Goto"])
60 end
61 subgraph bb3
62 bb3_instrs["
63 - [6] Let mutate z$9_@0[0:10] = Object { }
63 + [6] Const mutate z$9_@0[0:10] = Object { }
64 [7] Reassign mutate x$7_@0.z[0:10] = read z$9_@0
65 "]
66 bb3_instrs --> bb3_terminal(["Goto"])
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md
+4 -4
@@ -25,13 +25,13 @@ bb0:
25 [2] If (read a$6) then:bb2 else:bb3 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [3] Let mutate y$8_@0[0:10] = Object { }
28 + [3] Const mutate y$8_@0[0:10] = Object { }
29 [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0
30 [5] Call mutate mutate$4_@0(mutate y$8_@0)
31 [6] Goto bb1
32 bb3:
33 predecessor blocks: bb0
34 - [7] Let mutate z$9_@1 = Object { }
34 + [7] Const mutate z$9_@1 = Object { }
35 [8] Reassign mutate x$7_@0.z[0:10] = read z$9_@1
36 [9] Goto bb1
37 bb1:
@@ -54,7 +54,7 @@ flowchart TB
54 end
55 subgraph bb2
56 bb2_instrs["
57 - [3] Let mutate y$8_@0[0:10] = Object { }
57 + [3] Const mutate y$8_@0[0:10] = Object { }
58 [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0
59 [5] Call mutate mutate$4_@0(mutate y$8_@0)
60 "]
@@ -62,7 +62,7 @@ flowchart TB
62 end
63 subgraph bb3
64 bb3_instrs["
65 - [7] Let mutate z$9_@1 = Object { }
65 + [7] Const mutate z$9_@1 = Object { }
66 [8] Reassign mutate x$7_@0.z[0:10] = read z$9_@1
67 "]
68 bb3_instrs --> bb3_terminal(["Goto"])
compiler/forget/src/__tests__/fixtures/hir/ssa-reassign.expect.md
+8 -8
@@ -16,10 +16,10 @@ function foo(a, b, c) {
16
17 ```
18 bb0:
19 - [1] Let mutate x$8_@0 = 0
20 - [2] Reassign mutate x$9_@1 = read a$5
21 - [3] Reassign mutate x$10_@2 = read b$6
22 - [4] Reassign mutate x$11_@3 = read c$7
19 + [1] Const mutate x$8_@0 = 0
20 + [2] Const mutate x$9_@1 = read a$5
21 + [3] Const mutate x$10_@2 = read b$6
22 + [4] Const mutate x$11_@3 = read c$7
23 [5] Return read x$11_@3
24 scope1 [2:3]:
25 - read a$5
@@ -36,10 +36,10 @@ flowchart TB
36 %% Basic Blocks
37 subgraph bb0
38 bb0_instrs["
39 - [1] Let mutate x$8_@0 = 0
40 - [2] Reassign mutate x$9_@1 = read a$5
41 - [3] Reassign mutate x$10_@2 = read b$6
42 - [4] Reassign mutate x$11_@3 = read c$7
39 + [1] Const mutate x$8_@0 = 0
40 + [2] Const mutate x$9_@1 = read a$5
41 + [3] Const mutate x$10_@2 = read b$6
42 + [4] Const mutate x$11_@3 = read c$7
43 "]
44 bb0_instrs --> bb0_terminal(["Return read x$11_@3"])
45 end
compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md
+9 -11
@@ -19,18 +19,16 @@ function foo() {
19 bb0:
20 [1] Let mutate x$4_@0[1:7] = 1
21 [2] Const mutate $5_@1 = 1
22 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1
23 - [4] If (read $6_@2) then:bb2 else:bb1 fallthrough=bb1
22 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1
23 + [4] If (read $6_@0) then:bb2 else:bb1 fallthrough=bb1
24 bb2:
25 predecessor blocks: bb0
26 - [5] Reassign mutate x$7_@0[1:7] = 2
26 + [5] Reassign mutate x$4_@0[1:7] = 2
27 [6] Goto bb1
28 bb1:
29 predecessor blocks: bb2 bb0
30 - x$8_@0[1:7]: phi(bb2: x$7_@0, bb0: x$4_@0)
31 - [7] Return read x$8_@0
32 -scope2 [3:4]:
33 - - read $5_@1
30 + [7] Return read x$4_@0
31 +
32 ```
33
34 ### CFG
@@ -42,18 +40,18 @@ flowchart TB
40 bb0_instrs["
41 [1] Let mutate x$4_@0[1:7] = 1
42 [2] Const mutate $5_@1 = 1
45 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1
43 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1
44 "]
47 - bb0_instrs --> bb0_terminal(["If (read $6_@2)"])
45 + bb0_instrs --> bb0_terminal(["If (read $6_@0)"])
46 end
47 subgraph bb2
48 bb2_instrs["
51 - [5] Reassign mutate x$7_@0[1:7] = 2
49 + [5] Reassign mutate x$4_@0[1:7] = 2
50 "]
51 bb2_instrs --> bb2_terminal(["Goto"])
52 end
53 subgraph bb1
56 - bb1_terminal(["Return read x$8_@0"])
54 + bb1_terminal(["Return read x$4_@0"])
55 end
56
57 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md
+6 -7
@@ -52,17 +52,16 @@ bb0:
52 [2] If (read cond$5) then:bb2 else:bb3 fallthrough=bb1
53 bb2:
54 predecessor blocks: bb0
55 - [3] Let mutate str$7_@1 = "other test"
55 + [3] Const mutate str$7_@1 = "other test"
56 [4] Call mutate log$4_@2(read str$7_@1)
57 [5] Goto bb1
58 bb3:
59 predecessor blocks: bb0
60 - [6] Reassign mutate str$8_@0[1:8] = "fallthrough test"
60 + [6] Reassign mutate str$6_@0[1:8] = "fallthrough test"
61 [7] Goto bb1
62 bb1:
63 predecessor blocks: bb2 bb3
64 - str$10_@0[1:8]: phi(bb2: str$6_@0, bb3: str$8_@0)
65 - [8] Call mutate log$4_@2(read str$10_@0)
64 + [8] Call mutate log$4_@2(read str$6_@0)
65 [9] Return
66
67 ```
@@ -80,20 +79,20 @@ flowchart TB
79 end
80 subgraph bb2
81 bb2_instrs["
83 - [3] Let mutate str$7_@1 = 'other test'
82 + [3] Const mutate str$7_@1 = 'other test'
83 [4] Call mutate log$4_@2(read str$7_@1)
84 "]
85 bb2_instrs --> bb2_terminal(["Goto"])
86 end
87 subgraph bb3
88 bb3_instrs["
90 - [6] Reassign mutate str$8_@0[1:8] = 'fallthrough test'
89 + [6] Reassign mutate str$6_@0[1:8] = 'fallthrough test'
90 "]
91 bb3_instrs --> bb3_terminal(["Goto"])
92 end
93 subgraph bb1
94 bb1_instrs["
96 - [8] Call mutate log$4_@2(read str$10_@0)
95 + [8] Call mutate log$4_@2(read str$6_@0)
96 "]
97 bb1_instrs --> bb1_terminal(["Return"])
98 end
compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md
+22 -18
@@ -28,52 +28,54 @@ function foo(a, b, c, d) {
28
29 ```
30 bb0:
31 - [1] Let mutate x$13_@0 = 0
31 + [1] Const mutate x$13_@0 = 0
32 [2] Const mutate $14_@1 = true
33 [3] If (read $14_@1) then:bb2 else:bb6 fallthrough=bb1
34 bb2:
35 predecessor blocks: bb0
36 [4] Const mutate $15_@2 = true
37 + [5] Let mutate x$16_@3[5:10] = undefined
38 [5] If (read $15_@2) then:bb4 else:bb5 fallthrough=bb3
39 bb4:
40 predecessor blocks: bb2
40 - [6] Reassign mutate x$16_@3[6:9] = read a$9
41 + [6] Reassign mutate x$16_@3[5:10] = read a$9
42 [7] Goto bb3
43 bb5:
44 predecessor blocks: bb2
44 - [8] Reassign mutate x$17_@3[6:9] = read b$10
45 + [8] Reassign mutate x$16_@3[5:10] = read b$10
46 [9] Goto bb3
47 bb3:
48 predecessor blocks: bb4 bb5
48 - x$18_@3[6:9]: phi(bb4: x$16_@3, bb5: x$17_@3)
49 - [10] read x$18_@3
49 + [10] read x$16_@3
50 [11] Goto bb1
51 bb6:
52 predecessor blocks: bb0
53 [12] Const mutate $19_@4 = true
54 + [13] Let mutate x$20_@5[13:18] = undefined
55 [13] If (read $19_@4) then:bb8 else:bb9 fallthrough=bb7
56 bb8:
57 predecessor blocks: bb6
57 - [14] Reassign mutate x$20_@5[14:17] = read c$11
58 + [14] Reassign mutate x$20_@5[13:18] = read c$11
59 [15] Goto bb7
60 bb9:
61 predecessor blocks: bb6
61 - [16] Reassign mutate x$21_@5[14:17] = read d$12
62 + [16] Reassign mutate x$20_@5[13:18] = read d$12
63 [17] Goto bb7
64 bb7:
65 predecessor blocks: bb8 bb9
65 - x$22_@5[14:17]: phi(bb8: x$20_@5, bb9: x$21_@5)
66 - [18] read x$22_@5
66 + [18] read x$20_@5
67 [19] Goto bb1
68 bb1:
69 predecessor blocks: bb3 bb7
70 [20] Return
71 -scope3 [6:9]:
71 +scope3 [5:10]:
72 - read a$9
73 - read b$10
74 -scope5 [14:17]:
74 + - read $15_@2
75 +scope5 [13:18]:
76 - read c$11
77 - read d$12
78 + - read $19_@4
79 ```
80
81 ### CFG
@@ -83,7 +85,7 @@ flowchart TB
85 %% Basic Blocks
86 subgraph bb0
87 bb0_instrs["
86 - [1] Let mutate x$13_@0 = 0
88 + [1] Const mutate x$13_@0 = 0
89 [2] Const mutate $14_@1 = true
90 "]
91 bb0_instrs --> bb0_terminal(["If (read $14_@1)"])
@@ -91,48 +93,50 @@ flowchart TB
93 subgraph bb2
94 bb2_instrs["
95 [4] Const mutate $15_@2 = true
96 + [5] Let mutate x$16_@3[5:10] = undefined
97 "]
98 bb2_instrs --> bb2_terminal(["If (read $15_@2)"])
99 end
100 subgraph bb4
101 bb4_instrs["
99 - [6] Reassign mutate x$16_@3[6:9] = read a$9
102 + [6] Reassign mutate x$16_@3[5:10] = read a$9
103 "]
104 bb4_instrs --> bb4_terminal(["Goto"])
105 end
106 subgraph bb5
107 bb5_instrs["
105 - [8] Reassign mutate x$17_@3[6:9] = read b$10
108 + [8] Reassign mutate x$16_@3[5:10] = read b$10
109 "]
110 bb5_instrs --> bb5_terminal(["Goto"])
111 end
112 subgraph bb3
113 bb3_instrs["
111 - [10] read x$18_@3
114 + [10] read x$16_@3
115 "]
116 bb3_instrs --> bb3_terminal(["Goto"])
117 end
118 subgraph bb6
119 bb6_instrs["
120 [12] Const mutate $19_@4 = true
121 + [13] Let mutate x$20_@5[13:18] = undefined
122 "]
123 bb6_instrs --> bb6_terminal(["If (read $19_@4)"])
124 end
125 subgraph bb8
126 bb8_instrs["
123 - [14] Reassign mutate x$20_@5[14:17] = read c$11
127 + [14] Reassign mutate x$20_@5[13:18] = read c$11
128 "]
129 bb8_instrs --> bb8_terminal(["Goto"])
130 end
131 subgraph bb9
132 bb9_instrs["
129 - [16] Reassign mutate x$21_@5[14:17] = read d$12
133 + [16] Reassign mutate x$20_@5[13:18] = read d$12
134 "]
135 bb9_instrs --> bb9_terminal(["Goto"])
136 end
137 subgraph bb7
138 bb7_instrs["
135 - [18] read x$22_@5
139 + [18] read x$20_@5
140 "]
141 bb7_instrs --> bb7_terminal(["Goto"])
142 end
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+11 -10
@@ -20,27 +20,27 @@ function foo() {
20
21 ```
22 bb0:
23 - [1] Let mutate y$5_@0 = 2
23 + [1] Const mutate y$5_@0 = 2
24 [2] Const mutate $6_@1 = 1
25 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1
26 + [4] Let mutate y$8_@3[4:10] = undefined
27 [4] If (read $7_@2) then:bb2 else:bb3 fallthrough=bb1
28 bb2:
29 predecessor blocks: bb0
29 - [5] Reassign mutate y$8_@3[5:10] = 1
30 + [5] Reassign mutate y$8_@3[4:10] = 1
31 [6] Goto bb1
32 bb3:
33 predecessor blocks: bb0
33 - [7] Reassign mutate y$9_@3[5:10] = 2
34 + [7] Reassign mutate y$8_@3[4:10] = 2
35 [8] Goto bb1
36 bb1:
37 predecessor blocks: bb2 bb3
37 - y$10_@3[5:10]: phi(bb2: y$8_@3, bb3: y$9_@3)
38 - [9] Let mutate x$11_@3[5:10] = read y$10_@3
38 + [9] Const mutate x$11_@3[4:10] = read y$8_@3
39 [10] Return
40 scope2 [3:4]:
41 - read y$5_@0
42 - read $6_@1
43 -scope3 [5:10]:
43 +scope3 [4:10]:
44 - read $7_@2
45 ```
46
@@ -51,27 +51,28 @@ flowchart TB
51 %% Basic Blocks
52 subgraph bb0
53 bb0_instrs["
54 - [1] Let mutate y$5_@0 = 2
54 + [1] Const mutate y$5_@0 = 2
55 [2] Const mutate $6_@1 = 1
56 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1
57 + [4] Let mutate y$8_@3[4:10] = undefined
58 "]
59 bb0_instrs --> bb0_terminal(["If (read $7_@2)"])
60 end
61 subgraph bb2
62 bb2_instrs["
62 - [5] Reassign mutate y$8_@3[5:10] = 1
63 + [5] Reassign mutate y$8_@3[4:10] = 1
64 "]
65 bb2_instrs --> bb2_terminal(["Goto"])
66 end
67 subgraph bb3
68 bb3_instrs["
68 - [7] Reassign mutate y$9_@3[5:10] = 2
69 + [7] Reassign mutate y$8_@3[4:10] = 2
70 "]
71 bb3_instrs --> bb3_terminal(["Goto"])
72 end
73 subgraph bb1
74 bb1_instrs["
74 - [9] Let mutate x$11_@3[5:10] = read y$10_@3
75 + [9] Const mutate x$11_@3[4:10] = read y$8_@3
76 "]
77 bb1_instrs --> bb1_terminal(["Return"])
78 end
compiler/forget/src/__tests__/fixtures/hir/ssa-simple.expect.md
+4 -4
@@ -13,8 +13,8 @@ function foo() {
13
14 ```
15 bb0:
16 - [1] Let mutate x$3_@0 = 1
17 - [2] Let mutate y$4_@1 = 2
16 + [1] Const mutate x$3_@0 = 1
17 + [2] Const mutate y$4_@1 = 2
18 [3] Return
19
20 ```
@@ -26,8 +26,8 @@ flowchart TB
26 %% Basic Blocks
27 subgraph bb0
28 bb0_instrs["
29 - [1] Let mutate x$3_@0 = 1
30 - [2] Let mutate y$4_@1 = 2
29 + [1] Const mutate x$3_@0 = 1
30 + [2] Const mutate y$4_@1 = 2
31 "]
32 bb0_instrs --> bb0_terminal(["Return"])
33 end
compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md
+6 -6
@@ -17,12 +17,12 @@ function foo() {
17
18 ```
19 bb0:
20 - [1] Let mutate x$4_@0 = 1
21 - [2] Let mutate y$5_@1 = 2
20 + [1] Const mutate x$4_@0 = 1
21 + [2] Const mutate y$5_@1 = 2
22 [3] If (read y$5_@1) then:bb2 else:bb1 fallthrough=bb1
23 bb2:
24 predecessor blocks: bb0
25 - [4] Let mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1
25 + [4] Const mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1
26 [5] Goto bb1
27 bb1:
28 predecessor blocks: bb2 bb0
@@ -39,14 +39,14 @@ flowchart TB
39 %% Basic Blocks
40 subgraph bb0
41 bb0_instrs["
42 - [1] Let mutate x$4_@0 = 1
43 - [2] Let mutate y$5_@1 = 2
42 + [1] Const mutate x$4_@0 = 1
43 + [2] Const mutate y$5_@1 = 2
44 "]
45 bb0_instrs --> bb0_terminal(["If (read y$5_@1)"])
46 end
47 subgraph bb2
48 bb2_instrs["
49 - [4] Let mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1
49 + [4] Const mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1
50 "]
51 bb2_instrs --> bb2_terminal(["Goto"])
52 end
compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md
+17 -15
@@ -28,11 +28,12 @@ function foo() {
28
29 ```
30 bb0:
31 - [1] Let mutate x$10_@0 = 1
31 + [1] Const mutate x$10_@0 = 1
32 [2] Const mutate $11_@1 = 2
33 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1
34 [4] Const mutate $13_@3 = 1
35 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3
36 + [6] Let mutate x$16_@5[6:17] = undefined
37 [6] Switch (read x$10_@0)
38 Case read $14_@4: bb5
39 Case read $12_@2: bb3
@@ -40,23 +41,22 @@ bb0:
41 Fallthrough: bb1
42 bb5:
43 predecessor blocks: bb0
43 - [7] Const mutate $15_@5 = 1
44 - [8] Reassign mutate x$16_@6[8:17] = Binary read x$10_@0 + read $15_@5
44 + [7] Const mutate $15_@6 = 1
45 + [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6
46 [9] Goto bb1
47 bb3:
48 predecessor blocks: bb0
49 [10] Const mutate $17_@7 = 2
49 - [11] Reassign mutate x$18_@6[8:17] = Binary read x$10_@0 + read $17_@7
50 + [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7
51 [12] Goto bb1
52 bb2:
53 predecessor blocks: bb0
54 [13] Const mutate $19_@8 = 3
54 - [14] Reassign mutate x$20_@6[8:17] = Binary read x$10_@0 + read $19_@8
55 + [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8
56 [15] Goto bb1
57 bb1:
58 predecessor blocks: bb5 bb3 bb2
58 - x$21_@6[8:17]: phi(bb5: x$16_@6, bb3: x$18_@6, bb2: x$20_@6)
59 - [16] Let mutate y$22_@6[8:17] = read x$21_@6
59 + [16] Const mutate y$22_@5[6:17] = read x$16_@5
60 [17] Return
61 scope2 [3:4]:
62 - read x$10_@0
@@ -64,12 +64,13 @@ scope2 [3:4]:
64 scope4 [5:6]:
65 - read x$10_@0
66 - read $13_@3
67 -scope6 [8:17]:
67 +scope5 [6:17]:
68 - read x$10_@0
69 +scope8 [13:14]:
70 - read x$10_@0
71 scope7 [10:11]:
72 - read x$10_@0
72 -scope5 [7:8]:
73 +scope6 [7:8]:
74 - read x$10_@0
75 ```
76
@@ -80,38 +81,39 @@ flowchart TB
81 %% Basic Blocks
82 subgraph bb0
83 bb0_instrs["
83 - [1] Let mutate x$10_@0 = 1
84 + [1] Const mutate x$10_@0 = 1
85 [2] Const mutate $11_@1 = 2
86 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1
87 [4] Const mutate $13_@3 = 1
88 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3
89 + [6] Let mutate x$16_@5[6:17] = undefined
90 "]
91 bb0_instrs --> bb0_terminal(["Switch (read x$10_@0)"])
92 end
93 subgraph bb5
94 bb5_instrs["
93 - [7] Const mutate $15_@5 = 1
94 - [8] Reassign mutate x$16_@6[8:17] = Binary read x$10_@0 + read $15_@5
95 + [7] Const mutate $15_@6 = 1
96 + [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6
97 "]
98 bb5_instrs --> bb5_terminal(["Goto"])
99 end
100 subgraph bb3
101 bb3_instrs["
102 [10] Const mutate $17_@7 = 2
101 - [11] Reassign mutate x$18_@6[8:17] = Binary read x$10_@0 + read $17_@7
103 + [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7
104 "]
105 bb3_instrs --> bb3_terminal(["Goto"])
106 end
107 subgraph bb2
108 bb2_instrs["
109 [13] Const mutate $19_@8 = 3
108 - [14] Reassign mutate x$20_@6[8:17] = Binary read x$10_@0 + read $19_@8
110 + [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8
111 "]
112 bb2_instrs --> bb2_terminal(["Goto"])
113 end
114 subgraph bb1
115 bb1_instrs["
114 - [16] Let mutate y$22_@6[8:17] = read x$21_@6
116 + [16] Const mutate y$22_@5[6:17] = read x$16_@5
117 "]
118 bb1_instrs --> bb1_terminal(["Return"])
119 end
compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md
+9 -11
@@ -18,18 +18,16 @@ function foo() {
18 bb0:
19 [1] Let mutate x$4_@0[1:7] = 1
20 [2] Const mutate $5_@1 = 1
21 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1
22 - [4] If (read $6_@2) then:bb2 else:bb1 fallthrough=bb1
21 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1
22 + [4] If (read $6_@0) then:bb2 else:bb1 fallthrough=bb1
23 bb2:
24 predecessor blocks: bb0
25 - [5] Reassign mutate x$7_@0[1:7] = 2
25 + [5] Reassign mutate x$4_@0[1:7] = 2
26 [6] Goto bb1
27 bb1:
28 predecessor blocks: bb2 bb0
29 - x$8_@0[1:7]: phi(bb2: x$7_@0, bb0: x$4_@0)
30 - [7] Throw read x$8_@0
31 -scope2 [3:4]:
32 - - read $5_@1
29 + [7] Throw read x$4_@0
30 +
31 ```
32
33 ### CFG
@@ -41,18 +39,18 @@ flowchart TB
39 bb0_instrs["
40 [1] Let mutate x$4_@0[1:7] = 1
41 [2] Const mutate $5_@1 = 1
44 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1
42 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1
43 "]
46 - bb0_instrs --> bb0_terminal(["If (read $6_@2)"])
44 + bb0_instrs --> bb0_terminal(["If (read $6_@0)"])
45 end
46 subgraph bb2
47 bb2_instrs["
50 - [5] Reassign mutate x$7_@0[1:7] = 2
48 + [5] Reassign mutate x$4_@0[1:7] = 2
49 "]
50 bb2_instrs --> bb2_terminal(["Goto"])
51 end
52 subgraph bb1
55 - bb1_terminal(["Throw read x$8_@0"])
53 + bb1_terminal(["Throw read x$4_@0"])
54 end
55
56 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md
+2 -2
@@ -17,7 +17,7 @@ function foo() {
17
18 ```
19 bb0:
20 - [1] Let mutate x$5_@0 = 1
20 + [1] Const mutate x$5_@0 = 1
21 [2] While test=bb1 loop=bb3 fallthrough=bb2
22 bb1:
23 predecessor blocks: bb0 bb3
@@ -46,7 +46,7 @@ flowchart TB
46 %% Basic Blocks
47 subgraph bb0
48 bb0_instrs["
49 - [1] Let mutate x$5_@0 = 1
49 + [1] Const mutate x$5_@0 = 1
50 "]
51 bb0_instrs --> bb0_terminal(["While"])
52 end
compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md
+6 -7
@@ -21,18 +21,17 @@ bb0:
21 [2] While test=bb1 loop=bb3 fallthrough=bb2
22 bb1:
23 predecessor blocks: bb0 bb3
24 - x$7_@0[1:9]: phi(bb0: x$5_@0, bb3: x$10_@0)
24 [3] Const mutate $6_@1 = 10
26 - [4] Const mutate $8_@0[1:9] = Binary read x$7_@0 < read $6_@1
25 + [4] Const mutate $8_@0[1:9] = Binary read x$5_@0 < read $6_@1
26 [5] If (read $8_@0) then:bb3 else:bb2 fallthrough=bb2
27 bb3:
28 predecessor blocks: bb1
29 [6] Const mutate $9_@2 = 1
31 - [7] Reassign mutate x$10_@0[1:9] = Binary read x$7_@0 + read $9_@2
30 + [7] Reassign mutate x$5_@0[1:9] = Binary read x$5_@0 + read $9_@2
31 [8] Goto(Continue) bb1
32 bb2:
33 predecessor blocks: bb1
35 - [9] Return read x$7_@0
34 + [9] Return read x$5_@0
35
36 ```
37
@@ -50,19 +49,19 @@ flowchart TB
49 subgraph bb1
50 bb1_instrs["
51 [3] Const mutate $6_@1 = 10
53 - [4] Const mutate $8_@0[1:9] = Binary read x$7_@0 < read $6_@1
52 + [4] Const mutate $8_@0[1:9] = Binary read x$5_@0 < read $6_@1
53 "]
54 bb1_instrs --> bb1_terminal(["If (read $8_@0)"])
55 end
56 subgraph bb3
57 bb3_instrs["
58 [6] Const mutate $9_@2 = 1
60 - [7] Reassign mutate x$10_@0[1:9] = Binary read x$7_@0 + read $9_@2
59 + [7] Reassign mutate x$5_@0[1:9] = Binary read x$5_@0 + read $9_@2
60 "]
61 bb3_instrs --> bb3_terminal(["Goto"])
62 end
63 subgraph bb2
65 - bb2_terminal(["Return read x$7_@0"])
64 + bb2_terminal(["Return read x$5_@0"])
65 end
66
67 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md
+12 -11
@@ -32,7 +32,7 @@ function Component(props) {
32
33 ```
34 bb0:
35 - [1] Let mutate x$10_@0[1:12] = Array []
35 + [1] Const mutate x$10_@0[1:12] = Array []
36 [2] Let mutate y$11_@0[1:12] = undefined
37 [3] Const mutate $12_@1 = false
38 [4] Const mutate $13_@2 = true
@@ -46,18 +46,17 @@ bb0:
46 bb6:
47 predecessor blocks: bb0
48 [7] Call mutate x$10_@0.push(read props$9.p2)
49 - [8] Reassign mutate y$15_@0[1:12] = Array []
49 + [8] Reassign mutate y$11_@0[1:12] = Array []
50 [9] Goto bb1
51 bb2:
52 predecessor blocks: bb0
53 - [10] Reassign mutate y$16_@0[1:12] = read x$10_@0
53 + [10] Reassign mutate y$11_@0[1:12] = read x$10_@0
54 [11] Goto bb1
55 bb1:
56 predecessor blocks: bb0 bb6 bb2
57 - y$20_@0[1:12]: phi(bb0: y$11_@0, bb6: y$15_@0, bb2: y$16_@0)
57 [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$10_@0} ></read Component$0>
59 - [13] Call read y$20_@0.push(read props$9.p4)
60 - [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$20_@0} >{read child$19_@4}</read Component$0>
58 + [13] Call read y$11_@0.push(read props$9.p4)
59 + [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$11_@0} >{read child$19_@4}</read Component$0>
60 [15] Return read $22_@5
61 scope0 [1:12]:
62 - read props$9.p2
@@ -65,9 +64,11 @@ scope0 [1:12]:
64 scope4 [12:13]:
65 - read Component$0
66 - freeze x$10_@0
67 + - read y$11_@0.push
68 - read props$9.p4
69 scope5 [14:15]:
70 - read Component$0
71 + - freeze y$11_@0
72 - read child$19_@4
73 ```
74
@@ -78,7 +79,7 @@ flowchart TB
79 %% Basic Blocks
80 subgraph bb0
81 bb0_instrs["
81 - [1] Let mutate x$10_@0[1:12] = Array []
82 + [1] Const mutate x$10_@0[1:12] = Array []
83 [2] Let mutate y$11_@0[1:12] = undefined
84 [3] Const mutate $12_@1 = false
85 [4] Const mutate $13_@2 = true
@@ -89,21 +90,21 @@ flowchart TB
90 subgraph bb6
91 bb6_instrs["
92 [7] Call mutate x$10_@0.push(read props$9.p2)
92 - [8] Reassign mutate y$15_@0[1:12] = Array []
93 + [8] Reassign mutate y$11_@0[1:12] = Array []
94 "]
95 bb6_instrs --> bb6_terminal(["Goto"])
96 end
97 subgraph bb2
98 bb2_instrs["
98 - [10] Reassign mutate y$16_@0[1:12] = read x$10_@0
99 + [10] Reassign mutate y$11_@0[1:12] = read x$10_@0
100 "]
101 bb2_instrs --> bb2_terminal(["Goto"])
102 end
103 subgraph bb1
104 bb1_instrs["
105 [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$10_@0} ></read Component$0>
105 - [13] Call read y$20_@0.push(read props$9.p4)
106 - [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$20_@0} >{read child$19_@4}</read Component$0>
106 + [13] Call read y$11_@0.push(read props$9.p4)
107 + [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$11_@0} >{read child$19_@4}</read Component$0>
108 "]
109 bb1_instrs --> bb1_terminal(["Return read $22_@5"])
110 end
compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md
+14 -14
@@ -36,7 +36,7 @@ function foo(x) {
36
37 ```
38 bb0:
39 - [1] Let mutate y$10_@0 = undefined
39 + [1] Const mutate y$10_@0 = undefined
40 [2] Const mutate $11_@1 = 5
41 [3] Const mutate $12_@2 = 4
42 [4] Const mutate $13_@3 = 3
@@ -54,27 +54,27 @@ bb0:
54 Fallthrough: bb1
55 bb10:
56 predecessor blocks: bb0
57 - [9] Reassign mutate y$17_@7 = 0
57 + [9] Const mutate y$17_@7 = 0
58 [10] Goto bb9
59 bb9:
60 predecessor blocks: bb10 bb0
61 - [11] Reassign mutate y$18_@8 = 1
61 + [11] Const mutate y$18_@8 = 1
62 [12] Goto bb1
63 bb5:
64 predecessor blocks: bb0
65 - [13] Reassign mutate y$19_@9 = 3
65 + [13] Const mutate y$19_@9 = 3
66 [14] Goto bb1
67 bb4:
68 predecessor blocks: bb0
69 - [15] Reassign mutate y$20_@10 = 4
69 + [15] Const mutate y$20_@10 = 4
70 [16] Goto bb3
71 bb3:
72 predecessor blocks: bb4 bb0
73 - [17] Reassign mutate y$21_@11 = 5
73 + [17] Const mutate y$21_@11 = 5
74 [18] Goto bb2
75 bb2:
76 predecessor blocks: bb3 bb0
77 - [19] Reassign mutate y$22_@12 = 0
77 + [19] Const mutate y$22_@12 = 0
78 [20] Goto bb1
79 bb1:
80 predecessor blocks: bb9 bb0 bb5 bb2
@@ -89,7 +89,7 @@ flowchart TB
89 %% Basic Blocks
90 subgraph bb0
91 bb0_instrs["
92 - [1] Let mutate y$10_@0 = undefined
92 + [1] Const mutate y$10_@0 = undefined
93 [2] Const mutate $11_@1 = 5
94 [3] Const mutate $12_@2 = 4
95 [4] Const mutate $13_@3 = 3
@@ -101,37 +101,37 @@ flowchart TB
101 end
102 subgraph bb10
103 bb10_instrs["
104 - [9] Reassign mutate y$17_@7 = 0
104 + [9] Const mutate y$17_@7 = 0
105 "]
106 bb10_instrs --> bb10_terminal(["Goto"])
107 end
108 subgraph bb9
109 bb9_instrs["
110 - [11] Reassign mutate y$18_@8 = 1
110 + [11] Const mutate y$18_@8 = 1
111 "]
112 bb9_instrs --> bb9_terminal(["Goto"])
113 end
114 subgraph bb5
115 bb5_instrs["
116 - [13] Reassign mutate y$19_@9 = 3
116 + [13] Const mutate y$19_@9 = 3
117 "]
118 bb5_instrs --> bb5_terminal(["Goto"])
119 end
120 subgraph bb4
121 bb4_instrs["
122 - [15] Reassign mutate y$20_@10 = 4
122 + [15] Const mutate y$20_@10 = 4
123 "]
124 bb4_instrs --> bb4_terminal(["Goto"])
125 end
126 subgraph bb3
127 bb3_instrs["
128 - [17] Reassign mutate y$21_@11 = 5
128 + [17] Const mutate y$21_@11 = 5
129 "]
130 bb3_instrs --> bb3_terminal(["Goto"])
131 end
132 subgraph bb2
133 bb2_instrs["
134 - [19] Reassign mutate y$22_@12 = 0
134 + [19] Const mutate y$22_@12 = 0
135 "]
136 bb2_instrs --> bb2_terminal(["Goto"])
137 end
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+12 -11
@@ -28,7 +28,7 @@ function Component(props) {
28
29 ```
30 bb0:
31 - [1] Let mutate x$9_@0[1:12] = Array []
31 + [1] Const mutate x$9_@0[1:12] = Array []
32 [2] Let mutate y$10_@0[1:12] = undefined
33 [3] Const mutate $11_@1 = false
34 [4] Const mutate $12_@2 = true
@@ -41,18 +41,17 @@ bb4:
41 predecessor blocks: bb0
42 [6] Call mutate x$9_@0.push(read props$8.p2)
43 [7] Call mutate x$9_@0.push(read props$8.p3)
44 - [8] Reassign mutate y$13_@3 = Array []
44 + [8] Const mutate y$13_@3 = Array []
45 [9] Goto bb2
46 bb2:
47 predecessor blocks: bb4 bb0
48 - [10] Reassign mutate y$15_@0[1:12] = read x$9_@0
48 + [10] Reassign mutate y$10_@0[1:12] = read x$9_@0
49 [11] Goto bb1
50 bb1:
51 predecessor blocks: bb2 bb0
52 - y$20_@0[1:12]: phi(bb2: y$15_@0, bb0: y$10_@0)
52 [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$9_@0} ></read Component$0>
54 - [13] Call read y$20_@0.push(read props$8.p4)
55 - [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$20_@0} >{read child$19_@4}</read Component$0>
53 + [13] Call read y$10_@0.push(read props$8.p4)
54 + [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$10_@0} >{read child$19_@4}</read Component$0>
55 [15] Return read $23_@5
56 scope0 [1:12]:
57 - read props$8.p2
@@ -61,9 +60,11 @@ scope0 [1:12]:
60 scope4 [12:13]:
61 - read Component$0
62 - freeze x$9_@0
63 + - read y$10_@0.push
64 - read props$8.p4
65 scope5 [14:15]:
66 - read Component$0
67 + - read y$10_@0
68 - read child$19_@4
69 ```
70
@@ -74,7 +75,7 @@ flowchart TB
75 %% Basic Blocks
76 subgraph bb0
77 bb0_instrs["
77 - [1] Let mutate x$9_@0[1:12] = Array []
78 + [1] Const mutate x$9_@0[1:12] = Array []
79 [2] Let mutate y$10_@0[1:12] = undefined
80 [3] Const mutate $11_@1 = false
81 [4] Const mutate $12_@2 = true
@@ -85,21 +86,21 @@ flowchart TB
86 bb4_instrs["
87 [6] Call mutate x$9_@0.push(read props$8.p2)
88 [7] Call mutate x$9_@0.push(read props$8.p3)
88 - [8] Reassign mutate y$13_@3 = Array []
89 + [8] Const mutate y$13_@3 = Array []
90 "]
91 bb4_instrs --> bb4_terminal(["Goto"])
92 end
93 subgraph bb2
94 bb2_instrs["
94 - [10] Reassign mutate y$15_@0[1:12] = read x$9_@0
95 + [10] Reassign mutate y$10_@0[1:12] = read x$9_@0
96 "]
97 bb2_instrs --> bb2_terminal(["Goto"])
98 end
99 subgraph bb1
100 bb1_instrs["
101 [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$9_@0} ></read Component$0>
101 - [13] Call read y$20_@0.push(read props$8.p4)
102 - [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$20_@0} >{read child$19_@4}</read Component$0>
102 + [13] Call read y$10_@0.push(read props$8.p4)
103 + [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$10_@0} >{read child$19_@4}</read Component$0>
104 "]
105 bb1_instrs --> bb1_terminal(["Return read $23_@5"])
106 end
compiler/forget/src/__tests__/hir-test.ts
+3 -15
@@ -127,32 +127,20 @@ function transform(
127 traverse(ast, {
128 FunctionDeclaration: {
129 enter(nodePath) {
130 - const { ir } = run(nodePath, {
130 + const { ir, ast } = run(nodePath, {
131 eliminateRedundantPhi: true,
132 inferReferenceEffects: true,
133 inferMutableRanges: true,
134 inferReactiveScopeVariables: true,
135 inferReactiveScopes: true,
136 inferReactiveScopeDependencies: true,
137 - leaveSSA: false,
138 - codegen: false,
137 + leaveSSA: true,
138 + codegen: true,
139 });
140
141 - // Print the HIR before leaving SSA.
141 const textHIR = printFunction(ir);
142 const visualization = visualizeHIRMermaid(ir);
143
145 - const { ast } = run(nodePath, {
146 - eliminateRedundantPhi: true,
147 - inferReferenceEffects: true,
148 - inferMutableRanges: true,
149 - inferReactiveScopeVariables: true,
150 - inferReactiveScopes: true,
151 - inferReactiveScopeDependencies: true,
152 - leaveSSA: true,
153 - codegen: true,
154 - });
155 -
144 invariant(ast !== null, "ast is null when codegen option is enabled");
145 const text = prettier.format(generate(ast).code.replace("\n\n", "\n"), {
146 semi: true,