SSABuilder Class — react Architecture
Architecture documentation for the SSABuilder class in EnterSSA.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD f11adc00_6af6_2575_4ee8_974e26f2a6ed["SSABuilder"] 1aa7ee2e_5f6c_b797_fe10_9a09d30a5e12["EnterSSA.ts"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|defined in| 1aa7ee2e_5f6c_b797_fe10_9a09d30a5e12 1dbd3f72_5a05_f813_1248_92d655d26c9b["constructor()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 1dbd3f72_5a05_f813_1248_92d655d26c9b 7774c611_852e_feb7_3f2c_84010df85138["nextSsaId()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 7774c611_852e_feb7_3f2c_84010df85138 4e2bd58f_f439_41c9_5de4_16f463bd64b7["defineFunction()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 4e2bd58f_f439_41c9_5de4_16f463bd64b7 1cc91427_b243_17f1_f757_5baf28229c77["enter()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 1cc91427_b243_17f1_f757_5baf28229c77 22130362_6f7b_966d_4373_b384767b7acf["state()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 22130362_6f7b_966d_4373_b384767b7acf dde21261_8a25_cb71_4e56_b0eb6348704b["makeId()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| dde21261_8a25_cb71_4e56_b0eb6348704b e8a9db95_a3f8_ba5e_4289_87022b3ec4e0["defineContext()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| e8a9db95_a3f8_ba5e_4289_87022b3ec4e0 1bda4538_293e_48ce_ea89_3160033e51b6["definePlace()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 1bda4538_293e_48ce_ea89_3160033e51b6 9038f078_e688_0fe0_26fd_2eb655330c6f["getPlace()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 9038f078_e688_0fe0_26fd_2eb655330c6f ab76c4b1_9d69_98c8_d44f_9505c6f4c84e["getIdAt()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| ab76c4b1_9d69_98c8_d44f_9505c6f4c84e 239be53b_dfd4_96c6_9550_ca5aa6b80da2["addPhi()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 239be53b_dfd4_96c6_9550_ca5aa6b80da2 6504c0db_f212_8c3b_f87a_9a785dbe810d["fixIncompletePhis()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 6504c0db_f212_8c3b_f87a_9a785dbe810d 978204e9_69a1_fb3c_25d5_8786bc240205["startBlock()"] f11adc00_6af6_2575_4ee8_974e26f2a6ed -->|method| 978204e9_69a1_fb3c_25d5_8786bc240205
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts lines 40–238
class SSABuilder {
#states: Map<BasicBlock, State> = new Map();
#current: BasicBlock | null = null;
unsealedPreds: Map<BasicBlock, number> = new Map();
#blocks: Map<BlockId, BasicBlock>;
#env: Environment;
#unknown: Set<Identifier> = new Set();
#context: Set<Identifier> = new Set();
constructor(env: Environment, blocks: ReadonlyMap<BlockId, BasicBlock>) {
this.#blocks = new Map(blocks);
this.#env = env;
}
get nextSsaId(): IdentifierId {
return this.#env.nextIdentifierId;
}
defineFunction(func: HIRFunction): void {
for (const [id, block] of func.body.blocks) {
this.#blocks.set(id, block);
}
}
enter(fn: () => void): void {
const current = this.#current;
fn();
this.#current = current;
}
state(): State {
CompilerError.invariant(this.#current !== null, {
reason: 'we need to be in a block to access state!',
loc: GeneratedSource,
});
return this.#states.get(this.#current)!;
}
makeId(oldId: Identifier): Identifier {
return {
id: this.nextSsaId,
declarationId: oldId.declarationId,
name: oldId.name,
mutableRange: {
start: makeInstructionId(0),
end: makeInstructionId(0),
},
scope: null, // reset along w the mutable range
type: makeType(),
loc: oldId.loc,
};
}
defineContext(oldPlace: Place): Place {
const newPlace = this.definePlace(oldPlace);
this.#context.add(oldPlace.identifier);
return newPlace;
}
definePlace(oldPlace: Place): Place {
const oldId = oldPlace.identifier;
if (this.#unknown.has(oldId)) {
CompilerError.throwTodo({
reason: `[hoisting] EnterSSA: Expected identifier to be defined before being used`,
description: `Identifier ${printIdentifier(oldId)} is undefined`,
loc: oldPlace.loc,
suggestions: null,
});
}
// Do not redefine context references.
if (this.#context.has(oldId)) {
return this.getPlace(oldPlace);
}
const newId = this.makeId(oldId);
this.state().defs.set(oldId, newId);
return {
...oldPlace,
identifier: newId,
};
Domain
Source
Frequently Asked Questions
What is the SSABuilder class?
SSABuilder is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts.
Where is SSABuilder defined?
SSABuilder is defined in compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts at line 40.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free