@samitouri / QOS-React / commits / 2329326552

[hir] Run SSA pass on all tests

Sathya Gunasekaran committed Oct 27, 2022 at 16:43 UTC 23293265523c70facea017a4336ae55534e2f20d
23 files changed +597 -533
compiler/forget/src/__tests__/fixtures/hir/call.expect.md
+17 -17
@@ -34,28 +34,28 @@ function foo$0() {
34
35 ```
36 bb0:
37 - Const mutate a$2 = Array []
38 - Const mutate b$3 = Object { }
39 - Call mutate foo$4(mutate a$2, mutate b$3)
40 - Const mutate $6 = "div"
41 - Let mutate _$5 = JSX <read $6 a={freeze a$2} ></read $6>
42 - Call mutate foo$4(mutate b$3)
43 - Const mutate $7 = "div"
44 - Const mutate $8 = JSX <read $7 a={read a$2} b={freeze b$3} ></read $7>
45 - Return read $8
37 + Const mutate a$10 = Array []
38 + Const mutate b$11 = Object { }
39 + Call mutate foo$4(mutate a$10, mutate b$11)
40 + Const mutate $12 = "div"
41 + Let mutate _$13 = JSX <read $12 a={freeze a$10} ></read $12>
42 + Call mutate foo$4(mutate b$11)
43 + Const mutate $14 = "div"
44 + Const mutate $15 = JSX <read $14 a={read a$10} b={freeze b$11} ></read $14>
45 + Return read $15
46 ```
47
48 ## Code
49
50 ```javascript
51 -function Component$0(props$1) {
52 - const a$2 = [];
53 - const b$3 = {};
54 - foo$4(a$2, b$3);
55 - let _$5 = <div a={a$2}></div>;
56 -
57 - foo$4(b$3);
58 - return <div a={a$2} b={b$3}></div>;
51 +function Component$0(props$9) {
52 + const a$10 = [];
53 + const b$11 = {};
54 + foo$4(a$10, b$11);
55 + let _$13 = <div a={a$10}></div>;
56 +
57 + foo$4(b$11);
58 + return <div a={a$10} b={b$11}></div>;
59 }
60
61 ```
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+47 -35
@@ -35,63 +35,75 @@ function Component(props) {
35
36 ```
37 bb0:
38 - Const mutate items$2 = read props$1.items
39 - Const mutate maxItems$3 = read props$1.maxItems
40 - Const mutate renderedItems$4 = Array []
41 - Const mutate seen$5 = New mutate Set$6()
42 - Const mutate $9 = 0
43 - Const mutate max$7 = Call mutate Math$8.max(read $9, read maxItems$3)
38 + Const mutate items$27 = read props$26.items
39 + Const mutate maxItems$28 = read props$26.maxItems
40 + Const mutate renderedItems$29 = Array []
41 + Const mutate seen$30 = New mutate Set$6()
42 + Const mutate $31 = 0
43 + Const mutate max$32 = Call mutate Math$8.max(read $31, read maxItems$28)
44 Goto bb1
45 bb1:
46 predecessor blocks: bb0 bb4 bb7
47 - If (read items$2) then:bb3 else:bb2
47 + items$33: phi(bb0: items$27, bb4: items$50, bb7: items$50)
48 + item$35: phi(bb0: item$10, bb4: item$42, bb7: item$42)
49 + seen$38: phi(bb0: seen$30, bb4: seen$41, bb7: seen$41)
50 + renderedItems$46: phi(bb0: renderedItems$29, bb4: renderedItems$45, bb7: renderedItems$45)
51 + max$48: phi(bb0: max$32, bb4: max$47, bb7: max$47)
52 + If (read items$33) then:bb3 else:bb2
53 bb3:
54 predecessor blocks: bb1
50 - Const mutate $11 = null
51 - Const mutate $12 = Binary read item$10 == read $11
52 - If (read $12) then:bb8 else:bb9
55 + Const mutate $34 = null
56 + Const mutate $36 = Binary read item$35 == read $34
57 + If (read $36) then:bb8 else:bb9
58 bb8:
59 predecessor blocks: bb3
55 - Const mutate $13 = read $12
60 + Const mutate $37 = read $36
61 Goto bb7
62 bb9:
63 predecessor blocks: bb3
59 - Const mutate $13 = Call mutate seen$5.has(mutate item$10)
64 + Const mutate $39 = Call mutate seen$38.has(mutate item$35)
65 Goto bb7
66 bb7:
67 predecessor blocks: bb9 bb8
63 - If (read $13) then:bb1 else:bb4
68 + $40: phi(bb9: $39, bb8: $37)
69 + seen$41: phi(bb9: seen$38, bb8: seen$38)
70 + item$42: phi(bb9: item$35, bb8: item$35)
71 + renderedItems$45: phi(bb9: renderedItems$46, bb8: renderedItems$46)
72 + max$47: phi(bb9: max$48, bb8: max$48)
73 + items$50: phi(bb9: items$33, bb8: items$33)
74 + If (read $40) then:bb1 else:bb4
75 bb4:
76 predecessor blocks: bb7
66 - Call mutate seen$5.add(mutate item$10)
67 - Const mutate $14 = "div"
68 - Const mutate $15 = JSX <read $14>{read item$10}</read $14>
69 - Call mutate renderedItems$4.push(read $15)
70 - Const mutate $16 = Binary read renderedItems$4.length >= read max$7
71 - If (read $16) then:bb2 else:bb1
77 + Call mutate seen$41.add(mutate item$42)
78 + Const mutate $43 = "div"
79 + Const mutate $44 = JSX <read $43>{read item$42}</read $43>
80 + Call mutate renderedItems$45.push(read $44)
81 + Const mutate $49 = Binary read renderedItems$45.length >= read max$47
82 + If (read $49) then:bb2 else:bb1
83 bb2:
84 predecessor blocks: bb1 bb4
74 - Const mutate count$17 = read renderedItems$4.length
75 - Const mutate $18 = "div"
76 - Const mutate $19 = "\n "
77 - Const mutate $20 = "h1"
78 - Const mutate $21 = " Items"
79 - Const mutate $22 = JSX <read $20>{freeze count$17}{read $21}</read $20>
80 - Const mutate $23 = "\n "
81 - Const mutate $24 = "\n "
82 - Const mutate $25 = JSX <read $18>{read $19}{read $22}{read $23}{freeze renderedItems$4}{read $24}</read $18>
83 - Return read $25
85 + renderedItems$51: phi(bb1: renderedItems$46, bb4: renderedItems$45)
86 + Const mutate count$52 = read renderedItems$51.length
87 + Const mutate $53 = "div"
88 + Const mutate $54 = "\n "
89 + Const mutate $55 = "h1"
90 + Const mutate $56 = " Items"
91 + Const mutate $57 = JSX <read $55>{freeze count$52}{read $56}</read $55>
92 + Const mutate $58 = "\n "
93 + Const mutate $59 = "\n "
94 + Const mutate $60 = JSX <read $53>{read $54}{read $57}{read $58}{freeze renderedItems$51}{read $59}</read $53>
95 + Return read $60
96 ```
97
98 ## Code
99
100 ```javascript
89 -function Component$0(props$1) {
90 - const items$2 = props$1.items;
91 - const maxItems$3 = props$1.maxItems;
92 - const renderedItems$4 = [];
93 - const seen$5 = new Set$6();
94 - const max$7 = Math$8.max(0, maxItems$3);
101 +function Component$0(props$26) {
102 + const items$27 = props$26.items;
103 + const maxItems$28 = props$26.maxItems;
104 + const renderedItems$29 = [];
105 + const seen$30 = new Set$6();
106 + const max$32 = Math$8.max(0, maxItems$28);
107 ("<<TODO: handle complex control flow in codegen>>");
108 }
109
compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md
+73 -69
@@ -78,31 +78,31 @@ function Component(props) {
78
79 ```
80 bb0:
81 - Const mutate a_DEBUG$2 = Array []
82 - Call mutate a_DEBUG$2.push(read props$1.a)
83 - If (read props$1.b) then:bb2 else:bb1
81 + Const mutate a_DEBUG$5 = Array []
82 + Call mutate a_DEBUG$5.push(read props$4.a)
83 + If (read props$4.b) then:bb2 else:bb1
84 bb2:
85 predecessor blocks: bb0
86 - Const mutate $3 = null
87 - Return read $3
86 + Const mutate $6 = null
87 + Return read $6
88 bb1:
89 predecessor blocks: bb0
90 - Call mutate a_DEBUG$2.push(read props$1.d)
91 - Return freeze a_DEBUG$2
90 + Call mutate a_DEBUG$5.push(read props$4.d)
91 + Return freeze a_DEBUG$5
92 ```
93
94 ## Code
95
96 ```javascript
97 -function Component$0(props$1) {
98 - const a_DEBUG$2 = [];
99 - a_DEBUG$2.push(props$1.a);
100 - if (props$1.b) {
97 +function Component$0(props$4) {
98 + const a_DEBUG$5 = [];
99 + a_DEBUG$5.push(props$4.a);
100 + if (props$4.b) {
101 return null;
102 }
103
104 - a_DEBUG$2.push(props$1.d);
105 - return a_DEBUG$2;
104 + a_DEBUG$5.push(props$4.d);
105 + return a_DEBUG$5;
106 }
107
108 ```
@@ -110,32 +110,34 @@ function Component$0(props$1) {
110
111 ```
112 bb0:
113 - Const mutate a$2 = Array []
114 - Call mutate a$2.push(read props$1.a)
115 - If (read props$1.b) then:bb2 else:bb1
113 + Const mutate a$4 = Array []
114 + Call mutate a$4.push(read props$3.a)
115 + If (read props$3.b) then:bb2 else:bb1
116 bb2:
117 predecessor blocks: bb0
118 - Call mutate a$2.push(read props$1.c)
118 + Call mutate a$4.push(read props$3.c)
119 Goto bb1
120 bb1:
121 predecessor blocks: bb0 bb2
122 - Call mutate a$2.push(read props$1.d)
123 - Return freeze a$2
122 + a$5: phi(bb0: a$4, bb2: a$4)
123 + props$6: phi(bb0: props$3, bb2: props$3)
124 + Call mutate a$5.push(read props$6.d)
125 + Return freeze a$5
126 ```
127
128 ## Code
129
130 ```javascript
129 -function Component$0(props$1) {
130 - const a$2 = [];
131 - a$2.push(props$1.a);
132 - if (props$1.b) {
133 - a$2.push(props$1.c);
131 +function Component$0(props$3) {
132 + const a$4 = [];
133 + a$4.push(props$3.a);
134 + if (props$3.b) {
135 + a$4.push(props$3.c);
136 ("<<TODO: handle complex control flow in codegen>>");
137 }
138
137 - a$2.push(props$1.d);
138 - return a$2;
139 + a$5.push(props$6.d);
140 + return a$5;
141 }
142
143 ```
@@ -143,33 +145,33 @@ function Component$0(props$1) {
145
146 ```
147 bb0:
146 - Const mutate a$2 = Array []
147 - Call mutate a$2.push(read props$1.a)
148 - If (read props$1.b) then:bb2 else:bb1
148 + Const mutate a$5 = Array []
149 + Call mutate a$5.push(read props$4.a)
150 + If (read props$4.b) then:bb2 else:bb1
151 bb2:
152 predecessor blocks: bb0
151 - Call mutate a$2.push(read props$1.c)
152 - Const mutate $3 = null
153 - Return read $3
153 + Call mutate a$5.push(read props$4.c)
154 + Const mutate $6 = null
155 + Return read $6
156 bb1:
157 predecessor blocks: bb0
156 - Call mutate a$2.push(read props$1.d)
157 - Return freeze a$2
158 + Call mutate a$5.push(read props$4.d)
159 + Return freeze a$5
160 ```
161
162 ## Code
163
164 ```javascript
163 -function Component$0(props$1) {
164 - const a$2 = [];
165 - a$2.push(props$1.a);
166 - if (props$1.b) {
167 - a$2.push(props$1.c);
165 +function Component$0(props$4) {
166 + const a$5 = [];
167 + a$5.push(props$4.a);
168 + if (props$4.b) {
169 + a$5.push(props$4.c);
170 return null;
171 }
172
171 - a$2.push(props$1.d);
172 - return a$2;
173 + a$5.push(props$4.d);
174 + return a$5;
175 }
176
177 ```
@@ -177,32 +179,32 @@ function Component$0(props$1) {
179
180 ```
181 bb0:
180 - Const mutate a$2 = Array []
181 - Call mutate a$2.push(read props$1.a)
182 - If (read props$1.b) then:bb2 else:bb1
182 + Const mutate a$4 = Array []
183 + Call mutate a$4.push(read props$3.a)
184 + If (read props$3.b) then:bb2 else:bb1
185 bb2:
186 predecessor blocks: bb0
185 - Call mutate a$2.push(read props$1.c)
186 - Return freeze a$2
187 + Call mutate a$4.push(read props$3.c)
188 + Return freeze a$4
189 bb1:
190 predecessor blocks: bb0
189 - Call mutate a$2.push(read props$1.d)
190 - Return freeze a$2
191 + Call mutate a$4.push(read props$3.d)
192 + Return freeze a$4
193 ```
194
195 ## Code
196
197 ```javascript
196 -function Component$0(props$1) {
197 - const a$2 = [];
198 - a$2.push(props$1.a);
199 - if (props$1.b) {
200 - a$2.push(props$1.c);
201 - return a$2;
198 +function Component$0(props$3) {
199 + const a$4 = [];
200 + a$4.push(props$3.a);
201 + if (props$3.b) {
202 + a$4.push(props$3.c);
203 + return a$4;
204 }
205
204 - a$2.push(props$1.d);
205 - return a$2;
206 + a$4.push(props$3.d);
207 + return a$4;
208 }
209
210 ```
@@ -210,31 +212,33 @@ function Component$0(props$1) {
212
213 ```
214 bb0:
213 - Const mutate a$2 = Array []
214 - Call mutate a$2.push(read props$1.a)
215 - If (read props$1.b) then:bb1 else:bb2
215 + Const mutate a$4 = Array []
216 + Call mutate a$4.push(read props$3.a)
217 + If (read props$3.b) then:bb1 else:bb2
218 bb2:
219 predecessor blocks: bb0
218 - Call mutate a$2.push(read props$1.c)
220 + Call mutate a$4.push(read props$3.c)
221 Goto bb1
222 bb1:
223 predecessor blocks: bb2 bb0
222 - Call mutate a$2.push(read props$1.d)
223 - Return freeze a$2
224 + a$5: phi(bb2: a$4, bb0: a$4)
225 + props$6: phi(bb2: props$3, bb0: props$3)
226 + Call mutate a$5.push(read props$6.d)
227 + Return freeze a$5
228 ```
229
230 ## Code
231
232 ```javascript
229 -function Component$0(props$1) {
230 - const a$2 = [];
231 - a$2.push(props$1.a);
232 - if (props$1.b) {
233 - a$2.push(props$1.d);
234 - return a$2;
233 +function Component$0(props$3) {
234 + const a$4 = [];
235 + a$4.push(props$3.a);
236 + if (props$3.b) {
237 + a$5.push(props$6.d);
238 + return a$5;
239 }
240
237 - a$2.push(props$1.c);
241 + a$4.push(props$3.c);
242 ("<<TODO: handle complex control flow in codegen>>");
243 }
244
compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md
+47 -33
@@ -67,43 +67,50 @@ function mayMutate() {}
67
68 ```
69 bb0:
70 - Const mutate a$2 = Array []
71 - Const mutate b$3 = Array []
72 - If (read b$3) then:bb2 else:bb1
70 + Const mutate a$7 = Array []
71 + Const mutate b$8 = Array []
72 + If (read b$8) then:bb2 else:bb1
73 bb2:
74 predecessor blocks: bb0
75 - Call mutate a$2.push(read props$1.p0)
75 + Call mutate a$7.push(read props$6.p0)
76 Goto bb1
77 bb1:
78 predecessor blocks: bb0 bb2
79 - If (read props$1.p1) then:bb4 else:bb3
79 + props$9: phi(bb0: props$6, bb2: props$6)
80 + b$10: phi(bb0: b$8, bb2: b$8)
81 + Foo$12: phi(bb0: Foo$4, bb2: Foo$4)
82 + a$14: phi(bb0: a$7, bb2: a$7)
83 + If (read props$9.p1) then:bb4 else:bb3
84 bb4:
85 predecessor blocks: bb1
82 - Call mutate b$3.push(read props$1.p2)
86 + Call mutate b$10.push(read props$9.p2)
87 Goto bb3
88 bb3:
89 predecessor blocks: bb1 bb4
86 - Const mutate $5 = JSX <read Foo$4 a={freeze a$2} b={freeze b$3} ></read Foo$4>
87 - Return read $5
90 + Foo$11: phi(bb1: Foo$12, bb4: Foo$12)
91 + a$13: phi(bb1: a$14, bb4: a$14)
92 + b$15: phi(bb1: b$10, bb4: b$10)
93 + Const mutate $16 = JSX <read Foo$11 a={freeze a$13} b={freeze b$15} ></read Foo$11>
94 + Return read $16
95 ```
96
97 ## Code
98
99 ```javascript
93 -function Component$0(props$1) {
94 - const a$2 = [];
95 - const b$3 = [];
96 - if (b$3) {
97 - a$2.push(props$1.p0);
100 +function Component$0(props$6) {
101 + const a$7 = [];
102 + const b$8 = [];
103 + if (b$8) {
104 + a$7.push(props$6.p0);
105 ("<<TODO: handle complex control flow in codegen>>");
106 }
107
101 - if (props$1.p1) {
102 - b$3.push(props$1.p2);
108 + if (props$9.p1) {
109 + b$10.push(props$9.p2);
110 ("<<TODO: handle complex control flow in codegen>>");
111 }
112
106 - return <Foo$4 a={a$2} b={b$3}></Foo$4>;
113 + return <Foo$11 a={a$13} b={b$15}></Foo$11>;
114 }
115
116 ```
@@ -111,44 +118,51 @@ function Component$0(props$1) {
118
119 ```
120 bb0:
114 - Const mutate a$2 = Array []
115 - Const mutate b$3 = Array []
116 - Const mutate $5 = Call mutate mayMutate$4(mutate b$3)
117 - If (read $5) then:bb2 else:bb1
121 + Const mutate a$9 = Array []
122 + Const mutate b$10 = Array []
123 + Const mutate $11 = Call mutate mayMutate$4(mutate b$10)
124 + If (read $11) then:bb2 else:bb1
125 bb2:
126 predecessor blocks: bb0
120 - Call mutate a$2.push(read props$1.p0)
127 + Call mutate a$9.push(read props$8.p0)
128 Goto bb1
129 bb1:
130 predecessor blocks: bb0 bb2
124 - If (read props$1.p1) then:bb4 else:bb3
131 + props$12: phi(bb0: props$8, bb2: props$8)
132 + b$13: phi(bb0: b$10, bb2: b$10)
133 + Foo$15: phi(bb0: Foo$6, bb2: Foo$6)
134 + a$17: phi(bb0: a$9, bb2: a$9)
135 + If (read props$12.p1) then:bb4 else:bb3
136 bb4:
137 predecessor blocks: bb1
127 - Call mutate b$3.push(read props$1.p2)
138 + Call mutate b$13.push(read props$12.p2)
139 Goto bb3
140 bb3:
141 predecessor blocks: bb1 bb4
131 - Const mutate $7 = JSX <read Foo$6 a={freeze a$2} b={freeze b$3} ></read Foo$6>
132 - Return read $7
142 + Foo$14: phi(bb1: Foo$15, bb4: Foo$15)
143 + a$16: phi(bb1: a$17, bb4: a$17)
144 + b$18: phi(bb1: b$13, bb4: b$13)
145 + Const mutate $19 = JSX <read Foo$14 a={freeze a$16} b={freeze b$18} ></read Foo$14>
146 + Return read $19
147 ```
148
149 ## Code
150
151 ```javascript
138 -function Component$0(props$1) {
139 - const a$2 = [];
140 - const b$3 = [];
141 - if (mayMutate$4(b$3)) {
142 - a$2.push(props$1.p0);
152 +function Component$0(props$8) {
153 + const a$9 = [];
154 + const b$10 = [];
155 + if (mayMutate$4(b$10)) {
156 + a$9.push(props$8.p0);
157 ("<<TODO: handle complex control flow in codegen>>");
158 }
159
146 - if (props$1.p1) {
147 - b$3.push(props$1.p2);
160 + if (props$12.p1) {
161 + b$13.push(props$12.p2);
162 ("<<TODO: handle complex control flow in codegen>>");
163 }
164
151 - return <Foo$6 a={a$2} b={b$3}></Foo$6>;
165 + return <Foo$14 a={a$16} b={b$18}></Foo$14>;
166 }
167
168 ```
compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md
+17 -17
@@ -34,28 +34,28 @@ function Foo$0() {
34
35 ```
36 bb0:
37 - Const mutate a$2 = Array []
38 - Const mutate b$3 = Object { }
39 - New mutate Foo$4(mutate a$2, mutate b$3)
40 - Const mutate $6 = "div"
41 - Let mutate _$5 = JSX <read $6 a={freeze a$2} ></read $6>
42 - New mutate Foo$4(mutate b$3)
43 - Const mutate $7 = "div"
44 - Const mutate $8 = JSX <read $7 a={read a$2} b={freeze b$3} ></read $7>
45 - Return read $8
37 + Const mutate a$10 = Array []
38 + Const mutate b$11 = Object { }
39 + New mutate Foo$4(mutate a$10, mutate b$11)
40 + Const mutate $12 = "div"
41 + Let mutate _$13 = JSX <read $12 a={freeze a$10} ></read $12>
42 + New mutate Foo$4(mutate b$11)
43 + Const mutate $14 = "div"
44 + Const mutate $15 = JSX <read $14 a={read a$10} b={freeze b$11} ></read $14>
45 + Return read $15
46 ```
47
48 ## Code
49
50 ```javascript
51 -function Component$0(props$1) {
52 - const a$2 = [];
53 - const b$3 = {};
54 - new Foo$4(a$2, b$3);
55 - let _$5 = <div a={a$2}></div>;
56 -
57 - new Foo$4(b$3);
58 - return <div a={a$2} b={b$3}></div>;
51 +function Component$0(props$9) {
52 + const a$10 = [];
53 + const b$11 = {};
54 + new Foo$4(a$10, b$11);
55 + let _$13 = <div a={a$10}></div>;
56 +
57 + new Foo$4(b$11);
58 + return <div a={a$10} b={b$11}></div>;
59 }
60
61 ```
compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md
+9 -9
@@ -18,10 +18,10 @@ function foo(x) {}
18
19 ```
20 bb0:
21 - Const mutate a$1 = Array []
22 - Const mutate b$2 = read a$1
23 - Call read useFreeze$3(freeze a$1)
24 - Call mutate foo$4(read b$2)
21 + Const mutate a$5 = Array []
22 + Const mutate b$6 = read a$5
23 + Call read useFreeze$3(freeze a$5)
24 + Call mutate foo$4(read b$6)
25 Return
26 ```
27
@@ -29,10 +29,10 @@ bb0:
29
30 ```javascript
31 function Component$0() {
32 - const a$1 = [];
33 - const b$2 = a$1;
34 - useFreeze$3(a$1);
35 - foo$4(b$2);
32 + const a$5 = [];
33 + const b$6 = a$5;
34 + useFreeze$3(a$5);
35 + foo$4(b$6);
36 return;
37 }
38
@@ -62,7 +62,7 @@ bb0:
62 ## Code
63
64 ```javascript
65 -function foo$0(x$1) {
65 +function foo$0(x$2) {
66 return;
67 }
68
compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md
+14 -14
@@ -53,27 +53,27 @@ function foo$0() {
53
54 ```
55 bb0:
56 - Const mutate x$2 = Array []
57 - Const mutate y$3 = Call read useFreeze$4(freeze x$2)
58 - Call mutate foo$5(read y$3, read x$2)
59 - Const mutate $6 = "\n "
60 - Const mutate $7 = "\n "
61 - Const mutate $8 = "\n "
62 - Const mutate $9 = JSX <read Component$0>{read $6}{read x$2}{read $7}{read y$3}{read $8}</read Component$0>
63 - Return read $9
56 + Const mutate x$11 = Array []
57 + Const mutate y$12 = Call read useFreeze$4(freeze x$11)
58 + Call mutate foo$5(read y$12, read x$11)
59 + Const mutate $13 = "\n "
60 + Const mutate $14 = "\n "
61 + Const mutate $15 = "\n "
62 + Const mutate $16 = JSX <read Component$0>{read $13}{read x$11}{read $14}{read y$12}{read $15}</read Component$0>
63 + Return read $16
64 ```
65
66 ## Code
67
68 ```javascript
69 -function Component$0(props$1) {
70 - const x$2 = [];
71 - const y$3 = useFreeze$4(x$2);
72 - foo$5(y$3, x$2);
69 +function Component$0(props$10) {
70 + const x$11 = [];
71 + const y$12 = useFreeze$4(x$11);
72 + foo$5(y$12, x$11);
73 return (
74 <Component$0>
75 - {x$2}
76 - {y$3}
75 + {x$11}
76 + {y$12}
77 </Component$0>
78 );
79 }
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md
+12 -12
@@ -19,22 +19,22 @@ function call(x) {}
19
20 ```
21 bb0:
22 - Const mutate a$1 = Array []
23 - Call read useFreeze$2(freeze a$1)
24 - Call read useFreeze$2(read a$1)
25 - Call mutate call$3(read a$1)
26 - Return read a$1
22 + Const mutate a$4 = Array []
23 + Call read useFreeze$2(freeze a$4)
24 + Call read useFreeze$2(read a$4)
25 + Call mutate call$3(read a$4)
26 + Return read a$4
27 ```
28
29 ## Code
30
31 ```javascript
32 function Component$0() {
33 - const a$1 = [];
34 - useFreeze$2(a$1);
35 - useFreeze$2(a$1);
36 - call$3(a$1);
37 - return a$1;
33 + const a$4 = [];
34 + useFreeze$2(a$4);
35 + useFreeze$2(a$4);
36 + call$3(a$4);
37 + return a$4;
38 }
39
40 ```
@@ -48,7 +48,7 @@ bb0:
48 ## Code
49
50 ```javascript
51 -function useFreeze$0(x$1) {
51 +function useFreeze$0(x$2) {
52 return;
53 }
54
@@ -63,7 +63,7 @@ bb0:
63 ## Code
64
65 ```javascript
66 -function call$0(x$1) {
66 +function call$0(x$2) {
67 return;
68 }
69
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md
+26 -23
@@ -26,45 +26,48 @@ function call(x) {}
26
27 ```
28 bb0:
29 - Const mutate cond$2 = read props$1.cond
30 - Const mutate x$3 = read props$1.x
31 - Let mutate a$4 = undefined
32 - If (read cond$2) then:bb2 else:bb3
29 + Const mutate cond$8 = read props$7.cond
30 + Const mutate x$9 = read props$7.x
31 + Let mutate a$10 = undefined
32 + If (read cond$8) then:bb2 else:bb3
33 bb2:
34 predecessor blocks: bb0
35 - Reassign mutate a$4 = read x$3
35 + Reassign mutate a$11 = read x$9
36 Goto bb1
37 bb3:
38 predecessor blocks: bb0
39 - Reassign mutate a$4 = Array []
39 + Reassign mutate a$12 = Array []
40 Goto bb1
41 bb1:
42 predecessor blocks: bb3 bb2
43 - Call read useFreeze$5(freeze a$4)
44 - Call read useFreeze$5(read a$4)
45 - Call mutate call$6(read a$4)
46 - Return read a$4
43 + useFreeze$13: phi(bb3: useFreeze$5, bb2: useFreeze$5)
44 + a$14: phi(bb3: a$12, bb2: a$11)
45 + call$15: phi(bb3: call$6, bb2: call$6)
46 + Call read useFreeze$13(freeze a$14)
47 + Call read useFreeze$13(read a$14)
48 + Call mutate call$15(read a$14)
49 + Return read a$14
50 ```
51
52 ## Code
53
54 ```javascript
52 -function Component$0(props$1) {
53 - const cond$2 = props$1.cond;
54 - const x$3 = props$1.x;
55 - let a$4 = undefined;
56 - if (cond$2) {
57 - a$4 = x$3;
55 +function Component$0(props$7) {
56 + const cond$8 = props$7.cond;
57 + const x$9 = props$7.x;
58 + let a$10 = undefined;
59 + if (cond$8) {
60 + a$11 = x$9;
61 ("<<TODO: handle complex control flow in codegen>>");
62 } else {
60 - a$4 = [];
63 + a$12 = [];
64 ("<<TODO: handle complex control flow in codegen>>");
65 }
66
64 - useFreeze$5(a$4);
65 - useFreeze$5(a$4);
66 - call$6(a$4);
67 - return a$4;
67 + useFreeze$13(a$14);
68 + useFreeze$13(a$14);
69 + call$15(a$14);
70 + return a$14;
71 }
72
73 ```
@@ -78,7 +81,7 @@ bb0:
81 ## Code
82
83 ```javascript
81 -function useFreeze$0(x$1) {
84 +function useFreeze$0(x$2) {
85 return;
86 }
87
@@ -93,7 +96,7 @@ bb0:
96 ## Code
97
98 ```javascript
96 -function call$0(x$1) {
99 +function call$0(x$2) {
100 return;
101 }
102
compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md
+17 -14
@@ -97,33 +97,36 @@ function Foo$0() {
97
98 ```
99 bb0:
100 - Const mutate a$2 = Call mutate compute$3(read props$1.a)
101 - Const mutate b$4 = Call mutate compute$3(read props$1.b)
102 - If (read props$1.c) then:bb2 else:bb1
100 + Const mutate a$9 = Call mutate compute$3(read props$8.a)
101 + Const mutate b$10 = Call mutate compute$3(read props$8.b)
102 + If (read props$8.c) then:bb2 else:bb1
103 bb2:
104 predecessor blocks: bb0
105 - Call mutate mutate$5(mutate a$2)
106 - Call mutate mutate$5(mutate b$4)
105 + Call mutate mutate$5(mutate a$9)
106 + Call mutate mutate$5(mutate b$10)
107 Goto bb1
108 bb1:
109 predecessor blocks: bb0 bb2
110 - Const mutate $7 = JSX <read Foo$6 a={freeze a$2} b={freeze b$4} ></read Foo$6>
111 - Return read $7
110 + Foo$11: phi(bb0: Foo$6, bb2: Foo$6)
111 + a$12: phi(bb0: a$9, bb2: a$9)
112 + b$13: phi(bb0: b$10, bb2: b$10)
113 + Const mutate $14 = JSX <read Foo$11 a={freeze a$12} b={freeze b$13} ></read Foo$11>
114 + Return read $14
115 ```
116
117 ## Code
118
119 ```javascript
117 -function Component$0(props$1) {
118 - const a$2 = compute$3(props$1.a);
119 - const b$4 = compute$3(props$1.b);
120 - if (props$1.c) {
121 - mutate$5(a$2);
122 - mutate$5(b$4);
120 +function Component$0(props$8) {
121 + const a$9 = compute$3(props$8.a);
122 + const b$10 = compute$3(props$8.b);
123 + if (props$8.c) {
124 + mutate$5(a$9);
125 + mutate$5(b$10);
126 ("<<TODO: handle complex control flow in codegen>>");
127 }
128
126 - return <Foo$6 a={a$2} b={b$4}></Foo$6>;
129 + return <Foo$11 a={a$12} b={b$13}></Foo$11>;
130 }
131
132 ```
compiler/forget/src/__tests__/fixtures/hir/independent.expect.md
+8 -8
@@ -28,19 +28,19 @@ function Foo() {}
28
29 ```
30 bb0:
31 - Const mutate a$2 = Call mutate compute$3(read props$1.a)
32 - Const mutate b$4 = Call mutate compute$3(read props$1.b)
33 - Const mutate $6 = JSX <read Foo$5 a={freeze a$2} b={freeze b$4} ></read Foo$5>
34 - Return read $6
31 + Const mutate a$8 = Call mutate compute$3(read props$7.a)
32 + Const mutate b$9 = Call mutate compute$3(read props$7.b)
33 + Const mutate $10 = JSX <read Foo$5 a={freeze a$8} b={freeze b$9} ></read Foo$5>
34 + Return read $10
35 ```
36
37 ## Code
38
39 ```javascript
40 -function Component$0(props$1) {
41 - const a$2 = compute$3(props$1.a);
42 - const b$4 = compute$3(props$1.b);
43 - return <Foo$5 a={a$2} b={b$4}></Foo$5>;
40 +function Component$0(props$7) {
41 + const a$8 = compute$3(props$7.a);
42 + const b$9 = compute$3(props$7.b);
43 + return <Foo$5 a={a$8} b={b$9}></Foo$5>;
44 }
45
46 ```
compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md
+15 -12
@@ -76,31 +76,34 @@ function Foo$0() {
76
77 ```
78 bb0:
79 - Const mutate a$2 = Call mutate compute$3(read props$1.a)
80 - Const mutate b$4 = Call mutate compute$3(read props$1.b)
81 - If (read props$1.c) then:bb2 else:bb1
79 + Const mutate a$9 = Call mutate compute$3(read props$8.a)
80 + Const mutate b$10 = Call mutate compute$3(read props$8.b)
81 + If (read props$8.c) then:bb2 else:bb1
82 bb2:
83 predecessor blocks: bb0
84 - Call mutate foo$5(mutate a$2, mutate b$4)
84 + Call mutate foo$5(mutate a$9, mutate b$10)
85 Goto bb1
86 bb1:
87 predecessor blocks: bb0 bb2
88 - Const mutate $7 = JSX <read Foo$6 a={freeze a$2} b={freeze b$4} ></read Foo$6>
89 - Return read $7
88 + Foo$11: phi(bb0: Foo$6, bb2: Foo$6)
89 + a$12: phi(bb0: a$9, bb2: a$9)
90 + b$13: phi(bb0: b$10, bb2: b$10)
91 + Const mutate $14 = JSX <read Foo$11 a={freeze a$12} b={freeze b$13} ></read Foo$11>
92 + Return read $14
93 ```
94
95 ## Code
96
97 ```javascript
95 -function Component$0(props$1) {
96 - const a$2 = compute$3(props$1.a);
97 - const b$4 = compute$3(props$1.b);
98 - if (props$1.c) {
99 - foo$5(a$2, b$4);
98 +function Component$0(props$8) {
99 + const a$9 = compute$3(props$8.a);
100 + const b$10 = compute$3(props$8.b);
101 + if (props$8.c) {
102 + foo$5(a$9, b$10);
103 ("<<TODO: handle complex control flow in codegen>>");
104 }
105
103 - return <Foo$6 a={a$2} b={b$4}></Foo$6>;
106 + return <Foo$11 a={a$12} b={b$13}></Foo$11>;
107 }
108
109 ```
compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md
+10 -10
@@ -28,21 +28,21 @@ function Foo() {}
28
29 ```
30 bb0:
31 - Const mutate a$2 = Call mutate compute$3(read props$1.a)
32 - Const mutate b$4 = Call mutate compute$3(read props$1.b)
33 - Call mutate foo$5(mutate a$2, mutate b$4)
34 - Const mutate $7 = JSX <read Foo$6 a={freeze a$2} b={freeze b$4} ></read Foo$6>
35 - Return read $7
31 + Const mutate a$9 = Call mutate compute$3(read props$8.a)
32 + Const mutate b$10 = Call mutate compute$3(read props$8.b)
33 + Call mutate foo$5(mutate a$9, mutate b$10)
34 + Const mutate $11 = JSX <read Foo$6 a={freeze a$9} b={freeze b$10} ></read Foo$6>
35 + Return read $11
36 ```
37
38 ## Code
39
40 ```javascript
41 -function Component$0(props$1) {
42 - const a$2 = compute$3(props$1.a);
43 - const b$4 = compute$3(props$1.b);
44 - foo$5(a$2, b$4);
45 - return <Foo$6 a={a$2} b={b$4}></Foo$6>;
41 +function Component$0(props$8) {
42 + const a$9 = compute$3(props$8.a);
43 + const b$10 = compute$3(props$8.b);
44 + foo$5(a$9, b$10);
45 + return <Foo$6 a={a$9} b={b$10}></Foo$6>;
46 }
47
48 ```
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
+38 -27
@@ -49,7 +49,7 @@ bb0:
49 ## Code
50
51 ```javascript
52 -function mutate$0(x$1, y$2) {
52 +function mutate$0(x$3, y$4) {
53 return;
54 }
55
@@ -64,7 +64,7 @@ bb0:
64 ## Code
65
66 ```javascript
67 -function cond$0(x$1) {
67 +function cond$0(x$2) {
68 return;
69 }
70
@@ -73,52 +73,63 @@ function cond$0(x$1) {
73
74 ```
75 bb0:
76 - Let mutate a$2 = Object { }
77 - Let mutate b$3 = Object { }
78 - Let mutate c$4 = Object { }
79 - Let mutate d$5 = Object { }
76 + Let mutate a$13 = Object { }
77 + Let mutate b$14 = Object { }
78 + Let mutate c$15 = Object { }
79 + Let mutate d$16 = Object { }
80 Goto bb1
81 bb1:
82 predecessor blocks: bb0 bb3
83 - Const mutate $10 = true
84 - If (read $10) then:bb3 else:bb2
83 + a$18: phi(bb0: a$13, bb3: a$21)
84 + b$20: phi(bb0: b$14, bb3: b$23)
85 + c$22: phi(bb0: c$15, bb3: c$25)
86 + d$24: phi(bb0: d$16, bb3: d$26)
87 + mutate$27: phi(bb0: mutate$7, bb3: mutate$27)
88 + cond$28: phi(bb0: cond$8, bb3: cond$28)
89 + Const mutate $17 = true
90 + If (read $17) then:bb3 else:bb2
91 bb3:
92 predecessor blocks: bb1
87 - Let mutate z$6 = read a$2
88 - Reassign mutate a$2 = read b$3
89 - Reassign mutate b$3 = read c$4
90 - Reassign mutate c$4 = read d$5
91 - Reassign mutate d$5 = read z$6
92 - Call mutate mutate$7(mutate a$2, mutate b$3)
93 - Const mutate $9 = Call mutate cond$8(mutate a$2)
94 - If (read $9) then:bb2 else:bb1
93 + Let mutate z$19 = read a$18
94 + Reassign mutate a$21 = read b$20
95 + Reassign mutate b$23 = read c$22
96 + Reassign mutate c$25 = read d$24
97 + Reassign mutate d$26 = read z$19
98 + Call mutate mutate$27(mutate a$21, mutate b$23)
99 + Const mutate $29 = Call mutate cond$28(mutate a$21)
100 + If (read $29) then:bb2 else:bb1
101 bb2:
102 predecessor blocks: bb1 bb3
97 - If (read a$2) then:bb7 else:bb7
103 + a$30: phi(bb1: a$18, bb3: a$21)
104 + b$31: phi(bb1: b$20, bb3: b$23)
105 + c$32: phi(bb1: c$22, bb3: c$25)
106 + d$33: phi(bb1: d$24, bb3: d$26)
107 + mutate$35: phi(bb1: mutate$27, bb3: mutate$27)
108 + If (read a$30) then:bb7 else:bb7
109 bb7:
110 predecessor blocks: bb2
100 - If (read b$3) then:bb9 else:bb9
111 + If (read b$31) then:bb9 else:bb9
112 bb9:
113 predecessor blocks: bb7
103 - If (read c$4) then:bb11 else:bb11
114 + If (read c$32) then:bb11 else:bb11
115 bb11:
116 predecessor blocks: bb9
106 - If (read d$5) then:bb13 else:bb13
117 + If (read d$33) then:bb13 else:bb13
118 bb13:
119 predecessor blocks: bb11
109 - Const mutate $11 = null
110 - Call mutate mutate$7(mutate d$5, read $11)
120 + Const mutate $34 = null
121 + Call mutate mutate$35(mutate d$33, read $34)
122 Return
123 ```
124
125 ## Code
126
127 ```javascript
117 -function Component$0(props$1) {
118 - let a$2 = {};
119 - let b$3 = {};
120 - let c$4 = {};
121 - let d$5 = {};
128 +function Component$0(props$12) {
129 + let a$13 = {};
130 + let b$14 = {};
131 + let c$15 = {};
132 + let d$16 = {};
133 ("<<TODO: handle complex control flow in codegen>>");
134 }
135
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+87 -87
@@ -45,7 +45,7 @@ bb0:
45 ## Code
46
47 ```javascript
48 -function mutate$0(x$1, y$2) {
48 +function mutate$0(x$3, y$4) {
49 return;
50 }
51
@@ -54,202 +54,202 @@ function mutate$0(x$1, y$2) {
54
55 ```
56 bb0:
57 - Const mutate a$2 = Object { }
58 - Const mutate b$3 = Array [read a$2]
59 - Const mutate c$4 = Object { }
60 - Const mutate d$5 = Object { c: read c$4 }
61 - Const mutate x$6 = Object { }
62 - Reassign mutate x$6.b = read b$3
63 - Const mutate y$7 = Call mutate mutate$8(mutate x$6, mutate d$5)
64 - If (read a$2) then:bb1 else:bb1
57 + Const mutate a$11 = Object { }
58 + Const mutate b$12 = Array [read a$11]
59 + Const mutate c$13 = Object { }
60 + Const mutate d$14 = Object { c: read c$13 }
61 + Const mutate x$15 = Object { }
62 + Reassign mutate x$15.b = read b$12
63 + Const mutate y$16 = Call mutate mutate$8(mutate x$15, mutate d$14)
64 + If (read a$11) then:bb1 else:bb1
65 bb1:
66 predecessor blocks: bb0
67 - If (read b$3) then:bb3 else:bb3
67 + If (read b$12) then:bb3 else:bb3
68 bb3:
69 predecessor blocks: bb1
70 - If (read c$4) then:bb5 else:bb5
70 + If (read c$13) then:bb5 else:bb5
71 bb5:
72 predecessor blocks: bb3
73 - If (read d$5) then:bb7 else:bb7
73 + If (read d$14) then:bb7 else:bb7
74 bb7:
75 predecessor blocks: bb5
76 - If (read y$7) then:bb9 else:bb9
76 + If (read y$16) then:bb9 else:bb9
77 bb9:
78 predecessor blocks: bb7
79 - Const mutate $9 = null
80 - Call mutate mutate$8(mutate x$6, read $9)
79 + Const mutate $17 = null
80 + Call mutate mutate$8(mutate x$15, read $17)
81 Return
82 ```
83
84 ## Code
85
86 ```javascript
87 -function Component$0(props$1) {
88 - const a$2 = {};
89 - const b$3 = [a$2];
90 - const c$4 = {};
91 - const d$5 = {
92 - c: c$4,
87 +function Component$0(props$10) {
88 + const a$11 = {};
89 + const b$12 = [a$11];
90 + const c$13 = {};
91 + const d$14 = {
92 + c: c$13,
93 };
94 - const x$6 = {};
95 - x$6 = b$3;
96 - const y$7 = mutate$8(x$6, d$5);
97 - if (a$2) {
98 - if (b$3) {
99 - if (c$4) {
100 - if (d$5) {
101 - if (y$7) {
102 - mutate$8(x$6, null);
94 + const x$15 = {};
95 + x$15 = b$12;
96 + const y$16 = mutate$8(x$15, d$14);
97 + if (a$11) {
98 + if (b$12) {
99 + if (c$13) {
100 + if (d$14) {
101 + if (y$16) {
102 + mutate$8(x$15, null);
103 return;
104 }
105
106 - mutate$8(x$6, null);
106 + mutate$8(x$15, null);
107 return;
108 }
109
110 - if (y$7) {
111 - mutate$8(x$6, null);
110 + if (y$16) {
111 + mutate$8(x$15, null);
112 return;
113 }
114
115 - mutate$8(x$6, null);
115 + mutate$8(x$15, null);
116 return;
117 }
118
119 - if (d$5) {
120 - if (y$7) {
121 - mutate$8(x$6, null);
119 + if (d$14) {
120 + if (y$16) {
121 + mutate$8(x$15, null);
122 return;
123 }
124
125 - mutate$8(x$6, null);
125 + mutate$8(x$15, null);
126 return;
127 }
128
129 - if (y$7) {
130 - mutate$8(x$6, null);
129 + if (y$16) {
130 + mutate$8(x$15, null);
131 return;
132 }
133
134 - mutate$8(x$6, null);
134 + mutate$8(x$15, null);
135 return;
136 }
137
138 - if (c$4) {
139 - if (d$5) {
140 - if (y$7) {
141 - mutate$8(x$6, null);
138 + if (c$13) {
139 + if (d$14) {
140 + if (y$16) {
141 + mutate$8(x$15, null);
142 return;
143 }
144
145 - mutate$8(x$6, null);
145 + mutate$8(x$15, null);
146 return;
147 }
148
149 - if (y$7) {
150 - mutate$8(x$6, null);
149 + if (y$16) {
150 + mutate$8(x$15, null);
151 return;
152 }
153
154 - mutate$8(x$6, null);
154 + mutate$8(x$15, null);
155 return;
156 }
157
158 - if (d$5) {
159 - if (y$7) {
160 - mutate$8(x$6, null);
158 + if (d$14) {
159 + if (y$16) {
160 + mutate$8(x$15, null);
161 return;
162 }
163
164 - mutate$8(x$6, null);
164 + mutate$8(x$15, null);
165 return;
166 }
167
168 - if (y$7) {
169 - mutate$8(x$6, null);
168 + if (y$16) {
169 + mutate$8(x$15, null);
170 return;
171 }
172
173 - mutate$8(x$6, null);
173 + mutate$8(x$15, null);
174 return;
175 }
176
177 - if (b$3) {
178 - if (c$4) {
179 - if (d$5) {
180 - if (y$7) {
181 - mutate$8(x$6, null);
177 + if (b$12) {
178 + if (c$13) {
179 + if (d$14) {
180 + if (y$16) {
181 + mutate$8(x$15, null);
182 return;
183 }
184
185 - mutate$8(x$6, null);
185 + mutate$8(x$15, null);
186 return;
187 }
188
189 - if (y$7) {
190 - mutate$8(x$6, null);
189 + if (y$16) {
190 + mutate$8(x$15, null);
191 return;
192 }
193
194 - mutate$8(x$6, null);
194 + mutate$8(x$15, null);
195 return;
196 }
197
198 - if (d$5) {
199 - if (y$7) {
200 - mutate$8(x$6, null);
198 + if (d$14) {
199 + if (y$16) {
200 + mutate$8(x$15, null);
201 return;
202 }
203
204 - mutate$8(x$6, null);
204 + mutate$8(x$15, null);
205 return;
206 }
207
208 - if (y$7) {
209 - mutate$8(x$6, null);
208 + if (y$16) {
209 + mutate$8(x$15, null);
210 return;
211 }
212
213 - mutate$8(x$6, null);
213 + mutate$8(x$15, null);
214 return;
215 }
216
217 - if (c$4) {
218 - if (d$5) {
219 - if (y$7) {
220 - mutate$8(x$6, null);
217 + if (c$13) {
218 + if (d$14) {
219 + if (y$16) {
220 + mutate$8(x$15, null);
221 return;
222 }
223
224 - mutate$8(x$6, null);
224 + mutate$8(x$15, null);
225 return;
226 }
227
228 - if (y$7) {
229 - mutate$8(x$6, null);
228 + if (y$16) {
229 + mutate$8(x$15, null);
230 return;
231 }
232
233 - mutate$8(x$6, null);
233 + mutate$8(x$15, null);
234 return;
235 }
236
237 - if (d$5) {
238 - if (y$7) {
239 - mutate$8(x$6, null);
237 + if (d$14) {
238 + if (y$16) {
239 + mutate$8(x$15, null);
240 return;
241 }
242
243 - mutate$8(x$6, null);
243 + mutate$8(x$15, null);
244 return;
245 }
246
247 - if (y$7) {
248 - mutate$8(x$6, null);
247 + if (y$16) {
248 + mutate$8(x$15, null);
249 return;
250 }
251
252 - mutate$8(x$6, null);
252 + mutate$8(x$15, null);
253 return;
254 }
255
compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md
+14 -14
@@ -17,25 +17,25 @@ function Component(props) {
17
18 ```
19 bb0:
20 - Const mutate x$2 = Object { }
21 - Const mutate y$3 = Array []
22 - Reassign mutate x$2.y = read y$3
23 - Const mutate child$4 = JSX <read Component$0 data={freeze y$3} ></read Component$0>
24 - Call mutate x$2.y.push(read props$1.p0)
25 - Const mutate $5 = JSX <read Component$0 data={freeze x$2} >{read child$4}</read Component$0>
26 - Return read $5
20 + Const mutate x$7 = Object { }
21 + Const mutate y$8 = Array []
22 + Reassign mutate x$7.y = read y$8
23 + Const mutate child$9 = JSX <read Component$0 data={freeze y$8} ></read Component$0>
24 + Call mutate x$7.y.push(read props$6.p0)
25 + Const mutate $10 = JSX <read Component$0 data={freeze x$7} >{read child$9}</read Component$0>
26 + Return read $10
27 ```
28
29 ## Code
30
31 ```javascript
32 -function Component$0(props$1) {
33 - const x$2 = {};
34 - const y$3 = [];
35 - x$2 = y$3;
36 - const child$4 = <Component$0 data={y$3}></Component$0>;
37 - x$2.y.push(props$1.p0);
38 - return <Component$0 data={x$2}>{child$4}</Component$0>;
32 +function Component$0(props$6) {
33 + const x$7 = {};
34 + const y$8 = [];
35 + x$7 = y$8;
36 + const child$9 = <Component$0 data={y$8}></Component$0>;
37 + x$7.y.push(props$6.p0);
38 + return <Component$0 data={x$7}>{child$9}</Component$0>;
39 }
40
41 ```
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
+22 -18
@@ -23,38 +23,42 @@ function Component(props) {
23
24 ```
25 bb0:
26 - Let mutate x$2 = Array []
27 - Call mutate x$2.push(read props$1.p0)
28 - Let mutate y$3 = read x$2
29 - If (read props$1.p1) then:bb2 else:bb1
26 + Let mutate x$7 = Array []
27 + Call mutate x$7.push(read props$6.p0)
28 + Let mutate y$8 = read x$7
29 + If (read props$6.p1) then:bb2 else:bb1
30 bb2:
31 predecessor blocks: bb0
32 - Reassign mutate x$2 = Array []
32 + Reassign mutate x$9 = Array []
33 Goto bb1
34 bb1:
35 predecessor blocks: bb0 bb2
36 - Let mutate _$4 = JSX <read Component$0 x={freeze x$2} ></read Component$0>
37 - Call read y$3.push(read props$1.p2)
38 - Const mutate $5 = JSX <read Component$0 x={read x$2} y={read y$3} ></read Component$0>
39 - Return read $5
36 + Component$10: phi(bb0: Component$0, bb2: Component$0)
37 + x$11: phi(bb0: x$7, bb2: x$9)
38 + y$13: phi(bb0: y$8, bb2: y$8)
39 + props$14: phi(bb0: props$6, bb2: props$6)
40 + Let mutate _$12 = JSX <read Component$10 x={freeze x$11} ></read Component$10>
41 + Call read y$13.push(read props$14.p2)
42 + Const mutate $15 = JSX <read Component$10 x={read x$11} y={read y$13} ></read Component$10>
43 + Return read $15
44 ```
45
46 ## Code
47
48 ```javascript
45 -function Component$0(props$1) {
46 - let x$2 = [];
47 - x$2.push(props$1.p0);
48 - let y$3 = x$2;
49 - if (props$1.p1) {
50 - x$2 = [];
49 +function Component$0(props$6) {
50 + let x$7 = [];
51 + x$7.push(props$6.p0);
52 + let y$8 = x$7;
53 + if (props$6.p1) {
54 + x$9 = [];
55 ("<<TODO: handle complex control flow in codegen>>");
56 }
57
54 - let _$4 = <Component$0 x={x$2}></Component$0>;
58 + let _$12 = <Component$10 x={x$11}></Component$10>;
59
56 - y$3.push(props$1.p2);
57 - return <Component$0 x={x$2} y={y$3}></Component$0>;
60 + y$13.push(props$14.p2);
61 + return <Component$10 x={x$11} y={y$13}></Component$10>;
62 }
63
64 ```
compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md
+17 -17
@@ -21,28 +21,28 @@ function Component(props) {
21
22 ```
23 bb0:
24 - Let mutate x$2 = Array []
25 - Call mutate x$2.push(read props$1.p0)
26 - Let mutate y$3 = read x$2
27 - Reassign mutate x$2 = Array []
28 - Let mutate _$4 = JSX <read Component$0 x={freeze x$2} ></read Component$0>
29 - Call mutate y$3.push(read props$1.p1)
30 - Const mutate $5 = JSX <read Component$0 x={read x$2} y={freeze y$3} ></read Component$0>
31 - Return read $5
24 + Let mutate x$7 = Array []
25 + Call mutate x$7.push(read props$6.p0)
26 + Let mutate y$8 = read x$7
27 + Reassign mutate x$9 = Array []
28 + Let mutate _$10 = JSX <read Component$0 x={freeze x$9} ></read Component$0>
29 + Call mutate y$8.push(read props$6.p1)
30 + Const mutate $11 = JSX <read Component$0 x={read x$9} y={freeze y$8} ></read Component$0>
31 + Return read $11
32 ```
33
34 ## Code
35
36 ```javascript
37 -function Component$0(props$1) {
38 - let x$2 = [];
39 - x$2.push(props$1.p0);
40 - let y$3 = x$2;
41 - x$2 = [];
42 - let _$4 = <Component$0 x={x$2}></Component$0>;
43 -
44 - y$3.push(props$1.p1);
45 - return <Component$0 x={x$2} y={y$3}></Component$0>;
37 +function Component$0(props$6) {
38 + let x$7 = [];
39 + x$7.push(props$6.p0);
40 + let y$8 = x$7;
41 + x$9 = [];
42 + let _$10 = <Component$0 x={x$9}></Component$0>;
43 +
44 + y$8.push(props$6.p1);
45 + return <Component$0 x={x$9} y={y$8}></Component$0>;
46 }
47
48 ```
compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md
+31 -30
@@ -36,91 +36,92 @@ function Component(props) {
36
37 ```
38 bb0:
39 - Let mutate x$2 = undefined
40 - If (read props$1.cond) then:bb2 else:bb10
39 + Let mutate x$7 = undefined
40 + If (read props$6.cond) then:bb2 else:bb10
41 bb2:
42 predecessor blocks: bb0
43 - Const mutate $3 = 2
44 - Const mutate $4 = 1
45 - Const mutate $5 = 0
46 - Switch (<unknown> props$1.test)
47 - Case read $5: bb8
48 - Case read $4: bb6
49 - Case read $3: bb4
43 + Const mutate $8 = 2
44 + Const mutate $9 = 1
45 + Const mutate $10 = 0
46 + Switch (<unknown> props$6.test)
47 + Case read $10: bb8
48 + Case read $9: bb6
49 + Case read $8: bb4
50 Default: bb4
51 bb8:
52 predecessor blocks: bb2
53 - Reassign mutate x$2 = read props$1.v0
53 + Reassign mutate x$11 = read props$6.v0
54 Goto bb1
55 bb6:
56 predecessor blocks: bb2
57 - Reassign mutate x$2 = read props$1.v1
57 + Reassign mutate x$12 = read props$6.v1
58 Goto bb1
59 bb4:
60 predecessor blocks: bb2
61 - Reassign mutate x$2 = read props$1.v2
61 + Reassign mutate x$13 = read props$6.v2
62 Goto bb1
63 bb10:
64 predecessor blocks: bb0
65 - If (read props$1.cond2) then:bb12 else:bb13
65 + If (read props$6.cond2) then:bb12 else:bb13
66 bb12:
67 predecessor blocks: bb10
68 - Reassign mutate x$2 = read props$1.b
68 + Reassign mutate x$14 = read props$6.b
69 Goto bb1
70 bb13:
71 predecessor blocks: bb10
72 - Reassign mutate x$2 = read props$1.c
72 + Reassign mutate x$15 = read props$6.c
73 Goto bb1
74 bb1:
75 predecessor blocks: bb13 bb12 bb8 bb6 bb4
76 - read x$2
76 + x$16: phi(bb13: x$15, bb12: x$14, bb8: x$11, bb6: x$12, bb4: x$13)
77 + read x$16
78 Return
79 ```
80
81 ## Code
82
83 ```javascript
83 -function Component$0(props$1) {
84 - let x$2 = undefined;
85 - if (props$1.cond) {
86 - switch (props$1.test) {
84 +function Component$0(props$6) {
85 + let x$7 = undefined;
86 + if (props$6.cond) {
87 + switch (props$6.test) {
88 case 0: {
88 - x$2 = props$1.v0;
89 + x$11 = props$6.v0;
90 ("<<TODO: handle complex control flow in codegen>>");
91 }
92
93 case 1: {
93 - x$2 = props$1.v1;
94 + x$12 = props$6.v1;
95 ("<<TODO: handle complex control flow in codegen>>");
96 }
97
98 case 2: {
98 - x$2 = props$1.v2;
99 + x$13 = props$6.v2;
100 ("<<TODO: handle complex control flow in codegen>>");
101 }
102
103 default: {
103 - x$2 = props$1.v2;
104 + x$13 = props$6.v2;
105 ("<<TODO: handle complex control flow in codegen>>");
106 }
107 }
108
108 - x$2;
109 + x$16;
110 return;
111 } else {
111 - if (props$1.cond2) {
112 - x$2 = props$1.b;
112 + if (props$6.cond2) {
113 + x$14 = props$6.b;
114 ("<<TODO: handle complex control flow in codegen>>");
115 } else {
115 - x$2 = props$1.c;
116 + x$15 = props$6.c;
117 ("<<TODO: handle complex control flow in codegen>>");
118 }
119
119 - x$2;
120 + x$16;
121 return;
122 }
123
123 - x$2;
124 + x$16;
125 return;
126 }
127
compiler/forget/src/__tests__/fixtures/hir/simple.expect.md
+12 -12
@@ -15,28 +15,28 @@ function foo(x, y) {
15
16 ```
17 bb0:
18 - If (read x$1) then:bb2 else:bb1
18 + If (read x$8) then:bb2 else:bb1
19 bb2:
20 predecessor blocks: bb0
21 - Const mutate $3 = false
22 - Const mutate $4 = Call read foo$0(read $3, read y$2)
23 - Return freeze $4
21 + Const mutate $10 = false
22 + Const mutate $11 = Call read foo$0(read $10, read y$9)
23 + Return freeze $11
24 bb1:
25 predecessor blocks: bb0
26 - Const mutate $5 = 10
27 - Const mutate $6 = Binary read y$2 * read $5
28 - Const mutate $7 = Array [read $6]
29 - Return freeze $7
26 + Const mutate $12 = 10
27 + Const mutate $13 = Binary read y$9 * read $12
28 + Const mutate $14 = Array [read $13]
29 + Return freeze $14
30 ```
31
32 ## Code
33
34 ```javascript
35 -function foo$0(x$1, y$2) {
36 - if (x$1) {
37 - return foo$0(false, y$2);
35 +function foo$0(x$8, y$9) {
36 + if (x$8) {
37 + return foo$0(false, y$9);
38 }
39 - return [y$2 * 10];
39 + return [y$9 * 10];
40 }
41
42 ```
compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md
+30 -26
@@ -32,46 +32,50 @@ function Component(props) {
32
33 ```
34 bb0:
35 - Let mutate x$2 = Array []
36 - Let mutate y$3 = undefined
37 - Const mutate $4 = false
38 - Const mutate $5 = true
39 - Const mutate $6 = 1
40 - Switch (<unknown> props$1.p0)
41 - Case read $6: bb1
42 - Case read $5: bb6
35 + Let mutate x$10 = Array []
36 + Let mutate y$11 = undefined
37 + Const mutate $12 = false
38 + Const mutate $13 = true
39 + Const mutate $14 = 1
40 + Switch (<unknown> props$9.p0)
41 + Case read $14: bb1
42 + Case read $13: bb6
43 Default: bb1
44 - Case read $4: bb2
44 + Case read $12: bb2
45 bb6:
46 predecessor blocks: bb0
47 - Call mutate x$2.push(read props$1.p2)
48 - Reassign mutate y$3 = Array []
47 + Call mutate x$10.push(read props$9.p2)
48 + Reassign mutate y$15 = Array []
49 Goto bb1
50 bb2:
51 predecessor blocks: bb0
52 - Reassign mutate y$3 = read x$2
52 + Reassign mutate y$16 = read x$10
53 Goto bb1
54 bb1:
55 predecessor blocks: bb0 bb6 bb2
56 - Const mutate child$7 = JSX <read Component$0 data={freeze x$2} ></read Component$0>
57 - Call read y$3.push(read props$1.p4)
58 - Const mutate $8 = JSX <read Component$0 data={freeze y$3} >{read child$7}</read Component$0>
59 - Return read $8
56 + Component$17: phi(bb0: Component$0, bb6: Component$0, bb2: Component$0)
57 + x$18: phi(bb0: x$10, bb6: x$10, bb2: x$10)
58 + y$20: phi(bb0: y$11, bb6: y$15, bb2: y$16)
59 + props$21: phi(bb0: props$9, bb6: props$9, bb2: props$9)
60 + Const mutate child$19 = JSX <read Component$17 data={freeze x$18} ></read Component$17>
61 + Call read y$20.push(read props$21.p4)
62 + Const mutate $22 = JSX <read Component$17 data={freeze y$20} >{read child$19}</read Component$17>
63 + Return read $22
64 ```
65
66 ## Code
67
68 ```javascript
65 -function Component$0(props$1) {
66 - let x$2 = [];
67 - let y$3 = undefined;
68 - switch (props$1.p0) {
69 +function Component$0(props$9) {
70 + let x$10 = [];
71 + let y$11 = undefined;
72 + switch (props$9.p0) {
73 case 1:
74 break;
75
76 case true: {
73 - x$2.push(props$1.p2);
74 - y$3 = [];
77 + x$10.push(props$9.p2);
78 + y$15 = [];
79 ("<<TODO: handle complex control flow in codegen>>");
80 }
81
@@ -79,14 +83,14 @@ function Component$0(props$1) {
83 break;
84
85 case false: {
82 - y$3 = x$2;
86 + y$16 = x$10;
87 ("<<TODO: handle complex control flow in codegen>>");
88 }
89 }
90
87 - const child$7 = <Component$0 data={x$2}></Component$0>;
88 - y$3.push(props$1.p4);
89 - return <Component$0 data={y$3}>{child$7}</Component$0>;
91 + const child$19 = <Component$17 data={x$18}></Component$17>;
92 + y$20.push(props$21.p4);
93 + return <Component$17 data={y$20}>{child$19}</Component$17>;
94 }
95
96 ```
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+33 -26
@@ -28,55 +28,62 @@ function Component(props) {
28
29 ```
30 bb0:
31 - Let mutate x$2 = Array []
32 - Let mutate y$3 = undefined
33 - Const mutate $4 = false
34 - Const mutate $5 = true
35 - Switch (<unknown> props$1.p0)
36 - Case read $5: bb4
37 - Case read $4: bb2
31 + Let mutate x$9 = Array []
32 + Let mutate y$10 = undefined
33 + Const mutate $11 = false
34 + Const mutate $12 = true
35 + Switch (<unknown> props$8.p0)
36 + Case read $12: bb4
37 + Case read $11: bb2
38 Default: bb1
39 bb4:
40 predecessor blocks: bb0
41 - Call mutate x$2.push(read props$1.p2)
42 - Call mutate x$2.push(read props$1.p3)
43 - Reassign mutate y$3 = Array []
41 + Call mutate x$9.push(read props$8.p2)
42 + Call mutate x$9.push(read props$8.p3)
43 + Reassign mutate y$13 = Array []
44 Goto bb2
45 bb2:
46 predecessor blocks: bb4 bb0
47 - Reassign mutate y$3 = read x$2
47 + x$14: phi(bb4: x$9, bb0: x$9)
48 + Component$17: phi(bb4: Component$0, bb0: Component$0)
49 + props$22: phi(bb4: props$8, bb0: props$8)
50 + Reassign mutate y$15 = read x$14
51 Goto bb1
52 bb1:
53 predecessor blocks: bb2 bb0
51 - Const mutate child$6 = JSX <read Component$0 data={freeze x$2} ></read Component$0>
52 - Call read y$3.push(read props$1.p4)
53 - Const mutate $7 = JSX <read Component$0 data={read y$3} >{read child$6}</read Component$0>
54 - Return read $7
54 + Component$16: phi(bb2: Component$17, bb0: Component$0)
55 + x$18: phi(bb2: x$14, bb0: x$9)
56 + y$20: phi(bb2: y$15, bb0: y$10)
57 + props$21: phi(bb2: props$22, bb0: props$8)
58 + Const mutate child$19 = JSX <read Component$16 data={freeze x$18} ></read Component$16>
59 + Call read y$20.push(read props$21.p4)
60 + Const mutate $23 = JSX <read Component$16 data={read y$20} >{read child$19}</read Component$16>
61 + Return read $23
62 ```
63
64 ## Code
65
66 ```javascript
60 -function Component$0(props$1) {
61 - let x$2 = [];
62 - let y$3 = undefined;
63 - switch (props$1.p0) {
67 +function Component$0(props$8) {
68 + let x$9 = [];
69 + let y$10 = undefined;
70 + switch (props$8.p0) {
71 case true: {
65 - x$2.push(props$1.p2);
66 - x$2.push(props$1.p3);
67 - y$3 = [];
72 + x$9.push(props$8.p2);
73 + x$9.push(props$8.p3);
74 + y$13 = [];
75 ("<<TODO: handle complex control flow in codegen>>");
76 }
77
78 case false: {
72 - y$3 = x$2;
79 + y$15 = x$14;
80 ("<<TODO: handle complex control flow in codegen>>");
81 }
82 }
83
77 - const child$6 = <Component$0 data={x$2}></Component$0>;
78 - y$3.push(props$1.p4);
79 - return <Component$0 data={y$3}>{child$6}</Component$0>;
84 + const child$19 = <Component$16 data={x$18}></Component$16>;
85 + y$20.push(props$21.p4);
86 + return <Component$16 data={y$20}>{child$19}</Component$16>;
87 }
88
89 ```
compiler/forget/src/__tests__/hir-test.ts
+1 -3
@@ -47,9 +47,7 @@ describe("React Forget (HIR version)", () => {
47 enter(nodePath) {
48 const env: Environment = new Environment();
49 const ir: HIRFunction = lower(nodePath, env);
50 - if (file.startsWith("ssa")) {
51 - buildSSA(ir, env);
52 - }
50 + buildSSA(ir, env);
51 inferReferenceEffects(ir);
52 // const lifetimeGraph = buildDefUseGraph(ir);
53 const textHIR = printHIR(ir.body);