MergeConsecutiveBlocks traverses function expressions
Currently the process of lowering function expression bodies is deferred until AnalyzeFunctions. However, per the motivation of the previous PR, we'd like to be able to perform inference across function expression boundaries. To do that we need to use consistent identifier ids across function expression boundaries. This requires SSA conversion of function expressions at the same time as we enter SSA. To start, this PR moves MergeConsecutiveBlocks for function expressions into that phase.
Joe Savona committed
Jun 8, 2023 at 14:02 UTC
c2c221a452114a123c956ef77029f7d9071c4102
2 files changed
+6
-2
compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts
+6
@@ -31,6 +31,12 @@ import { mapOptionalFallthroughs } from "./visitors";
31
export function mergeConsecutiveBlocks(fn: HIRFunction): void {
32
const merged = new MergedBlocks();
33
for (const [, block] of fn.body.blocks) {
34
+ for (const instr of block.instructions) {
35
+ if (instr.value.kind === "FunctionExpression") {
36
+ mergeConsecutiveBlocks(instr.value.loweredFunc);
37
+ }
38
+ }
39
+
40
// Can only merge blocks with a single predecessor, can't merge
41
// value blocks
42
if (block.kind !== "block" || block.preds.size !== 1) {
compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts
-2
@@ -13,7 +13,6 @@ import {
13
Identifier,
14
isRefValueType,
15
isUseRefType,
16
- mergeConsecutiveBlocks,
16
Place,
17
ReactiveScopeDependency,
18
} from "../HIR";
@@ -90,7 +89,6 @@ export default function analyseFunctions(func: HIRFunction): void {
89
}
90
91
function lower(func: HIRFunction): void {
93
- mergeConsecutiveBlocks(func);
92
enterSSA(func);
93
eliminateRedundantPhi(func);
94
constantPropagation(func);