difftreelog
style enforce import style
in: master
38 files changed
.rustfmt.tomldiffbeforeafterboth--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -1 +1,3 @@
hard_tabs = true
+imports_granularity = "crate"
+group_imports = "stdexternalcrate"
bindings/jsonnet/src/import.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -1,9 +1,5 @@
//! Import resolution manipulation utilities
-use jrsonnet_evaluator::{
- error::{Error::*, Result},
- throw, EvaluationState, ImportResolver,
-};
use std::{
any::Any,
cell::RefCell,
@@ -17,6 +13,11 @@
rc::Rc,
};
+use jrsonnet_evaluator::{
+ error::{Error::*, Result},
+ throw, EvaluationState, ImportResolver,
+};
+
pub type JsonnetImportCallback = unsafe extern "C" fn(
ctx: *mut c_void,
base: *const c_char,
bindings/jsonnet/src/interop.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/interop.rs
+++ b/bindings/jsonnet/src/interop.rs
@@ -1,12 +1,14 @@
//! Jrsonnet specific additional binding helpers
-use crate::{import::jsonnet_import_callback, native::jsonnet_native_callback};
-use jrsonnet_evaluator::{EvaluationState, Val};
use std::{
ffi::c_void,
os::raw::{c_char, c_int},
};
+use jrsonnet_evaluator::{EvaluationState, Val};
+
+use crate::{import::jsonnet_import_callback, native::jsonnet_native_callback};
+
extern "C" {
pub fn _jrsonnet_static_import_callback(
ctx: *mut c_void,
bindings/jsonnet/src/lib.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -8,8 +8,6 @@
pub mod val_modify;
pub mod vars_tlas;
-use import::NativeImportResolver;
-use jrsonnet_evaluator::{EvaluationState, IStr, ManifestFormat, Val};
use std::{
alloc::Layout,
ffi::{CStr, CString},
@@ -17,6 +15,9 @@
path::PathBuf,
};
+use import::NativeImportResolver;
+use jrsonnet_evaluator::{EvaluationState, IStr, ManifestFormat, Val};
+
/// WASM stub
#[cfg(target_arch = "wasm32")]
#[no_mangle]
bindings/jsonnet/src/native.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -1,3 +1,11 @@
+use std::{
+ convert::TryFrom,
+ ffi::{c_void, CStr},
+ os::raw::{c_char, c_int},
+ path::Path,
+ rc::Rc,
+};
+
use gcmodule::Cc;
use jrsonnet_evaluator::{
error::{Error, LocError},
@@ -5,13 +13,6 @@
gc::TraceBox,
native::{NativeCallback, NativeCallbackHandler},
EvaluationState, IStr, Val,
-};
-use std::{
- convert::TryFrom,
- ffi::{c_void, CStr},
- os::raw::{c_char, c_int},
- path::Path,
- rc::Rc,
};
type JsonnetNativeCallback = unsafe extern "C" fn(
bindings/jsonnet/src/val_extract.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_extract.rs
+++ b/bindings/jsonnet/src/val_extract.rs
@@ -1,12 +1,12 @@
//! Extract values from VM
-use jrsonnet_evaluator::{EvaluationState, Val};
-
use std::{
ffi::CString,
os::raw::{c_char, c_double, c_int},
};
+use jrsonnet_evaluator::{EvaluationState, Val};
+
#[no_mangle]
pub extern "C" fn jsonnet_json_extract_string(_vm: &EvaluationState, v: &Val) -> *mut c_char {
match v {
bindings/jsonnet/src/val_make.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -1,12 +1,13 @@
//! Create values in VM
-use gcmodule::Cc;
-use jrsonnet_evaluator::{ArrValue, EvaluationState, ObjValue, Val};
use std::{
ffi::CStr,
os::raw::{c_char, c_double, c_int},
};
+use gcmodule::Cc;
+use jrsonnet_evaluator::{val::ArrValue, EvaluationState, ObjValue, Val};
+
/// # Safety
///
/// This function is safe, if received v is a pointer to normal C string
bindings/jsonnet/src/val_modify.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -2,10 +2,11 @@
//! Only tested with variables, which haven't altered by code before appearing here
//! In jrsonnet every value is immutable, and this code is probally broken
+use std::{ffi::CStr, os::raw::c_char};
+
use gcmodule::Cc;
-use jrsonnet_evaluator::{ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
+use jrsonnet_evaluator::{val::ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
use jrsonnet_parser::Visibility;
-use std::{ffi::CStr, os::raw::c_char};
/// # Safety
///
bindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/vars_tlas.rs
+++ b/bindings/jsonnet/src/vars_tlas.rs
@@ -1,8 +1,9 @@
//! Manipulate external variables and top level arguments
-use jrsonnet_evaluator::EvaluationState;
use std::{ffi::CStr, os::raw::c_char};
+use jrsonnet_evaluator::EvaluationState;
+
/// # Safety
#[no_mangle]
pub unsafe extern "C" fn jsonnet_ext_var(
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -1,13 +1,13 @@
+use std::{
+ fs::{create_dir_all, File},
+ io::{Read, Write},
+ path::PathBuf,
+};
+
use clap::{AppSettings, IntoApp, Parser};
use clap_complete::Shell;
use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};
use jrsonnet_evaluator::{error::LocError, EvaluationState};
-use std::{
- fs::{create_dir_all, File},
- io::Read,
- io::Write,
- path::PathBuf,
-};
#[cfg(feature = "mimalloc")]
#[global_allocator]
crates/jrsonnet-cli/src/ext.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/ext.rs
+++ b/crates/jrsonnet-cli/src/ext.rs
@@ -1,8 +1,10 @@
-use crate::ConfigureState;
+use std::{fs::read_to_string, str::FromStr};
+
use clap::Parser;
use jrsonnet_evaluator::{error::Result, EvaluationState};
-use std::{fs::read_to_string, str::FromStr};
+use crate::ConfigureState;
+
#[derive(Clone)]
pub struct ExtStr {
pub name: String,
crates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -3,14 +3,14 @@
mod tla;
mod trace;
+use std::{env, path::PathBuf};
+
+use clap::Parser;
pub use ext::*;
+use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
pub use manifest::*;
pub use tla::*;
pub use trace::*;
-
-use clap::Parser;
-use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
-use std::{env, path::PathBuf};
pub trait ConfigureState {
fn configure(&self, state: &EvaluationState) -> Result<()>;
crates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -1,8 +1,10 @@
-use crate::ConfigureState;
+use std::{path::PathBuf, str::FromStr};
+
use clap::Parser;
use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};
-use std::{path::PathBuf, str::FromStr};
+use crate::ConfigureState;
+
pub enum ManifestFormatName {
/// Expect string as output, and write them directly
String,
crates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -1,7 +1,8 @@
-use crate::{ConfigureState, ExtFile, ExtStr};
use clap::Parser;
use jrsonnet_evaluator::{error::Result, EvaluationState};
+use crate::{ConfigureState, ExtFile, ExtStr};
+
#[derive(Parser)]
#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]
pub struct TLAOpts {
crates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -1,12 +1,14 @@
-use crate::ConfigureState;
+use std::str::FromStr;
+
use clap::Parser;
use jrsonnet_evaluator::{
error::Result,
trace::{CompactFormat, ExplainingFormat, PathResolver},
EvaluationState,
};
-use std::str::FromStr;
+use crate::ConfigureState;
+
#[derive(PartialEq)]
pub enum TraceFormatName {
Compact,
crates/jrsonnet-evaluator/build.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/build.rs
+++ b/crates/jrsonnet-evaluator/build.rs
@@ -1,6 +1,3 @@
-use bincode::serialize;
-use jrsonnet_parser::{parse, ParserSettings};
-use jrsonnet_stdlib::STDLIB_STR;
use std::{
env,
fs::File,
@@ -8,6 +5,10 @@
path::{Path, PathBuf},
};
+use bincode::serialize;
+use jrsonnet_parser::{parse, ParserSettings};
+use jrsonnet_stdlib::STDLIB_STR;
+
fn main() {
let parsed = parse(
STDLIB_STR,
crates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/format.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/format.rs
@@ -1,13 +1,15 @@
//! faster std.format impl
#![allow(clippy::too_many_arguments)]
-use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
+use std::convert::TryFrom;
+
use gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_types::ValType;
-use std::convert::TryFrom;
use thiserror::Error;
+use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
+
#[derive(Debug, Clone, Error, Trace)]
pub enum FormatError {
#[error("truncated format code")]
crates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -1,7 +1,7 @@
-use crate::error::Error::*;
-use crate::error::Result;
-use crate::push_description_frame;
-use crate::{throw, Val};
+use crate::{
+ error::{Error::*, Result},
+ push_description_frame, throw, Val,
+};
#[derive(PartialEq, Clone, Copy)]
pub enum ManifestType {
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,23 +1,25 @@
-use crate::function::{CallLocation, StaticBuiltin};
-use crate::typed::{Any, Bytes, PositiveF64, VecVal, M1};
-use crate::{
- builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},
- equals,
- error::{Error::*, Result},
- operator::evaluate_mod_op,
- primitive_equals, push_frame, throw,
- typed::{Either2, Either4},
- with_state, ArrValue, FuncVal, IndexableVal, Val,
+use std::{
+ collections::HashMap,
+ convert::{TryFrom, TryInto},
};
-use crate::{Either, ObjValue};
+
use format::{format_arr, format_obj};
use gcmodule::Cc;
use jrsonnet_interner::IStr;
use serde::Deserialize;
use serde_yaml::DeserializingQuirks;
-use std::collections::HashMap;
-use std::convert::{TryFrom, TryInto};
+use crate::{
+ builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},
+ error::{Error::*, Result},
+ function::{CallLocation, StaticBuiltin},
+ operator::evaluate_mod_op,
+ push_frame, throw,
+ typed::{Any, BoundedUsize, Bytes, Either2, Either4, PositiveF64, VecVal, M1},
+ val::{equals, primitive_equals, ArrValue, FuncVal, IndexableVal, Slice},
+ with_state, Either, ObjValue, Val,
+};
+
pub mod stdlib;
pub use stdlib::*;
@@ -58,12 +60,12 @@
}
Ok(Val::Str(
- (s.chars()
- .skip(index)
- .take(end - index)
- .step_by(step)
- .collect::<String>())
- .into(),
+ (s.chars()
+ .skip(index)
+ .take(end - index)
+ .step_by(step)
+ .collect::<String>())
+ .into(),
))
}
IndexableVal::Arr(arr) => {
crates/jrsonnet-evaluator/src/builtin/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/sort.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/sort.rs
@@ -1,10 +1,12 @@
+use gcmodule::{Cc, Trace};
+
use crate::{
error::{Error, LocError, Result},
throw,
typed::Any,
- FuncVal, Val,
+ val::FuncVal,
+ Val,
};
-use gcmodule::{Cc, Trace};
#[derive(Debug, Clone, thiserror::Error, Trace)]
pub enum SortError {
crates/jrsonnet-evaluator/src/builtin/stdlib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
@@ -1,6 +1,7 @@
-use jrsonnet_parser::{LocExpr, ParserSettings};
use std::path::PathBuf;
+use jrsonnet_parser::{LocExpr, ParserSettings};
+
thread_local! {
/// To avoid parsing again when issued from the same thread
#[allow(unreachable_code)]
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -1,12 +1,12 @@
-use crate::cc_ptr_eq;
-use crate::gc::GcHashMap;
+use std::fmt::Debug;
+
+use gcmodule::{Cc, Trace};
+use jrsonnet_interner::IStr;
+
use crate::{
- error::Error::*, map::LayeredHashMap, FutureWrapper, LazyBinding, LazyVal, ObjValue, Result,
- Val,
+ cc_ptr_eq, error::Error::*, gc::GcHashMap, map::LayeredHashMap, FutureWrapper, LazyBinding,
+ LazyVal, ObjValue, Result, Val,
};
-use gcmodule::{Cc, Trace};
-use jrsonnet_interner::IStr;
-use std::fmt::Debug;
#[derive(Clone, Trace)]
pub struct ContextCreator(pub Context, pub FutureWrapper<GcHashMap<IStr, LazyBinding>>);
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -1,16 +1,18 @@
-use crate::{
- builtin::{format::FormatError, sort::SortError},
- typed::TypeLocError,
+use std::{
+ path::{Path, PathBuf},
+ rc::Rc,
};
+
use gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
use jrsonnet_types::ValType;
-use std::{
- path::{Path, PathBuf},
- rc::Rc,
+use thiserror::Error;
+
+use crate::{
+ builtin::{format::FormatError, sort::SortError},
+ typed::TypeLocError,
};
-use thiserror::Error;
#[derive(Error, Debug, Clone, Trace)]
pub enum Error {
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth1use std::convert::TryFrom;23use crate::{4 builtin::{std_slice, BUILTINS},5 error::Error::*,6 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},7 function::CallLocation,8 gc::TraceBox,9 push_frame, throw, with_state, ArrValue, Bindable, Context, ContextCreator, FuncDesc, FuncVal,10 FutureWrapper, GcHashMap, LazyBinding, LazyVal, LazyValValue, ObjValue, ObjValueBuilder,11 ObjectAssertion, Result, Val,12};13use gcmodule::{Cc, Trace};14use jrsonnet_interner::IStr;15use jrsonnet_parser::{16 ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, ForSpecData, IfSpecData,17 LiteralType, LocExpr, Member, ObjBody, ParamsDesc,18};19use jrsonnet_types::ValType;20pub mod operator;2122pub fn evaluate_binding_in_future(23 b: &BindSpec,24 context_creator: FutureWrapper<Context>,25) -> LazyVal {26 let b = b.clone();27 if let Some(params) = &b.params {28 let params = params.clone();2930 #[derive(Trace)]31 struct LazyMethodBinding {32 context_creator: FutureWrapper<Context>,33 name: IStr,34 params: ParamsDesc,35 value: LocExpr,36 }37 impl LazyValValue for LazyMethodBinding {38 fn get(self: Box<Self>) -> Result<Val> {39 Ok(evaluate_method(40 self.context_creator.unwrap(),41 self.name,42 self.params,43 self.value,44 ))45 }46 }4748 LazyVal::new(TraceBox(Box::new(LazyMethodBinding {49 context_creator,50 name: b.name.clone(),51 params,52 value: b.value.clone(),53 })))54 } else {55 #[derive(Trace)]56 struct LazyNamedBinding {57 context_creator: FutureWrapper<Context>,58 name: IStr,59 value: LocExpr,60 }61 impl LazyValValue for LazyNamedBinding {62 fn get(self: Box<Self>) -> Result<Val> {63 evaluate_named(self.context_creator.unwrap(), &self.value, self.name)64 }65 }66 LazyVal::new(TraceBox(Box::new(LazyNamedBinding {67 context_creator,68 name: b.name.clone(),69 value: b.value,70 })))71 }72}7374pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (IStr, LazyBinding) {75 let b = b.clone();76 if let Some(params) = &b.params {77 let params = params.clone();7879 #[derive(Trace)]80 struct BindableMethodLazyVal {81 this: Option<ObjValue>,82 super_obj: Option<ObjValue>,8384 context_creator: ContextCreator,85 name: IStr,86 params: ParamsDesc,87 value: LocExpr,88 }89 impl LazyValValue for BindableMethodLazyVal {90 fn get(self: Box<Self>) -> Result<Val> {91 Ok(evaluate_method(92 self.context_creator.create(self.this, self.super_obj)?,93 self.name,94 self.params,95 self.value,96 ))97 }98 }99100 #[derive(Trace)]101 struct BindableMethod {102 context_creator: ContextCreator,103 name: IStr,104 params: ParamsDesc,105 value: LocExpr,106 }107 impl Bindable for BindableMethod {108 fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {109 Ok(LazyVal::new(TraceBox(Box::new(BindableMethodLazyVal {110 this,111 super_obj,112113 context_creator: self.context_creator.clone(),114 name: self.name.clone(),115 params: self.params.clone(),116 value: self.value.clone(),117 }))))118 }119 }120121 (122 b.name.clone(),123 LazyBinding::Bindable(Cc::new(TraceBox(Box::new(BindableMethod {124 context_creator,125 name: b.name.clone(),126 params,127 value: b.value.clone(),128 })))),129 )130 } else {131 #[derive(Trace)]132 struct BindableNamedLazyVal {133 this: Option<ObjValue>,134 super_obj: Option<ObjValue>,135136 context_creator: ContextCreator,137 name: IStr,138 value: LocExpr,139 }140 impl LazyValValue for BindableNamedLazyVal {141 fn get(self: Box<Self>) -> Result<Val> {142 evaluate_named(143 self.context_creator.create(self.this, self.super_obj)?,144 &self.value,145 self.name,146 )147 }148 }149150 #[derive(Trace)]151 struct BindableNamed {152 context_creator: ContextCreator,153 name: IStr,154 value: LocExpr,155 }156 impl Bindable for BindableNamed {157 fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {158 Ok(LazyVal::new(TraceBox(Box::new(BindableNamedLazyVal {159 this,160 super_obj,161162 context_creator: self.context_creator.clone(),163 name: self.name.clone(),164 value: self.value.clone(),165 }))))166 }167 }168169 (170 b.name.clone(),171 LazyBinding::Bindable(Cc::new(TraceBox(Box::new(BindableNamed {172 context_creator,173 name: b.name.clone(),174 value: b.value.clone(),175 })))),176 )177 }178}179180pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {181 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {182 name,183 ctx,184 params,185 body,186 })))187}188189pub fn evaluate_field_name(190 context: Context,191 field_name: &jrsonnet_parser::FieldName,192) -> Result<Option<IStr>> {193 Ok(match field_name {194 jrsonnet_parser::FieldName::Fixed(n) => Some(n.clone()),195 jrsonnet_parser::FieldName::Dyn(expr) => push_frame(196 CallLocation::new(&expr.1),197 || "evaluating field name".to_string(),198 || {199 let value = evaluate(context, expr)?;200 if matches!(value, Val::Null) {201 Ok(None)202 } else {203 Ok(Some(IStr::try_from(value)?))204 }205 },206 )?,207 })208}209210pub fn evaluate_comp(211 context: Context,212 specs: &[CompSpec],213 callback: &mut impl FnMut(Context) -> Result<()>,214) -> Result<()> {215 match specs.get(0) {216 None => callback(context)?,217 Some(CompSpec::IfSpec(IfSpecData(cond))) => {218 if bool::try_from(evaluate(context.clone(), cond)?)? {219 evaluate_comp(context, &specs[1..], callback)?220 }221 }222 Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(context.clone(), expr)? {223 Val::Arr(list) => {224 for item in list.iter() {225 evaluate_comp(226 context.clone().with_var(var.clone(), item?.clone()),227 &specs[1..],228 callback,229 )?230 }231 }232 _ => throw!(InComprehensionCanOnlyIterateOverArray),233 },234 }235 Ok(())236}237238pub fn evaluate_member_list_object(context: Context, members: &[Member]) -> Result<ObjValue> {239 let new_bindings = FutureWrapper::new();240 let future_this = FutureWrapper::new();241 let context_creator = ContextCreator(context.clone(), new_bindings.clone());242 {243 let mut bindings: GcHashMap<IStr, LazyBinding> = GcHashMap::with_capacity(members.len());244 for (n, b) in members245 .iter()246 .filter_map(|m| match m {247 Member::BindStmt(b) => Some(b.clone()),248 _ => None,249 })250 .map(|b| evaluate_binding(&b, context_creator.clone()))251 {252 bindings.insert(n, b);253 }254 new_bindings.fill(bindings);255 }256257 let mut builder = ObjValueBuilder::new();258 for member in members.iter() {259 match member {260 Member::Field(FieldMember {261 name,262 plus,263 params: None,264 visibility,265 value,266 }) => {267 let name = evaluate_field_name(context.clone(), name)?;268 if name.is_none() {269 continue;270 }271 let name = name.unwrap();272273 #[derive(Trace)]274 struct ObjMemberBinding {275 context_creator: ContextCreator,276 value: LocExpr,277 name: IStr,278 }279 impl Bindable for ObjMemberBinding {280 fn bind(281 &self,282 this: Option<ObjValue>,283 super_obj: Option<ObjValue>,284 ) -> Result<LazyVal> {285 Ok(LazyVal::new_resolved(evaluate_named(286 self.context_creator.create(this, super_obj)?,287 &self.value,288 self.name.clone(),289 )?))290 }291 }292 builder293 .member(name.clone())294 .with_add(*plus)295 .with_visibility(*visibility)296 .with_location(value.1.clone())297 .bindable(TraceBox(Box::new(ObjMemberBinding {298 context_creator: context_creator.clone(),299 value: value.clone(),300 name,301 })))?;302 }303 Member::Field(FieldMember {304 name,305 params: Some(params),306 value,307 ..308 }) => {309 let name = evaluate_field_name(context.clone(), name)?;310 if name.is_none() {311 continue;312 }313 let name = name.unwrap();314 #[derive(Trace)]315 struct ObjMemberBinding {316 context_creator: ContextCreator,317 value: LocExpr,318 params: ParamsDesc,319 name: IStr,320 }321 impl Bindable for ObjMemberBinding {322 fn bind(323 &self,324 this: Option<ObjValue>,325 super_obj: Option<ObjValue>,326 ) -> Result<LazyVal> {327 Ok(LazyVal::new_resolved(evaluate_method(328 self.context_creator.create(this, super_obj)?,329 self.name.clone(),330 self.params.clone(),331 self.value.clone(),332 )))333 }334 }335 builder336 .member(name.clone())337 .hide()338 .with_location(value.1.clone())339 .bindable(TraceBox(Box::new(ObjMemberBinding {340 context_creator: context_creator.clone(),341 value: value.clone(),342 params: params.clone(),343 name,344 })))?;345 }346 Member::BindStmt(_) => {}347 Member::AssertStmt(stmt) => {348 #[derive(Trace)]349 struct ObjectAssert {350 context_creator: ContextCreator,351 assert: AssertStmt,352 }353 impl ObjectAssertion for ObjectAssert {354 fn run(355 &self,356 this: Option<ObjValue>,357 super_obj: Option<ObjValue>,358 ) -> Result<()> {359 let ctx = self.context_creator.create(this, super_obj)?;360 evaluate_assert(ctx, &self.assert)361 }362 }363 builder.assert(TraceBox(Box::new(ObjectAssert {364 context_creator: context_creator.clone(),365 assert: stmt.clone(),366 })));367 }368 }369 }370 let this = builder.build();371 future_this.fill(this.clone());372 Ok(this)373}374375pub fn evaluate_object(context: Context, object: &ObjBody) -> Result<ObjValue> {376 Ok(match object {377 ObjBody::MemberList(members) => evaluate_member_list_object(context, members)?,378 ObjBody::ObjComp(obj) => {379 let future_this = FutureWrapper::new();380 let mut builder = ObjValueBuilder::new();381 evaluate_comp(context.clone(), &obj.compspecs, &mut |ctx| {382 let new_bindings = FutureWrapper::new();383 let context_creator = ContextCreator(context.clone(), new_bindings.clone());384 let mut bindings: GcHashMap<IStr, LazyBinding> =385 GcHashMap::with_capacity(obj.pre_locals.len() + obj.post_locals.len());386 for (n, b) in obj387 .pre_locals388 .iter()389 .chain(obj.post_locals.iter())390 .map(|b| evaluate_binding(b, context_creator.clone()))391 {392 bindings.insert(n, b);393 }394 new_bindings.fill(bindings.clone());395 let ctx = ctx.extend_unbound(bindings, None, None, None)?;396 let key = evaluate(ctx.clone(), &obj.key)?;397398 match key {399 Val::Null => {}400 Val::Str(n) => {401 #[derive(Trace)]402 struct ObjCompBinding {403 context: Context,404 value: LocExpr,405 }406 impl Bindable for ObjCompBinding {407 fn bind(408 &self,409 this: Option<ObjValue>,410 _super_obj: Option<ObjValue>,411 ) -> Result<LazyVal> {412 Ok(LazyVal::new_resolved(evaluate(413 self.context414 .clone()415 .extend(GcHashMap::new(), None, this, None),416 &self.value,417 )?))418 }419 }420 builder421 .member(n)422 .with_location(obj.value.1.clone())423 .with_add(obj.plus)424 .bindable(TraceBox(Box::new(ObjCompBinding {425 context: ctx,426 value: obj.value.clone(),427 })))?;428 }429 v => throw!(FieldMustBeStringGot(v.value_type())),430 }431432 Ok(())433 })?;434435 let this = builder.build();436 future_this.fill(this.clone());437 this438 }439 })440}441442pub fn evaluate_apply(443 context: Context,444 value: &LocExpr,445 args: &ArgsDesc,446 loc: CallLocation,447 tailstrict: bool,448) -> Result<Val> {449 let value = evaluate(context.clone(), value)?;450 Ok(match value {451 Val::Func(f) => {452 let body = || f.evaluate(context, loc, args, tailstrict);453 if tailstrict {454 body()?455 } else {456 push_frame(loc, || format!("function <{}> call", f.name()), body)?457 }458 }459 v => throw!(OnlyFunctionsCanBeCalledGot(v.value_type())),460 })461}462463pub fn evaluate_assert(context: Context, assertion: &AssertStmt) -> Result<()> {464 let value = &assertion.0;465 let msg = &assertion.1;466 let assertion_result = push_frame(467 CallLocation::new(&value.1),468 || "assertion condition".to_owned(),469 || bool::try_from(evaluate(context.clone(), value)?),470 )?;471 if !assertion_result {472 push_frame(473 CallLocation::new(&value.1),474 || "assertion failure".to_owned(),475 || {476 if let Some(msg) = msg {477 throw!(AssertionFailed(evaluate(context, msg)?.to_string()?));478 } else {479 throw!(AssertionFailed(Val::Null.to_string()?));480 }481 },482 )?483 }484 Ok(())485}486487pub fn evaluate_named(context: Context, lexpr: &LocExpr, name: IStr) -> Result<Val> {488 use Expr::*;489 let LocExpr(expr, _loc) = lexpr;490 Ok(match &**expr {491 Function(params, body) => evaluate_method(context, name, params.clone(), body.clone()),492 _ => evaluate(context, lexpr)?,493 })494}495496pub fn evaluate(context: Context, expr: &LocExpr) -> Result<Val> {497 use Expr::*;498 let LocExpr(expr, loc) = expr;499 // let bp = with_state(|s| s.0.stop_at.borrow().clone());500 Ok(match &**expr {501 Literal(LiteralType::This) => {502 Val::Obj(context.this().clone().ok_or(CantUseSelfOutsideOfObject)?)503 }504 Literal(LiteralType::Super) => Val::Obj(505 context506 .super_obj()507 .clone()508 .ok_or(NoSuperFound)?509 .with_this(context.this().clone().unwrap()),510 ),511 Literal(LiteralType::Dollar) => {512 Val::Obj(context.dollar().clone().ok_or(NoTopLevelObjectFound)?)513 }514 Literal(LiteralType::True) => Val::Bool(true),515 Literal(LiteralType::False) => Val::Bool(false),516 Literal(LiteralType::Null) => Val::Null,517 Parened(e) => evaluate(context, e)?,518 Str(v) => Val::Str(v.clone()),519 Num(v) => Val::new_checked_num(*v)?,520 BinaryOp(v1, o, v2) => evaluate_binary_op_special(context, v1, *o, v2)?,521 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(context, v)?)?,522 Var(name) => push_frame(523 CallLocation::new(loc),524 || format!("variable <{}> access", name),525 || context.binding(name.clone())?.evaluate(),526 )?,527 Index(value, index) => {528 match (evaluate(context.clone(), value)?, evaluate(context, index)?) {529 (Val::Obj(v), Val::Str(s)) => {530 let sn = s.clone();531 push_frame(532 CallLocation::new(loc),533 || format!("field <{}> access", sn),534 || {535 if let Some(v) = v.get(s.clone())? {536 Ok(v)537 } else {538 throw!(NoSuchField(s))539 }540 },541 )?542 }543 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(544 ValType::Obj,545 ValType::Str,546 n.value_type(),547 )),548549 (Val::Arr(v), Val::Num(n)) => {550 if n.fract() > f64::EPSILON {551 throw!(FractionalIndex)552 }553 v.get(n as usize)?554 .ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?555 }556 (Val::Arr(_), Val::Str(n)) => throw!(AttemptedIndexAnArrayWithString(n)),557 (Val::Arr(_), n) => throw!(ValueIndexMustBeTypeGot(558 ValType::Arr,559 ValType::Num,560 n.value_type(),561 )),562563 (Val::Str(s), Val::Num(n)) => Val::Str(564 s.chars()565 .skip(n as usize)566 .take(1)567 .collect::<String>()568 .into(),569 ),570 (Val::Str(_), n) => throw!(ValueIndexMustBeTypeGot(571 ValType::Str,572 ValType::Num,573 n.value_type(),574 )),575576 (v, _) => throw!(CantIndexInto(v.value_type())),577 }578 }579 LocalExpr(bindings, returned) => {580 let mut new_bindings: GcHashMap<IStr, LazyVal> =581 GcHashMap::with_capacity(bindings.len());582 let future_context = Context::new_future();583 for b in bindings {584 new_bindings.insert(585 b.name.clone(),586 evaluate_binding_in_future(b, future_context.clone()),587 );588 }589 let context = context590 .extend_bound(new_bindings)591 .into_future(future_context);592 evaluate(context, &returned.clone())?593 }594 Arr(items) => {595 let mut out = Vec::with_capacity(items.len());596 for item in items {597 // TODO: Implement ArrValue::Lazy with same context for every element?598 #[derive(Trace)]599 struct ArrayElement {600 context: Context,601 item: LocExpr,602 }603 impl LazyValValue for ArrayElement {604 fn get(self: Box<Self>) -> Result<Val> {605 evaluate(self.context, &self.item)606 }607 }608 out.push(LazyVal::new(TraceBox(Box::new(ArrayElement {609 context: context.clone(),610 item: item.clone(),611 }))));612 }613 Val::Arr(out.into())614 }615 ArrComp(expr, comp_specs) => {616 let mut out = Vec::new();617 evaluate_comp(context, comp_specs, &mut |ctx| {618 out.push(evaluate(ctx, expr)?);619 Ok(())620 })?;621 Val::Arr(ArrValue::Eager(Cc::new(out)))622 }623 Obj(body) => Val::Obj(evaluate_object(context, body)?),624 ObjExtend(s, t) => evaluate_add_op(625 &evaluate(context.clone(), s)?,626 &Val::Obj(evaluate_object(context, t)?),627 )?,628 Apply(value, args, tailstrict) => {629 evaluate_apply(context, value, args, CallLocation::new(loc), *tailstrict)?630 }631 Function(params, body) => {632 evaluate_method(context, "anonymous".into(), params.clone(), body.clone())633 }634 Intrinsic(name) => Val::Func(FuncVal::StaticBuiltin(635 BUILTINS636 .with(|b| b.get(name).copied())637 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,638 )),639 AssertExpr(assert, returned) => {640 evaluate_assert(context.clone(), assert)?;641 evaluate(context, returned)?642 }643 ErrorStmt(e) => push_frame(644 CallLocation::new(loc),645 || "error statement".to_owned(),646 || throw!(RuntimeError(evaluate(context, e)?.to_string()?,)),647 )?,648 IfElse {649 cond,650 cond_then,651 cond_else,652 } => {653 if push_frame(654 CallLocation::new(loc),655 || "if condition".to_owned(),656 || bool::try_from(evaluate(context.clone(), &cond.0)?),657 )? {658 evaluate(context, cond_then)?659 } else {660 match cond_else {661 Some(v) => evaluate(context, v)?,662 None => Val::Null,663 }664 }665 }666 Slice(value, desc) => {667 let indexable = evaluate(context.clone(), value)?;668 let loc = CallLocation::new(loc);669670 fn parse_idx<const MIN: usize>(671 loc: CallLocation,672 context: &Context,673 expr: &Option<LocExpr>,674 desc: &'static str,675 ) -> Result<Option<BoundedUsize<MIN, { i32::MAX as usize }>>> {676 if let Some(value) = expr {677 Ok(Some(push_frame(678 loc,679 || format!("slice {}", desc),680 || Ok(evaluate(context.clone(), value)?.try_into()?),681 )?))682 } else {683 Ok(None)684 }685 }686687 let start = parse_idx(loc, &context, &desc.start, "start")?;688 let end = parse_idx(loc, &context, &desc.end, "end")?;689 let step = parse_idx(loc, &context, &desc.step, "step")?;690691 std_slice(indexable.into_indexable()?, start, end, step)?692 }693 Import(path) => {694 let tmp = loc.clone().0;695 let mut import_location = tmp.to_path_buf();696 import_location.pop();697 push_frame(698 CallLocation::new(loc),699 || format!("import {:?}", path),700 || with_state(|s| s.import_file(&import_location, path)),701 )?702 }703 ImportStr(path) => {704 let tmp = loc.clone().0;705 let mut import_location = tmp.to_path_buf();706 import_location.pop();707 Val::Str(with_state(|s| s.import_file_str(&import_location, path))?)708 }709 ImportBin(path) => {710 let tmp = loc.clone().0;711 let mut import_location = tmp.to_path_buf();712 import_location.pop();713 let bytes = with_state(|s| s.import_file_bin(&import_location, path))?;714 Val::Arr(ArrValue::Bytes(bytes))715 }716 })717}1use std::convert::TryFrom;23use gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;5use jrsonnet_parser::{6 ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, ForSpecData, IfSpecData,7 LiteralType, LocExpr, Member, ObjBody, ParamsDesc,8};9use jrsonnet_types::ValType;1011use crate::{12 builtin::{std_slice, BUILTINS},13 error::Error::*,14 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},15 function::CallLocation,16 gc::TraceBox,17 push_frame, throw,18 typed::BoundedUsize,19 val::{ArrValue, FuncDesc, FuncVal, LazyValValue},20 with_state, Bindable, Context, ContextCreator, FutureWrapper, GcHashMap, LazyBinding, LazyVal,21 ObjValue, ObjValueBuilder, ObjectAssertion, Result, Val,22};23pub mod operator;2425pub fn evaluate_binding_in_future(26 b: &BindSpec,27 context_creator: FutureWrapper<Context>,28) -> LazyVal {29 let b = b.clone();30 if let Some(params) = &b.params {31 let params = params.clone();3233 #[derive(Trace)]34 struct LazyMethodBinding {35 context_creator: FutureWrapper<Context>,36 name: IStr,37 params: ParamsDesc,38 value: LocExpr,39 }40 impl LazyValValue for LazyMethodBinding {41 fn get(self: Box<Self>) -> Result<Val> {42 Ok(evaluate_method(43 self.context_creator.unwrap(),44 self.name,45 self.params,46 self.value,47 ))48 }49 }5051 LazyVal::new(TraceBox(Box::new(LazyMethodBinding {52 context_creator,53 name: b.name.clone(),54 params,55 value: b.value.clone(),56 })))57 } else {58 #[derive(Trace)]59 struct LazyNamedBinding {60 context_creator: FutureWrapper<Context>,61 name: IStr,62 value: LocExpr,63 }64 impl LazyValValue for LazyNamedBinding {65 fn get(self: Box<Self>) -> Result<Val> {66 evaluate_named(self.context_creator.unwrap(), &self.value, self.name)67 }68 }69 LazyVal::new(TraceBox(Box::new(LazyNamedBinding {70 context_creator,71 name: b.name.clone(),72 value: b.value,73 })))74 }75}7677pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (IStr, LazyBinding) {78 let b = b.clone();79 if let Some(params) = &b.params {80 let params = params.clone();8182 #[derive(Trace)]83 struct BindableMethodLazyVal {84 this: Option<ObjValue>,85 super_obj: Option<ObjValue>,8687 context_creator: ContextCreator,88 name: IStr,89 params: ParamsDesc,90 value: LocExpr,91 }92 impl LazyValValue for BindableMethodLazyVal {93 fn get(self: Box<Self>) -> Result<Val> {94 Ok(evaluate_method(95 self.context_creator.create(self.this, self.super_obj)?,96 self.name,97 self.params,98 self.value,99 ))100 }101 }102103 #[derive(Trace)]104 struct BindableMethod {105 context_creator: ContextCreator,106 name: IStr,107 params: ParamsDesc,108 value: LocExpr,109 }110 impl Bindable for BindableMethod {111 fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {112 Ok(LazyVal::new(TraceBox(Box::new(BindableMethodLazyVal {113 this,114 super_obj,115116 context_creator: self.context_creator.clone(),117 name: self.name.clone(),118 params: self.params.clone(),119 value: self.value.clone(),120 }))))121 }122 }123124 (125 b.name.clone(),126 LazyBinding::Bindable(Cc::new(TraceBox(Box::new(BindableMethod {127 context_creator,128 name: b.name.clone(),129 params,130 value: b.value.clone(),131 })))),132 )133 } else {134 #[derive(Trace)]135 struct BindableNamedLazyVal {136 this: Option<ObjValue>,137 super_obj: Option<ObjValue>,138139 context_creator: ContextCreator,140 name: IStr,141 value: LocExpr,142 }143 impl LazyValValue for BindableNamedLazyVal {144 fn get(self: Box<Self>) -> Result<Val> {145 evaluate_named(146 self.context_creator.create(self.this, self.super_obj)?,147 &self.value,148 self.name,149 )150 }151 }152153 #[derive(Trace)]154 struct BindableNamed {155 context_creator: ContextCreator,156 name: IStr,157 value: LocExpr,158 }159 impl Bindable for BindableNamed {160 fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {161 Ok(LazyVal::new(TraceBox(Box::new(BindableNamedLazyVal {162 this,163 super_obj,164165 context_creator: self.context_creator.clone(),166 name: self.name.clone(),167 value: self.value.clone(),168 }))))169 }170 }171172 (173 b.name.clone(),174 LazyBinding::Bindable(Cc::new(TraceBox(Box::new(BindableNamed {175 context_creator,176 name: b.name.clone(),177 value: b.value.clone(),178 })))),179 )180 }181}182183pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {184 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {185 name,186 ctx,187 params,188 body,189 })))190}191192pub fn evaluate_field_name(193 context: Context,194 field_name: &jrsonnet_parser::FieldName,195) -> Result<Option<IStr>> {196 Ok(match field_name {197 jrsonnet_parser::FieldName::Fixed(n) => Some(n.clone()),198 jrsonnet_parser::FieldName::Dyn(expr) => push_frame(199 CallLocation::new(&expr.1),200 || "evaluating field name".to_string(),201 || {202 let value = evaluate(context, expr)?;203 if matches!(value, Val::Null) {204 Ok(None)205 } else {206 Ok(Some(IStr::try_from(value)?))207 }208 },209 )?,210 })211}212213pub fn evaluate_comp(214 context: Context,215 specs: &[CompSpec],216 callback: &mut impl FnMut(Context) -> Result<()>,217) -> Result<()> {218 match specs.get(0) {219 None => callback(context)?,220 Some(CompSpec::IfSpec(IfSpecData(cond))) => {221 if bool::try_from(evaluate(context.clone(), cond)?)? {222 evaluate_comp(context, &specs[1..], callback)?223 }224 }225 Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(context.clone(), expr)? {226 Val::Arr(list) => {227 for item in list.iter() {228 evaluate_comp(229 context.clone().with_var(var.clone(), item?.clone()),230 &specs[1..],231 callback,232 )?233 }234 }235 _ => throw!(InComprehensionCanOnlyIterateOverArray),236 },237 }238 Ok(())239}240241pub fn evaluate_member_list_object(context: Context, members: &[Member]) -> Result<ObjValue> {242 let new_bindings = FutureWrapper::new();243 let future_this = FutureWrapper::new();244 let context_creator = ContextCreator(context.clone(), new_bindings.clone());245 {246 let mut bindings: GcHashMap<IStr, LazyBinding> = GcHashMap::with_capacity(members.len());247 for (n, b) in members248 .iter()249 .filter_map(|m| match m {250 Member::BindStmt(b) => Some(b.clone()),251 _ => None,252 })253 .map(|b| evaluate_binding(&b, context_creator.clone()))254 {255 bindings.insert(n, b);256 }257 new_bindings.fill(bindings);258 }259260 let mut builder = ObjValueBuilder::new();261 for member in members.iter() {262 match member {263 Member::Field(FieldMember {264 name,265 plus,266 params: None,267 visibility,268 value,269 }) => {270 let name = evaluate_field_name(context.clone(), name)?;271 if name.is_none() {272 continue;273 }274 let name = name.unwrap();275276 #[derive(Trace)]277 struct ObjMemberBinding {278 context_creator: ContextCreator,279 value: LocExpr,280 name: IStr,281 }282 impl Bindable for ObjMemberBinding {283 fn bind(284 &self,285 this: Option<ObjValue>,286 super_obj: Option<ObjValue>,287 ) -> Result<LazyVal> {288 Ok(LazyVal::new_resolved(evaluate_named(289 self.context_creator.create(this, super_obj)?,290 &self.value,291 self.name.clone(),292 )?))293 }294 }295 builder296 .member(name.clone())297 .with_add(*plus)298 .with_visibility(*visibility)299 .with_location(value.1.clone())300 .bindable(TraceBox(Box::new(ObjMemberBinding {301 context_creator: context_creator.clone(),302 value: value.clone(),303 name,304 })))?;305 }306 Member::Field(FieldMember {307 name,308 params: Some(params),309 value,310 ..311 }) => {312 let name = evaluate_field_name(context.clone(), name)?;313 if name.is_none() {314 continue;315 }316 let name = name.unwrap();317 #[derive(Trace)]318 struct ObjMemberBinding {319 context_creator: ContextCreator,320 value: LocExpr,321 params: ParamsDesc,322 name: IStr,323 }324 impl Bindable for ObjMemberBinding {325 fn bind(326 &self,327 this: Option<ObjValue>,328 super_obj: Option<ObjValue>,329 ) -> Result<LazyVal> {330 Ok(LazyVal::new_resolved(evaluate_method(331 self.context_creator.create(this, super_obj)?,332 self.name.clone(),333 self.params.clone(),334 self.value.clone(),335 )))336 }337 }338 builder339 .member(name.clone())340 .hide()341 .with_location(value.1.clone())342 .bindable(TraceBox(Box::new(ObjMemberBinding {343 context_creator: context_creator.clone(),344 value: value.clone(),345 params: params.clone(),346 name,347 })))?;348 }349 Member::BindStmt(_) => {}350 Member::AssertStmt(stmt) => {351 #[derive(Trace)]352 struct ObjectAssert {353 context_creator: ContextCreator,354 assert: AssertStmt,355 }356 impl ObjectAssertion for ObjectAssert {357 fn run(358 &self,359 this: Option<ObjValue>,360 super_obj: Option<ObjValue>,361 ) -> Result<()> {362 let ctx = self.context_creator.create(this, super_obj)?;363 evaluate_assert(ctx, &self.assert)364 }365 }366 builder.assert(TraceBox(Box::new(ObjectAssert {367 context_creator: context_creator.clone(),368 assert: stmt.clone(),369 })));370 }371 }372 }373 let this = builder.build();374 future_this.fill(this.clone());375 Ok(this)376}377378pub fn evaluate_object(context: Context, object: &ObjBody) -> Result<ObjValue> {379 Ok(match object {380 ObjBody::MemberList(members) => evaluate_member_list_object(context, members)?,381 ObjBody::ObjComp(obj) => {382 let future_this = FutureWrapper::new();383 let mut builder = ObjValueBuilder::new();384 evaluate_comp(context.clone(), &obj.compspecs, &mut |ctx| {385 let new_bindings = FutureWrapper::new();386 let context_creator = ContextCreator(context.clone(), new_bindings.clone());387 let mut bindings: GcHashMap<IStr, LazyBinding> =388 GcHashMap::with_capacity(obj.pre_locals.len() + obj.post_locals.len());389 for (n, b) in obj390 .pre_locals391 .iter()392 .chain(obj.post_locals.iter())393 .map(|b| evaluate_binding(b, context_creator.clone()))394 {395 bindings.insert(n, b);396 }397 new_bindings.fill(bindings.clone());398 let ctx = ctx.extend_unbound(bindings, None, None, None)?;399 let key = evaluate(ctx.clone(), &obj.key)?;400401 match key {402 Val::Null => {}403 Val::Str(n) => {404 #[derive(Trace)]405 struct ObjCompBinding {406 context: Context,407 value: LocExpr,408 }409 impl Bindable for ObjCompBinding {410 fn bind(411 &self,412 this: Option<ObjValue>,413 _super_obj: Option<ObjValue>,414 ) -> Result<LazyVal> {415 Ok(LazyVal::new_resolved(evaluate(416 self.context417 .clone()418 .extend(GcHashMap::new(), None, this, None),419 &self.value,420 )?))421 }422 }423 builder424 .member(n)425 .with_location(obj.value.1.clone())426 .with_add(obj.plus)427 .bindable(TraceBox(Box::new(ObjCompBinding {428 context: ctx,429 value: obj.value.clone(),430 })))?;431 }432 v => throw!(FieldMustBeStringGot(v.value_type())),433 }434435 Ok(())436 })?;437438 let this = builder.build();439 future_this.fill(this.clone());440 this441 }442 })443}444445pub fn evaluate_apply(446 context: Context,447 value: &LocExpr,448 args: &ArgsDesc,449 loc: CallLocation,450 tailstrict: bool,451) -> Result<Val> {452 let value = evaluate(context.clone(), value)?;453 Ok(match value {454 Val::Func(f) => {455 let body = || f.evaluate(context, loc, args, tailstrict);456 if tailstrict {457 body()?458 } else {459 push_frame(loc, || format!("function <{}> call", f.name()), body)?460 }461 }462 v => throw!(OnlyFunctionsCanBeCalledGot(v.value_type())),463 })464}465466pub fn evaluate_assert(context: Context, assertion: &AssertStmt) -> Result<()> {467 let value = &assertion.0;468 let msg = &assertion.1;469 let assertion_result = push_frame(470 CallLocation::new(&value.1),471 || "assertion condition".to_owned(),472 || bool::try_from(evaluate(context.clone(), value)?),473 )?;474 if !assertion_result {475 push_frame(476 CallLocation::new(&value.1),477 || "assertion failure".to_owned(),478 || {479 if let Some(msg) = msg {480 throw!(AssertionFailed(evaluate(context, msg)?.to_string()?));481 } else {482 throw!(AssertionFailed(Val::Null.to_string()?));483 }484 },485 )?486 }487 Ok(())488}489490pub fn evaluate_named(context: Context, lexpr: &LocExpr, name: IStr) -> Result<Val> {491 use Expr::*;492 let LocExpr(expr, _loc) = lexpr;493 Ok(match &**expr {494 Function(params, body) => evaluate_method(context, name, params.clone(), body.clone()),495 _ => evaluate(context, lexpr)?,496 })497}498499pub fn evaluate(context: Context, expr: &LocExpr) -> Result<Val> {500 use Expr::*;501 let LocExpr(expr, loc) = expr;502 // let bp = with_state(|s| s.0.stop_at.borrow().clone());503 Ok(match &**expr {504 Literal(LiteralType::This) => {505 Val::Obj(context.this().clone().ok_or(CantUseSelfOutsideOfObject)?)506 }507 Literal(LiteralType::Super) => Val::Obj(508 context509 .super_obj()510 .clone()511 .ok_or(NoSuperFound)?512 .with_this(context.this().clone().unwrap()),513 ),514 Literal(LiteralType::Dollar) => {515 Val::Obj(context.dollar().clone().ok_or(NoTopLevelObjectFound)?)516 }517 Literal(LiteralType::True) => Val::Bool(true),518 Literal(LiteralType::False) => Val::Bool(false),519 Literal(LiteralType::Null) => Val::Null,520 Parened(e) => evaluate(context, e)?,521 Str(v) => Val::Str(v.clone()),522 Num(v) => Val::new_checked_num(*v)?,523 BinaryOp(v1, o, v2) => evaluate_binary_op_special(context, v1, *o, v2)?,524 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(context, v)?)?,525 Var(name) => push_frame(526 CallLocation::new(loc),527 || format!("variable <{}> access", name),528 || context.binding(name.clone())?.evaluate(),529 )?,530 Index(value, index) => {531 match (evaluate(context.clone(), value)?, evaluate(context, index)?) {532 (Val::Obj(v), Val::Str(s)) => {533 let sn = s.clone();534 push_frame(535 CallLocation::new(loc),536 || format!("field <{}> access", sn),537 || {538 if let Some(v) = v.get(s.clone())? {539 Ok(v)540 } else {541 throw!(NoSuchField(s))542 }543 },544 )?545 }546 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(547 ValType::Obj,548 ValType::Str,549 n.value_type(),550 )),551552 (Val::Arr(v), Val::Num(n)) => {553 if n.fract() > f64::EPSILON {554 throw!(FractionalIndex)555 }556 v.get(n as usize)?557 .ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?558 }559 (Val::Arr(_), Val::Str(n)) => throw!(AttemptedIndexAnArrayWithString(n)),560 (Val::Arr(_), n) => throw!(ValueIndexMustBeTypeGot(561 ValType::Arr,562 ValType::Num,563 n.value_type(),564 )),565566 (Val::Str(s), Val::Num(n)) => Val::Str(567 s.chars()568 .skip(n as usize)569 .take(1)570 .collect::<String>()571 .into(),572 ),573 (Val::Str(_), n) => throw!(ValueIndexMustBeTypeGot(574 ValType::Str,575 ValType::Num,576 n.value_type(),577 )),578579 (v, _) => throw!(CantIndexInto(v.value_type())),580 }581 }582 LocalExpr(bindings, returned) => {583 let mut new_bindings: GcHashMap<IStr, LazyVal> =584 GcHashMap::with_capacity(bindings.len());585 let future_context = Context::new_future();586 for b in bindings {587 new_bindings.insert(588 b.name.clone(),589 evaluate_binding_in_future(b, future_context.clone()),590 );591 }592 let context = context593 .extend_bound(new_bindings)594 .into_future(future_context);595 evaluate(context, &returned.clone())?596 }597 Arr(items) => {598 let mut out = Vec::with_capacity(items.len());599 for item in items {600 // TODO: Implement ArrValue::Lazy with same context for every element?601 #[derive(Trace)]602 struct ArrayElement {603 context: Context,604 item: LocExpr,605 }606 impl LazyValValue for ArrayElement {607 fn get(self: Box<Self>) -> Result<Val> {608 evaluate(self.context, &self.item)609 }610 }611 out.push(LazyVal::new(TraceBox(Box::new(ArrayElement {612 context: context.clone(),613 item: item.clone(),614 }))));615 }616 Val::Arr(out.into())617 }618 ArrComp(expr, comp_specs) => {619 let mut out = Vec::new();620 evaluate_comp(context, comp_specs, &mut |ctx| {621 out.push(evaluate(ctx, expr)?);622 Ok(())623 })?;624 Val::Arr(ArrValue::Eager(Cc::new(out)))625 }626 Obj(body) => Val::Obj(evaluate_object(context, body)?),627 ObjExtend(s, t) => evaluate_add_op(628 &evaluate(context.clone(), s)?,629 &Val::Obj(evaluate_object(context, t)?),630 )?,631 Apply(value, args, tailstrict) => {632 evaluate_apply(context, value, args, CallLocation::new(loc), *tailstrict)?633 }634 Function(params, body) => {635 evaluate_method(context, "anonymous".into(), params.clone(), body.clone())636 }637 Intrinsic(name) => Val::Func(FuncVal::StaticBuiltin(638 BUILTINS639 .with(|b| b.get(name).copied())640 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,641 )),642 AssertExpr(assert, returned) => {643 evaluate_assert(context.clone(), assert)?;644 evaluate(context, returned)?645 }646 ErrorStmt(e) => push_frame(647 CallLocation::new(loc),648 || "error statement".to_owned(),649 || throw!(RuntimeError(evaluate(context, e)?.to_string()?,)),650 )?,651 IfElse {652 cond,653 cond_then,654 cond_else,655 } => {656 if push_frame(657 CallLocation::new(loc),658 || "if condition".to_owned(),659 || bool::try_from(evaluate(context.clone(), &cond.0)?),660 )? {661 evaluate(context, cond_then)?662 } else {663 match cond_else {664 Some(v) => evaluate(context, v)?,665 None => Val::Null,666 }667 }668 }669 Slice(value, desc) => {670 let indexable = evaluate(context.clone(), value)?;671 let loc = CallLocation::new(loc);672673 fn parse_idx<const MIN: usize>(674 loc: CallLocation,675 context: &Context,676 expr: &Option<LocExpr>,677 desc: &'static str,678 ) -> Result<Option<BoundedUsize<MIN, { i32::MAX as usize }>>> {679 if let Some(value) = expr {680 Ok(Some(push_frame(681 loc,682 || format!("slice {}", desc),683 || Ok(evaluate(context.clone(), value)?.try_into()?),684 )?))685 } else {686 Ok(None)687 }688 }689690 let start = parse_idx(loc, &context, &desc.start, "start")?;691 let end = parse_idx(loc, &context, &desc.end, "end")?;692 let step = parse_idx(loc, &context, &desc.step, "step")?;693694 std_slice(indexable.into_indexable()?, start, end, step)?695 }696 Import(path) => {697 let tmp = loc.clone().0;698 let mut import_location = tmp.to_path_buf();699 import_location.pop();700 push_frame(701 CallLocation::new(loc),702 || format!("import {:?}", path),703 || with_state(|s| s.import_file(&import_location, path)),704 )?705 }706 ImportStr(path) => {707 let tmp = loc.clone().0;708 let mut import_location = tmp.to_path_buf();709 import_location.pop();710 Val::Str(with_state(|s| s.import_file_str(&import_location, path))?)711 }712 ImportBin(path) => {713 let tmp = loc.clone().0;714 let mut import_location = tmp.to_path_buf();715 import_location.pop();716 let bytes = with_state(|s| s.import_file_bin(&import_location, path))?;717 Val::Arr(ArrValue::Bytes(bytes))718 }719 })720}crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -1,10 +1,11 @@
use std::convert::TryInto;
-use crate::builtin::std_format;
-use crate::{equals, evaluate, Context, Val};
-use crate::{error::Error::*, throw, Result};
use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};
+use crate::{
+ builtin::std_format, error::Error::*, evaluate, throw, val::equals, Context, Result, Val,
+};
+
pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {
use UnaryOpType::*;
use Val::*;
crates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -1,16 +1,19 @@
+use std::{borrow::Cow, collections::HashMap, convert::TryFrom};
+
+use gcmodule::Trace;
+use jrsonnet_interner::IStr;
+pub use jrsonnet_macros::builtin;
+use jrsonnet_parser::{ArgsDesc, ExprLocation, LocExpr, ParamsDesc};
+
use crate::{
error::{Error::*, LocError},
evaluate, evaluate_named,
gc::TraceBox,
throw,
typed::Typed,
- Context, FutureWrapper, GcHashMap, LazyVal, LazyValValue, Result, Val,
+ val::LazyValValue,
+ Context, FutureWrapper, GcHashMap, LazyVal, Result, Val,
};
-use gcmodule::Trace;
-use jrsonnet_interner::IStr;
-pub use jrsonnet_macros::builtin;
-use jrsonnet_parser::{ArgsDesc, ExprLocation, LocExpr, ParamsDesc};
-use std::{borrow::Cow, collections::HashMap, convert::TryFrom};
#[derive(Clone, Copy)]
pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);
crates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -1,17 +1,20 @@
-use crate::{
- error::{Error::*, Result},
- throw,
-};
-use fs::File;
-use jrsonnet_interner::IStr;
-use std::fs;
use std::{
any::Any,
+ convert::TryFrom,
+ fs,
+ io::Read,
path::{Path, PathBuf},
rc::Rc,
};
-use std::{convert::TryFrom, io::Read};
+use fs::File;
+use jrsonnet_interner::IStr;
+
+use crate::{
+ error::{Error::*, Result},
+ throw,
+};
+
/// Implements file resolution logic for `import` and `importStr`
pub trait ImportResolver {
/// Resolves real file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -1,9 +1,11 @@
+use std::convert::{TryFrom, TryInto};
+
+use serde_json::{Map, Number, Value};
+
use crate::{
error::{Error::*, LocError, Result},
throw, ObjValueBuilder, Val,
};
-use serde_json::{Map, Number, Value};
-use std::convert::{TryFrom, TryInto};
impl TryFrom<&Val> for Value {
type Error = LocError;
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -13,6 +13,7 @@
pub mod error;
mod evaluate;
pub mod function;
+pub mod gc;
mod import;
mod integrations;
mod map;
@@ -20,9 +21,15 @@
mod obj;
pub mod trace;
pub mod typed;
-mod val;
+pub mod val;
-pub use jrsonnet_parser as parser;
+use std::{
+ cell::{Ref, RefCell, RefMut},
+ collections::HashMap,
+ fmt::Debug,
+ path::{Path, PathBuf},
+ rc::Rc,
+};
pub use ctx::*;
pub use dynamic::*;
@@ -33,18 +40,11 @@
use gcmodule::{Cc, Trace, Weak};
pub use import::*;
pub use jrsonnet_interner::IStr;
+pub use jrsonnet_parser as parser;
use jrsonnet_parser::*;
pub use obj::*;
-use std::{
- cell::{Ref, RefCell, RefMut},
- collections::HashMap,
- fmt::Debug,
- path::{Path, PathBuf},
- rc::Rc,
-};
use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};
-pub use val::*;
-pub mod gc;
+pub use val::{LazyVal, ManifestFormat, Val};
pub trait Bindable: Trace + 'static {
fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal>;
@@ -693,18 +693,24 @@
#[cfg(test)]
pub mod tests {
- use super::Val;
- use crate::{
- error::Error::*, function::BuiltinParam, gc::TraceBox, native::NativeCallbackHandler,
- primitive_equals, EvaluationState,
- };
- use gcmodule::{Cc, Trace};
- use jrsonnet_parser::*;
use std::{
path::{Path, PathBuf},
rc::Rc,
};
+ use gcmodule::{Cc, Trace};
+ use jrsonnet_parser::*;
+
+ use super::Val;
+ use crate::{
+ error::Error::*,
+ function::{BuiltinParam, CallLocation},
+ gc::TraceBox,
+ native::NativeCallbackHandler,
+ val::primitive_equals,
+ EvaluationState,
+ };
+
#[test]
#[should_panic]
fn eval_state_stacktrace() {
@@ -712,11 +718,15 @@
state.run_in_state(|| {
state
.push(
- Some(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
+ CallLocation::new(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
|| "outer".to_owned(),
|| {
state.push(
- Some(&ExprLocation(PathBuf::from("test2.jsonnet").into(), 30, 40)),
+ CallLocation::new(&ExprLocation(
+ PathBuf::from("test2.jsonnet").into(),
+ 30,
+ 40,
+ )),
|| "inner".to_owned(),
|| Err(RuntimeError("".into()).into()),
)?;
@@ -1290,10 +1300,11 @@
}
mod derive_typed {
+ use std::path::PathBuf;
+
use crate::{typed::Typed, EvaluationState};
- use std::path::PathBuf;
- #[derive(Typed, PartialEq, Debug)]
+ #[derive(PartialEq, Debug, Typed)]
struct MyTyped {
a: u32,
#[typed(rename = "b")]
crates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -1,13 +1,16 @@
#![allow(clippy::type_complexity)]
-use crate::function::{parse_builtin_call, ArgsLike, Builtin, BuiltinParam, CallLocation};
-use crate::gc::TraceBox;
-use crate::Context;
-use crate::{error::Result, Val};
+use std::{path::Path, rc::Rc};
+
use gcmodule::Trace;
-use std::path::Path;
-use std::rc::Rc;
+use crate::{
+ error::Result,
+ function::{parse_builtin_call, ArgsLike, Builtin, BuiltinParam, CallLocation},
+ gc::TraceBox,
+ Context, Val,
+};
+
#[derive(Trace)]
pub struct NativeCallback {
pub(crate) params: Vec<BuiltinParam>,
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,20 +1,23 @@
-use crate::error::LocError;
-use crate::function::CallLocation;
-use crate::gc::{GcHashMap, GcHashSet, TraceBox};
-use crate::operator::evaluate_add_op;
-use crate::push_frame;
-use crate::{
- cc_ptr_eq, error::Error::*, throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal,
- Result, Val,
+use std::{
+ cell::RefCell,
+ fmt::Debug,
+ hash::{Hash, Hasher},
};
+
use gcmodule::{Cc, Trace, Weak};
use jrsonnet_interner::IStr;
use jrsonnet_parser::{ExprLocation, Visibility};
use rustc_hash::FxHashMap;
-use std::cell::RefCell;
-use std::fmt::Debug;
-use std::hash::{Hash, Hasher};
+use crate::{
+ cc_ptr_eq,
+ error::{Error::*, LocError},
+ function::CallLocation,
+ gc::{GcHashMap, GcHashSet, TraceBox},
+ operator::evaluate_add_op,
+ push_frame, throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal, Result, Val,
+};
+
#[derive(Debug, Trace)]
pub struct ObjMember {
pub add: bool,
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -1,8 +1,10 @@
mod location;
+use std::path::{Path, PathBuf};
+
+pub use location::*;
+
use crate::{error::Error, EvaluationState, LocError};
-pub use location::*;
-use std::path::{Path, PathBuf};
/// The way paths should be displayed
pub enum PathResolver {
crates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -2,14 +2,14 @@
mod conversions;
pub use conversions::*;
+use gcmodule::Trace;
+pub use jrsonnet_types::{ComplexValType, ValType};
+use thiserror::Error;
use crate::{
error::{Error, LocError, Result},
push_description_frame, Val,
};
-use gcmodule::Trace;
-pub use jrsonnet_types::{ComplexValType, ValType};
-use thiserror::Error;
#[derive(Debug, Error, Clone, Trace)]
pub enum TypeError {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -1,3 +1,10 @@
+use std::{cell::RefCell, fmt::Debug, rc::Rc};
+
+use gcmodule::{Cc, Trace};
+use jrsonnet_interner::IStr;
+use jrsonnet_parser::{LocExpr, ParamsDesc};
+use jrsonnet_types::ValType;
+
use crate::{
builtin::manifest::{
manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,
@@ -12,11 +19,6 @@
gc::TraceBox,
throw, Context, ObjValue, Result,
};
-use gcmodule::{Cc, Trace};
-use jrsonnet_interner::IStr;
-use jrsonnet_parser::{LocExpr, ParamsDesc};
-use jrsonnet_types::ValType;
-use std::{cell::RefCell, fmt::Debug, rc::Rc};
pub trait LazyValValue: Trace {
fn get(self: Box<Self>) -> Result<Val>;
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -1,6 +1,3 @@
-use gcmodule::Trace;
-use rustc_hash::FxHashMap;
-use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
cell::RefCell,
@@ -12,6 +9,10 @@
str::Utf8Error,
};
+use gcmodule::Trace;
+use rustc_hash::FxHashMap;
+use serde::{Deserialize, Serialize};
+
#[derive(Clone, PartialOrd, Ord, Eq)]
pub struct IStr(Rc<str>);
impl Trace for IStr {
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -1,7 +1,3 @@
-use gcmodule::Trace;
-use jrsonnet_interner::IStr;
-#[cfg(feature = "serde")]
-use serde::{Deserialize, Serialize};
use std::{
fmt::{Debug, Display},
ops::Deref,
@@ -9,6 +5,11 @@
rc::Rc,
};
+use gcmodule::Trace;
+use jrsonnet_interner::IStr;
+#[cfg(feature = "serde")]
+use serde::{Deserialize, Serialize};
+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum FieldName {
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -1,10 +1,11 @@
#![allow(clippy::redundant_closure_call)]
-use peg::parser;
use std::{
path::{Path, PathBuf},
rc::Rc,
};
+
+use peg::parser;
mod expr;
pub use expr::*;
pub use jrsonnet_interner::IStr;
@@ -317,11 +318,13 @@
#[cfg(test)]
pub mod tests {
- use super::{expr::*, parse};
- use crate::ParserSettings;
use std::path::PathBuf;
+
use BinaryOpType::*;
+ use super::{expr::*, parse};
+ use crate::ParserSettings;
+
macro_rules! parse {
($s:expr) => {
parse(
crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -1,8 +1,9 @@
#![allow(clippy::redundant_closure_call)]
-use gcmodule::Trace;
use std::fmt::Display;
+use gcmodule::Trace;
+
#[macro_export]
macro_rules! ty {
((Array<number>)) => {{