Home / Function/ collectDependencies() — react Function Reference

collectDependencies() — react Function Reference

Architecture documentation for the collectDependencies() function in ValidateExhaustiveDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  75fd8677_19db_75c9_a011_6a3a774fa8f5["collectDependencies()"]
  fe7a7397_dddc_7222_20d4_d5b1015466f1["ValidateExhaustiveDependencies.ts"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|defined in| fe7a7397_dddc_7222_20d4_d5b1015466f1
  46f23ae0_a9cb_8a6e_401f_cd99f2f91c00["validateExhaustiveDependencies()"]
  46f23ae0_a9cb_8a6e_401f_cd99f2f91c00 -->|calls| 75fd8677_19db_75c9_a011_6a3a774fa8f5
  7eea44a9_aaa5_1ba7_f782_42d308fed0fd["findOptionalPlaces()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 7eea44a9_aaa5_1ba7_f782_42d308fed0fd
  0f1abc72_e074_1bef_6bd2_9c27c1ca2020["visitCandidateDependency()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 0f1abc72_e074_1bef_6bd2_9c27c1ca2020
  073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83
  21b1eb1e_eaf5_5238_3a24_f56eb8ef7278["eachInstructionValueLValue()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 21b1eb1e_eaf5_5238_3a24_f56eb8ef7278
  fe10d1a3_4543_7480_d548_fb8c5407eb8a["addDependency()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| fe10d1a3_4543_7480_d548_fb8c5407eb8a
  ff7b048c_7d03_6dc5_346d_49078c4cb8d3["isEffectHook()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| ff7b048c_7d03_6dc5_346d_49078c4cb8d3
  b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44
  10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 10043bf1_f7ee_9ed9_307a_fe3edfd02b09
  41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"]
  75fd8677_19db_75c9_a011_6a3a774fa8f5 -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7
  style 75fd8677_19db_75c9_a011_6a3a774fa8f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts lines 571–866

function collectDependencies(
  fn: HIRFunction,
  temporaries: Map<IdentifierId, Temporary>,
  callbacks: {
    onStartMemoize: (
      startMemo: StartMemoize,
      dependencies: Set<InferredDependency>,
      locals: Set<IdentifierId>,
    ) => void;
    onFinishMemoize: (
      finishMemo: FinishMemoize,
      dependencies: Set<InferredDependency>,
      locals: Set<IdentifierId>,
    ) => void;
    onEffect: (
      inferred: Set<InferredDependency>,
      manual: Set<InferredDependency>,
      manualMemoLoc: SourceLocation | null,
    ) => void;
  } | null,
  isFunctionExpression: boolean,
): Extract<Temporary, {kind: 'Aggregate'}> {
  const optionals = findOptionalPlaces(fn);
  if (DEBUG) {
    console.log(prettyFormat(optionals));
  }
  const locals: Set<IdentifierId> = new Set();
  if (isFunctionExpression) {
    for (const param of fn.params) {
      const place = param.kind === 'Identifier' ? param : param.place;
      locals.add(place.identifier.id);
    }
  }

  const dependencies: Set<InferredDependency> = new Set();
  function visit(place: Place): void {
    visitCandidateDependency(place, temporaries, dependencies, locals);
  }
  for (const block of fn.body.blocks.values()) {
    for (const phi of block.phis) {
      const deps: Array<InferredDependency> = [];
      for (const operand of phi.operands.values()) {
        const dep = temporaries.get(operand.identifier.id);
        if (dep == null) {
          continue;
        }
        if (dep.kind === 'Aggregate') {
          deps.push(...dep.dependencies);
        } else {
          deps.push(dep);
        }
      }
      if (deps.length === 0) {
        continue;
      } else if (deps.length === 1) {
        temporaries.set(phi.place.identifier.id, deps[0]!);
      } else {
        temporaries.set(phi.place.identifier.id, {
          kind: 'Aggregate',
          dependencies: new Set(deps),
        });
      }
    }

    for (const instr of block.instructions) {
      const {lvalue, value} = instr;
      switch (value.kind) {
        case 'LoadGlobal': {
          temporaries.set(lvalue.identifier.id, {
            kind: 'Global',
            binding: value.binding,
          });
          break;
        }
        case 'LoadContext':
        case 'LoadLocal': {
          const temp = temporaries.get(value.place.identifier.id);
          if (temp != null) {
            if (temp.kind === 'Local') {
              const local: Temporary = {...temp, loc: value.place.loc};
              temporaries.set(lvalue.identifier.id, local);

Domain

Subdomains

Frequently Asked Questions

What does collectDependencies() do?
collectDependencies() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts.
Where is collectDependencies() defined?
collectDependencies() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts at line 571.
What does collectDependencies() call?
collectDependencies() calls 9 function(s): addDependency, eachInstructionLValue, eachInstructionValueLValue, eachInstructionValueOperand, eachTerminalOperand, findOptionalPlaces, isEffectHook, push, and 1 more.
What calls collectDependencies()?
collectDependencies() is called by 1 function(s): validateExhaustiveDependencies.

Analyze Your Own Codebase

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

Try Supermodel Free