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

difftreelog

refactor drop impl ArgsLike for HashMap

ywsrpypxYaroslav Bolyukin2026-03-21parent: #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
before · crates/jrsonnet-evaluator/src/tla.rs
1use std::{collections::HashMap, hash::BuildHasher};23use jrsonnet_interner::IStr;4use jrsonnet_parser::Source;56use crate::{7	function::{CallLocation, TlaArg},8	in_description_frame, with_state, Result, Val,9};1011pub fn apply_tla<H: BuildHasher>(args: &HashMap<IStr, TlaArg, H>, val: Val) -> Result<Val> {12	Ok(if let Val::Func(func) = val {13		in_description_frame(14			|| "during TLA call".to_owned(),15			|| {16				func.evaluate(17					with_state(|s| {18						s.create_default_context(Source::new_virtual(19							"<top-level-arg>".into(),20							IStr::empty(),21						))22					}),23					CallLocation::native(),24					args,25					false,26				)27			},28		)?29	} else {30		val31	})32}