Home / Function/ computeUnconditionalBlocks() — react Function Reference

computeUnconditionalBlocks() — react Function Reference

Architecture documentation for the computeUnconditionalBlocks() function in ComputeUnconditionalBlocks.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  cc92da6a_36c2_147e_624d_3b9a7d1999b0["computeUnconditionalBlocks()"]
  c0d1dc03_8683_01ed_b02a_b10aae366514["ComputeUnconditionalBlocks.ts"]
  cc92da6a_36c2_147e_624d_3b9a7d1999b0 -->|defined in| c0d1dc03_8683_01ed_b02a_b10aae366514
  6eadf343_46d9_d614_1b21_1060f09386fc["validateHooksUsage()"]
  6eadf343_46d9_d614_1b21_1060f09386fc -->|calls| cc92da6a_36c2_147e_624d_3b9a7d1999b0
  da2fbbff_5a50_02e1_6269_0f09c43ccbeb["validateNoSetStateInRenderImpl()"]
  da2fbbff_5a50_02e1_6269_0f09c43ccbeb -->|calls| cc92da6a_36c2_147e_624d_3b9a7d1999b0
  style cc92da6a_36c2_147e_624d_3b9a7d1999b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/ComputeUnconditionalBlocks.ts lines 16–38

export function computeUnconditionalBlocks(fn: HIRFunction): Set<BlockId> {
  // Construct the set of blocks that is always reachable from the entry block.
  const unconditionalBlocks = new Set<BlockId>();
  const dominators = computePostDominatorTree(fn, {
    /*
     * Hooks must only be in a consistent order for executions that return normally,
     * so we opt-in to viewing throw as a non-exit node.
     */
    includeThrowsAsExitNode: false,
  });
  const exit = dominators.exit;
  let current: BlockId | null = fn.body.entry;
  while (current !== null && current !== exit) {
    CompilerError.invariant(!unconditionalBlocks.has(current), {
      reason:
        'Internal error: non-terminating loop in ComputeUnconditionalBlocks',
      loc: GeneratedSource,
    });
    unconditionalBlocks.add(current);
    current = dominators.get(current);
  }
  return unconditionalBlocks;
}

Subdomains

Frequently Asked Questions

What does computeUnconditionalBlocks() do?
computeUnconditionalBlocks() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/ComputeUnconditionalBlocks.ts.
Where is computeUnconditionalBlocks() defined?
computeUnconditionalBlocks() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/ComputeUnconditionalBlocks.ts at line 16.
What calls computeUnconditionalBlocks()?
computeUnconditionalBlocks() is called by 2 function(s): validateHooksUsage, validateNoSetStateInRenderImpl.

Analyze Your Own Codebase

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

Try Supermodel Free