Home / Function/ computeEffectsForSignature() — react Function Reference

computeEffectsForSignature() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f5d001aa_7d8a_3660_1e73_93f3fa2883da["computeEffectsForSignature()"]
  d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629
  7cb90dd3_dbe0_0087_670d_277ddeadabfc["applyEffect()"]
  7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| f5d001aa_7d8a_3660_1e73_93f3fa2883da
  4663af75_e270_25e3_3415_1230be609d66["getOrInsertWith()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| 4663af75_e270_25e3_3415_1230be609d66
  e29ee9ee_fc58_c34d_6913_1e7baa76e702["conditionallyMutateIterator()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| e29ee9ee_fc58_c34d_6913_1e7baa76e702
  49446ae1_b830_9411_8258_1139d21b314b["createTemporaryPlace()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| 49446ae1_b830_9411_8258_1139d21b314b
  cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64["throwTodo()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"]
  f5d001aa_7d8a_3660_1e73_93f3fa2883da -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb
  style f5d001aa_7d8a_3660_1e73_93f3fa2883da fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 2563–2756

function computeEffectsForSignature(
  env: Environment,
  signature: AliasingSignature,
  lvalue: Place,
  receiver: Place,
  args: Array<Place | SpreadPattern | Hole>,
  // Used for signatures constructed dynamically which reference context variables
  context: Array<Place> = [],
  loc: SourceLocation,
): Array<AliasingEffect> | null {
  if (
    // Not enough args
    signature.params.length > args.length ||
    // Too many args and there is no rest param to hold them
    (args.length > signature.params.length && signature.rest == null)
  ) {
    return null;
  }
  // Build substitutions
  const mutableSpreads = new Set<IdentifierId>();
  const substitutions: Map<IdentifierId, Array<Place>> = new Map();
  substitutions.set(signature.receiver, [receiver]);
  substitutions.set(signature.returns, [lvalue]);
  const params = signature.params;
  for (let i = 0; i < args.length; i++) {
    const arg = args[i];
    if (arg.kind === 'Hole') {
      continue;
    } else if (params == null || i >= params.length || arg.kind === 'Spread') {
      if (signature.rest == null) {
        return null;
      }
      const place = arg.kind === 'Identifier' ? arg : arg.place;
      getOrInsertWith(substitutions, signature.rest, () => []).push(place);

      if (arg.kind === 'Spread') {
        const mutateIterator = conditionallyMutateIterator(arg.place);
        if (mutateIterator != null) {
          mutableSpreads.add(arg.place.identifier.id);
        }
      }
    } else {
      const param = params[i];
      substitutions.set(param, [arg]);
    }
  }

  /*
   * Signatures constructed dynamically from function expressions will reference values
   * other than their receiver/args/etc. We populate the substitution table with these
   * values so that we can still exit for unpopulated substitutions
   */
  for (const operand of context) {
    substitutions.set(operand.identifier.id, [operand]);
  }

  const effects: Array<AliasingEffect> = [];
  for (const signatureTemporary of signature.temporaries) {
    const temp = createTemporaryPlace(env, receiver.loc);
    substitutions.set(signatureTemporary.identifier.id, [temp]);
  }

  // Apply substitutions
  for (const effect of signature.effects) {
    switch (effect.kind) {
      case 'MaybeAlias':
      case 'Assign':
      case 'ImmutableCapture':
      case 'Alias':
      case 'CreateFrom':
      case 'Capture': {
        const from = substitutions.get(effect.from.identifier.id) ?? [];
        const to = substitutions.get(effect.into.identifier.id) ?? [];
        for (const fromId of from) {
          for (const toId of to) {
            effects.push({
              kind: effect.kind,
              from: fromId,
              into: toId,
            });
          }

Domain

Subdomains

Called By

Frequently Asked Questions

What does computeEffectsForSignature() do?
computeEffectsForSignature() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is computeEffectsForSignature() defined?
computeEffectsForSignature() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 2563.
What does computeEffectsForSignature() call?
computeEffectsForSignature() calls 6 function(s): assertExhaustive, conditionallyMutateIterator, createTemporaryPlace, getOrInsertWith, push, throwTodo.
What calls computeEffectsForSignature()?
computeEffectsForSignature() 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