inferBlock() — react Function Reference
Architecture documentation for the inferBlock() function in InferMutationAliasingEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD ac82e9ee_09bc_b58c_f2ac_86bf2d552540["inferBlock()"] d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea["inferMutationAliasingEffects()"] 1f2853c7_05e1_f3c4_b9d5_1f5ca0f648ea -->|calls| ac82e9ee_09bc_b58c_f2ac_86bf2d552540 4731f41f_7c10_ab87_ad4e_bf2ac6809c5b["inferPhi()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 4731f41f_7c10_ab87_ad4e_bf2ac6809c5b a00426de_5aa3_d680_a1fe_29201ff58984["computeSignatureForInstruction()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| a00426de_5aa3_d680_a1fe_29201ff58984 f255dd41_8c48_19a9_1bcc_8efd2d663f32["applySignature()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| f255dd41_8c48_19a9_1bcc_8efd2d663f32 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e 8f06f55e_0851_0d44_0a89_d6dee31fdbb5["kind()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 8f06f55e_0851_0d44_0a89_d6dee31fdbb5 f22aa897_9419_712a_d84d_eb9e8581801f["throw()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| f22aa897_9419_712a_d84d_eb9e8581801f 7cb90dd3_dbe0_0087_670d_277ddeadabfc["applyEffect()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 7cb90dd3_dbe0_0087_670d_277ddeadabfc 6184f2b6_7ea4_aff3_4588_a9af7d7fdf3c["appendAlias()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 6184f2b6_7ea4_aff3_4588_a9af7d7fdf3c 97fe1d23_4f7c_ef28_ca5a_de2c6e376163["internEffect()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 97fe1d23_4f7c_ef28_ca5a_de2c6e376163 53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"] ac82e9ee_09bc_b58c_f2ac_86bf2d552540 -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb style ac82e9ee_09bc_b58c_f2ac_86bf2d552540 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 486–561
function inferBlock(
context: Context,
state: InferenceState,
block: BasicBlock,
): void {
for (const phi of block.phis) {
state.inferPhi(phi);
}
for (const instr of block.instructions) {
let instructionSignature = context.instructionSignatureCache.get(instr);
if (instructionSignature == null) {
instructionSignature = computeSignatureForInstruction(
context,
state.env,
instr,
);
context.instructionSignatureCache.set(instr, instructionSignature);
}
const effects = applySignature(context, state, instructionSignature, instr);
instr.effects = effects;
}
const terminal = block.terminal;
if (terminal.kind === 'try' && terminal.handlerBinding != null) {
context.catchHandlers.set(terminal.handler, terminal.handlerBinding);
} else if (terminal.kind === 'maybe-throw' && terminal.handler !== null) {
const handlerParam = context.catchHandlers.get(terminal.handler);
if (handlerParam != null) {
CompilerError.invariant(state.kind(handlerParam) != null, {
reason:
'Expected catch binding to be intialized with a DeclareLocal Catch instruction',
loc: terminal.loc,
});
const effects: Array<AliasingEffect> = [];
for (const instr of block.instructions) {
if (
instr.value.kind === 'CallExpression' ||
instr.value.kind === 'MethodCall'
) {
/**
* Many instructions can error, but only calls can throw their result as the error
* itself. For example, `c = a.b` can throw if `a` is nullish, but the thrown value
* is an error object synthesized by the JS runtime. Whereas `throwsInput(x)` can
* throw (effectively) the result of the call.
*
* TODO: call applyEffect() instead. This meant that the catch param wasn't inferred
* as a mutable value, though. See `try-catch-try-value-modified-in-catch-escaping.js`
* fixture as an example
*/
state.appendAlias(handlerParam, instr.lvalue);
const kind = state.kind(instr.lvalue).kind;
if (kind === ValueKind.Mutable || kind == ValueKind.Context) {
effects.push(
context.internEffect({
kind: 'Alias',
from: instr.lvalue,
into: handlerParam,
}),
);
}
}
}
terminal.effects = effects.length !== 0 ? effects : null;
}
} else if (terminal.kind === 'return') {
if (!context.isFuctionExpression) {
terminal.effects = [
context.internEffect({
kind: 'Freeze',
value: terminal.value,
reason: ValueReason.JsxCaptured,
}),
];
}
}
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does inferBlock() do?
inferBlock() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is inferBlock() defined?
inferBlock() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 486.
What does inferBlock() call?
inferBlock() calls 10 function(s): appendAlias, applyEffect, applySignature, computeSignatureForInstruction, inferPhi, internEffect, invariant, kind, and 2 more.
What calls inferBlock()?
inferBlock() 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