Home / Class/ HIRBuilder Class — react Architecture

HIRBuilder Class — react Architecture

Architecture documentation for the HIRBuilder class in HIRBuilder.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845["HIRBuilder"]
  df6865e0_b573_e905_84d6_4eb6b419a888["HIRBuilder.ts"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|defined in| df6865e0_b573_e905_84d6_4eb6b419a888
  04b95ed0_990c_cd06_0875_6c811d85feb6["nextIdentifierId()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 04b95ed0_990c_cd06_0875_6c811d85feb6
  56d7ae43_4be9_bce4_8d6f_835d51bc4df8["context()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 56d7ae43_4be9_bce4_8d6f_835d51bc4df8
  8bf0cecc_6952_90f3_0650_77f4e5af83a0["bindings()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 8bf0cecc_6952_90f3_0650_77f4e5af83a0
  db7298b1_363b_23b9_f286_96b0c5be5c0e["environment()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| db7298b1_363b_23b9_f286_96b0c5be5c0e
  120d83a3_3b47_09ef_b55b_3acb35934a1f["constructor()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 120d83a3_3b47_09ef_b55b_3acb35934a1f
  012a7acd_73d1_2699_77e8_481232bb47c8["currentBlockKind()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 012a7acd_73d1_2699_77e8_481232bb47c8
  53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 53244187_914c_cc90_5880_7bfc1fc9c0bb
  1d7aa375_c384_4340_37f5_155bfecb0e63["enterTryCatch()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 1d7aa375_c384_4340_37f5_155bfecb0e63
  6e09e8c4_b216_0635_0def_0235e002b844["resolveThrowHandler()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 6e09e8c4_b216_0635_0def_0235e002b844
  17407413_2252_f037_c1e8_b453546fbe66["makeTemporary()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 17407413_2252_f037_c1e8_b453546fbe66
  8aa53b05_6d81_334a_b328_32fca694c064["path()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 8aa53b05_6d81_334a_b328_32fca694c064
  c753d1dc_3d72_6c26_43d1_a3614937be80["resolveIdentifier()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| c753d1dc_3d72_6c26_43d1_a3614937be80
  4a17c055_80b4_82ac_17fb_4bf809d82c24["isContextIdentifier()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845 -->|method| 4a17c055_80b4_82ac_17fb_4bf809d82c24

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts lines 104–615

export default class HIRBuilder {
  #completed: Map<BlockId, BasicBlock> = new Map();
  #current: WipBlock;
  #entry: BlockId;
  #scopes: Array<Scope> = [];
  #context: Map<t.Identifier, SourceLocation>;
  #bindings: Bindings;
  #env: Environment;
  #exceptionHandlerStack: Array<BlockId> = [];
  errors: CompilerError = new CompilerError();
  /**
   * Traversal context: counts the number of `fbt` tag parents
   * of the current babel node.
   */
  fbtDepth: number = 0;

  get nextIdentifierId(): IdentifierId {
    return this.#env.nextIdentifierId;
  }

  get context(): Map<t.Identifier, SourceLocation> {
    return this.#context;
  }

  get bindings(): Bindings {
    return this.#bindings;
  }

  get environment(): Environment {
    return this.#env;
  }

  constructor(
    env: Environment,
    options?: {
      bindings?: Bindings | null;
      context?: Map<t.Identifier, SourceLocation>;
      entryBlockKind?: BlockKind;
    },
  ) {
    this.#env = env;
    this.#bindings = options?.bindings ?? new Map();
    this.#context = options?.context ?? new Map();
    this.#entry = makeBlockId(env.nextBlockId);
    this.#current = newBlock(this.#entry, options?.entryBlockKind ?? 'block');
  }

  currentBlockKind(): BlockKind {
    return this.#current.kind;
  }

  // Push a statement or expression onto the current block
  push(instruction: Instruction): void {
    this.#current.instructions.push(instruction);
    const exceptionHandler = this.#exceptionHandlerStack.at(-1);
    if (exceptionHandler !== undefined) {
      const continuationBlock = this.reserve(this.currentBlockKind());
      this.terminateWithContinuation(
        {
          kind: 'maybe-throw',
          continuation: continuationBlock.id,
          handler: exceptionHandler,
          id: makeInstructionId(0),
          loc: instruction.loc,
          effects: null,
        },
        continuationBlock,
      );
    }
  }

  enterTryCatch(handler: BlockId, fn: () => void): void {
    this.#exceptionHandlerStack.push(handler);
    fn();
    this.#exceptionHandlerStack.pop();
  }

  resolveThrowHandler(): BlockId | null {
    const handler = this.#exceptionHandlerStack.at(-1);
    return handler ?? null;
  }

Frequently Asked Questions

What is the HIRBuilder class?
HIRBuilder is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts.
Where is HIRBuilder defined?
HIRBuilder is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts at line 104.

Analyze Your Own Codebase

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

Try Supermodel Free