Skip to content

Commit 340f75c

Browse files
committed
fix: experimental features build
1 parent ca50bd2 commit 340f75c

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

cmds/jrsonnet/src/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ fn main_real(opts: Opts) -> Result<(), Error> {
186186
};
187187

188188
let tla = opts.tla.tla_opts()?;
189-
#[allow(unused_mut)]
190-
let mut val = apply_tla(s, &tla, val)?;
189+
#[allow(
190+
// It is not redundant/unused in exp-apply
191+
unused_mut,
192+
clippy::redundant_clone,
193+
)]
194+
let mut val = apply_tla(s.clone(), &tla, val)?;
191195

192196
#[cfg(feature = "exp-apply")]
193197
for apply in opts.input.exp_apply {

crates/jrsonnet-stdlib/src/arrays.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ pub fn builtin_map_with_index(func: FuncVal, arr: IndexableVal) -> ArrValue {
7070
#[builtin]
7171
pub fn builtin_map_with_key(func: FuncVal, obj: ObjValue) -> Result<ObjValue> {
7272
let mut out = ObjValueBuilder::new();
73-
for (k, v) in obj.iter() {
73+
for (k, v) in obj.iter(
74+
// Makes sense mapped object should be ordered the same way, should not break anything when the output is not ordered (the default).
75+
// The thrown error might be different, but jsonnet
76+
// does not specify the evaluation order.
77+
#[cfg(feature = "exp-preserve-order")]
78+
true,
79+
) {
7480
let v = v?;
7581
out.field(k.clone())
7682
.value(func.evaluate_simple(&(k, v), false)?);

crates/jrsonnet-stdlib/src/misc.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ pub fn builtin_assert_equal(a: Val, b: Val) -> Result<bool> {
147147
if equals(&a, &b)? {
148148
return Ok(true);
149149
}
150-
let format = JsonFormat::std_to_json(" ".to_owned(), "\n", ": ");
150+
// TODO: Use debug output format
151+
let format = JsonFormat::std_to_json(
152+
" ".to_owned(),
153+
"\n",
154+
": ",
155+
#[cfg(feature = "exp-preserve-order")]
156+
true,
157+
);
151158
let a = a.manifest(&format).description("<a> manifestification")?;
152159
let b = b.manifest(&format).description("<b> manifestification")?;
153160
bail!("assertion failed: A != B\nA: {a}\nB: {b}")
@@ -161,8 +168,30 @@ pub fn builtin_merge_patch(target: Val, patch: Val) -> Result<Val> {
161168
let Some(target) = target.as_obj() else {
162169
return Ok(Val::Obj(patch));
163170
};
164-
let target_fields = target.fields().into_iter().collect::<BTreeSet<IStr>>();
165-
let patch_fields = patch.fields().into_iter().collect::<BTreeSet<IStr>>();
171+
let target_fields = target
172+
.fields(
173+
// FIXME: Makes no sense to preserve order for BTreeSet, it would be better to use IndexSet here?
174+
// But IndexSet won't allow fast ordered union...
175+
// // Makes sense to preserve source ordering where possible.
176+
// // May affect evaluation order, but it is not specified by jsonnet spec.
177+
// #[cfg(feature = "exp-preserve-order")]
178+
// true,
179+
#[cfg(feature = "exp-preserve-order")]
180+
false,
181+
)
182+
.into_iter()
183+
.collect::<BTreeSet<IStr>>();
184+
let patch_fields = patch
185+
.fields(
186+
// No need to look at the patch field order, I think?
187+
// New fields (that will be appended at the end) will be alphabeticaly-ordered,
188+
// but it is fine for jsonpatch, I don't think people write jsonpatch in jsonnet,
189+
// when they can use mixins.
190+
#[cfg(feature = "exp-preserve-order")]
191+
false,
192+
)
193+
.into_iter()
194+
.collect::<BTreeSet<IStr>>();
166195

167196
let mut out = ObjValueBuilder::new();
168197
for field in target_fields.union(&patch_fields) {

0 commit comments

Comments
 (0)