about summary refs log tree commit diff
path: root/tvix/eval/src/vm
diff options
context:
space:
mode:
authorAspen Smith <root@gws.fyi>2024-02-10T17·39-0500
committerclbot <clbot@tvl.fyi>2024-02-13T16·49+0000
commit7e286aab1a573edc9aef16bb68e9907371917adc (patch)
treef3e9aeb1ac674800ed13dbb0bfacddfb50dd372e /tvix/eval/src/vm
parentdd261773192d0928571f806892d8065fbba1cf2d (diff)
feat(tvix/eval): Box Value::Catchable r/7508
This is now the only enum variant for Value that is larger than 8
bytes (it's 16 bytes), so boxing it (especially since it's not
perf-critical) allows us to get the Value size down to only 16 bytes!

Change-Id: I98598e2b762944448bef982e8ff7da6d6683c4aa
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10798
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: aspen <root@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm')
-rw-r--r--tvix/eval/src/vm/generators.rs6
-rw-r--r--tvix/eval/src/vm/macros.rs2
-rw-r--r--tvix/eval/src/vm/mod.rs8
3 files changed, 8 insertions, 8 deletions
diff --git a/tvix/eval/src/vm/generators.rs b/tvix/eval/src/vm/generators.rs
index cffe36e60239..fba4e7cd90d2 100644
--- a/tvix/eval/src/vm/generators.rs
+++ b/tvix/eval/src/vm/generators.rs
@@ -609,7 +609,7 @@ pub async fn request_string_coerce(
     match val {
         Value::String(s) => Ok(*s),
         _ => match co.yield_(VMRequest::StringCoerce(val, kind)).await {
-            VMResponse::Value(Value::Catchable(c)) => Err(c),
+            VMResponse::Value(Value::Catchable(c)) => Err(*c),
             VMResponse::Value(value) => Ok(value
                 .to_contextful_str()
                 .expect("coerce_to_string always returns a string")),
@@ -644,7 +644,7 @@ pub(crate) async fn check_equality(
         .await
     {
         VMResponse::Value(Value::Bool(b)) => Ok(Ok(b)),
-        VMResponse::Value(Value::Catchable(cek)) => Ok(Err(cek)),
+        VMResponse::Value(Value::Catchable(cek)) => Ok(Err(*cek)),
         msg => panic!(
             "Tvix bug: VM responded with incorrect generator message: {}",
             msg
@@ -776,7 +776,7 @@ pub(crate) async fn request_to_json(
 ) -> Result<serde_json::Value, CatchableErrorKind> {
     match co.yield_(VMRequest::ToJson(value)).await {
         VMResponse::Value(Value::Json(json)) => Ok(*json),
-        VMResponse::Value(Value::Catchable(cek)) => Err(cek),
+        VMResponse::Value(Value::Catchable(cek)) => Err(*cek),
         msg => panic!(
             "Tvix bug: VM responded with incorrect generator message: {}",
             msg
diff --git a/tvix/eval/src/vm/macros.rs b/tvix/eval/src/vm/macros.rs
index fdb812961172..d8a09706ab9c 100644
--- a/tvix/eval/src/vm/macros.rs
+++ b/tvix/eval/src/vm/macros.rs
@@ -44,7 +44,7 @@ macro_rules! cmp_op {
                     let span = generators::request_span(&co).await;
                     let ordering = a.nix_cmp_ordering(b, co, span).await?;
                     match ordering {
-                        Err(cek) => Ok(Value::Catchable(cek)),
+                        Err(cek) => Ok(Value::from(cek)),
                         Ok(ordering) => Ok(Value::Bool(cmp_op!(@order $op ordering))),
                     }
                 }
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs
index 7c2f5b97960f..0ca72bdf3072 100644
--- a/tvix/eval/src/vm/mod.rs
+++ b/tvix/eval/src/vm/mod.rs
@@ -901,7 +901,7 @@ where
 
                 OpCode::OpAssertFail => {
                     self.stack
-                        .push(Value::Catchable(CatchableErrorKind::AssertionFailed));
+                        .push(Value::from(CatchableErrorKind::AssertionFailed));
                 }
 
                 // Data-carrying operands should never be executed,
@@ -1250,7 +1250,7 @@ async fn add_values(co: GenCo, a: Value, b: Value) -> Result<Value, ErrorKind> {
                     path.push(vs.to_os_str()?);
                     crate::value::canon_path(PathBuf::from(path)).into()
                 }
-                Err(c) => Value::Catchable(c),
+                Err(c) => Value::Catchable(Box::new(c)),
             }
         }
         (Value::String(s1), Value::String(s2)) => Value::String(Box::new(s1.concat(&s2))),
@@ -1288,8 +1288,8 @@ async fn add_values(co: GenCo, a: Value, b: Value) -> Result<Value, ErrorKind> {
             .await;
             match (r1, r2) {
                 (Ok(s1), Ok(s2)) => Value::String(Box::new(s1.concat(&s2))),
-                (Err(c), _) => return Ok(Value::Catchable(c)),
-                (_, Err(c)) => return Ok(Value::Catchable(c)),
+                (Err(c), _) => return Ok(Value::from(c)),
+                (_, Err(c)) => return Ok(Value::from(c)),
             }
         }
     };