Driver Class — react Architecture
Architecture documentation for the Driver class in BuildReactiveFunction.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD e20dc57f_069b_7065_293d_92b4bae116ae["Driver"] 3e304366_7140_93cb_47c8_0d400140265a["BuildReactiveFunction.ts"] e20dc57f_069b_7065_293d_92b4bae116ae -->|defined in| 3e304366_7140_93cb_47c8_0d400140265a cce4e4fc_39be_5587_f09f_a3c65d0bac5a["constructor()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| cce4e4fc_39be_5587_f09f_a3c65d0bac5a 632db8c1_f225_c12d_1878_21c605802e1a["wrapWithSequence()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 632db8c1_f225_c12d_1878_21c605802e1a a043b9e3_4ef5_e5b0_f9fd_9ba1c267ff17["extractValueBlockResult()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| a043b9e3_4ef5_e5b0_f9fd_9ba1c267ff17 94607a28_ed02_b0d5_72b8_7b074efdebad["valueBlockResultToSequence()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 94607a28_ed02_b0d5_72b8_7b074efdebad de2e8e2f_72ef_875e_8240_38a6fb22ff0b["traverseBlock()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| de2e8e2f_72ef_875e_8240_38a6fb22ff0b 59c4bc0e_ec5f_af0c_d67c_d518b3f117bc["visitBlock()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 59c4bc0e_ec5f_af0c_d67c_d518b3f117bc 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66["visitValueBlock()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 bae7b350_498b_eec1_68c2_7ca15568b2bb["visitTestBlock()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| bae7b350_498b_eec1_68c2_7ca15568b2bb 69119c39_6bb5_7c2b_0712_73f7e045a58d["visitValueBlockTerminal()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 69119c39_6bb5_7c2b_0712_73f7e045a58d 14cac00b_2abe_f917_5c8f_e34a72cd5047["emptyBlock()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 14cac00b_2abe_f917_5c8f_e34a72cd5047 f1ad8882_f4aa_8bed_3eb6_757cd4990fab["visitBreak()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| f1ad8882_f4aa_8bed_3eb6_757cd4990fab 2b0607db_4995_18d7_b551_6ff462406377["visitContinue()"] e20dc57f_069b_7065_293d_92b4bae116ae -->|method| 2b0607db_4995_18d7_b551_6ff462406377
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts lines 59–1245
class Driver {
cx: Context;
constructor(cx: Context) {
this.cx = cx;
}
/*
* Wraps a continuation result with preceding instructions. If there are no
* instructions, returns the continuation as-is. Otherwise, wraps the continuation's
* value in a SequenceExpression with the instructions prepended.
*/
wrapWithSequence(
instructions: Array<ReactiveInstruction>,
continuation: {
block: BlockId;
value: ReactiveValue;
place: Place;
id: InstructionId;
},
loc: SourceLocation,
): {block: BlockId; value: ReactiveValue; place: Place; id: InstructionId} {
if (instructions.length === 0) {
return continuation;
}
const sequence: ReactiveSequenceValue = {
kind: 'SequenceExpression',
instructions,
id: continuation.id,
value: continuation.value,
loc,
};
return {
block: continuation.block,
value: sequence,
place: continuation.place,
id: continuation.id,
};
}
/*
* Extracts the result value from instructions at the end of a value block.
* Value blocks generally end in a StoreLocal to assign the value of the
* expression. These StoreLocal instructions can be pruned since we represent
* value blocks as compound values in ReactiveFunction (no phis). However,
* it's also possible to have a value block that ends in an AssignmentExpression,
* which we need to keep. So we only prune StoreLocal for temporaries.
*/
extractValueBlockResult(
instructions: BasicBlock['instructions'],
blockId: BlockId,
loc: SourceLocation,
): {block: BlockId; place: Place; value: ReactiveValue; id: InstructionId} {
CompilerError.invariant(instructions.length !== 0, {
reason: `Expected non-empty instructions in extractValueBlockResult`,
description: null,
loc,
});
const instr = instructions.at(-1)!;
let place: Place = instr.lvalue;
let value: ReactiveValue = instr.value;
if (
value.kind === 'StoreLocal' &&
value.lvalue.place.identifier.name === null
) {
place = value.lvalue.place;
value = {
kind: 'LoadLocal',
place: value.value,
loc: value.value.loc,
};
}
if (instructions.length === 1) {
return {block: blockId, place, value, id: instr.id};
}
const sequence: ReactiveSequenceValue = {
kind: 'SequenceExpression',
instructions: instructions.slice(0, -1),
id: instr.id,
value,
loc,
Domain
Defined In
Source
Frequently Asked Questions
What is the Driver class?
Driver is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts.
Where is Driver defined?
Driver is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts at line 59.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free