getAssumedInvokedFunctions() — react Function Reference
Architecture documentation for the getAssumedInvokedFunctions() function in CollectHoistablePropertyLoads.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 30edbd1d_6244_d8ca_6be9_9380bed866cf["getAssumedInvokedFunctions()"] 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72["CollectHoistablePropertyLoads.ts"] 30edbd1d_6244_d8ca_6be9_9380bed866cf -->|defined in| 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72 bff0b2a9_918b_8c37_61b5_56f59c89a9a1["collectHoistablePropertyLoads()"] bff0b2a9_918b_8c37_61b5_56f59c89a9a1 -->|calls| 30edbd1d_6244_d8ca_6be9_9380bed866cf bdf8cdce_736e_1a2d_6a67_5dacbcb1d645["collectHoistablePropertyLoadsInInnerFn()"] bdf8cdce_736e_1a2d_6a67_5dacbcb1d645 -->|calls| 30edbd1d_6244_d8ca_6be9_9380bed866cf 9cbd2355_05cd_5bbd_253f_7aeb4f947484["getHookKind()"] 30edbd1d_6244_d8ca_6be9_9380bed866cf -->|calls| 9cbd2355_05cd_5bbd_253f_7aeb4f947484 style 30edbd1d_6244_d8ca_6be9_9380bed866cf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts lines 685–810
function getAssumedInvokedFunctions(
fn: HIRFunction,
temporaries: Map<
IdentifierId,
{fn: LoweredFunction; mayInvoke: Set<LoweredFunction>}
> = new Map(),
): ReadonlySet<LoweredFunction> {
const hoistableFunctions = new Set<LoweredFunction>();
/**
* Step 1: Conservatively collect identifier to function expression mappings
*/
for (const block of fn.body.blocks.values()) {
for (const {lvalue, value} of block.instructions) {
/**
* Conservatively only match function expressions which can have guaranteed ssa.
* ObjectMethods and ObjectProperties do not.
*/
if (value.kind === 'FunctionExpression') {
temporaries.set(lvalue.identifier.id, {
fn: value.loweredFunc,
mayInvoke: new Set(),
});
} else if (value.kind === 'StoreLocal') {
const lvalue = value.lvalue.place.identifier;
const maybeLoweredFunc = temporaries.get(value.value.identifier.id);
if (maybeLoweredFunc != null) {
temporaries.set(lvalue.id, maybeLoweredFunc);
}
} else if (value.kind === 'LoadLocal') {
const maybeLoweredFunc = temporaries.get(value.place.identifier.id);
if (maybeLoweredFunc != null) {
temporaries.set(lvalue.identifier.id, maybeLoweredFunc);
}
}
}
}
/**
* Step 2: Forward pass to do analysis of assumed function calls. Note that
* this is conservative and does not count indirect references through
* containers (e.g. `return {cb: () => {...}})`).
*/
for (const block of fn.body.blocks.values()) {
for (const {lvalue, value} of block.instructions) {
if (value.kind === 'CallExpression') {
const callee = value.callee;
const maybeHook = getHookKind(fn.env, callee.identifier);
const maybeLoweredFunc = temporaries.get(callee.identifier.id);
if (maybeLoweredFunc != null) {
// Direct calls
hoistableFunctions.add(maybeLoweredFunc.fn);
} else if (maybeHook != null) {
/**
* Assume arguments to all hooks are safe to invoke
*/
for (const arg of value.args) {
if (arg.kind === 'Identifier') {
const maybeLoweredFunc = temporaries.get(arg.identifier.id);
if (maybeLoweredFunc != null) {
hoistableFunctions.add(maybeLoweredFunc.fn);
}
}
}
}
} else if (value.kind === 'JsxExpression') {
/**
* Assume JSX attributes and children are safe to invoke
*/
for (const attr of value.props) {
if (attr.kind === 'JsxSpreadAttribute') {
continue;
}
const maybeLoweredFunc = temporaries.get(attr.place.identifier.id);
if (maybeLoweredFunc != null) {
hoistableFunctions.add(maybeLoweredFunc.fn);
}
}
for (const child of value.children ?? []) {
const maybeLoweredFunc = temporaries.get(child.identifier.id);
if (maybeLoweredFunc != null) {
hoistableFunctions.add(maybeLoweredFunc.fn);
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does getAssumedInvokedFunctions() do?
getAssumedInvokedFunctions() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts.
Where is getAssumedInvokedFunctions() defined?
getAssumedInvokedFunctions() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts at line 685.
What does getAssumedInvokedFunctions() call?
getAssumedInvokedFunctions() calls 1 function(s): getHookKind.
What calls getAssumedInvokedFunctions()?
getAssumedInvokedFunctions() is called by 2 function(s): collectHoistablePropertyLoads, collectHoistablePropertyLoadsInInnerFn.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free