From 4f67cf221ab4328637025c2b39e43d68a30c6813 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 12 Sep 2022 01:44:17 +0300 Subject: feat(tvix/eval): implement initial fancy display for warnings This implements an initial fancy display for warnings emitted by the tvix compiler, using the codemap_diagnostic crate. Each warning variant has an associated message, and optionally an associated annotation for the span displayed to the user. In theory we could get a lot more fancy with the display for specific variants if needed (e.g. re-parse the AST and actually add multiple semantic spans based on context), but this is already a good start. Example: tvix-repl> let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} warning[W004]: declared variable 'toString' shadows a built-in global! --> [tvix-repl]:1:5 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^^^^^^^ variable declared here warning[W001]: URL literal syntax is deprecated, use a quoted string instead --> [tvix-repl]:1:16 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^^^^^^^^^^^^^^ warning[W002]: inherited variable already exists with the same value --> [tvix-repl]:1:40 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^^^^^^^^^^^^^^^^ warning[W999]: feature not yet implemented in tvix: recursive attribute sets --> [tvix-repl]:1:70 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^^^^^ warning[W999]: feature not yet implemented in tvix: closed formals --> [tvix-repl]:1:62 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^ warning[W003]: variable 'toString' is declared, but never used: --> [tvix-repl]:1:5 | 1 | let toString = https://tvl.fyi; in let inherit toString; in ({}: 42) rec {} | ^^^^^^^^ variable declared here => 42 :: int These are coloured when output to a terminal. Change-Id: If315648a07e333895db4ae1d0915ee2013806585 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6532 Autosubmit: tazjin Reviewed-by: grfn Tested-by: BuildkiteCI --- tvix/eval/src/compiler/attrs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tvix/eval/src/compiler/attrs.rs') diff --git a/tvix/eval/src/compiler/attrs.rs b/tvix/eval/src/compiler/attrs.rs index 864cc2cb3da0..91039d6dbfbe 100644 --- a/tvix/eval/src/compiler/attrs.rs +++ b/tvix/eval/src/compiler/attrs.rs @@ -33,7 +33,7 @@ impl Compiler<'_, '_> { let span = self.span_for(&node); self.emit_warning( span, - WarningKind::NotImplemented("recursive attribute sets are not yet implemented"), + WarningKind::NotImplemented("recursive attribute sets"), ); } -- cgit 1.4.1