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:
2026-03-26 13:44:38 +01:00
parent 273dc83d68
commit 78813e7197
2 changed files with 49 additions and 4 deletions
+4 -4
View File
@@ -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())
}