git.delta.rocks / jrsonnet / refs/commits / 795a53dd5dd7

difftreelog

refactor drop ArgsLike abstraction

pltounypYaroslav Bolyukin2026-03-22parent: #cf6d90f.patch.diff
in: master

17 files changed

modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -22,11 +22,11 @@
 
 use jrsonnet_evaluator::{
 	apply_tla, bail,
-	function::TlaArg,
 	gc::WithCapacityExt as _,
 	manifest::{JsonFormat, ManifestFormat, ToStringFormat},
 	rustc_hash::FxHashMap,
 	stack::set_stack_depth_limit,
+	tla::TlaArg,
 	trace::{CompactFormat, PathResolver, TraceFormat},
 	AsPathLike, FileImportResolver, IStr, ImportResolver, Result, State, Val,
 };
@@ -40,6 +40,7 @@
 pub extern "C" fn _start() {}
 
 /// Return the version string of the Jsonnet interpreter.
+///
 /// Conforms to [semantic versioning](http://semver.org/).
 /// If this does not match `LIB_JSONNET_VERSION`
 /// then there is a mismatch between header and compiled library.
modifiedbindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/vars_tlas.rs
+++ b/bindings/jsonnet/src/vars_tlas.rs
@@ -2,7 +2,8 @@
 
 use std::{ffi::CStr, os::raw::c_char};
 
