Skip to main content

Rule

Trait Rule 

Source
pub trait Rule<L: Lang> {
    // Required methods
    fn name(&self) -> &'static str;
    fn check(&self, ctx: RewriteCtx<'_, L>, id: L::Id) -> Option<Edit<L>>;

    // Provided methods
    fn kinds(&self) -> &'static [NodeKind] { ... }
    fn structural(&self) -> bool { ... }
}
Expand description

一条简化规则。

Required Methods§

Source

fn name(&self) -> &'static str

Source

fn check(&self, ctx: RewriteCtx<'_, L>, id: L::Id) -> Option<Edit<L>>

在节点 id 处检查是否可改写。 契约:只读既有结构(可向 arena 追加新节点);结构变更只经 Edit 提案。

Provided Methods§

Source

fn kinds(&self) -> &'static [NodeKind]

本规则关注的节点类别(空 = 全部类别)。pass 循环按类别建分派桶, 无关节点直接跳过检查——“全部规则 × 每节点一次虚调用“是扫描主开销。 声明必须覆盖 check() 入口的真实类别判定:多报只是浪费检查(正确), 漏报会让规则失效(漏改写,回归测试会暴露)。

Source

fn structural(&self) -> bool

结构性规则:豁免成本严格下降约束。 适用于“内联后暂时变贵、由后续折叠回本“的变换(如方法内联)。 实现方必须自证终止(如:每次消费一类节点且不引入新的同类节点)。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<L: Lang> Rule<L> for ArithIdentity

Source§

impl<L: Lang> Rule<L> for ArithReassoc

Source§

impl<L: Lang> Rule<L> for ArithZero

Source§

impl<L: Lang> Rule<L> for AssignBackFold

Source§

impl<L: Lang> Rule<L> for AssignPropagation

Source§

impl<L: Lang> Rule<L> for BitIdentity

Source§

impl<L: Lang> Rule<L> for BlockFlatten

Source§

impl<L: Lang> Rule<L> for BoolCompare

Source§

impl<L: Lang> Rule<L> for BoolNotFold

Source§

impl<L: Lang> Rule<L> for BoolShortCircuit

Source§

impl<L: Lang> Rule<L> for BooleanReturn

Source§

impl<L: Lang> Rule<L> for CmpConstFold

Source§

impl<L: Lang> Rule<L> for ConstCondition

Source§

impl<L: Lang> Rule<L> for ConstFoldBin

Source§

impl<L: Lang> Rule<L> for DeadDecl

Source§

impl<L: Lang> Rule<L> for DeadStore

Source§

impl<L: Lang> Rule<L> for DeclAssignMerge

Source§

impl<L: Lang> Rule<L> for DoubleNegFold

Source§

impl<L: Lang> Rule<L> for DoubleNot

Source§

impl<L: Lang> Rule<L> for IfAssignTernary

Source§

impl<L: Lang> Rule<L> for IfElseEmpty

Source§

impl<L: Lang> Rule<L> for IfToTernary

Source§

impl<L: Lang> Rule<L> for InverseAssignPair

Source§

impl<L: Lang> Rule<L> for LocalPropagation

Source§

impl<L: Lang> Rule<L> for MultiUseCopyPropagation

Source§

impl<L: Lang> Rule<L> for NotCompare

Source§

impl<L: Lang> Rule<L> for ParenRemoval

Source§

impl<L: Lang> Rule<L> for SelfAssign

Source§

impl<L: Lang> Rule<L> for StoreKill

Source§

impl<L: Lang> Rule<L> for TernaryBool

Source§

impl<L: Lang> Rule<L> for TernaryBoolOp

Source§

impl<L: Lang> Rule<L> for TernaryFold

Source§

impl<L: Lang> Rule<L> for TrailingContinue

Source§

impl<L: Lang> Rule<L> for TrailingReturn

Source§

impl<L: Lang> Rule<L> for UnreachableAfterTerminal