fix(tvix/eval): compile but don't emit dead code
This adds a mechanism to the compiler to compile an expression without emitting any code. This allows for detected dead code to still be compiled to detect errors & warnings inside of it. Change-Id: Ie78479173570e9c819d8f32ae683ce34234a4c5d Reviewed-on: https://cl.tvl.fyi/c/depot/+/7767 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
6a8541e35a
commit
e8dcdceb34
2 changed files with 33 additions and 9 deletions
|
|
@ -6,9 +6,9 @@ use super::*;
|
|||
use ast::Expr;
|
||||
|
||||
/// Optimise the given expression where possible.
|
||||
pub(super) fn optimise_expr(c: &mut Compiler, expr: ast::Expr) -> 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, expr),
|
||||
Expr::BinOp(_) => optimise_bin_op(c, slot, expr),
|
||||
_ => expr.to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ fn is_lit_bool(expr: ast::Expr) -> LitBool {
|
|||
}
|
||||
|
||||
/// Detect useless binary operations (i.e. useless bool comparisons).
|
||||
fn optimise_bin_op(c: &mut Compiler, expr: ast::Expr) -> ast::Expr {
|
||||
fn optimise_bin_op(c: &mut Compiler, slot: LocalIdx, expr: ast::Expr) -> ast::Expr {
|
||||
use ast::BinOpKind;
|
||||
|
||||
// bail out of this check if the user has poisoned either `true`
|
||||
|
|
@ -82,8 +82,7 @@ fn optimise_bin_op(c: &mut Compiler, expr: ast::Expr) -> ast::Expr {
|
|||
WarningKind::UselessBoolOperation("this expression is always true"),
|
||||
);
|
||||
|
||||
// TODO: still compile other to get errors/warnings from there, but don't emit
|
||||
c.emit_warning(&other, WarningKind::DeadCode);
|
||||
c.compile_dead_code(slot, other);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
@ -104,8 +103,7 @@ fn optimise_bin_op(c: &mut Compiler, expr: ast::Expr) -> ast::Expr {
|
|||
WarningKind::UselessBoolOperation("this expression is always false"),
|
||||
);
|
||||
|
||||
// TODO: still compile other to get errors/warnings from there, but don't emit
|
||||
c.emit_warning(&other, WarningKind::DeadCode);
|
||||
c.compile_dead_code(slot, other);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue