@samitouri / QOS-React / commits / c9c170b63b

[compiler] Remove phi type, infer phi.id.type

ghstack-source-id: 0c26bb224c6d5431898e683891df9b1a5c2e5b63 Pull Request resolved: https://github.com/facebook/react/pull/30795

Joe Savona committed Aug 22, 2024 at 16:52 UTC c9c170b63b086964272ea2632551b1f108c6fd56
5 files changed +3 -6
compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
-1
@@ -759,7 +759,6 @@ export type Phi = {
759 kind: 'Phi';
760 id: Identifier;
761 operands: Map<BlockId, Identifier>;
762 - type: Type;
762 };
763
764 /**
compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts
+1 -1
@@ -165,7 +165,7 @@ export function printPhi(phi: Phi): string {
165 const items = [];
166 items.push(printIdentifier(phi.id));
167 items.push(printMutableRange(phi.id));
168 - items.push(printType(phi.type));
168 + items.push(printType(phi.id.type));
169 items.push(': phi(');
170 const phis = [];
171 for (const [blockId, id] of phi.operands) {
compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts
-1
@@ -192,7 +192,6 @@ class SSABuilder {
192 kind: 'Phi',
193 id: newId,
194 operands: predDefs,
195 - type: makeType(),
195 };
196
197 block.phis.add(phi);
compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts
+2 -2
@@ -68,7 +68,7 @@ export function inferTypes(func: HIRFunction): void {
68 function apply(func: HIRFunction, unifier: Unifier): void {
69 for (const [_, block] of func.body.blocks) {
70 for (const phi of block.phis) {
71 - phi.type = unifier.get(phi.type);
71 + phi.id.type = unifier.get(phi.id.type);
72 }
73 for (const instr of block.instructions) {
74 for (const operand of eachInstructionLValue(instr)) {
@@ -126,7 +126,7 @@ function* generate(
126 const returnTypes: Array<Type> = [];
127 for (const [_, block] of func.body.blocks) {
128 for (const phi of block.phis) {
129 - yield equation(phi.type, {
129 + yield equation(phi.id.type, {
130 kind: 'Phi',
131 operands: [...phi.operands.values()].map(id => id.type),
132 });
compiler/packages/babel-plugin-react-compiler/src/TypeInference/PropagatePhiTypes.ts
-1
@@ -76,7 +76,6 @@ export function propagatePhiTypes(fn: HIRFunction): void {
76 }
77 if (type !== null) {
78 phi.id.type = type;
79 - phi.type = type;
79 propagated.add(phi.id.id);
80 }
81 }