PropagateEarlyReturns.ts — react Source File
Architecture documentation for PropagateEarlyReturns.ts, a typescript file in the react codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR adcc884e_716d_15ed_4c6a_2983e4feb77c["PropagateEarlyReturns.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> 0423f759_97e0_9101_4634_ed555abc5ca9 df6865e0_b573_e905_84d6_4eb6b419a888["HIRBuilder.ts"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> df6865e0_b573_e905_84d6_4eb6b419a888 49446ae1_b830_9411_8258_1139d21b314b["createTemporaryPlace"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> 49446ae1_b830_9411_8258_1139d21b314b dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> dc7f10c2_c914_a162_d02b_a10a15c64a5f 21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> 21609915_b03a_fd75_b58a_4cb86ef9315b af3ace55_db6d_865e_92b9_81486f6af1e7["ReactiveFunctionTransform"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> af3ace55_db6d_865e_92b9_81486f6af1e7 da7ad665_d709_433d_facd_dc3b2c4d34f5["Transformed"] adcc884e_716d_15ed_4c6a_2983e4feb77c --> da7ad665_d709_433d_facd_dc3b2c4d34f5 9dc3e5f8_0649_d981_e520_38c0ab672d18["."] adcc884e_716d_15ed_4c6a_2983e4feb77c --> 9dc3e5f8_0649_d981_e520_38c0ab672d18 2ed45bcd_6c82_3ccd_0e20_fa96b5111055[".."] adcc884e_716d_15ed_4c6a_2983e4feb77c --> 2ed45bcd_6c82_3ccd_0e20_fa96b5111055 style adcc884e_716d_15ed_4c6a_2983e4feb77c 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 {visitReactiveFunction} from '.';
import {Effect} from '..';
import {
Environment,
GeneratedSource,
InstructionKind,
ReactiveFunction,
ReactiveScope,
ReactiveScopeBlock,
ReactiveStatement,
ReactiveTerminalStatement,
makeInstructionId,
makePropertyLiteral,
promoteTemporary,
} from '../HIR';
import {createTemporaryPlace} from '../HIR/HIRBuilder';
import {EARLY_RETURN_SENTINEL} from './CodegenReactiveFunction';
import {ReactiveFunctionTransform, Transformed} from './visitors';
/**
* This pass ensures that reactive blocks honor the control flow behavior of the
* original code including early return semantics. Specifically, if a reactive
* scope early returned during the previous execution and the inputs to that block
* have not changed, then the code should early return (with the same value) again.
*
* Example:
*
* ```javascript
* let x = [];
* if (props.cond) {
* x.push(12);
* return x;
* } else {
* return foo();
* }
* ```
*
* Imagine that this code is called twice in a row with props.cond = true. Both
* times it should return the same object (===), an array `[12]`.
*
* The compilation strategy is as follows. For each top-level reactive scope
* that contains (transitively) an early return:
*
* - Label the scope
* - Synthesize a new temporary, eg `t0`, and set it as a declaration of the scope.
* This will represent the possibly-unset return value for that scope.
* - Make the first instruction of the scope the declaration of that temporary,
* assigning a sentinel value (can reuse the same symbol as we use for cache slots).
* This assignment ensures that if we don't take an early return, that the value
* is the sentinel.
* - Replace all `return` statements with:
* - An assignment of the temporary with the value being returned.
* - A `break` to the reactive scope's label.
// ... (278 more lines)
Domain
Subdomains
Functions
Classes
Types
Dependencies
Source
Frequently Asked Questions
What does PropagateEarlyReturns.ts do?
PropagateEarlyReturns.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 PropagateEarlyReturns.ts?
PropagateEarlyReturns.ts defines 1 function(s): propagateEarlyReturns.
What does PropagateEarlyReturns.ts depend on?
PropagateEarlyReturns.ts imports 9 module(s): ., .., CodegenReactiveFunction.ts, HIRBuilder.ts, ReactiveFunctionTransform, Transformed, createTemporaryPlace, index.ts, and 1 more.
Where is PropagateEarlyReturns.ts in the architecture?
PropagateEarlyReturns.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.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