git.delta.rocks / jrsonnet / refs/commits / 6f6b79fd0e0d

difftreelog

feat array unification

kxktrsumYaroslav Bolyukin2026-04-25parent: #953b3d0.patch.diff
in: master

11 files changed

modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -50,7 +50,7 @@
 /// Assign elements with [`jsonnet_json_array_append`].
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_array(_vm: &VM) -> *mut Val {
-	Box::into_raw(Box::new(Val::Arr(ArrValue::eager(Vec::new()))))
+	Box::into_raw(Box::new(Val::arr(())))
 }
 
 /// Make a `JsonnetJsonValue` representing an object.
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -24,7 +24,7 @@
 			}
 
 			new.push(Thunk::evaluated(val.clone()));
-			*arr = Val::Arr(ArrValue::lazy(new));
+			*arr = Val::arr(new);
 		}
 		_ => panic!("should receive array"),
 	}
modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -6,7 +6,6 @@
 };
 
 use jrsonnet_gcmodule::{Cc, cc_dyn};
-use jrsonnet_interner::IBytes;
 use jrsonnet_ir::Expr;
 
 use crate::{Context, Result, Thunk, Val, function::NativeFn, typed::IntoUntyped};
@@ -35,28 +34,17 @@
 
 impl ArrValue {
 	pub fn empty() -> Self {
-		Self::new(RangeArray::empty())
+		Self::new(())
 	}
 
 	pub fn expr(ctx: Context, exprs: Rc<Vec<Expr>>) -> Self {
 		Self::new(ExprArray::new(ctx, exprs))
-	}
-
-	pub fn lazy(thunks: Vec<Thunk<Val>>) -> Self {
-		Self::new(LazyArray(thunks))
 	}
 
-	pub fn eager(values: Vec<Val>) -> Self {
-		Self::new(EagerArray(values))
-	}
-
 	pub fn repeated(data: Self, repeats: usize) -> Option<Self> {
 		Some(Self::new(RepeatedArray::new(data, repeats)?))
 	}
 
-	pub fn bytes(bytes: IBytes) -> Self {
-		Self::new(BytesArray(bytes))
-	}
 	pub fn chars(chars: impl Iterator<Item = char>) -> Self {
 		Self::new(CharArray(chars.collect()))
 	}
@@ -83,7 +71,7 @@
 					out.push(i);
 				}
 			}
-			return Ok(Self::eager(out));
+			return Ok(Self::new(out));
 		};
 
 		let mut out = Vec::new();
@@ -92,29 +80,16 @@
 				out.push(i);
 			}
 		}
-		Ok(Self::lazy(out))
+		Ok(Self::new(out))
 	}
 
 	pub fn extended(a: Self, b: Self) -> Self {
-		// TODO: benchmark for an optimal value, currently just a arbitrary choice
-		const ARR_EXTEND_THRESHOLD: usize = 1000;
-
 		if a.is_empty() {
 			b
 		} else if b.is_empty() {
 			a
-		} else if a.len() + b.len() > ARR_EXTEND_THRESHOLD {
+		} else {
 			Self::new(ExtendedArray::new(a, b))
-		} else if let (Some(a), Some(b)) = (a.iter_cheap(), b.iter_cheap()) {
-			let mut out = Vec::with_capacity(a.len() + b.len());
-			out.extend(a);
-			out.extend(b);
-			Self::eager(out)
-		} else {
-			let mut out = Vec::with_capacity(a.len() + b.len());
-			out.extend(a.iter_lazy());
-			out.extend(b.iter_lazy());
-			Self::lazy(out)
 		}
 	}
 
@@ -165,19 +140,15 @@
 		self.0.is_empty()
 	}
 
+	pub fn is_cheap(&self) -> bool {
+		self.0.is_cheap()
+	}
+
 	/// Get array element by index, evaluating it, if it is lazy.
 	///
 	/// Returns `None` on out-of-bounds condition.
 	pub fn get(&self, index: usize) -> Result<Option<Val>> {
 		self.0.get(index)
-	}
-
-	/// Returns None if get is either non cheap, or out of bounds
-	/// Note that non-cheap access includes errorable values
-	///
-	/// Prefer it to `get_lazy`, but use `get` when you can.
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get_cheap(index)
 	}
 
 	/// Get array element by index, without evaluation.
@@ -196,15 +167,6 @@
 		(0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
 	}
 
-	/// Prefer it over `iter_lazy`, but do not use it where `iter` will do.
-	pub fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {
-		if self.is_cheap() {
-			Some((0..self.len()).map(|i| self.get_cheap(i).expect("length and is_cheap checked")))
-		} else {
-			None
-		}
-	}
-
 	/// Return a reversed view on current array.
 	#[must_use]
 	pub fn reversed(self) -> Self {
@@ -213,50 +175,25 @@
 
 	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		Cc::ptr_eq(&a.0, &b.0)
-	}
-
-	/// Is this vec supports `.get_cheap()?`
-	pub fn is_cheap(&self) -> bool {
-		self.0.is_cheap()
 	}
 
 	pub fn as_any(&self) -> &dyn Any {
 		&self.0
 	}
 }
