Skip to main content

Module extract_function

Module extract_function 

Source
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

  1. Query cfg_blocks to find all blocks whose line range overlaps the selected region.
  2. Run a backward-dataflow liveness pass over the whole function to compute live_in[B] / live_out[B] for every block.
  3. 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
  4. Inspect cfg_effects in the region to detect async/generator/defer/acquire.
  5. Inspect cfg_edges for EdgeKind::Exception edges that leave the region.
  6. Generate language-appropriate source text and produce a RefactoringPlan.

Structs§

ExtractFunctionOutcome
Outcome of a successful extract-function plan.
Parameter
A parameter of the extracted function.

Enums§

ExtractionWarning
A warning emitted when the extraction may produce semantically surprising code.
ReturnType
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.