git.delta.rocks / jrsonnet / refs/commits / 68bea05caa11

difftreelog

fix build on stable

Yaroslav Bolyukin2022-12-03parent: #0b32cb0.patch.diff
in: master

16 files changed

modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
26 /// This kind of arrays is generated by `std.range(start, end)` call, and used for loops.26 /// This kind of arrays is generated by `std.range(start, end)` call, and used for loops.
27 Range(RangeArray),27 Range(RangeArray),
28 /// Sliced array view.28 /// Sliced array view.
29 Slice(Box<SliceArray>),29 Slice(Cc<SliceArray>),
30 /// Reversed array view.30 /// Reversed array view.
31 /// Returned by `std.reverse(other)` call31 /// Returned by `std.reverse(other)` call
32 Reverse(Box<ReverseArray>),32 Reverse(Cc<ReverseArray>),
33 /// Returned by `std.map` call33 /// Returned by `std.map` call
34 Mapped(MappedArray),34 Mapped(MappedArray),
35 /// Returned by `std.repeat` call35 /// Returned by `std.repeat` call
36 Repeated(RepeatedArray),36 Repeated(RepeatedArray),
37}37}
38
39pub trait ArrayLikeIter<T>: Iterator<Item = T> + DoubleEndedIterator + ExactSizeIterator {}
40impl<I, T> ArrayLikeIter<T> for I where
41 I: Iterator<Item = T> + DoubleEndedIterator + ExactSizeIterator
42{
43}
3844
39impl ArrValue {45impl ArrValue {
40 pub fn empty() -> Self {46 pub fn empty() -> Self {
123 return None;129 return None;
124 }130 }
125131
126 Some(Self::Slice(Box::new(SliceArray {132 Some(Self::Slice(Cc::new(SliceArray {
127 inner: self,133 inner: self,
128 from: from as u32,134 from: from as u32,
129 to: to as u32,135 to: to as u32,
160 pass!(self.get_lazy(index))166 pass!(self.get_lazy(index))
161 }167 }
162168
163 /// Evaluate all array elements, returning new array.169 #[cfg(feature = "nightly")]
164 pub fn evaluatedcc(&self) -> Result<Cc<Vec<Val>>> {170 pub fn iter(&self) -> UnknownArrayIter<'_> {
165 self.evaluated().map(Cc::new)171 pass_iter_call!(self.iter => UnknownArrayIter)
166 }172 }
173 #[cfg(not(feature = "nightly"))]
167 pub fn evaluated(&self) -> Result<Vec<Val>> {174 pub fn iter(&self) -> impl ArrayLikeIter<Result<Val>> + '_ {
168 pass!(self.evaluated())175 (0..self.len()).map(|i| self.get(i).transpose().expect("length checked"))
169 }176 }
170177
171 /// Iterate over elements, evaluating them.178 /// Iterate over elements, returning lazy values.
179 #[cfg(feature = "nightly")]
172 pub fn iter(&self) -> UnknownArrayIter<'_> {180 pub fn iter_lazy(&self) -> UnknownArrayIterLazy<'_> {
173 pass_iter_call!(self.iter => UnknownArrayIter)181 pass_iter_call!(self.iter_lazy => UnknownArrayIterLazy)
174 }182 }
175183 #[cfg(not(feature = "nightly"))]
176 /// Iterate over elements, returning lazy values.
177 pub fn iter_lazy(&self) -> UnknownArrayIterLazy<'_> {184 pub fn iter_lazy(&self) -> impl ArrayLikeIter<Thunk<Val>> + '_ {
178 pass_iter_call!(self.iter_lazy => UnknownArrayIterLazy)185 (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
179 }186 }
180187
188 #[cfg(feature = "nightly")]
181 pub fn iter_cheap(&self) -> Option<UnknownArrayIterCheap<'_>> {189 pub fn iter_cheap(&self) -> Option<UnknownArrayIterCheap<'_>> {
182 macro_rules! question {190 macro_rules! question {
183 ($v:expr) => {191 ($v:expr) => {
187 Some(pass_iter_call!(self.iter_cheap in question => UnknownArrayIterCheap))195 Some(pass_iter_call!(self.iter_cheap in question => UnknownArrayIterCheap))
188 }196 }
197
198 #[cfg(not(feature = "nightly"))]
199 pub fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {
200 if self.is_cheap() {
201 Some((0..self.len()).map(|i| self.get_cheap(i).expect("length and is_cheap checked")))
202 } else {
203 None
204 }
205 }
189206
190 /// Return a reversed view on current array.207 /// Return a reversed view on current array.
191 #[must_use]208 #[must_use]
192 pub fn reversed(self) -> Self {209 pub fn reversed(self) -> Self {
193 Self::Reverse(Box::new(ReverseArray(self)))210 Self::Reverse(Cc::new(ReverseArray(self)))
194 }211 }
195212
196 pub fn ptr_eq(a: &Self, b: &Self) -> bool {213 pub fn ptr_eq(a: &Self, b: &Self) -> bool {
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
1//! Those implementations are a bit sketchy, as this is mostly performance experiments
2//! of not yet finished nightly rust features
3
1use std::{4use std::{cell::RefCell, iter, mem::replace};
2 cell::RefCell,
3 iter::{self, Rev},
4 mem::replace,
5};
65
7use jrsonnet_gcmodule::{Cc, Trace};6use jrsonnet_gcmodule::{Cc, Trace};
8use jrsonnet_interner::IBytes;7use jrsonnet_interner::IBytes;
9use jrsonnet_parser::LocExpr;8use jrsonnet_parser::LocExpr;
109
11use super::ArrValue;10use super::{ArrValue, ArrayLikeIter};
12use crate::{11use crate::{
13 error::ErrorKind::InfiniteRecursionDetected, evaluate, function::FuncVal, tb, typed::Any,12 error::ErrorKind::InfiniteRecursionDetected, evaluate, function::FuncVal, tb, typed::Any,
14 val::ThunkValue, Context, Error, Result, Thunk, Val,13 val::ThunkValue, Context, Error, Result, Thunk, Val,
15};14};
1615
17pub trait ArrayLike {16pub trait ArrayLike: Sized + Into<ArrValue> {
17 #[cfg(feature = "nightly")]
18 type Iter<'t>18 type Iter<'t>
19 where19 where
20 Self: 't;20 Self: 't;
21 #[cfg(feature = "nightly")]
21 type IterLazy<'t>22 type IterLazy<'t>
22 where23 where
23 Self: 't;24 Self: 't;
25 #[cfg(feature = "nightly")]
24 type IterCheap<'t>26 type IterCheap<'t>
25 where27 where
26 Self: 't;28 Self: 't;
32 fn get(&self, index: usize) -> Result<Option<Val>>;34 fn get(&self, index: usize) -> Result<Option<Val>>;
33 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>>;35 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>>;
34 fn get_cheap(&self, index: usize) -> Option<Val>;36 fn get_cheap(&self, index: usize) -> Option<Val>;
35 fn evaluated(&self) -> Result<Vec<Val>>;37 #[cfg(feature = "nightly")]
36 #[allow(clippy::iter_not_returning_iterator)]38 #[allow(clippy::iter_not_returning_iterator)]
37 fn iter(&self) -> Self::Iter<'_>;39 fn iter(&self) -> Self::Iter<'_>;
40 #[cfg(feature = "nightly")]
38 fn iter_lazy(&self) -> Self::IterLazy<'_>;41 fn iter_lazy(&self) -> Self::IterLazy<'_>;
42 #[cfg(feature = "nightly")]
39 fn iter_cheap(&self) -> Option<Self::IterCheap<'_>>;43 fn iter_cheap(&self) -> Option<Self::IterCheap<'_>>;
44
45 fn reverse(self) -> ArrValue {
46 ArrValue::Reverse(Cc::new(ReverseArray(self.into())))
47 }
40}48}
4149
42#[derive(Debug, Clone, Trace)]50#[derive(Debug, Clone, Trace)]
47 pub(crate) step: u32,55 pub(crate) step: u32,
48}56}
57
58impl SliceArray {
59 #[cfg(not(feature = "nightly"))]
60 fn iter(&self) -> impl Iterator<Item = Result<Val>> + '_ {
61 self.inner
62 .iter()
63 .skip(self.from as usize)
64 .take((self.to - self.from) as usize)
65 .step_by(self.step as usize)
66 }
67
68 #[cfg(not(feature = "nightly"))]
69 fn iter_lazy(&self) -> impl Iterator<Item = Thunk<Val>> + '_ {
70 self.inner
71 .iter_lazy()
72 .skip(self.from as usize)
73 .take((self.to - self.from) as usize)
74 .step_by(self.step as usize)
75 }
76
77 #[cfg(not(feature = "nightly"))]
78 fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {
79 Some(
80 self.inner
81 .iter_cheap()?
82 .skip(self.from as usize)
83 .take((self.to - self.from) as usize)
84 .step_by(self.step as usize),
85 )
86 }
87}
88#[cfg(feature = "nightly")]
49type SliceArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;89type SliceArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
90#[cfg(feature = "nightly")]
50type SliceArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;91type SliceArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
92#[cfg(feature = "nightly")]
51type SliceArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;93type SliceArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
52impl ArrayLike for SliceArray {94impl ArrayLike for SliceArray {
95 #[cfg(feature = "nightly")]
53 type Iter<'t> = SliceArrayIter<'t>;96 type Iter<'t> = SliceArrayIter<'t>;
5497 #[cfg(feature = "nightly")]
55 type IterLazy<'t> = SliceArrayLazyIter<'t>;98 type IterLazy<'t> = SliceArrayLazyIter<'t>;
5699 #[cfg(feature = "nightly")]
57 type IterCheap<'t> = SliceArrayCheapIter<'t>;100 type IterCheap<'t> = SliceArrayCheapIter<'t>;
58101
59 fn len(&self) -> usize {102 fn len(&self) -> usize {
75 self.iter_cheap()?.nth(index)118 self.iter_cheap()?.nth(index)
76 }119 }
77120
78 fn evaluated(&self) -> Result<Vec<Val>> {121 #[cfg(feature = "nightly")]
79 self.iter().collect()
80 }
81
82 fn iter(&self) -> SliceArrayIter<'_> {122 fn iter(&self) -> SliceArrayIter<'_> {
83 self.inner123 self.inner
87 .step_by(self.step as usize)127 .step_by(self.step as usize)
88 }128 }
89129
130 #[cfg(feature = "nightly")]
90 fn iter_lazy(&self) -> SliceArrayLazyIter<'_> {131 fn iter_lazy(&self) -> SliceArrayLazyIter<'_> {
91 self.inner132 self.inner
92 .iter_lazy()133 .iter_lazy()
95 .step_by(self.step as usize)136 .step_by(self.step as usize)
96 }137 }
97138
139 #[cfg(feature = "nightly")]
98 fn iter_cheap(&self) -> Option<SliceArrayCheapIter<'_>> {140 fn iter_cheap(&self) -> Option<SliceArrayCheapIter<'_>> {
99 Some(141 Some(
100 self.inner142 self.inner
105 )147 )
106 }148 }
107}149}
150impl From<SliceArray> for ArrValue {
151 fn from(value: SliceArray) -> Self {
152 Self::Slice(Cc::new(value))
153 }
154}
108155
109#[derive(Trace, Debug, Clone)]156#[derive(Trace, Debug, Clone)]
110pub struct BytesArray(pub IBytes);157pub struct BytesArray(pub IBytes);
158#[cfg(feature = "nightly")]
111type BytesArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;159type BytesArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
160#[cfg(feature = "nightly")]
112type BytesArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;161type BytesArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
162#[cfg(feature = "nightly")]
113type BytesArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;163type BytesArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
114impl ArrayLike for BytesArray {164impl ArrayLike for BytesArray {
165 #[cfg(feature = "nightly")]
115 type Iter<'t> = BytesArrayIter<'t>;166 type Iter<'t> = BytesArrayIter<'t>;
116167 #[cfg(feature = "nightly")]
117 type IterLazy<'t> = BytesArrayLazyIter<'t>;168 type IterLazy<'t> = BytesArrayLazyIter<'t>;
118169 #[cfg(feature = "nightly")]
119 type IterCheap<'t> = BytesArrayCheapIter<'t>;170 type IterCheap<'t> = BytesArrayCheapIter<'t>;
120171
121 fn len(&self) -> usize {172 fn len(&self) -> usize {
134 self.0.get(index).map(|v| Val::Num(f64::from(*v)))185 self.0.get(index).map(|v| Val::Num(f64::from(*v)))
135 }186 }
136187
137 fn evaluated(&self) -> Result<Vec<Val>> {188 #[cfg(feature = "nightly")]
138 self.iter().collect()
139 }
140
141 fn iter(&self) -> BytesArrayIter<'_> {189 fn iter(&self) -> BytesArrayIter<'_> {
142 self.0.iter().map(|v| Ok(Val::Num(f64::from(*v))))190 self.0.iter().map(|v| Ok(Val::Num(f64::from(*v))))
143 }191 }
144192
193 #[cfg(feature = "nightly")]
145 fn iter_lazy(&self) -> BytesArrayLazyIter<'_> {194 fn iter_lazy(&self) -> BytesArrayLazyIter<'_> {
146 self.0195 self.0
147 .iter()196 .iter()
148 .map(|v| Thunk::evaluated(Val::Num(f64::from(*v))))197 .map(|v| Thunk::evaluated(Val::Num(f64::from(*v))))
149 }198 }
150199
200 #[cfg(feature = "nightly")]
151 fn iter_cheap(&self) -> Option<BytesArrayCheapIter<'_>> {201 fn iter_cheap(&self) -> Option<BytesArrayCheapIter<'_>> {
152 Some(self.0.iter().map(|v| Val::Num(f64::from(*v))))202 Some(self.0.iter().map(|v| Val::Num(f64::from(*v))))
153 }203 }
154}204}
205impl From<BytesArray> for ArrValue {
206 fn from(value: BytesArray) -> Self {
207 ArrValue::Bytes(value)
208 }
209}
155210
156#[derive(Debug, Trace, Clone)]211#[derive(Debug, Trace, Clone)]
157enum ArrayThunk<T: 'static + Trace> {212enum ArrayThunk<T: 'static + Trace> {
168}223}
169#[derive(Debug, Trace, Clone)]224#[derive(Debug, Trace, Clone)]
170pub struct ExprArray(pub Cc<ExprArrayInner>);225pub struct ExprArray(pub Cc<ExprArrayInner>);
171type ExprArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
172type ExprArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
173type ExprArrayCheapIter<'t> = iter::Empty<Val>;
174impl ExprArray {226impl ExprArray {
175 pub fn new(ctx: Context, items: impl IntoIterator<Item = LocExpr>) -> Self {227 pub fn new(ctx: Context, items: impl IntoIterator<Item = LocExpr>) -> Self {
176 Self(Cc::new(ExprArrayInner {228 Self(Cc::new(ExprArrayInner {
179 }))231 }))
180 }232 }
181}233}
234#[cfg(feature = "nightly")]
235type ExprArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
236#[cfg(feature = "nightly")]
237type ExprArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
238#[cfg(feature = "nightly")]
239type ExprArrayCheapIter<'t> = iter::Empty<Val>;
182impl ArrayLike for ExprArray {240impl ArrayLike for ExprArray {
241 #[cfg(feature = "nightly")]
183 type Iter<'t> = ExprArrayIter<'t>;242 type Iter<'t> = ExprArrayIter<'t>;
184243 #[cfg(feature = "nightly")]
185 type IterLazy<'t> = ExprArrayLazyIter<'t>;244 type IterLazy<'t> = ExprArrayLazyIter<'t>;
186245 #[cfg(feature = "nightly")]
187 type IterCheap<'t> = ExprArrayCheapIter<'t>;246 type IterCheap<'t> = ExprArrayCheapIter<'t>;
188247
189 fn len(&self) -> usize {248 fn len(&self) -> usize {
250 None309 None
251 }310 }
252311
312 #[cfg(feature = "nightly")]
253 fn iter(&self) -> ExprArrayIter<'_> {313 fn iter(&self) -> ExprArrayIter<'_> {
254 (0..self.len()).map(|i| self.get(i).transpose().expect("index checked"))314 (0..self.len()).map(|i| self.get(i).transpose().expect("index checked"))
255 }315 }
316 #[cfg(feature = "nightly")]
256 fn iter_lazy(&self) -> ExprArrayLazyIter<'_> {317 fn iter_lazy(&self) -> ExprArrayLazyIter<'_> {
257 (0..self.len()).map(|i| self.get_lazy(i).expect("index checked"))318 (0..self.len()).map(|i| self.get_lazy(i).expect("index checked"))
258 }319 }
320 #[cfg(feature = "nightly")]
259 fn iter_cheap(&self) -> Option<ExprArrayCheapIter<'_>> {321 fn iter_cheap(&self) -> Option<Self::IterCheap<'_>> {
260 None322 None
261 }323 }
262
263 fn evaluated(&self) -> Result<Vec<Val>> {
264 self.iter().collect()
265 }
266}324}
325impl From<ExprArray> for ArrValue {
326 fn from(value: ExprArray) -> Self {
327 Self::Expr(value)
328 }
329}
267330
268#[derive(Trace, Debug, Clone)]331#[derive(Trace, Debug, Clone)]
269pub struct ExtendedArray {332pub struct ExtendedArray {
272 split: usize,335 split: usize,
273 len: usize,336 len: usize,
274}337}
338#[cfg(feature = "nightly")]
339
275type ExtendedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + 't;340type ExtendedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
341#[cfg(feature = "nightly")]
276type ExtendedArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + 't;342type ExtendedArrayLazyIter<'t> =
343 impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
344#[cfg(feature = "nightly")]
277type ExtendedArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + 't;345type ExtendedArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
278impl ExtendedArray {346impl ExtendedArray {
279 pub fn new(a: ArrValue, b: ArrValue) -> Self {347 pub fn new(a: ArrValue, b: ArrValue) -> Self {
280 let a_len = a.len();348 let a_len = a.len();
288 }356 }
289}357}
358
359struct WithExactSize<I>(I, usize);
360impl<I, T> Iterator for WithExactSize<I>
361where
362 I: Iterator<Item = T>,
363{
364 type Item = T;
365
366 fn next(&mut self) -> Option<Self::Item> {
367 self.0.next()
368 }
369 fn nth(&mut self, n: usize) -> Option<Self::Item> {
370 self.0.nth(n)
371 }
372 fn size_hint(&self) -> (usize, Option<usize>) {
373 (self.1, Some(self.1))
374 }
375}
376impl<I> DoubleEndedIterator for WithExactSize<I>
377where
378 I: DoubleEndedIterator,
379{
380 fn next_back(&mut self) -> Option<Self::Item> {
381 self.0.next_back()
382 }
383 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
384 self.0.nth_back(n)
385 }
386}
387impl<I> ExactSizeIterator for WithExactSize<I>
388where
389 I: Iterator,
390{
391 fn len(&self) -> usize {
392 self.1
393 }
394}
290impl ArrayLike for ExtendedArray {395impl ArrayLike for ExtendedArray {
396 #[cfg(feature = "nightly")]
291 type Iter<'t> = ExtendedArrayIter<'t>;397 type Iter<'t> = ExtendedArrayIter<'t>;
292398 #[cfg(feature = "nightly")]
293 type IterLazy<'t> = ExtendedArrayLazyIter<'t>;399 type IterLazy<'t> = ExtendedArrayLazyIter<'t>;
294400 #[cfg(feature = "nightly")]
295 type IterCheap<'t> = ExtendedArrayCheapIter<'t>;401 type IterCheap<'t> = ExtendedArrayCheapIter<'t>;
296402
297 fn get(&self, index: usize) -> Result<Option<Val>> {403 fn get(&self, index: usize) -> Result<Option<Val>> {
321 }427 }
322 }428 }
323429
324 fn evaluated(&self) -> Result<Vec<Val>> {430 #[cfg(feature = "nightly")]
325 let mut out = self.a.evaluated()?;
326 out.extend(self.b.evaluated()?.into_iter());
327 Ok(out)
328 }
329
330 fn iter(&self) -> ExtendedArrayIter<'_> {431 fn iter(&self) -> ExtendedArrayIter<'_> {
331 self.a.iter().chain(self.b.iter())432 WithExactSize(self.a.iter().chain(self.b.iter()), self.len)
332 }433 }
434 #[cfg(feature = "nightly")]
333 fn iter_lazy(&self) -> ExtendedArrayLazyIter<'_> {435 fn iter_lazy(&self) -> ExtendedArrayLazyIter<'_> {
334 self.a.iter_lazy().chain(self.b.iter_lazy())436 WithExactSize(self.a.iter_lazy().chain(self.b.iter_lazy()), self.len)
335 }437 }
438 #[cfg(feature = "nightly")]
336 fn iter_cheap(&self) -> Option<ExtendedArrayCheapIter<'_>> {439 fn iter_cheap(&self) -> Option<ExtendedArrayCheapIter<'_>> {
337 let a = self.a.iter_cheap()?;440 let a = self.a.iter_cheap()?;
338 let b = self.b.iter_cheap()?;441 let b = self.b.iter_cheap()?;
339 Some(a.chain(b))442 Some(WithExactSize(a.chain(b), self.len))
340 }443 }
341}444}
445impl From<ExtendedArray> for ArrValue {
446 fn from(value: ExtendedArray) -> Self {
447 Self::Extended(Cc::new(value))
448 }
449}
342450
343#[derive(Trace, Debug, Clone)]451#[derive(Trace, Debug, Clone)]
344pub struct LazyArray(pub Cc<Vec<Thunk<Val>>>);452pub struct LazyArray(pub Cc<Vec<Thunk<Val>>>);
453#[cfg(feature = "nightly")]
345type LazyArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;454type LazyArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
455#[cfg(feature = "nightly")]
346type LazyArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;456type LazyArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
457#[cfg(feature = "nightly")]
347type LazyArrayCheapIter<'t> = iter::Empty<Val>;458type LazyArrayCheapIter<'t> = iter::Empty<Val>;
348impl ArrayLike for LazyArray {459impl ArrayLike for LazyArray {
460 #[cfg(feature = "nightly")]
349 type Iter<'t> = LazyArrayIter<'t>;461 type Iter<'t> = LazyArrayIter<'t>;
350462
463 #[cfg(feature = "nightly")]
351 type IterLazy<'t> = LazyArrayLazyIter<'t>;464 type IterLazy<'t> = LazyArrayLazyIter<'t>;
352465
466 #[cfg(feature = "nightly")]
353 type IterCheap<'t> = LazyArrayCheapIter<'t>;467 type IterCheap<'t> = LazyArrayCheapIter<'t>;
354468
355 fn len(&self) -> usize {469 fn len(&self) -> usize {
367 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {481 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
368 self.0.get(index).cloned()482 self.0.get(index).cloned()
369 }483 }
370 fn evaluated(&self) -> Result<Vec<Val>> {484 #[cfg(feature = "nightly")]
371 let mut out = Vec::with_capacity(self.len());
372 for i in self.0.iter() {
373 out.push(i.evaluate()?);
374 }
375 Ok(out)
376 }
377 fn iter(&self) -> LazyArrayIter<'_> {485 fn iter(&self) -> LazyArrayIter<'_> {
378 self.0.iter().map(Thunk::evaluate)486 self.0.iter().map(Thunk::evaluate)
379 }487 }
488 #[cfg(feature = "nightly")]
380 fn iter_lazy(&self) -> LazyArrayLazyIter<'_> {489 fn iter_lazy(&self) -> LazyArrayLazyIter<'_> {
381 self.0.iter().cloned()490 self.0.iter().cloned()
382 }491 }
492 #[cfg(feature = "nightly")]
383 fn iter_cheap(&self) -> Option<LazyArrayCheapIter<'_>> {493 fn iter_cheap(&self) -> Option<LazyArrayCheapIter<'_>> {
384 None494 None
385 }495 }
386}496}
497impl From<LazyArray> for ArrValue {
498 fn from(value: LazyArray) -> Self {
499 Self::Lazy(value)
500 }
501}
387502
388#[derive(Trace, Debug, Clone)]503#[derive(Trace, Debug, Clone)]
389pub struct EagerArray(pub Cc<Vec<Val>>);504pub struct EagerArray(pub Cc<Vec<Val>>);
505#[cfg(feature = "nightly")]
390type EagerArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;506type EagerArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
507#[cfg(feature = "nightly")]
391type EagerArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;508type EagerArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
509#[cfg(feature = "nightly")]
392type EagerArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;510type EagerArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
393impl ArrayLike for EagerArray {511impl ArrayLike for EagerArray {
512 #[cfg(feature = "nightly")]
394 type Iter<'t> = EagerArrayIter<'t>;513 type Iter<'t> = EagerArrayIter<'t>;
395514
515 #[cfg(feature = "nightly")]
396 type IterLazy<'t> = EagerArrayLazyIter<'t>;516 type IterLazy<'t> = EagerArrayLazyIter<'t>;
397517
518 #[cfg(feature = "nightly")]
398 type IterCheap<'t> = EagerArrayCheapIter<'t>;519 type IterCheap<'t> = EagerArrayCheapIter<'t>;
399520
400 fn len(&self) -> usize {521 fn len(&self) -> usize {
413 self.0.get(index).cloned()534 self.0.get(index).cloned()
414 }535 }
415536
416 fn evaluated(&self) -> Result<Vec<Val>> {537 #[cfg(feature = "nightly")]
417 Ok((*self.0).clone())
418 }
419
420 fn iter(&self) -> EagerArrayIter<'_> {538 fn iter(&self) -> EagerArrayIter<'_> {
421 self.0.iter().cloned().map(Ok)539 self.0.iter().cloned().map(Ok)
422 }540 }
423541
542 #[cfg(feature = "nightly")]
424 fn iter_lazy(&self) -> EagerArrayLazyIter<'_> {543 fn iter_lazy(&self) -> EagerArrayLazyIter<'_> {
425 self.0.iter().cloned().map(Thunk::evaluated)544 self.0.iter().cloned().map(Thunk::evaluated)
426 }545 }
427546
547 #[cfg(feature = "nightly")]
428 fn iter_cheap(&self) -> Option<EagerArrayCheapIter<'_>> {548 fn iter_cheap(&self) -> Option<EagerArrayCheapIter<'_>> {
429 Some(self.0.iter().cloned())549 Some(self.0.iter().cloned())
430 }550 }
431}551}
552impl From<EagerArray> for ArrValue {
553 fn from(value: EagerArray) -> Self {
554 Self::Eager(value)
555 }
556}
432557
433/// Inclusive range type558/// Inclusive range type
434#[derive(Debug, Trace, Clone, PartialEq, Eq)]559#[derive(Debug, Trace, Clone, PartialEq, Eq)]
435pub struct RangeArray {560pub struct RangeArray {
436 start: i32,561 start: i32,
437 end: i32,562 end: i32,
438}563}
439struct RangeIter {
440 start: i32,
441 end: i32,
442}
443impl RangeIter {
444 fn finished(&self) -> bool {
445 self.end < self.start
446 }
447 fn finish(&mut self) {
448 self.start = 0;
449 self.end = -1;
450 }
451}
452impl Iterator for RangeIter {
453 type Item = i32;
454
455 fn next(&mut self) -> Option<Self::Item> {
456 if self.finished() {
457 return None;
458 }
459 let v = self.start;
460 if v == self.end {
461 self.finish();
462 } else {
463 self.start = v + 1;
464 }
465 Some(v)
466 }
467 fn nth(&mut self, n: usize) -> Option<Self::Item> {
468 let v = (self.start as usize) + n;
469 if v > self.end as usize {
470 self.finish();
471 None
472 } else {
473 self.start = v as i32;
474 self.next()
475 }
476 }
477 fn size_hint(&self) -> (usize, Option<usize>) {
478 let len = self.len();
479 (len, Some(len))
480 }
481}
482impl DoubleEndedIterator for RangeIter {
483 fn next_back(&mut self) -> Option<Self::Item> {
484 if self.finished() {
485 return None;
486 }
487 let v = self.end;
488 if v == self.start {
489 self.finish();
490 } else {
491 self.end = v - 1;
492 }
493 Some(v)
494 }
495 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
496 let v = (self.end as usize) - n;
497 if v < self.start as usize {
498 self.finish();
499 None
500 } else {
501 self.end = v as i32;
502 self.next_back()
503 }
504 }
505}
506impl ExactSizeIterator for RangeIter {
507 fn len(&self) -> usize {
508 if self.finished() {
509 0
510 } else {
511 (self.end as isize - self.start as isize + 1) as usize
512 }
513 }
514}
515impl RangeArray {564impl RangeArray {
516 pub fn empty() -> Self {565 pub fn empty() -> Self {
517 Self::new_exclusive(0, 0)566 Self::new_exclusive(0, 0)
523 pub fn new_inclusive(start: i32, end: i32) -> Self {572 pub fn new_inclusive(start: i32, end: i32) -> Self {
524 Self { start, end }573 Self { start, end }
525 }574 }
526 fn range(&self) -> RangeIter {575 fn range(&self) -> impl Iterator<Item = i32> + ExactSizeIterator + DoubleEndedIterator {
527 RangeIter {576 WithExactSize(
528 start: self.start,577 self.start..=self.end,
529 end: self.end,578 (self.end as usize)
530 }579 .wrapping_sub(self.start as usize)
580 .wrapping_add(1),
581 )
531 }582 }
532}583}
533584
585#[cfg(feature = "nightly")]
534type RangeArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;586type RangeArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
587#[cfg(feature = "nightly")]
535type RangeArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;588type RangeArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
589#[cfg(feature = "nightly")]
536type RangeArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;590type RangeArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
537impl ArrayLike for RangeArray {591impl ArrayLike for RangeArray {
592 #[cfg(feature = "nightly")]
538 type Iter<'t> = RangeArrayIter<'t>;593 type Iter<'t> = RangeArrayIter<'t>;
539594
595 #[cfg(feature = "nightly")]
540 type IterLazy<'t> = RangeArrayLazyIter<'t>;596 type IterLazy<'t> = RangeArrayLazyIter<'t>;
541597
598 #[cfg(feature = "nightly")]
542 type IterCheap<'t> = RangeArrayCheapIter<'t>;599 type IterCheap<'t> = RangeArrayCheapIter<'t>;
543600
544 fn len(&self) -> usize {601 fn len(&self) -> usize {
545 self.range().len()602 self.range().len()
546 }603 }
547 fn is_empty(&self) -> bool {604 fn is_empty(&self) -> bool {
548 self.range().finished()605 self.range().len() == 0
549 }606 }
550607
551 fn get(&self, index: usize) -> Result<Option<Val>> {608 fn get(&self, index: usize) -> Result<Option<Val>> {
560 self.range().nth(index).map(|i| Val::Num(f64::from(i)))617 self.range().nth(index).map(|i| Val::Num(f64::from(i)))
561 }618 }
562619
563 fn evaluated(&self) -> Result<Vec<Val>> {620 #[cfg(feature = "nightly")]
564 Ok(self.range().map(|i| Val::Num(f64::from(i))).collect())
565 }
566
567 fn iter(&self) -> RangeArrayIter<'_> {621 fn iter(&self) -> RangeArrayIter<'_> {
568 self.range().map(|i| Ok(Val::Num(f64::from(i))))622 self.range().map(|i| Ok(Val::Num(f64::from(i))))
569 }623 }
570624
625 #[cfg(feature = "nightly")]
571 fn iter_lazy(&self) -> RangeArrayLazyIter<'_> {626 fn iter_lazy(&self) -> RangeArrayLazyIter<'_> {
572 self.range()627 self.range()
573 .map(|i| Thunk::evaluated(Val::Num(f64::from(i))))628 .map(|i| Thunk::evaluated(Val::Num(f64::from(i))))
574 }629 }
575630
631 #[cfg(feature = "nightly")]
576 fn iter_cheap(&self) -> Option<RangeArrayCheapIter<'_>> {632 fn iter_cheap(&self) -> Option<RangeArrayCheapIter<'_>> {
577 Some(self.range().map(|i| Val::Num(f64::from(i))))633 Some(self.range().map(|i| Val::Num(f64::from(i))))
578 }634 }
579}635}
636impl From<RangeArray> for ArrValue {
637 fn from(value: RangeArray) -> Self {
638 Self::Range(value)
639 }
640}
580641
581#[derive(Debug, Trace, Clone)]642#[derive(Debug, Trace, Clone)]
582pub struct ReverseArray(pub ArrValue);643pub struct ReverseArray(pub ArrValue);
583impl ArrayLike for ReverseArray {644impl ArrayLike for ReverseArray {
645 #[cfg(feature = "nightly")]
584 type Iter<'t> = Rev<UnknownArrayIter<'t>>;646 type Iter<'t> = iter::Rev<UnknownArrayIter<'t>>;
585647
648 #[cfg(feature = "nightly")]
586 type IterLazy<'t> = Rev<UnknownArrayIterLazy<'t>>;649 type IterLazy<'t> = iter::Rev<UnknownArrayIterLazy<'t>>;
587650
651 #[cfg(feature = "nightly")]
588 type IterCheap<'t> = Rev<UnknownArrayIterCheap<'t>>;652 type IterCheap<'t> = iter::Rev<UnknownArrayIterCheap<'t>>;
589653
590 fn len(&self) -> usize {654 fn len(&self) -> usize {
591 self.0.len()655 self.0.len()
603 self.0.get_cheap(self.0.len() - index - 1)667 self.0.get_cheap(self.0.len() - index - 1)
604 }668 }
605669
606 fn evaluated(&self) -> Result<Vec<Val>> {670 #[cfg(feature = "nightly")]
607 let mut v = self.0.evaluated()?;
608 v.reverse();
609 Ok(v)
610 }
611
612 fn iter(&self) -> Rev<UnknownArrayIter<'_>> {671 fn iter(&self) -> iter::Rev<UnknownArrayIter<'_>> {
613 self.0.iter().rev()672 self.0.iter().rev()
614 }673 }
615674
675 #[cfg(feature = "nightly")]
616 fn iter_lazy(&self) -> Rev<UnknownArrayIterLazy<'_>> {676 fn iter_lazy(&self) -> iter::Rev<UnknownArrayIterLazy<'_>> {
617 self.0.iter_lazy().rev()677 self.0.iter_lazy().rev()
618 }678 }
619679
680 #[cfg(feature = "nightly")]
620 fn iter_cheap(&self) -> Option<Rev<UnknownArrayIterCheap<'_>>> {681 fn iter_cheap(&self) -> Option<iter::Rev<UnknownArrayIterCheap<'_>>> {
621 Some(self.0.iter_cheap()?.rev())682 Some(self.0.iter_cheap()?.rev())
622 }683 }
684 fn reverse(self) -> ArrValue {
685 self.0
686 }
623}687}
688impl From<ReverseArray> for ArrValue {
689 fn from(value: ReverseArray) -> Self {
690 Self::Reverse(Cc::new(value))
691 }
692}
624693
625#[derive(Trace, Debug)]694#[derive(Trace, Debug)]
626pub struct MappedArrayInner {695pub struct MappedArrayInner {
640 }))709 }))
641 }710 }
642}711}
712#[cfg(feature = "nightly")]
643type MappedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;713type MappedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
714#[cfg(feature = "nightly")]
644type MappedArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;715type MappedArrayLazyIter<'t> = impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
716#[cfg(feature = "nightly")]
645type MappedArrayCheapIter<'t> = iter::Empty<Val>;717type MappedArrayCheapIter<'t> = iter::Empty<Val>;
646impl ArrayLike for MappedArray {718impl ArrayLike for MappedArray {
719 #[cfg(feature = "nightly")]
647 type Iter<'t> = MappedArrayIter<'t>;720 type Iter<'t> = MappedArrayIter<'t>;
721 #[cfg(feature = "nightly")]
648 type IterLazy<'t> = MappedArrayLazyIter<'t>;722 type IterLazy<'t> = MappedArrayLazyIter<'t>;
723 #[cfg(feature = "nightly")]
649 type IterCheap<'t> = MappedArrayCheapIter<'t>;724 type IterCheap<'t> = MappedArrayCheapIter<'t>;
650725
651 fn len(&self) -> usize {726 fn len(&self) -> usize {
722 None797 None
723 }798 }
724799
725 fn evaluated(&self) -> Result<Vec<Val>> {800 #[cfg(feature = "nightly")]
726 self.iter().collect()
727 }
728
729 fn iter(&self) -> MappedArrayIter<'_> {801 fn iter(&self) -> MappedArrayIter<'_> {
730 (0..self.len()).map(|i| self.get(i).transpose().expect("length checked"))802 (0..self.len()).map(|i| self.get(i).transpose().expect("length checked"))
731 }803 }
732804
805 #[cfg(feature = "nightly")]
733 fn iter_lazy(&self) -> MappedArrayLazyIter<'_> {806 fn iter_lazy(&self) -> MappedArrayLazyIter<'_> {
734 (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))807 (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
735 }808 }
736809
810 #[cfg(feature = "nightly")]
737 fn iter_cheap(&self) -> Option<Self::IterCheap<'_>> {811 fn iter_cheap(&self) -> Option<Self::IterCheap<'_>> {
738 None812 None
739 }813 }
740}814}
741// impl MappedArray815impl From<MappedArray> for ArrValue {
816 fn from(value: MappedArray) -> Self {
817 Self::Mapped(value)
818 }
819}
742820
743#[derive(Trace, Debug)]821#[derive(Trace, Debug)]
744pub struct RepeatedArrayInner {822pub struct RepeatedArrayInner {
762 }840 }
763}841}
764842
843#[cfg(feature = "nightly")]
765type RepeatedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;844type RepeatedArrayIter<'t> = impl DoubleEndedIterator<Item = Result<Val>> + ExactSizeIterator + 't;
845#[cfg(feature = "nightly")]
766type RepeatedArrayLazyIter<'t> =846type RepeatedArrayLazyIter<'t> =
767 impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;847 impl DoubleEndedIterator<Item = Thunk<Val>> + ExactSizeIterator + 't;
848#[cfg(feature = "nightly")]
768type RepeatedArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;849type RepeatedArrayCheapIter<'t> = impl DoubleEndedIterator<Item = Val> + ExactSizeIterator + 't;
769impl ArrayLike for RepeatedArray {850impl ArrayLike for RepeatedArray {
851 #[cfg(feature = "nightly")]
770 type Iter<'t> = RepeatedArrayIter<'t>;852 type Iter<'t> = RepeatedArrayIter<'t>;
853 #[cfg(feature = "nightly")]
771 type IterLazy<'t> = RepeatedArrayLazyIter<'t>;854 type IterLazy<'t> = RepeatedArrayLazyIter<'t>;
855 #[cfg(feature = "nightly")]
772 type IterCheap<'t> = RepeatedArrayCheapIter<'t>;856 type IterCheap<'t> = RepeatedArrayCheapIter<'t>;
773857
774 fn len(&self) -> usize {858 fn len(&self) -> usize {
796 self.0.data.get_cheap(index % self.0.data.len())880 self.0.data.get_cheap(index % self.0.data.len())
797 }881 }
798882
799 fn evaluated(&self) -> Result<Vec<Val>> {883 #[cfg(feature = "nightly")]
800 let mut data = self.0.data.evaluated()?;
801 let data_range = 0..data.len();
802 for _ in 1..self.0.repeats {
803 data.extend_from_within(data_range.clone());
804 }
805 Ok(data)
806 }
807
808 fn iter(&self) -> RepeatedArrayIter<'_> {884 fn iter(&self) -> RepeatedArrayIter<'_> {
809 (0..self.0.total_len)885 (0..self.0.total_len)
810 .map(|i| self.get(i))886 .map(|i| self.get(i))
811 .map(Result::transpose)887 .map(Result::transpose)
812 .map(Option::unwrap)888 .map(Option::unwrap)
813 }889 }
814890
891 #[cfg(feature = "nightly")]
815 fn iter_lazy(&self) -> RepeatedArrayLazyIter<'_> {892 fn iter_lazy(&self) -> RepeatedArrayLazyIter<'_> {
816 (0..self.0.total_len)893 (0..self.0.total_len)
817 .map(|i| self.get_lazy(i))894 .map(|i| self.get_lazy(i))
818 .map(Option::unwrap)895 .map(Option::unwrap)
819 }896 }
820897
898 #[cfg(feature = "nightly")]
821 fn iter_cheap(&self) -> Option<RepeatedArrayCheapIter<'_>> {899 fn iter_cheap(&self) -> Option<RepeatedArrayCheapIter<'_>> {
822 if !self.0.data.is_cheap() {900 if !self.0.data.is_cheap() {
823 return None;901 return None;
829 )907 )
830 }908 }
831}909}
832910impl From<RepeatedArray> for ArrValue {
911 fn from(value: RepeatedArray) -> Self {
912 Self::Repeated(value)
913 }
914}
915
916#[cfg(feature = "nightly")]
833macro_rules! impl_iter_enum {917macro_rules! impl_iter_enum {
834 ($n:ident => $v:ident) => {918 ($n:ident => $v:ident) => {
835 pub enum $n<'t> {919 pub enum $n<'t> {
865}949}
866pub(super) use pass;950pub(super) use pass;
867951
952#[cfg(feature = "nightly")]
868macro_rules! pass_iter_call {953macro_rules! pass_iter_call {
869 ($t:ident.$c:ident $(in $wrap:ident)? => $e:ident) => {954 ($t:ident.$c:ident $(in $wrap:ident)? => $e:ident) => {
870 match $t {955 match $t {
881 }966 }
882 };967 };
883}968}
969#[cfg(feature = "nightly")]
884pub(super) use pass_iter_call;970pub(super) use pass_iter_call;
885971
972#[cfg(feature = "nightly")]
886macro_rules! impl_iter {973macro_rules! impl_iter {
887 ($t:ident => $out:ty) => {974 ($t:ident => $out:ty) => {
888 impl Iterator for $t<'_> {975 impl Iterator for $t<'_> {
927 };1014 };
928}1015}
9291016
1017#[cfg(feature = "nightly")]
930impl_iter_enum!(UnknownArrayIter => Iter);1018impl_iter_enum!(UnknownArrayIter => Iter);
1019#[cfg(feature = "nightly")]
931impl_iter_enum!(UnknownArrayIterLazy => IterLazy);1020impl_iter!(UnknownArrayIter => Result<Val>);
1021#[cfg(feature = "nightly")]
932impl_iter_enum!(UnknownArrayIterCheap => IterCheap);1022impl_iter_enum!(UnknownArrayIterLazy => IterLazy);
1023#[cfg(feature = "nightly")]
933impl_iter!(UnknownArrayIter => Result<Val>);1024impl_iter!(UnknownArrayIterLazy => Thunk<Val>);
1025#[cfg(feature = "nightly")]
934impl_iter!(UnknownArrayIterLazy => Thunk<Val>);1026impl_iter_enum!(UnknownArrayIterCheap => IterCheap);
1027#[cfg(feature = "nightly")]
935impl_iter!(UnknownArrayIterCheap => Val);1028impl_iter!(UnknownArrayIterCheap => Val);
9361029
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
414#[allow(clippy::too_many_lines)]414#[allow(clippy::too_many_lines)]
415pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {415pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {
416 use Expr::*;416 use Expr::*;
417 if let Some(trivial) = evaluate_trivial(&expr) {417 if let Some(trivial) = evaluate_trivial(expr) {
418 return Ok(trivial);418 return Ok(trivial);
419 }419 }
420 let LocExpr(expr, loc) = expr;420 let LocExpr(expr, loc) = expr;
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
96 (Str(a), Str(b)) => a.cmp(b),96 (Str(a), Str(b)) => a.cmp(b),
97 (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),97 (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),
98 (Arr(a), Arr(b)) => {98 (Arr(a), Arr(b)) => {
99 if let (Some(ai), Some(bi)) = (a.iter_cheap(), b.iter_cheap()) {
100 for (a, b) in ai.zip(bi) {
101 let ord = evaluate_compare_op(&a, &b, op)?;
102 if !ord.is_eq() {
103 return Ok(ord);
104 }
105 }
106 } else {
107 {
99 let ai = a.iter();108 let ai = a.iter();
100 let bi = b.iter();109 let bi = b.iter();
101110
105 return Ok(ord);114 return Ok(ord);
106 }115 }
107 }116 }
108117 }
118 // {
119 // let ai = a.iter_expl();
120 // let bi = b.iter_expl();
121
122 // for (a, b) in ai.zip(bi) {
123 // let ord = evaluate_compare_op(&a?, &b?, op)?;
124 // if !ord.is_eq() {
125 // return Ok(ord);
126 // }
127 // }
128 // }
129 }
109 a.len().cmp(&b.len())130 a.len().cmp(&b.len())
110 }131 }
111 (_, _) => throw!(BinaryOperatorDoesNotOperateOnValues(132 (_, _) => throw!(BinaryOperatorDoesNotOperateOnValues(
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
1//! jsonnet interpreter implementation1//! jsonnet interpreter implementation
2#![cfg_attr(feature = "nightly", feature(thread_local))]2#![cfg_attr(feature = "nightly", feature(thread_local, type_alias_impl_trait))]
3#![feature(type_alias_impl_trait)]
4#![deny(unsafe_op_in_unsafe_fn)]3#![deny(unsafe_op_in_unsafe_fn)]
5#![warn(4#![warn(
6 clippy::all,5 clippy::all,
modifiedcrates/jrsonnet-evaluator/src/stdlib/mod.rsdiffbeforeafterboth
13 || format!("std.format of {str}"),13 || format!("std.format of {str}"),
14 || {14 || {
15 Ok(match vals {15 Ok(match vals {
16 Val::Arr(vals) => format_arr(&str, &vals.evaluatedcc()?)?,16 Val::Arr(vals) => format_arr(str, &vals.iter().collect::<Result<Vec<_>>>()?)?,
17 Val::Obj(obj) => format_obj(&str, &obj)?,17 Val::Obj(obj) => format_obj(str, &obj)?,
18 o => format_arr(&str, &[o])?,18 o => format_arr(str, &[o])?,
19 })19 })
20 },20 },
21 )21 )
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
278}278}
279279
280/// Specialization, provides faster `TryFrom<VecVal>` for Val280/// Specialization, provides faster `TryFrom<VecVal>` for Val
281pub struct VecVal(pub Cc<Vec<Val>>);281pub struct VecVal(pub Vec<Val>);
282282
283impl Typed for VecVal {283impl Typed for VecVal {
284 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Arr);284 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Arr);
285285
286 fn into_untyped(value: Self) -> Result<Val> {286 fn into_untyped(value: Self) -> Result<Val> {
287 Ok(Val::Arr(ArrValue::eager(value.0)))287 Ok(Val::Arr(ArrValue::eager(Cc::new(value.0))))
288 }288 }
289289
290 fn from_untyped(value: Val) -> Result<Self> {290 fn from_untyped(value: Val) -> Result<Self> {
291 <Self as Typed>::TYPE.check(&value)?;291 <Self as Typed>::TYPE.check(&value)?;
292 match value {292 match value {
293 Val::Arr(a) => Ok(Self(a.evaluatedcc()?)),293 Val::Arr(a) => Ok(Self(a.iter().collect::<Result<Vec<_>>>()?)),
294 _ => unreachable!(),294 _ => unreachable!(),
295 }295 }
296 }296 }
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth

no syntactic changes

modifiedcrates/jrsonnet-stdlib/src/objects.rsdiffbeforeafterboth
5 val::{StrValue, Val},5 val::{StrValue, Val},
6 IStr, ObjValue,6 IStr, ObjValue,
7};7};
8use jrsonnet_gcmodule::Cc;
98
10#[builtin]9#[builtin]
11pub fn builtin_object_fields_ex(10pub fn builtin_object_fields_ex(
20 #[cfg(feature = "exp-preserve-order")]19 #[cfg(feature = "exp-preserve-order")]
21 preserve_order,20 preserve_order,
22 );21 );
23 Ok(VecVal(Cc::new(22 Ok(VecVal(
24 out.into_iter()23 out.into_iter()
25 .map(StrValue::Flat)24 .map(StrValue::Flat)
26 .map(Val::Str)25 .map(Val::Str)
27 .collect::<Vec<_>>(),26 .collect::<Vec<_>>(),
28 )))27 ))
29}28}
3029
31#[builtin]30#[builtin]
modifiedcrates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth
50}50}
5151
52/// * `key_getter` - None, if identity sort required52/// * `key_getter` - None, if identity sort required
53pub fn sort(ctx: Context, values: Cc<Vec<Val>>, key_getter: FuncVal) -> Result<Cc<Vec<Val>>> {53pub fn sort(ctx: Context, mut values: Vec<Val>, key_getter: FuncVal) -> Result<Vec<Val>> {
54 if values.len() <= 1 {54 if values.len() <= 1 {
55 return Ok(values);55 return Ok(values);
56 }56 }
57 if key_getter.is_identity() {57 if key_getter.is_identity() {
58 // Fast path, identity key getter58 // Fast path, identity key getter
59 let mut values = (*values).clone();
60 let sort_type = get_sort_type(&mut values, |k| k)?;59 let sort_type = get_sort_type(&mut values, |k| k)?;
61 match sort_type {60 match sort_type {
62 SortKeyType::Number => values.sort_unstable_by_key(|v| match v {61 SortKeyType::Number => values.sort_unstable_by_key(|v| match v {
69 }),68 }),
70 SortKeyType::Unknown => unreachable!(),69 SortKeyType::Unknown => unreachable!(),
71 };70 };
72 Ok(Cc::new(values))71 Ok(values)
73 } else {72 } else {
74 // Slow path, user provided key getter73 // Slow path, user provided key getter
75 let mut vk = Vec::with_capacity(values.len());74 let mut vk = Vec::with_capacity(values.len());
96 }),95 }),
97 SortKeyType::Unknown => unreachable!(),96 SortKeyType::Unknown => unreachable!(),
98 };97 };
99 Ok(Cc::new(vk.into_iter().map(|v| v.0).collect()))98 Ok(vk.into_iter().map(|v| v.0).collect())
100 }99 }
101}100}
102101
106 if arr.len() <= 1 {105 if arr.len() <= 1 {
107 return Ok(arr);106 return Ok(arr);
108 }107 }
109 Ok(ArrValue::eager(super::sort::sort(108 Ok(ArrValue::eager(Cc::new(super::sort::sort(
110 ctx,109 ctx,
111 arr.evaluatedcc()?,110 arr.iter().collect::<Result<Vec<_>>>()?,
112 keyF.unwrap_or_else(FuncVal::identity),111 keyF.unwrap_or_else(FuncVal::identity),
113 )?))112 )?)))
114}113}
115114
modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
6 val::{ArrValue, StrValue},6 val::{ArrValue, StrValue},
7 Either, IStr, Val,7 Either, IStr, Val,
8};8};
9use jrsonnet_gcmodule::Cc;
109
11#[builtin]10#[builtin]
12pub const fn builtin_codepoint(str: char) -> Result<u32> {11pub const fn builtin_codepoint(str: char) -> Result<u32> {
31#[builtin]30#[builtin]
32pub fn builtin_splitlimit(str: IStr, c: IStr, maxsplits: Either![usize, M1]) -> Result<VecVal> {31pub fn builtin_splitlimit(str: IStr, c: IStr, maxsplits: Either![usize, M1]) -> Result<VecVal> {
33 use Either2::*;32 use Either2::*;
34 Ok(VecVal(Cc::new(match maxsplits {33 Ok(VecVal(match maxsplits {
35 A(n) => str34 A(n) => str
36 .splitn(n + 1, &c as &str)35 .splitn(n + 1, &c as &str)
37 .map(|s| Val::Str(StrValue::Flat(s.into())))36 .map(|s| Val::Str(StrValue::Flat(s.into())))
40 .split(&c as &str)39 .split(&c as &str)
41 .map(|s| Val::Str(StrValue::Flat(s.into())))40 .map(|s| Val::Str(StrValue::Flat(s.into())))
42 .collect(),41 .collect(),
43 })))42 }))
44}43}
4544
46#[builtin]45#[builtin]
modifiedflake.lockdiffbeforeafterboth
15 "type": "github"15 "type": "github"
16 }16 }
17 },17 },
18 "flake-utils_2": {
19 "locked": {
20 "lastModified": 1659877975,
21 "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
22 "owner": "numtide",
23 "repo": "flake-utils",
24 "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
25 "type": "github"
26 },
27 "original": {
28 "owner": "numtide",
29 "repo": "flake-utils",
30 "type": "github"
31 }
32 },
33 "nixpkgs": {18 "nixpkgs": {
34 "locked": {19 "locked": {
35 "lastModified": 1668090223,20 "lastModified": 1670089411,
36 "narHash": "sha256-Bynlfyf/LsQJ+CJ//1TGmA7eiCzqk95bz+bxyP39xYY=",21 "narHash": "sha256-iiW+L7iN8At8s98qb2h1P8Z0BVTZLqY8KHpfZuM7ULQ=",
37 "owner": "nixos",22 "owner": "nixos",
38 "repo": "nixpkgs",23 "repo": "nixpkgs",
39 "rev": "1f6b98281191b50ba987cabd5bf3068870c26789",24 "rev": "ffa4eb958a435e9833bda0fdfc834e87232aa879",
40 "type": "github"25 "type": "github"
41 },26 },
42 "original": {27 "original": {
45 "type": "github"30 "type": "github"
46 }31 }
47 },32 },
48 "nixpkgs_2": {
49 "locked": {
50 "lastModified": 1665296151,
51 "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
52 "owner": "NixOS",
53 "repo": "nixpkgs",
54 "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
55 "type": "github"
56 },
57 "original": {
58 "owner": "NixOS",
59 "ref": "nixpkgs-unstable",
60 "repo": "nixpkgs",
61 "type": "github"
62 }
63 },
64 "root": {33 "root": {
65 "inputs": {34 "inputs": {
66 "flake-utils": "flake-utils",35 "flake-utils": "flake-utils",
70 },39 },
71 "rust-overlay": {40 "rust-overlay": {
72 "inputs": {41 "inputs": {
73 "flake-utils": "flake-utils_2",42 "flake-utils": [
43 "flake-utils"
44 ],
74 "nixpkgs": "nixpkgs_2"45 "nixpkgs": [
46 "nixpkgs"
47 ]
75 },48 },
76 "locked": {49 "locked": {
77 "lastModified": 1668048396,50 "lastModified": 1670034122,
78 "narHash": "sha256-SUWQlSa/H5XKPeuF9XmWzmwIJrgK42Lak6/1jBAwyd0=",51 "narHash": "sha256-EqmuOKucPWtMvCZtHraHr3Q3bgVszq1x2PoZtQkUuEk=",
79 "owner": "oxalica",52 "owner": "oxalica",
80 "repo": "rust-overlay",53 "repo": "rust-overlay",
81 "rev": "859fefb532bb957f51a9b5e8e3ba2e48394c9353",54 "rev": "a0d5773275ecd4f141d792d3a0376277c0fc0b65",
82 "type": "github"55 "type": "github"
83 },56 },
84 "original": {57 "original": {
modifiedflake.nixdiffbeforeafterboth
3 inputs = {3 inputs = {
4 nixpkgs.url = "github:nixos/nixpkgs";4 nixpkgs.url = "github:nixos/nixpkgs";
5 flake-utils.url = "github:numtide/flake-utils";5 flake-utils.url = "github:numtide/flake-utils";
6 rust-overlay.url = "github:oxalica/rust-overlay";6 rust-overlay = {
7 url = "github:oxalica/rust-overlay";
8 inputs.nixpkgs.follows = "nixpkgs";
9 inputs.flake-utils.follows = "flake-utils";
10 };
7 };11 };
8 outputs = { nixpkgs, flake-utils, rust-overlay, ... }:12 outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
9 flake-utils.lib.eachDefaultSystem (system:13 flake-utils.lib.eachDefaultSystem (system:
12 inherit system;16 inherit system;
13 overlays = [ rust-overlay.overlays.default ];17 overlays = [ rust-overlay.overlays.default ];
14 };18 };
15 rust = ((pkgs.rustChannelOf { date = "2022-11-10"; channel = "nightly"; }).default.override {19 rust = ((pkgs.rustChannelOf { date = "2022-11-19"; channel = "nightly"; }).default.override {
16 extensions = [ "rust-src" "miri" ];20 extensions = [ "rust-src" "miri" ];
17 });21 });
18 in22 in
29 cargo = rust;33 cargo = rust;
30 };34 };
31 };35 };
36 jrsonnet-nightly = pkgs.callPackage ./nix/jrsonnet.nix {
37 rustPlatform = pkgs.makeRustPlatform {
38 rustc = rust;
39 cargo = rust;
40 };
41 withNightlyFeatures = true;
42 };
32 jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {43 jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {
33 rustPlatform = pkgs.makeRustPlatform {44 rustPlatform = pkgs.makeRustPlatform {
34 rustc = rust;45 rustc = rust;
37 };48 };
3849
39 benchmarks = pkgs.callPackage ./nix/benchmarks.nix {50 benchmarks = pkgs.callPackage ./nix/benchmarks.nix {
40 inherit go-jsonnet sjsonnet jsonnet jrsonnet jrsonnet-release;51 inherit go-jsonnet sjsonnet jsonnet;
52 jrsonnetVariants = [
53 { drv = jrsonnet; name = "current"; }
54 { drv = jrsonnet-nightly; name = "current-nightly"; }
55 ];
41 };56 };
42 benchmarks-quick = pkgs.callPackage ./nix/benchmarks.nix {57 benchmarks-quick = pkgs.callPackage ./nix/benchmarks.nix {
43 inherit go-jsonnet sjsonnet jsonnet jrsonnet jrsonnet-release;58 inherit go-jsonnet sjsonnet jsonnet;
44 quick = true;59 quick = true;
60 jrsonnetVariants = [
61 { drv = jrsonnet; name = "current"; }
62 { drv = jrsonnet-nightly; name = "current-nightly"; }
63 ];
45 };64 };
46 benchmarks-against-release = pkgs.callPackage ./nix/benchmarks.nix {65 benchmarks-against-release = pkgs.callPackage ./nix/benchmarks.nix {
47 inherit go-jsonnet sjsonnet jsonnet jrsonnet jrsonnet-release;66 inherit go-jsonnet sjsonnet jsonnet;
67 jrsonnetVariants = [
68 { drv = jrsonnet; name = "current"; }
69 { drv = jrsonnet-nightly; name = "current-nightly"; }
48 againstRelease = true;70 { drv = jrsonnet-release; name = "before-str-extend"; }
71 ];
49 };72 };
50 benchmarks-quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {73 benchmarks-quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {
51 inherit go-jsonnet sjsonnet jsonnet jrsonnet jrsonnet-release;74 inherit go-jsonnet sjsonnet jsonnet;
52 quick = true;75 quick = true;
53 againstRelease = true;76 jrsonnetVariants = [
77 { drv = jrsonnet; name = "current"; }
78 { drv = jrsonnet-nightly; name = "current-nightly"; }
79 { drv = jrsonnet-release; name = "before-str-extend"; }
80 ];
54 };81 };
55 };82 };
56 devShell = pkgs.mkShell {83 devShell = pkgs.mkShell {
57 nativeBuildInputs = with pkgs;[84 nativeBuildInputs = with pkgs;[
58 rust85 rust
59 cargo-edit86 cargo-edit
87 cargo-asm
60 lld88 lld
61 hyperfine89 hyperfine
62 valgrind90 valgrind
91 kcachegrind
92 graphviz
63 ];93 ];
64 };94 };
65 }95 }
modifiednix/benchmarks.nixdiffbeforeafterboth
4, cacert4, cacert
5, stdenv5, stdenv
6, fetchFromGitHub6, fetchFromGitHub
7, jrsonnet
8, jrsonnet-release
9, go-jsonnet7, go-jsonnet
10, sjsonnet8, sjsonnet
11, jsonnet9, jsonnet
12, hyperfine10, hyperfine
13, quick ? false11, quick ? false
14, againstRelease ? false12, jrsonnetVariants
15}:13}:
14
15with lib;
16
16let17let
17 jsonnetBench = fetchFromGitHub {18 jsonnetBench = fetchFromGitHub {
65 unpackPhase = "true";66 unpackPhase = "true";
6667
67 buildInputs = [68 buildInputs = [
68 jrsonnet
69 go-jsonnet69 go-jsonnet
70 sjsonnet70 sjsonnet
71 jsonnet71 jsonnet
7272
73 hyperfine73 hyperfine
74 ] ++ (if againstRelease then [ jrsonnet-release ] else [ ]);74 ];
7575
76 installPhase =76 installPhase =
77 let77 let
78 mkBench = { name, path, omitSource ? false, pathIsGenerator ? false, skipScala ? "", skipCpp ? "", skipGo ? "", vendor ? "" }: ''78 mkBench = { name, path, omitSource ? false, pathIsGenerator ? false, skipScala ? "", skipCpp ? "", skipGo ? "", vendor ? "" }: ''
79 set -oux79 set -oux
8080
81 echo >> $out81 echo >> $out
82 echo "### ${name}" >> $out82 echo "### ${name}" >> $out
83 echo >> $out83 echo >> $out
84 ${if skipGo != "" then ''84 ${optionalString (skipGo != "") ''
85 echo "> Note: No results for Go, ${skipGo}" >> $out85 echo "> Note: No results for Go, ${skipGo}" >> $out
86 echo >> $out86 echo >> $out
87 '' else ""}87 ''}
88 ${if skipScala != "" then ''88 ${optionalString (skipScala != "") ''
89 echo "> Note: No results for Scala, ${skipScala}" >> $out89 echo "> Note: No results for Scala, ${skipScala}" >> $out
90 echo >> $out90 echo >> $out
91 '' else ""}91 ''}
92 ${if skipCpp != "" then ''92 ${optionalString (skipCpp != "") ''
93 echo "> Note: No results for C++, ${skipCpp}" >> $out93 echo "> Note: No results for C++, ${skipCpp}" >> $out
94 echo >> $out94 echo >> $out
95 '' else ""}95 ''}
96 ${if !quick then ''96 ${optionalString (!quick && !omitSource) ''
97 echo "<details>" >> $out97 echo "<details>" >> $out
98 echo "<summary>Source</summary>" >> $out98 echo "<summary>Source</summary>" >> $out
99 echo >> $out99 echo >> $out
100 echo "\`\`\`jsonnet" >> $out100 echo "\`\`\`jsonnet" >> $out
101 ${if pathIsGenerator then "echo \"// Generator source\" >> $out" else ""}101 ${optionalString pathIsGenerator "echo \"// Generator source\" >> $out"}
102 ${if omitSource then "echo \"// Omitted: too large\" >> $out" else "cat ${path} >> $out"}102 cat ${path} >> $out
103 echo >> $out103 echo >> $out
104 echo "\`\`\`" >> $out104 echo "\`\`\`" >> $out
105 echo "</details>" >> $out105 echo "</details>" >> $out
106 echo >> $out106 echo >> $out
107 '' else ""}107 ''}
108 path=${path}108 path=${path}
109 ${if pathIsGenerator then ''109 ${optionalString pathIsGenerator ''
110 jrsonnet $path > generated.jsonnet110 go-jsonnet $path > generated.jsonnet
111 path=generated.jsonnet111 path=generated.jsonnet
112 '' else ""}112 ''}
113 hyperfine -N -w4 --output=pipe --style=basic --export-markdown result.md \113 hyperfine -N -w4 -m20 --output=pipe --style=basic --export-markdown result.md \
114 "jrsonnet $path ${if vendor != "" then "-J${vendor}" else ""}" -n "Rust" \114 ${concatStringsSep " " (forEach jrsonnetVariants (variant:
115 ${if againstRelease then "\"jrsonnet-release $path ${if vendor != "" then "-J${vendor}" else ""}\" -n \"Rust (released)\"" else "" } \115 "\"${variant.drv}/bin/jrsonnet $path ${optionalString (vendor != "") "-J${vendor}"}\" -n \"Rust (${variant.name})\""
116 ))} \
116 ${if skipGo == "" then "\"go-jsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"Go\"" else "" } \117 ${optionalString (skipGo == "") "\"go-jsonnet $path ${optionalString (vendor != "") "-J ${vendor}"}\" -n \"Go\""} \
117 ${if skipScala == "" then "\"sjsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"Scala\"" else "" } \118 ${optionalString (skipScala == "") "\"sjsonnet $path ${optionalString (vendor != "") "-J ${vendor}"}\" -n \"Scala\""} \
118 ${if skipCpp == "" then "\"jsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"C++\"" else "" }119 ${optionalString (skipCpp == "") "\"jsonnet $path ${optionalString (vendor != "") "-J ${vendor}"}\" -n \"C++\""}
119 cat result.md >> $out120 cat result.md >> $out
120 '';121 '';
121 in122 in
122 ''123 ''
123 touch $out124 touch $out
124 ${if !quick then ''125 ${optionalString (!quick) ''
125 cat ${./benchmarks.md} >> $out126 cat ${./benchmarks.md} >> $out
126 echo >> $out127 echo >> $out
127128
128 echo "<details>" >> $out129 echo "<details>" >> $out
129 echo "<summary>Tested versions</summary>" >> $out130 echo "<summary>Tested versions</summary>" >> $out
130 echo >> $out131 echo >> $out
131 echo Rust: git as $(date +'%d.%m.%Y' -u) >> $out132 echo Rust: git as $(date +'%d.%m.%Y' -u) >> $out
132 echo >> $out133 echo >> $out
133 echo "\`\`\`" >> $out134 echo "\`\`\`" >> $out
134 jrsonnet --help >> $out135 jrsonnet --help >> $out
135 echo "\`\`\`" >> $out136 echo "\`\`\`" >> $out
136 echo >> $out137 echo >> $out
137 echo Go: $(go-jsonnet --version) >> $out138 echo Go: $(go-jsonnet --version) >> $out
138 echo >> $out139 echo >> $out
139 echo "\`\`\`" >> $out140 echo "\`\`\`" >> $out
140 go-jsonnet --help >> $out141 go-jsonnet --help >> $out
141 echo "\`\`\`" >> $out142 echo "\`\`\`" >> $out
142 echo >> $out143 echo >> $out
143 echo C++: $(jsonnet --version) >> $out144 echo C++: $(jsonnet --version) >> $out
144 echo >> $out145 echo >> $out
145 echo "\`\`\`" >> $out146 echo "\`\`\`" >> $out
146 jsonnet --help >> $out147 jsonnet --help >> $out
147 echo "\`\`\`" >> $out148 echo "\`\`\`" >> $out
148 echo >> $out149 echo >> $out
149 echo Scala: >> $out150 echo Scala: >> $out
150 echo >> $out151 echo >> $out
151 echo "\`\`\`" >> $out152 echo "\`\`\`" >> $out
152 sjsonnet 2>> $out || true153 sjsonnet 2>> $out || true
153 echo "\`\`\`" >> $out154 echo "\`\`\`" >> $out
154 echo >> $out155 echo >> $out
155 echo "</details>" >> $out156 echo "</details>" >> $out
156 echo >> $out157 echo >> $out
157158
158 echo >> $out159 echo >> $out
159 '' else ""}160 ''}
160 echo "## Real world" >> $out161 echo "## Real world" >> $out
161 ${mkBench {name = "Graalvm CI"; path = "${graalvmBench}/ci.jsonnet"; skipCpp = "takes longer than a hour";}}162 ${mkBench {name = "Graalvm CI"; path = "${graalvmBench}/ci.jsonnet"; skipCpp = "takes longer than a hour"; skipGo = skipSlow; skipScala = skipSlow;}}
162 ${mkBench {name = "Kube-prometheus manifests"; vendor = "${kubePrometheusBench}/vendor"; path = "${kubePrometheusBench}/example.jsonnet"; skipCpp = skipSlow;}}163 ${mkBench {name = "Kube-prometheus manifests"; vendor = "${kubePrometheusBench}/vendor"; path = "${kubePrometheusBench}/example.jsonnet"; skipCpp = skipSlow; skipGo = skipSlow; skipScala = skipSlow;}}
163164
164 echo >> $out165 echo >> $out
165 echo "## Benchmarks from C++ jsonnet (/perf_tests)" >> $out166 echo "## Benchmarks from C++ jsonnet (/perf_tests)" >> $out
166 ${mkBench {name = "Large string join"; path = "${jsonnetBench}/perf_tests/large_string_join.jsonnet";}}167 ${mkBench {name = "Large string join"; path = "${jsonnetBench}/perf_tests/large_string_join.jsonnet"; skipScala = skipSlow;}}
167 ${mkBench {name = "Large string template"; omitSource = true; path = "${jsonnetBench}/perf_tests/large_string_template.jsonnet"; skipGo = "fails with os stack size exhausion"; skipCpp = skipSlow;}}168 ${mkBench {name = "Large string template"; omitSource = true; path = "${jsonnetBench}/perf_tests/large_string_template.jsonnet"; skipGo = "fails with os stack size exhausion"; skipCpp = skipSlow; skipScala = skipSlow;}}
168 ${mkBench {name = "Realistic 1"; path = "${jsonnetBench}/perf_tests/realistic1.jsonnet"; skipGo = skipSlow; skipCpp = skipSlow;}}169 ${mkBench {name = "Realistic 1"; path = "${jsonnetBench}/perf_tests/realistic1.jsonnet"; skipGo = skipSlow; skipCpp = skipSlow; skipScala = skipSlow;}}
169 ${mkBench {name = "Realistic 2"; path = "${jsonnetBench}/perf_tests/realistic2.jsonnet"; skipGo = skipSlow; skipCpp = skipSlow;}}170 ${mkBench {name = "Realistic 2"; path = "${jsonnetBench}/perf_tests/realistic2.jsonnet"; skipGo = skipSlow; skipCpp = skipSlow; skipScala = skipSlow;}}
170171
171 echo >> $out172 echo >> $out
172 echo "## Benchmarks from C++ jsonnet (/benchmarks)" >> $out173 echo "## Benchmarks from C++ jsonnet (/benchmarks)" >> $out
173 ${mkBench {name = "Tail call"; path = "${jsonnetBench}/benchmarks/bench.01.jsonnet";}}174 ${mkBench {name = "Tail call"; path = "${jsonnetBench}/benchmarks/bench.01.jsonnet"; skipScala = skipSlow;}}
174 ${mkBench {name = "Inheritance recursion"; path = "${jsonnetBench}/benchmarks/bench.02.jsonnet"; skipCpp = skipSlow;}}175 ${mkBench {name = "Inheritance recursion"; path = "${jsonnetBench}/benchmarks/bench.02.jsonnet"; skipCpp = skipSlow; skipGo = skipSlow;}}
175 ${mkBench {name = "Simple recursive call"; path = "${jsonnetBench}/benchmarks/bench.03.jsonnet";}}176 ${mkBench {name = "Simple recursive call"; path = "${jsonnetBench}/benchmarks/bench.03.jsonnet"; skipScala = skipSlow; skipGo = skipSlow;}}
176 ${mkBench {name = "Foldl string concat"; path = "${jsonnetBench}/benchmarks/bench.04.jsonnet";}}177 ${mkBench {name = "Foldl string concat"; path = "${jsonnetBench}/benchmarks/bench.04.jsonnet"; skipCpp = skipSlow; skipScala = skipSlow;}}
177 ${mkBench {name = "Array sorts"; path = "${jsonnetBench}/benchmarks/bench.06.jsonnet"; skipScala = "std.reverse is not implemented"; skipCpp = skipSlow;}}178 ${mkBench {name = "Array sorts"; path = "${jsonnetBench}/benchmarks/bench.06.jsonnet"; skipScala = "std.reverse is not implemented"; skipCpp = skipSlow;}}
178 ${mkBench {name = "Lazy array"; path = "${jsonnetBench}/benchmarks/bench.07.jsonnet";}}179 ${mkBench {name = "Lazy array"; path = "${jsonnetBench}/benchmarks/bench.07.jsonnet"; skipGo = skipSlow; skipScala = skipSlow;}}
179 ${mkBench {name = "Inheritance function recursion"; path = "${jsonnetBench}/benchmarks/bench.08.jsonnet";}}180 ${mkBench {name = "Inheritance function recursion"; path = "${jsonnetBench}/benchmarks/bench.08.jsonnet"; skipCpp = skipSlow; skipScala = skipSlow;}}
180 ${mkBench {name = "String strips"; path = "${jsonnetBench}/benchmarks/bench.09.jsonnet"; skipCpp = skipSlow;}}181 ${mkBench {name = "String strips"; path = "${jsonnetBench}/benchmarks/bench.09.jsonnet"; skipCpp = skipSlow; skipScala = skipSlow;}}
181 ${mkBench {name = "Big object"; path = "${jsonnetBench}/benchmarks/gen_big_object.jsonnet"; pathIsGenerator = true;}}182 ${mkBench {name = "Big object"; path = "${jsonnetBench}/benchmarks/gen_big_object.jsonnet"; pathIsGenerator = true; skipScala = skipSlow;}}
182183
183 echo >> $out184 echo >> $out
184 echo "## Benchmarks from Go jsonnet (builtins)" >> $out185 echo "## Benchmarks from Go jsonnet (builtins)" >> $out
185 ${mkBench {name = "std.base64"; path = "${goJsonnetBench}/base64.jsonnet"; skipCpp = skipSlow;}}186 ${mkBench {name = "std.base64"; path = "${goJsonnetBench}/base64.jsonnet"; skipCpp = skipSlow; skipScala = skipSlow;}}
186 ${mkBench {name = "std.base64Decode"; path = "${goJsonnetBench}/base64Decode.jsonnet"; skipCpp = skipSlow;}}187 ${mkBench {name = "std.base64Decode"; path = "${goJsonnetBench}/base64Decode.jsonnet"; skipCpp = skipSlow; skipScala = skipSlow;}}
187 ${mkBench {name = "std.base64DecodeBytes"; path = "${goJsonnetBench}/base64DecodeBytes.jsonnet"; skipCpp = skipSlow;}}188 ${mkBench {name = "std.base64DecodeBytes"; path = "${goJsonnetBench}/base64DecodeBytes.jsonnet"; skipCpp = skipSlow; skipGo = skipSlow; skipScala = skipSlow;}}
188 ${mkBench {name = "std.base64 (byte array)"; path = "${goJsonnetBench}/base64_byte_array.jsonnet"; skipCpp = skipSlow;}}189 ${mkBench {name = "std.base64 (byte array)"; path = "${goJsonnetBench}/base64_byte_array.jsonnet"; skipCpp = skipSlow; skipGo = skipSlow; skipScala = skipSlow;}}
189 ${mkBench {name = "std.foldl"; path = "${goJsonnetBench}/foldl.jsonnet";}}190 ${mkBench {name = "std.foldl"; path = "${goJsonnetBench}/foldl.jsonnet"; skipScala = skipSlow;}}
190 ${mkBench {name = "std.manifestJsonEx"; path = "${goJsonnetBench}/manifestJsonEx.jsonnet";}}191 ${mkBench {name = "std.manifestJsonEx"; path = "${goJsonnetBench}/manifestJsonEx.jsonnet"; skipScala = skipSlow; skipCpp = skipSlow;}}
191 ${mkBench {name = "std.manifestTomlEx"; path = "${goJsonnetBench}/manifestTomlEx.jsonnet"; skipScala = "std.manifestTomlEx is not implemented";}}192 ${mkBench {name = "std.manifestTomlEx"; path = "${goJsonnetBench}/manifestTomlEx.jsonnet"; skipScala = "std.manifestTomlEx is not implemented"; skipCpp=skipSlow;}}
192 ${mkBench {name = "std.parseInt"; path = "${goJsonnetBench}/parseInt.jsonnet";}}193 ${mkBench {name = "std.parseInt"; path = "${goJsonnetBench}/parseInt.jsonnet"; skipScala = skipSlow; skipCpp = skipSlow;}}
193 ${mkBench {name = "std.reverse"; path = "${goJsonnetBench}/reverse.jsonnet"; skipScala = "std.reverse is not implemented";}}194 ${mkBench {name = "std.reverse"; path = "${goJsonnetBench}/reverse.jsonnet"; skipScala = "std.reverse is not implemented"; skipCpp = skipSlow; skipGo = skipSlow;}}
194 ${mkBench {name = "std.substr"; path = "${goJsonnetBench}/substr.jsonnet";}}195 ${mkBench {name = "std.substr"; path = "${goJsonnetBench}/substr.jsonnet"; skipScala = skipSlow;}}
195 ${mkBench {name = "Comparsion for array"; path = "${goJsonnetBench}/comparison.jsonnet"; skipScala = "array comparsion is not implemented"; skipCpp = skipSlow;}}196 ${mkBench {name = "Comparsion for array"; path = "${goJsonnetBench}/comparison.jsonnet"; skipScala = "array comparsion is not implemented"; skipCpp = skipSlow;}}
196 ${mkBench {name = "Comparsion for primitives"; path = "${goJsonnetBench}/comparison2.jsonnet"; skipCpp = "can't run: uses up to 192GB of RAM";}}197 ${mkBench {name = "Comparsion for primitives"; path = "${goJsonnetBench}/comparison2.jsonnet"; skipCpp = "can't run: uses up to 192GB of RAM"; skipGo = skipSlow; skipScala = skipSlow;}}
197 '';198 '';
198}199}
199200
modifiednix/jrsonnet-release.nixdiffbeforeafterboth
33
4rustPlatform.buildRustPackage rec {4rustPlatform.buildRustPackage rec {
5 pname = "jrsonnet";5 pname = "jrsonnet";
6 version = "d32fe45b8ed28fb39b5359a704922922368af1c0";6 version = "before-str-extend";
77
8 src = fetchFromGitHub {8 src = fetchFromGitHub {
9 owner = "CertainLach";9 owner = "CertainLach";
10 repo = pname;10 repo = pname;
11 rev = version;11 rev = "d32fe45b8ed28fb39b5359a704922922368af1c0";
12 hash = "sha256-R9Xt36bYS5upVDzt8hEifwmfocXpJbIKwvxkoJNEGVc=";12 hash = "sha256-R9Xt36bYS5upVDzt8hEifwmfocXpJbIKwvxkoJNEGVc=";
13 };13 };
14 cargoHash = "sha256-V+KGWeNlUnelofaGzufNPLGDyxazoFrjZ/n391VYYws=";14 cargoHash = "sha256-j2sUIzvK66jn8ajmMsXXHstw79jCLog93XCQj1qjAN8=";
1515
16 cargoTestFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];16 cargoTestFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
17 cargoBuildFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];17 cargoBuildFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
1818
19 buildInputs = [ makeWrapper ];19 buildInputs = [ makeWrapper ];
2020
21 postInstall = ''21 postInstall = ''
22 mv $out/bin/jrsonnet $out/bin/jrsonnet-release22 wrapProgram $out/bin/jrsonnet --add-flags "--max-stack=200000 --os-stack=200000"
23 wrapProgram $out/bin/jrsonnet-release --add-flags "--max-stack=200000 --os-stack=200000"23 '';
24 '';
25}24}
2625
modifiednix/jrsonnet.nixdiffbeforeafterboth
3, rustPlatform
4, runCommand
5, makeWrapper
6, withNightlyFeatures ? false
7}:
8
9with lib;
210
3let11let
4 filteredSrc = builtins.path {12 filteredSrc = builtins.path {
18rustPlatform.buildRustPackage rec {26rustPlatform.buildRustPackage rec {
19 inherit src;27 inherit src;
20 pname = "jrsonnet";28 pname = "jrsonnet";
21 version = "git";29 version = "current${optionalString withNightlyFeatures "-nightly"}";
2230
23 cargoTestFlags = [ "--features=mimalloc,legacy-this-file,nightly" ];31 cargoTestFlags = [
32 "--features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}"
33 ];
24 cargoBuildFlags = [ "--features=mimalloc,legacy-this-file,nightly" ];34 cargoBuildFlags = cargoTestFlags;
2535
26 buildInputs = [ makeWrapper ];36 buildInputs = [ makeWrapper ];
2737