applyEffect() — react Function Reference
Architecture documentation for the applyEffect() function in InferMutationAliasingEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 7cb90dd3_dbe0_0087_670d_277ddeadabfc["applyEffect()"] d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629 ac82e9ee_09bc_b58c_f2ac_86bf2d552540["inferBlock()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 7cb90dd3_dbe0_0087_670d_277ddeadabfc f255dd41_8c48_19a9_1bcc_8efd2d663f32["applySignature()"] f255dd41_8c48_19a9_1bcc_8efd2d663f32 -->|calls| 7cb90dd3_dbe0_0087_670d_277ddeadabfc 97fe1d23_4f7c_ef28_ca5a_de2c6e376163["internEffect()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 97fe1d23_4f7c_ef28_ca5a_de2c6e376163 3892e473_17c5_bb0e_5d49_0b377b5ed784["printAliasingEffect()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 3892e473_17c5_bb0e_5d49_0b377b5ed784 e0e4be16_6524_e844_c68d_262036cf06e3["freeze()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| e0e4be16_6524_e844_c68d_262036cf06e3 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e bf7f1cf7_fc0e_6bac_827c_8d36d98126da["printPlace()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| bf7f1cf7_fc0e_6bac_827c_8d36d98126da 1338ac96_28d3_4184_21f5_e19b4079bba3["initialize()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 1338ac96_28d3_4184_21f5_e19b4079bba3 1028b1e9_aaf3_f6b1_21dd_0c83f1c827e7["define()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 1028b1e9_aaf3_f6b1_21dd_0c83f1c827e7 8f06f55e_0851_0d44_0a89_d6dee31fdbb5["kind()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 8f06f55e_0851_0d44_0a89_d6dee31fdbb5 953c4d58_4239_ada6_0ba7_cf09db9625fe["assign()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 953c4d58_4239_ada6_0ba7_cf09db9625fe bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e["values()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e 2dd4869d_1f08_05d3_2645_bd8e186bc5db["buildSignatureFromFunctionExpression()"] 7cb90dd3_dbe0_0087_670d_277ddeadabfc -->|calls| 2dd4869d_1f08_05d3_2645_bd8e186bc5db style 7cb90dd3_dbe0_0087_670d_277ddeadabfc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 673–1308
function applyEffect(
context: Context,
state: InferenceState,
_effect: AliasingEffect,
initialized: Set<IdentifierId>,
effects: Array<AliasingEffect>,
): void {
const effect = context.internEffect(_effect);
if (DEBUG) {
console.log(printAliasingEffect(effect));
}
switch (effect.kind) {
case 'Freeze': {
const didFreeze = state.freeze(effect.value, effect.reason);
if (didFreeze) {
effects.push(effect);
}
break;
}
case 'Create': {
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
reason: `Cannot re-initialize variable within an instruction`,
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
loc: effect.into.loc,
});
initialized.add(effect.into.identifier.id);
let value = context.effectInstructionValueCache.get(effect);
if (value == null) {
value = {
kind: 'ObjectExpression',
properties: [],
loc: effect.into.loc,
};
context.effectInstructionValueCache.set(effect, value);
}
state.initialize(value, {
kind: effect.value,
reason: new Set([effect.reason]),
});
state.define(effect.into, value);
effects.push(effect);
break;
}
case 'ImmutableCapture': {
const kind = state.kind(effect.from).kind;
switch (kind) {
case ValueKind.Global:
case ValueKind.Primitive: {
// no-op: we don't need to track data flow for copy types
break;
}
default: {
effects.push(effect);
}
}
break;
}
case 'CreateFrom': {
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
reason: `Cannot re-initialize variable within an instruction`,
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
loc: effect.into.loc,
});
initialized.add(effect.into.identifier.id);
const fromValue = state.kind(effect.from);
let value = context.effectInstructionValueCache.get(effect);
if (value == null) {
value = {
kind: 'ObjectExpression',
properties: [],
loc: effect.into.loc,
};
context.effectInstructionValueCache.set(effect, value);
}
state.initialize(value, {
kind: fromValue.kind,
reason: new Set(fromValue.reason),
});
state.define(effect.into, value);
Domain
Subdomains
Defined In
Calls
- assertExhaustive()
- assign()
- buildSignatureFromFunctionExpression()
- cacheApplySignature()
- computeEffectsForLegacySignature()
- computeEffectsForSignature()
- conditionallyMutateIterator()
- create()
- debugAbstractValue()
- define()
- freeze()
- getWriteErrorReason()
- initialize()
- internEffect()
- invariant()
- kind()
- mutate()
- printAliasingEffect()
- printAliasingSignature()
- printPlace()
- push()
- values()
- withDetails()
Called By
Source
Frequently Asked Questions
What does applyEffect() do?
applyEffect() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is applyEffect() defined?
applyEffect() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 673.
What does applyEffect() call?
applyEffect() calls 23 function(s): assertExhaustive, assign, buildSignatureFromFunctionExpression, cacheApplySignature, computeEffectsForLegacySignature, computeEffectsForSignature, conditionallyMutateIterator, create, and 15 more.
What calls applyEffect()?
applyEffect() is called by 2 function(s): applySignature, inferBlock.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free