difftreelog
feat return NumValue directly from parser
in: master
15 files changed
bindings/jsonnet/src/val_make.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -5,10 +5,7 @@
os::raw::{c_char, c_double, c_int},
};
-use jrsonnet_evaluator::{
- ObjValue, Val,
- val::{ArrValue, NumValue},
-};
+use jrsonnet_evaluator::{NumValue, ObjValue, Val};
use crate::VM;
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -2,7 +2,9 @@
use jrsonnet_gcmodule::{Acyclic, Trace};
use jrsonnet_interner::IStr;
-use jrsonnet_ir::{BinaryOpType, Source, SourcePath, Span, Spanned, UnaryOpType};
+use jrsonnet_ir::{
+ BinaryOpType, ConvertNumValueError, Source, SourcePath, Span, Spanned, UnaryOpType,
+};
use jrsonnet_types::ValType;
use thiserror::Error;
@@ -11,7 +13,6 @@
function::{CallLocation, FunctionSignature, ParamName},
stdlib::format::FormatError,
typed::TypeLocError,
- val::ConvertNumValueError,
};
#[derive(Debug, Clone)]
@@ -228,6 +229,11 @@
Self::new(e)
}
}
+impl From<ConvertNumValueError> for Error {
+ fn from(e: ConvertNumValueError) -> Self {
+ Self::new(ErrorKind::ConvertNumValue(e))
+ }
+}
impl From<Infallible> for Error {
fn from(_value: Infallible) -> Self {
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -21,7 +21,7 @@
function::{CallLocation, FuncDesc, FuncVal, PreparedFuncVal},
in_frame,
typed::{FromUntyped, IntoUntyped as _, Typed},
- val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk},
+ val::{CachedUnbound, IndexableVal, StrValue, Thunk},
with_state,
};
pub mod destructure;
@@ -58,9 +58,7 @@
}
Some(match expr {
Expr::Str(s) => Val::string(s.clone()),
- Expr::Num(n) => {
- Val::Num(NumValue::new(*n).expect("parser will not allow non-finite values"))
- }
+ Expr::Num(n) => Val::Num(*n),
Expr::Literal(LiteralType::False) => Val::Bool(false),
Expr::Literal(LiteralType::True) => Val::Bool(true),
Expr::Literal(LiteralType::Null) => Val::Null,
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use jrsonnet_interner::{IBytes, IStr};
+use jrsonnet_ir::NumValue;
use serde::{
Deserialize, Serialize, Serializer,
de::{self, Visitor},
@@ -12,7 +13,6 @@
use crate::{
Error as JrError, ObjValue, ObjValueBuilder, Result, Val, in_description_frame, runtime_error,
- val::NumValue,
};
impl<'de> Deserialize<'de> for Val {
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -42,6 +42,7 @@
use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};
pub use jrsonnet_interner::{IBytes, IStr};
pub use jrsonnet_ir as parser;
+pub use jrsonnet_ir::NumValue;
use jrsonnet_ir::{Expr, Source, SourcePath};
#[doc(hidden)]
pub use jrsonnet_macros;
crates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -829,7 +829,7 @@
#[cfg(test)]
pub mod test_format {
use super::*;
- use crate::val::NumValue;
+ use crate::NumValue;
#[test]
fn parse() {
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth1use std::{any::TypeId, collections::BTreeMap, marker::PhantomData, mem::transmute, ops::Deref};23use jrsonnet_gcmodule::Trace;4use jrsonnet_interner::{IBytes, IStr};5use jrsonnet_types::{ComplexValType, ValType};67use crate::{8 ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,9 arr::ArrValue,10 bail,11 function::FuncVal,12 typed::CheckType,13 val::{IndexableVal, NumValue, StrValue, ThunkMapper},14};1516#[doc(hidden)]17pub mod __typed_macro_prelude {18 pub use ::jrsonnet_evaluator::{19 IStr, ObjValue, ObjValueBuilder, State, Val,20 error::{ErrorKind, Result as JrResult},21 typed::{22 CheckType, ComplexValType, FromUntyped, IntoUntyped, ParseTypedObj, SerializeTypedObj,23 Typed,24 },25 };26}27pub use jrsonnet_macros::{FromUntyped, IntoUntyped, Typed};2829#[derive(Trace)]30struct ThunkFromUntyped<K: Trace>(PhantomData<fn() -> K>);31impl<K> ThunkMapper<Val> for ThunkFromUntyped<K>32where33 K: Typed + FromUntyped + Trace,34{35 type Output = K;3637 fn map(self, from: Val) -> Result<Self::Output> {38 K::from_untyped(from)39 }40}41impl<K: Trace> Default for ThunkFromUntyped<K> {42 fn default() -> Self {43 Self(PhantomData)44 }45}46#[derive(Trace)]47struct ThunkIntoUntyped<K: Trace>(PhantomData<fn() -> K>);48impl<K> ThunkMapper<K> for ThunkIntoUntyped<K>49where50 K: Typed + Trace + IntoUntyped,51{52 type Output = Val;5354 fn map(self, from: K) -> Result<Self::Output> {55 K::into_untyped(from)56 }57}58impl<K: Trace> Default for ThunkIntoUntyped<K> {59 fn default() -> Self {60 Self(PhantomData)61 }62}6364#[diagnostic::on_unimplemented(65 note = "don't implement `ParseTypedObj` directly, it is automatically provided by `FromUntyped` derive"66)]67pub trait ParseTypedObj: Typed {68 fn parse(obj: &ObjValue) -> Result<Self>;69}7071#[diagnostic::on_unimplemented(72 note = "don't implement `SerializeTypedObj` directly, it is automatically provided by `IntoUntyped` derive"73)]74pub trait SerializeTypedObj: Typed {75 fn serialize(self, out: &mut ObjValueBuilder) -> Result<()>;76 fn into_object(self) -> Result<ObjValue> {77 let mut builder = ObjValueBuilder::new();78 self.serialize(&mut builder)?;79 Ok(builder.build())80 }81}8283pub trait Typed: Sized {84 const TYPE: &'static ComplexValType;85}86impl<T> Typed for &T87where88 T: Typed,89{90 const TYPE: &'static ComplexValType = <&T as Typed>::TYPE;91}92pub trait IntoUntyped: Typed {93 // Whatever caller should use `into_lazy_untyped` instead of `into_untyped`94 fn provides_lazy() -> bool {95 false96 }97 fn into_untyped(typed: Self) -> Result<Val>;98 fn into_lazy_untyped(typed: Self) -> Thunk<Val> {99 Thunk::from(Self::into_untyped(typed))100 }101}102103pub trait IntoUntypedResult: Typed {104 /// Hack to make builtins be able to return non-result values, and make macros able to convert those values to result105 /// This method returns identity in impl Typed for Result, and should not be overriden106 #[doc(hidden)]107 fn into_untyped_result(typed: Self) -> Result<Val>;108}109impl<T> IntoUntypedResult for T110where111 T: IntoUntyped,112{113 fn into_untyped_result(typed: Self) -> Result<Val> {114 T::into_untyped(typed)115 }116}117118pub trait FromUntyped: Typed {119 fn from_untyped(untyped: Val) -> Result<Self>;120 fn from_lazy_untyped(lazy: Thunk<Val>) -> Result<Self> {121 Self::from_untyped(lazy.evaluate()?)122 }123124 // Whatever caller should use `from_lazy_untyped` instead of `from_untyped` when possible125 fn wants_lazy() -> bool {126 false127 }128}129130impl<T> Typed for Thunk<T>131where132 T: Typed + Trace + Clone,133{134 const TYPE: &'static ComplexValType = &ComplexValType::Lazy(T::TYPE);135}136137#[inline]138fn try_cast_thunk_val<T: 'static>(typed: Thunk<T>) -> Result<Thunk<Val>, Thunk<T>> {139 if TypeId::of::<T>() == TypeId::of::<Val>() {140 // SAFETY: We know that it is exactly the same type, and we discard the original after that141 // to avoid double-free.142 let transmuted = unsafe { transmute::<Thunk<T>, Thunk<Val>>(typed) };143 Ok(transmuted)144 } else {145 Err(typed)146 }147}148impl<T> IntoUntyped for Thunk<T>149where150 T: IntoUntyped + Trace + Clone,151{152 #[inline]153 fn into_untyped(typed: Self) -> Result<Val> {154 T::into_untyped(typed.evaluate()?)155 }156 fn provides_lazy() -> bool {157 true158 }159160 fn into_lazy_untyped(inner: Self) -> Thunk<Val> {161 // Avoid lazy mapping162 let inner = match try_cast_thunk_val(inner) {163 Ok(v) => return v,164 Err(e) => e,165 };166 inner.map(<ThunkIntoUntyped<T>>::default())167 }168}169impl<T> IntoUntyped for &Thunk<T>170where171 T: IntoUntyped + Trace + Clone,172{173 fn into_untyped(typed: Self) -> Result<Val> {174 T::into_untyped(typed.evaluate()?)175 }176 fn provides_lazy() -> bool {177 true178 }179180 fn into_lazy_untyped(inner: Self) -> Thunk<Val> {181 // Avoid lazy mapping182 let inner = match try_cast_thunk_val(inner.clone()) {183 Ok(v) => return v,184 Err(e) => e,185 };186 inner.map(<ThunkIntoUntyped<T>>::default())187 }188}189190#[inline]191fn try_cast_thunk_t<T: 'static>(typed: Thunk<Val>) -> Result<Thunk<T>, Thunk<Val>> {192 if TypeId::of::<T>() == TypeId::of::<Val>() {193 // SAFETY: We know that it is exactly the same type, and we discard the original after that194 // to avoid double-free.195 let transmuted = unsafe { transmute::<Thunk<Val>, Thunk<T>>(typed) };196 Ok(transmuted)197 } else {198 Err(typed)199 }200}201impl<T> FromUntyped for Thunk<T>202where203 T: Typed + FromUntyped + Trace + Clone,204{205 fn from_untyped(untyped: Val) -> Result<Self> {206 Self::from_lazy_untyped(Thunk::evaluated(untyped))207 }208209 fn wants_lazy() -> bool {210 true211 }212213 fn from_lazy_untyped(inner: Thunk<Val>) -> Result<Self> {214 // Avoid lazy mapping215 let inner = match try_cast_thunk_t(inner) {216 Ok(v) => return Ok(v),217 Err(e) => e,218 };219 Ok(inner.map(<ThunkFromUntyped<T>>::default()))220 }221}222223#[expect(clippy::cast_precision_loss, reason = "checked to not overflow")]224pub const MAX_SAFE_INTEGER: f64 = ((1u64 << (f64::MANTISSA_DIGITS)) - 1) as f64;225#[expect(clippy::cast_precision_loss, reason = "checked to not overflow")]226pub const MIN_SAFE_INTEGER: f64 = (-((1i64 << (f64::MANTISSA_DIGITS)) - 1)) as f64;227228macro_rules! impl_int {229 ($($ty:ty)*) => {$(230 impl Typed for $ty {231 const TYPE: &'static ComplexValType =232 &ComplexValType::BoundedNumber(Some(Self::MIN as f64), Some(Self::MAX as f64));233 }234 impl FromUntyped for $ty {235 fn from_untyped(value: Val) -> Result<Self> {236 <Self as Typed>::TYPE.check(&value)?;237 match value {238 Val::Num(n) => {239 let n = n.get();240 #[allow(clippy::float_cmp)]241 if n.trunc() != n {242 bail!(243 "cannot convert number with fractional part to {}",244 stringify!($ty)245 )246 }247 #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation, reason = "checked by TYPE")]248 Ok(n as Self)249 }250 _ => unreachable!(),251 }252 }253 }254 impl IntoUntyped for &$ty {255 fn into_untyped(value: Self) -> Result<Val> {256 Ok(Val::Num((*value).into()))257 }258 }259 impl IntoUntyped for $ty {260 fn into_untyped(value: Self) -> Result<Val> {261 Ok(Val::Num(value.into()))262 }263 }264 )*};265}266267impl_int!(i8 u8 i16 u16 i32 u32);268269macro_rules! impl_bounded_int {270 ($($name:ident = $ty:ty)*) => {$(271 #[derive(Clone, Copy)]272 #[allow(clippy::cast_possible_truncation, reason = "overflow is api misuse")]273 pub struct $name<const MIN: $ty, const MAX: $ty>($ty);274 impl<const MIN: $ty, const MAX: $ty> $name<MIN, MAX> {275 pub const fn new(value: $ty) -> Option<$name<MIN, MAX>> {276 if value >= MIN && value <= MAX {277 Some(Self(value))278 } else {279 None280 }281 }282 pub const fn value(self) -> $ty {283 self.0284 }285 }286 impl<const MIN: $ty, const MAX: $ty> Deref for $name<MIN, MAX> {287 type Target = $ty;288 fn deref(&self) -> &Self::Target {289 &self.0290 }291 }292293 impl<const MIN: $ty, const MAX: $ty> Typed for $name<MIN, MAX> {294 #[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss, reason = "overflow is api misuse")]295 const TYPE: &'static ComplexValType =296 &ComplexValType::BoundedNumber(297 Some(MIN as f64),298 Some(MAX as f64),299 );300 }301302 impl<const MIN: $ty, const MAX: $ty> FromUntyped for $name<MIN, MAX> {303 fn from_untyped(value: Val) -> Result<Self> {304 <Self as Typed>::TYPE.check(&value)?;305 match value {306 Val::Num(n) => {307 let n = n.get();308 #[allow(clippy::float_cmp)]309 if n.trunc() != n {310 bail!(311 "cannot convert number with fractional part to {}",312 stringify!($ty)313 )314 }315 #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss, reason = "overflow is api misuse, the range is checked by TYPE")]316 Ok(Self(n as $ty))317 }318 _ => unreachable!(),319 }320 }321 }322323 impl<const MIN: $ty, const MAX: $ty> IntoUntyped for $name<MIN, MAX> {324 #[allow(clippy::cast_lossless)]325 fn into_untyped(value: Self) -> Result<Val> {326 Ok(Val::try_num(value.0)?)327 }328 }329 )*};330}331332impl_bounded_int!(333 BoundedI8 = i8334 BoundedI16 = i16335 BoundedI32 = i32336 BoundedI64 = i64337 BoundedUsize = usize338);339340impl Typed for f64 {341 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);342}343impl IntoUntyped for &f64 {344 fn into_untyped(value: Self) -> Result<Val> {345 Ok(Val::try_num(*value)?)346 }347}348impl IntoUntyped for f64 {349 fn into_untyped(value: Self) -> Result<Val> {350 Ok(Val::try_num(value)?)351 }352}353impl FromUntyped for f64 {354 fn from_untyped(value: Val) -> Result<Self> {355 <Self as Typed>::TYPE.check(&value)?;356 match value {357 Val::Num(n) => Ok(n.get()),358 _ => unreachable!(),359 }360 }361}362363pub struct PositiveF64(pub f64);364impl Typed for PositiveF64 {365 const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(0.0), None);366}367impl IntoUntyped for &PositiveF64 {368 fn into_untyped(value: Self) -> Result<Val> {369 Ok(Val::try_num(value.0)?)370 }371}372impl FromUntyped for PositiveF64 {373 fn from_untyped(value: Val) -> Result<Self> {374 <Self as Typed>::TYPE.check(&value)?;375 match value {376 Val::Num(n) => Ok(Self(n.get())),377 _ => unreachable!(),378 }379 }380}381impl Typed for usize {382 const TYPE: &'static ComplexValType =383 &ComplexValType::BoundedNumber(Some(0.0), Some(MAX_SAFE_INTEGER));384}385impl IntoUntyped for usize {386 fn into_untyped(value: Self) -> Result<Val> {387 Ok(Val::try_num(value)?)388 }389}390impl FromUntyped for usize {391 fn from_untyped(value: Val) -> Result<Self> {392 <Self as Typed>::TYPE.check(&value)?;393 match value {394 Val::Num(n) => {395 let n = n.get();396 #[allow(clippy::float_cmp)]397 if n.trunc() != n {398 bail!("cannot convert number with fractional part to usize")399 }400 #[allow(401 clippy::cast_possible_truncation,402 clippy::cast_sign_loss,403 reason = "the range is checked by TYPE"404 )]405 Ok(n as Self)406 }407 _ => unreachable!(),408 }409 }410}411412impl Typed for IStr {413 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);414}415impl IntoUntyped for IStr {416 fn into_untyped(value: Self) -> Result<Val> {417 Ok(Val::string(value))418 }419}420impl FromUntyped for IStr {421 fn from_untyped(value: Val) -> Result<Self> {422 <Self as Typed>::TYPE.check(&value)?;423 match value {424 Val::Str(s) => Ok(s.into_flat()),425 _ => unreachable!(),426 }427 }428}429430impl Typed for String {431 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);432}433impl IntoUntyped for String {434 fn into_untyped(value: Self) -> Result<Val> {435 Ok(Val::string(value))436 }437}438impl FromUntyped for String {439 fn from_untyped(value: Val) -> Result<Self> {440 <Self as Typed>::TYPE.check(&value)?;441 match value {442 Val::Str(s) => Ok(s.to_string()),443 _ => unreachable!(),444 }445 }446}447448impl Typed for StrValue {449 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);450}451impl IntoUntyped for StrValue {452 fn into_untyped(value: Self) -> Result<Val> {453 Ok(Val::Str(value))454 }455}456impl FromUntyped for StrValue {457 fn from_untyped(value: Val) -> Result<Self> {458 <Self as Typed>::TYPE.check(&value)?;459 match value {460 Val::Str(s) => Ok(s),461 _ => unreachable!(),462 }463 }464}465466impl Typed for char {467 const TYPE: &'static ComplexValType = &ComplexValType::Char;468}469impl IntoUntyped for &char {470 fn into_untyped(value: Self) -> Result<Val> {471 Ok(Val::string(*value))472 }473}474impl IntoUntyped for char {475 fn into_untyped(value: Self) -> Result<Val> {476 Ok(Val::string(value))477 }478}479impl FromUntyped for char {480 fn from_untyped(value: Val) -> Result<Self> {481 <Self as Typed>::TYPE.check(&value)?;482 match value {483 Val::Str(s) => Ok(s.into_flat().chars().next().unwrap()),484 _ => unreachable!(),485 }486 }487}488489// TODO: View into vec using ArrayLike?490impl<T> Typed for Vec<T>491where492 T: Typed,493{494 const TYPE: &'static ComplexValType = &ComplexValType::ArrayRef(T::TYPE);495}496impl<T: Typed + IntoUntyped> IntoUntyped for Vec<T> {497 fn into_untyped(value: Self) -> Result<Val> {498 Ok(Val::Arr(499 value500 .into_iter()501 .map(T::into_untyped)502 .collect::<Result<ArrValue>>()?,503 ))504 }505}506impl<T: Typed + FromUntyped> FromUntyped for Vec<T> {507 fn from_untyped(value: Val) -> Result<Self> {508 let Val::Arr(a) = value else {509 <Self as Typed>::TYPE.check(&value)?;510 unreachable!("typecheck should fail")511 };512 a.iter()513 .enumerate()514 .map(|(i, r)| {515 r.and_then(|t| {516 T::from_untyped(t).with_description(|| format!("parsing elem <{i}>"))517 })518 })519 .collect::<Result<Self>>()520 }521}522523// TODO: View into BTreeMap using ObjectCore?524impl<K, V> Typed for BTreeMap<K, V>525where526 K: Typed + Ord,527 V: Typed,528{529 const TYPE: &'static ComplexValType = &ComplexValType::AttrsOf(V::TYPE);530}531impl<K, V> IntoUntyped for BTreeMap<K, V>532where533 K: Typed + Ord + IntoUntyped,534 V: Typed + IntoUntyped,535{536 fn into_untyped(typed: Self) -> Result<Val> {537 let mut out = ObjValueBuilder::with_capacity(typed.len());538 for (k, v) in typed {539 let Some(key) = K::into_untyped(k)?.as_str() else {540 bail!("map key should serialize to string");541 };542 let value = V::into_untyped(v)?;543 out.field(key).value(value);544 }545 Ok(Val::Obj(out.build()))546 }547}548impl<K, V> FromUntyped for BTreeMap<K, V>549where550 K: FromUntyped + Ord,551 V: FromUntyped,552{553 fn from_untyped(value: Val) -> Result<Self> {554 Self::TYPE.check(&value)?;555 let obj = value.as_obj().expect("typecheck should fail");556557 let mut out = Self::new();558 if V::wants_lazy() {559 for key in obj.fields_ex(560 false,561 #[cfg(feature = "exp-preserve-order")]562 false,563 ) {564 let value = obj.get_lazy(key.clone()).expect("field exists");565 let value = V::from_lazy_untyped(value)?;566 let key = K::from_untyped(Val::Str(key.into()))?;567 let _ = out.insert(key, value);568 }569 } else {570 for (key, value) in obj.iter(571 #[cfg(feature = "exp-preserve-order")]572 false,573 ) {574 let key = K::from_untyped(Val::Str(key.into()))?;575 let value = V::from_untyped(value?)?;576 let _ = out.insert(key, value);577 }578 }579 Ok(out)580 }581}582583impl Typed for Val {584 const TYPE: &'static ComplexValType = &ComplexValType::Any;585}586impl IntoUntyped for &Val {587 #[inline]588 fn into_untyped(typed: Self) -> Result<Val> {589 Ok(typed.clone())590 }591}592impl IntoUntyped for Val {593 #[inline]594 fn into_untyped(typed: Self) -> Result<Val> {595 Ok(typed)596 }597}598impl FromUntyped for Val {599 fn from_untyped(untyped: Val) -> Result<Self> {600 Ok(untyped)601 }602}603604#[doc(hidden)]605impl<T> Typed for Result<T>606where607 T: Typed,608{609 const TYPE: &'static ComplexValType = &ComplexValType::Any;610}611impl<T: IntoUntyped> IntoUntypedResult for Result<T> {612 fn into_untyped_result(typed: Self) -> Result<Val> {613 typed.map(T::into_untyped)?614 }615}616617/// Specialization618impl Typed for IBytes {619 const TYPE: &'static ComplexValType =620 &ComplexValType::ArrayRef(&ComplexValType::BoundedNumber(Some(0.0), Some(255.0)));621}622impl IntoUntyped for &IBytes {623 fn into_untyped(value: Self) -> Result<Val> {624 Ok(Val::arr(value.clone()))625 }626}627impl IntoUntyped for IBytes {628 fn into_untyped(value: Self) -> Result<Val> {629 Ok(Val::arr(value))630 }631}632impl FromUntyped for IBytes {633 fn from_untyped(value: Val) -> Result<Self> {634 let Val::Arr(a) = &value else {635 <Self as Typed>::TYPE.check(&value)?;636 unreachable!()637 };638 if let Some(bytes) = a.as_any().downcast_ref::<IBytes>() {639 return Ok(bytes.clone());640 }641 <Self as Typed>::TYPE.check(&value)?;642 // Any::downcast_ref::<ByteArray>(&a);643 let mut out = Vec::with_capacity(a.len());644 for e in a.iter() {645 let r = e?;646 out.push(u8::from_untyped(r)?);647 }648 Ok(out.as_slice().into())649 }650}651652pub struct M1;653impl Typed for M1 {654 const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(-1.0), Some(-1.0));655}656impl IntoUntyped for &M1 {657 fn into_untyped(_: Self) -> Result<Val> {658 Ok(Val::Num(NumValue::new(-1.0).expect("finite")))659 }660}661impl FromUntyped for M1 {662 fn from_untyped(value: Val) -> Result<Self> {663 <Self as Typed>::TYPE.check(&value)?;664 Ok(Self)665 }666}667668macro_rules! decl_either {669 ($($name: ident, $($id: ident)*);*) => {$(670 #[derive(Clone)]671 pub enum $name<$($id),*> {672 $($id($id)),*673 }674 impl<$($id),*> Typed for $name<$($id),*>675 where676 $($id: Typed,)*677 {678 const TYPE: &'static ComplexValType = &ComplexValType::UnionRef(&[$($id::TYPE),*]);679 }680 impl<$($id),*> IntoUntyped for $name<$($id),*>681 where682 $($id: Typed + IntoUntyped,)*683 {684 fn into_untyped(value: Self) -> Result<Val> {685 match value {$(686 $name::$id(v) => $id::into_untyped(v)687 ),*}688 }689 }690691 impl<$($id),*> FromUntyped for $name<$($id),*>692 where693 $($id: Typed + FromUntyped,)*694 {695 fn from_untyped(value: Val) -> Result<Self> {696 $(697 if $id::TYPE.check(&value).is_ok() {698 $id::from_untyped(value).map(Self::$id)699 } else700 )* {701 <Self as Typed>::TYPE.check(&value)?;702 unreachable!()703 }704 }705 }706 )*}707}708decl_either!(709 Either1, A;710 Either2, A B;711 Either3, A B C;712 Either4, A B C D;713 Either5, A B C D E;714 Either6, A B C D E F;715 Either7, A B C D E F G716);717#[macro_export]718macro_rules! Either {719 ($a:ty) => {$crate::typed::Either1<$a>};720 ($a:ty, $b:ty) => {$crate::typed::Either2<$a, $b>};721 ($a:ty, $b:ty, $c:ty) => {$crate::typed::Either3<$a, $b, $c>};722 ($a:ty, $b:ty, $c:ty, $d:ty) => {$crate::typed::Either4<$a, $b, $c, $d>};723 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty) => {$crate::typed::Either5<$a, $b, $c, $d, $e>};724 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty, $f:ty) => {$crate::typed::Either6<$a, $b, $c, $d, $e, $f>};725 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty, $f:ty, $g:ty) => {$crate::typed::Either7<$a, $b, $c, $d, $e, $f, $g>};726}727pub use Either;728729pub type MyType = Either![u32, f64, String];730731impl Typed for ArrValue {732 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Arr);733}734impl IntoUntyped for ArrValue {735 fn into_untyped(value: Self) -> Result<Val> {736 Ok(Val::Arr(value))737 }738}739impl FromUntyped for ArrValue {740 fn from_untyped(value: Val) -> Result<Self> {741 <Self as Typed>::TYPE.check(&value)?;742 match value {743 Val::Arr(a) => Ok(a),744 _ => unreachable!(),745 }746 }747}748749impl Typed for FuncVal {750 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);751}752impl IntoUntyped for FuncVal {753 fn into_untyped(value: Self) -> Result<Val> {754 Ok(Val::Func(value))755 }756}757impl FromUntyped for FuncVal {758 fn from_untyped(value: Val) -> Result<Self> {759 <Self as Typed>::TYPE.check(&value)?;760 match value {761 Val::Func(a) => Ok(a),762 _ => unreachable!(),763 }764 }765}766767impl Typed for ObjValue {768 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Obj);769}770impl IntoUntyped for ObjValue {771 fn into_untyped(value: Self) -> Result<Val> {772 Ok(Val::Obj(value))773 }774}775impl FromUntyped for ObjValue {776 fn from_untyped(value: Val) -> Result<Self> {777 <Self as Typed>::TYPE.check(&value)?;778 match value {779 Val::Obj(a) => Ok(a),780 _ => unreachable!(),781 }782 }783}784785impl Typed for bool {786 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Bool);787}788impl IntoUntyped for &bool {789 fn into_untyped(value: Self) -> Result<Val> {790 Ok(Val::Bool(*value))791 }792}793impl IntoUntyped for bool {794 fn into_untyped(value: Self) -> Result<Val> {795 Ok(Val::Bool(value))796 }797}798impl FromUntyped for bool {799 fn from_untyped(value: Val) -> Result<Self> {800 <Self as Typed>::TYPE.check(&value)?;801 match value {802 Val::Bool(a) => Ok(a),803 _ => unreachable!(),804 }805 }806}807808impl Typed for IndexableVal {809 const TYPE: &'static ComplexValType = &ComplexValType::UnionRef(&[810 &ComplexValType::Simple(ValType::Arr),811 &ComplexValType::Simple(ValType::Str),812 ]);813}814impl IntoUntyped for IndexableVal {815 fn into_untyped(value: Self) -> Result<Val> {816 match value {817 Self::Str(s) => Ok(Val::string(s)),818 Self::Arr(a) => Ok(Val::Arr(a)),819 }820 }821}822impl FromUntyped for IndexableVal {823 fn from_untyped(value: Val) -> Result<Self> {824 <Self as Typed>::TYPE.check(&value)?;825 value.into_indexable()826 }827}828829impl Typed for () {830 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Null);831}832impl IntoUntyped for &() {833 fn into_untyped((): Self) -> Result<Val> {834 Ok(Val::Null)835 }836}837impl IntoUntyped for () {838 fn into_untyped((): Self) -> Result<Val> {839 Ok(Val::Null)840 }841}842impl FromUntyped for () {843 fn from_untyped(value: Val) -> Result<Self> {844 <Self as Typed>::TYPE.check(&value)?;845 Ok(())846 }847}848849impl<T> Typed for Option<T>850where851 T: Typed,852{853 const TYPE: &'static ComplexValType =854 &ComplexValType::UnionRef(&[&ComplexValType::Simple(ValType::Null), T::TYPE]);855}856impl<T> IntoUntyped for Option<T>857where858 T: Typed + IntoUntyped,859{860 fn into_untyped(typed: Self) -> Result<Val> {861 typed.map_or_else(|| Ok(Val::Null), |v| T::into_untyped(v))862 }863}864impl<T> FromUntyped for Option<T>865where866 T: Typed + FromUntyped,867{868 fn from_untyped(untyped: Val) -> Result<Self> {869 if matches!(untyped, Val::Null) {870 Ok(None)871 } else {872 T::from_untyped(untyped).map(Some)873 }874 }875}876877impl Typed for NumValue {878 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);879}880impl IntoUntyped for &NumValue {881 fn into_untyped(typed: Self) -> Result<Val> {882 Ok(Val::Num(*typed))883 }884}885impl FromUntyped for NumValue {886 fn from_untyped(untyped: Val) -> Result<Self> {887 Self::TYPE.check(&untyped)?;888 match untyped {889 Val::Num(v) => Ok(v),890 _ => unreachable!(),891 }892 }893}crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -5,7 +5,6 @@
marker::PhantomData,
mem::replace,
num::NonZeroU32,
- ops::Deref,
rc::Rc,
};
@@ -14,16 +13,15 @@
pub use jrsonnet_macros::Thunk;
use jrsonnet_types::ValType;
use rustc_hash::FxHashMap;
-use thiserror::Error;
pub use crate::arr::{ArrValue, ArrayLike};
use crate::{
- ObjValue, Result, SupThis, Unbound, WeakSupThis, bail,
+ NumValue, ObjValue, Result, SupThis, Unbound, WeakSupThis, bail,
error::{Error, ErrorKind::*},
function::FuncVal,
gc::WithCapacityExt as _,
manifest::{ManifestFormat, ToStringFormat},
- typed::{BoundedUsize, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER},
+ typed::BoundedUsize,
};
pub trait ThunkValue: Trace {
@@ -439,134 +437,6 @@
let a = self.clone().into_flat();
let b = other.clone().into_flat();
a.cmp(&b)
- }
-}
-
-/// Represents jsonnet number
-/// Jsonnet numbers are finite f64, with NaNs disallowed
-#[derive(Trace, Clone, Copy)]
-#[repr(transparent)]
-pub struct NumValue(f64);
-impl NumValue {
- /// Creates a [`NumValue`], if value is finite and not NaN
- pub fn new(v: f64) -> Option<Self> {
- if !v.is_finite() {
- return None;
- }
- Some(Self(v))
- }
- #[inline]
- pub const fn get(&self) -> f64 {
- self.0
- }
- pub(crate) fn truncate_for_bitwise(self) -> Result<i64> {
- if self.0 < MIN_SAFE_INTEGER || self.0 > MAX_SAFE_INTEGER {
- bail!("numberic value outside of safe integer range for bitwise operation");
- }
- #[expect(clippy::cast_possible_truncation, reason = "intended")]
- Ok(self.0 as i64)
- }
-}
-impl PartialEq for NumValue {
- fn eq(&self, other: &Self) -> bool {
- self.0 == other.0
- }
-}
-impl Eq for NumValue {}
-impl Ord for NumValue {
- #[inline]
- fn cmp(&self, other: &Self) -> Ordering {
- // Can't use `total_cmp`: its behavior for `-0` and `0`
- // is not following wanted.
- unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
- }
-}
-impl PartialOrd for NumValue {
- #[inline]
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.cmp(other))
- }
-}
-impl Debug for NumValue {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- Debug::fmt(&self.0, f)
- }
-}
-impl Display for NumValue {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- Display::fmt(&self.0, f)
- }
-}
-impl Deref for NumValue {
- type Target = f64;
-
- #[inline]
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-macro_rules! impl_num {
- ($($ty:ty),+) => {$(
- impl From<$ty> for NumValue {
- #[inline]
- fn from(value: $ty) -> Self {
- Self(value.into())
- }
- }
- )+};
-}
-impl_num!(i8, u8, i16, u16, i32, u32);
-
-#[derive(Clone, Copy, Debug, Error, Trace)]
-pub enum ConvertNumValueError {
- #[error("overflow")]
- Overflow,
- #[error("underflow")]
- Underflow,
- #[error("non-finite")]
- NonFinite,
-}
-impl From<ConvertNumValueError> for Error {
- fn from(e: ConvertNumValueError) -> Self {
- Self::new(e.into())
- }
-}
-
-macro_rules! impl_try_num {
- ($($ty:ty),+) => {$(
- impl TryFrom<$ty> for NumValue {
- type Error = ConvertNumValueError;
- #[inline]
- fn try_from(value: $ty) -> Result<Self, ConvertNumValueError> {
- #[expect(clippy::cast_precision_loss, reason = "precision loss is explicitly handled")]
- let value = value as f64;
- if value < MIN_SAFE_INTEGER {
- return Err(ConvertNumValueError::Underflow)
- } else if value > MAX_SAFE_INTEGER {
- return Err(ConvertNumValueError::Overflow)
- }
- // Number is finite.
- Ok(Self(value))
- }
- }
- )+};
-}
-impl_try_num!(usize, isize, i64, u64);
-
-impl TryFrom<f64> for NumValue {
- type Error = ConvertNumValueError;
-
- #[inline]
- fn try_from(value: f64) -> Result<Self, Self::Error> {
- Self::new(value).ok_or(ConvertNumValueError::NonFinite)
- }
-}
-impl TryFrom<f32> for NumValue {
- type Error = ConvertNumValueError;
-
- #[inline]
- fn try_from(value: f32) -> Result<Self, Self::Error> {
- Self::new(f64::from(value)).ok_or(ConvertNumValueError::NonFinite)
}
}
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -4,8 +4,8 @@
use jrsonnet_ir::{
ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,
- ImportKind, IndexPart, LiteralType, Member, ObjBody, ObjComp, ObjMembers, Slice, SliceDesc,
- Source, Span, Spanned, UnaryOpType, Visibility, unescape,
+ ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
+ SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility, unescape,
};
use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};
@@ -202,17 +202,21 @@
)
}
-fn parse_number(p: &mut Parser<'_>) -> Result<f64> {
+fn parse_number(p: &mut Parser<'_>) -> Result<NumValue> {
let text = p.text();
let n: f64 = text
.replace('_', "")
.parse()
.map_err(|_| p.error(format!("invalid number literal: {text}")))?;
- if !n.is_finite() {
- return Err(p.error("numbers are finite".into()));
- }
+
+ let v = match NumValue::try_from(n) {
+ Ok(v) => v,
+ Err(e) => return Err(p.error(format!("invalid number value: {e}"))),
+ };
+
p.eat_any();
- Ok(n)
+
+ Ok(v)
}
fn ident(p: &mut Parser<'_>) -> Result<IStr> {
crates/jrsonnet-ir/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-ir/Cargo.toml
+++ b/crates/jrsonnet-ir/Cargo.toml
@@ -19,6 +19,7 @@
static_assertions.workspace = true
peg.workspace = true
+thiserror.workspace = true
[dev-dependencies]
insta.workspace = true
crates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/expr.rs
+++ b/crates/jrsonnet-ir/src/expr.rs
@@ -8,6 +8,7 @@
use jrsonnet_interner::IStr;
use crate::{
+ NumValue,
function::{FunctionSignature, ParamDefault, ParamName, ParamParse},
source::Source,
};
@@ -398,7 +399,7 @@
/// String value: "hello"
Str(IStr),
/// Number: 1, 2.0, 2e+20
- Num(f64),
+ Num(NumValue),
/// Variable name: test
Var(Spanned<IStr>),
crates/jrsonnet-ir/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/lib.rs
+++ b/crates/jrsonnet-ir/src/lib.rs
@@ -1,7 +1,10 @@
#![allow(clippy::redundant_closure_call, clippy::derive_partial_eq_without_eq)]
mod expr;
+use std::{cmp::Ordering, fmt, ops::Deref};
+
pub use expr::*;
+use jrsonnet_gcmodule::Acyclic;
pub use jrsonnet_interner::IStr;
pub mod function;
mod location;
@@ -14,3 +17,134 @@
Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,
SourcePathT, SourceVirtual,
};
+
+// It seels to be a wrong place for this kind of stuff, but as it would also be used for static analysis and
+// is already wanted for NumValue, I don't know a better place.
+#[expect(clippy::cast_precision_loss, reason = "checked to not overflow")]
+pub const MAX_SAFE_INTEGER: f64 = ((1u64 << (f64::MANTISSA_DIGITS)) - 1) as f64;
+#[expect(clippy::cast_precision_loss, reason = "checked to not overflow")]
+pub const MIN_SAFE_INTEGER: f64 = (-((1i64 << (f64::MANTISSA_DIGITS)) - 1)) as f64;
+
+/// Represents jsonnet number
+/// Jsonnet numbers are finite f64, with NaNs disallowed
+#[derive(Acyclic, Clone, Copy)]
+pub struct NumValue(f64);
+impl NumValue {
+ /// Creates a [`NumValue`], if value is finite and not NaN
+ pub fn new(v: f64) -> Option<Self> {
+ if !v.is_finite() {
+ return None;
+ }
+ Some(Self(v))
+ }
+ #[inline]
+ pub const fn get(&self) -> f64 {
+ self.0
+ }
+ pub fn truncate_for_bitwise(self) -> Result<i64, ConvertNumValueError> {
+ if self.0 < MIN_SAFE_INTEGER || self.0 > MAX_SAFE_INTEGER {
+ return Err(ConvertNumValueError::BitwiseSafeRange);
+ }
+ #[expect(clippy::cast_possible_truncation, reason = "intended")]
+ Ok(self.0 as i64)
+ }
+}
+impl PartialEq for NumValue {
+ fn eq(&self, other: &Self) -> bool {
+ self.0 == other.0
+ }
+}
+impl Eq for NumValue {}
+impl Ord for NumValue {
+ #[inline]
+ fn cmp(&self, other: &Self) -> Ordering {
+ // Can't use `total_cmp`: its behavior for `-0` and `0`
+ // is not following wanted.
+ unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
+ }
+}
+impl PartialOrd for NumValue {
+ #[inline]
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+impl fmt::Debug for NumValue {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Debug::fmt(&self.0, f)
+ }
+}
+impl fmt::Display for NumValue {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Display::fmt(&self.0, f)
+ }
+}
+impl Deref for NumValue {
+ type Target = f64;
+
+ #[inline]
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+macro_rules! impl_num {
+ ($($ty:ty),+) => {$(
+ impl From<$ty> for NumValue {
+ #[inline]
+ fn from(value: $ty) -> Self {
+ Self(value.into())
+ }
+ }
+ )+};
+}
+impl_num!(i8, u8, i16, u16, i32, u32);
+
+#[derive(Clone, Copy, Debug, thiserror::Error, Acyclic)]
+pub enum ConvertNumValueError {
+ #[error("overflow")]
+ Overflow,
+ #[error("underflow")]
+ Underflow,
+ #[error("non-finite")]
+ NonFinite,
+ #[error("float out of safe int range")]
+ BitwiseSafeRange,
+}
+
+macro_rules! impl_try_num {
+ ($($ty:ty),+) => {$(
+ impl TryFrom<$ty> for NumValue {
+ type Error = ConvertNumValueError;
+ #[inline]
+ fn try_from(value: $ty) -> Result<Self, ConvertNumValueError> {
+ #[expect(clippy::cast_precision_loss, reason = "precision loss is explicitly handled")]
+ let value = value as f64;
+ if value < MIN_SAFE_INTEGER {
+ return Err(ConvertNumValueError::Underflow)
+ } else if value > MAX_SAFE_INTEGER {
+ return Err(ConvertNumValueError::Overflow)
+ }
+ // Number is finite.
+ Ok(Self(value))
+ }
+ }
+ )+};
+}
+impl_try_num!(usize, isize, i64, u64);
+
+impl TryFrom<f64> for NumValue {
+ type Error = ConvertNumValueError;
+
+ #[inline]
+ fn try_from(value: f64) -> Result<Self, Self::Error> {
+ Self::new(value).ok_or(ConvertNumValueError::NonFinite)
+ }
+}
+impl TryFrom<f32> for NumValue {
+ type Error = ConvertNumValueError;
+
+ #[inline]
+ fn try_from(value: f32) -> Result<Self, Self::Error> {
+ Self::new(f64::from(value)).ok_or(ConvertNumValueError::NonFinite)
+ }
+}
crates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-peg-parser/src/lib.rs
+++ b/crates/jrsonnet-peg-parser/src/lib.rs
@@ -4,8 +4,8 @@
use jrsonnet_ir::{
ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, DestructRest, Expr,
ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,
- ImportKind, IndexPart, LiteralType, Member, ObjBody, ObjComp, ObjMembers, Slice, SliceDesc,
- Source, Span, Spanned, Visibility, unescape,
+ ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
+ SliceDesc, Source, Span, Spanned, Visibility, unescape,
};
use peg::parser;
@@ -52,7 +52,7 @@
/// Sequence of digits
rule uint_str() -> &'input str = a:$(digit()+ ("_" digit()+)*) { a }
/// Number in scientific notation format
- rule number() -> f64 = quiet!{a:$(uint_str() ("." uint_str())? (['e'|'E'] (s:['+'|'-'])? uint_str())?) {? a.replace("_","").parse().map_err(|_| "<number>") }} / expected!("<number>")
+ rule number() -> f64 = quiet!{a:$(uint_str() ("." uint_str())? (['e'|'E'] (s:['+'|'-'])? uint_str())?) {? a.replace('_',"").parse().map_err(|_| "<number>") }} / expected!("<number>")
/// Reserved word followed by any non-alphanumberic
rule reserved() = ("assert" / "else" / "error" / "false" / "for" / "function" / "if" / "import" / "importstr" / "importbin" / "in" / "local" / "null" / "tailstrict" / "then" / "self" / "super" / "true") end_of_ident()
@@ -267,7 +267,7 @@
Expr::ArrComp(Rc::new(expr), specs)
}
pub rule number_expr(s: &ParserSettings) -> Expr
- = n:number() {? if n.is_finite() {
+ = n:number() {? if let Some(n) = NumValue::new(n) {
Ok(Expr::Num(n))
} else {
Err("!!!numbers are finite")
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -12,13 +12,12 @@
pub use encoding::*;
pub use hash::*;
use jrsonnet_evaluator::{
- ContextBuilder, IStr, ObjValue, ObjValueBuilder, Thunk, Val,
+ ContextBuilder, IStr, NumValue, ObjValue, ObjValueBuilder, Thunk, Val,
error::Result,
function::{CallLocation, FuncVal, builtin_id},
tla::TlaArg,
trace::PathResolver,
typed::SerializeTypedObj as _,
- val::NumValue,
};
use jrsonnet_gcmodule::{Acyclic, Cc, Trace};
use jrsonnet_ir::Source;
crates/jrsonnet-stdlib/src/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/operator.rs
+++ b/crates/jrsonnet-stdlib/src/operator.rs
@@ -2,12 +2,12 @@
//! However, in our case we instead implement them in native, and implement native functions on top of core for backwards compatibility
use jrsonnet_evaluator::{
- IStr, Result, Val,
+ IStr, NumValue, Result, Val,
function::builtin,
operator::evaluate_mod_op,
stdlib::std_format,
typed::{Either, Either2},
- val::{NumValue, equals, primitive_equals},
+ val::{equals, primitive_equals},
};
#[builtin]