about summary refs log tree commit diff
path: root/tvix/eval/src/compiler.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-12T14·07+0300
committertazjin <tazjin@tvl.su>2022-08-26T17·19+0000
commit7e77972d71967c65e5446e55673869ef2a8d27bb (patch)
treeb7c3f470eb00465ca9b50a4314e88aeff2ad0984 /tvix/eval/src/compiler.rs
parent5512108ca797184560c75bb2f356b699e88ee0ee (diff)
feat(tvix/eval): add mechanism for emitting warnings from compiler r/4507
These can be used predominantly to emit warnings about things that the
compiler can infer, such as deprecated language features.

Change-Id: I3649c625459d7f3f95cdf42d5c651d23d66569ec
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6174
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler.rs')
-rw-r--r--tvix/eval/src/compiler.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 1a4e8df1da4d..9b0530f0fa82 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -17,12 +17,22 @@ use crate::chunk::Chunk;
 use crate::errors::EvalResult;
 use crate::opcode::{CodeIdx, OpCode};
 use crate::value::Value;
+use crate::warnings::EvalWarning;
 
 use rnix;
 use rnix::types::{BinOpKind, EntryHolder, TokenWrapper, TypedNode, Wrapper};
 
+/// Represents the result of compiling a piece of Nix code. If
+/// compilation was successful, the resulting bytecode can be passed
+/// to the VM.
+pub struct CompilationResult {
+    pub chunk: Chunk,
+    pub warnings: Vec<EvalWarning>,
+}
+
 struct Compiler {
     chunk: Chunk,
+    warnings: Vec<EvalWarning>,
 }
 
 impl Compiler {
@@ -573,12 +583,16 @@ impl Compiler {
     }
 }
 
-pub fn compile(ast: rnix::AST) -> EvalResult<Chunk> {
+pub fn compile(ast: rnix::AST) -> EvalResult<CompilationResult> {
     let mut c = Compiler {
         chunk: Chunk::default(),
+        warnings: vec![],
     };
 
     c.compile(ast.node())?;
 
-    Ok(c.chunk)
+    Ok(CompilationResult {
+        chunk: c.chunk,
+        warnings: c.warnings,
+    })
 }