chore(tvix/eval): delete "useless parenthesis" warning/optimisation
Two main reasons: 1. Traversing the structure to do this optimisation is actually *slower* than not optimising it. 2. There are literally hundreds of thousands of incidences of this in nixpkgs, and with some of the weird code there some of these (functionally) useless parens are actually required for readability reasons. Change-Id: I1044b1c5f9fe20df4b6085851fc3b191277c65dc Reviewed-on: https://cl.tvl.fyi/c/depot/+/7917 Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
d2f1a290a4
commit
9ecf668452
2 changed files with 0 additions and 30 deletions
|
@ -9,7 +9,6 @@ use ast::Expr;
|
|||
pub(super) fn optimise_expr(c: &mut Compiler, slot: LocalIdx, expr: ast::Expr) -> ast::Expr {
|
||||
match expr {
|
||||
Expr::BinOp(_) => optimise_bin_op(c, slot, expr),
|
||||
Expr::Paren(_) => optimise_paren(c, expr),
|
||||
_ => expr.to_owned(),
|
||||
}
|
||||
}
|
||||
|
@ -124,28 +123,3 @@ fn optimise_bin_op(c: &mut Compiler, slot: LocalIdx, expr: ast::Expr) -> ast::Ex
|
|||
|
||||
expr
|
||||
}
|
||||
|
||||
/// Detect useless parenthesis around primitive expressions.
|
||||
fn optimise_paren(c: &mut Compiler, expr: ast::Expr) -> ast::Expr {
|
||||
if let Expr::Paren(inner) = &expr {
|
||||
let inner = inner.expr().unwrap();
|
||||
|
||||
if let Expr::Paren(_) = &inner {
|
||||
c.emit_warning(&expr, WarningKind::UselessParens);
|
||||
return optimise_paren(c, inner);
|
||||
}
|
||||
|
||||
if let Expr::Literal(_)
|
||||
| Expr::Str(_)
|
||||
| Expr::Select(_)
|
||||
| Expr::List(_)
|
||||
| Expr::AttrSet(_)
|
||||
| Expr::Ident(_) = &inner
|
||||
{
|
||||
c.emit_warning(&expr, WarningKind::UselessParens);
|
||||
return inner;
|
||||
}
|
||||
}
|
||||
|
||||
expr
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ pub enum WarningKind {
|
|||
DeadCode,
|
||||
EmptyInherit,
|
||||
EmptyLet,
|
||||
UselessParens,
|
||||
|
||||
/// Tvix internal warning for features triggered by users that are
|
||||
/// not actually implemented yet, but do not cause runtime failures.
|
||||
|
@ -101,8 +100,6 @@ impl EvalWarning {
|
|||
|
||||
WarningKind::EmptyLet => "this `let`-expression contains no bindings".to_string(),
|
||||
|
||||
WarningKind::UselessParens => "these parenthesis can be removed".to_string(),
|
||||
|
||||
WarningKind::NotImplemented(what) => {
|
||||
format!("feature not yet implemented in tvix: {}", what)
|
||||
}
|
||||
|
@ -123,7 +120,6 @@ impl EvalWarning {
|
|||
WarningKind::DeadCode => "W008",
|
||||
WarningKind::EmptyInherit => "W009",
|
||||
WarningKind::EmptyLet => "W010",
|
||||
WarningKind::UselessParens => "W011",
|
||||
|
||||
WarningKind::NotImplemented(_) => "W999",
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue