[λ] Re run SSA on function expr

Functions can capture variables declared after the definition of the function. 
This re runs SSA to map the captured identifiers to the new SSA identifiers if 
available.
This commit is contained in:
Sathya Gunasekaran
2023-01-23 13:20:33 -05:00
parent 123d024af7
commit 3927281fe4
3 changed files with 55 additions and 0 deletions
+8
View File
@@ -226,4 +226,12 @@ export default function enterSSA(func: HIRFunction) {
}
}
}
for (const [_, block] of func.body.blocks) {
for (const instr of block.instructions) {
if (instr.value.kind === "FunctionExpression") {
mapInstructionOperands(instr, (place) => builder.getPlace(place));
}
}
}
}
@@ -0,0 +1,38 @@
## Input
```javascript
function component(a) {
let y = function () {
m(x);
};
let x = { a };
m(x);
return y;
}
```
## Code
```javascript
function component(a) {
const $ = React.useMemoCache();
let y;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
y = function () {
m(x);
};
$[0] = y;
} else {
y = $[0];
}
const x = { a: a };
m(x);
return y;
}
```
@@ -0,0 +1,9 @@
function component(a) {
let y = function () {
m(x);
};
let x = { a };
m(x);
return y;
}