findReferencedIdentifiers() — react Function Reference
Architecture documentation for the findReferencedIdentifiers() function in DeadCodeElimination.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD b86031b6_78ac_d498_c775_7aedeaf6521e["findReferencedIdentifiers()"] 12a58551_b77c_3215_7e97_0c27aabd262e["DeadCodeElimination.ts"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|defined in| 12a58551_b77c_3215_7e97_0c27aabd262e e6e7641a_0356_e256_1ee6_a60705f7edfe["deadCodeElimination()"] e6e7641a_0356_e256_1ee6_a60705f7edfe -->|calls| b86031b6_78ac_d498_c775_7aedeaf6521e 4a0b4496_ef3b_6781_ecef_edfb88dec63e["hasBackEdge()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| 4a0b4496_ef3b_6781_ecef_edfb88dec63e 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7 b1f70586_b3c9_0ab7_ac2b_08f8ff64792a["reference()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| b1f70586_b3c9_0ab7_ac2b_08f8ff64792a b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44 1ddcaaa6_a274_5751_db05_5448b1a769b9["isIdOrNameUsed()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| 1ddcaaa6_a274_5751_db05_5448b1a769b9 4a81cc91_29b6_ce42_c446_03ec75c6b5f2["pruneableValue()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| 4a81cc91_29b6_ce42_c446_03ec75c6b5f2 568e9c36_44d8_d092_103e_197bdf559e4e["isIdUsed()"] b86031b6_78ac_d498_c775_7aedeaf6521e -->|calls| 568e9c36_44d8_d092_103e_197bdf559e4e style b86031b6_78ac_d498_c775_7aedeaf6521e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts lines 114–185
function findReferencedIdentifiers(fn: HIRFunction): State {
/*
* If there are no back-edges the algorithm can terminate after a single iteration
* of the blocks
*/
const hasLoop = hasBackEdge(fn);
const reversedBlocks = [...fn.body.blocks.values()].reverse();
const state = new State(fn.env);
let size = state.count;
do {
size = state.count;
/*
* Iterate blocks in postorder (successors before predecessors, excepting loops)
* to visit usages before declarations
*/
for (const block of reversedBlocks) {
for (const operand of eachTerminalOperand(block.terminal)) {
state.reference(operand.identifier);
}
for (let i = block.instructions.length - 1; i >= 0; i--) {
const instr = block.instructions[i]!;
const isBlockValue =
block.kind !== 'block' && i === block.instructions.length - 1;
if (isBlockValue) {
/**
* The last instr of a value block is never eligible for pruning,
* as that's the block's value. Pessimistically consider all operands
* as used to avoid rewriting the last instruction
*/
state.reference(instr.lvalue.identifier);
for (const place of eachInstructionValueOperand(instr.value)) {
state.reference(place.identifier);
}
} else if (
state.isIdOrNameUsed(instr.lvalue.identifier) ||
!pruneableValue(instr.value, state)
) {
state.reference(instr.lvalue.identifier);
if (instr.value.kind === 'StoreLocal') {
/*
* If this is a Let/Const declaration, mark the initializer as referenced
* only if the ssa'ed lval is also referenced
*/
if (
instr.value.lvalue.kind === InstructionKind.Reassign ||
state.isIdUsed(instr.value.lvalue.place.identifier)
) {
state.reference(instr.value.value.identifier);
}
} else {
for (const operand of eachInstructionValueOperand(instr.value)) {
state.reference(operand.identifier);
}
}
}
}
for (const phi of block.phis) {
if (state.isIdOrNameUsed(phi.place.identifier)) {
for (const [_pred, operand] of phi.operands) {
state.reference(operand.identifier);
}
}
}
}
} while (state.count > size && hasLoop);
return state;
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does findReferencedIdentifiers() do?
findReferencedIdentifiers() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts.
Where is findReferencedIdentifiers() defined?
findReferencedIdentifiers() is defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts at line 114.
What does findReferencedIdentifiers() call?
findReferencedIdentifiers() calls 7 function(s): eachInstructionValueOperand, eachTerminalOperand, hasBackEdge, isIdOrNameUsed, isIdUsed, pruneableValue, reference.
What calls findReferencedIdentifiers()?
findReferencedIdentifiers() is called by 1 function(s): deadCodeElimination.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free