@samitouri / QOS-React-2 / commits / 6efac28677

Prune unnecessary labels in output

Joe Savona committed Dec 14, 2022 at 16:42 UTC 6efac286770f8b104aea68bf84ae28c8286a24b2
59 files changed +184 -97
compiler/forget/src/HIR/Pipeline.ts
+2
@@ -23,6 +23,7 @@ import { inferTypes } from "./InferTypes";
23 import { logHIRFunction } from "./logger";
24 import { printReactiveFunction } from "./PrintReactiveFunction";
25 import { propagateScopeDependencies } from "./PropagateScopeDependencies";
26 +import { pruneUnusedLabels } from "./PruneUnusedLabels";
27
28 export type CompilerFlags = {
29 eliminateRedundantPhi: boolean;
@@ -89,6 +90,7 @@ export default function (
90
91 if (flags.codegen) {
92 const reactiveFunction = buildReactiveFunction(ir);
93 + pruneUnusedLabels(reactiveFunction);
94 flattenReactiveLoops(reactiveFunction);
95 propagateScopeDependencies(reactiveFunction);
96 const scopes = printReactiveFunction(reactiveFunction);
compiler/forget/src/HIR/PruneUnusedLabels.ts new
+83
@@ -0,0 +1,83 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + */
7 +
8 +import { assertExhaustive } from "../Common/utils";
9 +import {
10 + BlockId,
11 + ReactiveBasicBlock,
12 + ReactiveFunction,
13 + ReactiveTerminal,
14 +} from "./HIR";
15 +
16 +/**
17 + * Prunes terminal labels that are never explicitly jumped to.
18 + */
19 +export function pruneUnusedLabels(fn: ReactiveFunction): void {
20 + const labels: Labels = new Set();
21 + visitBlock(labels, fn.body);
22 +}
23 +
24 +type Labels = Set<BlockId>;
25 +
26 +function visitBlock(labels: Labels, block: ReactiveBasicBlock): void {
27 + for (const item of block) {
28 + if (item.kind === "terminal") {
29 + // first visit the terminal's contents, which is the only place that can
30 + // reference the terminal's label
31 + visitTerminal(labels, item.terminal);
32 + // if the label wasn't referenced by a break/continue, we can prune it
33 + if (item.label !== null && !labels.has(item.label)) {
34 + item.label = null;
35 + }
36 + } else if (item.kind === "block") {
37 + visitBlock(labels, item.instructions);
38 + }
39 + }
40 +}
41 +
42 +function visitTerminal(labels: Labels, terminal: ReactiveTerminal): void {
43 + switch (terminal.kind) {
44 + case "break":
45 + case "continue": {
46 + if (terminal.label !== null) {
47 + labels.add(terminal.label);
48 + }
49 + break;
50 + }
51 + case "for": {
52 + visitBlock(labels, terminal.loop);
53 + break;
54 + }
55 + case "if": {
56 + visitBlock(labels, terminal.consequent);
57 + if (terminal.alternate !== null) {
58 + visitBlock(labels, terminal.alternate);
59 + }
60 + break;
61 + }
62 + case "return":
63 + case "throw": {
64 + break;
65 + }
66 + case "switch": {
67 + for (const case_ of terminal.cases) {
68 + visitBlock(labels, case_.block!);
69 + }
70 + break;
71 + }
72 + case "while": {
73 + visitBlock(labels, terminal.loop);
74 + break;
75 + }
76 + default: {
77 + assertExhaustive(
78 + terminal,
79 + `Unexpected terminal kind '${(terminal as any).kind}'`
80 + );
81 + }
82 + }
83 +}
compiler/forget/src/__tests__/fixtures/hir/_bug_conditional-break-labeled.expect.md
+1 -1
@@ -69,7 +69,7 @@ function Component$0(props$3) {
69 const a$4 = [];
70 a$4.push(props$3.a);
71
72 - bb2: if (props$3.b) {
72 + if (props$3.b) {
73 a$4.push(props$3.d);
74 return a$4;
75 }
compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md
+1 -1
@@ -92,7 +92,7 @@ function foo$0(cond$7) {
92 b$9 = {};
93 c$10 = {};
94
95 - bb2: while (cond$7) {
95 + while (cond$7) {
96 const z$13 = a$8;
97 a$8 = b$9;
98 b$9 = c$10;
compiler/forget/src/__tests__/fixtures/hir/complex-while.expect.md
+2 -2
@@ -62,9 +62,9 @@ function foo(
62
63 ```javascript
64 function foo$0(a$4, b$5, c$6) {
65 - bb1: if (a$4) {
65 + if (a$4) {
66 while (b$5) {
67 - bb7: if (c$6) {
67 + if (c$6) {
68 break;
69 }
70 }
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+4 -4
@@ -189,21 +189,21 @@ function Component$0(props$29) {
189 } else {
190 }
191
192 - bb2: for (let i$36 = 0; i$36 < items$30.length; i$36 = i$36 + 1, i$36) {
192 + for (let i$36 = 0; i$36 < items$30.length; i$36 = i$36 + 1, i$36) {
193 const item$40 = items$30.at(i$36);
194
195 - bb9: if (item$40 == null) {
195 + if (item$40 == null) {
196 } else {
197 }
198
199 - bb6: if (seen$33.has(item$40)) {
199 + if (seen$33.has(item$40)) {
200 continue;
201 }
202
203 seen$33.add(item$40);
204 renderedItems$32.push(<div>{item$40}</div>);
205
206 - bb12: if (renderedItems$32.length >= max$35) {
206 + if (renderedItems$32.length >= max$35) {
207 break;
208 }
209 }
compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md
+5 -5
@@ -124,7 +124,7 @@ function Component$0(props$4) {
124 a_DEBUG$5 = [];
125 a_DEBUG$5.push(props$4.a);
126
127 - bb1: if (props$4.b) {
127 + if (props$4.b) {
128 return null;
129 }
130
@@ -191,7 +191,7 @@ function Component$0(props$3) {
191 a$4 = [];
192 a$4.push(props$3.a);
193
194 - bb1: if (props$3.b) {
194 + if (props$3.b) {
195 a$4.push(props$3.c);
196 }
197
@@ -262,7 +262,7 @@ function Component$0(props$4) {
262 a$5 = [];
263 a$5.push(props$4.a);
264
265 - bb1: if (props$4.b) {
265 + if (props$4.b) {
266 a$5.push(props$4.c);
267 return null;
268 }
@@ -332,7 +332,7 @@ function Component$0(props$3) {
332 a$4 = [];
333 a$4.push(props$3.a);
334
335 - bb1: if (props$3.b) {
335 + if (props$3.b) {
336 a$4.push(props$3.c);
337 return a$4;
338 }
@@ -400,7 +400,7 @@ function Component$0(props$3) {
400 const a$4 = [];
401 a$4.push(props$3.a);
402
403 - bb2: if (props$3.b) {
403 + if (props$3.b) {
404 a$4.push(props$3.d);
405 return a$4;
406 }
compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md
+4 -4
@@ -92,11 +92,11 @@ function Component$0(props$6) {
92 a$7 = [];
93 const b$8 = [];
94
95 - bb1: if (b$8) {
95 + if (b$8) {
96 a$7.push(props$6.p0);
97 }
98
99 - bb3: if (props$6.p1) {
99 + if (props$6.p1) {
100 b$8.push(props$6.p2);
101 }
102
@@ -188,11 +188,11 @@ function Component$0(props$8) {
188 a$9 = [];
189 const b$10 = [];
190
191 - bb1: if (mayMutate$4(b$10)) {
191 + if (mayMutate$4(b$10)) {
192 a$9.push(props$8.p0);
193 }
194
195 - bb3: if (props$8.p1) {
195 + if (props$8.p1) {
196 b$10.push(props$8.p2);
197 }
198
compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md
+2 -2
@@ -94,11 +94,11 @@ function foo$0(a$6, b$7) {
94 if (c_2 || c_3) {
95 const y$10 = [];
96
97 - bb1: if (x$8.length) {
97 + if (x$8.length) {
98 y$10.push(x$8);
99 }
100
101 - bb3: if (b$7) {
101 + if (b$7) {
102 y$10.push(b$7);
103 }
104
compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md
+2 -2
@@ -88,7 +88,7 @@ function foo$0(x$6, y$7, z$8) {
88 if (c_3 || c_4) {
89 items2$10 = [];
90
91 - bb1: if (x$6) {
91 + if (x$6) {
92 items2$10.push(y$7);
93 }
94
@@ -99,7 +99,7 @@ function foo$0(x$6, y$7, z$8) {
99 items2$10 = $[5];
100 }
101
102 - bb3: if (y$7) {
102 + if (y$7) {
103 items$9.push(x$6);
104 }
105
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md
+2 -2
@@ -87,7 +87,7 @@ function foo$0(a$7, b$8, c$9) {
87 if (c_0 || c_1 || c_2) {
88 const x$10 = [];
89
90 - bb1: if (a$7) {
90 + if (a$7) {
91 if (b$8) {
92 if (c$9) {
93 x$10.push(0);
@@ -101,7 +101,7 @@ function foo$0(a$7, b$8, c$9) {
101 } else {
102 }
103
104 - bb7: if (a$7.length) {
104 + if (a$7.length) {
105 return a$7;
106 }
107
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md
+1 -1
@@ -86,7 +86,7 @@ function Component$0(props$7) {
86 if (c_0 || c_1) {
87 a$11 = undefined;
88
89 - bb1: if (cond$8) {
89 + if (cond$8) {
90 a$11 = x$9;
91 } else {
92 a$11 = [];
compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md
+1 -1
@@ -178,7 +178,7 @@ function Component$0(props$8) {
178 a$9 = compute$3(props$8.a);
179 const b$10 = compute$3(props$8.b);
180
181 - bb1: if (props$8.c) {
181 + if (props$8.c) {
182 mutate$5(a$9);
183 mutate$5(b$10);
184 }
compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md
+1 -1
@@ -148,7 +148,7 @@ function Component$0(props$8) {
148 a$9 = compute$3(props$8.a);
149 b$10 = compute$3(props$8.b);
150
151 - bb1: if (props$8.c) {
151 + if (props$8.c) {
152 foo$5(a$9, b$10);
153 }
154
compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md
+1 -1
@@ -64,7 +64,7 @@ function foo$0(a$5, b$6, c$7) {
64 if (c_0 || c_1 || c_2) {
65 const y$8 = [];
66
67 - bb1: if (a$5) {
67 + if (a$5) {
68 if (b$6) {
69 y$8.push(c$7);
70 }
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
+3 -3
@@ -79,7 +79,7 @@ function And$0() {
79 if (c_1) {
80 t2$6 = undefined;
81
82 - bb1: if (t0$5) {
82 + if (t0$5) {
83 t2$6 = g$4();
84 } else {
85 t2$6 = t0$5;
@@ -155,7 +155,7 @@ function Or$0() {
155 if (c_1) {
156 t2$6 = undefined;
157
158 - bb1: if (t0$5) {
158 + if (t0$5) {
159 t2$6 = t0$5;
160 } else {
161 t2$6 = g$4();
@@ -236,7 +236,7 @@ function QuestionQuestion$0(props$8) {
236 if (c_1) {
237 t2$12 = undefined;
238
239 - bb1: if (t0$9 != null) {
239 + if (t0$9 != null) {
240 t2$12 = t0$9;
241 } else {
242 t2$12 = g$7();
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
+6 -6
@@ -184,7 +184,7 @@ function Component$0(props$12) {
184 let b$20 = {};
185 let c$22 = {};
186 let d$24 = {};
187 - bb2: while (true) {
187 + while (true) {
188 const z$19 = a$18;
189 a$18 = b$20;
190 b$20 = c$22;
@@ -192,21 +192,21 @@ function Component$0(props$12) {
192 d$24 = z$19;
193 mutate$7(a$18, b$20);
194
195 - bb4: if (cond$8(a$18)) {
195 + if (cond$8(a$18)) {
196 break;
197 }
198 }
199
200 - bb7: if (a$18) {
200 + if (a$18) {
201 }
202
203 - bb9: if (b$20) {
203 + if (b$20) {
204 }
205
206 - bb11: if (c$22) {
206 + if (c$22) {
207 }
208
209 - bb13: if (d$24) {
209 + if (d$24) {
210 }
211
212 mutate$7(d$24, null);
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+5 -5
@@ -157,19 +157,19 @@ function Component$0(props$10) {
157 x$15.b = b$12;
158 const y$16 = mutate$8(x$15, d$14);
159
160 - bb1: if (a$11) {
160 + if (a$11) {
161 }
162
163 - bb3: if (b$12) {
163 + if (b$12) {
164 }
165
166 - bb5: if (c$13) {
166 + if (c$13) {
167 }
168
169 - bb7: if (d$14) {
169 + if (d$14) {
170 }
171
172 - bb9: if (y$16) {
172 + if (y$16) {
173 }
174
175 mutate$8(x$15, null);
compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md
+6 -6
@@ -173,24 +173,24 @@ function Component$0(props$11) {
173
174 const d$15 = {};
175
176 - bb2: while (true) {
176 + while (true) {
177 mutate$6(a$12, b$13);
178
179 - bb4: if (cond$7(a$12)) {
179 + if (cond$7(a$12)) {
180 break;
181 }
182 }
183
184 - bb7: if (a$12) {
184 + if (a$12) {
185 }
186
187 - bb9: if (b$13) {
187 + if (b$13) {
188 }
189
190 - bb11: if (c$14) {
190 + if (c$14) {
191 }
192
193 - bb13: if (d$15) {
193 + if (d$15) {
194 }
195
196 mutate$6(d$15, null);
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved-by-terminal.expect.md
+1 -1
@@ -61,7 +61,7 @@ function foo$0(a$6, b$7, c$8) {
61 const x$9 = [];
62 const y$10 = [];
63
64 - bb1: if (x$9) {
64 + if (x$9) {
65 }
66
67 y$10.push(a$6);
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md
+2 -2
@@ -83,7 +83,7 @@ function foo$0(a$8, b$9, c$10) {
83 if (c_0 || c_1 || c_2) {
84 x$11 = [];
85
86 - bb1: if (a$8) {
86 + if (a$8) {
87 const c_4 = $[4] !== b$9;
88 const c_5 = $[5] !== c$10;
89 let y$12;
@@ -91,7 +91,7 @@ function foo$0(a$8, b$9, c$10) {
91 if (c_4 || c_5) {
92 y$12 = [];
93
94 - bb3: if (b$9) {
94 + if (b$9) {
95 y$12.push(c$10);
96 }
97
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md
+1 -1
@@ -68,7 +68,7 @@ function foo$0(a$6, b$7, c$8) {
68 const x$9 = [];
69 const y$10 = [];
70
71 - bb2: while (c$8) {
71 + while (c$8) {
72 y$10.push(b$7);
73 x$9.push(a$6);
74 }
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md
+2 -2
@@ -75,10 +75,10 @@ function foo$0(a$6, b$7, c$8) {
75 if (c_0 || c_1 || c_2) {
76 x$9 = [];
77
78 - bb1: if (a$6) {
78 + if (a$6) {
79 const y$10 = [];
80
81 - bb3: if (b$7) {
81 + if (b$7) {
82 y$10.push(c$8);
83 }
84
compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md
+1 -1
@@ -80,7 +80,7 @@ function foo$0(a$8, b$9, c$10) {
80 if (c_0 || c_1 || c_2) {
81 x$11 = [];
82
83 - bb1: if (a$8) {
83 + if (a$8) {
84 const c_4 = $[4] !== b$9;
85 let y$12;
86
compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md
+1 -1
@@ -74,7 +74,7 @@ function f$0(a$8, b$9) {
74 if (c_0 || c_1) {
75 x$10 = [];
76
77 - bb1: if (a$8.length === 1) {
77 + if (a$8.length === 1) {
78 if (b$9) {
79 x$10.push(b$9);
80 }
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
+1 -1
@@ -78,7 +78,7 @@ function Component$0(props$6) {
78 x$7.push(props$6.p0);
79 const y$8 = x$7;
80
81 - bb1: if (props$6.p1) {
81 + if (props$6.p1) {
82 x$7 = [];
83 }
84
compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md
+1 -1
@@ -125,7 +125,7 @@ function foo$0(a$13, b$14, c$15) {
125 if (c_0) {
126 x$16 = [];
127
128 - bb1: if (a$13) {
128 + if (a$13) {
129 x$16.push(a$13);
130 }
131
compiler/forget/src/__tests__/fixtures/hir/simple.expect.md
+1 -1
@@ -58,7 +58,7 @@ function foo(
58 ```javascript
59 function foo$0(x$8, y$9) {
60 const $ = React.useMemoCache();
61 - bb1: if (x$8) {
61 + if (x$8) {
62 const c_0 = $[0] !== y$9;
63 let t1$11;
64
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md
+1 -1
@@ -109,7 +109,7 @@ function Component$0(props$10) {
109 } else {
110 }
111
112 - bb1: if (foo$4()) {
112 + if (foo$4()) {
113 const c_2 = $[2] !== a$11;
114
115 if (c_2) {
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+2 -2
@@ -80,11 +80,11 @@ function foo$0() {
80 x$7 = 1;
81 const y$8 = 2;
82
83 - bb1: if (y$8 === 2) {
83 + if (y$8 === 2) {
84 x$7 = 3;
85 }
86
87 - bb3: if (y$8 === 3) {
87 + if (y$8 === 3) {
88 x$7 = 5;
89 }
90
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+1 -1
@@ -63,7 +63,7 @@ function foo$0() {
63 x$5 = 1;
64 const y$6 = 2;
65
66 - bb1: if (y$6 === 2) {
66 + if (y$6 === 2) {
67 x$5 = 3;
68 }
69
compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md
+1 -1
@@ -75,7 +75,7 @@ function foo$0() {
75 if (true) {
76 x$6 = 1;
77
78 - bb2: for (const i$7 = 0; i$7 < 10; i$7) {
78 + for (const i$7 = 0; i$7 < 10; i$7) {
79 x$6 = x$6 + 1;
80 }
81
compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md
+1 -1
@@ -79,7 +79,7 @@ function foo$0() {
79 if (true) {
80 x$7 = 1;
81
82 - bb2: for (let i$8 = 0; i$8 < 10; i$8 = i$8 + 1, i$8) {
82 + for (let i$8 = 0; i$8 < 10; i$8 = i$8 + 1, i$8) {
83 x$7 = x$7 + 1;
84 }
85
compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md
+1 -1
@@ -58,7 +58,7 @@ function foo(
58 function foo$0() {
59 const x$5 = 1;
60 const y$6 = 2;
61 - bb1: if (y$6) {
61 + if (y$6) {
62 const z$7 = x$5 + y$6;
63 } else {
64 const z$8 = x$5;
compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md
+3 -3
@@ -119,8 +119,8 @@ function foo$0(a$9, b$10, c$11, d$12) {
119 if (c_0 || c_1 || c_2 || c_3) {
120 x$18 = undefined;
121
122 - bb1: if (true) {
123 - bb3: if (true) {
122 + if (true) {
123 + if (true) {
124 x$18 = a$9;
125 } else {
126 x$18 = b$10;
@@ -128,7 +128,7 @@ function foo$0(a$9, b$10, c$11, d$12) {
128
129 x$18;
130 } else {
131 - bb7: if (true) {
131 + if (true) {
132 x$18 = c$11;
133 } else {
134 x$18 = d$12;
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md
+3 -3
@@ -87,9 +87,9 @@ function foo(
87 ```javascript
88 function foo$0(a$6, b$7, c$8) {
89 const x$9 = 0;
90 - bb2: while (a$6) {
91 - bb5: while (b$7) {
92 - bb8: while (c$8) {
90 + while (a$6) {
91 + while (b$7) {
92 + while (c$8) {
93 x$9 + 1;
94 }
95 }
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md
+2 -2
@@ -69,8 +69,8 @@ function foo$0(a$5, b$6, c$7) {
69 if (c_0 || c_1 || c_2) {
70 const x$8 = a$5;
71
72 - bb1: if (b$6) {
73 - bb3: if (c$7) {
72 + if (b$6) {
73 + if (c$7) {
74 x$8 = c$7;
75 }
76
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md
+1 -1
@@ -76,7 +76,7 @@ function foo$0(a$7, b$8, c$9, d$10, e$11) {
76 if (c_0 || c_1 || c_2 || c_3) {
77 x$12 = null;
78
79 - bb1: if (a$7) {
79 + if (a$7) {
80 x$12 = b$8;
81 } else {
82 if (c$9) {
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+1 -1
@@ -75,7 +75,7 @@ function foo$0() {
75 x$6 = 1;
76 let y$7 = 2;
77
78 - bb1: if (x$6 > 1) {
78 + if (x$6 > 1) {
79 x$6 = 2;
80 } else {
81 y$7 = 3;
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md
+1 -1
@@ -75,7 +75,7 @@ function foo$0(a$7) {
75 const b$8 = {};
76 x$9 = b$8;
77
78 - bb1: if (a$7) {
78 + if (a$7) {
79 const y$10 = {};
80 x$9.y = y$10;
81 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md
+1 -1
@@ -72,7 +72,7 @@ function foo$0(a$5) {
72 if (c_0) {
73 x$6 = {};
74
75 - bb1: if (a$5) {
75 + if (a$5) {
76 if (true) {
77 const y$7 = {};
78 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md
+1 -1
@@ -71,7 +71,7 @@ function foo$0(a$6) {
71 if (c_0) {
72 x$7 = {};
73
74 - bb1: if (a$6) {
74 + if (a$6) {
75 const y$8 = {};
76 x$7.y = y$8;
77 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md
+1 -1
@@ -73,7 +73,7 @@ function foo$0(a$6) {
73 if (c_0) {
74 x$7 = {};
75
76 - bb1: if (a$6) {
76 + if (a$6) {
77 const y$8 = {};
78 x$7.y = y$8;
79 mutate$4(y$8);
compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md
+1 -1
@@ -57,7 +57,7 @@ function foo$0() {
57 if (true) {
58 x$4 = 1;
59
60 - bb1: if (x$4 === 1) {
60 + if (x$4 === 1) {
61 x$4 = 2;
62 }
63
compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md
+1 -1
@@ -92,7 +92,7 @@ function Foo$0(cond$5) {
92 if (c_0) {
93 str$6 = "";
94
95 - bb1: if (cond$5) {
95 + if (cond$5) {
96 const str$7 = "other test";
97 log$4(str$7);
98 } else {
compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md
+3 -3
@@ -115,7 +115,7 @@ function foo(
115 function foo$0(a$9, b$10, c$11, d$12) {
116 const $ = React.useMemoCache();
117 const x$13 = 0;
118 - bb1: if (true) {
118 + if (true) {
119 const c_0 = $[0] !== a$9;
120 const c_1 = $[1] !== b$10;
121 let x$16;
@@ -123,7 +123,7 @@ function foo$0(a$9, b$10, c$11, d$12) {
123 if (c_0 || c_1) {
124 x$16 = undefined;
125
126 - bb3: if (true) {
126 + if (true) {
127 x$16 = a$9;
128 } else {
129 x$16 = b$10;
@@ -145,7 +145,7 @@ function foo$0(a$9, b$10, c$11, d$12) {
145 if (c_3 || c_4) {
146 x$20 = undefined;
147
148 - bb7: if (true) {
148 + if (true) {
149 x$20 = c$11;
150 } else {
151 x$20 = d$12;
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+1 -1
@@ -71,7 +71,7 @@ function foo$0() {
71 if (true) {
72 y$8 = undefined;
73
74 - bb1: if (y$5 > 1) {
74 + if (y$5 > 1) {
75 y$8 = 1;
76 } else {
77 y$8 = 2;
compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md
+1 -1
@@ -50,7 +50,7 @@ function foo(
50 function foo$0() {
51 const x$4 = 1;
52 const y$5 = 2;
53 - bb1: if (y$5) {
53 + if (y$5) {
54 const z$6 = x$4 + y$5;
55 }
56 }
compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md
+1 -1
@@ -56,7 +56,7 @@ function foo$0() {
56 if (true) {
57 x$4 = 1;
58
59 - bb1: if (x$4 === 1) {
59 + if (x$4 === 1) {
60 x$4 = 2;
61 }
62
compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md
+1 -1
@@ -58,7 +58,7 @@ function foo(
58 ```javascript
59 function foo$0() {
60 const x$5 = 1;
61 - bb2: while (x$5 < 10) {
61 + while (x$5 < 10) {
62 x$5 + 1;
63 }
64
compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md
+1 -1
@@ -64,7 +64,7 @@ function foo$0() {
64 if (true) {
65 x$5 = 1;
66
67 - bb2: while (x$5 < 10) {
67 + while (x$5 < 10) {
68 x$5 = x$5 + 1;
69 }
70
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+1 -1
@@ -103,7 +103,7 @@ function Component$0(props$8) {
103 x$9 = [];
104 let y$10 = undefined;
105
106 - bb1: switch (props$8.p0) {
106 + switch (props$8.p0) {
107 case true: {
108 x$9.push(props$8.p2);
109 x$9.push(props$8.p3);
compiler/forget/src/__tests__/fixtures/hir/type-args-test-binary-operator.expect.md
+1 -1
@@ -47,7 +47,7 @@ function component(
47
48 ```javascript
49 function component$0(a$5, b$6) {
50 - bb1: if (a$5 > b$6) {
50 + if (a$5 > b$6) {
51 if (true) {
52 const m$8 = {};
53 } else {
compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md
+1 -1
@@ -73,7 +73,7 @@ function component$0() {
73 b$8 = $[1];
74 }
75
76 - bb1: if (a$7 > b$8) {
76 + if (a$7 > b$8) {
77 if (true) {
78 const m$10 = {};
79 } else {
compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md
+1 -1
@@ -100,7 +100,7 @@ function component$0() {
100 const u$13 = x$12.u;
101 const v$14 = x$12.v;
102
103 - bb1: if (u$13 > v$14) {
103 + if (u$13 > v$14) {
104 }
105
106 const y$16 = x$12.u;
compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md
+1 -1
@@ -79,7 +79,7 @@ function component$0() {
79 y$8 = $[1];
80 }
81
82 - bb1: if (x$7 > y$8) {
82 + if (x$7 > y$8) {
83 if (true) {
84 const z$10 = {};
85 } else {
compiler/forget/src/__tests__/fixtures/hir/while-break.expect.md
+1 -1
@@ -45,7 +45,7 @@ function foo(
45
46 ```javascript
47 function foo$0(a$3, b$4) {
48 - bb2: while (a$3) {
48 + while (a$3) {
49 break;
50 }
51 return b$4;
compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md
+2 -2
@@ -66,8 +66,8 @@ function foo(
66
67 ```javascript
68 function foo$0(a$5, b$6, c$7, d$8) {
69 - bb2: while (a$5) {
70 - bb4: if (b$6) {
69 + while (a$5) {
70 + if (b$6) {
71 continue;
72 }
73 c$7();
compiler/forget/src/index.ts
+2
@@ -40,6 +40,7 @@ import { leaveSSA } from "./HIR/LeaveSSA";
40 import printHIR, { printFunction } from "./HIR/PrintHIR";
41 import { printReactiveFunction } from "./HIR/PrintReactiveFunction";
42 import { propagateScopeDependencies } from "./HIR/PropagateScopeDependencies";
43 +import { pruneUnusedLabels } from "./HIR/PruneUnusedLabels";
44
45 function parseFunctions(
46 source: string
@@ -81,6 +82,7 @@ export const HIR = {
82 printFunction,
83 printHIR,
84 printReactiveFunction,
85 + pruneUnusedLabels,
86 };
87
88 export default BabelPlugin;