Expand description
Extract-function recipe: lift a region of code into a new function.
Uses CFG liveness data from the index to determine the correct parameter list and return type for the extracted function.
§Algorithm
- Query
cfg_blocksto find all blocks whose line range overlaps the selected region. - Run a backward-dataflow liveness pass over the whole function to
compute
live_in[B]/live_out[B]for every block. - Derive:
- parameters = ∪(live_in[B] for B in R) ∩ vars_defined_outside_R
- return vars = ∪(live_out[B] for B in exit_blocks(R)) ∩ vars_defined_in_R
- Inspect
cfg_effectsin the region to detectasync/generator/defer/acquire. - Inspect
cfg_edgesforEdgeKind::Exceptionedges that leave the region. - Generate language-appropriate source text and produce a
RefactoringPlan.
Structs§
- Extract
Function Outcome - Outcome of a successful extract-function plan.
- Parameter
- A parameter of the extracted function.
Enums§
- Extraction
Warning - A warning emitted when the extraction may produce semantically surprising code.
- Return
Type - Return type of the extracted function.
Functions§
- parse_
line_ range - Parse a
"start-end"line-range string (e.g."10-25") into(start, end). Lines are 1-based inclusive. - plan_
extract_ function - Build an extract-function plan without touching the filesystem.