git.delta.rocks / jrsonnet / refs/commits / a05afd32cebc

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2023-01-20parent: #974f2c1.patch.diff
in: master

16 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
55
6use clap::{CommandFactory, Parser};6use clap::{CommandFactory, Parser};
7use clap_complete::Shell;7use clap_complete::Shell;
8use jrsonnet_cli::{ManifestOpts, OutputOpts, TraceOpts, MiscOpts, TlaOpts, StdOpts, GcOpts};8use jrsonnet_cli::{GcOpts, ManifestOpts, MiscOpts, OutputOpts, StdOpts, TlaOpts, TraceOpts};
9use jrsonnet_evaluator::{9use jrsonnet_evaluator::{
10 apply_tla,10 apply_tla,
11 error::{Error as JrError, ErrorKind},11 error::{Error as JrError, ErrorKind},
142 trace.write_trace(&mut out, &e).expect("format error");140 trace.write_trace(&mut out, &e).expect("format error");
143 eprintln!("{out}")141 eprintln!("{out}")
144 } else {142 } else {
145 eprintln!("{}", e);143 eprintln!("{e}");
146 }144 }
147 return false;145 return false;
148 }146 }
220 } else {218 } else {
221 let output = val.manifest(manifest_format)?;219 let output = val.manifest(manifest_format)?;
222 if !output.is_empty() {220 if !output.is_empty() {
223 println!("{}", output);221 println!("{output}");
224 }222 }
225 }223 }
226224
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
6use std::{env, marker::PhantomData, path::PathBuf};6use std::{env, marker::PhantomData, path::PathBuf};
77
8use clap::Parser;8use clap::Parser;
9use jrsonnet_evaluator::{error::Result, stack::{set_stack_depth_limit, StackDepthLimitOverrideGuard, limit_stack_depth}, FileImportResolver, State, ImportResolver};9use jrsonnet_evaluator::{
10 stack::{limit_stack_depth, StackDepthLimitOverrideGuard},
11 FileImportResolver,
12};
10use jrsonnet_gcmodule::with_thread_object_space;13use jrsonnet_gcmodule::with_thread_object_space;
71}74}
72impl GcOpts {75impl GcOpts {
73 pub fn stats_printer(&self) -> Option<GcStatsPrinter> {76 pub fn stats_printer(&self) -> Option<GcStatsPrinter> {
77 #[allow(clippy::unnecessary_lazy_evaluations/*, reason = "GcStatsPrinter has side-effect on Drop"*/)]
74 self.gc_print_stats.then(|| GcStatsPrinter {78 self.gc_print_stats.then(|| GcStatsPrinter {
75 collect_before_printing_stats: self.gc_collect_before_printing_stats,79 collect_before_printing_stats: self.gc_collect_before_printing_stats,
76 })80 })
96 eprintln!("=== GC STATS ===");100 eprintln!("=== GC STATS ===");
97 if self.collect_before_printing_stats {101 if self.collect_before_printing_stats {
98 let collected = jrsonnet_gcmodule::collect_thread_cycles();102 let collected = jrsonnet_gcmodule::collect_thread_cycles();
99 eprintln!("Collected: {}", collected);103 eprintln!("Collected: {collected}");
100 }104 }
101 eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())105 eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
102 }106 }
modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
1use std::path::PathBuf;1use std::path::PathBuf;
22
3use clap::{Parser, ValueEnum};3use clap::{Parser, ValueEnum};
4use jrsonnet_evaluator::{4use jrsonnet_evaluator::manifest::{
5 error::Result,
6 manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
7 State,
8};6};
9use jrsonnet_stdlib::{TomlFormat, YamlFormat};7use jrsonnet_stdlib::{TomlFormat, YamlFormat};
108
11#[derive(Clone, ValueEnum)]9#[derive(Clone, ValueEnum)]
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
1use std::{fs::read_to_string, str::FromStr};1use std::{fs::read_to_string, str::FromStr};
22
3use clap::Parser;3use clap::Parser;
4use jrsonnet_evaluator::{error::Result, tb, trace::PathResolver, State};4use jrsonnet_evaluator::{error::Result, trace::PathResolver, State};
5use jrsonnet_stdlib::ContextInitializer;5use jrsonnet_stdlib::ContextInitializer;
66
7#[derive(Clone)]7#[derive(Clone)]
49 name: out[0].into(),49 name: out[0].into(),
50 value: content,50 value: content,
51 }),51 }),
52 Err(e) => Err(format!("{}", e)),52 Err(e) => Err(format!("{e}")),
53 }53 }
54 }54 }
55}55}
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
3 error::{ErrorKind, Result},3 error::{ErrorKind, Result},
4 function::TlaArg,4 function::TlaArg,
5 gc::GcHashMap,5 gc::GcHashMap,
6 IStr, State,6 IStr,
7};7};
8use jrsonnet_parser::{ParserSettings, Source};8use jrsonnet_parser::{ParserSettings, Source};
99
modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
1use clap::{Parser, ValueEnum};1use clap::{Parser, ValueEnum};
2use jrsonnet_evaluator::{2use jrsonnet_evaluator::trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat};
3 error::Result,
4 trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat},
5 State,
6};
73
8#[derive(PartialEq, Eq, ValueEnum, Clone)]4#[derive(PartialEq, Eq, ValueEnum, Clone)]
9pub enum TraceFormatName {5pub enum TraceFormatName {
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
274 f.debug_tuple("LocError").field(&self.0).finish()274 f.debug_tuple("LocError").field(&self.0).finish()
275 }275 }
276}276}
277impl std::error::Error for Error {}
277278
278pub trait ErrorSource {279pub trait ErrorSource {
279 fn to_location(self) -> Option<ExprLocation>;280 fn to_location(self) -> Option<ExprLocation>;
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
104 }104 }
105 }105 }
106 } else {106 } else {
107 {
108 let ai = a.iter();107 let ai = a.iter();
109 let bi = b.iter();108 let bi = b.iter();
110109
114 return Ok(ord);113 return Ok(ord);
115 }114 }
116 }115 }
117 }
118 // {
119 // let ai = a.iter_expl();
120 // let bi = b.iter_expl();
121
122 // for (a, b) in ai.zip(bi) {
123 // let ord = evaluate_compare_op(&a?, &b?, op)?;
124 // if !ord.is_eq() {
125 // return Ok(ord);
126 // }
127 // }
128 // }
129 }116 }
130 a.len().cmp(&b.len())117 a.len().cmp(&b.len())
131 }118 }
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
36 clippy::use_self,36 clippy::use_self,
37 // https://github.com/rust-lang/rust-clippy/issues/853937 // https://github.com/rust-lang/rust-clippy/issues/8539
38 clippy::iter_with_drain,38 clippy::iter_with_drain,
39 clippy::type_repetition_in_bounds,
39 // ci is being run with nightly, but library should work on stable40 // ci is being run with nightly, but library should work on stable
40 clippy::missing_const_for_fn,41 clippy::missing_const_for_fn,
41)]42)]
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
5454
55#[cfg(feature = "exp-preserve-order")]55#[cfg(feature = "exp-preserve-order")]
56mod ordering {56mod ordering {
57 use std::cmp::Reverse;57 use std::cmp::{Ordering, Reverse};
5858
59 use jrsonnet_gcmodule::Trace;59 use jrsonnet_gcmodule::Trace;
6060
81 Self(Reverse(depth), index)81 Self(Reverse(depth), index)
82 }82 }
83 pub fn collide(self, other: Self) -> Self {83 pub fn collide(self, other: Self) -> Self {
84 if self.0 .0 > other.0 .0 {84 match self.0 .0.cmp(&other.0 .0) {
85 self85 Ordering::Greater => self,
86 } else if self.0 .0 < other.0 .0 {86 Ordering::Less => other,
87 other
88 } else {
89 unreachable!("object can't have two fields with same name")87 Ordering::Equal => unreachable!("object can't have two fields with the same name"),
90 }88 }
91 }89 }
92 }90 }
93}91}
188 pub fn new_empty() -> Self {186 pub fn new_empty() -> Self {
189 Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))187 Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))
190 }188 }
189 pub fn builder() -> ObjValueBuilder {
190 ObjValueBuilder::new()
191 }
192 pub fn builder_with_capacity(capacity: usize) -> ObjValueBuilder {
193 ObjValueBuilder::with_capacity(capacity)
194 }
191 #[must_use]195 #[must_use]
192 pub fn extend_from(&self, sup: Self) -> Self {196 pub fn extend_from(&self, sup: Self) -> Self {
193 match &self.0.sup {197 match &self.0.sup {
304 break;308 break;
305 }309 }
306 fields[j] = fields[k].clone();310 fields[j] = fields[k].clone();
307 j = k311 j = k;
308 }312 }
309 fields[j] = x;313 fields[j] = x;
310 }314 }
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
33 Pending,33 Pending,
34}34}
3535
36/// Lazily evaluated value
36#[allow(clippy::module_name_repetitions)]37#[allow(clippy::module_name_repetitions)]
37#[derive(Clone, Trace)]38#[derive(Clone, Trace)]
38pub struct Thunk<T: Trace>(Cc<RefCell<ThunkInner<T>>>);39pub struct Thunk<T: Trace>(Cc<RefCell<ThunkInner<T>>>);
58 Ok(())59 Ok(())
59 }60 }
61
62 /// Evaluate thunk, or return cached value
63 ///
64 /// # Errors
65 ///
66 /// - Lazy value evaluation returned error
67 /// - This method was called during inner value evaluation
60 pub fn evaluate(&self) -> Result<T> {68 pub fn evaluate(&self) -> Result<T> {
61 match &*self.0.borrow() {69 match &*self.0.borrow() {
62 ThunkInner::Computed(v) => return Ok(v.clone()),70 ThunkInner::Computed(v) => return Ok(v.clone()),
132 }140 }
133}141}
134142
135/// Represents a Jsonnet value, which can be spliced or indexed (string or array).143/// Represents a Jsonnet value, which can be sliced or indexed (string or array).
136#[allow(clippy::module_name_repetitions)]144#[allow(clippy::module_name_repetitions)]
137pub enum IndexableVal {145pub enum IndexableVal {
138 /// String.146 /// String.
247 }255 }
248 }256 }
249}257}
258impl From<&str> for StrValue {
259 fn from(value: &str) -> Self {
260 Self::Flat(value.into())
261 }
262}
263impl From<String> for StrValue {
264 fn from(value: String) -> Self {
265 Self::Flat(value.into())
266 }
267}
250impl Display for StrValue {268impl Display for StrValue {
251 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {269 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
252 match self {270 match self {
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth

no syntactic changes

modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
211 locs[0].line211 locs[0].line
212 );212 );
213 }213 }
214 eprintln!(" {}", value);214 eprintln!(" {value}");
215 }215 }
216}216}
217217
229}229}
230230
231fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {231fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {
232 let source_name = format!("<extvar:{}>", name);232 let source_name = format!("<extvar:{name}>");
233 Source::new_virtual(source_name.into(), code.into())233 Source::new_virtual(source_name.into(), code.into())
234}234}
235235
modifiedcrates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth
46 .ext_natives46 .ext_natives
47 .get(&x)47 .get(&x)
48 .cloned()48 .cloned()
49 .map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v.clone())))49 .map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v)))
50}50}
5151
52#[builtin(fields(52#[builtin(fields(
modifiedcrates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth
8#[builtin]8#[builtin]
9pub fn builtin_parse_json(str: IStr) -> Result<Val> {9pub fn builtin_parse_json(str: IStr) -> Result<Val> {
10 let value: Val = serde_json::from_str(&str)10 let value: Val = serde_json::from_str(&str)
11 .map_err(|e| RuntimeError(format!("failed to parse json: {}", e).into()))?;11 .map_err(|e| RuntimeError(format!("failed to parse json: {e}").into()))?;
12 Ok(value)12 Ok(value)
13}13}
1414
22 let mut out = vec![];22 let mut out = vec![];
23 for item in value {23 for item in value {
24 let val = Val::deserialize(item)24 let val = Val::deserialize(item)
25 .map_err(|e| RuntimeError(format!("failed to parse yaml: {}", e).into()))?;25 .map_err(|e| RuntimeError(format!("failed to parse yaml: {e}").into()))?;
26 out.push(val);26 out.push(val);
27 }27 }
28 Ok(if out.is_empty() {28 Ok(if out.is_empty() {
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
150 if should_add_braces {150 if should_add_braces {
151 write!(f, "(")?;151 write!(f, "(")?;
152 }152 }
153 write!(f, "{}", v)?;153 write!(f, "{v}")?;
154 if should_add_braces {154 if should_add_braces {
155 write!(f, ")")?;155 write!(f, ")")?;
156 }156 }
162 if *a == ComplexValType::Any {162 if *a == ComplexValType::Any {
163 write!(f, "array")?163 write!(f, "array")?
164 } else {164 } else {
165 write!(f, "Array<{}>", a)?165 write!(f, "Array<{a}>")?
166 }166 }
167 Ok(())167 Ok(())
168}168}
171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
172 match self {172 match self {
173 ComplexValType::Any => write!(f, "any")?,173 ComplexValType::Any => write!(f, "any")?,
174 ComplexValType::Simple(s) => write!(f, "{}", s)?,174 ComplexValType::Simple(s) => write!(f, "{s}")?,
175 ComplexValType::Char => write!(f, "char")?,175 ComplexValType::Char => write!(f, "char")?,
176 ComplexValType::BoundedNumber(a, b) => write!(176 ComplexValType::BoundedNumber(a, b) => write!(
177 f,177 f,
187 if i != 0 {187 if i != 0 {
188 write!(f, ", ")?;188 write!(f, ", ")?;
189 }189 }
190 write!(f, "{}: {}", k, v)?;190 write!(f, "{k}: {v}")?;
191 }191 }
192 write!(f, "}}")?;192 write!(f, "}}")?;
193 }193 }