about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/optimiser.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-05T12·25+0300
committertazjin <tazjin@tvl.su>2023-01-06T12·23+0000
commite8dcdceb34585dfe82d826978f0f1cd8a673b474 (patch)
tree2a244d378915c0253a4daa52f71b7394c5a40aec /tvix/eval/src/compiler/optimiser.rs
parent6a8541e35a76b1d0d100c505d395d0e0418377c7 (diff)
fix(tvix/eval): compile but don't emit dead code r/5603
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
Diffstat (limited to 'tvix/eval/src/compiler/optimiser.rs')
-rw-r--r--tvix/eval/src/compiler/optimiser.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/tvix/eval/src/compiler/optimiser.rs b/tvix/eval/src/compiler/optimiser.rs
index 533b6c540c25..615de32357e6 100644
--- a/tvix/eval/src/compiler/optimiser.rs
+++ b/tvix/eval/src/compiler/optimiser.rs
@@ -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;
             }