difftreelog
build(dep) share dependency versions in workspace
in: master
15 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -30,6 +30,12 @@
]
[[package]]
+name = "allocator-api2"
+version = "0.2.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
+
+[[package]]
name = "annotate-snippets"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -456,20 +462,15 @@
[[package]]
name = "hashbrown"
-version = "0.13.2"
+version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
+checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
dependencies = [
"ahash",
+ "allocator-api2",
]
[[package]]
-name = "hashbrown"
-version = "0.14.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
-
-[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -514,9 +515,9 @@
[[package]]
name = "indoc"
-version = "1.0.9"
+version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
+checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8"
[[package]]
name = "insta"
@@ -550,9 +551,9 @@
[[package]]
name = "itertools"
-version = "0.10.5"
+version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
+checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
@@ -600,7 +601,7 @@
"async-trait",
"bincode",
"derivative",
- "hashbrown 0.13.2",
+ "hashbrown 0.14.2",
"jrsonnet-gcmodule",
"jrsonnet-interner",
"jrsonnet-macros",
@@ -654,7 +655,7 @@
name = "jrsonnet-interner"
version = "0.5.0-pre95"
dependencies = [
- "hashbrown 0.13.2",
+ "hashbrown 0.14.2",
"jrsonnet-gcmodule",
"rustc-hash",
"serde",
@@ -680,7 +681,7 @@
dependencies = [
"proc-macro2",
"quote",
- "syn 1.0.109",
+ "syn 2.0.38",
]
[[package]]
@@ -700,7 +701,6 @@
version = "0.5.0-pre95"
dependencies = [
"anyhow",
- "backtrace",
"drop_bomb",
"indoc",
"insta",
@@ -801,32 +801,41 @@
[[package]]
name = "logos"
-version = "0.12.1"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
+checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
dependencies = [
"logos-derive",
]
[[package]]
-name = "logos-derive"
-version = "0.12.1"
+name = "logos-codegen"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
+checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
- "syn 1.0.109",
+ "syn 2.0.38",
+]
+
+[[package]]
+name = "logos-derive"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e"
+dependencies = [
+ "logos-codegen",
]
[[package]]
name = "lsp-server"
-version = "0.6.0"
+version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f70570c1c29cf6654029b8fe201a5507c153f0d85be6f234d471d756bc36775a"
+checksum = "b52dccdf3302eefab8c8a1273047f0a3c3dca4b527c8458d00c09484c8371928"
dependencies = [
"crossbeam-channel",
"log",
@@ -836,9 +845,9 @@
[[package]]
name = "lsp-types"
-version = "0.93.2"
+version = "0.94.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9be6e9c7e2d18f651974370d7aff703f9513e0df6e464fd795660edc77e6ca51"
+checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1"
dependencies = [
"bitflags 1.3.2",
"serde",
@@ -1232,18 +1241,18 @@
[[package]]
name = "serde"
-version = "1.0.171"
+version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9"
+checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.171"
+version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682"
+checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [
"proc-macro2",
"quote",
@@ -1758,7 +1767,7 @@
version = "0.1.0"
dependencies = [
"anyhow",
- "indexmap 1.9.3",
+ "indexmap 2.0.2",
"itertools",
"proc-macro2",
"quote",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,9 +16,54 @@
jrsonnet-types = { path = "./crates/jrsonnet-types", version = "0.5.0-pre95" }
jrsonnet-gcmodule = "0.3.6"
+ass-stroke = { git = "https://github.com/CertainLach/ass-stroke", version = "0.1.0" }
-# <= 1.0.171 due to serde-rs/serde#2538
-serde = { version = ">= 1.0.126, <= 1.0.171" }
+serde = "1.0.190"
+serde_json = "1.0.107"
+serde_yaml_with_quirks = "0.8.24"
+
+anyhow = "1.0.48"
+thiserror = "1.0"
+mimallocator = "0.1.3"
+indoc = "2.0"
+dprint-core = "0.63.2"
+insta = "1.15"
+tempfile = "3.8"
+pathdiff = "0.2.1"
+hashbrown = "0.14.2"
+static_assertions = "1.1"
+rustc-hash = "1.1"
+bincode = "1.3"
+annotate-snippets = "0.9.1"
+async-trait = "0.1.60"
+num-bigint = "0.4.3"
+derivative = "2.2.0"
+strsim = "0.10.0"
+structdump = "0.2.0"
+proc-macro2 = "1.0"
+quote = "1.0"
+syn = "2.0"
+peg = "0.8.2"
+drop_bomb = "0.1.5"
+logos = "0.13.0"
+miette = "5.5.0"
+rowan = "0.15"
+text-size = "1.1"
+md5 = "0.7.0"
+sha1 = "0.10.5"
+sha2 = "0.10.6"
+sha3 = "0.10.8"
+base64 = "0.21.0"
+indexmap = "2.0.2"
+itertools = "0.11.0"
+ungrammar = "1.16.1"
+xshell = "0.2.2"
+
+clap = "4.4"
+clap_complete = "4.4"
+
+lsp-server = "0.7.4"
+lsp-types = "0.94.1"
#[profile.test]
#opt-level = 1
cmds/jrsonnet-fmt/Cargo.tomldiffbeforeafterboth--- a/cmds/jrsonnet-fmt/Cargo.toml
+++ b/cmds/jrsonnet-fmt/Cargo.toml
@@ -4,11 +4,11 @@
edition = "2021"
[dependencies]
-dprint-core = "0.63.2"
+dprint-core.workspace = true
jrsonnet-rowan-parser.workspace = true
-insta = "1.15"
-indoc = "1.0"
-ass-stroke = { git = "https://github.com/CertainLach/ass-stroke.git", version = "0.1.0" }
-clap = { version = "4.4.2", features = ["derive"] }
-tempfile = "3.8.0"
-thiserror = "1.0.48"
+insta.workspace = true
+indoc.workspace = true
+ass-stroke.workspace = true
+clap = { workspace = true, features = ["derive"] }
+tempfile.workspace = true
+thiserror.workspace = true
cmds/jrsonnet-lsp/Cargo.tomldiffbeforeafterboth--- a/cmds/jrsonnet-lsp/Cargo.toml
+++ b/cmds/jrsonnet-lsp/Cargo.toml
@@ -4,10 +4,10 @@
edition = "2021"
[dependencies]
-anyhow = "1.0.48"
+anyhow.workspace = true
jrsonnet-evaluator.workspace = true
jrsonnet-rowan-parser.workspace = true
-lsp-server = "0.6.0"
-lsp-types = "0.93.0"
-serde = "1.0.130"
-serde_json = "1.0.71"
+lsp-server.workspace = true
+lsp-types.workspace = true
+serde.workspace = true
+serde_json.workspace = true
cmds/jrsonnet/Cargo.tomldiffbeforeafterboth--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -8,11 +8,21 @@
edition = "2021"
[features]
-experimental = ["exp-preserve-order", "exp-destruct", "exp-null-coaelse", "exp-object-iteration", "exp-bigint", "exp-apply"]
+experimental = [
+ "exp-preserve-order",
+ "exp-destruct",
+ "exp-null-coaelse",
+ "exp-object-iteration",
+ "exp-bigint",
+ "exp-apply",
+]
# Use mimalloc as allocator
mimalloc = ["mimallocator"]
# Experimental feature, which allows to preserve order of object fields
-exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order", "jrsonnet-cli/exp-preserve-order"]
+exp-preserve-order = [
+ "jrsonnet-evaluator/exp-preserve-order",
+ "jrsonnet-cli/exp-preserve-order",
+]
# Destructuring of locals
exp-destruct = ["jrsonnet-evaluator/exp-destruct"]
# Iteration over objects yields [key, value] elements
@@ -20,7 +30,11 @@
# Bigint type
exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]
# obj?.field, obj?.['field']
-exp-null-coaelse = ["jrsonnet-evaluator/exp-null-coaelse", "jrsonnet-parser/exp-null-coaelse", "jrsonnet-cli/exp-null-coaelse"]
+exp-null-coaelse = [
+ "jrsonnet-evaluator/exp-null-coaelse",
+ "jrsonnet-parser/exp-null-coaelse",
+ "jrsonnet-cli/exp-null-coaelse",
+]
# --exp-apply
exp-apply = []
@@ -35,10 +49,10 @@
jrsonnet-cli.workspace = true
jrsonnet-gcmodule.workspace = true
-mimallocator = { version = "0.1.3", optional = true }
-thiserror = "1.0"
-clap = { version = "4.1", features = ["derive"] }
-clap_complete = { version = "4.1" }
-serde_json = "1.0.104"
+mimallocator = { workspace = true, optional = true }
+thiserror.workspace = true
+clap = { workspace = true, features = ["derive"] }
+clap_complete.workspace = true
+serde_json.workspace = true
serde = { workspace = true, features = ["derive"] }
-ass-stroke = { git = "https://github.com/CertainLach/ass-stroke", version = "0.1.0" }
+ass-stroke.workspace = true
crates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -28,4 +28,4 @@
jrsonnet-stdlib.workspace = true
jrsonnet-gcmodule.workspace = true
-clap = { version = "4.1", features = ["derive"] }
+clap = { workspace = true, features = ["derive"] }
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -37,25 +37,25 @@
jrsonnet-macros.workspace = true
jrsonnet-gcmodule.workspace = true
-pathdiff = "0.2.1"
-hashbrown = "0.13.2"
-static_assertions = "1.1"
+pathdiff.workspace = true
+hashbrown.workspace = true
+static_assertions.workspace = true
-rustc-hash = "1.1"
+rustc-hash.workspace = true
-thiserror = "1.0"
+thiserror.workspace = true
# Friendly errors
-strsim = { version = "0.10.0" }
+strsim.workspace = true
serde.workspace = true
-anyhow = { version = "1.0", optional = true }
+anyhow = { workspace = true, optional = true }
# Serialized stdlib
-bincode = { version = "1.3", optional = true }
+bincode = { workspace = true, optional = true }
# Explaining traces
-annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
+annotate-snippets = { workspace = true, features = ["color"], optional = true }
# Async imports
-async-trait = { version = "0.1.60", optional = true }
+async-trait = { workspace = true, optional = true }
# Bigint
-num-bigint = { version = "0.4.3", features = ["serde"], optional = true }
-derivative = "2.2.0"
+num-bigint = { workspace = true, features = ["serde"], optional = true }
+derivative.workspace = true
crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -20,7 +20,7 @@
jrsonnet-gcmodule.workspace = true
serde = { workspace = true, optional = true }
-structdump = { version = "0.2.0", optional = true }
+structdump = { workspace = true, optional = true }
-rustc-hash = "1.1"
-hashbrown = { version = "0.13.2", features = ["inline-more"] }
+rustc-hash.workspace = true
+hashbrown = { workspace = true, features = ["inline-more"] }
crates/jrsonnet-macros/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-macros/Cargo.toml
+++ b/crates/jrsonnet-macros/Cargo.toml
@@ -11,6 +11,6 @@
proc-macro = true
[dependencies]
-proc-macro2 = "1.0"
-quote = "1.0"
-syn = { version = "1.0", features = ["full"] }
+proc-macro2.workspace = true
+quote.workspace = true
+syn = { workspace = true, features = ["full"] }
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth1use proc_macro2::TokenStream;2use quote::quote;3use syn::{4 parenthesized,5 parse::{Parse, ParseStream},6 parse_macro_input,7 punctuated::Punctuated,8 spanned::Spanned,9 token::{self, Comma},10 Attribute, DeriveInput, Error, Expr, FnArg, GenericArgument, Ident, ItemFn, LitStr, Pat, Path,11 PathArguments, Result, ReturnType, Token, Type,12};1314fn parse_attr<A: Parse, I>(attrs: &[Attribute], ident: I) -> Result<Option<A>>15where16 Ident: PartialEq<I>,17{18 let attrs = attrs19 .iter()20 .filter(|a| a.path.is_ident(&ident))21 .collect::<Vec<_>>();22 if attrs.len() > 1 {23 return Err(Error::new(24 attrs[1].span(),25 "this attribute may be specified only once",26 ));27 } else if attrs.is_empty() {28 return Ok(None);29 }30 let attr = attrs[0];31 let attr = attr.parse_args::<A>()?;3233 Ok(Some(attr))34}3536fn path_is(path: &Path, needed: &str) -> bool {37 path.leading_colon.is_none()38 && !path.segments.is_empty()39 && path.segments.iter().last().unwrap().ident == needed40}4142fn type_is_path<'ty>(ty: &'ty Type, needed: &str) -> Option<&'ty PathArguments> {43 match ty {44 Type::Path(path) if path.qself.is_none() && path_is(&path.path, needed) => {45 let args = &path.path.segments.iter().last().unwrap().arguments;46 Some(args)47 }48 _ => None,49 }50}5152fn extract_type_from_option(ty: &Type) -> Result<Option<&Type>> {53 let Some(args) = type_is_path(ty, "Option") else {54 return Ok(None);55 };56 // It should have only on angle-bracketed param ("<String>"):57 let PathArguments::AngleBracketed(params) = args else {58 return Err(Error::new(args.span(), "missing option generic"));59 };60 let generic_arg = params.args.iter().next().unwrap();61 // This argument must be a type:62 let GenericArgument::Type(ty) = generic_arg else {63 return Err(Error::new(64 generic_arg.span(),65 "option generic should be a type",66 ));67 };68 Ok(Some(ty))69}7071struct Field {72 attrs: Vec<Attribute>,73 name: Ident,74 _colon: Token![:],75 ty: Type,76}77impl Parse for Field {78 fn parse(input: ParseStream) -> syn::Result<Self> {79 Ok(Self {80 attrs: input.call(Attribute::parse_outer)?,81 name: input.parse()?,82 _colon: input.parse()?,83 ty: input.parse()?,84 })85 }86}8788mod kw {89 syn::custom_keyword!(fields);90 syn::custom_keyword!(rename);91 syn::custom_keyword!(flatten);92 syn::custom_keyword!(add);93 syn::custom_keyword!(hide);94 syn::custom_keyword!(ok);95}9697struct EmptyAttr;98impl Parse for EmptyAttr {99 fn parse(_input: ParseStream) -> Result<Self> {100 Ok(Self)101 }102}103104struct BuiltinAttrs {105 fields: Vec<Field>,106}107impl Parse for BuiltinAttrs {108 fn parse(input: ParseStream) -> syn::Result<Self> {109 if input.is_empty() {110 return Ok(Self { fields: Vec::new() });111 }112 input.parse::<kw::fields>()?;113 let fields;114 parenthesized!(fields in input);115 let p = Punctuated::<Field, Comma>::parse_terminated(&fields)?;116 Ok(Self {117 fields: p.into_iter().collect(),118 })119 }120}121122enum ArgInfo {123 Normal {124 ty: Box<Type>,125 is_option: bool,126 name: Option<String>,127 cfg_attrs: Vec<Attribute>,128 },129 Lazy {130 is_option: bool,131 name: Option<String>,132 },133 Context,134 Location,135 This,136}137138impl ArgInfo {139 fn parse(name: &str, arg: &FnArg) -> Result<Self> {140 let FnArg::Typed(arg) = arg else {141 unreachable!()142 };143 let ident = match &arg.pat as &Pat {144 Pat::Ident(i) => Some(i.ident.clone()),145 _ => None,146 };147 let ty = &arg.ty;148 if type_is_path(ty, "Context").is_some() {149 return Ok(Self::Context);150 } else if type_is_path(ty, "CallLocation").is_some() {151 return Ok(Self::Location);152 } else if type_is_path(ty, "Thunk").is_some() {153 return Ok(Self::Lazy {154 is_option: false,155 name: ident.map(|v| v.to_string()),156 });157 }158159 match ty as &Type {160 Type::Reference(r) if type_is_path(&r.elem, name).is_some() => return Ok(Self::This),161 _ => {}162 }163164 let (is_option, ty) = if let Some(ty) = extract_type_from_option(ty)? {165 if type_is_path(ty, "Thunk").is_some() {166 return Ok(Self::Lazy {167 is_option: true,168 name: ident.map(|v| v.to_string()),169 });170 }171172 (true, Box::new(ty.clone()))173 } else {174 (false, ty.clone())175 };176177 let cfg_attrs = arg178 .attrs179 .iter()180 .filter(|a| a.path.is_ident("cfg"))181 .cloned()182 .collect();183184 Ok(Self::Normal {185 ty,186 is_option,187 name: ident.map(|v| v.to_string()),188 cfg_attrs,189 })190 }191}192193#[proc_macro_attribute]194pub fn builtin(195 attr: proc_macro::TokenStream,196 item: proc_macro::TokenStream,197) -> proc_macro::TokenStream {198 let attr = parse_macro_input!(attr as BuiltinAttrs);199 let item_fn = item.clone();200 let item_fn: ItemFn = parse_macro_input!(item_fn);201202 match builtin_inner(attr, item_fn, item.into()) {203 Ok(v) => v.into(),204 Err(e) => e.into_compile_error().into(),205 }206}207208fn builtin_inner(209 attr: BuiltinAttrs,210 fun: ItemFn,211 item: proc_macro2::TokenStream,212) -> syn::Result<TokenStream> {213 let ReturnType::Type(_, result) = &fun.sig.output else {214 return Err(Error::new(215 fun.sig.span(),216 "builtin should return something",217 ));218 };219220 let name = fun.sig.ident.to_string();221 let args = fun222 .sig223 .inputs224 .iter()225 .map(|arg| ArgInfo::parse(&name, arg))226 .collect::<Result<Vec<_>>>()?;227228 let params_desc = args.iter().flat_map(|a| match a {229 ArgInfo::Normal {230 is_option,231 name,232 cfg_attrs,233 ..234 } => {235 let name = name236 .as_ref()237 .map(|n| quote! {ParamName::new_static(#n)})238 .unwrap_or_else(|| quote! {None});239 Some(quote! {240 #(#cfg_attrs)*241 BuiltinParam::new(#name, #is_option),242 })243 }244 ArgInfo::Lazy { is_option, name } => {245 let name = name246 .as_ref()247 .map(|n| quote! {ParamName::new_static(#n)})248 .unwrap_or_else(|| quote! {None});249 Some(quote! {250 BuiltinParam::new(#name, #is_option),251 })252 }253 ArgInfo::Context => None,254 ArgInfo::Location => None,255 ArgInfo::This => None,256 });257258 let mut id = 0usize;259 let pass = args260 .iter()261 .map(|a| match a {262 ArgInfo::Normal { .. } | ArgInfo::Lazy { .. } => {263 let cid = id;264 id += 1;265 (quote! {#cid}, a)266 }267 ArgInfo::Context | ArgInfo::Location | ArgInfo::This => {268 (quote! {compile_error!("should not use id")}, a)269 }270 })271 .map(|(id, a)| match a {272 ArgInfo::Normal {273 ty,274 is_option,275 name,276 cfg_attrs,277 } => {278 let name = name.as_ref().map(|v| v.as_str()).unwrap_or("<unnamed>");279 let eval = quote! {jrsonnet_evaluator::State::push_description(280 || format!("argument <{}> evaluation", #name),281 || <#ty>::from_untyped(value.evaluate()?),282 )?};283 let value = if *is_option {284 quote! {if let Some(value) = &parsed[#id] {285 Some(#eval)286 } else {287 None288 },}289 } else {290 quote! {{291 let value = parsed[#id].as_ref().expect("args shape is checked");292 #eval293 },}294 };295 quote! {296 #(#cfg_attrs)*297 #value298 }299 }300 ArgInfo::Lazy { is_option, .. } => {301 if *is_option {302 quote! {if let Some(value) = &parsed[#id] {303 Some(value.clone())304 } else {305 None306 }}307 } else {308 quote! {309 parsed[#id].as_ref().expect("args shape is correct").clone(),310 }311 }312 }313 ArgInfo::Context => quote! {ctx.clone(),},314 ArgInfo::Location => quote! {location,},315 ArgInfo::This => quote! {self,},316 });317318 let fields = attr.fields.iter().map(|field| {319 let attrs = &field.attrs;320 let name = &field.name;321 let ty = &field.ty;322 quote! {323 #(#attrs)*324 pub #name: #ty,325 }326 });327328 let name = &fun.sig.ident;329 let vis = &fun.vis;330 let static_ext = if attr.fields.is_empty() {331 quote! {332 impl #name {333 pub const INST: &'static dyn StaticBuiltin = &#name {};334 }335 impl StaticBuiltin for #name {}336 }337 } else {338 quote! {}339 };340 let static_derive_copy = if attr.fields.is_empty() {341 quote! {, Copy}342 } else {343 quote! {}344 };345346 Ok(quote! {347 #item348349 #[doc(hidden)]350 #[allow(non_camel_case_types)]351 #[derive(Clone, jrsonnet_gcmodule::Trace #static_derive_copy)]352 #vis struct #name {353 #(#fields)*354 }355 const _: () = {356 use ::jrsonnet_evaluator::{357 State, Val,358 function::{builtin::{Builtin, StaticBuiltin, BuiltinParam, ParamName}, CallLocation, ArgsLike, parse::parse_builtin_call},359 Result, Context, typed::Typed,360 parser::ExprLocation,361 };362 const PARAMS: &'static [BuiltinParam] = &[363 #(#params_desc)*364 ];365366 #static_ext367 impl Builtin for #name368 where369 Self: 'static370 {371 fn name(&self) -> &str {372 stringify!(#name)373 }374 fn params(&self) -> &[BuiltinParam] {375 PARAMS376 }377 fn call(&self, ctx: Context, location: CallLocation, args: &dyn ArgsLike) -> Result<Val> {378 let parsed = parse_builtin_call(ctx.clone(), &PARAMS, args, false)?;379380 let result: #result = #name(#(#pass)*);381 <_ as Typed>::into_result(result)382 }383 fn as_any(&self) -> &dyn ::std::any::Any {384 self385 }386 }387 };388 })389}390391#[derive(Default)]392struct TypedAttr {393 rename: Option<String>,394 flatten: bool,395 /// flatten(ok) strategy for flattened optionals396 /// field would be None in case of any parsing error (as in serde)397 flatten_ok: bool,398 // Should it be `field+:` instead of `field:`399 add: bool,400 // Should it be `field::` instead of `field:`401 hide: bool,402}403impl Parse for TypedAttr {404 fn parse(input: ParseStream) -> syn::Result<Self> {405 let mut out = Self::default();406 loop {407 let lookahead = input.lookahead1();408 if lookahead.peek(kw::rename) {409 input.parse::<kw::rename>()?;410 input.parse::<Token![=]>()?;411 let name = input.parse::<LitStr>()?;412 if out.rename.is_some() {413 return Err(Error::new(414 name.span(),415 "rename attribute may only be specified once",416 ));417 }418 out.rename = Some(name.value());419 } else if lookahead.peek(kw::flatten) {420 input.parse::<kw::flatten>()?;421 out.flatten = true;422 if input.peek(token::Paren) {423 let content;424 parenthesized!(content in input);425 let lookahead = content.lookahead1();426 if lookahead.peek(kw::ok) {427 content.parse::<kw::ok>()?;428 out.flatten_ok = true;429 } else {430 return Err(lookahead.error());431 }432 }433 } else if lookahead.peek(kw::add) {434 input.parse::<kw::add>()?;435 out.add = true;436 } else if lookahead.peek(kw::hide) {437 input.parse::<kw::hide>()?;438 out.hide = true;439 } else if input.is_empty() {440 break;441 } else {442 return Err(lookahead.error());443 }444 if input.peek(Token![,]) {445 input.parse::<Token![,]>()?;446 } else {447 break;448 }449 }450 Ok(out)451 }452}453454struct TypedField {455 attr: TypedAttr,456 ident: Ident,457 ty: Type,458 is_option: bool,459}460impl TypedField {461 fn parse(field: &syn::Field) -> Result<Self> {462 let attr = parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_default();463 let Some(ident) = field.ident.clone() else {464 return Err(Error::new(465 field.span(),466 "this field should appear in output object, but it has no visible name",467 ));468 };469 let (is_option, ty) = if let Some(ty) = extract_type_from_option(&field.ty)? {470 (true, ty.clone())471 } else {472 (false, field.ty.clone())473 };474 if is_option && attr.flatten {475 if !attr.flatten_ok {476 return Err(Error::new(477 field.span(),478 "strategy should be set when flattening Option",479 ));480 }481 } else if attr.flatten_ok {482 return Err(Error::new(483 field.span(),484 "flatten(ok) is only useable on optional fields",485 ));486 }487488 Ok(Self {489 attr,490 ident,491 ty,492 is_option,493 })494 }495 /// None if this field is flattened in jsonnet output496 fn name(&self) -> Option<String> {497 if self.attr.flatten {498 return None;499 }500 Some(501 self.attr502 .rename503 .clone()504 .unwrap_or_else(|| self.ident.to_string()),505 )506 }507508 fn expand_field(&self) -> Option<TokenStream> {509 if self.is_option {510 return None;511 }512 let name = self.name()?;513 let ty = &self.ty;514 Some(quote! {515 (#name, <#ty as Typed>::TYPE)516 })517 }518 fn expand_parse(&self) -> TokenStream {519 let ident = &self.ident;520 let ty = &self.ty;521 if self.attr.flatten {522 // optional flatten is handled in same way as serde523 return if self.is_option {524 quote! {525 #ident: <#ty as TypedObj>::parse(&obj).ok(),526 }527 } else {528 quote! {529 #ident: <#ty as TypedObj>::parse(&obj)?,530 }531 };532 };533534 let name = self.name().unwrap();535 let value = if self.is_option {536 quote! {537 if let Some(value) = obj.get(#name.into())? {538 Some(<#ty as Typed>::from_untyped(value)?)539 } else {540 None541 }542 }543 } else {544 quote! {545 <#ty as Typed>::from_untyped(obj.get(#name.into())?.ok_or_else(|| ErrorKind::NoSuchField(#name.into(), vec![]))?)?546 }547 };548549 quote! {550 #ident: #value,551 }552 }553 fn expand_serialize(&self) -> Result<TokenStream> {554 let ident = &self.ident;555 let ty = &self.ty;556 Ok(if let Some(name) = self.name() {557 let hide = if self.attr.hide {558 quote! {.hide()}559 } else {560 quote! {}561 };562 let add = if self.attr.add {563 quote! {.add()}564 } else {565 quote! {}566 };567 if self.is_option {568 quote! {569 if let Some(value) = self.#ident {570 out.field(#name)571 #hide572 #add573 .try_value(<#ty as Typed>::into_untyped(value)?)?;574 }575 }576 } else {577 quote! {578 out.field(#name)579 #hide580 #add581 .try_value(<#ty as Typed>::into_untyped(self.#ident)?)?;582 }583 }584 } else if self.is_option {585 quote! {586 if let Some(value) = self.#ident {587 <#ty as TypedObj>::serialize(value, out)?;588 }589 }590 } else {591 quote! {592 <#ty as TypedObj>::serialize(self.#ident, out)?;593 }594 })595 }596}597598#[proc_macro_derive(Typed, attributes(typed))]599pub fn derive_typed(item: proc_macro::TokenStream) -> proc_macro::TokenStream {600 let input = parse_macro_input!(item as DeriveInput);601602 match derive_typed_inner(input) {603 Ok(v) => v.into(),604 Err(e) => e.to_compile_error().into(),605 }606}607608fn derive_typed_inner(input: DeriveInput) -> Result<TokenStream> {609 let syn::Data::Struct(data) = &input.data else {610 return Err(Error::new(input.span(), "only structs supported"));611 };612613 let ident = &input.ident;614 let fields = data615 .fields616 .iter()617 .map(TypedField::parse)618 .collect::<Result<Vec<_>>>()?;619620 let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();621622 let typed = {623 let fields = fields624 .iter()625 .flat_map(TypedField::expand_field)626 .collect::<Vec<_>>();627 quote! {628 impl #impl_generics Typed for #ident #ty_generics #where_clause {629 const TYPE: &'static ComplexValType = &ComplexValType::ObjectRef(&[630 #(#fields,)*631 ]);632633 fn from_untyped(value: Val) -> JrResult<Self> {634 let obj = value.as_obj().expect("shape is correct");635 Self::parse(&obj)636 }637638 fn into_untyped(value: Self) -> JrResult<Val> {639 let mut out = ObjValueBuilder::new();640 value.serialize(&mut out)?;641 Ok(Val::Obj(out.build()))642 }643644 }645 }646 };647648 let fields_parse = fields.iter().map(TypedField::expand_parse);649 let fields_serialize = fields650 .iter()651 .map(TypedField::expand_serialize)652 .collect::<Result<Vec<_>>>()?;653654 Ok(quote! {655 const _: () = {656 use ::jrsonnet_evaluator::{657 typed::{ComplexValType, Typed, TypedObj, CheckType},658 Val, State,659 error::{ErrorKind, Result as JrResult},660 ObjValueBuilder, ObjValue,661 };662663 #typed664665 impl #impl_generics TypedObj for #ident #ty_generics #where_clause {666 fn serialize(self, out: &mut ObjValueBuilder) -> JrResult<()> {667 #(#fields_serialize)*668669 Ok(())670 }671 fn parse(obj: &ObjValue) -> JrResult<Self> {672 Ok(Self {673 #(#fields_parse)*674 })675 }676 }677 };678 })679}680681struct FormatInput {682 formatting: LitStr,683 arguments: Vec<Expr>,684}685impl Parse for FormatInput {686 fn parse(input: ParseStream) -> Result<Self> {687 let formatting = input.parse()?;688 let mut arguments = Vec::new();689690 while input.peek(Token![,]) {691 input.parse::<Token![,]>()?;692 if input.is_empty() {693 // Trailing comma694 break;695 }696 let expr = input.parse()?;697 arguments.push(expr);698 }699700 if !input.is_empty() {701 return Err(syn::Error::new(input.span(), "unexpected trailing input"));702 }703704 Ok(Self {705 formatting,706 arguments,707 })708 }709}710fn is_format_str(i: &str) -> bool {711 let mut is_plain = true;712 // -1 = {713 // +1 = }714 let mut is_bracket = 0i8;715 for ele in i.chars() {716 match ele {717 '{' if is_bracket == -1 => {718 is_bracket = 0;719 }720 '}' if is_bracket == -1 => {721 is_plain = false;722 break;723 }724 '}' if is_bracket == 1 => {725 is_bracket = 0;726 }727 '{' if is_bracket == 1 => {728 is_plain = false;729 break;730 }731 '{' => {732 is_bracket = -1;733 }734 '}' => {735 is_bracket = 1;736 }737 _ if is_bracket != 0 => {738 is_plain = false;739 break;740 }741 _ => {}742 }743 }744 !is_plain || is_bracket != 0745}746impl FormatInput {747 fn expand(self) -> TokenStream {748 let format = self.formatting;749 if is_format_str(&format.value()) {750 let args = self.arguments;751 quote! {752 ::jrsonnet_evaluator::IStr::from(format!(#format #(, #args)*))753 }754 } else {755 if let Some(first) = self.arguments.first() {756 return syn::Error::new(757 first.span(),758 "string has no formatting codes, it should not have the arguments",759 )760 .into_compile_error();761 }762 quote! {763 ::jrsonnet_evaluator::IStr::from(#format)764 }765 }766 }767}768769/// IStr formatting helper770///771/// Using `format!("literal with no codes").into()` is slower than just `"literal with no codes".into()`772/// This macro looks for formatting codes in the input string, and uses773/// `format!()` only when necessary774#[proc_macro]775pub fn format_istr(input: proc_macro::TokenStream) -> proc_macro::TokenStream {776 let input = parse_macro_input!(input as FormatInput);777 input.expand().into()778}crates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -31,9 +31,9 @@
jrsonnet-interner.workspace = true
jrsonnet-gcmodule.workspace = true
-static_assertions = "1.1"
+static_assertions.workspace = true
-peg = "0.8.1"
+peg.workspace = true
serde = { workspace = true, features = ["derive", "rc"], optional = true }
-structdump = { version = "0.2.0", features = ["derive"], optional = true }
+structdump = { workspace = true, features = ["derive"], optional = true }
crates/jrsonnet-rowan-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/Cargo.toml
+++ b/crates/jrsonnet-rowan-parser/Cargo.toml
@@ -4,18 +4,16 @@
edition = "2021"
[dependencies]
-anyhow = "1.0"
-backtrace = "0.3.63"
-drop_bomb = "0.1.5"
-indoc = "1.0"
-logos = "0.12"
-miette = { version = "5.5.0", features = ["fancy"] }
-rowan = "0.15"
-text-size = "1.1"
-thiserror = "1.0"
+anyhow.workspace = true
+drop_bomb.workspace = true
+indoc.workspace = true
+logos.workspace = true
+miette = { workspace = true, features = ["fancy"] }
+rowan.workspace = true
+text-size.workspace = true
+thiserror.workspace = true
[dev-dependencies]
-backtrace = "0.3.63"
-indoc = "1.0"
-insta = "1.15"
-anyhow = "1.0"
+indoc.workspace = true
+insta.workspace = true
+anyhow.workspace = true
crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -28,27 +28,27 @@
jrsonnet-gcmodule.workspace = true
# Used for stdlib AST serialization
-bincode = { version = "1.3", optional = true }
+bincode = { workspace = true, optional = true }
# Used both for stdlib AST serialization and std.parseJson/std.parseYaml
serde.workspace = true
# std.md5
-md5 = "0.7.0"
+md5.workspace = true
# std.sha1
-sha1 = "0.10.5"
+sha1.workspace = true
# std.sha256, std.sha512
-sha2 = "0.10.6"
+sha2.workspace = true
# std.sha3
-sha3 = "0.10.8"
+sha3.workspace = true
# std.base64
-base64 = "0.21.0"
+base64.workspace = true
# std.parseJson
-serde_json = "1.0"
+serde_json.workspace = true
# std.parseYaml, custom library fork is used for C++/golang compatibility
-serde_yaml_with_quirks = "0.8.24"
+serde_yaml_with_quirks.workspace = true
-num-bigint = { version = "0.4.3", optional = true }
+num-bigint = { workspace = true, optional = true }
[build-dependencies]
jrsonnet-parser.workspace = true
-structdump = { version = "0.2.0", features = ["derive"] }
+structdump = { workspace = true, features = ["derive"] }
crates/jrsonnet-types/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -10,7 +10,7 @@
[dependencies]
jrsonnet-gcmodule.workspace = true
-peg = "0.8.1"
+peg.workspace = true
[features]
exp-bigint = []
xtask/Cargo.tomldiffbeforeafterboth--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -4,10 +4,10 @@
edition = "2021"
[dependencies]
-anyhow = "1.0.57"
-indexmap = "1.9.0"
-itertools = "0.10.3"
-proc-macro2 = "1.0.39"
-quote = "1.0.18"
-ungrammar = "1.16.1"
-xshell = "0.2.2"
+anyhow.workspace = true
+indexmap.workspace = true
+itertools.workspace = true
+proc-macro2.workspace = true
+quote.workspace = true
+ungrammar.workspace = true
+xshell.workspace = true