Skip to content

Commit

Permalink
fix: experimental features build
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Jun 18, 2024
1 parent 1086a51 commit 18dc4db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 6 additions & 2 deletions cmds/jrsonnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ fn main_real(opts: Opts) -> Result<(), Error> {
};

let tla = opts.tla.tla_opts()?;
#[allow(unused_mut)]
let mut val = apply_tla(s, &tla, val)?;
#[allow(
// It is not redundant/unused in exp-apply
unused_mut,
clippy::redundant_clone,
)]
let mut val = apply_tla(s.clone(), &tla, val)?;

#[cfg(feature = "exp-apply")]
for apply in opts.input.exp_apply {
Expand Down
8 changes: 7 additions & 1 deletion crates/jrsonnet-stdlib/src/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ pub fn builtin_map_with_index(func: FuncVal, arr: IndexableVal) -> ArrValue {
#[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)?);
Expand Down
35 changes: 32 additions & 3 deletions crates/jrsonnet-stdlib/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ pub fn builtin_assert_equal(a: Val, b: Val) -> Result<bool> {
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}")
Expand All @@ -161,8 +168,30 @@ pub fn builtin_merge_patch(target: Val, patch: Val) -> Result<Val> {
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) {
Expand Down

0 comments on commit 18dc4db

Please sign in to comment.