getManualMemoizationReplacement() — react Function Reference
Architecture documentation for the getManualMemoizationReplacement() function in DropManualMemoization.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 193f2943_7c23_21d6_ef25_f7950dd25d21["getManualMemoizationReplacement()"] 4b3f307b_2e5b_6c5a_0729_065bd25db103["DropManualMemoization.ts"] 193f2943_7c23_21d6_ef25_f7950dd25d21 -->|defined in| 4b3f307b_2e5b_6c5a_0729_065bd25db103 dad92af5_71c7_94b3_8cce_ac3af87f3e61["dropManualMemoization()"] dad92af5_71c7_94b3_8cce_ac3af87f3e61 -->|calls| 193f2943_7c23_21d6_ef25_f7950dd25d21 style 193f2943_7c23_21d6_ef25_f7950dd25d21 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts lines 226–288
function getManualMemoizationReplacement(
fn: Place,
loc: SourceLocation,
kind: 'useMemo' | 'useCallback',
): LoadLocal | CallExpression {
if (kind === 'useMemo') {
/*
* Replace the hook callee with the fn arg.
*
* before:
* $1 = LoadGlobal useMemo // load the useMemo global
* $2 = FunctionExpression ... // memo function
* $3 = ArrayExpression [ ... ] // deps array
* $4 = Call $1 ($2, $3 ) // invoke useMemo w fn and deps
*
* after:
* $1 = LoadGlobal useMemo // load the useMemo global (dead code)
* $2 = FunctionExpression ... // memo function
* $3 = ArrayExpression [ ... ] // deps array (dead code)
* $4 = Call $2 () // invoke the memo function itself
*
* Note that a later pass (InlineImmediatelyInvokedFunctionExpressions) will
* inline the useMemo callback along with any other immediately invoked IIFEs.
*/
return {
kind: 'CallExpression',
callee: fn,
/*
* Drop the args, including the deps array which DCE will remove
* later.
*/
args: [],
loc,
};
} else {
/*
* Instead of a Call, just alias the callback directly.
*
* before:
* $1 = LoadGlobal useCallback
* $2 = FunctionExpression ... // the callback being memoized
* $3 = ArrayExpression ... // deps array
* $4 = Call $1 ( $2, $3 ) // invoke useCallback
*
* after:
* $1 = LoadGlobal useCallback // dead code
* $2 = FunctionExpression ... // the callback being memoized
* $3 = ArrayExpression ... // deps array (dead code)
* $4 = LoadLocal $2 // reference the function
*/
return {
kind: 'LoadLocal',
place: {
kind: 'Identifier',
identifier: fn.identifier,
effect: Effect.Unknown,
reactive: false,
loc,
},
loc,
};
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getManualMemoizationReplacement() do?
getManualMemoizationReplacement() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts.
Where is getManualMemoizationReplacement() defined?
getManualMemoizationReplacement() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts at line 226.
What calls getManualMemoizationReplacement()?
getManualMemoizationReplacement() is called by 1 function(s): dropManualMemoization.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free