-impl From<Vec<Val>> for ArrValue {
-	fn from(value: Vec<Val>) -> Self {
-		Self::eager(value)
-	}
-}
-impl From<Vec<Thunk<Val>>> for ArrValue {
-	fn from(value: Vec<Thunk<Val>>) -> Self {
-		Self::lazy(value)
-	}
-}
-impl FromIterator<Val> for ArrValue {
-	fn from_iter<T: IntoIterator<Item = Val>>(iter: T) -> Self {
-		Self::eager(iter.into_iter().collect())
+impl<T> From<T> for ArrValue
+where
+	T: ArrayLike,
+{
+	fn from(value: T) -> Self {
+		Self::new(value)
 	}
 }
-impl ArrayLike for ArrValue {
-	fn len(&self) -> usize {
-		self.0.len()
-	}
-
-	fn get(&self, index: usize) -> Result<Option<Val>> {
-		self.0.get(index)
-	}
-
-	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.0.get_lazy(index)
-	}
-
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get_cheap(index)
-	}
-
-	fn is_cheap(&self) -> bool {
-		self.0.is_cheap()
+impl<I> FromIterator<I> for ArrValue
+where
+	Vec<I>: ArrayLike,
+{
+	fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self {
+		Self::new(iter.into_iter().collect::<Vec<_>>())
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -1,4 +1,10 @@
-use std::{any::Any, cell::RefCell, fmt::Debug, mem::replace, rc::Rc};
+use std::{
+	any::Any,
+	cell::RefCell,
+	fmt::{self, Debug},
+	mem::replace,
+	rc::Rc,
+};
 
 use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::{IBytes, IStr};
@@ -21,11 +27,45 @@
 	}
 	fn get(&self, index: usize) -> Result<Option<Val>>;
 	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>>;
-	fn get_cheap(&self, index: usize) -> Option<Val>;
 
-	fn is_cheap(&self) -> bool;
+	fn is_cheap(&self) -> bool {
+		false
+	}
+}
+trait ArrayCheap {
+	fn get(&self, index: usize) -> Option<Val>;
+	fn len(&self) -> usize;
 }
+impl<T> ArrayLike for T
+where
+	T: Any + Trace + Debug + ArrayCheap,
+{
+	fn len(&self) -> usize {
+		<T as ArrayCheap>::len(self)
+	}
+
+	fn get(&self, index: usize) -> Result<Option<Val>> {
+		Ok(<T as ArrayCheap>::get(self, index))
+	}
 
+	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
+		<T as ArrayCheap>::get(self, index).map(Thunk::evaluated)
+	}
+
+	fn is_cheap(&self) -> bool {
+		true
+	}
+}
+
+impl ArrayCheap for () {
+	fn len(&self) -> usize {
+		0
+	}
+	fn get(&self, _index: usize) -> Option<Val> {
+		None
+	}
+}
+
 #[derive(Debug, Trace)]
 pub struct SliceArray {
 	pub(crate) inner: ArrValue,
@@ -52,9 +92,6 @@
 		self.inner.get_lazy(self.map_idx(index))
 	}
 
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.inner.get_cheap(self.map_idx(index))
-	}
 	fn is_cheap(&self) -> bool {
 		self.inner.is_cheap()
 	}
@@ -62,47 +99,21 @@
 
 #[derive(Trace, Debug)]
 pub struct CharArray(pub Vec<char>);
-impl ArrayLike for CharArray {
+impl ArrayCheap for CharArray {
 	fn len(&self) -> usize {
-		self.0.len()
+		self.0.as_slice().len()
 	}
-
-	fn get(&self, index: usize) -> Result<Option<Val>> {
-		Ok(self.get_cheap(index))
-	}
-
-	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.get_cheap(index).map(Thunk::evaluated)
-	}
-
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get(index).map(|v| Val::string(*v))
-	}
-	fn is_cheap(&self) -> bool {
-		true
+	fn get(&self, index: usize) -> Option<Val> {
+		self.0.as_slice().get(index).map(|v| Val::string(*v))
 	}
 }
 
-#[derive(Trace, Debug)]
-pub struct BytesArray(pub IBytes);
-impl ArrayLike for BytesArray {
+impl ArrayCheap for IBytes {
 	fn len(&self) -> usize {
-		self.0.len()
-	}
-
-	fn get(&self, index: usize) -> Result<Option<Val>> {
-		Ok(self.get_cheap(index))
-	}
-
-	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.get_cheap(index).map(Thunk::evaluated)
-	}
-
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get(index).map(|v| Val::Num((*v).into()))
+		self.as_slice().len()
 	}
-	fn is_cheap(&self) -> bool {
-		true
+	fn get(&self, index: usize) -> Option<Val> {
+		self.as_slice().get(index).map(|v| Val::Num((*v).into()))
 	}
 }
 
@@ -190,9 +201,6 @@
 			expr: self.clone(),
 			index,
 		}))
-	}
-	fn get_cheap(&self, _index: usize) -> Option<Val> {
-		None
 	}
 	fn is_cheap(&self) -> bool {
 		false
@@ -275,61 +283,34 @@
 		self.len
 	}
 
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		if self.split > index {
-			self.a.get_cheap(index)
-		} else {
-			self.b.get_cheap(index - self.split)
-		}
-	}
 	fn is_cheap(&self) -> bool {
 		self.a.is_cheap() && self.b.is_cheap()
 	}
 }
 
-#[derive(Trace, Debug)]
-pub struct LazyArray(pub Vec<Thunk<Val>>);
-impl ArrayLike for LazyArray {
+impl<T> ArrayLike for Vec<T>
+where
+	T: IntoUntyped + Trace + fmt::Debug,
+	for<'a> &'a T: IntoUntyped,
+{
 	fn len(&self) -> usize {
-		self.0.len()
+		self.as_slice().len()
 	}
+
 	fn get(&self, index: usize) -> Result<Option<Val>> {
-		let Some(v) = self.0.get(index) else {
+		let Some(elem) = self.as_slice().get(index) else {
 			return Ok(None);
 		};
-		v.evaluate().map(Some)
-	}
-	fn get_cheap(&self, _index: usize) -> Option<Val> {
-		None
-	}
-	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.0.get(index).cloned()
-	}
-	fn is_cheap(&self) -> bool {
-		false
-	}
-}
-
-#[derive(Trace, Debug)]
-pub struct EagerArray(pub Vec<Val>);
-impl ArrayLike for EagerArray {
-	fn len(&self) -> usize {
-		self.0.len()
+		IntoUntyped::into_untyped(elem).map(Some)
 	}
 
-	fn get(&self, index: usize) -> Result<Option<Val>> {
-		Ok(self.0.get(index).cloned())
-	}
-
 	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.0.get(index).cloned().map(Thunk::evaluated)
+		let elem = self.as_slice().get(index)?;
+		Some(IntoUntyped::into_lazy_untyped(elem))
 	}
 
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get(index).cloned()
-	}
 	fn is_cheap(&self) -> bool {
-		true
+		!T::provides_lazy()
 	}
 }
 
