git.delta.rocks / jrsonnet / refs/commits / 685a983a9749

difftreelog

feat optional tailstrict in FuncVal::evaluate_simple

Yaroslav Bolyukin2023-04-08parent: #9440ce0.patch.diff
in: master

7 files changed

modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
234 }234 }
235 }235 }
236236
237 /// Is this vec supports .get_cheap()?
237 pub fn is_cheap(&self) -> bool {238 pub fn is_cheap(&self) -> bool {
238 match self {239 match self {
239 ArrValue::Eager(_) | ArrValue::Range(..) | ArrValue::Bytes(_) => true,240 ArrValue::Eager(_) | ArrValue::Range(..) | ArrValue::Bytes(_) => true,
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
748 .get(index)748 .get(index)
749 .transpose()749 .transpose()
750 .expect("index checked")750 .expect("index checked")
751 .and_then(|r| self.0.mapper.evaluate_simple(&(r,)));751 .and_then(|r| self.0.mapper.evaluate_simple(&(r,), false));
752752
753 let new_value = match val {753 let new_value = match val {
754 Ok(v) => v,754 Ok(v) => v,
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth

no syntactic changes

modifiedcrates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth
166 }166 }
167 pub fn evaluate_simple<A: ArgsLike + OptionalContext>(&self, args: &A) -> Result<Val> {167 pub fn evaluate_simple<A: ArgsLike + OptionalContext>(
168 &self,
169 args: &A,
170 tailstrict: bool,
171 ) -> Result<Val> {
168 self.evaluate(172 self.evaluate(
169 ContextBuilder::dangerous_empty_state().build(),173 ContextBuilder::dangerous_empty_state().build(),
170 CallLocation::native(),174 CallLocation::native(),
171 args,175 args,
172 true,176 tailstrict,
173 )177 )
174 }178 }
175 /// Convert jsonnet function to plain `Fn` value.179 /// Convert jsonnet function to plain `Fn` value.
modifiedcrates/jrsonnet-evaluator/src/function/native.rsdiffbeforeafterboth
22 Box::new(move |$($gen),*| {22 Box::new(move |$($gen),*| {
23 let val = val.evaluate_simple(23 let val = val.evaluate_simple(
24 &($($gen,)*),24 &($($gen,)*),
25 false,
25 )?;26 )?;
26 O::from_untyped(val)27 O::from_untyped(val)
27 })28 })
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
174 }174 }
175 // First reference - current object, second - POOL175 // First reference - current object, second - POOL
176 if Inner::strong_count(&self.0) <= 2 {176 if Inner::strong_count(&self.0) <= 2 {
177 eprintln!("unpool");
178 unpool(&self.0);177 unpool(&self.0);
179 }178 }
180 }179 }
modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
8888
89#[builtin]89#[builtin]
90pub fn builtin_filter(func: FuncVal, arr: ArrValue) -> Result<ArrValue> {90pub fn builtin_filter(func: FuncVal, arr: ArrValue) -> Result<ArrValue> {
91 arr.filter(|val| bool::from_untyped(func.evaluate_simple(&(val.clone(),))?))91 arr.filter(|val| bool::from_untyped(func.evaluate_simple(&(val.clone(),), false)?))
92}92}
9393
94#[builtin]94#[builtin]
95pub fn builtin_foldl(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {95pub fn builtin_foldl(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {
96 let mut acc = init;96 let mut acc = init;
97 for i in arr.iter() {97 for i in arr.iter() {
98 acc = func.evaluate_simple(&(acc, i?))?;98 acc = func.evaluate_simple(&(acc, i?), false)?;
99 }99 }
100 Ok(acc)100 Ok(acc)
101}101}
104pub fn builtin_foldr(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {104pub fn builtin_foldr(func: FuncVal, arr: ArrValue, init: Val) -> Result<Val> {
105 let mut acc = init;105 let mut acc = init;
106 for i in arr.iter().rev() {106 for i in arr.iter().rev() {
107 acc = func.evaluate_simple(&(i?, acc))?;107 acc = func.evaluate_simple(&(i?, acc), false)?;
108 }108 }
109 Ok(acc)109 Ok(acc)
110}110}