inferMutationAliasingRanges() — react Function Reference
Architecture documentation for the inferMutationAliasingRanges() function in InferMutationAliasingRanges.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3["inferMutationAliasingRanges()"] 99c95040_9e14_265b_aae3_b58b12a70d8d["InferMutationAliasingRanges.ts"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|defined in| 99c95040_9e14_265b_aae3_b58b12a70d8d c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 549ab0df_dde0_c1fc_591d_a1d683921f55["lowerWithMutationAliasing()"] 549ab0df_dde0_c1fc_591d_a1d683921f55 -->|calls| f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 5d4e4d78_c36a_0635_7ac7_b280e427ea93["create()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| 5d4e4d78_c36a_0635_7ac7_b280e427ea93 fd717f31_7e4c_313d_1581_4e6a2ea3ca85["assign()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| fd717f31_7e4c_313d_1581_4e6a2ea3ca85 fba5b87c_4f97_a713_10e1_65cc2cf8d8ea["createFrom()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| fba5b87c_4f97_a713_10e1_65cc2cf8d8ea 2664d9ed_bf71_6603_1903_91e8305e45d4["maybeAlias()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| 2664d9ed_bf71_6603_1903_91e8305e45d4 74920f87_fc03_df5c_ac10_8ca6db32d279["capture()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| 74920f87_fc03_df5c_ac10_8ca6db32d279 cd8871a0_00ab_a3ba_98a3_61b6b75d973c["mutate()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| cd8871a0_00ab_a3ba_98a3_61b6b75d973c d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2 a245d666_3ea2_209a_f47a_fe1e2c5a2577["render()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| a245d666_3ea2_209a_f47a_fe1e2c5a2577 10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| 10043bf1_f7ee_9ed9_307a_fe3edfd02b09 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44 d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"] f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6 style f3815d1a_36a1_3e3d_92f2_dbbe88f01fe3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts lines 74–554
export function inferMutationAliasingRanges(
fn: HIRFunction,
{isFunctionExpression}: {isFunctionExpression: boolean},
): Result<Array<AliasingEffect>, CompilerError> {
// The set of externally-visible effects
const functionEffects: Array<AliasingEffect> = [];
/**
* Part 1: Infer mutable ranges for values. We build an abstract model of
* values, the alias/capture edges between them, and the set of mutations.
* Edges and mutations are ordered, with mutations processed against the
* abstract model only after it is fully constructed by visiting all blocks
* _and_ connecting phis. Phis are considered ordered at the time of the
* phi node.
*
* This should (may?) mean that mutations are able to see the full state
* of the graph and mark all the appropriate identifiers as mutated at
* the correct point, accounting for both backward and forward edges.
* Ie a mutation of x accounts for both values that flowed into x,
* and values that x flowed into.
*/
const state = new AliasingState();
type PendingPhiOperand = {from: Place; into: Place; index: number};
const pendingPhis = new Map<BlockId, Array<PendingPhiOperand>>();
const mutations: Array<{
index: number;
id: InstructionId;
transitive: boolean;
kind: MutationKind;
place: Place;
reason: MutationReason | null;
}> = [];
const renders: Array<{index: number; place: Place}> = [];
let index = 0;
const errors = new CompilerError();
for (const param of [...fn.params, ...fn.context, fn.returns]) {
const place = param.kind === 'Identifier' ? param : param.place;
state.create(place, {kind: 'Object'});
}
const seenBlocks = new Set<BlockId>();
for (const block of fn.body.blocks.values()) {
for (const phi of block.phis) {
state.create(phi.place, {kind: 'Phi'});
for (const [pred, operand] of phi.operands) {
if (!seenBlocks.has(pred)) {
// NOTE: annotation required to actually typecheck and not silently infer `any`
const blockPhis = getOrInsertWith<BlockId, Array<PendingPhiOperand>>(
pendingPhis,
pred,
() => [],
);
blockPhis.push({from: operand, into: phi.place, index: index++});
} else {
state.assign(index++, operand, phi.place);
}
}
}
seenBlocks.add(block.id);
for (const instr of block.instructions) {
if (instr.effects == null) continue;
for (const effect of instr.effects) {
if (effect.kind === 'Create') {
state.create(effect.into, {kind: 'Object'});
} else if (effect.kind === 'CreateFunction') {
state.create(effect.into, {
kind: 'Function',
function: effect.function.loweredFunc.func,
});
} else if (effect.kind === 'CreateFrom') {
state.createFrom(index++, effect.from, effect.into);
} else if (effect.kind === 'Assign') {
/**
* TODO: Invariant that the node is not initialized yet
*
* InferFunctionExpressionAliasingEffectSignatures currently infers
* Assign effects in some places that should be Alias, leading to
* Assign effects that reinitialize a value. The end result appears to
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does inferMutationAliasingRanges() do?
inferMutationAliasingRanges() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts.
Where is inferMutationAliasingRanges() defined?
inferMutationAliasingRanges() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts at line 74.
What does inferMutationAliasingRanges() call?
inferMutationAliasingRanges() calls 16 function(s): Err, Ok, assertExhaustive, assign, capture, create, createFrom, eachInstructionLValue, and 8 more.
What calls inferMutationAliasingRanges()?
inferMutationAliasingRanges() 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