Skip to main content

rewrite_morph

Function rewrite_morph 

Source
pub fn rewrite_morph<'a>(
    model: Model,
    rule_sets: &Vec<&'a RuleSet<'a>>,
    prop_multiple_equally_applicable: bool,
) -> Model
Expand description

Rewrites a Model by applying rule sets using an optimized, tree-morphing rewriter.

This function traverses the expression tree of the model and applies the given rules to transform it. It operates on the model’s internal structure, replacing the root expression and updating the symbol table based on the transformations performed by the morph function.

§Parameters

  • model: The Model to be rewritten. It is consumed and a new, transformed version is returned.
  • rule_sets: A vector of RuleSet references containing the rules for transformation. These rules are grouped by priority before being applied.
  • prop_multiple_equally_applicable: A boolean flag to control behavior when multiple rules of the same priority can be applied to the same expression.
    • If true, the rewriter will use a selection strategy (select_panic) that panics.
    • If false, the rewriter will use a selection strategy (select_first) that simply picks the first applicable rule it encounters.

§Returns

The rewritten Model after all applicable rules have been applied.

§Panics

This function will panic under two conditions:

  • If the internal grouping of rules by priority fails (from get_rules_grouped).
  • If prop_multiple_equally_applicable is set to true and more than one rule of the same priority can be applied to the same expression.