Home / Function/ merge() — react Function Reference

merge() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  27a7c554_72a2_eec2_c309_48c8a62bd9af["merge()"]
  7f9a06c8_8e18_76fc_0edd_1f0d608aae44["InferenceState"]
  27a7c554_72a2_eec2_c309_48c8a62bd9af -->|defined in| 7f9a06c8_8e18_76fc_0edd_1f0d608aae44
  1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea["inferMutationAliasingEffects()"]
  1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 27a7c554_72a2_eec2_c309_48c8a62bd9af
  7930cad6_ab99_ae3b_5cac_03042fe5727b["merge()"]
  27a7c554_72a2_eec2_c309_48c8a62bd9af -->|calls| 7930cad6_ab99_ae3b_5cac_03042fe5727b
  2f66f475_8a8e_7610_f27b_a0bed84c1b27["mergeAbstractValues()"]
  27a7c554_72a2_eec2_c309_48c8a62bd9af -->|calls| 2f66f475_8a8e_7610_f27b_a0bed84c1b27
  style 27a7c554_72a2_eec2_c309_48c8a62bd9af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 1545–1602

  merge(other: InferenceState): InferenceState | null {
    let nextValues: Map<InstructionValue, AbstractValue> | null = null;
    let nextVariables: Map<IdentifierId, Set<InstructionValue>> | null = null;

    for (const [id, thisValue] of this.#values) {
      const otherValue = other.#values.get(id);
      if (otherValue !== undefined) {
        const mergedValue = mergeAbstractValues(thisValue, otherValue);
        if (mergedValue !== thisValue) {
          nextValues = nextValues ?? new Map(this.#values);
          nextValues.set(id, mergedValue);
        }
      }
    }
    for (const [id, otherValue] of other.#values) {
      if (this.#values.has(id)) {
        // merged above
        continue;
      }
      nextValues = nextValues ?? new Map(this.#values);
      nextValues.set(id, otherValue);
    }

    for (const [id, thisValues] of this.#variables) {
      const otherValues = other.#variables.get(id);
      if (otherValues !== undefined) {
        let mergedValues: Set<InstructionValue> | null = null;
        for (const otherValue of otherValues) {
          if (!thisValues.has(otherValue)) {
            mergedValues = mergedValues ?? new Set(thisValues);
            mergedValues.add(otherValue);
          }
        }
        if (mergedValues !== null) {
          nextVariables = nextVariables ?? new Map(this.#variables);
          nextVariables.set(id, mergedValues);
        }
      }
    }
    for (const [id, otherValues] of other.#variables) {
      if (this.#variables.has(id)) {
        continue;
      }
      nextVariables = nextVariables ?? new Map(this.#variables);
      nextVariables.set(id, new Set(otherValues));
    }

    if (nextVariables === null && nextValues === null) {
      return null;
    } else {
      return new InferenceState(
        this.env,
        this.#isFunctionExpression,
        nextValues ?? new Map(this.#values),
        nextVariables ?? new Map(this.#variables),
      );
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does merge() do?
merge() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is merge() defined?
merge() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 1545.
What does merge() call?
merge() calls 2 function(s): merge, mergeAbstractValues.
What calls merge()?
merge() is called by 1 function(s): inferMutationAliasingEffects.

Analyze Your Own Codebase

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

Try Supermodel Free