findNonMutatedDestructureSpreads() — react Function Reference
Architecture documentation for the findNonMutatedDestructureSpreads() function in InferMutationAliasingEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD e7a5763f_4c18_e88b_d1ab_1552691b7387["findNonMutatedDestructureSpreads()"] d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"] e7a5763f_4c18_e88b_d1ab_1552691b7387 -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea["inferMutationAliasingEffects()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| e7a5763f_4c18_e88b_d1ab_1552691b7387 bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e["values()"] e7a5763f_4c18_e88b_d1ab_1552691b7387 -->|calls| bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"] e7a5763f_4c18_e88b_d1ab_1552691b7387 -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44 style e7a5763f_4c18_e88b_d1ab_1552691b7387 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 336–469
function findNonMutatedDestructureSpreads(fn: HIRFunction): Set<IdentifierId> {
const knownFrozen = new Set<IdentifierId>();
if (fn.fnType === 'Component') {
const [props] = fn.params;
if (props != null && props.kind === 'Identifier') {
knownFrozen.add(props.identifier.id);
}
} else {
for (const param of fn.params) {
if (param.kind === 'Identifier') {
knownFrozen.add(param.identifier.id);
}
}
}
// Map of temporaries to identifiers for spread objects
const candidateNonMutatingSpreads = new Map<IdentifierId, IdentifierId>();
for (const block of fn.body.blocks.values()) {
if (candidateNonMutatingSpreads.size !== 0) {
for (const phi of block.phis) {
for (const operand of phi.operands.values()) {
const spread = candidateNonMutatingSpreads.get(operand.identifier.id);
if (spread != null) {
candidateNonMutatingSpreads.delete(spread);
}
}
}
}
for (const instr of block.instructions) {
const {lvalue, value} = instr;
switch (value.kind) {
case 'Destructure': {
if (
!knownFrozen.has(value.value.identifier.id) ||
!(
value.lvalue.kind === InstructionKind.Let ||
value.lvalue.kind === InstructionKind.Const
) ||
value.lvalue.pattern.kind !== 'ObjectPattern'
) {
continue;
}
for (const item of value.lvalue.pattern.properties) {
if (item.kind !== 'Spread') {
continue;
}
candidateNonMutatingSpreads.set(
item.place.identifier.id,
item.place.identifier.id,
);
}
break;
}
case 'LoadLocal': {
const spread = candidateNonMutatingSpreads.get(
value.place.identifier.id,
);
if (spread != null) {
candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
}
break;
}
case 'StoreLocal': {
const spread = candidateNonMutatingSpreads.get(
value.value.identifier.id,
);
if (spread != null) {
candidateNonMutatingSpreads.set(lvalue.identifier.id, spread);
candidateNonMutatingSpreads.set(
value.lvalue.place.identifier.id,
spread,
);
}
break;
}
case 'JsxFragment':
case 'JsxExpression': {
// Passing objects created with spread to jsx can't mutate them
break;
}
case 'PropertyLoad': {
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does findNonMutatedDestructureSpreads() do?
findNonMutatedDestructureSpreads() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is findNonMutatedDestructureSpreads() defined?
findNonMutatedDestructureSpreads() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 336.
What does findNonMutatedDestructureSpreads() call?
findNonMutatedDestructureSpreads() calls 2 function(s): eachInstructionValueOperand, values.
What calls findNonMutatedDestructureSpreads()?
findNonMutatedDestructureSpreads() is called by 1 function(s): inferMutationAliasingEffects.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free