Home / Function/ alignReactiveScopesToBlockScopesHIR() — react Function Reference

alignReactiveScopesToBlockScopesHIR() — react Function Reference

Architecture documentation for the alignReactiveScopesToBlockScopesHIR() function in AlignReactiveScopesToBlockScopesHIR.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  8469c07f_bb75_970a_4a16_a21afba094e1["alignReactiveScopesToBlockScopesHIR()"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086["AlignReactiveScopesToBlockScopesHIR.ts"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|defined in| 7be237a7_8abd_01cf_0fb0_fb02f23a8086
  c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"]
  c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| 8469c07f_bb75_970a_4a16_a21afba094e1
  7107ba22_4065_0956_1ec3_286f637d0d22["getPlaceScope()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 7107ba22_4065_0956_1ec3_286f637d0d22
  d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2
  68bb9114_38de_ce6e_97e1_5c50fd0acbcd["retainWhere_Set()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 68bb9114_38de_ce6e_97e1_5c50fd0acbcd
  10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 10043bf1_f7ee_9ed9_307a_fe3edfd02b09
  b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44
  41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7
  127c19ef_021e_5644_a84e_da0d0ed84999["terminalFallthrough()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 127c19ef_021e_5644_a84e_da0d0ed84999
  d737cb4c_53f4_75b4_2d58_268e2f73fde4["eachTerminalSuccessor()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| d737cb4c_53f4_75b4_2d58_268e2f73fde4
  1e59d6f3_b074_b12f_86b8_b6d2fe62021a["mapTerminalSuccessors()"]
  8469c07f_bb75_970a_4a16_a21afba094e1 -->|calls| 1e59d6f3_b074_b12f_86b8_b6d2fe62021a
  style 8469c07f_bb75_970a_4a16_a21afba094e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.ts lines 70–284

export function alignReactiveScopesToBlockScopesHIR(fn: HIRFunction): void {
  const activeBlockFallthroughRanges: Array<{
    range: InstructionRange;
    fallthrough: BlockId;
  }> = [];
  const activeScopes = new Set<ReactiveScope>();
  const seen = new Set<ReactiveScope>();
  const valueBlockNodes = new Map<BlockId, ValueBlockNode>();
  const placeScopes = new Map<Place, ReactiveScope>();

  function recordPlace(
    id: InstructionId,
    place: Place,
    node: ValueBlockNode | null,
  ): void {
    if (place.identifier.scope !== null) {
      placeScopes.set(place, place.identifier.scope);
    }

    const scope = getPlaceScope(id, place);
    if (scope == null) {
      return;
    }
    activeScopes.add(scope);
    node?.children.push({kind: 'scope', scope, id});

    if (seen.has(scope)) {
      return;
    }
    seen.add(scope);
    if (node != null && node.valueRange !== null) {
      scope.range.start = makeInstructionId(
        Math.min(node.valueRange.start, scope.range.start),
      );
      scope.range.end = makeInstructionId(
        Math.max(node.valueRange.end, scope.range.end),
      );
    }
  }

  for (const [, block] of fn.body.blocks) {
    const startingId = block.instructions[0]?.id ?? block.terminal.id;
    retainWhere_Set(activeScopes, scope => scope.range.end > startingId);
    const top = activeBlockFallthroughRanges.at(-1);
    if (top?.fallthrough === block.id) {
      activeBlockFallthroughRanges.pop();
      /*
       * All active scopes must have either started before or within the last
       * block-fallthrough range. In either case, they overlap this block-
       * fallthrough range and can have their ranges extended.
       */
      for (const scope of activeScopes) {
        scope.range.start = makeInstructionId(
          Math.min(scope.range.start, top.range.start),
        );
      }
    }

    const {instructions, terminal} = block;
    const node = valueBlockNodes.get(block.id) ?? null;
    for (const instr of instructions) {
      for (const lvalue of eachInstructionLValue(instr)) {
        recordPlace(instr.id, lvalue, node);
      }
      for (const operand of eachInstructionValueOperand(instr.value)) {
        recordPlace(instr.id, operand, node);
      }
    }
    for (const operand of eachTerminalOperand(terminal)) {
      recordPlace(terminal.id, operand, node);
    }

    const fallthrough = terminalFallthrough(terminal);
    if (fallthrough !== null && terminal.kind !== 'branch') {
      /*
       * Any currently active scopes that overlaps the block-fallthrough range
       * need their range extended to at least the first instruction of the
       * fallthrough
       */
      const fallthroughBlock = fn.body.blocks.get(fallthrough)!;
      const nextId =

Domain

Subdomains

Frequently Asked Questions

What does alignReactiveScopesToBlockScopesHIR() do?
alignReactiveScopesToBlockScopesHIR() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.ts.
Where is alignReactiveScopesToBlockScopesHIR() defined?
alignReactiveScopesToBlockScopesHIR() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.ts at line 70.
What does alignReactiveScopesToBlockScopesHIR() call?
alignReactiveScopesToBlockScopesHIR() calls 9 function(s): eachInstructionLValue, eachInstructionValueOperand, eachTerminalOperand, eachTerminalSuccessor, getPlaceScope, makeInstructionId, mapTerminalSuccessors, retainWhere_Set, and 1 more.
What calls alignReactiveScopesToBlockScopesHIR()?
alignReactiveScopesToBlockScopesHIR() is called by 1 function(s): runWithEnvironment.

Analyze Your Own Codebase

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

Try Supermodel Free