git.delta.rocks / jrsonnet / refs/commits / cf6d90fc07cc

difftreelog

refactor drop impl ArgsLike for HashMap

ywsrpypxYaroslav Bolyukin2026-03-22parent: #57e587b.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/arglike.rs
+++ b/crates/jrsonnet-evaluator/src/function/arglike.rs
@@ -89,18 +89,6 @@
 	}
 }
 
-// TODO: Is this implementation really required, as there is no Context to use?
-// Maybe something a bit stricter is possible to add, especially with precompiled calls?
-impl ArgLike for TlaArg {
-	fn evaluate_arg(&self, _ctx: Context, tailstrict: bool) -> Result<Thunk<Val>> {
-		if tailstrict {
-			self.evaluate_tailstrict().map(Thunk::evaluated)
-		} else {
-			self.evaluate()
-		}
-	}
-}
-
 pub trait ArgsLike {
 	fn unnamed_len(&self) -> usize;
 	fn unnamed_iter(
@@ -205,121 +193,5 @@
 
 	fn is_empty(&self) -> bool {
 		self.unnamed.is_empty() && self.named.is_empty()
-	}
-}
-
-impl<V: ArgLike, S> ArgsLike for HashMap<IStr, V, S> {
-	fn unnamed_len(&self) -> usize {
-		0
-	}
-
-	fn unnamed_iter(
-		&self,
-		_ctx: Context,
-		_tailstrict: bool,
-		_handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		Ok(())
-	}
-
-	fn named_iter(
-		&self,
-		ctx: Context,
-		tailstrict: bool,
-		handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		for (name, value) in self {
-			handler(name, value.evaluate_arg(ctx.clone(), tailstrict)?)?;
-		}
-		Ok(())
-	}
-
-	fn named_names(&self, handler: &mut dyn FnMut(&IStr)) {
-		for name in self.keys() {
-			handler(name);
-		}
-	}
-
-	fn is_empty(&self) -> bool {
-		self.is_empty()
-	}
-}
-
-macro_rules! impl_args_like {
-	($count:expr; $($gen:ident)*) => {
-		impl<$($gen: ArgLike,)*> ArgsLike for ($($gen,)*) {
-			fn unnamed_len(&self) -> usize {
-				$count
-			}
-			#[allow(non_snake_case, unused_assignments)]
-			fn unnamed_iter(
-				&self,
-				ctx: Context,
-				tailstrict: bool,
-				handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-			) -> Result<()> {
-				let mut i = 0usize;
-				let ($($gen,)*) = self;
-				$(
-					handler(i, $gen.evaluate_arg(ctx.clone(), tailstrict)?)?;
-					i+=1;
-				)*
-				Ok(())
-			}
-			fn named_iter(
-				&self,
-				_ctx: Context,
-				_tailstrict: bool,
-				_handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
-			) -> Result<()> {
-				Ok(())
-			}
-			fn named_names(&self, _handler: &mut dyn FnMut(&IStr)) {}
-
-			fn is_empty(&self) -> bool {
-				// impl_args_like only implements non-empty tuples.
-				false
-			}
-		}
-	};
-	($count:expr; $($cur:ident)* @ $c:ident $($rest:ident)*) => {
-		impl_args_like!($count; $($cur)*);
-		impl_args_like!($count + 1usize; $($cur)* $c @ $($rest)*);
-	};
-	($count:expr; $($cur:ident)* @) => {
-		impl_args_like!($count; $($cur)*);
-	}
-}
-impl_args_like! {
-	// First argument is already in position, so count starts from 1
-	1usize; A @ B C D E F G H I J K L
-}
-
-impl ArgsLike for () {
-	fn unnamed_len(&self) -> usize {
-		0
-	}
-
-	fn unnamed_iter(
-		&self,
-		_ctx: Context,
-		_tailstrict: bool,
-		_handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		Ok(())
-	}
-
-	fn named_iter(
-		&self,
-		_ctx: Context,
-		_tailstrict: bool,
-		_handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		Ok(())
-	}
-
-	fn named_names(&self, _handler: &mut dyn FnMut(&IStr)) {}
-	fn is_empty(&self) -> bool {
-		true
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/tla.rsdiffbeforeafterboth
1use std::{collections::HashMap, hash::BuildHasher};1use std::{collections::HashMap, hash::BuildHasher};
22
3use jrsonnet_interner::IStr;3use jrsonnet_interner::IStr;
4use jrsonnet_parser::Source;
54
6use crate::{5use crate::{
7 function::{CallLocation, TlaArg},6 function::{CallLocation, PreparedFuncVal, TlaArg},
8 in_description_frame, with_state, Result, Val,7 in_description_frame, Result, Val,
9};8};
109
11pub fn apply_tla<H: BuildHasher>(args: &HashMap<IStr, TlaArg, H>, val: Val) -> Result<Val> {10pub fn apply_tla<H: BuildHasher>(args: &HashMap<IStr, TlaArg, H>, val: Val) -> Result<Val> {
12 Ok(if let Val::Func(func) = val {11 Ok(if let Val::Func(func) = val {
13 in_description_frame(12 in_description_frame(
14 || "during TLA call".to_owned(),13 || "during TLA call".to_owned(),
15 || {14 || {
16 func.evaluate(15 let mut names = Vec::with_capacity(args.len());
17 with_state(|s| {16 let mut values = Vec::with_capacity(args.len());
17 for (name, value) in args {
18 s.create_default_context(Source::new_virtual(18 names.push(name.clone());
19 "<top-level-arg>".into(),
20 IStr::empty(),
21 ))
22 }),
23 CallLocation::native(),19 values.push(value.evaluate()?);
24 args,20 }
25 false,21 let prepared = PreparedFuncVal::new(func, 0, &names)?;
26 )22 prepared.call(CallLocation::native(), &[], &values)
27 },23 },
28 )?24 )?
29 } else {25 } else {