PruneInitializationDependencies.ts — react Source File
Architecture documentation for PruneInitializationDependencies.ts, a typescript file in the react codebase. 13 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 83a1c183_c297_45dd_0ea8_066d3722d763["PruneInitializationDependencies.ts"] dc42c94f_a520_5ac0_ac00_798715c0c971["CompilerError.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> dc42c94f_a520_5ac0_ac00_798715c0c971 49751b2b_1a1c_262e_844c_2007bbc5d3ec["CompilerError"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 49751b2b_1a1c_262e_844c_2007bbc5d3ec 0bb7f0b6_145c_efa4_bb9e_70549ae82bc7["index.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 0bb7f0b6_145c_efa4_bb9e_70549ae82bc7 d9b2aef1_81c1_3c22_a001_2fd7fcc95ecb["visitors.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> d9b2aef1_81c1_3c22_a001_2fd7fcc95ecb 2fb7e48b_7627_c043_05f4_4ff0df4341f4["eachCallArgument"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 2fb7e48b_7627_c043_05f4_4ff0df4341f4 9050415e_479c_c9d6_757c_555d4b4d39dc["eachInstructionLValue"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 9050415e_479c_c9d6_757c_555d4b4d39dc 633cea1f_4572_7f09_5f2b_da39de3f488c["DisjointSet.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 633cea1f_4572_7f09_5f2b_da39de3f488c dfee7a95_a87a_9424_6f30_0e9d1791153c["DisjointSet"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> dfee7a95_a87a_9424_6f30_0e9d1791153c 891d7cb3_d1f5_73c4_791e_82c06c38d73f["utils.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 891d7cb3_d1f5_73c4_791e_82c06c38d73f fdb34752_1680_a668_07f5_1b01cbfc762e["assertExhaustive"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> fdb34752_1680_a668_07f5_1b01cbfc762e 2caf683b_d6b2_db30_8018_ea841573790d["visitors.ts"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 2caf683b_d6b2_db30_8018_ea841573790d 78c3f81d_5ec3_1cfd_76fe_94c51335da65["ReactiveFunctionVisitor"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 78c3f81d_5ec3_1cfd_76fe_94c51335da65 0860478d_e397_413d_e682_fadbd09dc4fd["visitReactiveFunction"] 83a1c183_c297_45dd_0ea8_066d3722d763 --> 0860478d_e397_413d_e682_fadbd09dc4fd 4c539367_5743_c2c5_1cd4_cb3507dcd1d7["Pipeline.ts"] 4c539367_5743_c2c5_1cd4_cb3507dcd1d7 --> 83a1c183_c297_45dd_0ea8_066d3722d763 style 83a1c183_c297_45dd_0ea8_066d3722d763 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 {
Environment,
Identifier,
IdentifierId,
InstructionId,
Place,
PropertyLiteral,
ReactiveBlock,
ReactiveFunction,
ReactiveInstruction,
ReactiveScopeBlock,
ReactiveTerminalStatement,
getHookKind,
isUseRefType,
isUseStateType,
} from '../HIR';
import {eachCallArgument, eachInstructionLValue} from '../HIR/visitors';
import DisjointSet from '../Utils/DisjointSet';
import {assertExhaustive} from '../Utils/utils';
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
/**
* This pass is built based on the observation by @jbrown215 that arguments
* to useState and useRef are only used the first time a component is rendered.
* Any subsequent times, the arguments will be evaluated but ignored. In this pass,
* we use this fact to improve the output of the compiler by not recomputing values that
* are only used as arguments (or inputs to arguments to) useState and useRef.
*
* This pass isn't yet stress-tested so it's not enabled by default. It's only enabled
* to support certain debug modes that detect non-idempotent code, since non-idempotent
* code can "safely" be used if its only passed to useState and useRef. We plan to rewrite
* this pass in HIR and enable it as an optimization in the future.
*
* Algorithm:
* We take two passes over the reactive function AST. In the first pass, we gather
* aliases and build relationships between property accesses--the key thing we need
* to do here is to find that, e.g., $0.x and $1 refer to the same value if
* $1 = PropertyLoad $0.x.
*
* In the second pass, we traverse the AST in reverse order and track how each place
* is used. If a place is read from in any Terminal, we mark the place as "Update", meaning
* it is used whenever the component is updated/re-rendered. If a place is read from in
* a useState or useRef hook call, we mark it as "Create", since it is only used when the
* component is created. In other instructions, we propagate the inferred place for the
* instructions lvalues onto any other instructions that are read.
*
* Whenever we finish this reverse pass over a reactive block, we can look at the blocks
* dependencies and see whether the dependencies are used in an "Update" context or only
* in a "Create" context. If a dependency is create-only, then we can remove that dependency
* from the block.
*/
// ... (235 more lines)
Domain
Subdomains
Classes
Types
Dependencies
Source
Frequently Asked Questions
What does PruneInitializationDependencies.ts do?
PruneInitializationDependencies.ts is a source file in the react codebase, written in typescript. It belongs to the OptimizationPasses domain, ConstantPropagation subdomain.
What functions are defined in PruneInitializationDependencies.ts?
PruneInitializationDependencies.ts defines 3 function(s): getAliases, pruneInitializationDependencies, update.
What does PruneInitializationDependencies.ts depend on?
PruneInitializationDependencies.ts imports 13 module(s): CompilerError, CompilerError.ts, DisjointSet, DisjointSet.ts, ReactiveFunctionVisitor, assertExhaustive, eachCallArgument, eachInstructionLValue, and 5 more.
What files import PruneInitializationDependencies.ts?
PruneInitializationDependencies.ts is imported by 1 file(s): Pipeline.ts.
Where is PruneInitializationDependencies.ts in the architecture?
PruneInitializationDependencies.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneInitializationDependencies.ts (domain: OptimizationPasses, subdomain: ConstantPropagation, 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