Home / File/ AlignReactiveScopesToBlockScopesHIR.ts — react Source File

AlignReactiveScopesToBlockScopesHIR.ts — react Source File

Architecture documentation for AlignReactiveScopesToBlockScopesHIR.ts, a typescript file in the react codebase. 18 imports, 1 dependents.

File typescript BabelCompiler Validation 18 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  7be237a7_8abd_01cf_0fb0_fb02f23a8086["AlignReactiveScopesToBlockScopesHIR.ts"]
  18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 18a78965_f593_105b_e5e8_07001321c2ec
  4a73a9b9_07eb_502f_14c1_2f045ba2666c["BlockId"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 4a73a9b9_07eb_502f_14c1_2f045ba2666c
  9241c5c1_a9a7_17bc_e41c_e967225008dd["HIRFunction"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 9241c5c1_a9a7_17bc_e41c_e967225008dd
  23767d65_9554_fcd2_f2aa_7de7634389f9["InstructionId"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 23767d65_9554_fcd2_f2aa_7de7634389f9
  60ce9143_a09b_64a1_ee02_3366e85369eb["MutableRange"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 60ce9143_a09b_64a1_ee02_3366e85369eb
  c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> c7aaa235_c19e_3530_31c2_911f38eed3e0
  ca9a6820_460e_0b15_8169_3aa4c6503770["ReactiveScope"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> ca9a6820_460e_0b15_8169_3aa4c6503770
  7107ba22_4065_0956_1ec3_286f637d0d22["getPlaceScope"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 7107ba22_4065_0956_1ec3_286f637d0d22
  d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> d0270ab6_a621_bd55_a1b9_a5cad8b406b2
  2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 2f3caf55_cc64_415c_55dd_9771ba7dc210
  10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 10043bf1_f7ee_9ed9_307a_fe3edfd02b09
  b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> b2fc2985_a7ba_9865_c2a3_2a7531f27d44
  41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 41232a25_deb6_6e83_05a8_ae9f961656f7
  1e59d6f3_b074_b12f_86b8_b6d2fe62021a["mapTerminalSuccessors"]
  7be237a7_8abd_01cf_0fb0_fb02f23a8086 --> 1e59d6f3_b074_b12f_86b8_b6d2fe62021a
  style 7be237a7_8abd_01cf_0fb0_fb02f23a8086 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {CompilerError} from '..';
import {
  BlockId,
  HIRFunction,
  InstructionId,
  MutableRange,
  Place,
  ReactiveScope,
  getPlaceScope,
  makeInstructionId,
} from '../HIR/HIR';
import {
  eachInstructionLValue,
  eachInstructionValueOperand,
  eachTerminalOperand,
  mapTerminalSuccessors,
  terminalFallthrough,
} from '../HIR/visitors';
import {retainWhere_Set} from '../Utils/utils';

type InstructionRange = MutableRange;
/*
 * Note: this is the 2nd of 4 passes that determine how to break a function into discrete
 * reactive scopes (independently memoizeable units of code):
 * 1. InferReactiveScopeVariables (on HIR) determines operands that mutate together and assigns
 *     them a unique reactive scope.
 * 2. AlignReactiveScopesToBlockScopes (this pass, on ReactiveFunction) aligns reactive scopes
 *     to block scopes.
 * 3. MergeOverlappingReactiveScopes (on ReactiveFunction) ensures that reactive scopes do not
 *     overlap, merging any such scopes.
 * 4. BuildReactiveBlocks (on ReactiveFunction) groups the statements for each scope into
 *     a ReactiveScopeBlock.
 *
 * Prior inference passes assign a reactive scope to each operand, but the ranges of these
 * scopes are based on specific instructions at arbitrary points in the control-flow graph.
 * However, to codegen blocks around the instructions in each scope, the scopes must be
 * aligned to block-scope boundaries - we can't memoize half of a loop!
 *
 * This pass updates reactive scope boundaries to align to control flow boundaries, for
 * example:
 *
 * ```javascript
 * function foo(cond, a) {
 *                     ⌵ original scope
 *                          ⌵ expanded scope
 *    const x = [];    ⌝    ⌝
 *    if (cond) {      ⎮    ⎮
 *      ...            ⎮    ⎮
 *      x.push(a);     ⌟    ⎮
 *      ...                 ⎮
 *    }                     ⌟
 * }
 * ```
// ... (262 more lines)

Domain

Subdomains

Frequently Asked Questions

What does AlignReactiveScopesToBlockScopesHIR.ts do?
AlignReactiveScopesToBlockScopesHIR.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in AlignReactiveScopesToBlockScopesHIR.ts?
AlignReactiveScopesToBlockScopesHIR.ts defines 3 function(s): _debug, _printNode, alignReactiveScopesToBlockScopesHIR.
What does AlignReactiveScopesToBlockScopesHIR.ts depend on?
AlignReactiveScopesToBlockScopesHIR.ts imports 18 module(s): .., BlockId, HIR.ts, HIRFunction, InstructionId, MutableRange, Place, ReactiveScope, and 10 more.
What files import AlignReactiveScopesToBlockScopesHIR.ts?
AlignReactiveScopesToBlockScopesHIR.ts is imported by 1 file(s): Pipeline.ts.
Where is AlignReactiveScopesToBlockScopesHIR.ts in the architecture?
AlignReactiveScopesToBlockScopesHIR.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).

Analyze Your Own Codebase

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

Try Supermodel Free