[lambdas] Track ReactiveScopeDepenency of ComputedLoad

Fixes an issue where we did not track mutations to captured computed loads in 
lambdas.
This commit is contained in:
Sathya Gunasekaran
2023-03-28 16:29:31 +01:00
parent ec0abcd643
commit e0180ce86a
9 changed files with 206 additions and 0 deletions
@@ -62,6 +62,12 @@ export default function analyseFunctions(func: HIRFunction): void {
);
break;
}
case "ComputedLoad": {
// The path is set to an empty string as the path doesn't really
// matter for a computed load.
state.declareProperty(instr.lvalue, instr.value.object, "");
break;
}
case "LoadLocal": {
if (instr.lvalue.identifier.name === null) {
state.declareTemporary(instr.lvalue, instr.value.place);
@@ -0,0 +1,39 @@
## Input
```javascript
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0][1];
})();
return y;
}
```
## Code
```javascript
function bar(a) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== a;
let y;
if (c_0) {
const x = [a];
y = {};
(function () {
y = x[0][1];
})();
$[0] = a;
$[1] = y;
} else {
y = $[1];
}
return y;
}
```
@@ -0,0 +1,9 @@
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0][1];
})();
return y;
}
@@ -0,0 +1,45 @@
## Input
```javascript
function bar(a, b) {
let x = [a, b];
let y = {};
let t = {};
(function () {
y = x[0][1];
t = x[1][0];
})();
return y;
}
```
## Code
```javascript
function bar(a, b) {
const $ = React.unstable_useMemoCache(3);
const c_0 = $[0] !== a;
const c_1 = $[1] !== b;
let y;
if (c_0 || c_1) {
const x = [a, b];
y = {};
const t = {};
(function () {
y = x[0][1];
t = x[1][0];
})();
$[0] = a;
$[1] = b;
$[2] = y;
} else {
y = $[2];
}
return y;
}
```
@@ -0,0 +1,11 @@
function bar(a, b) {
let x = [a, b];
let y = {};
let t = {};
(function () {
y = x[0][1];
t = x[1][0];
})();
return y;
}
@@ -0,0 +1,39 @@
## Input
```javascript
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0].a[1];
})();
return y;
}
```
## Code
```javascript
function bar(a) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== a;
let y;
if (c_0) {
const x = [a];
y = {};
(function () {
y = x[0].a[1];
})();
$[0] = a;
$[1] = y;
} else {
y = $[1];
}
return y;
}
```
@@ -0,0 +1,9 @@
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0].a[1];
})();
return y;
}
@@ -0,0 +1,39 @@
## Input
```javascript
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0];
})();
return y;
}
```
## Code
```javascript
function bar(a) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== a;
let y;
if (c_0) {
const x = [a];
y = {};
(function () {
y = x[0];
})();
$[0] = a;
$[1] = y;
} else {
y = $[1];
}
return y;
}
```
@@ -0,0 +1,9 @@
function bar(a) {
let x = [a];
let y = {};
(function () {
y = x[0];
})();
return y;
}