difftreelog
build upgrade to 2021 edition
in: master
13 files changed
bindings/jsonnet/Cargo.tomldiffbeforeafterboth--- a/bindings/jsonnet/Cargo.toml
+++ b/bindings/jsonnet/Cargo.toml
@@ -4,7 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
publish = false
[dependencies]
cmds/jrsonnet/Cargo.tomldiffbeforeafterboth--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -4,8 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
-publish = false
+edition = "2021"
[features]
# Use mimalloc as allocator
crates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -4,8 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
-publish = false
+edition = "2021"
[dependencies]
jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2", features = [
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -4,7 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
[features]
default = ["serialized-stdlib", "explaining-traces"]
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -7,7 +7,7 @@
operator::evaluate_mod_op,
primitive_equals, push_frame, throw,
typed::{Either2, Either4},
- with_state, ArrValue, Context, FuncVal, IndexableVal, Val,
+ with_state, ArrValue, FuncVal, IndexableVal, Val,
};
use crate::{Either, ObjValue};
use format::{format_arr, format_obj};
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -23,6 +23,8 @@
pub mod typed;
mod val;
+pub use jrsonnet_parser as parser;
+
pub use ctx::*;
pub use dynamic::*;
use error::{Error::*, LocError, Result, StackTraceElement};
@@ -175,7 +177,7 @@
pub(crate) fn with_state<T>(f: impl FnOnce(&EvaluationState) -> T) -> T {
EVAL_STATE.with(|s| f(s.borrow().as_ref().unwrap()))
}
-pub(crate) fn push_frame<T>(
+pub fn push_frame<T>(
e: Option<&ExprLocation>,
frame_desc: impl FnOnce() -> String,
f: impl FnOnce() -> Result<T>,
@@ -184,7 +186,7 @@
}
#[allow(dead_code)]
-pub(crate) fn push_val_frame(
+pub fn push_val_frame(
e: &ExprLocation,
frame_desc: impl FnOnce() -> String,
f: impl FnOnce() -> Result<Val>,
@@ -192,7 +194,7 @@
with_state(|s| s.push_val(e, frame_desc, f))
}
#[allow(dead_code)]
-pub(crate) fn push_description_frame<T>(
+pub fn push_description_frame<T>(
frame_desc: impl FnOnce() -> String,
f: impl FnOnce() -> Result<T>,
) -> Result<T> {
crates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -13,9 +13,9 @@
#[macro_export]
macro_rules! unwrap_type {
- ($desc: expr, $value: expr, $typ: expr => $match: path) => {{
- use $crate::{push_stack_frame, typed::CheckType};
- push_stack_frame(None, $desc, || Ok($typ.check(&$value)?))?;
+ ($desc:expr, $value:expr, $typ:expr => $match:path) => {{
+ use $crate::{push_frame, typed::CheckType};
+ push_frame(None, $desc, || Ok($typ.check(&$value)?))?;
match $value {
$match(v) => v,
_ => unreachable!(),
crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -4,7 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
[dependencies]
serde = { version = "1.0" }
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth1use quote::quote;2use syn::{3 parse_macro_input, FnArg, GenericArgument, ItemFn, Pat, PatType, Path, PathArguments, Type,4};56fn is_location_arg(t: &PatType) -> bool {7 t.attrs.iter().any(|a| a.path.is_ident("location"))8}910trait RetainHad<T> {11 fn retain_had(&mut self, h: impl FnMut(&T) -> bool) -> bool;12}13impl<T> RetainHad<T> for Vec<T> {14 fn retain_had(&mut self, h: impl FnMut(&T) -> bool) -> bool {15 let before = self.len();16 self.retain(h);17 let after = self.len();18 before != after19 }20}2122fn extract_type_from_option(ty: &Type) -> Option<&Type> {23 fn path_is_option(path: &Path) -> bool {24 path.leading_colon.is_none()25 && path.segments.len() == 126 && path.segments.iter().next().unwrap().ident == "Option"27 }2829 match ty {30 Type::Path(typepath) if typepath.qself.is_none() && path_is_option(&typepath.path) => {31 // Get the first segment of the path (there is only one, in fact: "Option"):32 let type_params = &typepath.path.segments.iter().next().unwrap().arguments;33 // It should have only on angle-bracketed param ("<String>"):34 let generic_arg = match type_params {35 PathArguments::AngleBracketed(params) => params.args.iter().next().unwrap(),36 _ => panic!("missing option generic"),37 };38 // This argument must be a type:39 match generic_arg {40 GenericArgument::Type(ty) => Some(ty),41 _ => panic!("option generic should be a type"),42 }43 }44 _ => None,45 }46}4748#[proc_macro_attribute]49pub fn builtin(50 _attr: proc_macro::TokenStream,51 item: proc_macro::TokenStream,52) -> proc_macro::TokenStream {53 // syn::ItemFn::parse(input)54 let mut fun: ItemFn = parse_macro_input!(item);5556 let result = match fun.sig.output {57 syn::ReturnType::Default => panic!("builtin should return something"),58 syn::ReturnType::Type(_, ref ty) => ty.clone(),59 };6061 let params = fun62 .sig63 .inputs64 .iter()65 .map(|i| match i {66 FnArg::Receiver(_) => unreachable!(),67 FnArg::Typed(t) => t,68 })69 .filter(|a| !is_location_arg(a))70 .map(|t| {71 let ident = match &t.pat as &Pat {72 Pat::Ident(i) => i.ident.to_string(),73 _ => panic!("only idents supported yet"),74 };75 let optional = extract_type_from_option(&t.ty).is_some();76 quote! {77 BuiltinParam {78 name: std::borrow::Cow::Borrowed(#ident),79 has_default: #optional,80 }81 }82 })83 .collect::<Vec<_>>();8485 let args = fun86 .sig87 .inputs88 .iter_mut()89 .map(|i| match i {90 FnArg::Receiver(_) => unreachable!(),91 FnArg::Typed(t) => t,92 })93 .map(|t| {94 let is_location = t.attrs.retain_had(|a| !a.path.is_ident("location"));95 if is_location {96 quote! {{97 loc98 }}99 } else {100 let ident = match &t.pat as &Pat {101 Pat::Ident(i) => i.ident.to_string(),102 _ => panic!("only idents supported yet"),103 };104 let ty = &t.ty;105 if let Some(opt_ty) = extract_type_from_option(&t.ty) {106 quote! {{107 if let Some(value) = parsed.get(#ident) {108 Some(::jrsonnet_evaluator::push_description_frame(109 || format!("argument <{}> evaluation", #ident),110 || <#opt_ty>::try_from(value.evaluate()?),111 )?)112 } else {113 None114 }115 }}116 } else {117 quote! {{118 let value = parsed.get(#ident).unwrap();119120 ::jrsonnet_evaluator::push_description_frame(121 || format!("argument <{}> evaluation", #ident),122 || <#ty>::try_from(value.evaluate()?),123 )?124 }}125 }126 }127 })128 .collect::<Vec<_>>();129130 let name = &fun.sig.ident;131 let vis = &fun.vis;132 (quote! {133 #fun134 #[doc(hidden)]135 #[allow(non_camel_case_types)]136 #[derive(Clone, Copy, gcmodule::Trace)]137 #vis struct #name {}138 const _: () = {139 use ::jrsonnet_evaluator::function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike};140 const PARAMS: &'static [BuiltinParam] = &[141 #(#params),*142 ];143144 impl #name {145 pub const INST: &'static dyn StaticBuiltin = &#name {};146 }147 impl StaticBuiltin for #name {}148 impl Builtin for #name149 where150 Self: 'static151 {152 fn name(&self) -> &str {153 stringify!(#name)154 }155 fn params(&self) -> &[BuiltinParam] {156 PARAMS157 }158 fn call(&self, context: Context, loc: Option<&ExprLocation>, args: &dyn ArgsLike) -> Result<Val> {159 let parsed = ::jrsonnet_evaluator::function::parse_builtin_call(context, &PARAMS, args, false)?;160161 let result: #result = #name(#(#args),*);162 let result = result?;163 result.try_into()164 }165 }166 };167 })168 .into()169}1use quote::quote;2use syn::{3 parse_macro_input, FnArg, GenericArgument, ItemFn, Pat, PatType, Path, PathArguments, Type,4};56fn is_location_arg(t: &PatType) -> bool {7 t.attrs.iter().any(|a| a.path.is_ident("location"))8}910trait RetainHad<T> {11 fn retain_had(&mut self, h: impl FnMut(&T) -> bool) -> bool;12}13impl<T> RetainHad<T> for Vec<T> {14 fn retain_had(&mut self, h: impl FnMut(&T) -> bool) -> bool {15 let before = self.len();16 self.retain(h);17 let after = self.len();18 before != after19 }20}2122fn extract_type_from_option(ty: &Type) -> Option<&Type> {23 fn path_is_option(path: &Path) -> bool {24 path.leading_colon.is_none()25 && path.segments.len() == 126 && path.segments.iter().next().unwrap().ident == "Option"27 }2829 match ty {30 Type::Path(typepath) if typepath.qself.is_none() && path_is_option(&typepath.path) => {31 // Get the first segment of the path (there is only one, in fact: "Option"):32 let type_params = &typepath.path.segments.iter().next().unwrap().arguments;33 // It should have only on angle-bracketed param ("<String>"):34 let generic_arg = match type_params {35 PathArguments::AngleBracketed(params) => params.args.iter().next().unwrap(),36 _ => panic!("missing option generic"),37 };38 // This argument must be a type:39 match generic_arg {40 GenericArgument::Type(ty) => Some(ty),41 _ => panic!("option generic should be a type"),42 }43 }44 _ => None,45 }46}4748#[proc_macro_attribute]49pub fn builtin(50 _attr: proc_macro::TokenStream,51 item: proc_macro::TokenStream,52) -> proc_macro::TokenStream {53 // syn::ItemFn::parse(input)54 let mut fun: ItemFn = parse_macro_input!(item);5556 let result = match fun.sig.output {57 syn::ReturnType::Default => panic!("builtin should return something"),58 syn::ReturnType::Type(_, ref ty) => ty.clone(),59 };6061 let params = fun62 .sig63 .inputs64 .iter()65 .map(|i| match i {66 FnArg::Receiver(_) => unreachable!(),67 FnArg::Typed(t) => t,68 })69 .filter(|a| !is_location_arg(a))70 .map(|t| {71 let ident = match &t.pat as &Pat {72 Pat::Ident(i) => i.ident.to_string(),73 _ => panic!("only idents supported yet"),74 };75 let optional = extract_type_from_option(&t.ty).is_some();76 quote! {77 BuiltinParam {78 name: std::borrow::Cow::Borrowed(#ident),79 has_default: #optional,80 }81 }82 })83 .collect::<Vec<_>>();8485 let args = fun86 .sig87 .inputs88 .iter_mut()89 .map(|i| match i {90 FnArg::Receiver(_) => unreachable!(),91 FnArg::Typed(t) => t,92 })93 .map(|t| {94 let is_location = t.attrs.retain_had(|a| !a.path.is_ident("location"));95 if is_location {96 quote! {{97 loc98 }}99 } else {100 let ident = match &t.pat as &Pat {101 Pat::Ident(i) => i.ident.to_string(),102 _ => panic!("only idents supported yet"),103 };104 let ty = &t.ty;105 if let Some(opt_ty) = extract_type_from_option(&t.ty) {106 quote! {{107 if let Some(value) = parsed.get(#ident) {108 Some(::jrsonnet_evaluator::push_description_frame(109 || format!("argument <{}> evaluation", #ident),110 || <#opt_ty>::try_from(value.evaluate()?),111 )?)112 } else {113 None114 }115 }}116 } else {117 quote! {{118 let value = parsed.get(#ident).unwrap();119120 ::jrsonnet_evaluator::push_description_frame(121 || format!("argument <{}> evaluation", #ident),122 || <#ty>::try_from(value.evaluate()?),123 )?124 }}125 }126 }127 })128 .collect::<Vec<_>>();129130 let name = &fun.sig.ident;131 let vis = &fun.vis;132 (quote! {133 #fun134 #[doc(hidden)]135 #[allow(non_camel_case_types)]136 #[derive(Clone, Copy, gcmodule::Trace)]137 #vis struct #name {}138 const _: () = {139 use ::jrsonnet_evaluator::{140 function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike, parse_builtin_call},141 error::Result, Context,142 parser::ExprLocation,143 };144 const PARAMS: &'static [BuiltinParam] = &[145 #(#params),*146 ];147148 impl #name {149 pub const INST: &'static dyn StaticBuiltin = &#name {};150 }151 impl StaticBuiltin for #name {}152 impl Builtin for #name153 where154 Self: 'static155 {156 fn name(&self) -> &str {157 stringify!(#name)158 }159 fn params(&self) -> &[BuiltinParam] {160 PARAMS161 }162 fn call(&self, context: Context, loc: Option<&ExprLocation>, args: &dyn ArgsLike) -> Result<Val> {163 let parsed = parse_builtin_call(context, &PARAMS, args, false)?;164165 let result: #result = #name(#(#args),*);166 let result = result?;167 result.try_into()168 }169 }170 };171 })172 .into()173}crates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -4,7 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
[features]
default = []
@@ -14,7 +14,7 @@
[dependencies]
jrsonnet-interner = { path = "../jrsonnet-interner", version = "0.4.2" }
-peg = "0.7.0"
+peg = "0.8.0"
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -114,8 +114,8 @@
/ "\\x" hex_char() hex_char()
/ ['\\'] (quiet! { ['b' | 'f' | 'n' | 'r' | 't'] / c() } / expected!("<escape character>"))
pub rule string() -> String
- = ['"'] str:$(string_char(<['"']>)*) ['"'] {? unescape::unescape(str).ok_or("<escaped string>")}
- / ['\''] str:$(string_char(<['\'']>)*) ['\''] {? unescape::unescape(str).ok_or("<escaped string>")}
+ = ['"'] str:$(string_char(<"\"">)*) ['"'] {? unescape::unescape(str).ok_or("<escaped string>")}
+ / ['\''] str:$(string_char(<"\'">)*) ['\''] {? unescape::unescape(str).ok_or("<escaped string>")}
/ quiet!{ "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}
/ "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}
/ string_block() } / expected!("<string>")
crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -4,7 +4,7 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
[features]
crates/jrsonnet-types/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -4,8 +4,8 @@
version = "0.4.2"
authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
license = "MIT"
-edition = "2018"
+edition = "2021"
[dependencies]
-peg = "0.7.0"
+peg = "0.8.0"
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }