mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Correctly identify mutated identifiers
mutableRange.end is exclusive so account for this extra 1 instruction.
This commit is contained in:
@@ -132,7 +132,7 @@ export function inferMutableRanges(func: HIRFunction) {
|
||||
// Update mutableRange.end only if the identifiers have actually been
|
||||
// mutated.
|
||||
const haveIdentifiersBeenMutated = [...aliasSet].some(
|
||||
(id) => id.mutableRange.end > id.mutableRange.start
|
||||
(id) => id.mutableRange.end - id.mutableRange.start > 1
|
||||
);
|
||||
|
||||
if (haveIdentifiersBeenMutated) {
|
||||
|
||||
@@ -18,12 +18,14 @@ function foo(x) {}
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate a$5_@0[1:3] = Array []
|
||||
[2] Const mutate b$6_@0[1:3] = read a$5_@0
|
||||
[1] Const mutate a$5_@0 = Array []
|
||||
[2] Const mutate b$6_@1 = read a$5_@0
|
||||
[3] Call read useFreeze$3(freeze a$5_@0)
|
||||
[4] Call mutate foo$4_@1(read b$6_@0)
|
||||
[4] Call mutate foo$4_@2(read b$6_@1)
|
||||
[5] Return
|
||||
|
||||
scope1 [2:3]:
|
||||
- read a$5_@0
|
||||
- freeze a$5_@0
|
||||
```
|
||||
|
||||
### CFG
|
||||
@@ -33,10 +35,10 @@ flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate a$5_@0[1:3] = Array []
|
||||
[2] Const mutate b$6_@0[1:3] = read a$5_@0
|
||||
[1] Const mutate a$5_@0 = Array []
|
||||
[2] Const mutate b$6_@1 = read a$5_@0
|
||||
[3] Call read useFreeze$3(freeze a$5_@0)
|
||||
[4] Call mutate foo$4_@1(read b$6_@0)
|
||||
[4] Call mutate foo$4_@2(read b$6_@1)
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["Return"])
|
||||
end
|
||||
|
||||
+18
-17
@@ -27,29 +27,30 @@ function call(x) {}
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate cond$8_@0 = read props$7.cond
|
||||
[2] Const mutate x$9_@1[2:9] = read props$7.x
|
||||
[2] Const mutate x$9_@1 = read props$7.x
|
||||
[3] Let mutate a$10_@2 = undefined
|
||||
[4] If (read cond$8_@0) then:bb2 else:bb3
|
||||
bb2:
|
||||
predecessor blocks: bb0
|
||||
[5] Reassign mutate a$11_@1[2:9] = read x$9_@1
|
||||
[5] Reassign mutate a$11_@3[5:8] = read x$9_@1
|
||||
[6] Goto bb1
|
||||
bb3:
|
||||
predecessor blocks: bb0
|
||||
[7] Reassign mutate a$12_@1[2:9] = Array []
|
||||
[7] Reassign mutate a$12_@3[5:8] = Array []
|
||||
[8] Goto bb1
|
||||
bb1:
|
||||
predecessor blocks: bb2 bb3
|
||||
a$14_@1[2:9]: phi(bb2: a$11_@1, bb3: a$12_@1)
|
||||
[9] Call read useFreeze$5(freeze a$14_@1)
|
||||
[10] Call read useFreeze$5(read a$14_@1)
|
||||
[11] Call mutate call$6_@3(read a$14_@1)
|
||||
[12] Return read a$14_@1
|
||||
a$14_@3[5:8]: phi(bb2: a$11_@3, bb3: a$12_@3)
|
||||
[9] Call read useFreeze$5(freeze a$14_@3)
|
||||
[10] Call read useFreeze$5(read a$14_@3)
|
||||
[11] Call mutate call$6_@4(read a$14_@3)
|
||||
[12] Return read a$14_@3
|
||||
scope0 [1:2]:
|
||||
- read props$7.cond
|
||||
scope1 [2:9]:
|
||||
scope1 [2:3]:
|
||||
- read props$7.x
|
||||
- read cond$8_@0
|
||||
scope3 [5:8]:
|
||||
- read x$9_@1
|
||||
```
|
||||
|
||||
### CFG
|
||||
@@ -60,30 +61,30 @@ flowchart TB
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate cond$8_@0 = read props$7.cond
|
||||
[2] Const mutate x$9_@1[2:9] = read props$7.x
|
||||
[2] Const mutate x$9_@1 = read props$7.x
|
||||
[3] Let mutate a$10_@2 = undefined
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["If (read cond$8_@0)"])
|
||||
end
|
||||
subgraph bb2
|
||||
bb2_instrs["
|
||||
[5] Reassign mutate a$11_@1[2:9] = read x$9_@1
|
||||
[5] Reassign mutate a$11_@3[5:8] = read x$9_@1
|
||||
"]
|
||||
bb2_instrs --> bb2_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb3
|
||||
bb3_instrs["
|
||||
[7] Reassign mutate a$12_@1[2:9] = Array []
|
||||
[7] Reassign mutate a$12_@3[5:8] = Array []
|
||||
"]
|
||||
bb3_instrs --> bb3_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb1
|
||||
bb1_instrs["
|
||||
[9] Call read useFreeze$5(freeze a$14_@1)
|
||||
[10] Call read useFreeze$5(read a$14_@1)
|
||||
[11] Call mutate call$6_@3(read a$14_@1)
|
||||
[9] Call read useFreeze$5(freeze a$14_@3)
|
||||
[10] Call read useFreeze$5(read a$14_@3)
|
||||
[11] Call mutate call$6_@4(read a$14_@3)
|
||||
"]
|
||||
bb1_instrs --> bb1_terminal(["Return read a$14_@1"])
|
||||
bb1_instrs --> bb1_terminal(["Return read a$14_@3"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
|
||||
@@ -23,20 +23,20 @@ function g() {}
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate $5_@0[0:7] = Call mutate f$1_@0()
|
||||
[1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
|
||||
[2] If (read $5_@0) then:bb2 else:bb3
|
||||
bb2:
|
||||
predecessor blocks: bb0
|
||||
[3] Const mutate $6_@0[0:7] = Call mutate g$4_@0()
|
||||
[3] Const mutate $6_@1[0:6] = Call mutate g$4_@1()
|
||||
[4] Goto bb1
|
||||
bb3:
|
||||
predecessor blocks: bb0
|
||||
[5] Const mutate $7_@0[0:7] = read $5_@0
|
||||
[5] Const mutate $7_@1[0:6] = read $5_@0
|
||||
[6] Goto bb1
|
||||
bb1:
|
||||
predecessor blocks: bb2 bb3
|
||||
$8_@0[0:7]: phi(bb2: $6_@0, bb3: $7_@0)
|
||||
[7] Return freeze $8_@0
|
||||
$8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1)
|
||||
[7] Return freeze $8_@1
|
||||
|
||||
```
|
||||
|
||||
@@ -47,24 +47,24 @@ flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate $5_@0[0:7] = Call mutate f$1_@0()
|
||||
[1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["If (read $5_@0)"])
|
||||
end
|
||||
subgraph bb2
|
||||
bb2_instrs["
|
||||
[3] Const mutate $6_@0[0:7] = Call mutate g$4_@0()
|
||||
[3] Const mutate $6_@1[0:6] = Call mutate g$4_@1()
|
||||
"]
|
||||
bb2_instrs --> bb2_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb3
|
||||
bb3_instrs["
|
||||
[5] Const mutate $7_@0[0:7] = read $5_@0
|
||||
[5] Const mutate $7_@1[0:6] = read $5_@0
|
||||
"]
|
||||
bb3_instrs --> bb3_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb1
|
||||
bb1_terminal(["Return freeze $8_@0"])
|
||||
bb1_terminal(["Return freeze $8_@1"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
@@ -91,20 +91,20 @@ function And$0() {
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate $5_@0[0:7] = Call mutate f$1_@0()
|
||||
[1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
|
||||
[2] If (read $5_@0) then:bb2 else:bb3
|
||||
bb2:
|
||||
predecessor blocks: bb0
|
||||
[3] Const mutate $6_@0[0:7] = read $5_@0
|
||||
[3] Const mutate $6_@1[0:6] = read $5_@0
|
||||
[4] Goto bb1
|
||||
bb3:
|
||||
predecessor blocks: bb0
|
||||
[5] Const mutate $7_@0[0:7] = Call mutate g$4_@0()
|
||||
[5] Const mutate $7_@1[0:6] = Call mutate g$4_@1()
|
||||
[6] Goto bb1
|
||||
bb1:
|
||||
predecessor blocks: bb2 bb3
|
||||
$8_@0[0:7]: phi(bb2: $6_@0, bb3: $7_@0)
|
||||
[7] Return freeze $8_@0
|
||||
$8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1)
|
||||
[7] Return freeze $8_@1
|
||||
|
||||
```
|
||||
|
||||
@@ -115,24 +115,24 @@ flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate $5_@0[0:7] = Call mutate f$1_@0()
|
||||
[1] Const mutate $5_@0[0:2] = Call mutate f$1_@0()
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["If (read $5_@0)"])
|
||||
end
|
||||
subgraph bb2
|
||||
bb2_instrs["
|
||||
[3] Const mutate $6_@0[0:7] = read $5_@0
|
||||
[3] Const mutate $6_@1[0:6] = read $5_@0
|
||||
"]
|
||||
bb2_instrs --> bb2_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb3
|
||||
bb3_instrs["
|
||||
[5] Const mutate $7_@0[0:7] = Call mutate g$4_@0()
|
||||
[5] Const mutate $7_@1[0:6] = Call mutate g$4_@1()
|
||||
"]
|
||||
bb3_instrs --> bb3_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb1
|
||||
bb1_terminal(["Return freeze $8_@0"])
|
||||
bb1_terminal(["Return freeze $8_@1"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
@@ -159,23 +159,25 @@ function Or$0() {
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate $9_@0[0:9] = Call mutate f$2_@0()
|
||||
[1] Const mutate $9_@0[0:2] = Call mutate f$2_@0()
|
||||
[2] Const mutate $10_@1 = null
|
||||
[3] Const mutate $11_@0[0:9] = Binary read $9_@0 != read $10_@1
|
||||
[4] If (read $11_@0) then:bb2 else:bb3
|
||||
[3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1
|
||||
[4] If (read $11_@2) then:bb2 else:bb3
|
||||
bb2:
|
||||
predecessor blocks: bb0
|
||||
[5] Const mutate $12_@0[0:9] = read $9_@0
|
||||
[5] Const mutate $12_@3[0:8] = read $9_@0
|
||||
[6] Goto bb1
|
||||
bb3:
|
||||
predecessor blocks: bb0
|
||||
[7] Const mutate $13_@0[0:9] = Call mutate g$7_@0()
|
||||
[7] Const mutate $13_@3[0:8] = Call mutate g$7_@3()
|
||||
[8] Goto bb1
|
||||
bb1:
|
||||
predecessor blocks: bb2 bb3
|
||||
$14_@0[0:9]: phi(bb2: $12_@0, bb3: $13_@0)
|
||||
[9] Return freeze $14_@0
|
||||
|
||||
$14_@3[0:8]: phi(bb2: $12_@3, bb3: $13_@3)
|
||||
[9] Return freeze $14_@3
|
||||
scope2 [3:4]:
|
||||
- read $9_@0
|
||||
- read $10_@1
|
||||
```
|
||||
|
||||
### CFG
|
||||
@@ -185,26 +187,26 @@ flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate $9_@0[0:9] = Call mutate f$2_@0()
|
||||
[1] Const mutate $9_@0[0:2] = Call mutate f$2_@0()
|
||||
[2] Const mutate $10_@1 = null
|
||||
[3] Const mutate $11_@0[0:9] = Binary read $9_@0 != read $10_@1
|
||||
[3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["If (read $11_@0)"])
|
||||
bb0_instrs --> bb0_terminal(["If (read $11_@2)"])
|
||||
end
|
||||
subgraph bb2
|
||||
bb2_instrs["
|
||||
[5] Const mutate $12_@0[0:9] = read $9_@0
|
||||
[5] Const mutate $12_@3[0:8] = read $9_@0
|
||||
"]
|
||||
bb2_instrs --> bb2_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb3
|
||||
bb3_instrs["
|
||||
[7] Const mutate $13_@0[0:9] = Call mutate g$7_@0()
|
||||
[7] Const mutate $13_@3[0:8] = Call mutate g$7_@3()
|
||||
"]
|
||||
bb3_instrs --> bb3_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb1
|
||||
bb1_terminal(["Return freeze $14_@0"])
|
||||
bb1_terminal(["Return freeze $14_@3"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
|
||||
@@ -19,21 +19,25 @@ function foo() {
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Let mutate x$5_@0[1:8] = 1
|
||||
[1] Let mutate x$5_@0 = 1
|
||||
[2] Let mutate y$6_@1 = 2
|
||||
[3] If (read y$6_@1) then:bb2 else:bb3
|
||||
bb2:
|
||||
predecessor blocks: bb0
|
||||
[4] Let mutate z$7_@0[1:8] = Binary read x$5_@0 + read y$6_@1
|
||||
[4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
|
||||
[5] Goto bb1
|
||||
bb3:
|
||||
predecessor blocks: bb0
|
||||
[6] Let mutate z$8_@0[1:8] = read x$5_@0
|
||||
[6] Let mutate z$8_@3 = read x$5_@0
|
||||
[7] Goto bb1
|
||||
bb1:
|
||||
predecessor blocks: bb2 bb3
|
||||
[8] Return
|
||||
|
||||
scope2 [4:5]:
|
||||
- read x$5_@0
|
||||
- read y$6_@1
|
||||
scope3 [6:7]:
|
||||
- read x$5_@0
|
||||
```
|
||||
|
||||
### CFG
|
||||
@@ -43,20 +47,20 @@ flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Let mutate x$5_@0[1:8] = 1
|
||||
[1] Let mutate x$5_@0 = 1
|
||||
[2] Let mutate y$6_@1 = 2
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["If (read y$6_@1)"])
|
||||
end
|
||||
subgraph bb2
|
||||
bb2_instrs["
|
||||
[4] Let mutate z$7_@0[1:8] = Binary read x$5_@0 + read y$6_@1
|
||||
[4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1
|
||||
"]
|
||||
bb2_instrs --> bb2_terminal(["Goto"])
|
||||
end
|
||||
subgraph bb3
|
||||
bb3_instrs["
|
||||
[6] Let mutate z$8_@0[1:8] = read x$5_@0
|
||||
[6] Let mutate z$8_@3 = read x$5_@0
|
||||
"]
|
||||
bb3_instrs --> bb3_terminal(["Goto"])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user