mutate() — react Function Reference
Architecture documentation for the mutate() function in InferMutationAliasingRanges.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD cd8871a0_00ab_a3ba_98a3_61b6b75d973c["mutate()"] 78bdc9d3_b80e_c93f_98e8_83b50c1b2b77["AliasingState"] cd8871a0_00ab_a3ba_98a3_61b6b75d973c -->|defined in| 78bdc9d3_b80e_c93f_98e8_83b50c1b2b77 f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3["inferMutationAliasingRanges()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| cd8871a0_00ab_a3ba_98a3_61b6b75d973c d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"] cd8871a0_00ab_a3ba_98a3_61b6b75d973c -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2 f54dd966_4662_1205_ce47_174c3758a7ff["appendFunctionErrors()"] cd8871a0_00ab_a3ba_98a3_61b6b75d973c -->|calls| f54dd966_4662_1205_ce47_174c3758a7ff style cd8871a0_00ab_a3ba_98a3_61b6b75d973c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts lines 700–838
mutate(
index: number,
start: Identifier,
// Null is used for simulated mutations
end: InstructionId | null,
transitive: boolean,
startKind: MutationKind,
loc: SourceLocation,
reason: MutationReason | null,
errors: CompilerError,
): void {
const seen = new Map<Identifier, MutationKind>();
const queue: Array<{
place: Identifier;
transitive: boolean;
direction: 'backwards' | 'forwards';
kind: MutationKind;
}> = [{place: start, transitive, direction: 'backwards', kind: startKind}];
while (queue.length !== 0) {
const {place: current, transitive, direction, kind} = queue.pop()!;
const previousKind = seen.get(current);
if (previousKind != null && previousKind >= kind) {
continue;
}
seen.set(current, kind);
const node = this.nodes.get(current);
if (node == null) {
continue;
}
node.mutationReason ??= reason;
node.lastMutated = Math.max(node.lastMutated, index);
if (end != null) {
node.id.mutableRange.end = makeInstructionId(
Math.max(node.id.mutableRange.end, end),
);
}
if (
node.value.kind === 'Function' &&
node.transitive == null &&
node.local == null
) {
appendFunctionErrors(errors, node.value.function);
}
if (transitive) {
if (node.transitive == null || node.transitive.kind < kind) {
node.transitive = {kind, loc};
}
} else {
if (node.local == null || node.local.kind < kind) {
node.local = {kind, loc};
}
}
/**
* all mutations affect "forward" edges by the rules:
* - Capture a -> b, mutate(a) => mutate(b)
* - Alias a -> b, mutate(a) => mutate(b)
*/
for (const edge of node.edges) {
if (edge.index >= index) {
break;
}
queue.push({
place: edge.node,
transitive,
direction: 'forwards',
// Traversing a maybeAlias edge always downgrades to conditional mutation
kind: edge.kind === 'maybeAlias' ? MutationKind.Conditional : kind,
});
}
for (const [alias, when] of node.createdFrom) {
if (when >= index) {
continue;
}
queue.push({
place: alias,
transitive: true,
direction: 'backwards',
kind,
});
}
if (direction === 'backwards' || node.value.kind !== 'Phi') {
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does mutate() do?
mutate() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts.
Where is mutate() defined?
mutate() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts at line 700.
What does mutate() call?
mutate() calls 2 function(s): appendFunctionErrors, makeInstructionId.
What calls mutate()?
mutate() is called by 1 function(s): inferMutationAliasingRanges.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free