about summary refs log tree commit diff
path: root/tvix/eval/src/value
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-27T00·31+0300
committertazjin <tazjin@tvl.su>2022-09-04T17·40+0000
commit33cde1422e473770ab0ca30759ece618cb4c3680 (patch)
tree163268a01d64d0154339354a863cd18412f4f053 /tvix/eval/src/value
parent10b0879c009098d3c5f9fe21067ff656a29442a5 (diff)
feat(tvix/eval): implement upvalue resolution in `with` scopes r/4635
These need to be handled specially by the runtime if the compiler
determines that a given local must be resolved via `with`.

Note that this implementation has a bug: It currently allows `with`
inside of nested lambdas to shadow statically known identifiers. This
will be cleaned up in the next commit.

Change-Id: If196b99cbd1a0f2dbb4a40a0e88cdb09a009c6b9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6299
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/value')
-rw-r--r--tvix/eval/src/value/mod.rs11
-rw-r--r--tvix/eval/src/value/string.rs6
2 files changed, 17 insertions, 0 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index f6583db5ab97..eb23605bd0b2 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -80,6 +80,17 @@ impl Value {
         }
     }
 
+    pub fn as_str(&self) -> EvalResult<&str> {
+        match self {
+            Value::String(s) => Ok(s.as_str()),
+            other => Err(ErrorKind::TypeError {
+                expected: "string",
+                actual: other.type_of(),
+            }
+            .into()),
+        }
+    }
+
     pub fn to_string(self) -> EvalResult<NixString> {
         match self {
             Value::String(s) => Ok(s),
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index 51b0f0345457..65022b6cc49c 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -46,6 +46,12 @@ impl From<String> for NixString {
     }
 }
 
+impl From<SmolStr> for NixString {
+    fn from(s: SmolStr) -> Self {
+        NixString(StringRepr::Smol(s))
+    }
+}
+
 impl Hash for NixString {
     fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
         self.as_str().hash(state)