Home / Function/ validateNoDerivedComputationsInEffects_exp() — react Function Reference

validateNoDerivedComputationsInEffects_exp() — react Function Reference

Architecture documentation for the validateNoDerivedComputationsInEffects_exp() function in ValidateNoDerivedComputationsInEffects_exp.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f9f36408_8e51_961b_c26d_24ee285bd479["validateNoDerivedComputationsInEffects_exp()"]
  a38a9d1f_969c_8056_aa80_6cb5fedba226["ValidateNoDerivedComputationsInEffects_exp.ts"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|defined in| a38a9d1f_969c_8056_aa80_6cb5fedba226
  c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"]
  c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| f9f36408_8e51_961b_c26d_24ee285bd479
  2743f1aa_8811_26e3_a021_346fb59df244["takeSnapshot()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 2743f1aa_8811_26e3_a021_346fb59df244
  2d80e3d3_eaf3_911b_9f07_e94ea4f8013f["recordPhiDerivations()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 2d80e3d3_eaf3_911b_9f07_e94ea4f8013f
  23e95905_7740_9185_1ad6_1a529d6f88ad["recordInstructionDerivations()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 23e95905_7740_9185_1ad6_1a529d6f88ad
  c50dbb50_939e_8d12_f49a_d3815a85e074["checkForChanges()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| c50dbb50_939e_8d12_f49a_d3815a85e074
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  85e01863_7f22_28ac_88d4_1bee2b6ae4a3["snapshot()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 85e01863_7f22_28ac_88d4_1bee2b6ae4a3
  8014ef2c_7e1b_b1da_b888_615d609f3c01["validateEffect()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 8014ef2c_7e1b_b1da_b888_615d609f3c01
  531eb985_e192_f9a2_2d7b_5deeb85ba95c["asResult()"]
  f9f36408_8e51_961b_c26d_24ee285bd479 -->|calls| 531eb985_e192_f9a2_2d7b_5deeb85ba95c
  style f9f36408_8e51_961b_c26d_24ee285bd479 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts lines 183–256

export function validateNoDerivedComputationsInEffects_exp(
  fn: HIRFunction,
): Result<void, CompilerError> {
  const functions: Map<IdentifierId, FunctionExpression> = new Map();
  const candidateDependencies: Map<IdentifierId, ArrayExpression> = new Map();
  const derivationCache = new DerivationCache();
  const errors = new CompilerError();
  const effectsCache: Map<IdentifierId, EffectMetadata> = new Map();

  const setStateLoads: Map<IdentifierId, IdentifierId> = new Map();
  const setStateUsages: Map<IdentifierId, Set<SourceLocation>> = new Map();

  const context: ValidationContext = {
    functions,
    candidateDependencies,
    errors,
    derivationCache,
    effectsCache,
    setStateLoads,
    setStateUsages,
  };

  if (fn.fnType === 'Hook') {
    for (const param of fn.params) {
      if (param.kind === 'Identifier') {
        context.derivationCache.cache.set(param.identifier.id, {
          place: param,
          sourcesIds: new Set(),
          typeOfValue: 'fromProps',
          isStateSource: true,
        });
      }
    }
  } else if (fn.fnType === 'Component') {
    const props = fn.params[0];
    if (props != null && props.kind === 'Identifier') {
      context.derivationCache.cache.set(props.identifier.id, {
        place: props,
        sourcesIds: new Set(),
        typeOfValue: 'fromProps',
        isStateSource: true,
      });
    }
  }

  let isFirstPass = true;
  let iterationCount = 0;
  do {
    context.derivationCache.takeSnapshot();

    for (const block of fn.body.blocks.values()) {
      recordPhiDerivations(block, context);
      for (const instr of block.instructions) {
        recordInstructionDerivations(instr, context, isFirstPass);
      }
    }

    context.derivationCache.checkForChanges();
    isFirstPass = false;
    iterationCount++;
    CompilerError.invariant(iterationCount < MAX_FIXPOINT_ITERATIONS, {
      reason:
        '[ValidateNoDerivedComputationsInEffects] Fixpoint iteration failed to converge.',
      description: `Fixpoint iteration exceeded ${MAX_FIXPOINT_ITERATIONS} iterations while tracking derivations. This suggests a cyclic dependency in the derivation cache.`,
      loc: fn.loc,
    });
  } while (context.derivationCache.snapshot());

  for (const [, effect] of effectsCache) {
    validateEffect(effect.effect, effect.dependencies, context);
  }

  return errors.asResult();
}

Domain

Subdomains

Frequently Asked Questions

What does validateNoDerivedComputationsInEffects_exp() do?
validateNoDerivedComputationsInEffects_exp() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts.
Where is validateNoDerivedComputationsInEffects_exp() defined?
validateNoDerivedComputationsInEffects_exp() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts at line 183.
What does validateNoDerivedComputationsInEffects_exp() call?
validateNoDerivedComputationsInEffects_exp() calls 8 function(s): asResult, checkForChanges, invariant, recordInstructionDerivations, recordPhiDerivations, snapshot, takeSnapshot, validateEffect.
What calls validateNoDerivedComputationsInEffects_exp()?
validateNoDerivedComputationsInEffects_exp() is called by 1 function(s): runWithEnvironment.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free