@samitouri / QOS-React-2 / commits / 255700e2cd

Increase precision in InferMutableRangesForAlias

Previously, this step just set the mutable range of any alias set including any mutation to the end of the last mutable range of any of the containing identifiers. This change makes it so that the ends are only updated of the ranges that end before the last mutation. Fixes #852

Jan Kassens committed Dec 9, 2022 at 13:10 UTC 255700e2cdc5d66cb4158a136f9964b434352d55
10 files changed +220 -138
compiler/forget/src/HIR/InferMutableRangesForAlias.ts
+13 -6
@@ -7,18 +7,25 @@ export function inferMutableRangesForAlias(aliases: DisjointSet<Identifier>) {
7 for (const aliasSet of aliasSets) {
8 // Update mutableRange.end only if the identifiers have actually been
9 // mutated.
10 - const haveIdentifiersBeenMutated = [...aliasSet].some(
10 + const mutatingIdentifiers = [...aliasSet].filter(
11 (id) => id.mutableRange.end - id.mutableRange.start > 1
12 );
13
14 - if (haveIdentifiersBeenMutated) {
14 + if (mutatingIdentifiers.length > 0) {
15 // Find final instruction which mutates this alias set.
16 - const mutableRangeEnds = [...aliasSet].map((id) => id.mutableRange.end);
17 - const maxMutableRangeEnd = Math.max(...mutableRangeEnds) as InstructionId;
16 + let lastMutatingInstructionId = 0;
17 + for (const id of mutatingIdentifiers) {
18 + if (id.mutableRange.end > lastMutatingInstructionId) {
19 + lastMutatingInstructionId = id.mutableRange.end;
20 + }
21 + }
22
19 - // Update mutableRange.end for all aliases in this set.
23 + // Update mutableRange.end for all aliases in this set ending before the
24 + // last mutation.
25 for (const alias of aliasSet) {
21 - alias.mutableRange.end = maxMutableRangeEnd;
26 + if (alias.mutableRange.end < lastMutatingInstructionId) {
27 + alias.mutableRange.end = lastMutatingInstructionId as InstructionId;
28 + }
29 }
30 }
31 }
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+26 -26
@@ -37,7 +37,7 @@ function Component(props) {
37 bb0:
38 [1] Const mutate items$27_@0 = read props$26.items
39 [2] Const mutate maxItems$28_@1 = read props$26.maxItems
40 - [3] Const mutate renderedItems$29_@2[3:26] = Array []
40 + [3] Const mutate renderedItems$29_@2[3:22] = Array []
41 [4] Const mutate seen$30_@3[0:19] = New mutate Set$6_@3()
42 [5] Const mutate $31_@4 = 0
43 [6] Const mutate max$32_@5[0:7] = Call mutate Math$8_@5.max(read $31_@4, read maxItems$28_@1)
@@ -71,23 +71,23 @@ bb4:
71 [19] Const mutate $43_@7 = "div"
72 [20] Const mutate $44_@8 = JSX <read $43_@7>{read item$10_@3}</read $43_@7>
73 [21] Call mutate renderedItems$29_@2.push(read $44_@8)
74 - [22] Const mutate $49_@2[3:26] = Binary read renderedItems$29_@2.length >= read max$32_@5
75 - [23] If (read $49_@2) then:bb2 else:bb10 fallthrough=bb10
74 + [22] Const mutate $49_@9 = Binary read renderedItems$29_@2.length >= read max$32_@5
75 + [23] If (read $49_@9) then:bb2 else:bb10 fallthrough=bb10
76 bb10:
77 predecessor blocks: bb4
78 [24] Goto(Continue) bb1
79 bb2:
80 predecessor blocks: bb4 bb1
81 - [25] Const mutate count$52_@2[3:26] = read renderedItems$29_@2.length
82 - [26] Const mutate $53_@9 = "div"
83 - [27] Const mutate $54_@10 = "\n "
84 - [28] Const mutate $55_@11 = "h1"
85 - [29] Const mutate $56_@12 = " Items"
86 - [30] Const mutate $57_@13 = JSX <read $55_@11>{freeze count$52_@2}{read $56_@12}</read $55_@11>
87 - [31] Const mutate $58_@14 = "\n "
88 - [32] Const mutate $59_@15 = "\n "
89 - [33] Const mutate $60_@16 = JSX <read $53_@9>{read $54_@10}{read $57_@13}{read $58_@14}{freeze renderedItems$29_@2}{read $59_@15}</read $53_@9>
90 - [34] Return read $60_@16
81 + [25] Const mutate count$52_@10 = read renderedItems$29_@2.length
82 + [26] Const mutate $53_@11 = "div"
83 + [27] Const mutate $54_@12 = "\n "
84 + [28] Const mutate $55_@13 = "h1"
85 + [29] Const mutate $56_@14 = " Items"
86 + [30] Const mutate $57_@15 = JSX <read $55_@13>{freeze count$52_@10}{read $56_@14}</read $55_@13>
87 + [31] Const mutate $58_@16 = "\n "
88 + [32] Const mutate $59_@17 = "\n "
89 + [33] Const mutate $60_@18 = JSX <read $53_@11>{read $54_@12}{read $57_@15}{read $58_@16}{freeze renderedItems$29_@2}{read $59_@17}</read $53_@11>
90 + [34] Return read $60_@18
91 scope0 [1:2]:
92 - read props$26.items
93 scope1 [2:3]:
@@ -103,7 +103,7 @@ flowchart TB
103 bb0_instrs["
104 [1] Const mutate items$27_@0 = read props$26.items
105 [2] Const mutate maxItems$28_@1 = read props$26.maxItems
106 - [3] Const mutate renderedItems$29_@2[3:26] = Array []
106 + [3] Const mutate renderedItems$29_@2[3:22] = Array []
107 [4] Const mutate seen$30_@3[0:19] = New mutate Set$6_@3()
108 [5] Const mutate $31_@4 = 0
109 [6] Const mutate max$32_@5[0:7] = Call mutate Math$8_@5.max(read $31_@4, read maxItems$28_@1)
@@ -145,26 +145,26 @@ flowchart TB
145 [19] Const mutate $43_@7 = 'div'
146 [20] Const mutate $44_@8 = JSX <read $43_@7>{read item$10_@3}</read $43_@7>
147 [21] Call mutate renderedItems$29_@2.push(read $44_@8)
148 - [22] Const mutate $49_@2[3:26] = Binary read renderedItems$29_@2.length >= read max$32_@5
148 + [22] Const mutate $49_@9 = Binary read renderedItems$29_@2.length >= read max$32_@5
149 "]
150 - bb4_instrs --> bb4_terminal(["If (read $49_@2)"])
150 + bb4_instrs --> bb4_terminal(["If (read $49_@9)"])
151 end
152 subgraph bb10
153 bb10_terminal(["Goto"])
154 end
155 subgraph bb2
156 bb2_instrs["
157 - [25] Const mutate count$52_@2[3:26] = read renderedItems$29_@2.length
158 - [26] Const mutate $53_@9 = 'div'
159 - [27] Const mutate $54_@10 = '\n '
160 - [28] Const mutate $55_@11 = 'h1'
161 - [29] Const mutate $56_@12 = ' Items'
162 - [30] Const mutate $57_@13 = JSX <read $55_@11>{freeze count$52_@2}{read $56_@12}</read $55_@11>
163 - [31] Const mutate $58_@14 = '\n '
164 - [32] Const mutate $59_@15 = '\n '
165 - [33] Const mutate $60_@16 = JSX <read $53_@9>{read $54_@10}{read $57_@13}{read $58_@14}{freeze renderedItems$29_@2}{read $59_@15}</read $53_@9>
157 + [25] Const mutate count$52_@10 = read renderedItems$29_@2.length
158 + [26] Const mutate $53_@11 = 'div'
159 + [27] Const mutate $54_@12 = '\n '
160 + [28] Const mutate $55_@13 = 'h1'
161 + [29] Const mutate $56_@14 = ' Items'
162 + [30] Const mutate $57_@15 = JSX <read $55_@13>{freeze count$52_@10}{read $56_@14}</read $55_@13>
163 + [31] Const mutate $58_@16 = '\n '
164 + [32] Const mutate $59_@17 = '\n '
165 + [33] Const mutate $60_@18 = JSX <read $53_@11>{read $54_@12}{read $57_@15}{read $58_@16}{freeze renderedItems$29_@2}{read $59_@17}</read $53_@11>
166 "]
167 - bb2_instrs --> bb2_terminal(["Return read $60_@16"])
167 + bb2_instrs --> bb2_terminal(["Return read $60_@18"])
168 end
169
170 %% Jumps
compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md new
+61
@@ -0,0 +1,61 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(c) {
6 + let x = { c };
7 + mutate(x);
8 + let a = x;
9 + let b = a;
10 +}
11 +
12 +```
13 +
14 +## HIR
15 +
16 +```
17 +bb0:
18 + [1] Const mutate x$7_@0[0:3] = Object { c: read c$6 }
19 + [2] Call mutate mutate$3_@0(mutate x$7_@0)
20 + [3] Const mutate a$8_@1 = read x$7_@0
21 + [4] Const mutate b$9_@2 = read a$8_@1
22 + [5] Return
23 +scope1 [3:4]:
24 + - read x$7_@0
25 +scope2 [4:5]:
26 + - read a$8_@1
27 +```
28 +
29 +### CFG
30 +
31 +```mermaid
32 +flowchart TB
33 + %% Basic Blocks
34 + subgraph bb0
35 + bb0_instrs["
36 + [1] Const mutate x$7_@0[0:3] = Object { c: read c$6 }
37 + [2] Call mutate mutate$3_@0(mutate x$7_@0)
38 + [3] Const mutate a$8_@1 = read x$7_@0
39 + [4] Const mutate b$9_@2 = read a$8_@1
40 + "]
41 + bb0_instrs --> bb0_terminal(["Return"])
42 + end
43 +
44 + %% Jumps
45 + %% empty
46 +```
47 +
48 +## Code
49 +
50 +```javascript
51 +function Component$0(c$6) {
52 + const x$7 = {
53 + c: c$6,
54 + };
55 + mutate$3(x$7);
56 + const a$8 = x$7;
57 + const b$9 = a$8;
58 +}
59 +
60 +```
61 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/issue852.js new
+6
@@ -0,0 +1,6 @@
1 +function Component(c) {
2 + let x = { c };
3 + mutate(x);
4 + let a = x;
5 + let b = a;
6 +}
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+10 -8
@@ -21,14 +21,14 @@ function foo() {
21
22 ```
23 bb0:
24 - [1] Let mutate x$7_@0[1:14] = 1
24 + [1] Let mutate x$7_@0[1:13] = 1
25 [2] Const mutate y$8_@1 = 2
26 [3] Const mutate $9_@2 = 2
27 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2
28 [5] If (read $10_@3) then:bb2 else:bb1 fallthrough=bb1
29 bb2:
30 predecessor blocks: bb0
31 - [6] Reassign mutate x$7_@0[1:14] = 3
31 + [6] Reassign mutate x$7_@0[1:13] = 3
32 [7] Goto bb1
33 bb1:
34 predecessor blocks: bb2 bb0
@@ -37,11 +37,11 @@ bb1:
37 [10] If (read $14_@5) then:bb4 else:bb3 fallthrough=bb3
38 bb4:
39 predecessor blocks: bb1
40 - [11] Reassign mutate x$7_@0[1:14] = 5
40 + [11] Reassign mutate x$7_@0[1:13] = 5
41 [12] Goto bb3
42 bb3:
43 predecessor blocks: bb4 bb1
44 - [13] Const mutate y$18_@0[1:14] = read x$7_@0
44 + [13] Const mutate y$18_@6 = read x$7_@0
45 [14] Return
46 scope3 [4:5]:
47 - read y$8_@1
@@ -49,6 +49,8 @@ scope3 [4:5]:
49 scope5 [9:10]:
50 - read y$8_@1
51 - read $12_@4
52 +scope6 [13:14]:
53 + - read x$7_@0
54 ```
55
56 ### CFG
@@ -58,7 +60,7 @@ flowchart TB
60 %% Basic Blocks
61 subgraph bb0
62 bb0_instrs["
61 - [1] Let mutate x$7_@0[1:14] = 1
63 + [1] Let mutate x$7_@0[1:13] = 1
64 [2] Const mutate y$8_@1 = 2
65 [3] Const mutate $9_@2 = 2
66 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2
@@ -67,7 +69,7 @@ flowchart TB
69 end
70 subgraph bb2
71 bb2_instrs["
70 - [6] Reassign mutate x$7_@0[1:14] = 3
72 + [6] Reassign mutate x$7_@0[1:13] = 3
73 "]
74 bb2_instrs --> bb2_terminal(["Goto"])
75 end
@@ -80,13 +82,13 @@ flowchart TB
82 end
83 subgraph bb4
84 bb4_instrs["
83 - [11] Reassign mutate x$7_@0[1:14] = 5
85 + [11] Reassign mutate x$7_@0[1:13] = 5
86 "]
87 bb4_instrs --> bb4_terminal(["Goto"])
88 end
89 subgraph bb3
90 bb3_instrs["
89 - [13] Const mutate y$18_@0[1:14] = read x$7_@0
91 + [13] Const mutate y$18_@6 = read x$7_@0
92 "]
93 bb3_instrs --> bb3_terminal(["Return"])
94 end
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+8 -6
@@ -18,22 +18,24 @@ function foo() {
18
19 ```
20 bb0:
21 - [1] Let mutate x$5_@0[1:9] = 1
21 + [1] Let mutate x$5_@0[1:8] = 1
22 [2] Const mutate y$6_@1 = 2
23 [3] Const mutate $7_@2 = 2
24 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2
25 [5] If (read $8_@3) then:bb2 else:bb1 fallthrough=bb1
26 bb2:
27 predecessor blocks: bb0
28 - [6] Reassign mutate x$5_@0[1:9] = 3
28 + [6] Reassign mutate x$5_@0[1:8] = 3
29 [7] Goto bb1
30 bb1:
31 predecessor blocks: bb2 bb0
32 - [8] Const mutate y$11_@0[1:9] = read x$5_@0
32 + [8] Const mutate y$11_@4 = read x$5_@0
33 [9] Return
34 scope3 [4:5]:
35 - read y$6_@1
36 - read $7_@2
37 +scope4 [8:9]:
38 + - read x$5_@0
39 ```
40
41 ### CFG
@@ -43,7 +45,7 @@ flowchart TB
45 %% Basic Blocks
46 subgraph bb0
47 bb0_instrs["
46 - [1] Let mutate x$5_@0[1:9] = 1
48 + [1] Let mutate x$5_@0[1:8] = 1
49 [2] Const mutate y$6_@1 = 2
50 [3] Const mutate $7_@2 = 2
51 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2
@@ -52,13 +54,13 @@ flowchart TB
54 end
55 subgraph bb2
56 bb2_instrs["
55 - [6] Reassign mutate x$5_@0[1:9] = 3
57 + [6] Reassign mutate x$5_@0[1:8] = 3
58 "]
59 bb2_instrs --> bb2_terminal(["Goto"])
60 end
61 subgraph bb1
62 bb1_instrs["
61 - [8] Const mutate y$11_@0[1:9] = read x$5_@0
63 + [8] Const mutate y$11_@4 = read x$5_@0
64 "]
65 bb1_instrs --> bb1_terminal(["Return"])
66 end
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+11 -9
@@ -23,25 +23,27 @@ bb0:
23 [1] Const mutate y$5_@0 = 2
24 [2] Const mutate $6_@1 = 1
25 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1
26 - [4] Let mutate y$8_@3[4:10] = undefined
26 + [4] Let mutate y$8_@3[4:9] = undefined
27 [4] If (read $7_@2) then:bb2 else:bb3 fallthrough=bb1
28 bb2:
29 predecessor blocks: bb0
30 - [5] Reassign mutate y$8_@3[4:10] = 1
30 + [5] Reassign mutate y$8_@3[4:9] = 1
31 [6] Goto bb1
32 bb3:
33 predecessor blocks: bb0
34 - [7] Reassign mutate y$8_@3[4:10] = 2
34 + [7] Reassign mutate y$8_@3[4:9] = 2
35 [8] Goto bb1
36 bb1:
37 predecessor blocks: bb2 bb3
38 - [9] Const mutate x$11_@3[4:10] = read y$8_@3
38 + [9] Const mutate x$11_@4 = read y$8_@3
39 [10] Return
40 scope2 [3:4]:
41 - read y$5_@0
42 - read $6_@1
43 -scope3 [4:10]:
43 +scope3 [4:9]:
44 - read $7_@2
45 +scope4 [9:10]:
46 + - read y$8_@3
47 ```
48
49 ### CFG
@@ -54,25 +56,25 @@ flowchart TB
56 [1] Const mutate y$5_@0 = 2
57 [2] Const mutate $6_@1 = 1
58 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1
57 - [4] Let mutate y$8_@3[4:10] = undefined
59 + [4] Let mutate y$8_@3[4:9] = undefined
60 "]
61 bb0_instrs --> bb0_terminal(["If (read $7_@2)"])
62 end
63 subgraph bb2
64 bb2_instrs["
63 - [5] Reassign mutate y$8_@3[4:10] = 1
65 + [5] Reassign mutate y$8_@3[4:9] = 1
66 "]
67 bb2_instrs --> bb2_terminal(["Goto"])
68 end
69 subgraph bb3
70 bb3_instrs["
69 - [7] Reassign mutate y$8_@3[4:10] = 2
71 + [7] Reassign mutate y$8_@3[4:9] = 2
72 "]
73 bb3_instrs --> bb3_terminal(["Goto"])
74 end
75 subgraph bb1
76 bb1_instrs["
75 - [9] Const mutate x$11_@3[4:10] = read y$8_@3
77 + [9] Const mutate x$11_@4 = read y$8_@3
78 "]
79 bb1_instrs --> bb1_terminal(["Return"])
80 end
compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md
+13 -11
@@ -33,7 +33,7 @@ bb0:
33 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1
34 [4] Const mutate $13_@3 = 1
35 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3
36 - [6] Let mutate x$16_@5[6:17] = undefined
36 + [6] Let mutate x$16_@5[6:16] = undefined
37 [6] Switch (read x$10_@0)
38 Case read $14_@4: bb5
39 Case read $12_@2: bb3
@@ -42,21 +42,21 @@ bb0:
42 bb5:
43 predecessor blocks: bb0
44 [7] Const mutate $15_@6 = 1
45 - [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6
45 + [8] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $15_@6
46 [9] Goto bb1
47 bb3:
48 predecessor blocks: bb0
49 [10] Const mutate $17_@7 = 2
50 - [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7
50 + [11] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $17_@7
51 [12] Goto bb1
52 bb2:
53 predecessor blocks: bb0
54 [13] Const mutate $19_@8 = 3
55 - [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8
55 + [14] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $19_@8
56 [15] Goto bb1
57 bb1:
58 predecessor blocks: bb5 bb3 bb2
59 - [16] Const mutate y$22_@5[6:17] = read x$16_@5
59 + [16] Const mutate y$22_@9 = read x$16_@5
60 [17] Return
61 scope2 [3:4]:
62 - read x$10_@0
@@ -64,7 +64,7 @@ scope2 [3:4]:
64 scope4 [5:6]:
65 - read x$10_@0
66 - read $13_@3
67 -scope5 [6:17]:
67 +scope5 [6:16]:
68 - read x$10_@0
69 scope8 [13:14]:
70 - read x$10_@0
@@ -72,6 +72,8 @@ scope7 [10:11]:
72 - read x$10_@0
73 scope6 [7:8]:
74 - read x$10_@0
75 +scope9 [16:17]:
76 + - read x$16_@5
77 ```
78
79 ### CFG
@@ -86,34 +88,34 @@ flowchart TB
88 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1
89 [4] Const mutate $13_@3 = 1
90 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3
89 - [6] Let mutate x$16_@5[6:17] = undefined
91 + [6] Let mutate x$16_@5[6:16] = undefined
92 "]
93 bb0_instrs --> bb0_terminal(["Switch (read x$10_@0)"])
94 end
95 subgraph bb5
96 bb5_instrs["
97 [7] Const mutate $15_@6 = 1
96 - [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6
98 + [8] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $15_@6
99 "]
100 bb5_instrs --> bb5_terminal(["Goto"])
101 end
102 subgraph bb3
103 bb3_instrs["
104 [10] Const mutate $17_@7 = 2
103 - [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7
105 + [11] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $17_@7
106 "]
107 bb3_instrs --> bb3_terminal(["Goto"])
108 end
109 subgraph bb2
110 bb2_instrs["
111 [13] Const mutate $19_@8 = 3
110 - [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8
112 + [14] Reassign mutate x$16_@5[6:16] = Binary read x$10_@0 + read $19_@8
113 "]
114 bb2_instrs --> bb2_terminal(["Goto"])
115 end
116 subgraph bb1
117 bb1_instrs["
116 - [16] Const mutate y$22_@5[6:17] = read x$16_@5
118 + [16] Const mutate y$22_@9 = read x$16_@5
119 "]
120 bb1_instrs --> bb1_terminal(["Return"])
121 end
compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md
+37 -37
@@ -32,44 +32,44 @@ function Component(props) {
32
33 ```
34 bb0:
35 - [1] Const mutate x$10_@0[1:12] = Array []
36 - [2] Let mutate y$11_@0[1:12] = undefined
37 - [3] Const mutate $12_@1 = false
38 - [4] Const mutate $13_@2 = true
39 - [5] Const mutate $14_@3 = 1
35 + [1] Const mutate x$10_@1[1:12] = Array []
36 + [2] Let mutate y$11_@1[1:12] = undefined
37 + [3] Const mutate $12_@2 = false
38 + [4] Const mutate $13_@3 = true
39 + [5] Const mutate $14_@4 = 1
40 [6] Switch (read props$9.p0)
41 - Case read $14_@3: bb1
42 - Case read $13_@2: bb6
41 + Case read $14_@4: bb1
42 + Case read $13_@3: bb6
43 Default: bb1
44 - Case read $12_@1: bb2
44 + Case read $12_@2: bb2
45 Fallthrough: bb1
46 bb6:
47 predecessor blocks: bb0
48 - [7] Call mutate x$10_@0.push(read props$9.p2)
49 - [8] Reassign mutate y$11_@0[1:12] = Array []
48 + [7] Call mutate x$10_@1.push(read props$9.p2)
49 + [8] Reassign mutate y$11_@1[1:12] = Array []
50 [9] Goto bb1
51 bb2:
52 predecessor blocks: bb0
53 - [10] Reassign mutate y$11_@0[1:12] = read x$10_@0
53 + [10] Reassign mutate y$11_@1[1:12] = read x$10_@1
54 [11] Goto bb1
55 bb1:
56 predecessor blocks: bb0 bb6 bb2
57 - [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$10_@0} ></read Component$0>
58 - [13] Call read y$11_@0.push(read props$9.p4)
59 - [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$11_@0} >{read child$19_@4}</read Component$0>
60 - [15] Return read $22_@5
61 -scope0 [1:12]:
57 + [12] Const mutate child$19_@5 = JSX <read Component$0 data={freeze x$10_@1} ></read Component$0>
58 + [13] Call read y$11_@1.push(read props$9.p4)
59 + [14] Const mutate $22_@6 = JSX <read Component$0 data={freeze y$11_@1} >{read child$19_@5}</read Component$0>
60 + [15] Return read $22_@6
61 +scope1 [1:12]:
62 - read props$9.p2
63 - read props$9.p0
64 -scope4 [12:13]:
64 +scope5 [12:13]:
65 - read Component$0
66 - - freeze x$10_@0
67 - - read y$11_@0.push
66 + - freeze x$10_@1
67 + - read y$11_@1.push
68 - read props$9.p4
69 -scope5 [14:15]:
69 +scope6 [14:15]:
70 - read Component$0
71 - - freeze y$11_@0
72 - - read child$19_@4
71 + - freeze y$11_@1
72 + - read child$19_@5
73 ```
74
75 ### CFG
@@ -79,41 +79,41 @@ flowchart TB
79 %% Basic Blocks
80 subgraph bb0
81 bb0_instrs["
82 - [1] Const mutate x$10_@0[1:12] = Array []
83 - [2] Let mutate y$11_@0[1:12] = undefined
84 - [3] Const mutate $12_@1 = false
85 - [4] Const mutate $13_@2 = true
86 - [5] Const mutate $14_@3 = 1
82 + [1] Const mutate x$10_@1[1:12] = Array []
83 + [2] Let mutate y$11_@1[1:12] = undefined
84 + [3] Const mutate $12_@2 = false
85 + [4] Const mutate $13_@3 = true
86 + [5] Const mutate $14_@4 = 1
87 "]
88 bb0_instrs --> bb0_terminal(["Switch (read props$9.p0)"])
89 end
90 subgraph bb6
91 bb6_instrs["
92 - [7] Call mutate x$10_@0.push(read props$9.p2)
93 - [8] Reassign mutate y$11_@0[1:12] = Array []
92 + [7] Call mutate x$10_@1.push(read props$9.p2)
93 + [8] Reassign mutate y$11_@1[1:12] = Array []
94 "]
95 bb6_instrs --> bb6_terminal(["Goto"])
96 end
97 subgraph bb2
98 bb2_instrs["
99 - [10] Reassign mutate y$11_@0[1:12] = read x$10_@0
99 + [10] Reassign mutate y$11_@1[1:12] = read x$10_@1
100 "]
101 bb2_instrs --> bb2_terminal(["Goto"])
102 end
103 subgraph bb1
104 bb1_instrs["
105 - [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$10_@0} ></read Component$0>
106 - [13] Call read y$11_@0.push(read props$9.p4)
107 - [14] Const mutate $22_@5 = JSX <read Component$0 data={freeze y$11_@0} >{read child$19_@4}</read Component$0>
105 + [12] Const mutate child$19_@5 = JSX <read Component$0 data={freeze x$10_@1} ></read Component$0>
106 + [13] Call read y$11_@1.push(read props$9.p4)
107 + [14] Const mutate $22_@6 = JSX <read Component$0 data={freeze y$11_@1} >{read child$19_@5}</read Component$0>
108 "]
109 - bb1_instrs --> bb1_terminal(["Return read $22_@5"])
109 + bb1_instrs --> bb1_terminal(["Return read $22_@6"])
110 end
111
112 %% Jumps
113 - bb0_terminal -- "read $14_@3" --> bb1
114 - bb0_terminal -- "read $13_@2" --> bb6
113 + bb0_terminal -- "read $14_@4" --> bb1
114 + bb0_terminal -- "read $13_@3" --> bb6
115 bb0_terminal -- "default" --> bb1
116 - bb0_terminal -- "read $12_@1" --> bb2
116 + bb0_terminal -- "read $12_@2" --> bb2
117 bb0_terminal -- "fallthrough" --> bb1
118 bb6_terminal --> bb1
119 bb2_terminal --> bb1
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
+35 -35
@@ -28,44 +28,44 @@ function Component(props) {
28
29 ```
30 bb0:
31 - [1] Const mutate x$9_@0[1:12] = Array []
32 - [2] Let mutate y$10_@0[1:12] = undefined
33 - [3] Const mutate $11_@1 = false
34 - [4] Const mutate $12_@2 = true
31 + [1] Const mutate x$9_@1[1:12] = Array []
32 + [2] Let mutate y$10_@1[1:12] = undefined
33 + [3] Const mutate $11_@2 = false
34 + [4] Const mutate $12_@3 = true
35 [5] Switch (read props$8.p0)
36 - Case read $12_@2: bb4
37 - Case read $11_@1: bb2
36 + Case read $12_@3: bb4
37 + Case read $11_@2: bb2
38 Default: bb1
39 Fallthrough: bb1
40 bb4:
41 predecessor blocks: bb0
42 - [6] Call mutate x$9_@0.push(read props$8.p2)
43 - [7] Call mutate x$9_@0.push(read props$8.p3)
44 - [8] Const mutate y$13_@3 = Array []
42 + [6] Call mutate x$9_@1.push(read props$8.p2)
43 + [7] Call mutate x$9_@1.push(read props$8.p3)
44 + [8] Const mutate y$13_@4 = Array []
45 [9] Goto bb2
46 bb2:
47 predecessor blocks: bb4 bb0
48 - [10] Reassign mutate y$10_@0[1:12] = read x$9_@0
48 + [10] Reassign mutate y$10_@1[1:12] = read x$9_@1
49 [11] Goto bb1
50 bb1:
51 predecessor blocks: bb2 bb0
52 - [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$9_@0} ></read Component$0>
53 - [13] Call read y$10_@0.push(read props$8.p4)
54 - [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$10_@0} >{read child$19_@4}</read Component$0>
55 - [15] Return read $23_@5
56 -scope0 [1:12]:
52 + [12] Const mutate child$19_@5 = JSX <read Component$0 data={freeze x$9_@1} ></read Component$0>
53 + [13] Call read y$10_@1.push(read props$8.p4)
54 + [14] Const mutate $23_@6 = JSX <read Component$0 data={read y$10_@1} >{read child$19_@5}</read Component$0>
55 + [15] Return read $23_@6
56 +scope1 [1:12]:
57 - read props$8.p2
58 - read props$8.p3
59 - read props$8.p0
60 -scope4 [12:13]:
60 +scope5 [12:13]:
61 - read Component$0
62 - - freeze x$9_@0
63 - - read y$10_@0.push
62 + - freeze x$9_@1
63 + - read y$10_@1.push
64 - read props$8.p4
65 -scope5 [14:15]:
65 +scope6 [14:15]:
66 - read Component$0
67 - - read y$10_@0
68 - - read child$19_@4
67 + - read y$10_@1
68 + - read child$19_@5
69 ```
70
71 ### CFG
@@ -75,39 +75,39 @@ flowchart TB
75 %% Basic Blocks
76 subgraph bb0
77 bb0_instrs["
78 - [1] Const mutate x$9_@0[1:12] = Array []
79 - [2] Let mutate y$10_@0[1:12] = undefined
80 - [3] Const mutate $11_@1 = false
81 - [4] Const mutate $12_@2 = true
78 + [1] Const mutate x$9_@1[1:12] = Array []
79 + [2] Let mutate y$10_@1[1:12] = undefined
80 + [3] Const mutate $11_@2 = false
81 + [4] Const mutate $12_@3 = true
82 "]
83 bb0_instrs --> bb0_terminal(["Switch (read props$8.p0)"])
84 end
85 subgraph bb4
86 bb4_instrs["
87 - [6] Call mutate x$9_@0.push(read props$8.p2)
88 - [7] Call mutate x$9_@0.push(read props$8.p3)
89 - [8] Const mutate y$13_@3 = Array []
87 + [6] Call mutate x$9_@1.push(read props$8.p2)
88 + [7] Call mutate x$9_@1.push(read props$8.p3)
89 + [8] Const mutate y$13_@4 = Array []
90 "]
91 bb4_instrs --> bb4_terminal(["Goto"])
92 end
93 subgraph bb2
94 bb2_instrs["
95 - [10] Reassign mutate y$10_@0[1:12] = read x$9_@0
95 + [10] Reassign mutate y$10_@1[1:12] = read x$9_@1
96 "]
97 bb2_instrs --> bb2_terminal(["Goto"])
98 end
99 subgraph bb1
100 bb1_instrs["
101 - [12] Const mutate child$19_@4 = JSX <read Component$0 data={freeze x$9_@0} ></read Component$0>
102 - [13] Call read y$10_@0.push(read props$8.p4)
103 - [14] Const mutate $23_@5 = JSX <read Component$0 data={read y$10_@0} >{read child$19_@4}</read Component$0>
101 + [12] Const mutate child$19_@5 = JSX <read Component$0 data={freeze x$9_@1} ></read Component$0>
102 + [13] Call read y$10_@1.push(read props$8.p4)
103 + [14] Const mutate $23_@6 = JSX <read Component$0 data={read y$10_@1} >{read child$19_@5}</read Component$0>
104 "]
105 - bb1_instrs --> bb1_terminal(["Return read $23_@5"])
105 + bb1_instrs --> bb1_terminal(["Return read $23_@6"])
106 end
107
108 %% Jumps
109 - bb0_terminal -- "read $12_@2" --> bb4
110 - bb0_terminal -- "read $11_@1" --> bb2
109 + bb0_terminal -- "read $12_@3" --> bb4
110 + bb0_terminal -- "read $11_@2" --> bb2
111 bb0_terminal -- "default" --> bb1
112 bb0_terminal -- "fallthrough" --> bb1
113 bb4_terminal --> bb2