findTemporariesUsedOutsideDeclaringScope() — react Function Reference
Architecture documentation for the findTemporariesUsedOutsideDeclaringScope() function in PropagateScopeDependenciesHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 3cbb5167_d55c_6775_cfe5_cd15846ca8d2["findTemporariesUsedOutsideDeclaringScope()"] 76832af2_c0a7_f31c_e448_af5664da4b88["PropagateScopeDependenciesHIR.ts"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|defined in| 76832af2_c0a7_f31c_e448_af5664da4b88 55f3fce3_0db5_e260_b549_d5a721561462["propagateScopeDependenciesHIR()"] 55f3fce3_0db5_e260_b549_d5a721561462 -->|calls| 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e["handleInstruction()"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e e905b26b_28fa_658a_742c_b1836921c75b["recordScopes()"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| e905b26b_28fa_658a_742c_b1836921c75b ccace1c3_85b7_a05e_c2a5_7eff8b3422ed["eachInstructionOperand()"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| ccace1c3_85b7_a05e_c2a5_7eff8b3422ed 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7 e4202808_c854_fd63_c981_990ad95d6125["isScopeActive()"] 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| e4202808_c854_fd63_c981_990ad95d6125 style 3cbb5167_d55c_6775_cfe5_cd15846ca8d2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts lines 120–180
export function findTemporariesUsedOutsideDeclaringScope(
fn: HIRFunction,
): ReadonlySet<DeclarationId> {
/*
* tracks all relevant LoadLocal and PropertyLoad lvalues
* and the scope where they are defined
*/
const declarations = new Map<DeclarationId, ScopeId>();
const prunedScopes = new Set<ScopeId>();
const scopeTraversal = new ScopeBlockTraversal();
const usedOutsideDeclaringScope = new Set<DeclarationId>();
function handlePlace(place: Place): void {
const declaringScope = declarations.get(place.identifier.declarationId);
if (
declaringScope != null &&
!scopeTraversal.isScopeActive(declaringScope) &&
!prunedScopes.has(declaringScope)
) {
// Declaring scope is not active === used outside declaring scope
usedOutsideDeclaringScope.add(place.identifier.declarationId);
}
}
function handleInstruction(instr: Instruction): void {
const scope = scopeTraversal.currentScope;
if (scope == null || prunedScopes.has(scope)) {
return;
}
switch (instr.value.kind) {
case 'LoadLocal':
case 'LoadContext':
case 'PropertyLoad': {
declarations.set(instr.lvalue.identifier.declarationId, scope);
break;
}
default: {
break;
}
}
}
for (const [blockId, block] of fn.body.blocks) {
scopeTraversal.recordScopes(block);
const scopeStartInfo = scopeTraversal.blockInfos.get(blockId);
if (scopeStartInfo?.kind === 'begin' && scopeStartInfo.pruned) {
prunedScopes.add(scopeStartInfo.scope.id);
}
for (const instr of block.instructions) {
for (const place of eachInstructionOperand(instr)) {
handlePlace(place);
}
handleInstruction(instr);
}
for (const place of eachTerminalOperand(block.terminal)) {
handlePlace(place);
}
}
return usedOutsideDeclaringScope;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does findTemporariesUsedOutsideDeclaringScope() do?
findTemporariesUsedOutsideDeclaringScope() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts.
Where is findTemporariesUsedOutsideDeclaringScope() defined?
findTemporariesUsedOutsideDeclaringScope() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts at line 120.
What does findTemporariesUsedOutsideDeclaringScope() call?
findTemporariesUsedOutsideDeclaringScope() calls 5 function(s): eachInstructionOperand, eachTerminalOperand, handleInstruction, isScopeActive, recordScopes.
What calls findTemporariesUsedOutsideDeclaringScope()?
findTemporariesUsedOutsideDeclaringScope() is called by 1 function(s): propagateScopeDependenciesHIR.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free