-use jrsonnet_evaluator::{function::TlaArg, IStr};
+use jrsonnet_evaluator::tla::TlaArg;
+use jrsonnet_evaluator::IStr;
 
 use crate::VM;
 
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
before · crates/jrsonnet-cli/src/stdlib.rs
1use std::str::FromStr;23use clap::Parser;4use jrsonnet_evaluator::{function::TlaArg, trace::PathResolver, Result};5use jrsonnet_stdlib::ContextInitializer;67#[derive(Clone)]8pub struct ExtStr {9	pub name: String,10	pub value: String,11}1213/// Parses a string like `name=<value>`, or `name` and reads value from env variable.14/// With no value it will be read from env variable.15/// If env variable is not found then it will be an error.16/// Value can contain `=` symbol.17///18/// ```19/// use std::str::FromStr;20/// use jrsonnet_cli::ExtStr;21///22/// let ext = ExtStr::from_str("name=value").unwrap();23/// assert_eq!(ext.name, "name");24/// assert_eq!(ext.value, "value");25///26/// std::env::set_var("name", "value");27///28/// let ext = ExtStr::from_str("name").unwrap();29/// assert_eq!(ext.name, "name");30/// assert_eq!(ext.value, "value");31///32/// let ext = ExtStr::from_str("name=value=with=equals").unwrap();33/// assert_eq!(ext.name, "name");34/// assert_eq!(ext.value, "value=with=equals");35/// ```36///37impl FromStr for ExtStr {38	type Err = &'static str;3940	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {41		match s.find('=') {42			Some(idx) => Ok(Self {43				name: s[..idx].to_owned(),44				value: s[idx + 1..].to_owned(),45			}),46			None => Ok(Self {47				name: s.to_owned(),48				value: std::env::var(s).or(Err("missing env var"))?,49			}),50		}51	}52}5354#[derive(Clone)]55pub struct ExtFile {56	pub name: String,57	pub path: String,58}5960impl FromStr for ExtFile {61	type Err = String;6263	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {64		let Some((name, path)) = s.split_once('=') else {65			return Err("bad ext-file syntax".to_owned());66		};67		Ok(Self {68			name: name.into(),69			path: path.into(),70		})71	}72}7374#[derive(Parser)]75#[clap(next_help_heading = "STANDARD LIBRARY")]76pub struct StdOpts {77	/// Disable standard library.78	/// By default standard library will be available via global `std` variable.79	#[clap(long)]80	no_stdlib: bool,81	/// Add string external variable.82	/// External variables are globally available so it is preferred83	/// to use top level arguments whenever it's possible.84	/// If [=data] is not set then it will be read from `name` env variable.85	/// Can be accessed from code via `std.extVar("name")`.86	#[clap(long, short = 'V', name = "name[=var data]", number_of_values = 1)]87	ext_str: Vec<ExtStr>,88	/// Read string external variable from file.89	/// See also `--ext-str`90	#[clap(long, name = "name=var path", number_of_values = 1)]91	ext_str_file: Vec<ExtFile>,92	/// Add external variable from code.93	/// See also `--ext-str`94	#[clap(long, name = "name[=var source]", number_of_values = 1)]95	ext_code: Vec<ExtStr>,96	/// Read string external variable from file.97	/// See also `--ext-str`98	#[clap(long, name = "name=var code path", number_of_values = 1)]99	ext_code_file: Vec<ExtFile>,100}101impl StdOpts {102	pub fn context_initializer(&self) -> Result<Option<ContextInitializer>> {103		if self.no_stdlib {104			return Ok(None);105		}106		let ctx = ContextInitializer::new(PathResolver::new_cwd_fallback());107		for ext in &self.ext_str {108			ctx.settings_mut().ext_vars.insert(109				ext.name.as_str().into(),110				TlaArg::String(ext.value.as_str().into()),111			);112		}113		for ext in &self.ext_str_file {114			ctx.settings_mut().ext_vars.insert(115				ext.name.as_str().into(),116				TlaArg::ImportStr(ext.path.clone()),117			);118		}119		for ext in &self.ext_code {120			ctx.settings_mut().ext_vars.insert(121				ext.name.as_str().into(),122				TlaArg::InlineCode(ext.value.clone()),123			);124		}125		for ext in &self.ext_code_file {126			ctx.settings_mut()127				.ext_vars128				.insert(ext.name.as_str().into(), TlaArg::Import(ext.path.clone()));129		}130		Ok(Some(ctx))131	}132}
after · crates/jrsonnet-cli/src/stdlib.rs
1use std::str::FromStr;23use clap::Parser;4use jrsonnet_evaluator::tla::TlaArg;5use jrsonnet_evaluator::{trace::PathResolver, Result};6use jrsonnet_stdlib::ContextInitializer;78#[derive(Clone)]9pub struct ExtStr {10	pub name: String,11	pub value: String,12}1314/// Parses a string like `name=<value>`, or `name` and reads value from env variable.15/// With no value it will be read from env variable.16/// If env variable is not found then it will be an error.17/// Value can contain `=` symbol.18///19/// ```20/// use std::str::FromStr;21/// use jrsonnet_cli::ExtStr;22///23/// let ext = ExtStr::from_str("name=value").unwrap();24/// assert_eq!(ext.name, "name");25/// assert_eq!(ext.value, "value");26///27/// std::env::set_var("name", "value");28///29/// let ext = ExtStr::from_str("name").unwrap();30/// assert_eq!(ext.name, "name");31/// assert_eq!(ext.value, "value");32///33/// let ext = ExtStr::from_str("name=value=with=equals").unwrap();34/// assert_eq!(ext.name, "name");35/// assert_eq!(ext.value, "value=with=equals");36/// ```37///38impl FromStr for ExtStr {39	type Err = &'static str;4041	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {42		match s.find('=') {43			Some(idx) => Ok(Self {44				name: s[..idx].to_owned(),45				value: s[idx + 1..].to_owned(),46			}),47			None => Ok(Self {48				name: s.to_owned(),49				value: std::env::var(s).or(Err("missing env var"))?,50			}),51		}52	}53}5455#[derive(Clone)]56pub struct ExtFile {57	pub name: String,58	pub path: String,59}6061impl FromStr for ExtFile {62	type Err = String;6364	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {65		let Some((name, path)) = s.split_once('=') else {66			return Err("bad ext-file syntax".to_owned());67		};68		Ok(Self {69			name: name.into(),70			path: path.into(),71		})72	}73}7475#[derive(Parser)]76#[clap(next_help_heading = "STANDARD LIBRARY")]77pub struct StdOpts {78	/// Disable standard library.79	/// By default standard library will be available via global `std` variable.80	#[clap(long)]81	no_stdlib: bool,82	/// Add string external variable.83	/// External variables are globally available so it is preferred84	/// to use top level arguments whenever it's possible.85	/// If [=data] is not set then it will be read from `name` env variable.86	/// Can be accessed from code via `std.extVar("name")`.87	#[clap(long, short = 'V', name = "name[=var data]", number_of_values = 1)]88	ext_str: Vec<ExtStr>,89	/// Read string external variable from file.90	/// See also `--ext-str`91	#[clap(long, name = "name=var path", number_of_values = 1)]92	ext_str_file: Vec<ExtFile>,93	/// Add external variable from code.94	/// See also `--ext-str`95	#[clap(long, name = "name[=var source]", number_of_values = 1)]96	ext_code: Vec<ExtStr>,97	/// Read string external variable from file.98	/// See also `--ext-str`99	#[clap(long, name = "name=var code path", number_of_values = 1)]100	ext_code_file: Vec<ExtFile>,101}102impl StdOpts {103	pub fn context_initializer(&self) -> Result<Option<ContextInitializer>> {104		if self.no_stdlib {105			return Ok(None);106		}107		let ctx = ContextInitializer::new(PathResolver::new_cwd_fallback());108		for ext in &self.ext_str {109			ctx.settings_mut().ext_vars.insert(110				ext.name.as_str().into(),111				TlaArg::String(ext.value.as_str().into()),112			);113		}114		for ext in &self.ext_str_file {115			ctx.settings_mut().ext_vars.insert(116				ext.name.as_str().into(),117				TlaArg::ImportStr(ext.path.clone()),118			);119		}120		for ext in &self.ext_code {121			ctx.settings_mut().ext_vars.insert(122				ext.name.as_str().into(),123				TlaArg::InlineCode(ext.value.clone()),124			);125		}126		for ext in &self.ext_code_file {127			ctx.settings_mut()128				.ext_vars129				.insert(ext.name.as_str().into(), TlaArg::Import(ext.path.clone()));130		}131		Ok(Some(ctx))132	}133}
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -1,7 +1,6 @@
 use clap::Parser;
