replaceFireFunctions() — react Function Reference
Architecture documentation for the replaceFireFunctions() function in TransformFire.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 38224692_55f3_a937_63fd_e0266e855650["replaceFireFunctions()"] 6061353e_921a_a1a8_d6c1_777e8d9f8896["TransformFire.ts"] 38224692_55f3_a937_63fd_e0266e855650 -->|defined in| 6061353e_921a_a1a8_d6c1_777e8d9f8896 eb912b93_4822_3d1c_01d1_b29c95176ed7["transformFire()"] eb912b93_4822_3d1c_01d1_b29c95176ed7 -->|calls| 38224692_55f3_a937_63fd_e0266e855650 7756ca6a_d541_c148_b849_a02c3a6f4e97["visitFunctionExpressionAndPropagateFireDependencies()"] 7756ca6a_d541_c148_b849_a02c3a6f4e97 -->|calls| 38224692_55f3_a937_63fd_e0266e855650 c364fd16_6f94_1a73_8d9e_4534958d949d["getFunctionExpression()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| c364fd16_6f94_1a73_8d9e_4534958d949d 7756ca6a_d541_c148_b849_a02c3a6f4e97["visitFunctionExpressionAndPropagateFireDependencies()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 7756ca6a_d541_c148_b849_a02c3a6f4e97 a9536a88_f563_4f72_20a0_40128435fa78["hasCalleeWithInsertedFire()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| a9536a88_f563_4f72_20a0_40128435fa78 65848e0e_926f_e89b_6b6d_02c250615f44["addCalleeWithInsertedFire()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 65848e0e_926f_e89b_6b6d_02c250615f44 afd978c1_e7a8_7328_882e_0e05af6cb8a7["makeLoadUseFireInstruction()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| afd978c1_e7a8_7328_882e_0e05af6cb8a7 9efe5af8_de23_9f01_22ae_74fa1ea707f8["makeLoadFireCalleeInstruction()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 9efe5af8_de23_9f01_22ae_74fa1ea707f8 af87d057_2d4b_c617_1d9b_77698e1be8af["makeCallUseFireInstruction()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| af87d057_2d4b_c617_1d9b_77698e1be8af d5d4ccd4_0661_c4b1_7123_0457823424e7["makeStoreUseFireInstruction()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| d5d4ccd4_0661_c4b1_7123_0457823424e7 3ef5f503_9220_a675_38bb_f67e8ab24028["getLoadGlobalInstrId()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 3ef5f503_9220_a675_38bb_f67e8ab24028 7d01f68a_73c6_619d_f94a_4a30b935a1dc["pushError()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 7d01f68a_73c6_619d_f94a_4a30b935a1dc 6e048cfd_d7b0_b702_7929_3e87d8dcd51c["ensureNoRemainingCalleeCaptures()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 6e048cfd_d7b0_b702_7929_3e87d8dcd51c 1ae47ff6_cf78_70b0_2eb9_3539b62a8b0e["getArrayExpression()"] 38224692_55f3_a937_63fd_e0266e855650 -->|calls| 1ae47ff6_cf78_70b0_2eb9_3539b62a8b0e style 38224692_55f3_a937_63fd_e0266e855650 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts lines 60–308
function replaceFireFunctions(fn: HIRFunction, context: Context): void {
let importedUseFire: NonLocalImportSpecifier | null = null;
let hasRewrite = false;
for (const [, block] of fn.body.blocks) {
const rewriteInstrs = new Map<InstructionId, Array<Instruction>>();
const deleteInstrs = new Set<InstructionId>();
for (const instr of block.instructions) {
const {value, lvalue} = instr;
if (
value.kind === 'CallExpression' &&
isUseEffectHookType(value.callee.identifier) &&
value.args.length > 0 &&
value.args[0].kind === 'Identifier'
) {
const lambda = context.getFunctionExpression(
value.args[0].identifier.id,
);
if (lambda != null) {
const capturedCallees =
visitFunctionExpressionAndPropagateFireDependencies(
lambda,
context,
true,
);
// Add useFire calls for all fire calls in found in the lambda
const newInstrs = [];
for (const [
fireCalleePlace,
fireCalleeInfo,
] of capturedCallees.entries()) {
if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) {
context.addCalleeWithInsertedFire(fireCalleePlace);
importedUseFire ??= fn.env.programContext.addImportSpecifier({
source: fn.env.programContext.reactRuntimeModule,
importSpecifierName: USE_FIRE_FUNCTION_NAME,
});
const loadUseFireInstr = makeLoadUseFireInstruction(
fn.env,
importedUseFire,
);
const loadFireCalleeInstr = makeLoadFireCalleeInstruction(
fn.env,
fireCalleeInfo.capturedCalleeIdentifier,
);
const callUseFireInstr = makeCallUseFireInstruction(
fn.env,
loadUseFireInstr.lvalue,
loadFireCalleeInstr.lvalue,
);
const storeUseFireInstr = makeStoreUseFireInstruction(
fn.env,
callUseFireInstr.lvalue,
fireCalleeInfo.fireFunctionBinding,
);
newInstrs.push(
loadUseFireInstr,
loadFireCalleeInstr,
callUseFireInstr,
storeUseFireInstr,
);
// We insert all of these instructions before the useEffect is loaded
const loadUseEffectInstrId = context.getLoadGlobalInstrId(
value.callee.identifier.id,
);
if (loadUseEffectInstrId == null) {
context.pushError({
loc: value.loc,
description: null,
category: ErrorCategory.Invariant,
reason: '[InsertFire] No LoadGlobal found for useEffect call',
suggestions: null,
});
continue;
}
rewriteInstrs.set(loadUseEffectInstrId, newInstrs);
}
}
ensureNoRemainingCalleeCaptures(
Domain
Subdomains
Calls
- addArrayExpression()
- addCallExpression()
- addCalleeWithInsertedFire()
- addFunctionExpression()
- addLoadGlobalInstrId()
- addLoadLocalInstr()
- deleteInstructions()
- ensureNoRemainingCalleeCaptures()
- getArrayExpression()
- getCallExpression()
- getFunctionExpression()
- getLoadGlobalInstrId()
- getLoadLocalInstr()
- getOrGenerateFireFunctionBinding()
- hasCalleeWithInsertedFire()
- inUseEffectLambda()
- makeCallUseFireInstruction()
- makeLoadFireCalleeInstruction()
- makeLoadUseFireInstruction()
- makeStoreUseFireInstruction()
- markInstructionIds()
- push()
- pushError()
- rewriteInstructions()
- visitFunctionExpressionAndPropagateFireDependencies()
Source
Frequently Asked Questions
What does replaceFireFunctions() do?
replaceFireFunctions() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts.
Where is replaceFireFunctions() defined?
replaceFireFunctions() is defined in compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts at line 60.
What does replaceFireFunctions() call?
replaceFireFunctions() calls 25 function(s): addArrayExpression, addCallExpression, addCalleeWithInsertedFire, addFunctionExpression, addLoadGlobalInstrId, addLoadLocalInstr, deleteInstructions, ensureNoRemainingCalleeCaptures, and 17 more.
What calls replaceFireFunctions()?
replaceFireFunctions() is called by 2 function(s): transformFire, visitFunctionExpressionAndPropagateFireDependencies.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free