PruneTemporaryLValues.ts — react Source File
Architecture documentation for PruneTemporaryLValues.ts, a typescript file in the react codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 3d902967_8874_4cce_367f_23c9a916116a["PruneTemporaryLValues.ts"] 18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"] 3d902967_8874_4cce_367f_23c9a916116a --> 18a78965_f593_105b_e5e8_07001321c2ec bf1aef24_2e0f_0adb_12d8_9e5ba8245644["DeclarationId"] 3d902967_8874_4cce_367f_23c9a916116a --> bf1aef24_2e0f_0adb_12d8_9e5ba8245644 23767d65_9554_fcd2_f2aa_7de7634389f9["InstructionId"] 3d902967_8874_4cce_367f_23c9a916116a --> 23767d65_9554_fcd2_f2aa_7de7634389f9 c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"] 3d902967_8874_4cce_367f_23c9a916116a --> c7aaa235_c19e_3530_31c2_911f38eed3e0 c0555545_1ea3_9d37_62ad_521eafe2daa8["ReactiveFunction"] 3d902967_8874_4cce_367f_23c9a916116a --> c0555545_1ea3_9d37_62ad_521eafe2daa8 60e40c84_1324_6a2b_a7cf_f69d86f17579["ReactiveInstruction"] 3d902967_8874_4cce_367f_23c9a916116a --> 60e40c84_1324_6a2b_a7cf_f69d86f17579 21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"] 3d902967_8874_4cce_367f_23c9a916116a --> 21609915_b03a_fd75_b58a_4cb86ef9315b 171a5d22_bb6b_1c99_05a4_6ad897438a35["ReactiveFunctionVisitor"] 3d902967_8874_4cce_367f_23c9a916116a --> 171a5d22_bb6b_1c99_05a4_6ad897438a35 2435b5f8_41a6_0458_ba88_4479b965455f["visitReactiveFunction"] 3d902967_8874_4cce_367f_23c9a916116a --> 2435b5f8_41a6_0458_ba88_4479b965455f style 3d902967_8874_4cce_367f_23c9a916116a 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 {
DeclarationId,
InstructionId,
Place,
ReactiveFunction,
ReactiveInstruction,
} from '../HIR/HIR';
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
/*
* Nulls out lvalues for temporary variables that are never accessed later. This only
* nulls out the lvalue itself, it does not remove the corresponding instructions.
*/
export function pruneUnusedLValues(fn: ReactiveFunction): void {
const lvalues = new Map<DeclarationId, ReactiveInstruction>();
visitReactiveFunction(fn, new Visitor(), lvalues);
for (const [, instr] of lvalues) {
instr.lvalue = null;
}
}
/**
* This pass uses DeclarationIds because the lvalue IdentifierId of a compound expression
* (ternary, logical, optional) in ReactiveFunction may not be the same as the IdentifierId
* of the phi, and which is referenced later. Keying by DeclarationId ensures we don't
* delete lvalues for identifiers that are used.
*
* TODO LeaveSSA: once we use HIR everywhere, this can likely move back to using IdentifierId
*/
type LValues = Map<DeclarationId, ReactiveInstruction>;
class Visitor extends ReactiveFunctionVisitor<LValues> {
override visitPlace(id: InstructionId, place: Place, state: LValues): void {
state.delete(place.identifier.declarationId);
}
override visitInstruction(
instruction: ReactiveInstruction,
state: LValues,
): void {
this.traverseInstruction(instruction, state);
if (
instruction.lvalue !== null &&
instruction.lvalue.identifier.name === null
) {
state.set(instruction.lvalue.identifier.declarationId, instruction);
}
}
}
Domain
Subdomains
Functions
Classes
Types
Dependencies
Source
Frequently Asked Questions
What does PruneTemporaryLValues.ts do?
PruneTemporaryLValues.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in PruneTemporaryLValues.ts?
PruneTemporaryLValues.ts defines 1 function(s): pruneUnusedLValues.
What does PruneTemporaryLValues.ts depend on?
PruneTemporaryLValues.ts imports 9 module(s): DeclarationId, HIR.ts, InstructionId, Place, ReactiveFunction, ReactiveFunctionVisitor, ReactiveInstruction, visitReactiveFunction, and 1 more.
Where is PruneTemporaryLValues.ts in the architecture?
PruneTemporaryLValues.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneTemporaryLValues.ts (domain: BabelCompiler, subdomain: Validation, 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