Fix optimizer bug for closures.

This commit is contained in:
Stephen Chung
2023-04-09 16:31:06 +08:00
parent 6ee4a1efa6
commit 8369a9bf63
2 changed files with 15 additions and 0 deletions

View File

@@ -840,6 +840,20 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
// return expr;
Stmt::Return(Some(ref mut expr), ..) => optimize_expr(expr, state, false),
// Share nothing
Stmt::Share(x) if x.is_empty() => {
state.set_dirty();
*stmt = Stmt::Noop(Position::NONE);
}
// Share constants
Stmt::Share(x) => {
let len = x.len();
x.retain(|(v, _, _)| !state.find_constant(v).is_some());
if x.len() != len {
state.set_dirty();
}
}
// All other statements - skip
_ => (),
}