difftreelog
fix makeArray should be lazy
in: master
7 files changed
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth1use jrsonnet_gcmodule::{Cc, Trace};2use jrsonnet_interner::IBytes;3use jrsonnet_parser::LocExpr;45use crate::{function::FuncVal, Context, Result, Thunk, Val};67mod spec;8use spec::*;910/// Represents a Jsonnet array value.11#[derive(Debug, Clone, Trace)]12// may contrain other ArrValue13#[trace(tracking(force))]14pub enum ArrValue {15 /// Layout optimized byte array.16 Bytes(BytesArray),17 /// Every element is lazy evaluated.18 Lazy(LazyArray),19 /// Every element is defined somewhere in source code20 Expr(ExprArray),21 /// Every field is already evaluated.22 Eager(EagerArray),23 /// Concatenation of two arrays of any kind.24 Extended(Cc<ExtendedArray>),25 /// Represents a integer array in form `[start, start + 1, ... end - 1, end]`.26 /// This kind of arrays is generated by `std.range(start, end)` call, and used for loops.27 Range(RangeArray),28 /// Sliced array view.29 Slice(Box<SliceArray>),30 /// Reversed array view.31 /// Returned by `std.reverse(other)` call32 Reverse(Box<ReverseArray>),33 /// Returned by `std.map` call34 Mapped(MappedArray),35}3637impl ArrValue {38 pub fn empty() -> Self {39 Self::Range(RangeArray::empty())40 }4142 pub fn expr(ctx: Context, exprs: impl IntoIterator<Item = LocExpr>) -> Self {43 Self::Expr(ExprArray::new(ctx, exprs))44 }4546 pub fn lazy(thunks: Cc<Vec<Thunk<Val>>>) -> Self {47 Self::Lazy(LazyArray(thunks))48 }4950 pub fn eager(values: Cc<Vec<Val>>) -> Self {51 Self::Eager(EagerArray(values))52 }5354 pub fn bytes(bytes: IBytes) -> Self {55 Self::Bytes(BytesArray(bytes))56 }5758 #[must_use]59 pub fn map(self, mapper: FuncVal) -> Self {60 Self::Mapped(MappedArray::new(self, mapper))61 }6263 pub fn filter(self, filter: impl Fn(&Val) -> Result<bool>) -> Result<Self> {64 // TODO: ArrValue::Picked(inner, indexes) for large arrays65 let mut out = Vec::new();66 for i in self.iter() {67 let i = i?;68 if filter(&i)? {69 out.push(i);70 };71 }72 Ok(Self::eager(Cc::new(out)))73 }7475 pub fn extended(a: ArrValue, b: ArrValue) -> Self {76 // TODO: benchmark for an optimal value, currently just a arbitrary choice77 const ARR_EXTEND_THRESHOLD: usize = 100;7879 if a.len() + b.len() > ARR_EXTEND_THRESHOLD {80 Self::Extended(Cc::new(ExtendedArray::new(a, b)))81 } else if let (Some(a), Some(b)) = (a.iter_cheap(), b.iter_cheap()) {82 let mut out = Vec::with_capacity(a.len() + b.len());83 out.extend(a);84 out.extend(b);85 Self::eager(Cc::new(out))86 } else {87 let mut out = Vec::with_capacity(a.len() + b.len());88 out.extend(a.iter_lazy());89 out.extend(b.iter_lazy());90 Self::lazy(Cc::new(out))91 }92 }9394 pub fn range_exclusive(a: i32, b: i32) -> Self {95 Self::Range(RangeArray::new_exclusive(a, b))96 }97 pub fn range_inclusive(a: i32, b: i32) -> Self {98 Self::Range(RangeArray::new_inclusive(a, b))99 }100101 #[must_use]102 pub fn slice(103 self,104 from: Option<usize>,105 to: Option<usize>,106 step: Option<usize>,107 ) -> Option<Self> {108 let len = self.len();109 let from = from.unwrap_or(0);110 let to = to.unwrap_or(len).min(len);111 let step = step.unwrap_or(1);112 if from >= to || step == 0 {113 return None;114 }115116 Some(Self::Slice(Box::new(SliceArray {117 inner: self,118 from: from as u32,119 to: to as u32,120 step: step as u32,121 })))122 }123124 /// Array length.125 pub fn len(&self) -> usize {126 pass!(self.len())127 }128129 /// Is array contains no elements?130 pub fn is_empty(&self) -> bool {131 pass!(self.is_empty())132 }133134 /// Get array element by index, evaluating it, if it is lazy.135 ///136 /// Returns `None` on out-of-bounds condition.137 pub fn get(&self, index: usize) -> Result<Option<Val>> {138 pass!(self.get(index))139 }140141 /// Returns None if get is either non cheap, or out of bounds142 fn get_cheap(&self, index: usize) -> Option<Val> {143 pass!(self.get_cheap(index))144 }145146 /// Get array element by index, without evaluation.147 ///148 /// Returns `None` on out-of-bounds condition.149 pub fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {150 pass!(self.get_lazy(index))151 }152153 /// Evaluate all array elements, returning new array.154 pub fn evaluatedcc(&self) -> Result<Cc<Vec<Val>>> {155 self.evaluated().map(Cc::new)156 }157 pub fn evaluated(&self) -> Result<Vec<Val>> {158 pass!(self.evaluated())159 }160161 /// Iterate over elements, evaluating them.162 pub fn iter(&self) -> UnknownArrayIter<'_> {163 pass_iter_call!(self.iter => UnknownArrayIter)164 }165166 /// Iterate over elements, returning lazy values.167 pub fn iter_lazy(&self) -> UnknownArrayIterLazy<'_> {168 pass_iter_call!(self.iter_lazy => UnknownArrayIterLazy)169 }170171 pub fn iter_cheap(&self) -> Option<UnknownArrayIterCheap<'_>> {172 macro_rules! question {173 ($v:expr) => {174 $v?175 };176 }177 Some(pass_iter_call!(self.iter_cheap in question => UnknownArrayIterCheap))178 }179180 /// Return a reversed view on current array.181 #[must_use]182 pub fn reversed(self) -> Self {183 Self::Reverse(Box::new(ReverseArray(self)))184 }185186 pub fn ptr_eq(a: &Self, b: &Self) -> bool {187 match (a, b) {188 (ArrValue::Bytes(a), ArrValue::Bytes(b)) => a.0 == b.0,189 (ArrValue::Lazy(a), ArrValue::Lazy(b)) => Cc::ptr_eq(&a.0, &b.0),190 (ArrValue::Expr(a), ArrValue::Expr(b)) => Cc::ptr_eq(&a.0, &b.0),191 (ArrValue::Eager(a), ArrValue::Eager(b)) => Cc::ptr_eq(&a.0, &b.0),192 (ArrValue::Extended(a), ArrValue::Extended(b)) => Cc::ptr_eq(&a, &b),193 (ArrValue::Range(a), ArrValue::Range(b)) => a == b,194 (ArrValue::Slice(_), ArrValue::Slice(_)) => false,195 (ArrValue::Reverse(_), ArrValue::Reverse(_)) => false,196 _ => false,197 }198 }199200 pub fn is_cheap(&self) -> bool {201 match self {202 ArrValue::Eager(_) | ArrValue::Range(..) | ArrValue::Bytes(_) => true,203 ArrValue::Extended(v) => v.a.is_cheap() && v.b.is_cheap(),204 ArrValue::Slice(r) => r.inner.is_cheap(),205 ArrValue::Reverse(i) => i.0.is_cheap(),206 ArrValue::Expr(_) | ArrValue::Lazy(_) | ArrValue::Mapped(_) => false,207 }208 }209}210impl From<Vec<Val>> for ArrValue {211 fn from(value: Vec<Val>) -> Self {212 Self::eager(Cc::new(value))213 }214}215impl From<Vec<Thunk<Val>>> for ArrValue {216 fn from(value: Vec<Thunk<Val>>) -> Self {217 Self::lazy(Cc::new(value))218 }219}220221#[cfg(target_pointer_width = "64")]222static_assertions::assert_eq_size!(ArrValue, [u8; 16]);1use jrsonnet_gcmodule::{Cc, Trace};2use jrsonnet_interner::IBytes;3use jrsonnet_parser::LocExpr;45use crate::{function::FuncVal, Context, Result, Thunk, Val};67mod spec;8use spec::*;910/// Represents a Jsonnet array value.11#[derive(Debug, Clone, Trace)]12// may contrain other ArrValue13#[trace(tracking(force))]14pub enum ArrValue {15 /// Layout optimized byte array.16 Bytes(BytesArray),17 /// Every element is lazy evaluated.18 Lazy(LazyArray),19 /// Every element is defined somewhere in source code20 Expr(ExprArray),21 /// Every field is already evaluated.22 Eager(EagerArray),23 /// Concatenation of two arrays of any kind.24 Extended(Cc<ExtendedArray>),25 /// Represents a integer array in form `[start, start + 1, ... end - 1, end]`.26 /// This kind of arrays is generated by `std.range(start, end)` call, and used for loops.27 Range(RangeArray),28 /// Sliced array view.29 Slice(Box<SliceArray>),30 /// Reversed array view.31 /// Returned by `std.reverse(other)` call32 Reverse(Box<ReverseArray>),33 /// Returned by `std.map` call34 Mapped(MappedArray),35 /// Returned by `std.repeat` call36 Repeated(RepeatedArray),37}3839impl ArrValue {40 pub fn empty() -> Self {41 Self::Range(RangeArray::empty())42 }4344 pub fn expr(ctx: Context, exprs: impl IntoIterator<Item = LocExpr>) -> Self {45 Self::Expr(ExprArray::new(ctx, exprs))46 }4748 pub fn lazy(thunks: Cc<Vec<Thunk<Val>>>) -> Self {49 Self::Lazy(LazyArray(thunks))50 }5152 pub fn eager(values: Cc<Vec<Val>>) -> Self {53 Self::Eager(EagerArray(values))54 }5556 pub fn repeated(data: ArrValue, repeats: usize) -> Option<Self> {57 Some(Self::Repeated(RepeatedArray::new(data, repeats)?))58 }5960 pub fn bytes(bytes: IBytes) -> Self {61 Self::Bytes(BytesArray(bytes))62 }6364 #[must_use]65 pub fn map(self, mapper: FuncVal) -> Self {66 Self::Mapped(MappedArray::new(self, mapper))67 }6869 pub fn filter(self, filter: impl Fn(&Val) -> Result<bool>) -> Result<Self> {70 // TODO: ArrValue::Picked(inner, indexes) for large arrays71 let mut out = Vec::new();72 for i in self.iter() {73 let i = i?;74 if filter(&i)? {75 out.push(i);76 };77 }78 Ok(Self::eager(Cc::new(out)))79 }8081 pub fn extended(a: ArrValue, b: ArrValue) -> Self {82 // TODO: benchmark for an optimal value, currently just a arbitrary choice83 const ARR_EXTEND_THRESHOLD: usize = 100;8485 if a.is_empty() {86 b87 } else if b.is_empty() {88 a89 } else if a.len() + b.len() > ARR_EXTEND_THRESHOLD {90 Self::Extended(Cc::new(ExtendedArray::new(a, b)))91 } else if let (Some(a), Some(b)) = (a.iter_cheap(), b.iter_cheap()) {92 let mut out = Vec::with_capacity(a.len() + b.len());93 out.extend(a);94 out.extend(b);95 Self::eager(Cc::new(out))96 } else {97 let mut out = Vec::with_capacity(a.len() + b.len());98 out.extend(a.iter_lazy());99 out.extend(b.iter_lazy());100 Self::lazy(Cc::new(out))101 }102 }103104 pub fn range_exclusive(a: i32, b: i32) -> Self {105 Self::Range(RangeArray::new_exclusive(a, b))106 }107 pub fn range_inclusive(a: i32, b: i32) -> Self {108 Self::Range(RangeArray::new_inclusive(a, b))109 }110111 #[must_use]112 pub fn slice(113 self,114 from: Option<usize>,115 to: Option<usize>,116 step: Option<usize>,117 ) -> Option<Self> {118 let len = self.len();119 let from = from.unwrap_or(0);120 let to = to.unwrap_or(len).min(len);121 let step = step.unwrap_or(1);122 if from >= to || step == 0 {123 return None;124 }125126 Some(Self::Slice(Box::new(SliceArray {127 inner: self,128 from: from as u32,129 to: to as u32,130 step: step as u32,131 })))132 }133134 /// Array length.135 pub fn len(&self) -> usize {136 pass!(self.len())137 }138139 /// Is array contains no elements?140 pub fn is_empty(&self) -> bool {141 pass!(self.is_empty())142 }143144 /// Get array element by index, evaluating it, if it is lazy.145 ///146 /// Returns `None` on out-of-bounds condition.147 pub fn get(&self, index: usize) -> Result<Option<Val>> {148 pass!(self.get(index))149 }150151 /// Returns None if get is either non cheap, or out of bounds152 fn get_cheap(&self, index: usize) -> Option<Val> {153 pass!(self.get_cheap(index))154 }155156 /// Get array element by index, without evaluation.157 ///158 /// Returns `None` on out-of-bounds condition.159 pub fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {160 pass!(self.get_lazy(index))161 }162163 /// Evaluate all array elements, returning new array.164 pub fn evaluatedcc(&self) -> Result<Cc<Vec<Val>>> {165 self.evaluated().map(Cc::new)166 }167 pub fn evaluated(&self) -> Result<Vec<Val>> {168 pass!(self.evaluated())169 }170171 /// Iterate over elements, evaluating them.172 pub fn iter(&self) -> UnknownArrayIter<'_> {173 pass_iter_call!(self.iter => UnknownArrayIter)174 }175176 /// Iterate over elements, returning lazy values.177 pub fn iter_lazy(&self) -> UnknownArrayIterLazy<'_> {178 pass_iter_call!(self.iter_lazy => UnknownArrayIterLazy)179 }180181 pub fn iter_cheap(&self) -> Option<UnknownArrayIterCheap<'_>> {182 macro_rules! question {183 ($v:expr) => {184 $v?185 };186 }187 Some(pass_iter_call!(self.iter_cheap in question => UnknownArrayIterCheap))188 }189190 /// Return a reversed view on current array.191 #[must_use]192 pub fn reversed(self) -> Self {193 Self::Reverse(Box::new(ReverseArray(self)))194 }195196 pub fn ptr_eq(a: &Self, b: &Self) -> bool {197 match (a, b) {198 (ArrValue::Bytes(a), ArrValue::Bytes(b)) => a.0 == b.0,199 (ArrValue::Lazy(a), ArrValue::Lazy(b)) => Cc::ptr_eq(&a.0, &b.0),200 (ArrValue::Expr(a), ArrValue::Expr(b)) => Cc::ptr_eq(&a.0, &b.0),201 (ArrValue::Eager(a), ArrValue::Eager(b)) => Cc::ptr_eq(&a.0, &b.0),202 (ArrValue::Extended(a), ArrValue::Extended(b)) => Cc::ptr_eq(a, b),203 (ArrValue::Range(a), ArrValue::Range(b)) => a == b,204 _ => false,205 }206 }207208 pub fn is_cheap(&self) -> bool {209 match self {210 ArrValue::Eager(_) | ArrValue::Range(..) | ArrValue::Bytes(_) => true,211 ArrValue::Extended(v) => v.a.is_cheap() && v.b.is_cheap(),212 ArrValue::Slice(r) => r.inner.is_cheap(),213 ArrValue::Reverse(i) => i.0.is_cheap(),214 ArrValue::Repeated(v) => v.is_cheap(),215 ArrValue::Expr(_) | ArrValue::Lazy(_) | ArrValue::Mapped(_) => false,216 }217 }218}219impl From<Vec<Val>> for ArrValue {220 fn from(value: Vec<Val>) -> Self {221 Self::eager(Cc::new(value))222 }223}224impl From<Vec<Thunk<Val>>> for ArrValue {225 fn from(value: Vec<Thunk<Val>>) -> Self {226 Self::lazy(Cc::new(value))227 }228}229230#[cfg(target_pointer_width = "64")]231static_assertions::assert_eq_size!(ArrValue, [u8; 16]);crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -740,6 +740,96 @@
}
// impl MappedArray
+#[derive(Trace, Debug)]
+pub struct RepeatedArrayInner {
+ data: ArrValue,
+ repeats: usize,
+ total_len: usize,
+}
+#[derive(Trace, Debug, Clone)]
+pub struct RepeatedArray(Cc<RepeatedArrayInner>);
+impl RepeatedArray {
+ pub fn new(data: ArrValue, repeats: usize) -> Option<Self> {
+ let total_len = data.len().checked_mul(repeats)?;
+ Some(Self(Cc::new(RepeatedArrayInner {
+ data,
+ repeats,
+ total_len,
+ })))
+ }
+ pub fn is_cheap(&self) -> bool {
+ self.0.data.is_cheap()
+ }
+}
+
+type RepeatedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
+type RepeatedArrayLazyIter<'t> =
+ impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
+type RepeatedArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
+impl ArrayLike for RepeatedArray {
+ type Iter<'t> = RepeatedArrayIter<'t>;
+ type IterLazy<'t> = RepeatedArrayLazyIter<'t>;
+ type IterCheap<'t> = RepeatedArrayCheapIter<'t>;
+
+ fn len(&self) -> usize {
+ self.0.total_len
+ }
+
+ fn get(&self, index: usize) -> Result<Option<Val>> {
+ if index > self.0.total_len {
+ return Ok(None);
+ }
+ self.0.data.get(index % self.0.data.len())
+ }
+
+ fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
+ if index > self.0.total_len {
+ return None;
+ }
+ self.0.data.get_lazy(index % self.0.data.len())
+ }
+
+ fn get_cheap(&self, index: usize) -> Option<Val> {
+ if index > self.0.total_len {
+ return None;
+ }
+ self.0.data.get_cheap(index % self.0.data.len())
+ }
+
+ fn evaluated(&self) -> Result<Vec<Val>> {
+ let mut data = self.0.data.evaluated()?;
+ let data_range = 0..data.len();
+ for _ in 1..self.0.repeats {
+ data.extend_from_within(data_range.clone());
+ }
+ Ok(data)
+ }
+
+ fn iter(&self) -> RepeatedArrayIter<'_> {
+ (0..self.0.total_len)
+ .map(|i| self.get(i))
+ .map(Result::transpose)
+ .map(Option::unwrap)
+ }
+
+ fn iter_lazy(&self) -> RepeatedArrayLazyIter<'_> {
+ (0..self.0.total_len)
+ .map(|i| self.get_lazy(i))
+ .map(Option::unwrap)
+ }
+
+ fn iter_cheap(&self) -> Option<RepeatedArrayCheapIter<'_>> {
+ if !self.0.data.is_cheap() {
+ return None;
+ }
+ Some(
+ (0..self.0.total_len)
+ .map(|i| self.get_cheap(i))
+ .map(Option::unwrap),
+ )
+ }
+}
+
macro_rules! impl_iter_enum {
($n:ident => $v:ident) => {
pub enum $n<'t> {
@@ -752,6 +842,7 @@
Extended(Box<<ExtendedArray as ArrayLike>::$v<'t>>),
Reverse(Box<<ReverseArray as ArrayLike>::$v<'t>>),
Mapped(Box<<MappedArray as ArrayLike>::$v<'t>>),
+ Repeated(Box<<RepeatedArray as ArrayLike>::$v<'t>>),
}
};
}
@@ -768,6 +859,7 @@
Self::Extended(e) => e.$m($($ident)*),
Self::Reverse(e) => e.$m($($ident)*),
Self::Mapped(e) => e.$m($($ident)*),
+ Self::Repeated(e) => e.$m($($ident)*),
}
};
}
@@ -785,6 +877,7 @@
ArrValue::Extended(e) => $e::Extended(Box::new($($wrap!)?(e.$c()))),
ArrValue::Reverse(e) => $e::Reverse(Box::new($($wrap!)?(e.$c()))),
ArrValue::Mapped(e) => $e::Mapped(Box::new($($wrap!)?(e.$c()))),
+ ArrValue::Repeated(e) => $e::Repeated(Box::new($($wrap!)?(e.$c()))),
}
};
}
@@ -827,6 +920,7 @@
}
Self::Reverse(e) => e.len(),
Self::Mapped(e) => e.len(),
+ Self::Repeated(e) => e.len(),
}
}
}
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -12,7 +12,9 @@
native::NativeDesc,
parse::{parse_default_function_call, parse_function_call},
};
-use crate::{evaluate, gc::TraceBox, typed::Any, Context, ContextBuilder, Result, Val};
+use crate::{
+ evaluate, evaluate_trivial, gc::TraceBox, typed::Any, Context, ContextBuilder, Result, Val,
+};
pub mod arglike;
pub mod builtin;
@@ -80,6 +82,10 @@
) -> Result<Context> {
parse_function_call(call_ctx, self.ctx.clone(), &self.params, args, tailstrict)
}
+
+ pub fn evaluate_trivial(&self) -> Option<Val> {
+ evaluate_trivial(&self.body)
+ }
}
/// Represents a Jsonnet function value, including plain functions and user-provided builtins.
@@ -201,4 +207,11 @@
pub const fn identity() -> Self {
Self::Id
}
+
+ pub fn evaluate_trivial(&self) -> Option<Val> {
+ match self {
+ FuncVal::Normal(n) => n.evaluate_trivial(),
+ _ => None,
+ }
+ }
}
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -1,23 +1,41 @@
use jrsonnet_evaluator::{
- error::Result,
+ error::{ErrorKind::RuntimeError, Result},
function::{builtin, FuncVal},
throw,
- typed::{Any, BoundedUsize, Either2, NativeFn, Typed, VecVal},
- val::{equals, ArrValue, IndexableVal},
+ typed::{Any, BoundedI32, BoundedUsize, Either2, NativeFn, Typed},
+ val::{equals, ArrValue, IndexableVal, StrValue},
Either, IStr, Val,
};
use jrsonnet_gcmodule::Cc;
#[builtin]
-pub fn builtin_make_array(sz: usize, func: NativeFn<((f64,), Any)>) -> Result<VecVal> {
- let mut out = Vec::with_capacity(sz);
- for i in 0..sz {
- out.push(func(i as f64)?.0);
+pub fn builtin_make_array(sz: BoundedI32<0, { i32::MAX }>, func: FuncVal) -> Result<ArrValue> {
+ if *sz == 0 {
+ return Ok(ArrValue::empty());
+ }
+ if let Some(trivial) = func.evaluate_trivial() {
+ let mut out = Vec::with_capacity(*sz as usize);
+ for _ in 0..*sz {
+ out.push(trivial.clone())
+ }
+ Ok(ArrValue::eager(Cc::new(out)))
+ } else {
+ Ok(ArrValue::range_exclusive(0, *sz).map(func))
}
- Ok(VecVal(Cc::new(out)))
}
#[builtin]
+pub fn builtin_repeat(what: Either![IStr, ArrValue], count: usize) -> Result<Any> {
+ Ok(Any(match what {
+ Either2::A(s) => Val::Str(StrValue::Flat(s.repeat(count).into())),
+ Either2::B(arr) => Val::Arr(
+ ArrValue::repeated(arr, count)
+ .ok_or_else(|| RuntimeError("repeated length overflow".into()))?,
+ ),
+ }))
+}
+
+#[builtin]
pub fn builtin_slice(
indexable: IndexableVal,
index: Option<BoundedUsize<0, { i32::MAX as usize }>>,
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -63,6 +63,7 @@
("isFunction", builtin_is_function::INST),
// Arrays
("makeArray", builtin_make_array::INST),
+ ("repeat", builtin_repeat::INST),
("slice", builtin_slice::INST),
("map", builtin_map::INST),
("flatMap", builtin_flatmap::INST),
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -27,13 +27,6 @@
split(str, c):: std.splitLimit(str, c, -1),
- repeat(what, count)::
- local joiner =
- if std.isString(what) then ''
- else if std.isArray(what) then []
- else error 'std.repeat first argument must be an array or a string';
- std.join(joiner, std.makeArray(count, function(i) what)),
-
mapWithIndex(func, arr)::
if !std.isFunction(func) then
error ('std.mapWithIndex first param must be function, got ' + std.type(func))
nix/jrsonnet-release.nixdiffbeforeafterboth--- /dev/null
+++ b/nix/jrsonnet-release.nix
@@ -0,0 +1,24 @@
+{ lib, fetchFromGitHub, rustPlatform, runCommand, makeWrapper }:
+
+
+rustPlatform.buildRustPackage rec {
+ pname = "jrsonnet";
+ version = "5f0f8de9f52f961e2ff162e0a3fd4ca20a275f1d";
+
+ src = fetchFromGitHub {
+ owner = "CertainLach";
+ repo = pname;
+ rev = version;
+ hash = lib.fakeHash;
+ };
+
+ cargoTestFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
+ cargoBuildFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
+
+ buildInputs = [ makeWrapper ];
+
+ postInstall = ''
+ mv $out/bin/jrsonnet $out/bin/jrsonnet-release
+ wrapProgram $out/bin/jrsonnet-release --add-flags "--max-stack=200000 --os-stack=200000"
+ '';
+}