Phi operands belong in the same reactive scope
This completes the implementation of InferReactiveScopeVariables, adding support for phi nodes. Example: ```javascript let x$0 = null; mutate(x$0); if (cond) { x$1 = a; mutate(x$1) } else { x$2 = b; } x$3 = phi(x$1, x$2); mutate(x$3); ``` We now add x$1, x$2, and x$3 to the same reactive scope. This reflects the fact that x$3 cannot be computed without also computing both x$1 and x$2. Note that x$3 can never be x$0, so x$0 is _not_ added to the same scope. This allows us to take advantage of SSA form to note that _some_ instances of an identifier really are distinct.
Joe Savona committed
Nov 17, 2022 at 09:35 UTC
2d8dc3ec4f84bd961924965aad26776e674e4f44
19 files changed
+200
-207
compiler/forget/src/HIR/InferReactiveScopeVariables.ts
+6
-13
@@ -52,7 +52,7 @@ import { eachInstructionOperand } from "./visitors";
52
*
53
* ## Other Issues Uncovered
54
*
55
- * 1. Mutable lifetimes need to account for aliasing.
55
+ * Mutable lifetimes need to account for aliasing (known todo, already described in InferMutableLifetimes.ts)
56
*
57
* ```javascript
58
* let x = {};
@@ -60,24 +60,17 @@ import { eachInstructionOperand } from "./visitors";
60
* x.y = y; // RHS is not considered mutable here bc not further mutation
61
* mutate(x); // bc y is aliased here, it should still be considered mutable above
62
* ```
63
- *
64
- * 2. Mutable lifetimes need to account for SSA reassignment.
65
- *
66
- * ```javascript
67
- * // y is never considered mutable bc SSA treats subsequent assignments as distinct identifiers
68
- * let y;
69
- * if (cond) {
70
- * y = ...;
71
- * } else {
72
- * y = ...;
73
- * }
74
- * ```
63
*/
64
export function inferReactiveScopeVariables(fn: HIRFunction) {
65
// Represents the set of reactive scopes as disjoint sets of identifiers
66
// that mutate together.
67
const scopes = new DisjointSet<Identifier>();
68
for (const [_, block] of fn.body.blocks) {
69
+ for (const phi of block.phis) {
70
+ const operands: Array<Identifier> = [phi.id, ...phi.operands.values()];
71
+ scopes.union(operands);
72
+ }
73
+
74
for (const instr of block.instructions) {
75
const operands: Array<Identifier> = [];
76
if (instr.lvalue !== null) {
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+34
-34
@@ -52,7 +52,7 @@ bb3:
52
If (read $12_@3) then:bb8 else:bb9
53
bb8:
54
predecessor blocks: bb3
55
- [9] Const mutate $13_@7 = read $12_@3
55
+ [9] Const mutate $13_@3 = read $12_@3
56
Goto bb7
57
bb9:
58
predecessor blocks: bb3
@@ -60,33 +60,33 @@ bb9:
60
Goto bb7
61
bb7:
62
predecessor blocks: bb8 bb9
63
- If (read $13) then:bb5 else:bb4
63
+ If (read $13_@3) then:bb5 else:bb4
64
bb5:
65
predecessor blocks: bb7
66
Goto(Continue) bb1
67
bb4:
68
predecessor blocks: bb7
69
[11] Call mutate seen$5_@3.add(mutate item$10_@3)
70
- [12] Const mutate $14_@8 = "div"
71
- [13] Const mutate $15_@9 = JSX <read $14_@8>{read item$10_@3}</read $14_@8>
72
- [14] Call mutate renderedItems$4_@2.push(read $15_@9)
73
- [15] Const mutate $16_@10 = Binary read renderedItems$4_@2.length >= read max$7_@5
74
- If (read $16_@10) then:bb2 else:bb10
70
+ [12] Const mutate $14_@7 = "div"
71
+ [13] Const mutate $15_@8 = JSX <read $14_@7>{read item$10_@3}</read $14_@7>
72
+ [14] Call mutate renderedItems$4_@2.push(read $15_@8)
73
+ [15] Const mutate $16_@9 = Binary read renderedItems$4_@2.length >= read max$7_@5
74
+ If (read $16_@9) then:bb2 else:bb10
75
bb10:
76
predecessor blocks: bb4
77
Goto(Continue) bb1
78
bb2:
79
predecessor blocks: bb4 bb1
80
- [16] Const mutate count$17_@11 = read renderedItems$4_@2.length
81
- [17] Const mutate $18_@12 = "div"
82
- [18] Const mutate $19_@13 = "\n "
83
- [19] Const mutate $20_@14 = "h1"
84
- [20] Const mutate $21_@15 = " Items"
85
- [21] Const mutate $22_@16 = JSX <read $20_@14>{freeze count$17_@11}{read $21_@15}</read $20_@14>
86
- [22] Const mutate $23_@17 = "\n "
87
- [23] Const mutate $24_@18 = "\n "
88
- [24] Const mutate $25_@19 = JSX <read $18_@12>{read $19_@13}{read $22_@16}{read $23_@17}{freeze renderedItems$4_@2}{read $24_@18}</read $18_@12>
89
- Return read $25_@19
80
+ [16] Const mutate count$17_@10 = read renderedItems$4_@2.length
81
+ [17] Const mutate $18_@11 = "div"
82
+ [18] Const mutate $19_@12 = "\n "
83
+ [19] Const mutate $20_@13 = "h1"
84
+ [20] Const mutate $21_@14 = " Items"
85
+ [21] Const mutate $22_@15 = JSX <read $20_@13>{freeze count$17_@10}{read $21_@14}</read $20_@13>
86
+ [22] Const mutate $23_@16 = "\n "
87
+ [23] Const mutate $24_@17 = "\n "
88
+ [24] Const mutate $25_@18 = JSX <read $18_@11>{read $19_@12}{read $22_@15}{read $23_@16}{freeze renderedItems$4_@2}{read $24_@17}</read $18_@11>
89
+ Return read $25_@18
90
```
91
92
### CFG
@@ -117,7 +117,7 @@ flowchart TB
117
end
118
subgraph bb8
119
bb8_instrs["
120
- [9] Const mutate $13_@7 = read $12_@3
120
+ [9] Const mutate $13_@3 = read $12_@3
121
"]
122
bb8_instrs --> bb8_terminal(["Goto"])
123
end
@@ -128,7 +128,7 @@ flowchart TB
128
bb9_instrs --> bb9_terminal(["Goto"])
129
end
130
subgraph bb7
131
- bb7_terminal(["If (read $13)"])
131
+ bb7_terminal(["If (read $13_@3)"])
132
end
133
subgraph bb5
134
bb5_terminal(["Goto"])
@@ -136,29 +136,29 @@ flowchart TB
136
subgraph bb4
137
bb4_instrs["
138
[11] Call mutate seen$5_@3.add(mutate item$10_@3)
139
- [12] Const mutate $14_@8 = 'div'
140
- [13] Const mutate $15_@9 = JSX <read $14_@8>{read item$10_@3}</read $14_@8>
141
- [14] Call mutate renderedItems$4_@2.push(read $15_@9)
142
- [15] Const mutate $16_@10 = Binary read renderedItems$4_@2.length >= read max$7_@5
139
+ [12] Const mutate $14_@7 = 'div'
140
+ [13] Const mutate $15_@8 = JSX <read $14_@7>{read item$10_@3}</read $14_@7>
141
+ [14] Call mutate renderedItems$4_@2.push(read $15_@8)
142
+ [15] Const mutate $16_@9 = Binary read renderedItems$4_@2.length >= read max$7_@5
143
"]
144
- bb4_instrs --> bb4_terminal(["If (read $16_@10)"])
144
+ bb4_instrs --> bb4_terminal(["If (read $16_@9)"])
145
end
146
subgraph bb10
147
bb10_terminal(["Goto"])
148
end
149
subgraph bb2
150
bb2_instrs["
151
- [16] Const mutate count$17_@11 = read renderedItems$4_@2.length
152
- [17] Const mutate $18_@12 = 'div'
153
- [18] Const mutate $19_@13 = '\n '
154
- [19] Const mutate $20_@14 = 'h1'
155
- [20] Const mutate $21_@15 = ' Items'
156
- [21] Const mutate $22_@16 = JSX <read $20_@14>{freeze count$17_@11}{read $21_@15}</read $20_@14>
157
- [22] Const mutate $23_@17 = '\n '
158
- [23] Const mutate $24_@18 = '\n '
159
- [24] Const mutate $25_@19 = JSX <read $18_@12>{read $19_@13}{read $22_@16}{read $23_@17}{freeze renderedItems$4_@2}{read $24_@18}</read $18_@12>
151
+ [16] Const mutate count$17_@10 = read renderedItems$4_@2.length
152
+ [17] Const mutate $18_@11 = 'div'
153
+ [18] Const mutate $19_@12 = '\n '
154
+ [19] Const mutate $20_@13 = 'h1'
155
+ [20] Const mutate $21_@14 = ' Items'
156
+ [21] Const mutate $22_@15 = JSX <read $20_@13>{freeze count$17_@10}{read $21_@14}</read $20_@13>
157
+ [22] Const mutate $23_@16 = '\n '
158
+ [23] Const mutate $24_@17 = '\n '
159
+ [24] Const mutate $25_@18 = JSX <read $18_@11>{read $19_@12}{read $22_@15}{read $23_@16}{freeze renderedItems$4_@2}{read $24_@17}</read $18_@11>
160
"]
161
- bb2_instrs --> bb2_terminal(["Return read $25_@19"])
161
+ bb2_instrs --> bb2_terminal(["Return read $25_@18"])
162
end
163
164
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md
+10
-10
@@ -36,14 +36,14 @@ bb2:
36
Goto bb1
37
bb3:
38
predecessor blocks: bb0
39
- [5] Reassign mutate a$4_@4 = Array []
39
+ [5] Reassign mutate a$4_@3 = Array []
40
Goto bb1
41
bb1:
42
predecessor blocks: bb2 bb3
43
- [6] Call read useFreeze$5(freeze a$4)
44
- [7] Call read useFreeze$5(read a$4)
45
- [8] Call mutate call$6_@5(read a$4)
46
- Return read a$4
43
+ [6] Call read useFreeze$5(freeze a$4_@3)
44
+ [7] Call read useFreeze$5(read a$4_@3)
45
+ [8] Call mutate call$6_@4(read a$4_@3)
46
+ Return read a$4_@3
47
```
48
49
### CFG
@@ -67,17 +67,17 @@ flowchart TB
67
end
68
subgraph bb3
69
bb3_instrs["
70
- [5] Reassign mutate a$4_@4 = Array []
70
+ [5] Reassign mutate a$4_@3 = Array []
71
"]
72
bb3_instrs --> bb3_terminal(["Goto"])
73
end
74
subgraph bb1
75
bb1_instrs["
76
- [6] Call read useFreeze$5(freeze a$4)
77
- [7] Call read useFreeze$5(read a$4)
78
- [8] Call mutate call$6_@5(read a$4)
76
+ [6] Call read useFreeze$5(freeze a$4_@3)
77
+ [7] Call read useFreeze$5(read a$4_@3)
78
+ [8] Call mutate call$6_@4(read a$4_@3)
79
"]
80
- bb1_instrs --> bb1_terminal(["Return read a$4"])
80
+ bb1_instrs --> bb1_terminal(["Return read a$4_@3"])
81
end
82
83
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
+12
-12
@@ -31,11 +31,11 @@ bb2:
31
Goto bb1
32
bb3:
33
predecessor blocks: bb0
34
- [3] Const mutate $3_@2 = read $2_@0
34
+ [3] Const mutate $3_@1 = read $2_@0
35
Goto bb1
36
bb1:
37
predecessor blocks: bb2 bb3
38
- Return freeze $3
38
+ Return freeze $3_@1
39
```
40
41
### CFG
@@ -57,12 +57,12 @@ flowchart TB
57
end
58
subgraph bb3
59
bb3_instrs["
60
- [3] Const mutate $3_@2 = read $2_@0
60
+ [3] Const mutate $3_@1 = read $2_@0
61
"]
62
bb3_instrs --> bb3_terminal(["Goto"])
63
end
64
subgraph bb1
65
- bb1_terminal(["Return freeze $3"])
65
+ bb1_terminal(["Return freeze $3_@1"])
66
end
67
68
%% Jumps
@@ -97,11 +97,11 @@ bb2:
97
Goto bb1
98
bb3:
99
predecessor blocks: bb0
100
- [3] Const mutate $3_@2 = Call mutate g$4_@2()
100
+ [3] Const mutate $3_@1 = Call mutate g$4_@1()
101
Goto bb1
102
bb1:
103
predecessor blocks: bb2 bb3
104
- Return freeze $3
104
+ Return freeze $3_@1
105
```
106
107
### CFG
@@ -123,12 +123,12 @@ flowchart TB
123
end
124
subgraph bb3
125
bb3_instrs["
126
- [3] Const mutate $3_@2 = Call mutate g$4_@2()
126
+ [3] Const mutate $3_@1 = Call mutate g$4_@1()
127
"]
128
bb3_instrs --> bb3_terminal(["Goto"])
129
end
130
subgraph bb1
131
- bb1_terminal(["Return freeze $3"])
131
+ bb1_terminal(["Return freeze $3_@1"])
132
end
133
134
%% Jumps
@@ -165,11 +165,11 @@ bb2:
165
Goto bb1
166
bb3:
167
predecessor blocks: bb0
168
- [5] Const mutate $6_@4 = Call mutate g$7_@4()
168
+ [5] Const mutate $6_@3 = Call mutate g$7_@3()
169
Goto bb1
170
bb1:
171
predecessor blocks: bb2 bb3
172
- Return freeze $6
172
+ Return freeze $6_@3
173
```
174
175
### CFG
@@ -193,12 +193,12 @@ flowchart TB
193
end
194
subgraph bb3
195
bb3_instrs["
196
- [5] Const mutate $6_@4 = Call mutate g$7_@4()
196
+ [5] Const mutate $6_@3 = Call mutate g$7_@3()
197
"]
198
bb3_instrs --> bb3_terminal(["Goto"])
199
end
200
subgraph bb1
201
- bb1_terminal(["Return freeze $6"])
201
+ bb1_terminal(["Return freeze $6_@3"])
202
end
203
204
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
+38
-38
@@ -100,43 +100,43 @@ function cond$0(x$1) {
100
```
101
bb0:
102
[1] Let mutate a$2_@0 = Object { }
103
- [2] Let mutate b$3_@1 = Object { }
104
- [3] Let mutate c$4_@2 = Object { }
105
- [4] Let mutate d$5_@3 = Object { }
103
+ [2] Let mutate b$3_@0 = Object { }
104
+ [3] Let mutate c$4_@1 = Object { }
105
+ [4] Let mutate d$5_@0 = Object { }
106
While test=bb1 loop=bb3 fallthrough=bb2
107
bb1:
108
predecessor blocks: bb0 bb4
109
- [5] Const mutate $10_@4 = true
110
- If (read $10_@4) then:bb3 else:bb2
109
+ [5] Const mutate $10_@2 = true
110
+ If (read $10_@2) then:bb3 else:bb2
111
bb3:
112
predecessor blocks: bb1
113
- [6] Let mutate z$6_@5 = read a$2
114
- [7] Reassign mutate a$2_@6[7:12] = read b$3
115
- [8] Reassign mutate b$3_@6[8:11] = read c$4
116
- [9] Reassign mutate c$4_@7 = read d$5
117
- [10] Reassign mutate d$5_@8 = read z$6_@5
118
- [11] Call mutate mutate$7_@6(mutate a$2_@6, mutate b$3_@6)
119
- [12] Const mutate $9_@6 = Call mutate cond$8_@6(mutate a$2_@6)
120
- If (read $9_@6) then:bb2 else:bb4
113
+ [6] Let mutate z$6_@3 = read a$2_@0
114
+ [7] Reassign mutate a$2_@0[7:12] = read b$3_@0
115
+ [8] Reassign mutate b$3_@0[8:11] = read c$4_@1
116
+ [9] Reassign mutate c$4_@1 = read d$5_@0
117
+ [10] Reassign mutate d$5_@0 = read z$6_@3
118
+ [11] Call mutate mutate$7_@0(mutate a$2_@0, mutate b$3_@0)
119
+ [12] Const mutate $9_@0 = Call mutate cond$8_@0(mutate a$2_@0)
120
+ If (read $9_@0) then:bb2 else:bb4
121
bb4:
122
predecessor blocks: bb3
123
Goto(Continue) bb1
124
bb2:
125
predecessor blocks: bb3 bb1
126
- If (read a$2) then:bb7 else:bb7
126
+ If (read a$2_@0) then:bb7 else:bb7
127
bb7:
128
predecessor blocks: bb2
129
- If (read b$3) then:bb9 else:bb9
129
+ If (read b$3_@0) then:bb9 else:bb9
130
bb9:
131
predecessor blocks: bb7
132
- If (read c$4) then:bb11 else:bb11
132
+ If (read c$4_@1) then:bb11 else:bb11
133
bb11:
134
predecessor blocks: bb9
135
- If (read d$5_@6) then:bb13 else:bb13
135
+ If (read d$5_@0) then:bb13 else:bb13
136
bb13:
137
predecessor blocks: bb11
138
- [13] Const mutate $11_@9 = null
139
- [14] Call mutate mutate$7_@6(mutate d$5_@6, read $11_@9)
138
+ [13] Const mutate $11_@4 = null
139
+ [14] Call mutate mutate$7_@0(mutate d$5_@0, read $11_@4)
140
Return
141
```
142
@@ -148,49 +148,49 @@ flowchart TB
148
subgraph bb0
149
bb0_instrs["
150
[1] Let mutate a$2_@0 = Object { }
151
- [2] Let mutate b$3_@1 = Object { }
152
- [3] Let mutate c$4_@2 = Object { }
153
- [4] Let mutate d$5_@3 = Object { }
151
+ [2] Let mutate b$3_@0 = Object { }
152
+ [3] Let mutate c$4_@1 = Object { }
153
+ [4] Let mutate d$5_@0 = Object { }
154
"]
155
bb0_instrs --> bb0_terminal(["While"])
156
end
157
subgraph bb1
158
bb1_instrs["
159
- [5] Const mutate $10_@4 = true
159
+ [5] Const mutate $10_@2 = true
160
"]
161
- bb1_instrs --> bb1_terminal(["If (read $10_@4)"])
161
+ bb1_instrs --> bb1_terminal(["If (read $10_@2)"])
162
end
163
subgraph bb3
164
bb3_instrs["
165
- [6] Let mutate z$6_@5 = read a$2
166
- [7] Reassign mutate a$2_@6[7:12] = read b$3
167
- [8] Reassign mutate b$3_@6[8:11] = read c$4
168
- [9] Reassign mutate c$4_@7 = read d$5
169
- [10] Reassign mutate d$5_@8 = read z$6_@5
170
- [11] Call mutate mutate$7_@6(mutate a$2_@6, mutate b$3_@6)
171
- [12] Const mutate $9_@6 = Call mutate cond$8_@6(mutate a$2_@6)
165
+ [6] Let mutate z$6_@3 = read a$2_@0
166
+ [7] Reassign mutate a$2_@0[7:12] = read b$3_@0
167
+ [8] Reassign mutate b$3_@0[8:11] = read c$4_@1
168
+ [9] Reassign mutate c$4_@1 = read d$5_@0
169
+ [10] Reassign mutate d$5_@0 = read z$6_@3
170
+ [11] Call mutate mutate$7_@0(mutate a$2_@0, mutate b$3_@0)
171
+ [12] Const mutate $9_@0 = Call mutate cond$8_@0(mutate a$2_@0)
172
"]
173
- bb3_instrs --> bb3_terminal(["If (read $9_@6)"])
173
+ bb3_instrs --> bb3_terminal(["If (read $9_@0)"])
174
end
175
subgraph bb4
176
bb4_terminal(["Goto"])
177
end
178
subgraph bb2
179
- bb2_terminal(["If (read a$2)"])
179
+ bb2_terminal(["If (read a$2_@0)"])
180
end
181
subgraph bb7
182
- bb7_terminal(["If (read b$3)"])
182
+ bb7_terminal(["If (read b$3_@0)"])
183
end
184
subgraph bb9
185
- bb9_terminal(["If (read c$4)"])
185
+ bb9_terminal(["If (read c$4_@1)"])
186
end
187
subgraph bb11
188
- bb11_terminal(["If (read d$5_@6)"])
188
+ bb11_terminal(["If (read d$5_@0)"])
189
end
190
subgraph bb13
191
bb13_instrs["
192
- [13] Const mutate $11_@9 = null
193
- [14] Call mutate mutate$7_@6(mutate d$5_@6, read $11_@9)
192
+ [13] Const mutate $11_@4 = null
193
+ [14] Call mutate mutate$7_@0(mutate d$5_@0, read $11_@4)
194
"]
195
bb13_instrs --> bb13_terminal(["Return"])
196
end
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
+8
-8
@@ -29,14 +29,14 @@ bb0:
29
If (read props$1.p1) then:bb2 else:bb1
30
bb2:
31
predecessor blocks: bb0
32
- [4] Reassign mutate x$2_@2 = Array []
32
+ [4] Reassign mutate x$2_@0 = Array []
33
Goto bb1
34
bb1:
35
predecessor blocks: bb2 bb0
36
- [5] Let mutate _$4_@3 = JSX <read Component$0 x={freeze x$2} ></read Component$0>
36
+ [5] Let mutate _$4_@2 = JSX <read Component$0 x={freeze x$2_@0} ></read Component$0>
37
[6] Call read y$3_@1.push(read props$1.p2)
38
- [7] Const mutate $5_@4 = JSX <read Component$0 x={read x$2} y={read y$3_@1} ></read Component$0>
39
- Return read $5_@4
38
+ [7] Const mutate $5_@3 = JSX <read Component$0 x={read x$2_@0} y={read y$3_@1} ></read Component$0>
39
+ Return read $5_@3
40
```
41
42
### CFG
@@ -54,17 +54,17 @@ flowchart TB
54
end
55
subgraph bb2
56
bb2_instrs["
57
- [4] Reassign mutate x$2_@2 = Array []
57
+ [4] Reassign mutate x$2_@0 = Array []
58
"]
59
bb2_instrs --> bb2_terminal(["Goto"])
60
end
61
subgraph bb1
62
bb1_instrs["
63
- [5] Let mutate _$4_@3 = JSX <read Component$0 x={freeze x$2} ></read Component$0>
63
+ [5] Let mutate _$4_@2 = JSX <read Component$0 x={freeze x$2_@0} ></read Component$0>
64
[6] Call read y$3_@1.push(read props$1.p2)
65
- [7] Const mutate $5_@4 = JSX <read Component$0 x={read x$2} y={read y$3_@1} ></read Component$0>
65
+ [7] Const mutate $5_@3 = JSX <read Component$0 x={read x$2_@0} y={read y$3_@1} ></read Component$0>
66
"]
67
- bb1_instrs --> bb1_terminal(["Return read $5_@4"])
67
+ bb1_instrs --> bb1_terminal(["Return read $5_@3"])
68
end
69
70
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md
+10
-10
@@ -54,26 +54,26 @@ bb8:
54
Goto bb1
55
bb6:
56
predecessor blocks: bb2
57
- [6] Reassign mutate x$2_@5 = read props$1.v1
57
+ [6] Reassign mutate x$2_@4 = read props$1.v1
58
Goto bb1
59
bb4:
60
predecessor blocks: bb2
61
- [7] Reassign mutate x$2_@6 = read props$1.v2
61
+ [7] Reassign mutate x$2_@4 = read props$1.v2
62
Goto bb1
63
bb10:
64
predecessor blocks: bb0
65
If (read props$1.cond2) then:bb12 else:bb13
66
bb12:
67
predecessor blocks: bb10
68
- [8] Reassign mutate x$2_@7 = read props$1.b
68
+ [8] Reassign mutate x$2_@4 = read props$1.b
69
Goto bb1
70
bb13:
71
predecessor blocks: bb10
72
- [9] Reassign mutate x$2_@8 = read props$1.c
72
+ [9] Reassign mutate x$2_@4 = read props$1.c
73
Goto bb1
74
bb1:
75
predecessor blocks: bb8 bb6 bb4 bb12 bb13
76
- [10] read x$2
76
+ [10] read x$2_@4
77
Return
78
```
79
@@ -104,13 +104,13 @@ flowchart TB
104
end
105
subgraph bb6
106
bb6_instrs["
107
- [6] Reassign mutate x$2_@5 = read props$1.v1
107
+ [6] Reassign mutate x$2_@4 = read props$1.v1
108
"]
109
bb6_instrs --> bb6_terminal(["Goto"])
110
end
111
subgraph bb4
112
bb4_instrs["
113
- [7] Reassign mutate x$2_@6 = read props$1.v2
113
+ [7] Reassign mutate x$2_@4 = read props$1.v2
114
"]
115
bb4_instrs --> bb4_terminal(["Goto"])
116
end
@@ -119,19 +119,19 @@ flowchart TB
119
end
120
subgraph bb12
121
bb12_instrs["
122
- [8] Reassign mutate x$2_@7 = read props$1.b
122
+ [8] Reassign mutate x$2_@4 = read props$1.b
123
"]
124
bb12_instrs --> bb12_terminal(["Goto"])
125
end
126
subgraph bb13
127
bb13_instrs["
128
- [9] Reassign mutate x$2_@8 = read props$1.c
128
+ [9] Reassign mutate x$2_@4 = read props$1.c
129
"]
130
bb13_instrs --> bb13_terminal(["Goto"])
131
end
132
subgraph bb1
133
bb1_instrs["
134
- [10] read x$2
134
+ [10] read x$2_@4
135
"]
136
bb1_instrs --> bb1_terminal(["Return"])
137
end
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+12
-12
@@ -28,20 +28,20 @@ bb0:
28
If (read $4_@3) then:bb2 else:bb1
29
bb2:
30
predecessor blocks: bb0
31
- [5] Reassign mutate x$1_@4 = 3
31
+ [5] Reassign mutate x$1_@0 = 3
32
Goto bb1
33
bb1:
34
predecessor blocks: bb2 bb0
35
- [6] Const mutate $5_@5 = 3
36
- [7] Const mutate $6_@6 = Binary read y$2_@1 === read $5_@5
37
- If (read $6_@6) then:bb4 else:bb3
35
+ [6] Const mutate $5_@4 = 3
36
+ [7] Const mutate $6_@5 = Binary read y$2_@1 === read $5_@4
37
+ If (read $6_@5) then:bb4 else:bb3
38
bb4:
39
predecessor blocks: bb1
40
- [8] Reassign mutate x$1_@7 = 5
40
+ [8] Reassign mutate x$1_@0 = 5
41
Goto bb3
42
bb3:
43
predecessor blocks: bb4 bb1
44
- [9] Reassign mutate y$2_@8 = read x$1
44
+ [9] Reassign mutate y$2_@6 = read x$1_@0
45
Return
46
```
47
@@ -61,26 +61,26 @@ flowchart TB
61
end
62
subgraph bb2
63
bb2_instrs["
64
- [5] Reassign mutate x$1_@4 = 3
64
+ [5] Reassign mutate x$1_@0 = 3
65
"]
66
bb2_instrs --> bb2_terminal(["Goto"])
67
end
68
subgraph bb1
69
bb1_instrs["
70
- [6] Const mutate $5_@5 = 3
71
- [7] Const mutate $6_@6 = Binary read y$2_@1 === read $5_@5
70
+ [6] Const mutate $5_@4 = 3
71
+ [7] Const mutate $6_@5 = Binary read y$2_@1 === read $5_@4
72
"]
73
- bb1_instrs --> bb1_terminal(["If (read $6_@6)"])
73
+ bb1_instrs --> bb1_terminal(["If (read $6_@5)"])
74
end
75
subgraph bb4
76
bb4_instrs["
77
- [8] Reassign mutate x$1_@7 = 5
77
+ [8] Reassign mutate x$1_@0 = 5
78
"]
79
bb4_instrs --> bb4_terminal(["Goto"])
80
end
81
subgraph bb3
82
bb3_instrs["
83
- [9] Reassign mutate y$2_@8 = read x$1
83
+ [9] Reassign mutate y$2_@6 = read x$1_@0
84
"]
85
bb3_instrs --> bb3_terminal(["Return"])
86
end
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+4
-4
@@ -25,11 +25,11 @@ bb0:
25
If (read $4_@3) then:bb2 else:bb1
26
bb2:
27
predecessor blocks: bb0
28
- [5] Reassign mutate x$1_@4 = 3
28
+ [5] Reassign mutate x$1_@0 = 3
29
Goto bb1
30
bb1:
31
predecessor blocks: bb2 bb0
32
- [6] Reassign mutate y$2_@5 = read x$1
32
+ [6] Reassign mutate y$2_@4 = read x$1_@0
33
Return
34
```
35
@@ -49,13 +49,13 @@ flowchart TB
49
end
50
subgraph bb2
51
bb2_instrs["
52
- [5] Reassign mutate x$1_@4 = 3
52
+ [5] Reassign mutate x$1_@0 = 3
53
"]
54
bb2_instrs --> bb2_terminal(["Goto"])
55
end
56
subgraph bb1
57
bb1_instrs["
58
- [6] Reassign mutate y$2_@5 = read x$1
58
+ [6] Reassign mutate y$2_@4 = read x$1_@0
59
"]
60
bb1_instrs --> bb1_terminal(["Return"])
61
end
compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md
+6
-6
@@ -21,16 +21,16 @@ bb0:
21
bb1:
22
predecessor blocks: bb0 bb4
23
[2] Const mutate $3_@1 = 10
24
- [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1
24
+ [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1
25
If (read $4_@2) then:bb4 else:bb2
26
bb4:
27
predecessor blocks: bb1
28
[4] Const mutate $2_@3 = 1
29
- [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3
29
+ [5] Reassign mutate x$1_@0 = Binary read x$1_@0 + read $2_@3
30
Goto(Continue) bb1
31
bb2:
32
predecessor blocks: bb1
33
- Return read x$1
33
+ Return read x$1_@0
34
```
35
36
### CFG
@@ -47,19 +47,19 @@ flowchart TB
47
subgraph bb1
48
bb1_instrs["
49
[2] Const mutate $3_@1 = 10
50
- [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1
50
+ [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1
51
"]
52
bb1_instrs --> bb1_terminal(["If (read $4_@2)"])
53
end
54
subgraph bb4
55
bb4_instrs["
56
[4] Const mutate $2_@3 = 1
57
- [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3
57
+ [5] Reassign mutate x$1_@0 = Binary read x$1_@0 + read $2_@3
58
"]
59
bb4_instrs --> bb4_terminal(["Goto"])
60
end
61
subgraph bb2
62
- bb2_terminal(["Return read x$1"])
62
+ bb2_terminal(["Return read x$1_@0"])
63
end
64
65
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+8
-8
@@ -29,16 +29,16 @@ bb0:
29
If (read $4_@3) then:bb2 else:bb3
30
bb2:
31
predecessor blocks: bb0
32
- [5] Reassign mutate x$1_@4 = 2
32
+ [5] Reassign mutate x$1_@0 = 2
33
Goto bb1
34
bb3:
35
predecessor blocks: bb0
36
- [6] Reassign mutate y$2_@5 = 3
36
+ [6] Reassign mutate y$2_@1 = 3
37
Goto bb1
38
bb1:
39
predecessor blocks: bb2 bb3
40
- [7] Let mutate t$5_@6 = Object { x: read x$1, y: read y$2 }
41
- Return freeze t$5_@6
40
+ [7] Let mutate t$5_@4 = Object { x: read x$1_@0, y: read y$2_@1 }
41
+ Return freeze t$5_@4
42
```
43
44
### CFG
@@ -57,21 +57,21 @@ flowchart TB
57
end
58
subgraph bb2
59
bb2_instrs["
60
- [5] Reassign mutate x$1_@4 = 2
60
+ [5] Reassign mutate x$1_@0 = 2
61
"]
62
bb2_instrs --> bb2_terminal(["Goto"])
63
end
64
subgraph bb3
65
bb3_instrs["
66
- [6] Reassign mutate y$2_@5 = 3
66
+ [6] Reassign mutate y$2_@1 = 3
67
"]
68
bb3_instrs --> bb3_terminal(["Goto"])
69
end
70
subgraph bb1
71
bb1_instrs["
72
- [7] Let mutate t$5_@6 = Object { x: read x$1, y: read y$2 }
72
+ [7] Let mutate t$5_@4 = Object { x: read x$1_@0, y: read y$2_@1 }
73
"]
74
- bb1_instrs --> bb1_terminal(["Return freeze t$5_@6"])
74
+ bb1_instrs --> bb1_terminal(["Return freeze t$5_@4"])
75
end
76
77
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md
+4
-4
@@ -23,11 +23,11 @@ bb0:
23
If (read $3_@2) then:bb2 else:bb1
24
bb2:
25
predecessor blocks: bb0
26
- [4] Reassign mutate x$1_@3 = 2
26
+ [4] Reassign mutate x$1_@0 = 2
27
Goto bb1
28
bb1:
29
predecessor blocks: bb2 bb0
30
- Return read x$1
30
+ Return read x$1_@0
31
```
32
33
### CFG
@@ -45,12 +45,12 @@ flowchart TB
45
end
46
subgraph bb2
47
bb2_instrs["
48
- [4] Reassign mutate x$1_@3 = 2
48
+ [4] Reassign mutate x$1_@0 = 2
49
"]
50
bb2_instrs --> bb2_terminal(["Goto"])
51
end
52
subgraph bb1
53
- bb1_terminal(["Return read x$1"])
53
+ bb1_terminal(["Return read x$1_@0"])
54
end
55
56
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md
+4
-4
@@ -58,11 +58,11 @@ bb2:
58
Goto bb1
59
bb3:
60
predecessor blocks: bb0
61
- [4] Reassign mutate str$2_@3 = "fallthrough test"
61
+ [4] Reassign mutate str$2_@0 = "fallthrough test"
62
Goto bb1
63
bb1:
64
predecessor blocks: bb2 bb3
65
- [5] Call mutate log$4_@2(read str$2)
65
+ [5] Call mutate log$4_@2(read str$2_@0)
66
Return
67
```
68
@@ -86,13 +86,13 @@ flowchart TB
86
end
87
subgraph bb3
88
bb3_instrs["
89
- [4] Reassign mutate str$2_@3 = 'fallthrough test'
89
+ [4] Reassign mutate str$2_@0 = 'fallthrough test'
90
"]
91
bb3_instrs --> bb3_terminal(["Goto"])
92
end
93
subgraph bb1
94
bb1_instrs["
95
- [5] Call mutate log$4_@2(read str$2)
95
+ [5] Call mutate log$4_@2(read str$2_@0)
96
"]
97
bb1_instrs --> bb1_terminal(["Return"])
98
end
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+4
-4
@@ -30,11 +30,11 @@ bb2:
30
Goto bb1
31
bb3:
32
predecessor blocks: bb0
33
- [5] Reassign mutate y$1_@4 = 2
33
+ [5] Reassign mutate y$1_@3 = 2
34
Goto bb1
35
bb1:
36
predecessor blocks: bb2 bb3
37
- [6] Let mutate x$4_@5 = read y$1
37
+ [6] Let mutate x$4_@4 = read y$1_@3
38
Return
39
```
40
@@ -59,13 +59,13 @@ flowchart TB
59
end
60
subgraph bb3
61
bb3_instrs["
62
- [5] Reassign mutate y$1_@4 = 2
62
+ [5] Reassign mutate y$1_@3 = 2
63
"]
64
bb3_instrs --> bb3_terminal(["Goto"])
65
end
66
subgraph bb1
67
bb1_instrs["
68
- [6] Let mutate x$4_@5 = read y$1
68
+ [6] Let mutate x$4_@4 = read y$1_@3
69
"]
70
bb1_instrs --> bb1_terminal(["Return"])
71
end
compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md
+8
-8
@@ -45,16 +45,16 @@ bb5:
45
bb3:
46
predecessor blocks: bb0
47
[8] Const mutate $3_@7 = 2
48
- [9] Reassign mutate x$1_@8 = Binary read x$1_@0 + read $3_@7
48
+ [9] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $3_@7
49
Goto bb1
50
bb2:
51
predecessor blocks: bb0
52
- [10] Const mutate $2_@9 = 3
53
- [11] Reassign mutate x$1_@10 = Binary read x$1_@0 + read $2_@9
52
+ [10] Const mutate $2_@8 = 3
53
+ [11] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $2_@8
54
Goto bb1
55
bb1:
56
predecessor blocks: bb5 bb3 bb2
57
- [12] Let mutate y$9_@11 = read x$1
57
+ [12] Let mutate y$9_@9 = read x$1_@6
58
Return
59
```
60
@@ -83,20 +83,20 @@ flowchart TB
83
subgraph bb3
84
bb3_instrs["
85
[8] Const mutate $3_@7 = 2
86
- [9] Reassign mutate x$1_@8 = Binary read x$1_@0 + read $3_@7
86
+ [9] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $3_@7
87
"]
88
bb3_instrs --> bb3_terminal(["Goto"])
89
end
90
subgraph bb2
91
bb2_instrs["
92
- [10] Const mutate $2_@9 = 3
93
- [11] Reassign mutate x$1_@10 = Binary read x$1_@0 + read $2_@9
92
+ [10] Const mutate $2_@8 = 3
93
+ [11] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $2_@8
94
"]
95
bb2_instrs --> bb2_terminal(["Goto"])
96
end
97
subgraph bb1
98
bb1_instrs["
99
- [12] Let mutate y$9_@11 = read x$1
99
+ [12] Let mutate y$9_@9 = read x$1_@6
100
"]
101
bb1_instrs --> bb1_terminal(["Return"])
102
end
compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md
+4
-4
@@ -22,11 +22,11 @@ bb0:
22
If (read $3_@2) then:bb2 else:bb1
23
bb2:
24
predecessor blocks: bb0
25
- [4] Reassign mutate x$1_@3 = 2
25
+ [4] Reassign mutate x$1_@0 = 2
26
Goto bb1
27
bb1:
28
predecessor blocks: bb2 bb0
29
- Throw read x$1
29
+ Throw read x$1_@0
30
```
31
32
### CFG
@@ -44,12 +44,12 @@ flowchart TB
44
end
45
subgraph bb2
46
bb2_instrs["
47
- [4] Reassign mutate x$1_@3 = 2
47
+ [4] Reassign mutate x$1_@0 = 2
48
"]
49
bb2_instrs --> bb2_terminal(["Goto"])
50
end
51
subgraph bb1
52
- bb1_terminal(["Throw read x$1"])
52
+ bb1_terminal(["Throw read x$1_@0"])
53
end
54
55
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md
+6
-6
@@ -22,16 +22,16 @@ bb0:
22
bb1:
23
predecessor blocks: bb0 bb3
24
[2] Const mutate $3_@1 = 10
25
- [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1
25
+ [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1
26
If (read $4_@2) then:bb3 else:bb2
27
bb3:
28
predecessor blocks: bb1
29
[4] Const mutate $2_@3 = 1
30
- [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3
30
+ [5] Reassign mutate x$1_@0 = Binary read x$1_@0 + read $2_@3
31
Goto(Continue) bb1
32
bb2:
33
predecessor blocks: bb1
34
- Return read x$1
34
+ Return read x$1_@0
35
```
36
37
### CFG
@@ -48,19 +48,19 @@ flowchart TB
48
subgraph bb1
49
bb1_instrs["
50
[2] Const mutate $3_@1 = 10
51
- [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1
51
+ [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1
52
"]
53
bb1_instrs --> bb1_terminal(["If (read $4_@2)"])
54
end
55
subgraph bb3
56
bb3_instrs["
57
[4] Const mutate $2_@3 = 1
58
- [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3
58
+ [5] Reassign mutate x$1_@0 = Binary read x$1_@0 + read $2_@3
59
"]
60
bb3_instrs --> bb3_terminal(["Goto"])
61
end
62
subgraph bb2
63
- bb2_terminal(["Return read x$1"])
63
+ bb2_terminal(["Return read x$1_@0"])
64
end
65
66
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md
+12
-12
@@ -45,18 +45,18 @@ bb0:
45
bb6:
46
predecessor blocks: bb0
47
[6] Call mutate x$2_@0.push(read props$1.p2)
48
- [7] Reassign mutate y$3_@5 = Array []
48
+ [7] Reassign mutate y$3_@1 = Array []
49
Goto bb1
50
bb2:
51
predecessor blocks: bb0
52
- [8] Reassign mutate y$3_@6 = read x$2_@0
52
+ [8] Reassign mutate y$3_@1 = read x$2_@0
53
Goto bb1
54
bb1:
55
predecessor blocks: bb0 bb6 bb2
56
- [9] Const mutate child$7_@7 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
57
- [10] Call read y$3.push(read props$1.p4)
58
- [11] Const mutate $8_@8 = JSX <read Component$0 data={freeze y$3} >{read child$7_@7}</read Component$0>
59
- Return read $8_@8
56
+ [9] Const mutate child$7_@5 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
57
+ [10] Call read y$3_@1.push(read props$1.p4)
58
+ [11] Const mutate $8_@6 = JSX <read Component$0 data={freeze y$3_@1} >{read child$7_@5}</read Component$0>
59
+ Return read $8_@6
60
```
61
62
### CFG
@@ -77,23 +77,23 @@ flowchart TB
77
subgraph bb6
78
bb6_instrs["
79
[6] Call mutate x$2_@0.push(read props$1.p2)
80
- [7] Reassign mutate y$3_@5 = Array []
80
+ [7] Reassign mutate y$3_@1 = Array []
81
"]
82
bb6_instrs --> bb6_terminal(["Goto"])
83
end
84
subgraph bb2
85
bb2_instrs["
86
- [8] Reassign mutate y$3_@6 = read x$2_@0
86
+ [8] Reassign mutate y$3_@1 = read x$2_@0
87
"]
88
bb2_instrs --> bb2_terminal(["Goto"])
89
end
90
subgraph bb1
91
bb1_instrs["
92
- [9] Const mutate child$7_@7 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
93
- [10] Call read y$3.push(read props$1.p4)
94
- [11] Const mutate $8_@8 = JSX <read Component$0 data={freeze y$3} >{read child$7_@7}</read Component$0>
92
+ [9] Const mutate child$7_@5 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
93
+ [10] Call read y$3_@1.push(read props$1.p4)
94
+ [11] Const mutate $8_@6 = JSX <read Component$0 data={freeze y$3_@1} >{read child$7_@5}</read Component$0>
95
"]
96
- bb1_instrs --> bb1_terminal(["Return read $8_@8"])
96
+ bb1_instrs --> bb1_terminal(["Return read $8_@6"])
97
end
98
99
%% Jumps
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+10
-10
@@ -44,14 +44,14 @@ bb4:
44
Goto bb2
45
bb2:
46
predecessor blocks: bb4 bb0
47
- [8] Reassign mutate y$3_@5 = read x$2_@0
47
+ [8] Reassign mutate y$3_@1 = read x$2_@0
48
Goto bb1
49
bb1:
50
predecessor blocks: bb2 bb0
51
- [9] Const mutate child$6_@6 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
52
- [10] Call read y$3.push(read props$1.p4)
53
- [11] Const mutate $7_@7 = JSX <read Component$0 data={read y$3} >{read child$6_@6}</read Component$0>
54
- Return read $7_@7
51
+ [9] Const mutate child$6_@5 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
52
+ [10] Call read y$3_@1.push(read props$1.p4)
53
+ [11] Const mutate $7_@6 = JSX <read Component$0 data={read y$3_@1} >{read child$6_@5}</read Component$0>
54
+ Return read $7_@6
55
```
56
57
### CFG
@@ -78,17 +78,17 @@ flowchart TB
78
end
79
subgraph bb2
80
bb2_instrs["
81
- [8] Reassign mutate y$3_@5 = read x$2_@0
81
+ [8] Reassign mutate y$3_@1 = read x$2_@0
82
"]
83
bb2_instrs --> bb2_terminal(["Goto"])
84
end
85
subgraph bb1
86
bb1_instrs["
87
- [9] Const mutate child$6_@6 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
88
- [10] Call read y$3.push(read props$1.p4)
89
- [11] Const mutate $7_@7 = JSX <read Component$0 data={read y$3} >{read child$6_@6}</read Component$0>
87
+ [9] Const mutate child$6_@5 = JSX <read Component$0 data={freeze x$2_@0} ></read Component$0>
88
+ [10] Call read y$3_@1.push(read props$1.p4)
89
+ [11] Const mutate $7_@6 = JSX <read Component$0 data={read y$3_@1} >{read child$6_@5}</read Component$0>
90
"]
91
- bb1_instrs --> bb1_terminal(["Return read $7_@7"])
91
+ bb1_instrs --> bb1_terminal(["Return read $7_@6"])
92
end
93
94
%% Jumps