difftreelog
style fix formatting
in: master
31 files changed
crates/jrsonnet-evaluator/src/analyze.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/analyze.rs
+++ b/crates/jrsonnet-evaluator/src/analyze.rs
@@ -21,10 +21,10 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_interner::IStr;
use jrsonnet_ir::{
- function::FunctionSignature, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType,
- BindSpec, CompSpec, Destruct, Expr, ExprParams, FieldName, ForSpecData, IfElse, IfSpecData,
- ImportKind, LiteralType, NumValue, ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, Span,
- Spanned, UnaryOpType, Visibility,
+ ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
+ ExprParams, FieldName, ForSpecData, IfElse, IfSpecData, ImportKind, LiteralType, NumValue,
+ ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, Span, Spanned, UnaryOpType, Visibility,
+ function::FunctionSignature,
};
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -5,9 +5,9 @@
rc::Rc,
};
-use jrsonnet_gcmodule::{cc_dyn, Cc};
+use jrsonnet_gcmodule::{Cc, cc_dyn};
-use crate::{analyze::LExpr, function::NativeFn, typed::IntoUntyped, Context, Result, Thunk, Val};
+use crate::{Context, Result, Thunk, Val, analyze::LExpr, function::NativeFn, typed::IntoUntyped};
mod spec;
pub use spec::{ArrayLike, *};
crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -11,13 +11,13 @@
use super::ArrValue;
use crate::{
+ Context, Error, ObjValue, Result, Thunk, Val,
analyze::LExpr,
error::ErrorKind::InfiniteRecursionDetected,
evaluate::evaluate,
function::NativeFn,
typed::{IntoUntyped, Typed},
val::ThunkValue,
- Context, Error, ObjValue, Result, Thunk, Val,
};
pub trait ArrayLike: Any + Trace + Debug {
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -4,7 +4,7 @@
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;
-use crate::{analyze::LocalId, error, error::ErrorKind::*, Pending, Result, SupThis, Thunk, Val};
+use crate::{Pending, Result, SupThis, Thunk, Val, analyze::LocalId, error, error::ErrorKind::*};
#[derive(Debug, Trace, Clone, Educe)]
#[educe(PartialEq)]
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -9,10 +9,10 @@
use thiserror::Error;
use crate::{
+ ObjValue, ResolvePathOwned,
function::{CallLocation, FunctionSignature, ParamName},
stdlib::format::FormatError,
typed::TypeLocError,
- ObjValue, ResolvePathOwned,
};
#[derive(Debug, Clone, Acyclic)]
@@ -286,11 +286,11 @@
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- writeln!(f, "{}", self.0 .0)?;
- for el in &self.0 .1 .0 {
+ writeln!(f, "{}", self.0.0)?;
+ for el in &self.0.1.0 {
write!(f, "\t{}", el.desc)?;
if let Some(loc) = &el.location {
- write!(f, "at {}", loc.0 .0 .0)?;
+ write!(f, "at {}", loc.0.0.0)?;
loc.0.map_source_locations(&[loc.1, loc.2]);
}
writeln!(f)?;
crates/jrsonnet-evaluator/src/evaluate/compspec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
@@ -7,12 +7,12 @@
evaluate_field_member_static, evaluate_field_member_unbound,
};
use crate::{
+ Context, ContextBuilder, ObjValue, ObjValueBuilder, Pending, Result, Thunk, Val,
analyze::{LArrComp, LBind, LCompSpec, LDestruct, LExpr, LFieldMember, LObjComp, LocalId},
arr::ArrValue,
bail,
error::ErrorKind::*,
evaluate::evaluate,
- Context, ContextBuilder, ObjValue, ObjValueBuilder, Pending, Result, Thunk, Val,
};
trait CompCollector {
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -3,10 +3,10 @@
use jrsonnet_gcmodule::Trace;
use crate::{
+ Context, ContextBuilder, Pending, Result, SupThis, Thunk, Unbound, Val,
analyze::{LBind, LDestruct, LDestructField, LDestructRest, LExpr, LocalId},
bail,
evaluate::evaluate,
- Context, ContextBuilder, Pending, Result, SupThis, Thunk, Unbound, Val,
};
#[allow(dead_code, reason = "not dead in exp-destruct")]
@@ -97,7 +97,7 @@
use jrsonnet_interner::IStr;
use rustc_hash::FxHashSet;
- use crate::{bail, ObjValueBuilder};
+ use crate::{ObjValueBuilder, bail};
let captured_fields: FxHashSet<IStr> = fields.iter().map(|f| f.name.clone()).collect();
let field_names: Vec<(IStr, bool)> = fields
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -11,19 +11,20 @@
operator::evaluate_binary_op_special,
};
use crate::{
+ Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Result, ResultExt as _, SupThis,
+ Unbound, Val,
analyze::{
LArgsDesc, LAssertStmt, LExpr, LFieldMember, LFieldName, LFunction, LIndexPart, LObjBody,
LObjMembers,
},
bail,
- error::{suggest_object_fields, ErrorKind::*},
+ error::{ErrorKind::*, suggest_object_fields},
evaluate::operator::evaluate_unary_op,
- function::{prepared::PreparedFuncVal, CallLocation, FuncDesc, FuncVal},
+ function::{CallLocation, FuncDesc, FuncVal, prepared::PreparedFuncVal},
in_frame, runtime_error,
typed::FromUntyped as _,
val::{CachedUnbound, Thunk},
- with_state, Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Result, ResultExt as _,
- SupThis, Unbound, Val,
+ with_state,
};
pub mod compspec;
crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -3,6 +3,7 @@
use jrsonnet_ir::{BinaryOpType, UnaryOpType};
use crate::{
+ Context, Result, Val,
analyze::LExpr,
arr::ArrValue,
bail, error,
@@ -10,8 +11,7 @@
evaluate::evaluate,
stdlib::std_format,
typed::IntoUntyped as _,
- val::{equals, StrValue},
- Context, Result, Val,
+ val::{StrValue, equals},
};
pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth1use std::{fmt::Debug, rc::Rc};23use educe::Educe;4use jrsonnet_gcmodule::{Cc, Trace};5use jrsonnet_interner::IStr;6use jrsonnet_ir::Span;7pub use jrsonnet_macros::builtin;89use self::{10 builtin::Builtin,11 prepared::{parse_prepared_builtin_call, PreparedCall},12};13use crate::{14 analyze::{LDestruct, LExpr, LFunction},15 evaluate::{destructure::destruct, ensure_sufficient_stack, evaluate, evaluate_trivial},16 function::builtin::BuiltinFunc,17 Context, ContextBuilder, Result, Thunk, Val,18};1920pub mod builtin;21mod native;22mod parse;23pub(crate) mod prepared;2425pub use jrsonnet_ir::function::*;26pub use native::NativeFn;27pub(crate) use prepared::PreparedFuncVal;2829/// Function callsite location.30/// Either from other jsonnet code, specified by expression location, or from native (without location).31#[derive(Clone, Copy)]32pub struct CallLocation<'l>(pub Option<&'l Span>);33impl<'l> CallLocation<'l> {34 /// Construct new location for calls coming from specified jsonnet expression location.35 pub const fn new(loc: &'l Span) -> Self {36 Self(Some(loc))37 }38}39impl CallLocation<'static> {40 /// Construct new location for calls coming from native code.41 pub const fn native() -> Self {42 Self(None)43 }44}4546/// Represents Jsonnet function defined in code.47#[derive(Trace, Educe)]48#[educe(Debug, PartialEq)]49pub struct FuncDesc {50 /// # Example51 ///52 /// In expressions like this, deducted to `a`, unspecified otherwise.53 /// ```jsonnet54 /// local a = function() ...55 /// local a() ...56 /// { a: function() ... }57 /// { a() = ... }58 /// ```59 pub name: IStr,60 /// Context, in which this function was evaluated.61 ///62 /// # Example63 /// In64 /// ```jsonnet65 /// local a = 2;66 /// function() ...67 /// ```68 /// context will contain `a`.69 pub ctx: Context,7071 #[educe(PartialEq(method = Rc::ptr_eq))]72 pub func: Rc<LFunction>,73}7475impl FuncDesc {76 pub fn signature(&self) -> FunctionSignature {77 self.func.signature.clone()78 }7980 pub fn call(81 &self,82 unnamed: &[Thunk<Val>],83 named: &[Thunk<Val>],84 prepared: &PreparedCall,85 ) -> Result<Val> {86 let has_defaults = !prepared.defaults().is_empty();87 let mut builder = ContextBuilder::extend(self.ctx.clone(), self.func.params.len());8889 let fctx = Context::new_future();90 for (param_idx, thunk) in unnamed.iter().enumerate() {91 destruct(92 &self.func.params[param_idx].destruct,93 thunk.clone(),94 fctx.clone(),95 &mut builder,96 );97 }9899 for &(param_idx, arg_idx) in prepared.named() {100 destruct(101 &self.func.params[param_idx].destruct,102 named[arg_idx].clone(),103 fctx.clone(),104 &mut builder,105 );106 }107108 if has_defaults {109 for ¶m_idx in prepared.defaults() {110 let param = &self.func.params[param_idx];111 if let Some(default_expr) = ¶m.default {112 let default_expr = default_expr.clone();113 let fctxc = fctx.clone();114 let thunk = Thunk!(move || {115 let ctx = fctxc.unwrap();116 evaluate(ctx, &default_expr)117 });118 destruct(¶m.destruct, thunk, fctx.clone(), &mut builder);119 }120 }121 };122 let ctx = builder.build().into_future(fctx);123 ensure_sufficient_stack(|| evaluate(ctx, &self.func.body))124 }125126 pub fn evaluate_trivial(&self) -> Option<Val> {127 evaluate_trivial(&self.func.body)128 }129}130131/// Represents a Jsonnet function value, including plain functions and user-provided builtins.132#[allow(clippy::module_name_repetitions)]133#[derive(Trace, Clone)]134pub enum FuncVal {135 /// Plain function implemented in jsonnet.136 Normal(Cc<FuncDesc>),137 /// User-provided function.138 Builtin(BuiltinFunc),139}140141impl Debug for FuncVal {142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {143 match self {144 Self::Normal(arg0) => f.debug_tuple("Normal").field(arg0).finish(),145 Self::Builtin(arg0) => f.debug_tuple("Builtin").field(&arg0.name()).finish(),146 }147 }148}149150#[allow(clippy::unnecessary_wraps)]151#[builtin]152pub const fn builtin_id(x: Thunk<Val>) -> Thunk<Val> {153 x154}155156impl FuncVal {157 pub fn builtin(builtin: impl Builtin) -> Self {158 Self::Builtin(BuiltinFunc::new(builtin))159 }160161 pub fn params(&self) -> FunctionSignature {162 match self {163 Self::Builtin(i) => i.params(),164 Self::Normal(p) => p.signature(),165 }166 }167 /// Amount of non-default required arguments168 pub fn params_len(&self) -> u32 {169 self.params().iter().filter(|p| !p.has_default()).count() as u32170 }171 /// Function name, as defined in code.172 pub fn name(&self) -> IStr {173 match self {174 Self::Normal(normal) => normal.name.clone(),175 Self::Builtin(builtin) => builtin.name().into(),176 }177 }178179 pub(crate) fn evaluate_prepared(180 &self,181 prepared: &PreparedCall,182 loc: CallLocation<'_>,183 unnamed: &[Thunk<Val>],184 named: &[Thunk<Val>],185 _tailstrict: bool,186 ) -> Result<Val> {187 match self {188 FuncVal::Normal(func) => func.call(unnamed, named, prepared),189 FuncVal::Builtin(b) => {190 let args = parse_prepared_builtin_call(prepared, b.params(), unnamed, named);191 b.call(loc, &args)192 }193 }194 }195196 /// Is this function an identity function.197 ///198 /// Currently only works for builtin `std.id`, aka `Self::Id` value, and `function(x) x`.199 ///200 /// This function should only be used for optimization, not for the conditional logic, i.e code should work with syntetic identity function too201 pub fn is_identity(&self) -> bool {202 match self {203 Self::Builtin(b) => b.as_any().downcast_ref::<builtin_id>().is_some(),204 Self::Normal(desc) => {205 if desc.func.params.len() != 1 {206 return false;207 }208 let param = &desc.func.params[0];209 if param.default.is_some() {210 return false;211 }212 #[allow(irrefutable_let_patterns, reason = "refutable with exp-destruct")]213 let LDestruct::Full(id) = ¶m.destruct214 else {215 return false;216 };217 matches!(&*desc.func.body, LExpr::Local(v) if v == id)218 }219 }220 }221222 pub fn evaluate_trivial(&self) -> Option<Val> {223 match self {224 Self::Normal(n) => n.evaluate_trivial(),225 Self::Builtin(_) => None,226 }227 }228}229230impl<T> From<T> for FuncVal231where232 T: Builtin,233{234 fn from(value: T) -> Self {235 Self::builtin(value)236 }237}1use std::{fmt::Debug, rc::Rc};23use educe::Educe;4use jrsonnet_gcmodule::{Cc, Trace};5use jrsonnet_interner::IStr;6use jrsonnet_ir::Span;7pub use jrsonnet_macros::builtin;89use self::{10 builtin::Builtin,11 prepared::{PreparedCall, parse_prepared_builtin_call},12};13use crate::{14 Context, ContextBuilder, Result, Thunk, Val,15 analyze::{LDestruct, LExpr, LFunction},16 evaluate::{destructure::destruct, ensure_sufficient_stack, evaluate, evaluate_trivial},17 function::builtin::BuiltinFunc,18};1920pub mod builtin;21mod native;22mod parse;23pub(crate) mod prepared;2425pub use jrsonnet_ir::function::*;26pub use native::NativeFn;27pub(crate) use prepared::PreparedFuncVal;2829/// Function callsite location.30/// Either from other jsonnet code, specified by expression location, or from native (without location).31#[derive(Clone, Copy)]32pub struct CallLocation<'l>(pub Option<&'l Span>);33impl<'l> CallLocation<'l> {34 /// Construct new location for calls coming from specified jsonnet expression location.35 pub const fn new(loc: &'l Span) -> Self {36 Self(Some(loc))37 }38}39impl CallLocation<'static> {40 /// Construct new location for calls coming from native code.41 pub const fn native() -> Self {42 Self(None)43 }44}4546/// Represents Jsonnet function defined in code.47#[derive(Trace, Educe)]48#[educe(Debug, PartialEq)]49pub struct FuncDesc {50 /// # Example51 ///52 /// In expressions like this, deducted to `a`, unspecified otherwise.53 /// ```jsonnet54 /// local a = function() ...55 /// local a() ...56 /// { a: function() ... }57 /// { a() = ... }58 /// ```59 pub name: IStr,60 /// Context, in which this function was evaluated.61 ///62 /// # Example63 /// In64 /// ```jsonnet65 /// local a = 2;66 /// function() ...67 /// ```68 /// context will contain `a`.69 pub ctx: Context,7071 #[educe(PartialEq(method = Rc::ptr_eq))]72 pub func: Rc<LFunction>,73}7475impl FuncDesc {76 pub fn signature(&self) -> FunctionSignature {77 self.func.signature.clone()78 }7980 pub fn call(81 &self,82 unnamed: &[Thunk<Val>],83 named: &[Thunk<Val>],84 prepared: &PreparedCall,85 ) -> Result<Val> {86 let has_defaults = !prepared.defaults().is_empty();87 let mut builder = ContextBuilder::extend(self.ctx.clone(), self.func.params.len());8889 let fctx = Context::new_future();90 for (param_idx, thunk) in unnamed.iter().enumerate() {91 destruct(92 &self.func.params[param_idx].destruct,93 thunk.clone(),94 fctx.clone(),95 &mut builder,96 );97 }9899 for &(param_idx, arg_idx) in prepared.named() {100 destruct(101 &self.func.params[param_idx].destruct,102 named[arg_idx].clone(),103 fctx.clone(),104 &mut builder,105 );106 }107108 if has_defaults {109 for ¶m_idx in prepared.defaults() {110 let param = &self.func.params[param_idx];111 if let Some(default_expr) = ¶m.default {112 let default_expr = default_expr.clone();113 let fctxc = fctx.clone();114 let thunk = Thunk!(move || {115 let ctx = fctxc.unwrap();116 evaluate(ctx, &default_expr)117 });118 destruct(¶m.destruct, thunk, fctx.clone(), &mut builder);119 }120 }121 };122 let ctx = builder.build().into_future(fctx);123 ensure_sufficient_stack(|| evaluate(ctx, &self.func.body))124 }125126 pub fn evaluate_trivial(&self) -> Option<Val> {127 evaluate_trivial(&self.func.body)128 }129}130131/// Represents a Jsonnet function value, including plain functions and user-provided builtins.132#[allow(clippy::module_name_repetitions)]133#[derive(Trace, Clone)]134pub enum FuncVal {135 /// Plain function implemented in jsonnet.136 Normal(Cc<FuncDesc>),137 /// User-provided function.138 Builtin(BuiltinFunc),139}140141impl Debug for FuncVal {142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {143 match self {144 Self::Normal(arg0) => f.debug_tuple("Normal").field(arg0).finish(),145 Self::Builtin(arg0) => f.debug_tuple("Builtin").field(&arg0.name()).finish(),146 }147 }148}149150#[allow(clippy::unnecessary_wraps)]151#[builtin]152pub const fn builtin_id(x: Thunk<Val>) -> Thunk<Val> {153 x154}155156impl FuncVal {157 pub fn builtin(builtin: impl Builtin) -> Self {158 Self::Builtin(BuiltinFunc::new(builtin))159 }160161 pub fn params(&self) -> FunctionSignature {162 match self {163 Self::Builtin(i) => i.params(),164 Self::Normal(p) => p.signature(),165 }166 }167 /// Amount of non-default required arguments168 pub fn params_len(&self) -> u32 {169 self.params().iter().filter(|p| !p.has_default()).count() as u32170 }171 /// Function name, as defined in code.172 pub fn name(&self) -> IStr {173 match self {174 Self::Normal(normal) => normal.name.clone(),175 Self::Builtin(builtin) => builtin.name().into(),176 }177 }178179 pub(crate) fn evaluate_prepared(180 &self,181 prepared: &PreparedCall,182 loc: CallLocation<'_>,183 unnamed: &[Thunk<Val>],184 named: &[Thunk<Val>],185 _tailstrict: bool,186 ) -> Result<Val> {187 match self {188 FuncVal::Normal(func) => func.call(unnamed, named, prepared),189 FuncVal::Builtin(b) => {190 let args = parse_prepared_builtin_call(prepared, b.params(), unnamed, named);191 b.call(loc, &args)192 }193 }194 }195196 /// Is this function an identity function.197 ///198 /// Currently only works for builtin `std.id`, aka `Self::Id` value, and `function(x) x`.199 ///200 /// This function should only be used for optimization, not for the conditional logic, i.e code should work with syntetic identity function too201 pub fn is_identity(&self) -> bool {202 match self {203 Self::Builtin(b) => b.as_any().downcast_ref::<builtin_id>().is_some(),204 Self::Normal(desc) => {205 if desc.func.params.len() != 1 {206 return false;207 }208 let param = &desc.func.params[0];209 if param.default.is_some() {210 return false;211 }212 #[allow(irrefutable_let_patterns, reason = "refutable with exp-destruct")]213 let LDestruct::Full(id) = ¶m.destruct else {214 return false;215 };216 matches!(&*desc.func.body, LExpr::Local(v) if v == id)217 }218 }219 }220221 pub fn evaluate_trivial(&self) -> Option<Val> {222 match self {223 Self::Normal(n) => n.evaluate_trivial(),224 Self::Builtin(_) => None,225 }226 }227}228229impl<T> From<T> for FuncVal230where231 T: Builtin,232{233 fn from(value: T) -> Self {234 Self::builtin(value)235 }236}crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -1,9 +1,9 @@
use std::rc::Rc;
use crate::{
+ Context, ContextBuilder, Result, Thunk,
analyze::LFunction,
evaluate::{destructure::destruct, evaluate},
- Context, ContextBuilder, Result, Thunk,
};
/// Creates Context with all argument default values applied
crates/jrsonnet-evaluator/src/function/prepared.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/prepared.rs
+++ b/crates/jrsonnet-evaluator/src/function/prepared.rs
@@ -5,10 +5,7 @@
use rustc_hash::FxHashSet;
use super::{CallLocation, FuncVal};
-use crate::{
- Result, Thunk, Val, bail,
- error::ErrorKind::*,
-};
+use crate::{Result, Thunk, Val, bail, error::ErrorKind::*};
#[derive(Debug, Trace, Clone)]
pub struct PreparedFuncVal {
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -3,16 +3,16 @@
use jrsonnet_interner::{IBytes, IStr};
use jrsonnet_ir::NumValue;
use serde::{
+ Deserialize, Serialize, Serializer,
de::{self, Visitor},
ser::{
Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant, SerializeTuple,
SerializeTupleStruct, SerializeTupleVariant,
},
- Deserialize, Serialize, Serializer,
};
use crate::{
- in_description_frame, runtime_error, Error as JrError, ObjValue, ObjValueBuilder, Result, Val,
+ Error as JrError, ObjValue, ObjValueBuilder, Result, Val, in_description_frame, runtime_error,
};
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
@@ -39,7 +39,7 @@
pub use evaluate::ensure_sufficient_stack;
use function::CallLocation;
pub use import::*;
-use jrsonnet_gcmodule::{cc_dyn, Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};
pub use jrsonnet_interner::{IBytes, IStr};
use jrsonnet_ir::Expr;
pub use jrsonnet_ir::{NumValue, Source, SourcePath, Span};
crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -1,8 +1,7 @@
use std::{borrow::Cow, fmt::Write, hint::black_box, ptr};
use crate::{
- bail, evaluate::ensure_sufficient_stack, in_description_frame, Error,
- Result, ResultExt, Val,
+ Error, Result, ResultExt, Val, bail, evaluate::ensure_sufficient_stack, in_description_frame,
};
pub trait ManifestFormat {
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -11,8 +11,8 @@
};
use educe::Educe;
-use im_rc::{vector, Vector};
-use jrsonnet_gcmodule::{cc_dyn, Acyclic, Cc, Trace, Weak};
+use im_rc::{Vector, vector};
+use jrsonnet_gcmodule::{Acyclic, Cc, Trace, Weak, cc_dyn};
use jrsonnet_interner::IStr;
use jrsonnet_ir::Span;
use rustc_hash::{FxHashMap, FxHashSet};
@@ -23,13 +23,13 @@
pub use oop::ObjValueBuilder;
use crate::{
+ CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
arr::{PickObjectKeyValues, PickObjectValues},
bail,
- error::{suggest_object_fields, ErrorKind::*},
+ error::{ErrorKind::*, suggest_object_fields},
evaluate::operator::evaluate_add_op,
identity_hash,
val::{ArrValue, ThunkValue},
- CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
};
#[cfg(not(feature = "exp-preserve-order"))]
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -10,7 +10,7 @@
#[cfg(feature = "explaining-traces")]
use jrsonnet_ir::Span;
-use crate::{error::ErrorKind, Error};
+use crate::{Error, error::ErrorKind};
/// The way paths should be displayed
#[derive(Clone, Trace)]
@@ -259,7 +259,7 @@
struct ResetData {
loc: Span,
}
- use hi_doc::{source_to_ansi, Formatting, SnippetBuilder, Text};
+ use hi_doc::{Formatting, SnippetBuilder, Text, source_to_ansi};
write!(out, "{}", error.error())?;
if let ErrorKind::ImportSyntaxError { path, error } = error.error() {
@@ -277,14 +277,15 @@
use crate::analyze::DiagLevel;
let mut builder: Option<SnippetBuilder> = None;
let mut current_src: Option<&str> = None;
- let flush =
- |builder: Option<SnippetBuilder>, out: &mut dyn std::fmt::Write| -> Result<(), std::fmt::Error> {
- if let Some(b) = builder {
- let ansi = source_to_ansi(&b.build());
- write!(out, "\n{}", ansi.trim_end())?;
- }
- Ok(())
- };
+ let flush = |builder: Option<SnippetBuilder>,
+ out: &mut dyn std::fmt::Write|
+ -> Result<(), std::fmt::Error> {
+ if let Some(b) = builder {
+ let ansi = source_to_ansi(&b.build());
+ write!(out, "\n{}", ansi.trim_end())?;
+ }
+ Ok(())
+ };
for diag in diagnostics {
if let Some(span) = &diag.span {
let src = span.0.code();
@@ -295,14 +296,12 @@
}
let b = builder.as_mut().unwrap();
let ab = match diag.level {
- DiagLevel::Error => b.error(Text::fragment(
- diag.message.clone(),
- Formatting::default(),
- )),
- DiagLevel::Warning => b.warning(Text::fragment(
- diag.message.clone(),
- Formatting::default(),
- )),
+ DiagLevel::Error => {
+ b.error(Text::fragment(diag.message.clone(), Formatting::default()))
+ }
+ DiagLevel::Warning => {
+ b.warning(Text::fragment(diag.message.clone(), Formatting::default()))
+ }
};
ab.range(span.range()).build();
} else {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -17,7 +17,13 @@
pub use crate::arr::{ArrValue, ArrayLike};
use crate::{
- NumValue, ObjValue, Result, SupThis, Unbound, WeakSupThis, bail, error::{Error, ErrorKind::*}, evaluate::operator::{evaluate_compare_op, evaluate_mod_op}, function::FuncVal, gc::WithCapacityExt as _, manifest::{ManifestFormat, ToStringFormat}, typed::BoundedUsize
+ NumValue, ObjValue, Result, SupThis, Unbound, WeakSupThis, bail,
+ error::{Error, ErrorKind::*},
+ evaluate::operator::{evaluate_compare_op, evaluate_mod_op},
+ function::FuncVal,
+ gc::WithCapacityExt as _,
+ manifest::{ManifestFormat, ToStringFormat},
+ typed::BoundedUsize,
};
pub trait ThunkValue: Trace {
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -1,11 +1,11 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_ir::{
- unescape, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec,
- Destruct, Expr, ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse,
- IfSpecData, ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers,
- Slice, SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility,
+ ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
+ ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,
+ ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
+ SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility, unescape,
};
-use jrsonnet_lexer::{collect_lexed_str_block, Lexeme, Lexer, Span as LexSpan, SyntaxKind, T};
+use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};
pub struct ParserSettings {
pub source: Source,
crates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/expr.rs
+++ b/crates/jrsonnet-ir/src/expr.rs
@@ -7,9 +7,9 @@
use jrsonnet_interner::IStr;
use crate::{
+ NumValue,
function::{FunctionSignature, ParamDefault, ParamName, ParamParse},
source::Source,
- NumValue,
};
#[derive(Debug, PartialEq, Acyclic)]
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -3,14 +3,13 @@
use proc_macro2::TokenStream;
use quote::{quote, quote_spanned};
use syn::{
- parenthesized,
+ Attribute, DeriveInput, Error, Expr, ExprClosure, FnArg, GenericArgument, Ident, ItemFn,
+ LitStr, Meta, Pat, Path, PathArguments, Result, ReturnType, Token, Type, parenthesized,
parse::{Parse, ParseStream},
parse_macro_input,
punctuated::Punctuated,
spanned::Spanned,
token::Comma,
- Attribute, DeriveInput, Error, Expr, ExprClosure, FnArg, GenericArgument, Ident, ItemFn,
- LitStr, Meta, Pat, Path, PathArguments, Result, ReturnType, Token, Type,
};
use self::typed::{derive_from_untyped_inner, derive_into_untyped_inner, derive_typed_inner};
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -1,12 +1,11 @@
#![allow(non_snake_case)]
use jrsonnet_evaluator::{
- bail, error,
- function::{builtin, NativeFn},
+ Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,
+ function::{NativeFn, builtin},
runtime_error,
typed::{BoundedUsize, Either2, FromUntyped},
- val::{equals, ArrValue, IndexableVal},
- Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,
+ val::{ArrValue, IndexableVal, equals},
};
pub fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {
crates/jrsonnet-stdlib/src/compat.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/compat.rs
+++ b/crates/jrsonnet-stdlib/src/compat.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
-use jrsonnet_evaluator::{function::builtin, val::ArrValue, Result, Val};
+use jrsonnet_evaluator::{Result, Val, function::builtin, val::ArrValue};
#[builtin]
#[allow(non_snake_case)]
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -12,7 +12,12 @@
pub use encoding::*;
pub use hash::*;
use jrsonnet_evaluator::{
- IStr, InitialContextBuilder, NumValue, ObjValue, ObjValueBuilder, Source, Thunk, Val, error::Result, function::{CallLocation, FuncVal, builtin_id}, tla::TlaArg, trace::PathResolver, typed::SerializeTypedObj as _
+ IStr, InitialContextBuilder, NumValue, ObjValue, ObjValueBuilder, Source, Thunk, Val,
+ error::Result,
+ function::{CallLocation, FuncVal, builtin_id},
+ tla::TlaArg,
+ trace::PathResolver,
+ typed::SerializeTypedObj as _,
};
use jrsonnet_gcmodule::{Acyclic, Cc, Trace};
use jrsonnet_macros::{IntoUntyped, Typed};
crates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -1,7 +1,10 @@
use std::borrow::Cow;
use jrsonnet_evaluator::{
- Error, IStr, ObjValue, Result, ResultExt, Val, bail, ensure_sufficient_stack, in_description_frame, manifest::{ManifestFormat, escape_string_json_buf}, val::ArrValue
+ Error, IStr, ObjValue, Result, ResultExt, Val, bail, ensure_sufficient_stack,
+ in_description_frame,
+ manifest::{ManifestFormat, escape_string_json_buf},
+ val::ArrValue,
};
pub struct TomlFormat<'s> {
@@ -218,14 +221,16 @@
}
first = false;
path.push(k.clone());
- ensure_sufficient_stack(|| in_description_frame(
- || format!("section <{k}> manifestification"),
- || match v {
- Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),
- Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),
- _ => unreachable!("iterating over sections"),
- },
- ))?;
+ ensure_sufficient_stack(|| {
+ in_description_frame(
+ || format!("section <{k}> manifestification"),
+ || match v {
+ Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),
+ Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),
+ _ => unreachable!("iterating over sections"),
+ },
+ )
+ })?;
path.pop();
}
Ok(())
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -1,13 +1,12 @@
use std::{cell::RefCell, collections::BTreeSet};
use jrsonnet_evaluator::{
- bail,
+ Either, IStr, ObjValue, ObjValueBuilder, ResultExt, Thunk, Val, bail,
error::{ErrorKind::*, Result},
- function::{builtin, CallLocation, FuncVal},
+ function::{CallLocation, FuncVal, builtin},
manifest::JsonFormat,
typed::{Either2, Either4},
- val::{equals, ArrValue},
- Either, IStr, ObjValue, ObjValueBuilder, ResultExt, Thunk, Val,
+ val::{ArrValue, equals},
};
use jrsonnet_gcmodule::Cc;
crates/jrsonnet-stdlib/src/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/operator.rs
+++ b/crates/jrsonnet-stdlib/src/operator.rs
@@ -2,11 +2,11 @@
//! 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, NumValue, Result, Val,
function::builtin,
stdlib::std_format,
typed::{Either, Either2},
val::{equals, primitive_equals},
- IStr, NumValue, Result, Val,
};
#[builtin]
crates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sets.rs
+++ b/crates/jrsonnet-stdlib/src/sets.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
-use jrsonnet_evaluator::{function::builtin, val::ArrValue, Result, Thunk, Val};
+use jrsonnet_evaluator::{Result, Thunk, Val, function::builtin, val::ArrValue};
use crate::keyf::KeyF;
crates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -3,10 +3,9 @@
use std::cmp::Ordering;
use jrsonnet_evaluator::{
- bail,
+ Result, Thunk, Val, bail,
function::builtin,
- val::{equals, ArrValue},
- Result, Thunk, Val,
+ val::{ArrValue, equals},
};
use crate::{eval_on_empty, keyf::KeyF};
tests/tests/builtin.rsdiffbeforeafterboth--- a/tests/tests/builtin.rs
+++ b/tests/tests/builtin.rs
@@ -1,7 +1,11 @@
mod common;
use jrsonnet_evaluator::{
- ContextInitializer, FileImportResolver, InitialContextBuilder, Result, Source, State, Thunk, Val, function::{CallLocation, FuncVal, builtin, builtin::{Builtin}}, trace::PathResolver, typed::FromUntyped
+ ContextInitializer, FileImportResolver, InitialContextBuilder, Result, Source, State, Thunk,
+ Val,
+ function::{CallLocation, FuncVal, builtin, builtin::Builtin},
+ trace::PathResolver,
+ typed::FromUntyped,
};
use jrsonnet_gcmodule::Trace;
use jrsonnet_stdlib::ContextInitializer as StdContextInitializer;
tests/tests/common.rsdiffbeforeafterboth--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -1,5 +1,7 @@
use jrsonnet_evaluator::{
- ContextBuilder, ContextInitializer as ContextInitializerT, InitialContextBuilder, ObjValueBuilder, Result, Thunk, Val, bail, function::{FuncVal, builtin}, Source
+ ContextBuilder, ContextInitializer as ContextInitializerT, InitialContextBuilder,
+ ObjValueBuilder, Result, Source, Thunk, Val, bail,
+ function::{FuncVal, builtin},
};
use jrsonnet_gcmodule::Trace;