@@ -363,28 +344,12 @@
 		WithExactSize(self.start..=self.end, self.size())
 	}
 }
-
-impl ArrayLike for RangeArray {
-	fn len(&self) -> usize {
-		self.size()
-	}
-	fn is_empty(&self) -> bool {
-		self.size() == 0
-	}
-
-	fn get(&self, index: usize) -> Result<Option<Val>> {
-		Ok(self.get_cheap(index))
-	}
-
-	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		self.get_cheap(index).map(Thunk::evaluated)
-	}
-
-	fn get_cheap(&self, index: usize) -> Option<Val> {
+impl ArrayCheap for RangeArray {
+	fn get(&self, index: usize) -> Option<Val> {
 		self.range().nth(index).map(|i| Val::Num(i.into()))
 	}
-	fn is_cheap(&self) -> bool {
-		true
+	fn len(&self) -> usize {
+		self.size()
 	}
 }
 
@@ -403,9 +368,6 @@
 		self.0.get_lazy(self.0.len() - index - 1)
 	}
 
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		self.0.get_cheap(self.0.len() - index - 1)
-	}
 	fn is_cheap(&self) -> bool {
 		self.0.is_cheap()
 	}
@@ -509,13 +471,6 @@
 			arr: self.clone(),
 			index,
 		}))
-	}
-
-	fn get_cheap(&self, _index: usize) -> Option<Val> {
-		None
-	}
-	fn is_cheap(&self) -> bool {
-		false
 	}
 }
 
@@ -534,6 +489,12 @@
 			total_len,
 		})
 	}
+	fn map_idx(&self, index: usize) -> Option<usize> {
+		if index > self.total_len {
+			return None;
+		}
+		Some(index % self.data.len())
+	}
 }
 
 impl ArrayLike for RepeatedArray {
@@ -542,25 +503,17 @@
 	}
 
 	fn get(&self, index: usize) -> Result<Option<Val>> {
-		if index > self.total_len {
+		let Some(idx) = self.map_idx(index) else {
 			return Ok(None);
-		}
-		self.data.get(index % self.data.len())
+		};
+		self.data.get(idx)
 	}
 
 	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		if index > self.total_len {
-			return None;
-		}
-		self.data.get_lazy(index % self.data.len())
+		let idx = self.map_idx(index)?;
+		self.data.get_lazy(idx)
 	}
 
-	fn get_cheap(&self, index: usize) -> Option<Val> {
-		if index > self.total_len {
-			return None;
-		}
-		self.data.get_cheap(index % self.data.len())
-	}
 	fn is_cheap(&self) -> bool {
 		self.data.is_cheap()
 	}
@@ -584,21 +537,17 @@
 	}
 
 	fn get(&self, index: usize) -> Result<Option<Val>> {
-		let Some(key) = self.keys.get(index) else {
+		let Some(key) = self.keys.as_slice().get(index) else {
 			return Ok(None);
 		};
 		Ok(Some(self.obj.get_or_bail(key.clone())?))
 	}
 
 	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		let key = self.keys.get(index)?;
+		let key = self.keys.as_slice().get(index)?;
 		Some(self.obj.get_lazy_or_bail(key.clone()))
 	}
 
-	fn get_cheap(&self, _index: usize) -> Option<Val> {
-		None
-	}
-
 	fn is_cheap(&self) -> bool {
 		false
 	}
@@ -628,7 +577,7 @@
 	}
 
 	fn get(&self, index: usize) -> Result<Option<Val>> {
-		let Some(key) = self.keys.get(index) else {
+		let Some(key) = self.keys.as_slice().get(index) else {
 			return Ok(None);
 		};
 		Ok(Some(
@@ -641,7 +590,7 @@
 	}
 
 	fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
-		let key = self.keys.get(index)?;
+		let key = self.keys.as_slice().get(index)?;
 		// Nothing can fail in the key part, yet value is still
 		// lazy-evaluated
 		Some(Thunk::evaluated(
@@ -651,10 +600,6 @@
 			})
 			.expect("convertible"),
 		))
-	}
-
-	fn get_cheap(&self, _index: usize) -> Option<Val> {
-		None
 	}
 
 	fn is_cheap(&self) -> bool {
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -70,12 +70,12 @@
 			if n.iter().any(|e| !is_trivial(e)) {
 				return None;
 			}
-			Val::Arr(ArrValue::eager(
+			Val::Arr(
 				n.iter()
 					.map(evaluate_trivial)
 					.map(|e| e.expect("checked trivial"))
 					.collect(),
-			))
+			)
 		}
 		_ => return None,
 	})
@@ -145,12 +145,12 @@
 						let fctx = Pending::new();
 						let mut new_bindings = FxHashMap::with_capacity(into.binds_len());
 						let obj = obj.clone();
-						let value = Thunk::evaluated(Val::Arr(ArrValue::lazy(vec![
+						let value = Thunk::evaluated(Val::arr(vec![
 							Thunk::evaluated(Val::string(field.clone())),
-							Thunk!(move || obj.get(field).transpose().expect(
+							obj.get_lazy(field).transpose().expect(
 								"field exists, as field name was obtained from object.fields()",
-							)),
-						])));
+							),
+						]));
 						destruct(into, value, fctx.clone(), &mut new_bindings)?;
 						let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);
 
