rewriteInstructionKindsBasedOnReassignment() — react Function Reference
Architecture documentation for the rewriteInstructionKindsBasedOnReassignment() function in RewriteInstructionKindsBasedOnReassignment.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49["rewriteInstructionKindsBasedOnReassignment()"] 11a22739_6713_26cd_7efc_ba4dab5043a4["RewriteInstructionKindsBasedOnReassignment.ts"] f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49 -->|defined in| 11a22739_6713_26cd_7efc_ba4dab5043a4 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e bf7f1cf7_fc0e_6bac_827c_8d36d98126da["printPlace()"] f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49 -->|calls| bf7f1cf7_fc0e_6bac_827c_8d36d98126da f5637d03_fd91_50b8_9da7_b2a24c91bab7["eachPatternOperand()"] f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49 -->|calls| f5637d03_fd91_50b8_9da7_b2a24c91bab7 style f1ab4a04_b3ae_c2ef_cecf_f39e8b62bb49 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/SSA/RewriteInstructionKindsBasedOnReassignment.ts lines 31–168
export function rewriteInstructionKindsBasedOnReassignment(
fn: HIRFunction,
): void {
const declarations = new Map<DeclarationId, LValue | LValuePattern>();
for (const param of fn.params) {
let place: Place = param.kind === 'Identifier' ? param : param.place;
if (place.identifier.name !== null) {
declarations.set(place.identifier.declarationId, {
kind: InstructionKind.Let,
place,
});
}
}
for (const place of fn.context) {
if (place.identifier.name !== null) {
declarations.set(place.identifier.declarationId, {
kind: InstructionKind.Let,
place,
});
}
}
for (const [, block] of fn.body.blocks) {
for (const instr of block.instructions) {
const {value} = instr;
switch (value.kind) {
case 'DeclareLocal': {
const lvalue = value.lvalue;
CompilerError.invariant(
!declarations.has(lvalue.place.identifier.declarationId),
{
reason: `Expected variable not to be defined prior to declaration`,
description: `${printPlace(lvalue.place)} was already defined`,
loc: lvalue.place.loc,
},
);
declarations.set(lvalue.place.identifier.declarationId, lvalue);
break;
}
case 'StoreLocal': {
const lvalue = value.lvalue;
if (lvalue.place.identifier.name !== null) {
const declaration = declarations.get(
lvalue.place.identifier.declarationId,
);
if (declaration === undefined) {
CompilerError.invariant(
!declarations.has(lvalue.place.identifier.declarationId),
{
reason: `Expected variable not to be defined prior to declaration`,
description: `${printPlace(lvalue.place)} was already defined`,
loc: lvalue.place.loc,
},
);
declarations.set(lvalue.place.identifier.declarationId, lvalue);
lvalue.kind = InstructionKind.Const;
} else {
declaration.kind = InstructionKind.Let;
lvalue.kind = InstructionKind.Reassign;
}
}
break;
}
case 'Destructure': {
const lvalue = value.lvalue;
let kind: InstructionKind | null = null;
for (const place of eachPatternOperand(lvalue.pattern)) {
if (place.identifier.name === null) {
CompilerError.invariant(
kind === null || kind === InstructionKind.Const,
{
reason: `Expected consistent kind for destructuring`,
description: `other places were \`${kind}\` but '${printPlace(
place,
)}' is const`,
loc: place.loc,
},
);
kind = InstructionKind.Const;
} else {
const declaration = declarations.get(
place.identifier.declarationId,
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does rewriteInstructionKindsBasedOnReassignment() do?
rewriteInstructionKindsBasedOnReassignment() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/SSA/RewriteInstructionKindsBasedOnReassignment.ts.
Where is rewriteInstructionKindsBasedOnReassignment() defined?
rewriteInstructionKindsBasedOnReassignment() is defined in compiler/packages/babel-plugin-react-compiler/src/SSA/RewriteInstructionKindsBasedOnReassignment.ts at line 31.
What does rewriteInstructionKindsBasedOnReassignment() call?
rewriteInstructionKindsBasedOnReassignment() calls 3 function(s): eachPatternOperand, invariant, printPlace.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free