Skip to main content

CompilerPass

Trait CompilerPass 

Source
pub trait CompilerPass<S: WorkflowState, M: MergeStrategy<S>>: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn run(&self, graph: &mut Graph<S, M>, ctx: &mut CompilerContext<S>) -> bool;
}
Expand description

编译器优化 pass trait。

每个 pass 负责一个特定的优化, 例如:内联、死代码消除、Barrier 合并等。

§示例

struct MyPass;

impl<S: WorkflowState, M: MergeStrategy<S>> CompilerPass<S, M> for MyPass {
    fn name(&self) -> &str {
        "my_pass"
    }

    fn run(&self, graph: &mut Graph<S, M>, ctx: &mut CompilerContext<S>) -> bool {
        // 优化逻辑
        false
    }
}

Required Methods§

Source

fn name(&self) -> &str

pass 的名称。

Source

fn run(&self, graph: &mut Graph<S, M>, ctx: &mut CompilerContext<S>) -> bool

执行优化 pass。

§参数
  • graph — 要优化的图(可变引用)
  • ctx — 编译上下文,包含配置和统计信息
§返回

如果 pass 修改了图,返回 true; 否则返回 false

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§