DeadCodeElimination.ts — react Source File
Architecture documentation for DeadCodeElimination.ts, a typescript file in the react codebase. 8 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 12a58551_b77c_3215_7e97_0c27aabd262e["DeadCodeElimination.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 12a58551_b77c_3215_7e97_0c27aabd262e --> 0423f759_97e0_9101_4634_ed555abc5ca9 2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"] 12a58551_b77c_3215_7e97_0c27aabd262e --> 2f3caf55_cc64_415c_55dd_9771ba7dc210 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand"] 12a58551_b77c_3215_7e97_0c27aabd262e --> b2fc2985_a7ba_9865_c2a3_2a7531f27d44 f5637d03_fd91_50b8_9da7_b2a24c91bab7["eachPatternOperand"] 12a58551_b77c_3215_7e97_0c27aabd262e --> f5637d03_fd91_50b8_9da7_b2a24c91bab7 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand"] 12a58551_b77c_3215_7e97_0c27aabd262e --> 41232a25_deb6_6e83_05a8_ae9f961656f7 eb9d33f9_42c1_205c_93e6_8e1365a31839["utils.ts"] 12a58551_b77c_3215_7e97_0c27aabd262e --> eb9d33f9_42c1_205c_93e6_8e1365a31839 d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive"] 12a58551_b77c_3215_7e97_0c27aabd262e --> d7fde76c_4fd9_feb3_299b_798689f05bc6 c447b97e_0b8e_b187_e3a8_4be412d6f495["retainWhere"] 12a58551_b77c_3215_7e97_0c27aabd262e --> c447b97e_0b8e_b187_e3a8_4be412d6f495 158befb1_050c_87d2_b4ec_54305bac5a4f["OutlineJsx.ts"] 158befb1_050c_87d2_b4ec_54305bac5a4f --> 12a58551_b77c_3215_7e97_0c27aabd262e style 12a58551_b77c_3215_7e97_0c27aabd262e 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 {
BlockId,
Environment,
getHookKind,
HIRFunction,
Identifier,
IdentifierId,
Instruction,
InstructionKind,
InstructionValue,
ObjectPattern,
} from '../HIR';
import {
eachInstructionValueOperand,
eachPatternOperand,
eachTerminalOperand,
} from '../HIR/visitors';
import {assertExhaustive, retainWhere} from '../Utils/utils';
/*
* Implements dead-code elimination, eliminating instructions whose values are unused.
*
* Note that unreachable blocks are already pruned during HIR construction.
*/
export function deadCodeElimination(fn: HIRFunction): void {
/**
* Phase 1: Find/mark all referenced identifiers
* Usages may be visited AFTER declarations if there are circular phi / data dependencies
* between blocks, so we wait to sweep until after fixed point iteration is complete
*/
const state = findReferencedIdentifiers(fn);
/**
* Phase 2: Prune / sweep unreferenced identifiers and instructions
* as possible (subject to HIR structural constraints)
*/
for (const [, block] of fn.body.blocks) {
for (const phi of block.phis) {
if (!state.isIdOrNameUsed(phi.place.identifier)) {
block.phis.delete(phi);
}
}
retainWhere(block.instructions, instr =>
state.isIdOrNameUsed(instr.lvalue.identifier),
);
// Rewrite retained instructions
for (let i = 0; i < block.instructions.length; i++) {
const isBlockValue =
block.kind !== 'block' && i === block.instructions.length - 1;
if (!isBlockValue) {
rewriteInstruction(block.instructions[i], state);
}
}
// ... (367 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
Source
Frequently Asked Questions
What does DeadCodeElimination.ts do?
DeadCodeElimination.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in DeadCodeElimination.ts?
DeadCodeElimination.ts defines 6 function(s): deadCodeElimination, findBlocksWithBackEdges, findReferencedIdentifiers, hasBackEdge, pruneableValue, rewriteInstruction.
What does DeadCodeElimination.ts depend on?
DeadCodeElimination.ts imports 8 module(s): assertExhaustive, eachInstructionValueOperand, eachPatternOperand, eachTerminalOperand, index.ts, retainWhere, utils.ts, visitors.ts.
What files import DeadCodeElimination.ts?
DeadCodeElimination.ts is imported by 1 file(s): OutlineJsx.ts.
Where is DeadCodeElimination.ts in the architecture?
DeadCodeElimination.ts is located at compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts (domain: BabelCompiler, subdomain: Optimization, directory: compiler/packages/babel-plugin-react-compiler/src/Optimization).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free