collectNonNullsInBlocks() — react Function Reference
Architecture documentation for the collectNonNullsInBlocks() function in CollectHoistablePropertyLoads.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 2c85e7b5_d003_b439_dc7b_cb881996ea23["collectNonNullsInBlocks()"] 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72["CollectHoistablePropertyLoads.ts"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|defined in| 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72 bb062ddc_03b9_8460_2af6_d98cc2189d33["collectHoistablePropertyLoadsImpl()"] bb062ddc_03b9_8460_2af6_d98cc2189d33 -->|calls| 2c85e7b5_d003_b439_dc7b_cb881996ea23 084ee472_d720_c32a_2f8a_dffbbb1be6af["getOrCreateIdentifier()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| 084ee472_d720_c32a_2f8a_dffbbb1be6af afcd35a2_87ac_64f3_d39b_e78954698dc0["getOrCreateProperty()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| afcd35a2_87ac_64f3_d39b_e78954698dc0 618d3d38_bcbf_713e_ce1a_d85056287498["getMaybeNonNullInInstruction()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| 618d3d38_bcbf_713e_ce1a_d85056287498 cac490a6_2858_f9b4_a7b9_507c998b97b7["isImmutableAtInstr()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| cac490a6_2858_f9b4_a7b9_507c998b97b7 bb062ddc_03b9_8460_2af6_d98cc2189d33["collectHoistablePropertyLoadsImpl()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| bb062ddc_03b9_8460_2af6_d98cc2189d33 7cd776c7_0283_e0eb_af1b_5474c371bd16["assertNonNull()"] 2c85e7b5_d003_b439_dc7b_cb881996ea23 -->|calls| 7cd776c7_0283_e0eb_af1b_5474c371bd16 style 2c85e7b5_d003_b439_dc7b_cb881996ea23 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts lines 380–485
function collectNonNullsInBlocks(
fn: HIRFunction,
context: CollectHoistablePropertyLoadsContext,
): ReadonlyMap<BlockId, BlockInfo> {
/**
* Known non-null objects such as functional component props can be safely
* read from any block.
*/
const knownNonNullIdentifiers = new Set<PropertyPathNode>();
if (
fn.fnType === 'Component' &&
fn.params.length > 0 &&
fn.params[0].kind === 'Identifier'
) {
const identifier = fn.params[0].identifier;
knownNonNullIdentifiers.add(
context.registry.getOrCreateIdentifier(identifier, true),
);
}
const nodes = new Map<
BlockId,
{
block: BasicBlock;
assumedNonNullObjects: Set<PropertyPathNode>;
}
>();
for (const [_, block] of fn.body.blocks) {
const assumedNonNullObjects = new Set<PropertyPathNode>(
knownNonNullIdentifiers,
);
const maybeOptionalChain = context.hoistableFromOptionals.get(block.id);
if (maybeOptionalChain != null) {
assumedNonNullObjects.add(
context.registry.getOrCreateProperty(maybeOptionalChain),
);
}
for (const instr of block.instructions) {
const maybeNonNull = getMaybeNonNullInInstruction(instr.value, context);
if (
maybeNonNull != null &&
isImmutableAtInstr(maybeNonNull.fullPath.identifier, instr.id, context)
) {
assumedNonNullObjects.add(maybeNonNull);
}
if (instr.value.kind === 'FunctionExpression') {
const innerFn = instr.value.loweredFunc;
if (context.assumedInvokedFns.has(innerFn)) {
const innerHoistableMap = collectHoistablePropertyLoadsImpl(
innerFn.func,
{
...context,
nestedFnImmutableContext:
context.nestedFnImmutableContext ??
new Set(
innerFn.func.context
.filter(place =>
isImmutableAtInstr(place.identifier, instr.id, context),
)
.map(place => place.identifier.id),
),
},
);
const innerHoistables = assertNonNull(
innerHoistableMap.get(innerFn.func.body.entry),
);
for (const entry of innerHoistables.assumedNonNullObjects) {
assumedNonNullObjects.add(entry);
}
}
} else if (
fn.env.config.enablePreserveExistingMemoizationGuarantees &&
instr.value.kind === 'StartMemoize' &&
instr.value.deps != null
) {
for (const dep of instr.value.deps) {
if (dep.root.kind === 'NamedLocal') {
if (
!isImmutableAtInstr(dep.root.value.identifier, instr.id, context)
) {
continue;
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does collectNonNullsInBlocks() do?
collectNonNullsInBlocks() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts.
Where is collectNonNullsInBlocks() defined?
collectNonNullsInBlocks() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts at line 380.
What does collectNonNullsInBlocks() call?
collectNonNullsInBlocks() calls 6 function(s): assertNonNull, collectHoistablePropertyLoadsImpl, getMaybeNonNullInInstruction, getOrCreateIdentifier, getOrCreateProperty, isImmutableAtInstr.
What calls collectNonNullsInBlocks()?
collectNonNullsInBlocks() is called by 1 function(s): collectHoistablePropertyLoadsImpl.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free