evaluatePhi() — react Function Reference
Architecture documentation for the evaluatePhi() function in ConstantPropagation.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 9356843d_f70e_f922_5710_d8bd36a38797["evaluatePhi()"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129["ConstantPropagation.ts"] 9356843d_f70e_f922_5710_d8bd36a38797 -->|defined in| ee83ff7b_e532_0fd6_0eae_7fe885ffe129 4419ef20_4b5f_b18c_6237_57b76d298666["applyConstantPropagation()"] 4419ef20_4b5f_b18c_6237_57b76d298666 -->|calls| 9356843d_f70e_f922_5710_d8bd36a38797 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 9356843d_f70e_f922_5710_d8bd36a38797 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e style 9356843d_f70e_f922_5710_d8bd36a38797 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts lines 168–222
function evaluatePhi(phi: Phi, constants: Constants): Constant | null {
let value: Constant | null = null;
for (const [, operand] of phi.operands) {
const operandValue = constants.get(operand.identifier.id) ?? null;
// did not find a constant, can't constant propogate
if (operandValue === null) {
return null;
}
/*
* first iteration of the loop, let's store the operand and continue
* looping.
*/
if (value === null) {
value = operandValue;
continue;
}
// found different kinds of constants, can't constant propogate
if (operandValue.kind !== value.kind) {
return null;
}
switch (operandValue.kind) {
case 'Primitive': {
CompilerError.invariant(value.kind === 'Primitive', {
reason: 'value kind expected to be Primitive',
loc: GeneratedSource,
});
// different constant values, can't constant propogate
if (operandValue.value !== value.value) {
return null;
}
break;
}
case 'LoadGlobal': {
CompilerError.invariant(value.kind === 'LoadGlobal', {
reason: 'value kind expected to be LoadGlobal',
loc: GeneratedSource,
});
// different global values, can't constant propogate
if (operandValue.binding.name !== value.binding.name) {
return null;
}
break;
}
default:
return null;
}
}
return value;
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does evaluatePhi() do?
evaluatePhi() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts.
Where is evaluatePhi() defined?
evaluatePhi() is defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts at line 168.
What does evaluatePhi() call?
evaluatePhi() calls 1 function(s): invariant.
What calls evaluatePhi()?
evaluatePhi() is called by 1 function(s): applyConstantPropagation.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free