Refactor: Optimize block handling in optimizer
The optimizer now correctly handles empty blocks by collapsing them into Nop nodes. It also unwraps blocks containing a single expression, making the AST more concise. This change improves AST simplification by ensuring that redundant block structures are removed.
This commit is contained in:
@@ -562,10 +562,6 @@ impl Optimizer {
|
||||
new_exprs.push(opt);
|
||||
}
|
||||
|
||||
if !block_changed {
|
||||
return node_rc;
|
||||
}
|
||||
|
||||
if self.enabled {
|
||||
if new_exprs.is_empty() {
|
||||
return Rc::new(folder.make_nop_node(node));
|
||||
@@ -574,6 +570,10 @@ impl Optimizer {
|
||||
}
|
||||
}
|
||||
|
||||
if !block_changed {
|
||||
return node_rc;
|
||||
}
|
||||
|
||||
(NodeKind::Block { exprs: new_exprs }, node.ty.clone())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user