Home / Function/ computeEffectsForLegacySignature() — react Function Reference

computeEffectsForLegacySignature() — react Function Reference

Architecture documentation for the computeEffectsForLegacySignature() function in InferMutationAliasingEffects.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  fc22e84f_49a6_8d04_faba_43cbf926c0aa["computeEffectsForLegacySignature()"]
  d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629
  7cb90dd3_dbe0_0087_670d_277ddeadabfc["applyEffect()"]
  7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| fc22e84f_49a6_8d04_faba_43cbf926c0aa
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab
  02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69
  e29ee9ee_fc58_c34d_6913_1e7baa76e702["conditionallyMutateIterator()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| e29ee9ee_fc58_c34d_6913_1e7baa76e702
  10386ad8_f999_3e46_b390_aba6afce2aec["areArgumentsImmutableAndNonMutating()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| 10386ad8_f999_3e46_b390_aba6afce2aec
  f255dd41_8c48_19a9_1bcc_8efd2d663f32["applySignature()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| f255dd41_8c48_19a9_1bcc_8efd2d663f32
  e1fecb5e_21c7_c2f3_65f9_02c98934dd77["getArgumentEffect()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| e1fecb5e_21c7_c2f3_65f9_02c98934dd77
  53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb
  style fc22e84f_49a6_8d04_faba_43cbf926c0aa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 2316–2498

function computeEffectsForLegacySignature(
  state: InferenceState,
  signature: FunctionSignature,
  lvalue: Place,
  receiver: Place,
  args: Array<Place | SpreadPattern | Hole>,
  loc: SourceLocation,
): Array<AliasingEffect> {
  const returnValueReason = signature.returnValueReason ?? ValueReason.Other;
  const effects: Array<AliasingEffect> = [];
  effects.push({
    kind: 'Create',
    into: lvalue,
    value: signature.returnValueKind,
    reason: returnValueReason,
  });
  if (signature.impure && state.env.config.validateNoImpureFunctionsInRender) {
    effects.push({
      kind: 'Impure',
      place: receiver,
      error: CompilerDiagnostic.create({
        category: ErrorCategory.Purity,
        reason: 'Cannot call impure function during render',
        description:
          (signature.canonicalName != null
            ? `\`${signature.canonicalName}\` is an impure function. `
            : '') +
          'Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)',
      }).withDetails({
        kind: 'error',
        loc,
        message: 'Cannot call impure function',
      }),
    });
  }
  if (signature.knownIncompatible != null && state.env.enableValidations) {
    const errors = new CompilerError();
    errors.pushDiagnostic(
      CompilerDiagnostic.create({
        category: ErrorCategory.IncompatibleLibrary,
        reason: 'Use of incompatible library',
        description: [
          'This API returns functions which cannot be memoized without leading to stale UI. ' +
            'To prevent this, by default React Compiler will skip memoizing this component/hook. ' +
            'However, you may see issues if values from this API are passed to other components/hooks that are ' +
            'memoized',
        ].join(''),
      }).withDetails({
        kind: 'error',
        loc: receiver.loc,
        message: signature.knownIncompatible,
      }),
    );
    throw errors;
  }
  const stores: Array<Place> = [];
  const captures: Array<Place> = [];
  function visit(place: Place, effect: Effect): void {
    switch (effect) {
      case Effect.Store: {
        effects.push({
          kind: 'Mutate',
          value: place,
        });
        stores.push(place);
        break;
      }
      case Effect.Capture: {
        captures.push(place);
        break;
      }
      case Effect.ConditionallyMutate: {
        effects.push({
          kind: 'MutateTransitiveConditionally',
          value: place,
        });
        break;
      }
      case Effect.ConditionallyMutateIterator: {
        const mutateIterator = conditionallyMutateIterator(place);
        if (mutateIterator != null) {

Domain

Subdomains

Called By

Frequently Asked Questions

What does computeEffectsForLegacySignature() do?
computeEffectsForLegacySignature() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is computeEffectsForLegacySignature() defined?
computeEffectsForLegacySignature() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 2316.
What does computeEffectsForLegacySignature() call?
computeEffectsForLegacySignature() calls 8 function(s): applySignature, areArgumentsImmutableAndNonMutating, conditionallyMutateIterator, create, getArgumentEffect, push, pushDiagnostic, withDetails.
What calls computeEffectsForLegacySignature()?
computeEffectsForLegacySignature() is called by 1 function(s): applyEffect.

Analyze Your Own Codebase

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

Try Supermodel Free