validateEffect() — react Function Reference
Architecture documentation for the validateEffect() function in ValidateNoDerivedComputationsInEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD a72f7c73_27c5_90bc_40c7_fca057f06dfa["validateEffect()"] a3af5b5e_3d98_91f8_296b_f84c4c65a51c["ValidateNoDerivedComputationsInEffects.ts"] a72f7c73_27c5_90bc_40c7_fca057f06dfa -->|defined in| a3af5b5e_3d98_91f8_296b_f84c4c65a51c 1d91b2b6_6806_f495_0567_ab13bf567e33["validateNoDerivedComputationsInEffects()"] 1d91b2b6_6806_f495_0567_ab13bf567e33 -->|calls| a72f7c73_27c5_90bc_40c7_fca057f06dfa b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"] a72f7c73_27c5_90bc_40c7_fca057f06dfa -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44 073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"] a72f7c73_27c5_90bc_40c7_fca057f06dfa -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"] a72f7c73_27c5_90bc_40c7_fca057f06dfa -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7 style a72f7c73_27c5_90bc_40c7_fca057f06dfa fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts lines 105–231
function validateEffect(
effectFunction: HIRFunction,
effectDeps: Array<IdentifierId>,
errors: CompilerError,
): void {
for (const operand of effectFunction.context) {
if (isSetStateType(operand.identifier)) {
continue;
} else if (effectDeps.find(dep => dep === operand.identifier.id) != null) {
continue;
} else {
// Captured something other than the effect dep or setState
return;
}
}
for (const dep of effectDeps) {
if (
effectFunction.context.find(operand => operand.identifier.id === dep) ==
null
) {
// effect dep wasn't actually used in the function
return;
}
}
const seenBlocks: Set<BlockId> = new Set();
const values: Map<IdentifierId, Array<IdentifierId>> = new Map();
for (const dep of effectDeps) {
values.set(dep, [dep]);
}
const setStateLocations: Array<SourceLocation> = [];
for (const block of effectFunction.body.blocks.values()) {
for (const pred of block.preds) {
if (!seenBlocks.has(pred)) {
// skip if block has a back edge
return;
}
}
for (const phi of block.phis) {
const aggregateDeps: Set<IdentifierId> = new Set();
for (const operand of phi.operands.values()) {
const deps = values.get(operand.identifier.id);
if (deps != null) {
for (const dep of deps) {
aggregateDeps.add(dep);
}
}
}
if (aggregateDeps.size !== 0) {
values.set(phi.place.identifier.id, Array.from(aggregateDeps));
}
}
for (const instr of block.instructions) {
switch (instr.value.kind) {
case 'Primitive':
case 'JSXText':
case 'LoadGlobal': {
break;
}
case 'LoadLocal': {
const deps = values.get(instr.value.place.identifier.id);
if (deps != null) {
values.set(instr.lvalue.identifier.id, deps);
}
break;
}
case 'ComputedLoad':
case 'PropertyLoad':
case 'BinaryExpression':
case 'TemplateLiteral':
case 'CallExpression':
case 'MethodCall': {
const aggregateDeps: Set<IdentifierId> = new Set();
for (const operand of eachInstructionValueOperand(instr.value)) {
const deps = values.get(operand.identifier.id);
if (deps != null) {
for (const dep of deps) {
aggregateDeps.add(dep);
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does validateEffect() do?
validateEffect() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts.
Where is validateEffect() defined?
validateEffect() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts at line 105.
What does validateEffect() call?
validateEffect() calls 3 function(s): eachInstructionValueOperand, eachTerminalOperand, push.
What calls validateEffect()?
validateEffect() is called by 1 function(s): validateNoDerivedComputationsInEffects.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free