ConstantPropagation.ts — react Source File
Architecture documentation for ConstantPropagation.ts, a typescript file in the react codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ee83ff7b_e532_0fd6_0eae_7fe885ffe129["ConstantPropagation.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> e96f281e_f381_272d_2359_3e6a091c9a1d e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> e51fd0d2_bb38_cc97_7763_efe37f300a47 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> 0423f759_97e0_9101_4634_ed555abc5ca9 df6865e0_b573_e905_84d6_4eb6b419a888["HIRBuilder.ts"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> df6865e0_b573_e905_84d6_4eb6b419a888 ba25d103_adb3_8e17_0348_cdf4b23496b5["removeDeadDoWhileStatements"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> ba25d103_adb3_8e17_0348_cdf4b23496b5 c678dac0_f0b5_fd43_e8fe_97067c37de7d["removeUnnecessaryTryCatch"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> c678dac0_f0b5_fd43_e8fe_97067c37de7d 4fd451a9_a7fd_9520_07fd_783e18d24c84["removeUnreachableForUpdates"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> 4fd451a9_a7fd_9520_07fd_783e18d24c84 d2425665_ca9d_6abf_459e_d86a6540ef14["index.ts"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> d2425665_ca9d_6abf_459e_d86a6540ef14 52e3d8d7_abf4_7343_1f98_3f701ec04082["types"] ee83ff7b_e532_0fd6_0eae_7fe885ffe129 --> 52e3d8d7_abf4_7343_1f98_3f701ec04082 style ee83ff7b_e532_0fd6_0eae_7fe885ffe129 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 {isValidIdentifier} from '@babel/types';
import {CompilerError} from '../CompilerError';
import {
GeneratedSource,
GotoVariant,
HIRFunction,
IdentifierId,
Instruction,
InstructionValue,
LoadGlobal,
Phi,
Place,
Primitive,
assertConsistentIdentifiers,
assertTerminalSuccessorsExist,
makePropertyLiteral,
markInstructionIds,
markPredecessors,
mergeConsecutiveBlocks,
reversePostorderBlocks,
} from '../HIR';
import {
removeDeadDoWhileStatements,
removeUnnecessaryTryCatch,
removeUnreachableForUpdates,
} from '../HIR/HIRBuilder';
import {eliminateRedundantPhi} from '../SSA';
/*
* Applies constant propagation/folding to the given function. The approach is
* [Sparse Conditional Constant Propagation](https://en.wikipedia.org/wiki/Sparse_conditional_constant_propagation):
* we use abstract interpretation to record known constant values for identifiers,
* with lack of a value indicating that the identifier does not have a
* known constant value.
*
* Instructions which can be compile-time evaluated *and* whose operands are known constants
* are replaced with the resulting constant value. For example a BinaryExpression
* where the left value is known to be `1` and the right value is known to be `2`
* can be replaced with a `Constant 3` instruction.
*
* This pass also exploits the use of SSA form, tracking the constant values of
* local variables. For example, in `let x = 4; let y = x + 1` we know that
* `x = 4` in the binary expression and can replace the binary expression with
* `Constant 5`.
*
* This pass also visits conditionals (currently only IfTerminal) and can prune
* unreachable branches when the condition is a known truthy/falsey constant. The
* pass uses fixpoint iteration, looping until no additional updates can be
* performed. This allows the compiler to find cases where once one conditional is pruned,
* other values become constant, allowing subsequent conditionals to be pruned and so on.
*/
export function constantPropagation(fn: HIRFunction): void {
const constants: Constants = new Map();
// ... (567 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does ConstantPropagation.ts do?
ConstantPropagation.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 ConstantPropagation.ts?
ConstantPropagation.ts defines 6 function(s): applyConstantPropagation, constantPropagation, constantPropagationImpl, evaluateInstruction, evaluatePhi, read.
What does ConstantPropagation.ts depend on?
ConstantPropagation.ts imports 9 module(s): CompilerError, CompilerError.ts, HIRBuilder.ts, index.ts, index.ts, removeDeadDoWhileStatements, removeUnnecessaryTryCatch, removeUnreachableForUpdates, and 1 more.
Where is ConstantPropagation.ts in the architecture?
ConstantPropagation.ts is located at compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.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