about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-03-06T14·23+0300
committertazjin <tazjin@tvl.su>2023-03-13T20·30+0000
commit5d9bfd7735373cde72ebac4be4a05f1c846c13ba (patch)
tree1420e8d149454eca61c7cba7970fdb7e524854a9 /tvix/eval/src
parent43b0416bd8b5c4c7c99b146f8cee7b1a979a7782 (diff)
fix(tvix/eval): emit warnings from builtins.import again r/5983
Wires up generator logic to emit warnings that already have spans
attached again.

Change-Id: I9f878cec3b9d4f6f7819e7c71bab7ae70bd3f08b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8224
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/builtins/mod.rs7
-rw-r--r--tvix/eval/src/compiler/import.rs7
-rw-r--r--tvix/eval/src/vm/generators.rs35
3 files changed, 35 insertions, 14 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index e24285f5c23a..ba31d66b11d9 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -923,7 +923,8 @@ mod pure_builtins {
 
     #[builtin("placeholder")]
     async fn builtin_placeholder(co: GenCo, #[lazy] _x: Value) -> Result<Value, ErrorKind> {
-        generators::emit_warning(&co, WarningKind::NotImplemented("builtins.placeholder")).await;
+        generators::emit_warning_kind(&co, WarningKind::NotImplemented("builtins.placeholder"))
+            .await;
         Ok("<builtins.placeholder-is-not-implemented-in-tvix-yet>".into())
     }
 
@@ -1017,7 +1018,7 @@ mod placeholder_builtins {
         #[lazy] _context: Value,
         #[lazy] val: Value,
     ) -> Result<Value, ErrorKind> {
-        generators::emit_warning(&co, WarningKind::NotImplemented("builtins.addErrorContext"))
+        generators::emit_warning_kind(&co, WarningKind::NotImplemented("builtins.addErrorContext"))
             .await;
         Ok(val)
     }
@@ -1028,7 +1029,7 @@ mod placeholder_builtins {
         _name: Value,
         _attrset: Value,
     ) -> Result<Value, ErrorKind> {
-        generators::emit_warning(
+        generators::emit_warning_kind(
             &co,
             WarningKind::NotImplemented("builtins.unsafeGetAttrsPos"),
         )
diff --git a/tvix/eval/src/compiler/import.rs b/tvix/eval/src/compiler/import.rs
index 467fc256afc6..7e1aabbf1f8b 100644
--- a/tvix/eval/src/compiler/import.rs
+++ b/tvix/eval/src/compiler/import.rs
@@ -77,10 +77,9 @@ async fn import_impl(
         });
     }
 
-    // TODO: emit not just the warning kind, hmm
-    // for warning in result.warnings {
-    //     vm.push_warning(warning);
-    // }
+    for warning in result.warnings {
+        generators::emit_warning(&co, warning).await;
+    }
 
     // Compilation succeeded, we can construct a thunk from whatever it spat
     // out and return that.
diff --git a/tvix/eval/src/vm/generators.rs b/tvix/eval/src/vm/generators.rs
index 9b055eb1c826..65b7287a69e3 100644
--- a/tvix/eval/src/vm/generators.rs
+++ b/tvix/eval/src/vm/generators.rs
@@ -15,7 +15,7 @@ use std::fmt::Display;
 use std::future::Future;
 
 use crate::value::{PointerEquality, SharedThunkSet};
-use crate::warnings::WarningKind;
+use crate::warnings::{EvalWarning, WarningKind};
 use crate::FileType;
 use crate::NixString;
 
@@ -85,8 +85,12 @@ pub enum GeneratorRequest {
         light_span: LightSpan,
     },
 
-    /// Emit a runtime warning through the VM. Receives a NoOp-response.
-    EmitWarning(WarningKind),
+    /// Emit a runtime warning (already containing a span) through the VM.
+    EmitWarning(EvalWarning),
+
+    /// Emit a runtime warning through the VM. The span of the current generator
+    /// is used for the final warning.
+    EmitWarningKind(WarningKind),
 
     /// Request a lookup in the VM's import cache, which tracks the
     /// thunks yielded by previously imported files.
@@ -150,6 +154,7 @@ impl Display for GeneratorRequest {
                 write!(f, "enter_lambda({:p})", *lambda)
             }
             GeneratorRequest::EmitWarning(_) => write!(f, "emit_warning"),
+            GeneratorRequest::EmitWarningKind(_) => write!(f, "emit_warning_kind"),
             GeneratorRequest::ImportCacheLookup(p) => {
                 write!(f, "import_cache_lookup({})", p.to_string_lossy())
             }
@@ -374,7 +379,12 @@ impl<'o> VM<'o> {
                             return Ok(false);
                         }
 
-                        GeneratorRequest::EmitWarning(kind) => {
+                        GeneratorRequest::EmitWarning(warning) => {
+                            self.push_warning(warning);
+                            message = GeneratorResponse::Empty;
+                        }
+
+                        GeneratorRequest::EmitWarningKind(kind) => {
                             self.emit_warning(kind);
                             message = GeneratorResponse::Empty;
                         }
@@ -611,9 +621,20 @@ pub(crate) async fn check_equality(
     }
 }
 
-/// Emit a runtime warning.
-pub(crate) async fn emit_warning(co: &GenCo, kind: WarningKind) {
-    match co.yield_(GeneratorRequest::EmitWarning(kind)).await {
+/// Emit a fully constructed runtime warning.
+pub(crate) async fn emit_warning(co: &GenCo, warning: EvalWarning) {
+    match co.yield_(GeneratorRequest::EmitWarning(warning)).await {
+        GeneratorResponse::Empty => {}
+        msg => panic!(
+            "Tvix bug: VM responded with incorrect generator message: {}",
+            msg
+        ),
+    }
+}
+
+/// Emit a runtime warning with the span of the current generator.
+pub(crate) async fn emit_warning_kind(co: &GenCo, kind: WarningKind) {
+    match co.yield_(GeneratorRequest::EmitWarningKind(kind)).await {
         GeneratorResponse::Empty => {}
         msg => panic!(
             "Tvix bug: VM responded with incorrect generator message: {}",