Skip to main content

extract_function

Function extract_function 

Source
pub fn extract_function(
    stage: &Stage,
    expr_node: &NodeId,
    spec: ExtractFnSpec,
) -> Result<(Stage, Stage), TransformError>
Expand description

Extract a sub-expression from a fn body into a new top-level function (#280 slice 4). Returns (modified_source, new_fn): the original stage with the extracted expression replaced by a call to the new fn, and the new fn itself as a fresh Stage.

expr_node is the NodeId of the expression to extract. spec describes the new fn’s full signature; the transform verifies that spec.params covers exactly the free variables of the extracted expression — names must match. Type checking of the extracted body against the spec happens after the transform, in the apply path’s re-typecheck.

The replacement call site uses the parameter order from spec.params: f(a, b, c) for params = [a, b, c].