Expand description
引擎内置通用规则:只依赖 Lang 抽象,任何语言 crate 均可复用。
每条规则文档化其语义前提;所有提案都必须严格降低成本(runner 校验)。
Structs§
- Arith
Identity - Arith
Reassoc - Arith
Zero - Assign
Back Fold - Assign
Propagation - BitIdentity
- Block
Flatten - 块展平:Block 的直接孩子是 Block 且内层无任何声明(VarDecl/ ForEach/Catch 绑定引入作用域)→ 内层语句上提。典型形态:try 剥壳、 CFF 还原后的裸嵌套块。无声明 ⇒ 无遮蔽 ⇒ 语义等价。
- Bool
Compare - Bool
NotFold - Bool
Short Circuit - Boolean
Return - CmpConst
Fold - Const
Condition - Const
Fold Bin - Dead
Decl - Dead
Store - Decl
Assign Merge - Double
NegFold - 数值双重取负:-(-x) → x(补码回绕下恒等:-(-MIN) ≡ MIN ≡ x); -(-lit) → |lit|(解析器不折负字面量的外层负)。
- Double
Not - IfAssign
Ternary - IfElse
Empty - IfTo
Ternary - Inverse
Assign Pair - Local
Propagation - Multi
UseCopy Propagation - NotCompare
- Paren
Removal - Self
Assign - Store
Kill - Ternary
Bool - Ternary
Bool Op - Ternary
Fold - Trailing
Continue - Trailing
Return - Unreachable
After Terminal
Functions§
- all_
rules - 全量规则(含 DCE 类选配项;按设计文档“可选配,默认不启用“)。
- collect_
stmt_ kill_ events - One DFS of a statement computing the dominating=true kill event for
every name that has one. Recursion order matches
scan_kill_event; the first event per name wins. Used by language crates to build a per-statement index so StoreKill does not rescan subtrees per candidate. - default_
rules - 默认规则(保守集:不做 DCE 类清理)。
- scan_
kill_ event - 扫描一个节点在
name上的事件。dominating:当前子树是否在必经路径上(If/While 的 cond、Ternary 的 cond、For 的 init/cond、非短路二元两侧 = true;分支体/循环体 = false)。