difftreelog
refactor cleanup
in: master
9 files changed
bindings/jsonnet/src/lib.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -45,8 +45,8 @@
/// If this does not match `LIB_JSONNET_VERSION`
/// then there is a mismatch between header and compiled library.
#[no_mangle]
-pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {
- b"v0.20.0\0"
+pub extern "C" fn jsonnet_version() -> &'static [u8; 12] {
+ b"v0.22.0-rc1\0"
}
unsafe fn parse_path(input: &CStr) -> Cow<'_, Path> {
crates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth4use jrsonnet_gcmodule::Acyclic;4use jrsonnet_gcmodule::Acyclic;5use jrsonnet_ir::visit::Visitor;5use jrsonnet_ir::visit::Visitor;6use jrsonnet_ir::{6use jrsonnet_ir::{IStr, Source, SourcePath};7 ArgsDesc, AssertExpr, AssertStmt, BindSpec, CompSpec, Destruct, Expr, ExprParam, ExprParams,8 FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData, ImportKind, ObjBody, Slice,9 SliceDesc, Source, SourcePath, Spanned,10};11use rustc_hash::FxHashMap;7use rustc_hash::FxHashMap;12823 self.0.push(Import {19 self.0.push(Import {24 path: ResolvePathOwned::Str(value.to_string()),20 path: ResolvePathOwned::Str(value.to_string()),25 expression,21 expression,26 })22 });27 }23 }28}24}2925crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -5,7 +5,7 @@
extern crate self as jrsonnet_evaluator;
mod arr;
-// pub mod async_import;
+pub mod async_import;
mod ctx;
mod dynamic;
pub mod error;
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -1,5 +1,13 @@
use std::{
- any::Any, cell::{Cell, RefCell}, clone::Clone, cmp::Reverse, collections::hash_map::Entry, fmt::{self, Debug}, hash::{Hash, Hasher}, num::Saturating, ops::ControlFlow
+ any::Any,
+ cell::{Cell, RefCell},
+ clone::Clone,
+ cmp::Reverse,
+ collections::hash_map::Entry,
+ fmt::{self, Debug},
+ hash::{Hash, Hasher},
+ num::Saturating,
+ ops::ControlFlow,
};
use educe::Educe;
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -3,9 +3,9 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_ir::{
unescape, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec,
- Destruct, DestructRest, Expr, ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr,
- IfElse, IfSpecData, ImportKind, IndexPart, LiteralType, Member, ObjBody, ObjComp, ObjMembers,
- Slice, SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility,
+ Destruct, Expr, ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse,
+ IfSpecData, ImportKind, IndexPart, LiteralType, Member, ObjBody, ObjComp, ObjMembers, Slice,
+ SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility,
};
use jrsonnet_lexer::{collect_lexed_str_block, Lexeme, Lexer, SyntaxKind, T};
@@ -30,7 +30,7 @@
}
}
-type R<T> = Result<T, ParseError>;
+type Result<T> = std::result::Result<T, ParseError>;
struct Parser<'a> {
lexemes: Vec<Lexeme<'a>>,
@@ -103,7 +103,7 @@
}
}
- fn eat(&mut self, t: SyntaxKind) -> R<()> {
+ fn eat(&mut self, t: SyntaxKind) -> Result<()> {
if !self.at(t) {
return Err(self.error(format!(
"expected {}, got {}",
@@ -138,15 +138,13 @@
}
}
- fn expect_ident(&mut self) -> R<IStr> {
+ fn expect_ident(&mut self) -> Result<IStr> {
if !self.at(SyntaxKind::IDENT) {
return Err(self.error(format!("expected identifier, got {}", self.current_desc())));
}
let text = self.text();
if is_reserved(text) {
- return Err(self.error(format!(
- "expected identifier, got reserved word '{text}'"
- )));
+ return Err(self.error(format!("expected identifier, got reserved word '{text}'")));
}
let s: IStr = text.into();
self.eat_any();
@@ -164,36 +162,38 @@
"assert"
| "else" | "error"
| "false" | "for"
- | "function" | "if"
- | "import" | "importstr"
- | "importbin" | "in"
- | "local" | "null"
- | "tailstrict" | "then"
- | "self" | "super"
- | "true"
+ | "function"
+ | "if" | "import"
+ | "importstr"
+ | "importbin"
+ | "in" | "local"
+ | "null" | "tailstrict"
+ | "then" | "self"
+ | "super" | "true"
)
}
-fn spanned<T: Acyclic>(p: &mut Parser<'_>, cb: impl FnOnce(&mut Parser<'_>) -> R<T>) -> R<Spanned<T>> {
+fn spanned<T: Acyclic>(
+ p: &mut Parser<'_>,
+ cb: impl FnOnce(&mut Parser<'_>) -> Result<T>,
+) -> Result<Spanned<T>> {
let start = p.span_start();
let v = cb(p)?;
let end = p.span_end();
Ok(Spanned::new(v, Span(p.source.clone(), start, end)))
}
-fn parse_string_content(p: &mut Parser<'_>) -> R<IStr> {
+fn parse_string_content(p: &mut Parser<'_>) -> Result<IStr> {
let kind = p.peek();
let text = p.text();
let s = match kind {
SyntaxKind::STRING_DOUBLE => {
let inner = &text[1..text.len() - 1];
- unescape::unescape(inner)
- .ok_or_else(|| p.error("invalid string escape".into()))?
+ unescape::unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?
}
SyntaxKind::STRING_SINGLE => {
let inner = &text[1..text.len() - 1];
- unescape::unescape(inner)
- .ok_or_else(|| p.error("invalid string escape".into()))?
+ unescape::unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?
}
SyntaxKind::STRING_DOUBLE_VERBATIM => {
let inner = &text[2..text.len() - 1];
@@ -236,7 +236,7 @@
)
}
-fn parse_number(p: &mut Parser<'_>) -> R<f64> {
+fn parse_number(p: &mut Parser<'_>) -> Result<f64> {
let text = p.text();
let n: f64 = text
.replace('_', "")
@@ -263,7 +263,7 @@
Some(t)
}
-fn assert_stmt(p: &mut Parser<'_>) -> R<AssertStmt> {
+fn assert_stmt(p: &mut Parser<'_>) -> Result<AssertStmt> {
p.eat(T![assert])?;
let cond = spanned(p, expr)?;
let msg = if p.try_eat(T![:]) {
@@ -274,13 +274,13 @@
Ok(AssertStmt(cond, msg))
}
-fn if_spec_data(p: &mut Parser<'_>) -> R<IfSpecData> {
+fn if_spec_data(p: &mut Parser<'_>) -> Result<IfSpecData> {
let v = spanned(p, |p| p.eat(T![if]))?;
let cond = expr(p)?;
Ok(IfSpecData { span: v.span, cond })
}
-fn if_else(p: &mut Parser<'_>) -> R<IfElse> {
+fn if_else(p: &mut Parser<'_>) -> Result<IfElse> {
let cond = if_spec_data(p)?;
p.eat(T![then])?;
let cond_then = expr(p)?;
@@ -296,7 +296,7 @@
})
}
-fn slice_desc(p: &mut Parser<'_>, start: Option<Spanned<Expr>>) -> R<SliceDesc> {
+fn slice_desc(p: &mut Parser<'_>, start: Option<Spanned<Expr>>) -> Result<SliceDesc> {
p.eat(T![:])?;
let end = if !p.at(T![:]) && !p.at(T![']']) {
Some(spanned(p, expr)?)
@@ -315,15 +315,12 @@
Ok(SliceDesc { start, end, step })
}
-fn destruct(p: &mut Parser<'_>) -> R<Destruct> {
+fn destruct(p: &mut Parser<'_>) -> Result<Destruct> {
if p.at_ident() {
return Ok(Destruct::Full(p.expect_ident()?));
}
#[cfg(not(feature = "exp-destruct"))]
- return Err(p.error(format!(
- "expected identifier, got {}",
- p.current_desc()
- )));
+ return Err(p.error(format!("expected identifier, got {}", p.current_desc())));
#[cfg(feature = "exp-destruct")]
{
if p.try_eat(T![?]) {
@@ -343,17 +340,17 @@
}
#[cfg(feature = "exp-destruct")]
-fn destruct_rest(p: &mut Parser<'_>) -> R<DestructRest> {
+fn destruct_rest(p: &mut Parser<'_>) -> Result<jrsonnet_ir::DestructRest> {
p.eat(T![...])?;
if p.at_ident() {
- Ok(DestructRest::Keep(p.expect_ident()?))
+ Ok(jrsonnet_ir::DestructRest::Keep(p.expect_ident()?))
} else {
- Ok(DestructRest::Drop)
+ Ok(jrsonnet_ir::DestructRest::Drop)
}
}
#[cfg(feature = "exp-destruct")]
-fn destruct_array(p: &mut Parser<'_>) -> R<Destruct> {
+fn destruct_array(p: &mut Parser<'_>) -> Result<Destruct> {
p.eat(T!['['])?;
let mut start = Vec::new();
let mut rest = None;
@@ -391,7 +388,7 @@
}
#[cfg(feature = "exp-destruct")]
-fn destruct_object(p: &mut Parser<'_>) -> R<Destruct> {
+fn destruct_object(p: &mut Parser<'_>) -> Result<Destruct> {
p.eat(T!['{'])?;
let mut fields = Vec::new();
let mut rest = None;
@@ -426,7 +423,7 @@
Ok(Destruct::Object { fields, rest })
}
-fn params(p: &mut Parser<'_>) -> R<ExprParams> {
+fn params(p: &mut Parser<'_>) -> Result<ExprParams> {
if p.at(T![')']) {
return Ok(ExprParams::new(Vec::new()));
}
@@ -452,7 +449,7 @@
Ok(ExprParams::new(result))
}
-fn args(p: &mut Parser<'_>) -> R<ArgsDesc> {
+fn args(p: &mut Parser<'_>) -> Result<ArgsDesc> {
if p.at(T![')']) {
return Ok(ArgsDesc::new(Vec::new(), Vec::new()));
}
@@ -489,7 +486,7 @@
Ok(ArgsDesc::new(unnamed, named))
}
-fn bind(p: &mut Parser<'_>) -> R<BindSpec> {
+fn bind(p: &mut Parser<'_>) -> Result<BindSpec> {
#[cfg(feature = "exp-destruct")]
{
if !p.at_ident() {
@@ -520,7 +517,7 @@
}
}
-fn visibility(p: &mut Parser<'_>) -> R<Visibility> {
+fn visibility(p: &mut Parser<'_>) -> Result<Visibility> {
p.eat(T![:])?;
if p.try_eat(T![:]) {
if p.try_eat(T![:]) {
@@ -533,7 +530,7 @@
}
}
-fn field_name(p: &mut Parser<'_>) -> R<FieldName> {
+fn field_name(p: &mut Parser<'_>) -> Result<FieldName> {
if p.at_ident() {
Ok(FieldName::Fixed(p.expect_ident()?))
} else if is_string_token(p.peek()) {
@@ -548,7 +545,7 @@
}
}
-fn field(p: &mut Parser<'_>) -> R<FieldMember> {
+fn field(p: &mut Parser<'_>) -> Result<FieldMember> {
let name = spanned(p, field_name)?;
if p.at(T!['(']) {
@@ -578,7 +575,7 @@
}
}
-fn member(p: &mut Parser<'_>) -> R<Member> {
+fn member(p: &mut Parser<'_>) -> Result<Member> {
if p.at(T![local]) {
p.eat(T![local])?;
Ok(Member::BindStmt(bind(p)?))
@@ -589,7 +586,7 @@
}
}
-fn for_spec(p: &mut Parser<'_>) -> R<ForSpecData> {
+fn for_spec(p: &mut Parser<'_>) -> Result<ForSpecData> {
p.eat(T![for])?;
let d = destruct(p)?;
p.eat(T![in])?;
@@ -597,7 +594,7 @@
Ok(ForSpecData { destruct: d, over })
}
-fn compspecs(p: &mut Parser<'_>) -> R<Vec<CompSpec>> {
+fn compspecs(p: &mut Parser<'_>) -> Result<Vec<CompSpec>> {
let mut specs = Vec::new();
specs.push(CompSpec::ForSpec(for_spec(p)?));
loop {
@@ -613,7 +610,7 @@
Ok(specs)
}
-fn objinside(p: &mut Parser<'_>) -> R<ObjBody> {
+fn objinside(p: &mut Parser<'_>) -> Result<ObjBody> {
if p.at(T!['}']) {
return Ok(ObjBody::MemberList(ObjMembers {
locals: Rc::new(Vec::new()),
@@ -641,26 +638,22 @@
match m {
Member::Field(f) => {
if field_member.is_some() {
- return Err(p.error(
- "object comprehension can only contain one field".into(),
- ));
+ return Err(
+ p.error("object comprehension can only contain one field".into())
+ );
}
field_member = Some(f);
}
Member::BindStmt(b) => locals.push(b),
Member::AssertStmt(_) => {
- return Err(p.error(
- "asserts are unsupported in object comprehension".into(),
- ));
+ return Err(p.error("asserts are unsupported in object comprehension".into()));
}
}
}
Ok(ObjBody::ObjComp(ObjComp {
locals: Rc::new(locals),
field: Rc::new(
- field_member.ok_or_else(|| {
- p.error("missing object comprehension field".into())
- })?,
+ field_member.ok_or_else(|| p.error("missing object comprehension field".into()))?,
),
compspecs: specs,
}))
@@ -683,7 +676,7 @@
}
}
-fn expr_basic(p: &mut Parser<'_>) -> R<Expr> {
+fn expr_basic(p: &mut Parser<'_>) -> Result<Expr> {
if let Some(lit) = literal(p) {
return Ok(Expr::Literal(lit));
}
@@ -825,7 +818,6 @@
}
}
-/// Flush accumulated index parts into an Expr::Index wrapping `e`.
fn flush_index_parts(e: &mut Expr, parts: &mut Vec<IndexPart>) {
if parts.is_empty() {
return;
@@ -837,7 +829,7 @@
};
}
-fn expr_suffix(p: &mut Parser<'_>) -> R<Expr> {
+fn expr_suffix(p: &mut Parser<'_>) -> Result<Expr> {
let mut e = expr_basic(p)?;
// Accumulate consecutive index parts (.field, [expr], ?.field, ?.[expr])
// into a single Expr::Index. This is critical for null-coalesce semantics:
@@ -1006,7 +998,7 @@
}
}
-fn expr_bp(p: &mut Parser<'_>, min_bp: u8) -> R<Expr> {
+fn expr_bp(p: &mut Parser<'_>, min_bp: u8) -> Result<Expr> {
let mut lhs = if let Some(op) = unary_op(p.peek()) {
p.eat_any();
let rbp = prefix_binding_power(op);
@@ -1038,11 +1030,11 @@
Ok(lhs)
}
-fn expr(p: &mut Parser<'_>) -> R<Expr> {
+fn expr(p: &mut Parser<'_>) -> Result<Expr> {
expr_bp(p, 0)
}
-pub fn parse(str: &str, settings: &ParserSettings) -> Result<Expr, ParseError> {
+pub fn parse(str: &str, settings: &ParserSettings) -> Result<Expr> {
let mut p = Parser::new(str, settings.source.clone());
for lexeme in &p.lexemes {
if let Some(desc) = lexeme.kind.error_description() {
@@ -1056,20 +1048,14 @@
}
let e = expr(&mut p)?;
if !p.at_eof() {
- return Err(p.error(format!(
- "expected end of file, got {}",
- p.current_desc(),
- )));
+ return Err(p.error(format!("expected end of file, got {}", p.current_desc(),)));
}
Ok(e)
}
pub fn string_to_expr(s: IStr, settings: &ParserSettings) -> Spanned<Expr> {
let len = s.len();
- Spanned::new(
- Expr::Str(s),
- Span(settings.source.clone(), 0, len as u32),
- )
+ Spanned::new(Expr::Str(s), Span(settings.source.clone(), 0, len as u32))
}
#[cfg(test)]
crates/jrsonnet-ir/src/visit.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/visit.rs
+++ b/crates/jrsonnet-ir/src/visit.rs
@@ -21,6 +21,7 @@
}
}
+#[allow(unused_variables, reason = "used with exp-destruct")]
pub fn visit_destruct<V: Visitor>(v: &mut V, destruct: &Destruct) {
match destruct {
Destruct::Full(_istr) => {}
crates/jrsonnet-rowan-parser/src/lex.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/lex.rs
+++ b/crates/jrsonnet-rowan-parser/src/lex.rs
@@ -11,9 +11,11 @@
}
pub fn lex(input: &str) -> Vec<Lexeme<'_>> {
- Lexer::new(input).map(|l| Lexeme {
- kind: SyntaxKind::from_raw(l.kind.into_raw()),
- text: l.text,
- range: TextRange::new(TextSize::from(l.range.0), TextSize::from(l.range.1)),
- }).collect()
+ Lexer::new(input)
+ .map(|l| Lexeme {
+ kind: SyntaxKind::from_raw(l.kind.into_raw()),
+ text: l.text,
+ range: TextRange::new(TextSize::from(l.range.0), TextSize::from(l.range.1)),
+ })
+ .collect()
}
crates/jrsonnet-stdlib/src/manifest/ini.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/ini.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/ini.rs
@@ -3,8 +3,7 @@
use jrsonnet_evaluator::{
manifest::{ManifestFormat, ToStringFormat},
typed::{FromUntyped, Typed},
- ObjValue, Result, ResultExt, Val,
- IStr,
+ IStr, ObjValue, Result, ResultExt, Val,
};
pub struct IniFormat {
xtask/src/sourcegen/kinds.rsdiffbeforeafterboth--- a/xtask/src/sourcegen/kinds.rs
+++ b/xtask/src/sourcegen/kinds.rs
@@ -120,11 +120,15 @@
Self::Literal { name, .. } => match name.as_str() {
"FLOAT" => "number".to_owned(),
"IDENT" => "identifier".to_owned(),
- "STRING_DOUBLE" | "STRING_SINGLE" | "STRING_DOUBLE_VERBATIM"
- | "STRING_SINGLE_VERBATIM" | "STRING_BLOCK" => "string".to_owned(),
+ "STRING_DOUBLE"
+ | "STRING_SINGLE"
+ | "STRING_DOUBLE_VERBATIM"
+ | "STRING_SINGLE_VERBATIM"
+ | "STRING_BLOCK" => "string".to_owned(),
"WHITESPACE" => "whitespace".to_owned(),
- "SINGLE_LINE_SLASH_COMMENT" | "SINGLE_LINE_HASH_COMMENT"
- | "MULTI_LINE_COMMENT" => "comment".to_owned(),
+ "SINGLE_LINE_SLASH_COMMENT" | "SINGLE_LINE_HASH_COMMENT" | "MULTI_LINE_COMMENT" => {
+ "comment".to_owned()
+ }
_ => name.to_lowercase(),
},
Self::Meta { name, .. } => name.to_lowercase(),