From c9c8b103701411eddcc00955d30eaa667091963f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 3 Feb 2023 12:38:41 +0100 Subject: feat(tvix/eval): don't warn twice about dead code We currently send two warnings in case of detecting dead code - W008 inside compile_dead_code, and a more detailed warning in all places that invoke compile_dead_code: ``` warning[W007]: useless operation on boolean: this expression is always false --> /nix/store/qz3gjn95gazab4fkb7s8lm6hz17rdzzy-414z9nnj1wy66ymq6vgb693x9xjz6hf2-nixpkgs-src/pkgs/top-level/perl-packages.nix:12079:15 | 12079 | doCheck = false && !stdenv.isDarwin; | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning[W008]: this code will never be executed --> /nix/store/qz3gjn95gazab4fkb7s8lm6hz17rdzzy-414z9nnj1wy66ymq6vgb693x9xjz6hf2-nixpkgs-src/pkgs/top-level/perl-packages.nix:12079:24 | 12079 | doCheck = false && !stdenv.isDarwin; | ^^^^^^^^^^^^^^^^ ``` The place invoking `compile_dead_code` has more context to why the code is unused, so it's error message is much more useful. Stop emitting the less informative warning inside compile_dead_code (W008), and update the comment that we expect the caller to emit a warning. I kept W008 itself still around, in case we end up having places this will get used again. Change-Id: I2c5d84fc0cb4035872cd4b71cc3e9e34e120eb37 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8024 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: raitobezarius --- tvix/eval/src/compiler/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index a59f935b0494..69c232926b41 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -302,9 +302,11 @@ impl Compiler<'_> { /// Compiles an expression, but does not emit any code for it as /// it is considered dead. This will still catch errors and /// warnings in that expression. + /// + /// A warning about the that code being dead is assumed to already be + /// emitted by the caller of [compile_dead_code]. fn compile_dead_code(&mut self, slot: LocalIdx, node: ast::Expr) { self.dead_scope += 1; - self.emit_warning(&node, WarningKind::DeadCode); self.compile(slot, node); self.dead_scope -= 1; } -- cgit 1.4.1