Home / Function/ findDisjointMutableValues() — react Function Reference

findDisjointMutableValues() — react Function Reference

Architecture documentation for the findDisjointMutableValues() function in InferReactiveScopeVariables.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b474edef_a60d_b132_2ae0_98f6768ec241["findDisjointMutableValues()"]
  f041318d_301f_daad_4198_91d141b3039d["InferReactiveScopeVariables.ts"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|defined in| f041318d_301f_daad_4198_91d141b3039d
  fddc4da2_1151_8052_c771_8b67085ebeca["inferReactivePlaces()"]
  fddc4da2_1151_8052_c771_8b67085ebeca -->|calls| b474edef_a60d_b132_2ae0_98f6768ec241
  956ca4bb_7b0f_7eb2_4fbb_bda123ddbc98["inferReactiveScopeVariables()"]
  956ca4bb_7b0f_7eb2_4fbb_bda123ddbc98 -->|calls| b474edef_a60d_b132_2ae0_98f6768ec241
  d17d77ab_7e43_9266_e176_75b6266f6340["has()"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|calls| d17d77ab_7e43_9266_e176_75b6266f6340
  25afae47_3217_0d09_3179_995552e8b339["mayAllocate()"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|calls| 25afae47_3217_0d09_3179_995552e8b339
  11746e9a_2fdf_98bb_bb3c_a63d8b200df2["isMutable()"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|calls| 11746e9a_2fdf_98bb_bb3c_a63d8b200df2
  f5637d03_fd91_50b8_9da7_b2a24c91bab7["eachPatternOperand()"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|calls| f5637d03_fd91_50b8_9da7_b2a24c91bab7
  ccace1c3_85b7_a05e_c2a5_7eff8b3422ed["eachInstructionOperand()"]
  b474edef_a60d_b132_2ae0_98f6768ec241 -->|calls| ccace1c3_85b7_a05e_c2a5_7eff8b3422ed
  style b474edef_a60d_b132_2ae0_98f6768ec241 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/InferReactiveScopeVariables.ts lines 272–396

export function findDisjointMutableValues(
  fn: HIRFunction,
): DisjointSet<Identifier> {
  const scopeIdentifiers = new DisjointSet<Identifier>();

  const declarations = new Map<DeclarationId, Identifier>();
  function declareIdentifier(lvalue: Place): void {
    if (!declarations.has(lvalue.identifier.declarationId)) {
      declarations.set(lvalue.identifier.declarationId, lvalue.identifier);
    }
  }

  for (const [_, block] of fn.body.blocks) {
    /*
     * If a phi is mutated after creation, then we need to alias all of its operands such that they
     * are assigned to the same scope.
     */
    for (const phi of block.phis) {
      if (
        phi.place.identifier.mutableRange.start + 1 !==
          phi.place.identifier.mutableRange.end &&
        phi.place.identifier.mutableRange.end >
          (block.instructions.at(0)?.id ?? block.terminal.id)
      ) {
        const operands = [phi.place.identifier];
        const declaration = declarations.get(
          phi.place.identifier.declarationId,
        );
        if (declaration !== undefined) {
          operands.push(declaration);
        }
        for (const [_, phiId] of phi.operands) {
          operands.push(phiId.identifier);
        }
        scopeIdentifiers.union(operands);
      } else if (fn.env.config.enableForest) {
        for (const [, phiId] of phi.operands) {
          scopeIdentifiers.union([phi.place.identifier, phiId.identifier]);
        }
      }
    }

    for (const instr of block.instructions) {
      const operands: Array<Identifier> = [];
      const range = instr.lvalue.identifier.mutableRange;
      if (range.end > range.start + 1 || mayAllocate(fn.env, instr)) {
        operands.push(instr.lvalue!.identifier);
      }
      if (
        instr.value.kind === 'DeclareLocal' ||
        instr.value.kind === 'DeclareContext'
      ) {
        declareIdentifier(instr.value.lvalue.place);
      } else if (
        instr.value.kind === 'StoreLocal' ||
        instr.value.kind === 'StoreContext'
      ) {
        declareIdentifier(instr.value.lvalue.place);
        if (
          instr.value.lvalue.place.identifier.mutableRange.end >
          instr.value.lvalue.place.identifier.mutableRange.start + 1
        ) {
          operands.push(instr.value.lvalue.place.identifier);
        }
        if (
          isMutable(instr, instr.value.value) &&
          instr.value.value.identifier.mutableRange.start > 0
        ) {
          operands.push(instr.value.value.identifier);
        }
      } else if (instr.value.kind === 'Destructure') {
        for (const place of eachPatternOperand(instr.value.lvalue.pattern)) {
          declareIdentifier(place);
          if (
            place.identifier.mutableRange.end >
            place.identifier.mutableRange.start + 1
          ) {
            operands.push(place.identifier);
          }
        }
        if (

Domain

Subdomains

Frequently Asked Questions

What does findDisjointMutableValues() do?
findDisjointMutableValues() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/InferReactiveScopeVariables.ts.
Where is findDisjointMutableValues() defined?
findDisjointMutableValues() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/InferReactiveScopeVariables.ts at line 272.
What does findDisjointMutableValues() call?
findDisjointMutableValues() calls 5 function(s): eachInstructionOperand, eachPatternOperand, has, isMutable, mayAllocate.
What calls findDisjointMutableValues()?
findDisjointMutableValues() is called by 2 function(s): inferReactivePlaces, inferReactiveScopeVariables.

Analyze Your Own Codebase

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

Try Supermodel Free