inferMutationAliasingEffects() — react Function Reference
Architecture documentation for the inferMutationAliasingEffects() function in InferMutationAliasingEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea["inferMutationAliasingEffects()"] d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629 c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea 549ab0df_dde0_c1fc_591d_a1d683921f55["lowerWithMutationAliasing()"] 549ab0df_dde0_c1fc_591d_a1d683921f55 -->|calls| 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea bc21e0dd_8d22_ea1e_540e_d310cb629833["empty()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| bc21e0dd_8d22_ea1e_540e_d310cb629833 1338ac96_28d3_4184_21f5_e19b4079bba3["initialize()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 1338ac96_28d3_4184_21f5_e19b4079bba3 1028b1e9_aaf3_f6b1_21dd_0c83f1c827e7["define()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 1028b1e9_aaf3_f6b1_21dd_0c83f1c827e7 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e eba1a943_35fa_0645_9e58_2d015c93dba7["inferParam()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| eba1a943_35fa_0645_9e58_2d015c93dba7 27a7c554_72a2_eec2_c309_48c8a62bd9af["merge()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 27a7c554_72a2_eec2_c309_48c8a62bd9af a434dd08_0de3_17ca_8d4f_08a598a9c73e["findHoistedContextDeclarations()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| a434dd08_0de3_17ca_8d4f_08a598a9c73e e7a5763f_4c18_e88b_d1ab_1552691b7387["findNonMutatedDestructureSpreads()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| e7a5763f_4c18_e88b_d1ab_1552691b7387 6ebab1ee_aaee_a649_32a1_d9f91bbdc948["clone()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| 6ebab1ee_aaee_a649_32a1_d9f91bbdc948 ac82e9ee_09bc_b58c_f2ac_86bf2d552540["inferBlock()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| ac82e9ee_09bc_b58c_f2ac_86bf2d552540 d737cb4c_53f4_75b4_2d58_268e2f73fde4["eachTerminalSuccessor()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| d737cb4c_53f4_75b4_2d58_268e2f73fde4 style 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 98–224
export function inferMutationAliasingEffects(
fn: HIRFunction,
{isFunctionExpression}: {isFunctionExpression: boolean} = {
isFunctionExpression: false,
},
): Result<void, CompilerError> {
const initialState = InferenceState.empty(fn.env, isFunctionExpression);
// Map of blocks to the last (merged) incoming state that was processed
const statesByBlock: Map<BlockId, InferenceState> = new Map();
for (const ref of fn.context) {
// TODO: using InstructionValue as a bit of a hack, but it's pragmatic
const value: InstructionValue = {
kind: 'ObjectExpression',
properties: [],
loc: ref.loc,
};
initialState.initialize(value, {
kind: ValueKind.Context,
reason: new Set([ValueReason.Other]),
});
initialState.define(ref, value);
}
const paramKind: AbstractValue = isFunctionExpression
? {
kind: ValueKind.Mutable,
reason: new Set([ValueReason.Other]),
}
: {
kind: ValueKind.Frozen,
reason: new Set([ValueReason.ReactiveFunctionArgument]),
};
if (fn.fnType === 'Component') {
CompilerError.invariant(fn.params.length <= 2, {
reason:
'Expected React component to have not more than two parameters: one for props and for ref',
loc: fn.loc,
});
const [props, ref] = fn.params;
if (props != null) {
inferParam(props, initialState, paramKind);
}
if (ref != null) {
const place = ref.kind === 'Identifier' ? ref : ref.place;
const value: InstructionValue = {
kind: 'ObjectExpression',
properties: [],
loc: place.loc,
};
initialState.initialize(value, {
kind: ValueKind.Mutable,
reason: new Set([ValueReason.Other]),
});
initialState.define(place, value);
}
} else {
for (const param of fn.params) {
inferParam(param, initialState, paramKind);
}
}
/*
* Multiple predecessors may be visited prior to reaching a given successor,
* so track the list of incoming state for each successor block.
* These are merged when reaching that block again.
*/
const queuedStates: Map<BlockId, InferenceState> = new Map();
function queue(blockId: BlockId, state: InferenceState): void {
let queuedState = queuedStates.get(blockId);
if (queuedState != null) {
// merge the queued states for this block
state = queuedState.merge(state) ?? queuedState;
queuedStates.set(blockId, state);
} else {
/*
* this is the first queued state for this block, see whether
* there are changed relative to the last time it was processed.
*/
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does inferMutationAliasingEffects() do?
inferMutationAliasingEffects() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is inferMutationAliasingEffects() defined?
inferMutationAliasingEffects() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 98.
What does inferMutationAliasingEffects() call?
inferMutationAliasingEffects() calls 12 function(s): Ok, clone, define, eachTerminalSuccessor, empty, findHoistedContextDeclarations, findNonMutatedDestructureSpreads, inferBlock, and 4 more.
What calls inferMutationAliasingEffects()?
inferMutationAliasingEffects() is called by 2 function(s): lowerWithMutationAliasing, runWithEnvironment.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free