@@ -528,7 +528,7 @@
 						#[cfg(feature = "exp-null-coaelse")]
 						None if part.null_coaelse => return Ok(Val::Null),
 						None => {
-							let suggestions = suggest_object_fields(&v, key.clone().into_flat());
+							let suggestions = suggest_object_fields(&v, key.into_flat());
 
 							return Err(Error::from(NoSuchField(
 								key.clone().into_flat(),
@@ -628,7 +628,7 @@
 		}
 		Arr(items) => {
 			if items.is_empty() {
-				Val::Arr(ArrValue::empty())
+				Val::arr(())
 			} else {
 				Val::Arr(ArrValue::expr(ctx, items.clone()))
 			}
@@ -640,7 +640,7 @@
 				out.push(Thunk!(move || evaluate(ctx, &expr)));
 				Ok(())
 			})?;
-			Val::Arr(ArrValue::lazy(out))
+			Val::arr(out)
 		}
 		Obj(body) => Val::Obj(evaluate_object(None, ctx, body)?),
 		ObjExtend(a, b) => {
@@ -718,9 +718,7 @@
 						|| s.import_resolved(resolved_path),
 					)?,
 					ImportKind::Str => Val::string(s.import_resolved_str(resolved_path)?),
-					ImportKind::Bin => {
-						Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?))
-					}
+					ImportKind::Bin => Val::arr(s.import_resolved_bin(resolved_path)?),
 				}) as Result<Val>
 			})?
 		}
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use std::borrow::Cow;23use jrsonnet_interner::IStr;4use serde::{5	Deserialize, Serialize, Serializer,6	de::{self, Visitor},7	ser::{8		Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant, SerializeTuple,9		SerializeTupleStruct, SerializeTupleVariant,10	},11};1213use crate::{14	Error as JrError, ObjValue, ObjValueBuilder, Result, Val, arr::ArrValue, in_description_frame,15	runtime_error, val::NumValue,16};1718impl<'de> Deserialize<'de> for Val {19	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>20	where21		D: serde::Deserializer<'de>,22	{23		struct ValVisitor;2425		// macro_rules! visit_num {26		// 	($($method:ident => $ty:ty),* $(,)?) => {$(27		// 		fn $method<E>(self, v: $ty) -> Result<Self::Value, E>28		// 		where29		// 			E: serde::de::Error,30		// 		{31		// 			Ok(Val::Num(f64::from(v)))32		// 		}33		// 	)*};34		// }3536		impl<'de> Visitor<'de> for ValVisitor {37			type Value = Val;3839			fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>40			where41				E: de::Error,42			{43				Ok(Val::Bool(v))44			}45			fn visit_f64<E>(self, v: f64) -> Result<Self::Value, E>46			where47				E: de::Error,48			{49				Ok(Val::Num(NumValue::new(v).ok_or_else(|| {50					E::custom("only finite numbers are supported")51				})?))52			}53			fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>54			where55				E: de::Error,56			{57				Ok(Val::string(v))58			}5960			// visit_num! {61			// 	visit_i8 => i8,62			// 	visit_i16 => i16,63			// 	visit_i32 => i32,64			// 	visit_u8 => u8,65			// 	visit_u16 => u16,66			// 	visit_u32 => u32,67			// }68			fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E>69			where70				E: de::Error,71			{72				#[expect(73					clippy::cast_precision_loss,74					reason = "this is how it works with stdlib functions"75				)]76				Ok(Val::Num(NumValue::new(v as f64).expect("no overflow")))77			}78			fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>79			where80				E: de::Error,81			{82				#[expect(83					clippy::cast_precision_loss,84					reason = "this is how it works with stdlib functions"85				)]86				Ok(Val::Num(NumValue::new(v as f64).expect("no overflow")))87			}8889			fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>90			where91				E: de::Error,92			{93				Ok(Val::Arr(ArrValue::bytes(v.into())))94			}9596			fn visit_none<E>(self) -> Result<Self::Value, E>97			where98				E: de::Error,99			{100				Ok(Val::Null)101			}102			fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>103			where104				D: serde::Deserializer<'de>,105			{106				deserializer.deserialize_any(self)107			}108109			fn visit_unit<E>(self) -> Result<Self::Value, E>110			where111				E: de::Error,112			{113				Ok(Val::Null)114			}115116			fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>117			where118				D: serde::Deserializer<'de>,119			{120				deserializer.deserialize_any(self)121			}122123			fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>124			where125				A: de::SeqAccess<'de>,126			{127				let mut out = seq.size_hint().map_or_else(Vec::new, Vec::with_capacity);128129				while let Some(val) = seq.next_element::<Val>()? {130					out.push(val);131				}132133				Ok(Val::Arr(ArrValue::eager(out)))134			}135136			fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>137			where138				A: de::MapAccess<'de>,139			{140				let mut out = map141					.size_hint()142					.map_or_else(ObjValueBuilder::new, ObjValueBuilder::with_capacity);143144				while let Some((k, v)) = map.next_entry::<Cow<'de, str>, Val>()? {145					// Jsonnet ignores duplicate keys146					out.field(k).value(v);147				}148149				Ok(Val::Obj(out.build()))150			}151152			fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {153				write!(formatter, "any valid jsonnet value")154			}155		}156		deserializer.deserialize_any(ValVisitor)157	}158}159160impl Serialize for Val {161	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>162	where163		S: serde::Serializer,164	{165		match self {166			Self::Bool(v) => serializer.serialize_bool(*v),167			Self::Null => serializer.serialize_none(),168			Self::Str(s) => serializer.serialize_str(&s.clone().into_flat()),169			Self::Num(n) => {170				let n = n.get();171				if n.fract() == 0.0 {172					#[expect(173						clippy::cast_possible_truncation,174						reason = "no correct implementation is possible here; expected"175					)]176					let n = n as i64;177					serializer.serialize_i64(n)178				} else {179					serializer.serialize_f64(n)180				}181			}182			#[cfg(feature = "exp-bigint")]183			Self::BigInt(b) => b.serialize(serializer),184			Self::Arr(arr) => {185				let mut seq = serializer.serialize_seq(Some(arr.len()))?;186				for (i, element) in arr.iter().enumerate() {187					let mut serde_error = None;188					in_description_frame(189						|| format!("array index [{i}]"),190						|| {191							let e = element?;192							if let Err(e) = seq.serialize_element(&e) {193								serde_error = Some(e);194							}195							Ok(())196						},197					)198					.map_err(|e| S::Error::custom(e.to_string()))?;199					if let Some(e) = serde_error {200						return Err(e);201					}202				}203				seq.end()204			}205			Self::Obj(obj) => {206				let mut map = serializer.serialize_map(Some(obj.len()))?;207				for (field, value) in obj.iter(208					#[cfg(feature = "exp-preserve-order")]209					true,210				) {211					let mut serde_error = None;212					// TODO: rewrite using try{} after stabilization213					in_description_frame(214						|| format!("object field {field:?}"),215						|| {216							let v = value?;217							if let Err(e) = map.serialize_entry(field.as_str(), &v) {218								serde_error = Some(e);219							}220							Ok(())221						},222					)223					.map_err(|e| S::Error::custom(e.to_string()))?;224					if let Some(e) = serde_error {225						return Err(e);226					}227				}228				map.end()229			}230			Self::Func(_) => Err(S::Error::custom("tried to manifest function")),231		}232	}233}234235struct IntoVecValSerializer {236	variant: Option<IStr>,237	data: Vec<Val>,238}239impl IntoVecValSerializer {240	fn new() -> Self {241		Self {242			variant: None,243			data: Vec::new(),244		}245	}246	fn with_capacity(capacity: usize) -> Self {247		Self {248			variant: None,249			data: Vec::with_capacity(capacity),250		}251	}252	fn variant_with_capacity(variant: impl Into<IStr>, capacity: usize) -> Self {253		Self {254			variant: Some(variant.into()),255			data: Vec::with_capacity(capacity),256		}257	}258}259impl SerializeSeq for IntoVecValSerializer {260	type Ok = Val;261	type Error = JrError;262263	fn serialize_element<T>(&mut self, value: &T) -> Result<()>264	where265		T: ?Sized + Serialize,266	{267		let value = value.serialize(IntoValSerializer)?;268		self.data.push(value);269		Ok(())270	}271272	fn end(self) -> Result<Val> {273		let inner = Val::Arr(ArrValue::eager(self.data));274		if let Some(variant) = self.variant {275			let mut out = ObjValue::builder_with_capacity(1);276			out.field(variant).value(inner);277			Ok(Val::Obj(out.build()))278		} else {279			Ok(inner)280		}281	}282}283impl SerializeTuple for IntoVecValSerializer {284	type Ok = Val;285	type Error = JrError;286287	fn serialize_element<T>(&mut self, value: &T) -> Result<()>288	where289		T: ?Sized + Serialize,290	{291		SerializeSeq::serialize_element(self, value)292	}293294	fn end(self) -> Result<Val> {295		SerializeSeq::end(self)296	}297}298impl SerializeTupleVariant for IntoVecValSerializer {299	type Ok = Val;300	type Error = JrError;301302	fn serialize_field<T>(&mut self, value: &T) -> Result<()>303	where304		T: ?Sized + Serialize,305	{306		SerializeSeq::serialize_element(self, value)307	}308309	fn end(self) -> Result<Val> {310		SerializeSeq::end(self)311	}312}313impl SerializeTupleStruct for IntoVecValSerializer {314	type Ok = Val;315	type Error = JrError;316317	fn serialize_field<T>(&mut self, value: &T) -> Result<()>318	where319		T: ?Sized + Serialize,320	{321		SerializeSeq::serialize_element(self, value)322	}323324	fn end(self) -> Result<Val> {325		SerializeSeq::end(self)326	}327}328329struct IntoObjValueSerializer {330	variant: Option<IStr>,331	data: ObjValueBuilder,332	key: Option<IStr>,333}334impl IntoObjValueSerializer {335	fn new() -> Self {336		Self {337			variant: None,338			data: ObjValue::builder(),339			key: None,340		}341	}342	fn with_capacity(capacity: usize) -> Self {343		Self {344			variant: None,345			data: ObjValue::builder_with_capacity(capacity),346			key: None,347		}348	}349	fn variant_with_capacity(variant: impl Into<IStr>, capacity: usize) -> Self {350		Self {351			variant: Some(variant.into()),352			data: ObjValue::builder_with_capacity(capacity),353			key: None,354		}355	}356}357impl SerializeMap for IntoObjValueSerializer {358	type Ok = Val;359	type Error = JrError;360361	fn serialize_key<T>(&mut self, key: &T) -> Result<()>362	where363		T: ?Sized + Serialize,364	{365		let key = key.serialize(IntoValSerializer)?;366		let key = key.to_string()?;367		self.key = Some(key);368		Ok(())369	}370371	fn serialize_value<T>(&mut self, value: &T) -> Result<()>372	where373		T: ?Sized + Serialize,374	{375		let key = self.key.take().expect("no serialize_key called");376		let value = value.serialize(IntoValSerializer)?;377		self.data.field(key).try_value(value)?;378		Ok(())379	}380381	// TODO: serialize_key/serialize_value382	fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<()>383	where384		K: ?Sized + Serialize,385		V: ?Sized + Serialize,386	{387		let key = key.serialize(IntoValSerializer)?;388		let key = key.to_string()?;389		let value = value.serialize(IntoValSerializer)?;390		self.data.field(key).try_value(value)?;391		Ok(())392	}393394	fn end(self) -> Result<Val> {395		let inner = Val::Obj(self.data.build());396		if let Some(variant) = self.variant {397			let mut out = ObjValue::builder_with_capacity(1);398			out.field(variant).value(inner);399			Ok(Val::Obj(out.build()))400		} else {401			Ok(inner)402		}403	}404}405impl SerializeStruct for IntoObjValueSerializer {406	type Ok = Val;407	type Error = JrError;408409	fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>410	where411		T: ?Sized + Serialize,412	{413		SerializeMap::serialize_entry(self, key, value)?;414		Ok(())415	}416417	fn end(self) -> Result<Val> {418		SerializeMap::end(self)419	}420}421impl SerializeStructVariant for IntoObjValueSerializer {422	type Ok = Val;423424	type Error = JrError;425426	fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>427	where428		T: ?Sized + Serialize,429	{430		SerializeMap::serialize_entry(self, key, value)?;431		Ok(())432	}433434	fn end(self) -> Result<Val> {435		SerializeMap::end(self)436	}437}438439struct IntoValSerializer;440impl Serializer for IntoValSerializer {441	type Ok = Val;442443	type Error = JrError;444445	type SerializeSeq = IntoVecValSerializer;446447	type SerializeTuple = IntoVecValSerializer;448449	type SerializeTupleStruct = IntoVecValSerializer;450451	type SerializeTupleVariant = IntoVecValSerializer;452453	type SerializeMap = IntoObjValueSerializer;454455	type SerializeStruct = IntoObjValueSerializer;456457	type SerializeStructVariant = IntoObjValueSerializer;458459	fn serialize_bool(self, v: bool) -> Result<Val> {460		Ok(Val::Bool(v))461	}462463	fn serialize_i8(self, v: i8) -> Result<Val> {464		Ok(Val::Num(v.into()))465	}466467	fn serialize_i16(self, v: i16) -> Result<Val> {468		Ok(Val::Num(v.into()))469	}470471	fn serialize_i32(self, v: i32) -> Result<Val> {472		Ok(Val::Num(v.into()))473	}474475	fn serialize_i64(self, v: i64) -> Result<Val> {476		Ok(Val::Str(v.to_string().into()))477	}478479	fn serialize_u8(self, v: u8) -> Result<Val> {480		Ok(Val::Num(v.into()))481	}482483	fn serialize_u16(self, v: u16) -> Result<Val> {484		Ok(Val::Num(v.into()))485	}486487	fn serialize_u32(self, v: u32) -> Result<Val> {488		Ok(Val::Num(v.into()))489	}490491	fn serialize_u64(self, v: u64) -> Result<Val> {492		Ok(Val::Str(v.to_string().into()))493	}494495	fn serialize_f32(self, v: f32) -> Result<Val> {496		Ok(Val::try_num(f64::from(v))?)497	}498499	fn serialize_f64(self, v: f64) -> Result<Val> {500		Ok(Val::try_num(v)?)501	}502503	fn serialize_char(self, v: char) -> Result<Val> {504		Ok(Val::Str(v.to_string().into()))505	}506507	fn serialize_str(self, v: &str) -> Result<Val> {508		Ok(Val::Str(v.into()))509	}510511	fn serialize_bytes(self, v: &[u8]) -> Result<Val> {512		Ok(Val::Arr(ArrValue::bytes(v.into())))513	}514515	fn serialize_none(self) -> Result<Val> {516		Ok(Val::Null)517	}518519	fn serialize_some<T>(self, value: &T) -> Result<Val>520	where521		T: ?Sized + Serialize,522	{523		value.serialize(self)524	}525526	fn serialize_unit(self) -> Result<Val> {527		Ok(Val::Null)528	}529530	fn serialize_unit_struct(self, _name: &'static str) -> Result<Val> {531		Ok(Val::Null)532	}533534	fn serialize_unit_variant(535		self,536		_name: &'static str,537		_variant_index: u32,538		variant: &'static str,539	) -> Result<Val> {540		Ok(Val::Str(variant.into()))541	}542543	fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result<Val>544	where545		T: ?Sized + Serialize,546	{547		value.serialize(self)548	}549550	fn serialize_newtype_variant<T>(551		self,552		_name: &'static str,553		_variant_index: u32,554		variant: &'static str,555		value: &T,556	) -> Result<Val>557	where558		T: ?Sized + Serialize,559	{560		let mut out = ObjValue::builder_with_capacity(1);561		let value = value.serialize(self)?;562		out.field(variant).value(value);563		Ok(Val::Obj(out.build()))564	}565566	fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {567		Ok(len.map_or_else(568			IntoVecValSerializer::new,569			IntoVecValSerializer::with_capacity,570		))571	}572573	fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {574		Ok(IntoVecValSerializer::with_capacity(len))575	}576577	fn serialize_tuple_struct(578		self,579		_name: &'static str,580		len: usize,581	) -> Result<Self::SerializeTupleStruct, Self::Error> {582		Ok(IntoVecValSerializer::with_capacity(len))583	}584585	fn serialize_tuple_variant(586		self,587		_name: &'static str,588		_variant_index: u32,589		variant: &'static str,590		len: usize,591	) -> Result<Self::SerializeTupleVariant, Self::Error> {592		Ok(IntoVecValSerializer::variant_with_capacity(variant, len))593	}594595	fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {596		Ok(len.map_or_else(597			IntoObjValueSerializer::new,598			IntoObjValueSerializer::with_capacity,599		))600	}601602	fn serialize_struct(603		self,604		_name: &'static str,605		len: usize,606	) -> Result<Self::SerializeStruct, Self::Error> {607		Ok(IntoObjValueSerializer::with_capacity(len))608	}609610	fn serialize_struct_variant(611		self,612		_name: &'static str,613		_variant_index: u32,614		variant: &'static str,615		len: usize,616	) -> Result<Self::SerializeStructVariant, Self::Error> {617		Ok(IntoObjValueSerializer::variant_with_capacity(variant, len))618	}619}620621impl Val {622	pub fn from_serde(v: impl Serialize) -> Result<Self, JrError> {623		v.serialize(IntoValSerializer)624	}625}626627impl serde::ser::Error for JrError {628	fn custom<T>(msg: T) -> Self629	where630		T: std::fmt::Display,631	{632		runtime_error!("serde: {msg}")633	}634}
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -6,7 +6,7 @@
 
 use crate::{
 	ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,
-	arr::{ArrValue, BytesArray},
+	arr::ArrValue,
 	bail,
 	function::FuncVal,
 	typed::CheckType,
@@ -83,6 +83,12 @@
 pub trait Typed: Sized {
 	const TYPE: &'static ComplexValType;
 }
+impl<T> Typed for &T
+where
+	T: Typed,
+{
+	const TYPE: &'static ComplexValType = <&T as Typed>::TYPE;
+}
 pub trait IntoUntyped: Typed {
 	// Whatever caller should use `into_lazy_untyped` instead of `into_untyped`
 	fn provides_lazy() -> bool {
@@ -93,6 +99,7 @@
 		Thunk::from(Self::into_untyped(typed))
 	}
 }
+
 pub trait IntoUntypedResult: Typed {
 	/// Hack to make builtins be able to return non-result values, and make macros able to convert those values to result
 	/// This method returns identity in impl Typed for Result, and should not be overriden
@@ -157,6 +164,26 @@
 		inner.map(<ThunkIntoUntyped<T>>::default())
 	}
 }
+impl<T> IntoUntyped for &Thunk<T>
+where
+	T: IntoUntyped + Trace + Clone,
+{
+	fn into_untyped(typed: Self) -> Result<Val> {
+		T::into_untyped(typed.evaluate()?)
+	}
+	fn provides_lazy() -> bool {
+		true
+	}
+
+	fn into_lazy_untyped(inner: Self) -> Thunk<Val> {
+		// Avoid lazy mapping
+		let inner = match try_cast_thunk_val(inner.clone()) {
+			Ok(v) => return v,
+			Err(e) => e,
+		};
+		inner.map(<ThunkIntoUntyped<T>>::default())
+	}
+}
 
 fn try_cast_thunk_t<T: 'static>(typed: Thunk<Val>) -> Result<Thunk<T>, Thunk<Val>> {
 	if TypeId::of::<T>() == TypeId::of::<Val>() {
@@ -221,6 +248,11 @@
 				}
 			}
 		}
