mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Run mutable range analysis for aliases to fix point
This commit is contained in:
@@ -83,4 +83,8 @@ export default class DisjointSet<T> {
|
||||
fn(item, group);
|
||||
}
|
||||
}
|
||||
|
||||
get size(): number {
|
||||
return this.#entries.size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,20 @@ import { inferMutableLifetimes } from "./InferMutableLifetimes";
|
||||
import { inferMutableRangesForAlias } from "./InferMutableRangesForAlias";
|
||||
|
||||
export function inferMutableRanges(ir: HIRFunction) {
|
||||
// Calculate aliases
|
||||
const aliases = inferAliases(ir);
|
||||
|
||||
// Infer mutable ranges for non fields
|
||||
inferMutableLifetimes(ir, false);
|
||||
|
||||
// Infer mutable ranges for aliases that are not fields
|
||||
inferMutableRangesForAlias(aliases);
|
||||
// Calculate aliases
|
||||
const aliases = inferAliases(ir);
|
||||
let size = aliases.size;
|
||||
do {
|
||||
size = aliases.size;
|
||||
// Infer mutable ranges for aliases that are not fields
|
||||
inferMutableRangesForAlias(aliases);
|
||||
|
||||
// Update aliasing information of fields
|
||||
inferAliasForFields(ir, aliases);
|
||||
// Update aliasing information of fields
|
||||
inferAliasForFields(ir, aliases);
|
||||
} while (aliases.size > size);
|
||||
|
||||
// Re-infer mutable ranges for all values
|
||||
inferMutableLifetimes(ir, true);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component() {
|
||||
let z = [];
|
||||
let y = {};
|
||||
y.z = z;
|
||||
let x = {};
|
||||
x.y = y;
|
||||
mutate(x.y.z);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## HIR
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate z$5_@0[0:7] = Array []
|
||||
[2] Const mutate y$6_@0[0:7] = Object { }
|
||||
[3] Reassign mutate y$6_@0.z[0:7] = read z$5_@0
|
||||
[4] Const mutate x$7_@0[0:7] = Object { }
|
||||
[5] Reassign mutate x$7_@0.y[0:7] = read y$6_@0
|
||||
[6] Call mutate mutate$4_@0(mutate x$7_@0.y.z)
|
||||
[7] Return
|
||||
|
||||
```
|
||||
|
||||
### CFG
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate z$5_@0[0:7] = Array []
|
||||
[2] Const mutate y$6_@0[0:7] = Object { }
|
||||
[3] Reassign mutate y$6_@0.z[0:7] = read z$5_@0
|
||||
[4] Const mutate x$7_@0[0:7] = Object { }
|
||||
[5] Reassign mutate x$7_@0.y[0:7] = read y$6_@0
|
||||
[6] Call mutate mutate$4_@0(mutate x$7_@0.y.z)
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["Return"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
%% empty
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component$0() {
|
||||
const z$5 = [];
|
||||
const y$6 = {};
|
||||
y$6.z = z$5;
|
||||
const x$7 = {};
|
||||
x$7.y = y$6;
|
||||
mutate$4(x$7.y.z);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
function component() {
|
||||
let z = [];
|
||||
let y = {};
|
||||
y.z = z;
|
||||
let x = {};
|
||||
x.y = y;
|
||||
mutate(x.y.z);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component() {
|
||||
let z = [];
|
||||
let y = {};
|
||||
y.z = z;
|
||||
let x = {};
|
||||
x.y = y;
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## HIR
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate z$4_@0 = Array []
|
||||
[2] Const mutate y$5_@1[2:4] = Object { }
|
||||
[3] Reassign mutate y$5_@1.z[2:4] = read z$4_@0
|
||||
[4] Const mutate x$6_@2[4:6] = Object { }
|
||||
[5] Reassign mutate x$6_@2.y[4:6] = read y$5_@1
|
||||
[6] Return freeze x$6_@2
|
||||
scope1 [2:4]:
|
||||
- dependency: read z$4_@0
|
||||
scope2 [4:6]:
|
||||
- dependency: read y$5_@1
|
||||
```
|
||||
|
||||
### CFG
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate z$4_@0 = Array []
|
||||
[2] Const mutate y$5_@1[2:4] = Object { }
|
||||
[3] Reassign mutate y$5_@1.z[2:4] = read z$4_@0
|
||||
[4] Const mutate x$6_@2[4:6] = Object { }
|
||||
[5] Reassign mutate x$6_@2.y[4:6] = read y$5_@1
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["Return freeze x$6_@2"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
%% empty
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component$0() {
|
||||
const z$4 = [];
|
||||
const y$5 = {};
|
||||
y$5.z = z$4;
|
||||
const x$6 = {};
|
||||
x$6.y = y$5;
|
||||
return x$6;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
function component() {
|
||||
let z = [];
|
||||
let y = {};
|
||||
y.z = z;
|
||||
let x = {};
|
||||
x.y = y;
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component() {
|
||||
let x = {};
|
||||
let p = {};
|
||||
let q = {};
|
||||
let y = {};
|
||||
|
||||
x.y = y;
|
||||
p.y = x.y;
|
||||
q.y = p.y;
|
||||
|
||||
mutate(q);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## HIR
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate x$6_@0[0:9] = Object { }
|
||||
[2] Const mutate p$7_@0[0:9] = Object { }
|
||||
[3] Const mutate q$8_@0[0:9] = Object { }
|
||||
[4] Const mutate y$9_@0[0:9] = Object { }
|
||||
[5] Reassign mutate x$6_@0.y[0:9] = read y$9_@0
|
||||
[6] Reassign mutate p$7_@0.y[0:9] = read x$6_@0.y
|
||||
[7] Reassign mutate q$8_@0.y[0:9] = read p$7_@0.y
|
||||
[8] Call mutate mutate$5_@0(mutate q$8_@0)
|
||||
[9] Return
|
||||
|
||||
```
|
||||
|
||||
### CFG
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
%% Basic Blocks
|
||||
subgraph bb0
|
||||
bb0_instrs["
|
||||
[1] Const mutate x$6_@0[0:9] = Object { }
|
||||
[2] Const mutate p$7_@0[0:9] = Object { }
|
||||
[3] Const mutate q$8_@0[0:9] = Object { }
|
||||
[4] Const mutate y$9_@0[0:9] = Object { }
|
||||
[5] Reassign mutate x$6_@0.y[0:9] = read y$9_@0
|
||||
[6] Reassign mutate p$7_@0.y[0:9] = read x$6_@0.y
|
||||
[7] Reassign mutate q$8_@0.y[0:9] = read p$7_@0.y
|
||||
[8] Call mutate mutate$5_@0(mutate q$8_@0)
|
||||
"]
|
||||
bb0_instrs --> bb0_terminal(["Return"])
|
||||
end
|
||||
|
||||
%% Jumps
|
||||
%% empty
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component$0() {
|
||||
const x$6 = {};
|
||||
const p$7 = {};
|
||||
const q$8 = {};
|
||||
const y$9 = {};
|
||||
x$6.y = y$9;
|
||||
p$7.y = x$6.y;
|
||||
q$8.y = p$7.y;
|
||||
mutate$5(q$8);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
function component() {
|
||||
let x = {};
|
||||
let p = {};
|
||||
let q = {};
|
||||
let y = {};
|
||||
|
||||
x.y = y;
|
||||
p.y = x.y;
|
||||
q.y = p.y;
|
||||
|
||||
mutate(q);
|
||||
}
|
||||
Reference in New Issue
Block a user