git.delta.rocks / jrsonnet / refs/commits / 18dc4db46973

difftreelog

fix experimental features build

Yaroslav Bolyukin2024-06-18parent: #1086a51.patch.diff
in: master

3 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
187187
188 let tla = opts.tla.tla_opts()?;188 let tla = opts.tla.tla_opts()?;
189 #[allow(unused_mut)]189 #[allow(
190 // It is not redundant/unused in exp-apply
191 unused_mut,
192 clippy::redundant_clone,
193 )]
190 let mut val = apply_tla(s, &tla, val)?;194 let mut val = apply_tla(s.clone(), &tla, val)?;
191195
192 #[cfg(feature = "exp-apply")]196 #[cfg(feature = "exp-apply")]
193 for apply in opts.input.exp_apply {197 for apply in opts.input.exp_apply {
modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -70,7 +70,13 @@
 #[builtin]
 pub fn builtin_map_with_key(func: FuncVal, obj: ObjValue) -> Result<ObjValue> {
 	let mut out = ObjValueBuilder::new();
-	for (k, v) in obj.iter() {
+	for (k, v) in obj.iter(
+		// Makes sense mapped object should be ordered the same way, should not break anything when the output is not ordered (the default).
+		// The thrown error might be different, but jsonnet
+		// does not specify the evaluation order.
+		#[cfg(feature = "exp-preserve-order")]
+		true,
+	) {
 		let v = v?;
 		out.field(k.clone())
 			.value(func.evaluate_simple(&(k, v), false)?);
modifiedcrates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -147,7 +147,14 @@
 	if equals(&a, &b)? {
 		return Ok(true);
 	}
-	let format = JsonFormat::std_to_json("  ".to_owned(), "\n", ": ");
+	// TODO: Use debug output format
+	let format = JsonFormat::std_to_json(
+		"  ".to_owned(),
+		"\n",
+		": ",
+		#[cfg(feature = "exp-preserve-order")]
+		true,
+	);
 	let a = a.manifest(&format).description("<a> manifestification")?;
 	let b = b.manifest(&format).description("<b> manifestification")?;
 	bail!("assertion failed: A != B\nA: {a}\nB: {b}")
@@ -161,8 +168,30 @@
 	let Some(target) = target.as_obj() else {
 		return Ok(Val::Obj(patch));
 	};
-	let target_fields = target.fields().into_iter().collect::<BTreeSet<IStr>>();
-	let patch_fields = patch.fields().into_iter().collect::<BTreeSet<IStr>>();
+	let target_fields = target
+		.fields(
+			// FIXME: Makes no sense to preserve order for BTreeSet, it would be better to use IndexSet here?
+			// But IndexSet won't allow fast ordered union...
+			// // Makes sense to preserve source ordering where possible.
+			// // May affect evaluation order, but it is not specified by jsonnet spec.
+			// #[cfg(feature = "exp-preserve-order")]
+			// true,
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		)
+		.into_iter()
+		.collect::<BTreeSet<IStr>>();
+	let patch_fields = patch
+		.fields(
+			// No need to look at the patch field order, I think?
+			// New fields (that will be appended at the end) will be alphabeticaly-ordered,
+			// but it is fine for jsonpatch, I don't think people write jsonpatch in jsonnet,
+			// when they can use mixins.
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		)
+		.into_iter()
+		.collect::<BTreeSet<IStr>>();
 
 	let mut out = ObjValueBuilder::new();
 	for field in target_fields.union(&patch_fields) {