Handle IIFE with logical mutated later

The previous changes mostly meant that we removed the label terminal and didn't 
have instructions for the same scope split in a way that we couldn't merge. But 
logicals were still causing a split because MergeConsecutiveScopes can't merge 
the blocks in that case. Here we move PruneUnusedLabels earlier in the pipeline 
to ensure that instructions from IIFEs have floated up to the parent block scope 
level.
This commit is contained in:
Joe Savona
2023-11-06 08:33:30 -08:00
parent e502e69b2d
commit 35fee31355
3 changed files with 68 additions and 7 deletions
@@ -210,6 +210,13 @@ function* runWithEnvironment(
value: reactiveFunction,
});
pruneUnusedLabels(reactiveFunction);
yield log({
kind: "reactive",
name: "PruneUnusedLabels",
value: reactiveFunction,
});
memoizeFbtOperandsInSameScope(reactiveFunction);
yield log({
kind: "reactive",
@@ -320,13 +327,6 @@ function* runWithEnvironment(
value: reactiveFunction,
});
pruneUnusedLabels(reactiveFunction);
yield log({
kind: "reactive",
name: "PruneUnusedLabels",
value: reactiveFunction,
});
pruneUnusedLValues(reactiveFunction);
yield log({
kind: "reactive",
@@ -0,0 +1,49 @@
## Input
```javascript
function Component(props) {
const items = (() => {
return foo() ?? [];
})();
items.push(props.a);
return items;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ a: {} }],
};
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(3);
let t10;
let items;
if ($[0] !== props.a) {
t10 = foo() ?? [];
items = t10;
items.push(props.a);
$[0] = props.a;
$[1] = items;
$[2] = t10;
} else {
items = $[1];
t10 = $[2];
}
return items;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ a: {} }],
};
```
@@ -0,0 +1,12 @@
function Component(props) {
const items = (() => {
return foo() ?? [];
})();
items.push(props.a);
return items;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ a: {} }],
};