Home / File/ MergeConsecutiveBlocks.ts — react Source File

MergeConsecutiveBlocks.ts — react Source File

Architecture documentation for MergeConsecutiveBlocks.ts, a typescript file in the react codebase. 13 imports, 0 dependents.

File typescript MIRInfrastructure HIR 13 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  010bd3a7_d091_50ea_4e1f_20541d841f85["MergeConsecutiveBlocks.ts"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> e96f281e_f381_272d_2359_3e6a091c9a1d
  e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> e51fd0d2_bb38_cc97_7763_efe37f300a47
  18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 18a78965_f593_105b_e5e8_07001321c2ec
  4a73a9b9_07eb_502f_14c1_2f045ba2666c["BlockId"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 4a73a9b9_07eb_502f_14c1_2f045ba2666c
  60d25db4_8803_db04_13e8_2251272ec589["Effect"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 60d25db4_8803_db04_13e8_2251272ec589
  9241c5c1_a9a7_17bc_e41c_e967225008dd["HIRFunction"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 9241c5c1_a9a7_17bc_e41c_e967225008dd
  02d16d8e_0a17_fa6f_eeef_ee0c7d25bd36["Instruction"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 02d16d8e_0a17_fa6f_eeef_ee0c7d25bd36
  c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> c7aaa235_c19e_3530_31c2_911f38eed3e0
  df6865e0_b573_e905_84d6_4eb6b419a888["HIRBuilder.ts"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> df6865e0_b573_e905_84d6_4eb6b419a888
  6d209f7d_6d38_4dee_c66c_76af0358f508["markPredecessors"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 6d209f7d_6d38_4dee_c66c_76af0358f508
  2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 2f3caf55_cc64_415c_55dd_9771ba7dc210
  127c19ef_021e_5644_a84e_da0d0ed84999["terminalFallthrough"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> 127c19ef_021e_5644_a84e_da0d0ed84999
  d0cd56ee_e8d2_fa25_8e21_652a56c56855["terminalHasFallthrough"]
  010bd3a7_d091_50ea_4e1f_20541d841f85 --> d0cd56ee_e8d2_fa25_8e21_652a56c56855
  style 010bd3a7_d091_50ea_4e1f_20541d841f85 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 '../CompilerError';
import {
  BlockId,
  Effect,
  GeneratedSource,
  HIRFunction,
  Instruction,
  Place,
} from './HIR';
import {markPredecessors} from './HIRBuilder';
import {terminalFallthrough, terminalHasFallthrough} from './visitors';

/*
 * Merges sequences of blocks that will always execute consecutively —
 * ie where the predecessor always transfers control to the successor
 * (ie ends in a goto) and where the predecessor is the only predecessor
 * for that successor (ie, there is no other way to reach the successor).
 *
 * Note that this pass leaves value/loop blocks alone because they cannot
 * be merged without breaking the structure of the high-level terminals
 * that reference them.
 */
export function mergeConsecutiveBlocks(fn: HIRFunction): void {
  const merged = new MergedBlocks();
  const fallthroughBlocks = new Set<BlockId>();
  for (const [, block] of fn.body.blocks) {
    const fallthrough = terminalFallthrough(block.terminal);
    if (fallthrough !== null) {
      fallthroughBlocks.add(fallthrough);
    }

    for (const instr of block.instructions) {
      if (
        instr.value.kind === 'FunctionExpression' ||
        instr.value.kind === 'ObjectMethod'
      ) {
        mergeConsecutiveBlocks(instr.value.loweredFunc.func);
      }
    }

    if (
      // Can only merge blocks with a single predecessor
      block.preds.size !== 1 ||
      // Value blocks cannot merge
      block.kind !== 'block' ||
      // Merging across fallthroughs could move the predecessor out of its block scope
      fallthroughBlocks.has(block.id)
    ) {
      continue;
    }
    const originalPredecessorId = Array.from(block.preds)[0]!;
    const predecessorId = merged.get(originalPredecessorId);
    const predecessor = fn.body.blocks.get(predecessorId);
// ... (87 more lines)

Subdomains

Classes

Frequently Asked Questions

What does MergeConsecutiveBlocks.ts do?
MergeConsecutiveBlocks.ts is a source file in the react codebase, written in typescript. It belongs to the MIRInfrastructure domain, HIR subdomain.
What functions are defined in MergeConsecutiveBlocks.ts?
MergeConsecutiveBlocks.ts defines 1 function(s): mergeConsecutiveBlocks.
What does MergeConsecutiveBlocks.ts depend on?
MergeConsecutiveBlocks.ts imports 13 module(s): BlockId, CompilerError, CompilerError.ts, Effect, HIR.ts, HIRBuilder.ts, HIRFunction, Instruction, and 5 more.
Where is MergeConsecutiveBlocks.ts in the architecture?
MergeConsecutiveBlocks.ts is located at compiler/packages/babel-plugin-react-compiler/src/HIR/MergeConsecutiveBlocks.ts (domain: MIRInfrastructure, subdomain: HIR, directory: compiler/packages/babel-plugin-react-compiler/src/HIR).

Analyze Your Own Codebase

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

Try Supermodel Free