+		impl IntoUntyped for &$ty {
+			fn into_untyped(value: Self) -> Result<Val> {
+				Ok(Val::Num((*value).into()))
+			}
+		}
 		impl IntoUntyped for $ty {
 			fn into_untyped(value: Self) -> Result<Val> {
 				Ok(Val::Num(value.into()))
@@ -305,6 +337,11 @@
 impl Typed for f64 {
 	const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);
 }
+impl IntoUntyped for &f64 {
+	fn into_untyped(value: Self) -> Result<Val> {
+		Ok(Val::try_num(*value)?)
+	}
+}
 impl IntoUntyped for f64 {
 	fn into_untyped(value: Self) -> Result<Val> {
 		Ok(Val::try_num(value)?)
@@ -324,7 +361,7 @@
 impl Typed for PositiveF64 {
 	const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(0.0), None);
 }
-impl IntoUntyped for PositiveF64 {
+impl IntoUntyped for &PositiveF64 {
 	fn into_untyped(value: Self) -> Result<Val> {
 		Ok(Val::try_num(value.0)?)
 	}
@@ -538,6 +575,11 @@
 impl Typed for Val {
 	const TYPE: &'static ComplexValType = &ComplexValType::Any;
 }
+impl IntoUntyped for &Val {
+	fn into_untyped(typed: Self) -> Result<Val> {
+		Ok(typed.clone())
+	}
+}
 impl IntoUntyped for Val {
 	fn into_untyped(typed: Self) -> Result<Val> {
 		Ok(typed)
@@ -567,9 +609,14 @@
 	const TYPE: &'static ComplexValType =
 		&ComplexValType::ArrayRef(&ComplexValType::BoundedNumber(Some(0.0), Some(255.0)));
 }
+impl IntoUntyped for &IBytes {
+	fn into_untyped(value: Self) -> Result<Val> {
+		Ok(Val::arr(value.clone()))
+	}
+}
 impl IntoUntyped for IBytes {
 	fn into_untyped(value: Self) -> Result<Val> {
-		Ok(Val::Arr(ArrValue::bytes(value)))
+		Ok(Val::arr(value))
 	}
 }
 impl FromUntyped for IBytes {
@@ -578,8 +625,8 @@
 			<Self as Typed>::TYPE.check(&value)?;
 			unreachable!()
 		};
-		if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {
-			return Ok(bytes.0.as_slice().into());
+		if let Some(bytes) = a.as_any().downcast_ref::<IBytes>() {
+			return Ok(bytes.clone());
 		}
 		<Self as Typed>::TYPE.check(&value)?;
 		// Any::downcast_ref::<ByteArray>(&a);
@@ -596,7 +643,7 @@
 impl Typed for M1 {
 	const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(-1.0), Some(-1.0));
 }
-impl IntoUntyped for M1 {
+impl IntoUntyped for &M1 {
 	fn into_untyped(_: Self) -> Result<Val> {
 		Ok(Val::Num(NumValue::new(-1.0).expect("finite")))
 	}
@@ -728,6 +775,11 @@
 impl Typed for bool {
 	const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Bool);
 }
+impl IntoUntyped for &bool {
+	fn into_untyped(value: Self) -> Result<Val> {
+		Ok(Val::Bool(*value))
+	}
+}
 impl IntoUntyped for bool {
 	fn into_untyped(value: Self) -> Result<Val> {
 		Ok(Val::Bool(value))
@@ -764,19 +816,23 @@
 	}
 }
 
-pub struct Null;
-impl Typed for Null {
+impl Typed for () {
 	const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Null);
 }
-impl IntoUntyped for Null {
-	fn into_untyped(_: Self) -> Result<Val> {
+impl IntoUntyped for &() {
+	fn into_untyped((): Self) -> Result<Val> {
 		Ok(Val::Null)
 	}
 }
-impl FromUntyped for Null {
+impl IntoUntyped for () {
+	fn into_untyped((): Self) -> Result<Val> {
+		Ok(Val::Null)
+	}
+}
+impl FromUntyped for () {
 	fn from_untyped(value: Val) -> Result<Self> {
 		<Self as Typed>::TYPE.check(&value)?;
-		Ok(Self)
+		Ok(())
 	}
 }
 
@@ -811,9 +867,9 @@
 impl Typed for NumValue {
 	const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);
 }
-impl IntoUntyped for NumValue {
+impl IntoUntyped for &NumValue {
 	fn into_untyped(typed: Self) -> Result<Val> {
-		Ok(Val::Num(typed))
+		Ok(Val::Num(*typed))
 	}
 }
 impl FromUntyped for NumValue {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -137,7 +137,7 @@
 
 impl<T> Thunk<T>
 where
-	T: Clone + Trace,
+	T: Trace,
 {
 	pub fn force(&self) -> Result<()> {
 		self.evaluate()?;
@@ -161,7 +161,7 @@
 }
 impl<Input> Thunk<Input>
 where
-	Input: Trace + Clone,
+	Input: Trace,
 {
 	pub fn map<M>(self, mapper: M) -> Thunk<M::Output>
 	where
@@ -355,7 +355,7 @@
 			Self::Tree(Rc::new((a, b, len)))
 		}
 	}
-	pub fn into_flat(self) -> IStr {
+	pub fn into_flat(&self) -> IStr {
 		#[cold]
 		fn write_buf(s: &StrValue, out: &mut String) {
 			match s {
@@ -367,10 +367,10 @@
 			}
 		}
 		match self {
-			Self::Flat(f) => f,
+			Self::Flat(f) => f.clone(),
 			Self::Tree(_) => {
 				let mut buf = String::with_capacity(self.len());
-				write_buf(&self, &mut buf);
+				write_buf(self, &mut buf);
 				buf.into()
 			}
 		}
@@ -701,6 +701,9 @@
 	{
 		Ok(Self::Num(num.try_into()?))
 	}
+	pub fn arr(a: impl ArrayLike) -> Self {
+		Self::Arr(ArrValue::new(a))
+	}
 }
 
 impl From<IStr> for Val {
modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -34,7 +34,7 @@
 			for _ in 0..*sz {
 				out.push(trivial.clone());
 			}
-			Ok(ArrValue::eager(out))
+			Ok(ArrValue::new(out))
 		},
 	)
 }
@@ -256,7 +256,7 @@
 pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {
 	builtin_join(
 		IndexableVal::Str("\n".into()),
-		ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])),
+		ArrValue::extended(arr, ArrValue::new(vec![Val::string("")])),
 	)
 }
 
@@ -468,7 +468,7 @@
 					out.push(ele);
 				}
 			}
-			Val::Arr(ArrValue::eager(out))
+			Val::arr(out)
 		}
 		Val::Obj(o) => {
 			let mut out = ObjValueBuilder::new();
modifiedcrates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/sets.rs
+++ b/crates/jrsonnet-stdlib/src/sets.rs
@@ -29,7 +29,11 @@
 
 #[builtin]
 #[allow(non_snake_case, clippy::redundant_closure)]
-pub fn builtin_set_inter(a: ArrValue, b: ArrValue, #[default] keyF: KeyF) -> Result<ArrValue> {
+pub fn builtin_set_inter(
+	a: ArrValue,
+	b: ArrValue,
+	#[default] keyF: KeyF,
+) -> Result<Vec<Thunk<Val>>> {
 	let mut a = a.iter_lazy();
 	let mut b = b.iter_lazy();
 
@@ -60,12 +64,16 @@
 			}
 		}
 	}
-	Ok(ArrValue::lazy(out))
+	Ok(out)
 }
 
 #[builtin]
 #[allow(non_snake_case, clippy::redundant_closure)]
-pub fn builtin_set_diff(a: ArrValue, b: ArrValue, #[default] keyF: KeyF) -> Result<ArrValue> {
+pub fn builtin_set_diff(
+	a: ArrValue,
+	b: ArrValue,
+	#[default] keyF: KeyF,
+) -> Result<Vec<Thunk<Val>>> {
 	let mut a = a.iter_lazy();
 	let mut b = b.iter_lazy();
 
@@ -103,12 +111,16 @@
 		av = a.next();
 		ak = av.clone().map(keyF).transpose()?;
 	}
-	Ok(ArrValue::lazy(out))
+	Ok(out)
 }
 
 #[builtin]
 #[allow(non_snake_case, clippy::redundant_closure)]
-pub fn builtin_set_union(a: ArrValue, b: ArrValue, #[default] keyF: KeyF) -> Result<ArrValue> {
+pub fn builtin_set_union(
+	a: ArrValue,
+	b: ArrValue,
+	#[default] keyF: KeyF,
+) -> Result<Vec<Thunk<Val>>> {
 	let mut a = a.iter_lazy();
 	let mut b = b.iter_lazy();
 
@@ -154,5 +166,5 @@
 		bv = b.next();
 		bk = bv.clone().map(keyF).transpose()?;
 	}
-	Ok(ArrValue::lazy(out))
+	Ok(out)
 }
modifiedcrates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -113,11 +113,11 @@
 		return Ok(values);
 	}
 	if key_getter.is_identity() {
-		Ok(ArrValue::eager(sort_identity(
+		Ok(ArrValue::new(sort_identity(
 			values.iter().collect::<Result<Vec<Val>>>()?,
 		)?))
 	} else {
-		Ok(ArrValue::lazy(sort_keyf(values, key_getter)?))
+		Ok(ArrValue::new(sort_keyf(values, key_getter)?))
 	}
 }
 
@@ -162,11 +162,11 @@
 		return Ok(arr);
 	}
 	if keyF.is_identity() {
-		Ok(ArrValue::eager(uniq_identity(
+		Ok(ArrValue::new(uniq_identity(
 			arr.iter().collect::<Result<Vec<Val>>>()?,
 		)?))
 	} else {
-		Ok(ArrValue::lazy(uniq_keyf(arr, keyF)?))
+		Ok(ArrValue::new(uniq_keyf(arr, keyF)?))
 	}
 }
 
@@ -180,11 +180,11 @@
 		let arr = arr.iter().collect::<Result<Vec<Val>>>()?;
 		let arr = sort_identity(arr)?;
 		let arr = uniq_identity(arr)?;
-		Ok(ArrValue::eager(arr))
+		Ok(ArrValue::new(arr))
 	} else {
 		let arr = sort_keyf(arr, keyF.clone())?;
-		let arr = uniq_keyf(ArrValue::lazy(arr), keyF)?;
-		Ok(ArrValue::lazy(arr))
+		let arr = uniq_keyf(ArrValue::new(arr), keyF)?;
+		Ok(ArrValue::new(arr))
 	}
 }