getReversePostorderedBlocks() — react Function Reference
Architecture documentation for the getReversePostorderedBlocks() function in HIRBuilder.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 7833545a_a3bd_6148_f79c_09179baa11a3["getReversePostorderedBlocks()"] df6865e0_b573_e905_84d6_4eb6b419a888["HIRBuilder.ts"] 7833545a_a3bd_6148_f79c_09179baa11a3 -->|defined in| df6865e0_b573_e905_84d6_4eb6b419a888 5dec5bb8_e0f9_d79d_1c1d_65a05ff57391["build()"] 5dec5bb8_e0f9_d79d_1c1d_65a05ff57391 -->|calls| 7833545a_a3bd_6148_f79c_09179baa11a3 0ed953ae_5345_6a11_8ecf_c387365fdf84["reversePostorderBlocks()"] 0ed953ae_5345_6a11_8ecf_c387365fdf84 -->|calls| 7833545a_a3bd_6148_f79c_09179baa11a3 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 7833545a_a3bd_6148_f79c_09179baa11a3 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e d737cb4c_53f4_75b4_2d58_268e2f73fde4["eachTerminalSuccessor()"] 7833545a_a3bd_6148_f79c_09179baa11a3 -->|calls| d737cb4c_53f4_75b4_2d58_268e2f73fde4 127c19ef_021e_5644_a84e_da0d0ed84999["terminalFallthrough()"] 7833545a_a3bd_6148_f79c_09179baa11a3 -->|calls| 127c19ef_021e_5644_a84e_da0d0ed84999 53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"] 7833545a_a3bd_6148_f79c_09179baa11a3 -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb style 7833545a_a3bd_6148_f79c_09179baa11a3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts lines 723–810
function getReversePostorderedBlocks(func: HIR): HIR['blocks'] {
const visited: Set<BlockId> = new Set();
const used: Set<BlockId> = new Set();
const usedFallthroughs: Set<BlockId> = new Set();
const postorder: Array<BlockId> = [];
function visit(blockId: BlockId, isUsed: boolean): void {
const wasUsed = used.has(blockId);
const wasVisited = visited.has(blockId);
visited.add(blockId);
if (isUsed) {
used.add(blockId);
}
if (wasVisited && (wasUsed || !isUsed)) {
return;
}
/*
* Note that we visit successors in reverse order. This ensures that when we
* reverse the list at the end, that "sibling" edges appear in-order. For example,
* ```
* // bb0
* let x;
* if (c) {
* // bb1
* x = 1;
* } else {
* // bb2
* x = 2;
* }
* // bb3
* x;
* ```
*
* We want the output to be bb0, bb1, bb2, bb3 just to line up with the original
* program order for visual debugging. By visiting the successors in reverse order
* (eg bb2 then bb1), we ensure that they get reversed back to the correct order.
*/
const block = func.blocks.get(blockId)!;
CompilerError.invariant(block != null, {
reason: '[HIRBuilder] Unexpected null block',
description: `expected block ${blockId} to exist`,
loc: GeneratedSource,
});
const successors = [...eachTerminalSuccessor(block.terminal)].reverse();
const fallthrough = terminalFallthrough(block.terminal);
/**
* Fallthrough blocks are only used to record original program block structure. If the
* fallthrough is actually reachable, it will be reached through terminal successors.
* To retain program structure, we visit fallthrough blocks first (marking them as not
* actually used yet) to ensure their block IDs emitted in the correct order.
*/
if (fallthrough != null) {
if (isUsed) {
usedFallthroughs.add(fallthrough);
}
visit(fallthrough, false);
}
for (const successor of successors) {
visit(successor, isUsed);
}
if (!wasVisited) {
postorder.push(blockId);
}
}
visit(func.entry, true);
const blocks = new Map<BlockId, BasicBlock>();
for (const blockId of postorder.reverse()) {
const block = func.blocks.get(blockId)!;
if (used.has(blockId)) {
blocks.set(blockId, func.blocks.get(blockId)!);
} else if (usedFallthroughs.has(blockId)) {
blocks.set(blockId, {
...block,
instructions: [],
terminal: {
kind: 'unreachable',
id: block.terminal.id,
loc: block.terminal.loc,
},
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getReversePostorderedBlocks() do?
getReversePostorderedBlocks() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts.
Where is getReversePostorderedBlocks() defined?
getReversePostorderedBlocks() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts at line 723.
What does getReversePostorderedBlocks() call?
getReversePostorderedBlocks() calls 4 function(s): eachTerminalSuccessor, invariant, push, terminalFallthrough.
What calls getReversePostorderedBlocks()?
getReversePostorderedBlocks() is called by 2 function(s): build, reversePostorderBlocks.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free