Fix optimizer bug for closures.
This commit is contained in:
parent
6ee4a1efa6
commit
8369a9bf63
@ -10,6 +10,7 @@ Buf fixes
|
|||||||
----------
|
----------
|
||||||
|
|
||||||
* `is_shared` is a reserved keyword and is now handled properly (e.g. it cannot be the target of a function pointer).
|
* `is_shared` is a reserved keyword and is now handled properly (e.g. it cannot be the target of a function pointer).
|
||||||
|
* Re-optimizing an AST via `optimize_ast` with constants now works correctly for closures. Previously the hidden `Share` nodes are not removed and causes variable-not-found errors during runtime if the constants are not available in the scope.
|
||||||
|
|
||||||
New features
|
New features
|
||||||
------------
|
------------
|
||||||
|
@ -840,6 +840,20 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
|
|||||||
// return expr;
|
// return expr;
|
||||||
Stmt::Return(Some(ref mut expr), ..) => optimize_expr(expr, state, false),
|
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
|
// All other statements - skip
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user