Optimize Stmt/Expr reflections.
This commit is contained in:
parent
427af14f1b
commit
00b1051732
@ -408,6 +408,11 @@ fn optimize_stmt(stmt: Stmt, state: &mut State, preserve_result: bool) -> Stmt {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
// expr;
|
// expr;
|
||||||
|
Stmt::Expr(Expr::Stmt(x)) if matches!(x.0, Stmt::Expr(_)) => {
|
||||||
|
state.set_dirty();
|
||||||
|
optimize_stmt(x.0, state, preserve_result)
|
||||||
|
}
|
||||||
|
// expr;
|
||||||
Stmt::Expr(expr) => Stmt::Expr(optimize_expr(expr, state)),
|
Stmt::Expr(expr) => Stmt::Expr(optimize_expr(expr, state)),
|
||||||
// return expr;
|
// return expr;
|
||||||
Stmt::ReturnWithVal(ret, Some(expr), pos) => {
|
Stmt::ReturnWithVal(ret, Some(expr), pos) => {
|
||||||
@ -432,20 +437,20 @@ fn optimize_expr(expr: Expr, state: &mut State) -> Expr {
|
|||||||
match expr {
|
match expr {
|
||||||
// expr - do not promote because there is a reason it is wrapped in an `Expr::Expr`
|
// expr - do not promote because there is a reason it is wrapped in an `Expr::Expr`
|
||||||
Expr::Expr(x) => Expr::Expr(Box::new(optimize_expr(*x, state))),
|
Expr::Expr(x) => Expr::Expr(Box::new(optimize_expr(*x, state))),
|
||||||
// ( stmt )
|
// { stmt }
|
||||||
Expr::Stmt(x) => match optimize_stmt(x.0, state, true) {
|
Expr::Stmt(x) => match x.0 {
|
||||||
// ( Noop ) -> ()
|
// {} -> ()
|
||||||
Stmt::Noop(_) => {
|
Stmt::Noop(_) => {
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
Expr::Unit(x.1)
|
Expr::Unit(x.1)
|
||||||
}
|
}
|
||||||
// ( expr ) -> expr
|
// { expr } -> expr
|
||||||
Stmt::Expr(expr) => {
|
Stmt::Expr(expr) => {
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
expr
|
optimize_expr(expr, state)
|
||||||
}
|
}
|
||||||
// ( stmt )
|
// { stmt }
|
||||||
stmt => Expr::Stmt(Box::new((stmt, x.1))),
|
stmt => Expr::Stmt(Box::new((optimize_stmt(stmt, state, true), x.1))),
|
||||||
},
|
},
|
||||||
|
|
||||||
// lhs.rhs
|
// lhs.rhs
|
||||||
|
Loading…
Reference in New Issue
Block a user