-use jrsonnet_evaluator::{
-	error::Result, function::TlaArg, gc::WithCapacityExt as _, rustc_hash::FxHashMap, IStr,
-};
+use jrsonnet_evaluator::tla::TlaArg;
+use jrsonnet_evaluator::{error::Result, gc::WithCapacityExt as _, rustc_hash::FxHashMap, IStr};
 
 use crate::{ExtFile, ExtStr};
 
modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -9,7 +9,7 @@
 use jrsonnet_interner::IBytes;
 use jrsonnet_parser::{Expr, Spanned};
 
-use crate::{typed::NativeFn, Context, Result, Thunk, Val};
+use crate::{function::NativeFn, Context, Result, Thunk, Val};
 
 mod spec;
 pub use spec::{ArrayLike, *};
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -6,8 +6,7 @@
 use jrsonnet_parser::{Expr, Spanned};
 
 use super::ArrValue;
-use crate::typed::NativeFn;
-use crate::val::NumValue;
+use crate::function::NativeFn;
 use crate::{
 	error::ErrorKind::InfiniteRecursionDetected, evaluate, typed::Typed, val::ThunkValue, Context,
 	Error, ObjValue, Result, Thunk, Val,
deletedcrates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/arglike.rs
+++ /dev/null
@@ -1,197 +0,0 @@
-use std::collections::HashMap;
-use std::rc::Rc;
-
-use jrsonnet_gcmodule::Trace;
-use jrsonnet_interner::IStr;
-use jrsonnet_parser::{ArgsDesc, Expr, SourceFifo, SourcePath, Spanned};
-
-use crate::{evaluate, typed::Typed, with_state, Context, Result, Thunk, Val};
-
-pub trait ArgLike {
-	fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result<Thunk<Val>>;
-}
-
-impl ArgLike for &Rc<Spanned<Expr>> {
-	fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result<Thunk<Val>> {
-		Ok(if tailstrict {
-			Thunk::evaluated(evaluate(ctx, self)?)
-		} else {
-			let expr = (*self).clone();
-			Thunk!(move || evaluate(ctx, &expr))
-		})
-	}
-}
-
-impl<T> ArgLike for T
-where
-	T: Typed + Clone,
-{
-	fn evaluate_arg(&self, _ctx: Context, tailstrict: bool) -> Result<Thunk<Val>> {
-		if T::provides_lazy() && !tailstrict {
-			return Ok(T::into_lazy_untyped(self.clone()));
-		}
-		let val = T::into_untyped(self.clone())?;
-		Ok(Thunk::evaluated(val))
-	}
-}
-
-#[derive(Clone, Trace)]
-pub enum TlaArg {
-	String(IStr),
-	Val(Val),
-	Lazy(Thunk<Val>),
-	Import(String),
-	ImportStr(String),
-	InlineCode(String),
-}
-impl TlaArg {
-	pub fn evaluate_tailstrict(&self) -> Result<Val> {
-		match self {
-			Self::String(s) => Ok(Val::string(s.clone())),
-			Self::Val(val) => Ok(val.clone()),
-			Self::Lazy(lazy) => Ok(lazy.evaluate()?),
-			Self::Import(p) => with_state(|s| {
-				let resolved = s.resolve_from_default(&p.as_str())?;
-				s.import_resolved(resolved)
-			}),
-			Self::ImportStr(p) => with_state(|s| {
-				let resolved = s.resolve_from_default(&p.as_str())?;
-				s.import_resolved_str(resolved).map(Val::string)
-			}),
-			Self::InlineCode(p) => with_state(|s| {
-				let resolved =
-					SourcePath::new(SourceFifo("<inline code>".to_owned(), p.as_bytes().into()));
-				s.import_resolved(resolved)
-			}),
-		}
-	}
-	pub fn evaluate(&self) -> Result<Thunk<Val>> {
-		match self {
-			Self::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
-			Self::Val(val) => Ok(Thunk::evaluated(val.clone())),
-			Self::Lazy(lazy) => Ok(lazy.clone()),
-			Self::Import(p) => with_state(|s| {
-				let resolved = s.resolve_from_default(&p.as_str())?;
-				Ok(Thunk!(move || s.import_resolved(resolved)))
-			}),
-			Self::ImportStr(p) => with_state(|s| {
-				let resolved = s.resolve_from_default(&p.as_str())?;
-				Ok(Thunk!(move || s
-					.import_resolved_str(resolved)
-					.map(Val::string)))
-			}),
-			Self::InlineCode(p) => with_state(|s| {
-				let resolved =
-					SourcePath::new(SourceFifo("<inline code>".to_owned(), p.as_bytes().into()));
-				Ok(Thunk!(move || s.import_resolved(resolved)))
-			}),
-		}
-	}
-}
-
-pub trait ArgsLike {
-	fn unnamed_len(&self) -> usize;
-	fn unnamed_iter(
-		&self,
-		ctx: Context,
-		tailstrict: bool,
-		handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-	) -> Result<()>;
-	fn named_iter(
-		&self,
-		ctx: Context,
-		tailstrict: bool,
-		handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
-	) -> Result<()>;
-	fn named_names(&self, handler: &mut dyn FnMut(&IStr));
-	fn is_empty(&self) -> bool;
-}
-
-impl ArgsLike for Vec<Val> {
-	fn unnamed_len(&self) -> usize {
-		self.len()
-	}
-	fn unnamed_iter(
-		&self,
-		_ctx: Context,
-		_tailstrict: bool,
-		handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		for (idx, el) in self.iter().enumerate() {
-			handler(idx, Thunk::evaluated(el.clone()))?;
-		}
-		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 {
-		self.is_empty()
-	}
-}
-
-impl ArgsLike for ArgsDesc {
-	fn unnamed_len(&self) -> usize {
-		self.unnamed.len()
-	}
-
-	fn unnamed_iter(
-		&self,
-		ctx: Context,
-		tailstrict: bool,
-		handler: &mut dyn FnMut(usize, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		for (id, arg) in self.unnamed.iter().enumerate() {
-			handler(
-				id,
-				if tailstrict {
-					Thunk::evaluated(evaluate(ctx.clone(), arg)?)
-				} else {
-					let ctx = ctx.clone();
-					let arg = arg.clone();
-
-					Thunk!(move || evaluate(ctx, &arg))
-				},
-			)?;
-		}
-		Ok(())
-	}
-
-	fn named_iter(
-		&self,
-		ctx: Context,
-		tailstrict: bool,
-		handler: &mut dyn FnMut(&IStr, Thunk<Val>) -> Result<()>,
-	) -> Result<()> {
-		for (name, arg) in &self.named {
-			handler(
-				name,
-				if tailstrict {
-					Thunk::evaluated(evaluate(ctx.clone(), arg)?)
-				} else {
-					let ctx = ctx.clone();
-					let arg = arg.clone();
-
-					Thunk!(move || evaluate(ctx, &arg))
-				},
-			)?;
-		}
-		Ok(())
-	}
-
-	fn named_names(&self, handler: &mut dyn FnMut(&IStr)) {
-		for (name, _) in &self.named {
-			handler(name);
-		}
-	}
-
-	fn is_empty(&self) -> bool {
-		self.unnamed.is_empty() && self.named.is_empty()
-	}
-}
modifiedcrates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -1,11 +1,10 @@
 use std::{fmt::Debug, rc::Rc};
 
-pub use arglike::{ArgLike, ArgsLike, TlaArg};
 use educe::Educe;
 use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 pub use jrsonnet_macros::builtin;
-use jrsonnet_parser::{Destruct, Expr, ExprParams, Span, Spanned};
+use jrsonnet_parser::{ArgsDesc, Destruct, Expr, ExprParams, Span, Spanned};
 
 use self::{
 	builtin::{Builtin, StaticBuiltin},
@@ -17,12 +16,12 @@
 	Result, Thunk, Val,
 };
 
-pub mod arglike;
 pub mod builtin;
-pub mod native;
-pub mod parse;
+mod native;
+mod parse;
 mod prepared;
 
+pub use native::NativeFn;
 pub use prepared::PreparedFuncVal;
 
 pub use jrsonnet_parser::function::*;
@@ -81,10 +80,10 @@
 	}
 
 	/// Create context, with which body code will run
-	pub fn call_body_context(
+	pub(crate) fn call_body_context(
 		&self,
 		call_ctx: Context,
-		args: &dyn ArgsLike,
+		args: &ArgsDesc,
 		tailstrict: bool,
 	) -> Result<Context> {
 		parse_function_call(call_ctx, self.ctx.clone(), &self.params, args, tailstrict)
@@ -170,7 +169,7 @@
 		&self,
 		call_ctx: Context,
 		loc: CallLocation<'_>,
-		args: &dyn ArgsLike,
+		args: &ArgsDesc,
 		tailstrict: bool,
 	) -> Result<Val> {
 		match self {
@@ -179,7 +178,7 @@
 				evaluate(body_ctx, &func.body)
 			}
 			Self::Thunk(thunk) => {
-				if !args.is_empty() {
+				if !args.named.is_empty() || !args.unnamed.is_empty() {
 					bail!(TooManyArgsFunctionHas(0, FunctionSignature::empty()))
 				}
 				thunk.evaluate()
modifiedcrates/jrsonnet-evaluator/src/function/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/native.rs
+++ b/crates/jrsonnet-evaluator/src/function/native.rs
@@ -1,2 +1,68 @@
+use std::marker::PhantomData;
+
+use jrsonnet_gcmodule::Trace;
+
 use super::PreparedFuncVal;
-use crate::{typed::Typed, CallLocation, Result, Thunk};
+use crate::{bail, function::FuncVal, typed::Typed, CallLocation, Result, Val};
+use jrsonnet_types::{ComplexValType, ValType};
+
+#[derive(Debug, Trace, Clone)]
+pub struct NativeFn<D: 'static>(pub(crate) PreparedFuncVal, PhantomData<D>);
+macro_rules! impl_native_desc {
+	($i:expr; $($gen:ident)*) => {
+		impl<$($gen,)* O> NativeFn<($($gen,)* O,)>
+		where
+			$($gen: Typed,)*
+			O: Typed,
+		{
+			#[allow(non_snake_case, clippy::too_many_arguments)]
+			pub fn call(
+				&self,
+				$($gen: $gen,)*
+			) -> Result<O> {
+				let val = self.0.call(
+					CallLocation::native(),
+					&[$(Typed::into_lazy_untyped($gen),)*],
+					&[],
+				)?;
+				O::from_untyped(val)
+			}
+		}
+		impl<$($gen,)* O> Typed for NativeFn<($($gen,)* O,)> {
+			const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);
+
+			fn into_untyped(_typed: Self) -> Result<Val> {
+				bail!("can only convert functions from jsonnet to native")
+			}
+
+			fn from_untyped(untyped: Val) -> Result<Self> {
+				let func = FuncVal::from_untyped(untyped)?;
+				Ok(Self(
+					PreparedFuncVal::new(func, $i, &[])?,
+					PhantomData,
+				))
+			}
+		}
+	};
+	($i:expr; $($cur:ident)* @ $c:ident $($rest:ident)*) => {
+		impl_native_desc!($i; $($cur)*);
+		impl_native_desc!($i + 1; $($cur)* $c @ $($rest)*);
+	};
+	($i:expr; $($cur:ident)* @) => {
+		impl_native_desc!($i; $($cur)*);
+	}
+}
+
+impl_native_desc! {
+	0; @ A B C D E F G H I J K L
+}
+
+mod native_macro {
+	#[macro_export]
+	macro_rules! NativeFn {
+		(($($t:ty),* $(,)?) -> $res:ty) => {
+			NativeFn<($($t,)* $res)>
+		}
+	}
+}
+pub use crate::NativeFn;
modifiedcrates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -1,19 +1,29 @@
+use std::rc::Rc;
+
 use jrsonnet_parser::{
 	function::{FunctionSignature, ParamName},
-	ExprParams,
+	ArgsDesc, Expr, ExprParams, Spanned,
 };
 use rustc_hash::FxHashMap;
 
-use super::arglike::ArgsLike;
 use crate::{
 	bail,
 	destructure::destruct,
 	error::{ErrorKind::*, Result},
-	evaluate_named_param,
+	evaluate, evaluate_named_param,
 	gc::WithCapacityExt as _,
 	Context, Pending, Thunk, Val,
 };
 
+fn eval_arg(ctx: Context, arg: &Rc<Spanned<Expr>>, tailstrict: bool) -> Result<Thunk<Val>> {
+	if tailstrict {
+		Ok(Thunk::evaluated(evaluate(ctx, arg)?))
+	} else {
+		let arg = arg.clone();
+		Ok(Thunk!(move || evaluate(ctx, &arg)))
+	}
+}
+
 /// Creates correct [context](Context) for function body evaluation returning error on invalid call.
 ///
 /// ## Parameters
@@ -22,15 +32,15 @@
 /// * `params`: function parameters' definition
 /// * `args`: passed function arguments
 /// * `tailstrict`: if set to `true` function arguments are eagerly executed, otherwise - lazily
-pub fn parse_function_call(
+pub(crate) fn parse_function_call(
 	ctx: Context,
 	body_ctx: Context,
 	params: &ExprParams,
-	args: &dyn ArgsLike,
+	args: &ArgsDesc,
 	tailstrict: bool,
 ) -> Result<Context> {
 	let mut passed_args = FxHashMap::with_capacity(params.binds_len());
-	if args.unnamed_len() > params.signature.len() {
+	if args.unnamed.len() > params.signature.len() {
 		bail!(TooManyArgsFunctionHas(
 			params.signature.len(),
 			params.signature.clone(),
@@ -40,28 +50,29 @@
 	let mut filled_named = 0;
 	let mut filled_positionals = 0;
 
-	args.unnamed_iter(ctx.clone(), tailstrict, &mut |id, arg| {
+	for (id, arg) in args.unnamed.iter().enumerate() {
 		destruct(
 			&params.exprs[id].destruct,
-			arg,
+			eval_arg(ctx.clone(), arg, tailstrict)?,
 			Pending::new_filled(ctx.clone()),
 			&mut passed_args,
 		)?;
 		filled_positionals += 1;
-		Ok(())
-	})?;
+	}
 
-	args.named_iter(ctx, tailstrict, &mut |name, value| {
+	for (name, value) in &args.named {
 		// FIXME: O(n) for arg existence check
 		if !params.exprs.iter().any(|p| &p.destruct.name() == name) {
 			bail!(UnknownFunctionParameter(name.clone()));
 		}
-		if passed_args.insert(name.clone(), value).is_some() {
+		if passed_args
+			.insert(name.clone(), eval_arg(ctx.clone(), value, tailstrict)?)
+			.is_some()
+		{
 			bail!(BindingParameterASecondTime(name.clone()));
 		}
 		filled_named += 1;
-		Ok(())
-	})?;
+	}
 
 	if filled_named + filled_positionals < params.len() {
 		// Some args are unset, but maybe we have defaults for them
@@ -104,13 +115,13 @@
 
 		// Some args still weren't filled
 		if filled_named + filled_positionals != params.len() {
-			for param in params.exprs.iter().skip(args.unnamed_len()) {
+			for param in params.exprs.iter().skip(args.unnamed.len()) {
 				let mut found = false;
-				args.named_names(&mut |name| {
+				for (name, _) in &args.named {
 					if &param.destruct.name() == name {
 						found = true;
 					}
-				});
+				}
 				if !found {
 					bail!(FunctionParameterNotBoundInCall(
 						param.destruct.name(),
@@ -141,34 +152,35 @@
 pub fn parse_builtin_call(
 	ctx: Context,
 	params: FunctionSignature,
-	args: &dyn ArgsLike,
+	args: &ArgsDesc,
 	tailstrict: bool,
 ) -> Result<Vec<Option<Thunk<Val>>>> {
 	let mut passed_args: Vec<Option<Thunk<Val>>> = vec![None; params.len()];
-	if args.unnamed_len() > params.len() {
+	if args.unnamed.len() > params.len() {
 		bail!(TooManyArgsFunctionHas(params.len(), params,))
 	}
 
 	let mut filled_args = 0;
 
-	args.unnamed_iter(ctx.clone(), tailstrict, &mut |id, arg| {
-		passed_args[id] = Some(arg);
+	for (id, arg) in args.unnamed.iter().enumerate() {
+		passed_args[id] = Some(eval_arg(ctx.clone(), arg, tailstrict)?);
 		filled_args += 1;
-		Ok(())
-	})?;
+	}
 
-	args.named_iter(ctx, tailstrict, &mut |name, arg| {
+	for (name, arg) in &args.named {
 		// FIXME: O(n) for arg existence check
 		let id = params
 			.iter()
 			.position(|p| p.name() == name)
 			.ok_or_else(|| UnknownFunctionParameter(name.clone()))?;
-		if passed_args[id].replace(arg).is_some() {
+		if passed_args[id]
+			.replace(eval_arg(ctx.clone(), arg, tailstrict)?)
+			.is_some()
+		{
 			bail!(BindingParameterASecondTime(name.clone()));
 		}
 		filled_args += 1;
-		Ok(())
-	})?;
+	}
 
 	if filled_args < params.len() {
 		for (id, _) in params.iter().enumerate().filter(|(_, p)| p.has_default()) {
@@ -180,13 +192,13 @@
 
 		// Some args still wasn't filled
 		if filled_args != params.len() {
-			for param in params.iter().skip(args.unnamed_len()) {
+			for param in params.iter().skip(args.unnamed.len()) {
 				let mut found = false;
-				args.named_names(&mut |name| {
+				for (name, _) in &args.named {
 					if param.name() == name {
 						found = true;
 					}
-				});
+				}
 				if !found {
 					bail!(FunctionParameterNotBoundInCall(
 						param.name().clone(),
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -19,7 +19,7 @@
 mod obj;
 pub mod stack;
 pub mod stdlib;
-mod tla;
+pub mod tla;
 pub mod trace;
 pub mod typed;
 pub mod val;
modifiedcrates/jrsonnet-evaluator/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/tla.rs
+++ b/crates/jrsonnet-evaluator/src/tla.rs
@@ -1,12 +1,68 @@
 use std::{collections::HashMap, hash::BuildHasher};
 
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
+use jrsonnet_parser::{SourceFifo, SourcePath};
 
 use crate::{
-	function::{CallLocation, PreparedFuncVal, TlaArg},
-	in_description_frame, Result, Val,
+	function::{CallLocation, PreparedFuncVal},
+	in_description_frame, with_state, Result, Thunk, Val,
 };
 
+#[derive(Clone, Trace)]
+pub enum TlaArg {
+	String(IStr),
+	Val(Val),
+	Lazy(Thunk<Val>),
+	Import(String),
+	ImportStr(String),
+	InlineCode(String),
+}
+impl TlaArg {
+	pub fn evaluate_tailstrict(&self) -> Result<Val> {
+		match self {
+			Self::String(s) => Ok(Val::string(s.clone())),
+			Self::Val(val) => Ok(val.clone()),
+			Self::Lazy(lazy) => Ok(lazy.evaluate()?),
+			Self::Import(p) => with_state(|s| {
+				let resolved = s.resolve_from_default(&p.as_str())?;
+				s.import_resolved(resolved)
+			}),
+			Self::ImportStr(p) => with_state(|s| {
+				let resolved = s.resolve_from_default(&p.as_str())?;
+				s.import_resolved_str(resolved).map(Val::string)
+			}),
+			Self::InlineCode(p) => with_state(|s| {
+				let resolved =
+					SourcePath::new(SourceFifo("<inline code>".to_owned(), p.as_bytes().into()));
+				s.import_resolved(resolved)
+			}),
+		}
+	}
+	pub fn evaluate(&self) -> Result<Thunk<Val>> {
+		match self {
+			Self::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
+			Self::Val(val) => Ok(Thunk::evaluated(val.clone())),
+			Self::Lazy(lazy) => Ok(lazy.clone()),
+			Self::Import(p) => with_state(|s| {
+				let resolved = s.resolve_from_default(&p.as_str())?;
+				Ok(Thunk!(move || s.import_resolved(resolved)))
+			}),
+			Self::ImportStr(p) => with_state(|s| {
+				let resolved = s.resolve_from_default(&p.as_str())?;
+				Ok(Thunk!(move || s
+					.import_resolved_str(resolved)
+					.map(Val::string)))
+			}),
+			Self::InlineCode(p) => with_state(|s| {
+				let resolved =
+					SourcePath::new(SourceFifo("<inline code>".to_owned(), p.as_bytes().into()));
+				Ok(Thunk!(move || s.import_resolved(resolved)))
+			}),
+		}
+	}
+}
+
 pub fn apply_tla<H: BuildHasher>(args: &HashMap<IStr, TlaArg, H>, val: Val) -> Result<Val> {
 	Ok(if let Val::Func(func) = val {
 		in_description_frame(
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -8,7 +8,7 @@
 use crate::{
 	arr::{ArrValue, BytesArray},
 	bail,
-	function::{CallLocation, FuncDesc, FuncVal, PreparedFuncVal},
+	function::{FuncDesc, FuncVal},
 	typed::CheckType,
 	val::{IndexableVal, NumValue, StrValue, ThunkMapper},
 	ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,
@@ -671,69 +671,9 @@
 			Ok(None)
 		} else {
 			T::from_untyped(untyped).map(Some)
-		}
-	}
-}
-
-#[derive(Debug, Trace, Clone)]
-pub struct NativeFn<D: 'static>(pub(crate) PreparedFuncVal, PhantomData<D>);
-macro_rules! impl_native_desc {
-	($i:expr; $($gen:ident)*) => {
-		impl<$($gen,)* O> NativeFn<($($gen,)* O,)>
-		where
-			$($gen: Typed,)*
-			O: Typed,
-		{
-			pub fn call(
-				&self,
-				$($gen: $gen,)*
-			) -> Result<O> {
-				let val = self.0.call(
-					CallLocation::native(),
-					&[$(Typed::into_lazy_untyped($gen),)*],
-					&[],
-				)?;
-				O::from_untyped(val)
-			}
-		}
-		impl<$($gen,)* O> Typed for NativeFn<($($gen,)* O,)> {
-			const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);
-
-			fn into_untyped(_typed: Self) -> Result<Val> {
-				bail!("can only convert functions from jsonnet to native")
-			}
-
-			fn from_untyped(untyped: Val) -> Result<Self> {
-				let func = FuncVal::from_untyped(untyped)?;
-				Ok(Self(
-					PreparedFuncVal::new(func, $i, &[])?,
-					PhantomData,
-				))
-			}
 		}
-	};
-	($i:expr; $($cur:ident)* @ $c:ident $($rest:ident)*) => {
-		impl_native_desc!($i; $($cur)*);
-		impl_native_desc!($i + 1; $($cur)* $c @ $($rest)*);
-	};
-	($i:expr; $($cur:ident)* @) => {
-		impl_native_desc!($i; $($cur)*);
 	}
-}
-
-impl_native_desc! {
-	0; @ A B C D E F G H I J K L
 }
-
-mod native_macro {
-	#[macro_export]
-	macro_rules! NativeFn {
-		(($($t:ty),* $(,)?) -> $res:ty) => {
-			NativeFn<($($t,)* $res)>
-		}
-	}
-}
-pub use crate::NativeFn;
 
 impl Typed for NumValue {
 	const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -405,7 +405,7 @@
 		const _: () = {
 			use ::jrsonnet_evaluator::{
 				State, Val,
-				function::{builtin::{Builtin, StaticBuiltin}, FunctionSignature, ParamParse, ParamName, ParamDefault, CallLocation, ArgsLike, parse::parse_builtin_call},
+				function::{builtin::{Builtin, StaticBuiltin}, FunctionSignature, ParamParse, ParamName, ParamDefault, CallLocation},
 				Result, Context, typed::Typed,
 				parser::Span, params, Thunk,
 			};
modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -2,9 +2,9 @@
 
 use jrsonnet_evaluator::{
 	bail,
-	function::{builtin, FuncVal},
+	function::{builtin, FuncVal, NativeFn},
 	runtime_error,
-	typed::{BoundedI32, BoundedUsize, Either2, NativeFn, Typed},
+	typed::{BoundedI32, BoundedUsize, Either2, Typed},
 	val::{equals, ArrValue, IndexableVal},
 	Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,
 };
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -13,7 +13,8 @@
 pub use hash::*;
 use jrsonnet_evaluator::{
 	error::Result,
-	function::{CallLocation, FuncVal, TlaArg},
+	function::{CallLocation, FuncVal},
+	tla::TlaArg,
 	trace::PathResolver,
 	val::NumValue,
 	ContextBuilder, IStr, ObjValue, ObjValueBuilder, Thunk, Val,
modifiedtests/tests/cpp_test_suite.rsdiffbeforeafterboth
--- a/tests/tests/cpp_test_suite.rs
+++ b/tests/tests/cpp_test_suite.rs
@@ -6,10 +6,10 @@
 
 use jrsonnet_evaluator::{
 	FileImportResolver, IStr, ObjValueBuilder, State, Val, apply_tla,
-	function::TlaArg,
 	gc::WithCapacityExt as _,
 	manifest::JsonFormat,
 	rustc_hash::FxHashMap,
+	tla::TlaArg,
 	trace::{CompactFormat, PathResolver, TraceFormat},
 };
 use jrsonnet_stdlib::ContextInitializer;