From 9e8f62cd9503461d5813b914608a8bcdf2e09d4c Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 22 Aug 2024 16:51:59 -0700 Subject: [PATCH] [compiler] Remove phi type, infer phi.id.type [ghstack-poisoned] --- compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts | 1 - .../packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts | 2 +- .../packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts | 1 - .../src/TypeInference/InferTypes.ts | 4 ++-- .../src/TypeInference/PropagatePhiTypes.ts | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts index ea121c6fcd727..06fa48a73656c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts @@ -759,7 +759,6 @@ export type Phi = { kind: 'Phi'; id: Identifier; operands: Map; - type: Type; }; /** diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts index a5ad303d7a587..8bcab1d7b25ae 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts @@ -165,7 +165,7 @@ export function printPhi(phi: Phi): string { const items = []; items.push(printIdentifier(phi.id)); items.push(printMutableRange(phi.id)); - items.push(printType(phi.type)); + items.push(printType(phi.id.type)); items.push(': phi('); const phis = []; for (const [blockId, id] of phi.operands) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts b/compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts index 7d665514f4f6e..73942769c22be 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts @@ -192,7 +192,6 @@ class SSABuilder { kind: 'Phi', id: newId, operands: predDefs, - type: makeType(), }; block.phis.add(phi); diff --git a/compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts b/compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts index d0d23f0823df8..b7a4495f1f931 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts @@ -68,7 +68,7 @@ export function inferTypes(func: HIRFunction): void { function apply(func: HIRFunction, unifier: Unifier): void { for (const [_, block] of func.body.blocks) { for (const phi of block.phis) { - phi.type = unifier.get(phi.type); + phi.id.type = unifier.get(phi.id.type); } for (const instr of block.instructions) { for (const operand of eachInstructionLValue(instr)) { @@ -126,7 +126,7 @@ function* generate( const returnTypes: Array = []; for (const [_, block] of func.body.blocks) { for (const phi of block.phis) { - yield equation(phi.type, { + yield equation(phi.id.type, { kind: 'Phi', operands: [...phi.operands.values()].map(id => id.type), }); diff --git a/compiler/packages/babel-plugin-react-compiler/src/TypeInference/PropagatePhiTypes.ts b/compiler/packages/babel-plugin-react-compiler/src/TypeInference/PropagatePhiTypes.ts index 81335c175a31b..b33c8773dc0c7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/TypeInference/PropagatePhiTypes.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/TypeInference/PropagatePhiTypes.ts @@ -76,7 +76,6 @@ export function propagatePhiTypes(fn: HIRFunction): void { } if (type !== null) { phi.id.type = type; - phi.type = type; propagated.add(phi.id.id); } }