git.delta.rocks / jrsonnet / refs/commits / 27958b04316f

difftreelog

refactor cleanup

pyypxomoYaroslav Bolyukin2026-03-23parent: #325f0a1.patch.diff
in: master

9 files changed

modifiedbindings/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> {
modifiedcrates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/async_import.rs
+++ b/crates/jrsonnet-evaluator/src/async_import.rs
@@ -3,11 +3,7 @@
 
 use jrsonnet_gcmodule::Acyclic;
 use jrsonnet_ir::visit::Visitor;
-use jrsonnet_ir::{
-	ArgsDesc, AssertExpr, AssertStmt, BindSpec, CompSpec, Destruct, Expr, ExprParam, ExprParams,
-	FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData, ImportKind, ObjBody, Slice,
-	SliceDesc, Source, SourcePath, Spanned,
-};
+use jrsonnet_ir::{IStr, Source, SourcePath};
 use rustc_hash::FxHashMap;
 
 use crate::{AsPathLike, FileData, ImportResolver, ResolvePathOwned, State};
@@ -23,7 +19,7 @@
 		self.0.push(Import {
 			path: ResolvePathOwned::Str(value.to_string()),
 			expression,
-		})
+		});
 	}
 }
 
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/lib.rs
1//! jsonnet interpreter implementation2#![cfg_attr(nightly, feature(thread_local, type_alias_impl_trait))]34// For jrsonnet-macros5extern crate self as jrsonnet_evaluator;67mod arr;8// pub mod async_import;9mod ctx;10mod dynamic;11pub mod error;12mod evaluate;13pub mod function;14pub mod gc;15mod import;16mod integrations;17pub mod manifest;18mod map;19mod obj;20pub mod stack;21pub mod stdlib;22pub mod tla;23pub mod trace;24pub mod typed;25pub mod val;2627use std::{28	any::Any,29	cell::{RefCell, RefMut},30	clone::Clone,31	collections::hash_map::Entry,32	fmt::{self, Debug},33	marker::PhantomData,34	rc::Rc,35};3637pub use ctx::*;38pub use dynamic::*;39pub use error::{Error, ErrorKind::*, Result, ResultExt};40pub use evaluate::*;41use function::CallLocation;42pub use import::*;43use jrsonnet_gcmodule::{cc_dyn, Cc, Trace};44pub use jrsonnet_interner::{IBytes, IStr};45pub use jrsonnet_ir as parser;46use jrsonnet_ir::{Expr, Source, SourcePath};47#[doc(hidden)]48pub use jrsonnet_macros;4950#[cfg(not(any(feature = "ir-parser", feature = "peg-parser")))]51compile_error!("at least one of `ir-parser` or `peg-parser` features must be enabled");5253pub use error::{SyntaxError, SyntaxErrorLocation};54pub use obj::*;55pub use rustc_hash;56use rustc_hash::FxHashMap;57use stack::check_depth;58pub use tla::apply_tla;59pub use val::{Thunk, Val};6061use crate::gc::WithCapacityExt as _;6263#[allow(clippy::needless_return)]64pub(crate) fn parse_jsonnet(code: &str, source: Source) -> Result<Expr, SyntaxError> {65	#[cfg(feature = "peg-parser")]66	{67		static USE_LEGACY_PARSER: LazyLock<bool> =68			LazyLock::new(|| std::env::var_os("JRSONNET_LEGACY_PARSER").is_some());6970		if USE_LEGACY_PARSER {71			return parse_peg(code, source);72		}73	}74	#[cfg(feature = "ir-parser")]75	{76		return parse_ir(code, source);77	}78	#[cfg(feature = "peg-parser")]79	{80		return parse_peg(code, source);81	}82}8384#[cfg(feature = "ir-parser")]85fn parse_ir(code: &str, source: Source) -> Result<Expr, SyntaxError> {86	jrsonnet_ir_parser::parse(code, &jrsonnet_ir_parser::ParserSettings { source }).map_err(|e| {87		SyntaxError {88			message: e.message,89			location: SyntaxErrorLocation {90				offset: e.location.offset,91			},92		}93	})94}9596#[cfg(feature = "peg-parser")]97fn parse_peg(code: &str, source: Source) -> Result<Expr, SyntaxError> {98	jrsonnet_peg_parser::parse(code, &jrsonnet_peg_parser::ParserSettings { source }).map_err(|e| {99		let message = e100			.expected101			.tokens()102			.find(|t| t.starts_with("!!!"))103			.map_or_else(104				|| {105					format!(106						"expected {}, got {:?}",107						e.expected,108						code.chars()109							.nth(e.location.offset)110							.map_or_else(|| "EOF".into(), |c: char| c.to_string())111					)112				},113				|v| v[3..].into(),114			);115		SyntaxError {116			message,117			location: SyntaxErrorLocation {118				offset: e.location.offset,119			},120		}121	})122}123124cc_dyn!(125	#[derive(Clone)]126	CcUnbound<V>,127	Unbound<Bound = V>128);129130/// Thunk without bound `super`/`this`131/// object inheritance may be overriden multiple times, and will be fixed only on field read132pub trait Unbound: Trace {133	/// Type of value after object context is bound134	type Bound;135	/// Create value bound to specified object context136	fn bind(&self, sup_this: SupThis) -> Result<Self::Bound>;137}138139/// Object fields may, or may not depend on `this`/`super`, this enum allows cheaper reuse of object-independent fields for native code140/// Standard jsonnet fields are always unbound141#[derive(Clone, Trace)]142pub enum MaybeUnbound {143	/// Value needs to be bound to `this`/`super`144	Unbound(CcUnbound<Val>),145	/// Value is object-independent146	Bound(Thunk<Val>),147}148149impl Debug for MaybeUnbound {150	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {151		write!(f, "MaybeUnbound")152	}153}154impl MaybeUnbound {155	/// Attach object context to value, if required156	pub fn evaluate(&self, sup_this: SupThis) -> Result<Val> {157		match self {158			Self::Unbound(v) => v.0.bind(sup_this),159			Self::Bound(v) => Ok(v.evaluate()?),160		}161	}162}163164cc_dyn!(CcContextInitializer, ContextInitializer);165166/// During import, this trait will be called to create initial context for file.167/// It may initialize global variables, stdlib for example.168pub trait ContextInitializer: Trace {169	/// For which size the builder should be preallocated170	fn reserve_vars(&self) -> usize {171		0172	}173	/// Initialize default file context.174	/// Has default implementation, which calls `populate`.175	/// Prefer to always implement `populate` instead.176	fn initialize(&self, for_file: Source) -> Context {177		let mut builder = ContextBuilder::with_capacity(self.reserve_vars());178		self.populate(for_file, &mut builder);179		builder.build()180	}181	/// For composability: extend builder. May panic if this initialization is not supported,182	/// and the context may only be created via `initialize`.183	fn populate(&self, for_file: Source, builder: &mut ContextBuilder);184	/// Allows upcasting from abstract to concrete context initializer.185	/// jrsonnet by itself doesn't use this method, it is allowed for it to panic.186	fn as_any(&self) -> &dyn Any;187}188189/// Context initializer which adds nothing.190impl ContextInitializer for () {191	fn populate(&self, _for_file: Source, _builder: &mut ContextBuilder) {}192	fn as_any(&self) -> &dyn Any {193		self194	}195}196197impl<T> ContextInitializer for Option<T>198where199	T: ContextInitializer,200{201	fn initialize(&self, for_file: Source) -> Context {202		if let Some(ctx) = self {203			ctx.initialize(for_file)204		} else {205			().initialize(for_file)206		}207	}208209	fn populate(&self, for_file: Source, builder: &mut ContextBuilder) {210		if let Some(ctx) = self {211			ctx.populate(for_file, builder);212		}213	}214215	fn as_any(&self) -> &dyn Any {216		self217	}218}219220macro_rules! impl_context_initializer {221	($($gen:ident)*) => {222		#[allow(non_snake_case)]223		impl<$($gen: ContextInitializer + Trace,)*> ContextInitializer for ($($gen,)*) {224			fn reserve_vars(&self) -> usize {225				let mut out = 0;226				let ($($gen,)*) = self;227				$(out += $gen.reserve_vars();)*228				out229			}230			fn populate(&self, for_file: Source, builder: &mut ContextBuilder) {231				let ($($gen,)*) = self;232				$($gen.populate(for_file.clone(), builder);)*233			}234			fn as_any(&self) -> &dyn Any {235				self236			}237		}238	};239	($($cur:ident)* @ $c:ident $($rest:ident)*) => {240		impl_context_initializer!($($cur)*);241		impl_context_initializer!($($cur)* $c @ $($rest)*);242	};243	($($cur:ident)* @) => {244		impl_context_initializer!($($cur)*);245	}246}247impl_context_initializer! {248	A @ B C D E F G249}250251#[derive(Trace)]252struct FileData {253	string: Option<IStr>,254	bytes: Option<IBytes>,255	parsed: Option<Rc<Expr>>,256	evaluated: Option<Val>,257258	evaluating: bool,259}260impl FileData {261	fn new_string(data: IStr) -> Self {262		Self {263			string: Some(data),264			bytes: None,265			parsed: None,266			evaluated: None,267			evaluating: false,268		}269	}270	fn new_bytes(data: IBytes) -> Self {271		Self {272			string: None,273			bytes: Some(data),274			parsed: None,275			evaluated: None,276			evaluating: false,277		}278	}279	pub(crate) fn get_string(&mut self) -> Option<IStr> {280		if self.string.is_none() {281			self.string = Some(282				self.bytes283					.as_ref()284					.expect("either string or bytes should be set")285					.clone()286					.cast_str()?,287			);288		}289		Some(self.string.clone().expect("just set"))290	}291}292293#[derive(Trace)]294pub struct EvaluationStateInternals {295	/// Internal state296	file_cache: RefCell<FxHashMap<SourcePath, FileData>>,297	/// Context initializer, which will be used for imports and everything298	/// [`NoopContextInitializer`] is used by default, most likely you want to have `jrsonnet-stdlib`299	context_initializer: CcContextInitializer,300	/// Used to resolve file locations/contents301	import_resolver: Rc<dyn ImportResolver>,302}303304/// Maintains stack trace and import resolution305#[derive(Clone, Trace)]306pub struct State(Cc<EvaluationStateInternals>);307308thread_local! {309	pub static DEFAULT_STATE: State = State::builder().build();310	pub static STATE: RefCell<Option<State>> = const {RefCell::new(None)};311}312pub struct StateEnterGuard(PhantomData<()>);313impl Drop for StateEnterGuard {314	fn drop(&mut self) {315		STATE.with_borrow_mut(|v| *v = None);316	}317}318319pub fn with_state<V>(v: impl FnOnce(State) -> V) -> V {320	if let Some(state) = STATE.with_borrow(Clone::clone) {321		v(state)322	} else {323		let s = DEFAULT_STATE.with(Clone::clone);324		v(s)325	}326}327328impl State {329	pub fn enter(&self) -> StateEnterGuard {330		self.try_enter().expect("entered state already exists")331	}332	pub fn try_enter(&self) -> Option<StateEnterGuard> {333		STATE.with_borrow_mut(|v| {334			if v.is_none() {335				*v = Some(self.clone());336				Some(StateEnterGuard(PhantomData))337			} else {338				None339			}340		})341	}342	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise343	pub fn import_resolved_str(&self, path: SourcePath) -> Result<IStr> {344		let mut file_cache = self.file_cache();345		let mut file = file_cache.entry(path.clone());346347		let file = match file {348			Entry::Occupied(ref mut d) => d.get_mut(),349			Entry::Vacant(v) => {350				let data = self.import_resolver().load_file_contents(&path)?;351				v.insert(FileData::new_string(352					std::str::from_utf8(&data)353						.map_err(|_| ImportBadFileUtf8(path.clone()))?354						.into(),355				))356			}357		};358		Ok(file359			.get_string()360			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?)361	}362	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise363	pub fn import_resolved_bin(&self, path: SourcePath) -> Result<IBytes> {364		let mut file_cache = self.file_cache();365		let mut file = file_cache.entry(path.clone());366367		let file = match file {368			Entry::Occupied(ref mut d) => d.get_mut(),369			Entry::Vacant(v) => {370				let data = self.import_resolver().load_file_contents(&path)?;371				v.insert(FileData::new_bytes(data.as_slice().into()))372			}373		};374		if let Some(str) = &file.bytes {375			return Ok(str.clone());376		}377		if file.bytes.is_none() {378			file.bytes = Some(379				file.string380					.as_ref()381					.expect("either string or bytes should be set")382					.clone()383					.cast_bytes(),384			);385		}386		Ok(file.bytes.as_ref().expect("just set").clone())387	}388	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise389	pub fn import_resolved(&self, path: SourcePath) -> Result<Val> {390		let mut file_cache = self.file_cache();391		let mut file = file_cache.entry(path.clone());392393		let file = match file {394			Entry::Occupied(ref mut d) => d.get_mut(),395			Entry::Vacant(v) => {396				let data = self.import_resolver().load_file_contents(&path)?;397				v.insert(FileData::new_string(398					std::str::from_utf8(&data)399						.map_err(|_| ImportBadFileUtf8(path.clone()))?400						.into(),401				))402			}403		};404		if let Some(val) = &file.evaluated {405			return Ok(val.clone());406		}407		let code = file408			.get_string()409			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?;410		let file_name = Source::new(path.clone(), code.clone());411		if file.parsed.is_none() {412			file.parsed = Some(413				parse_jsonnet(&code, file_name.clone())414					.map(Rc::new)415					.map_err(|e| ImportSyntaxError {416						path: file_name.clone(),417						error: Box::new(e),418					})?,419			);420		}421		let parsed = file.parsed.as_ref().expect("just set").clone();422		if file.evaluating {423			bail!(InfiniteRecursionDetected)424		}425		file.evaluating = true;426		// Dropping file cache guard here, as evaluation may use this map too427		drop(file_cache);428		let res = evaluate(self.create_default_context(file_name), &parsed);429430		let mut file_cache = self.file_cache();431		let mut file = file_cache.entry(path);432433		let Entry::Occupied(file) = &mut file else {434			unreachable!("this file was just here")435		};436		let file = file.get_mut();437		file.evaluating = false;438		match res {439			Ok(v) => {440				file.evaluated = Some(v.clone());441				Ok(v)442			}443			Err(e) => Err(e),444		}445	}446447	/// Has same semantics as `import 'path'` called from `from` file448	pub fn import_from(&self, from: &SourcePath, path: impl AsPathLike) -> Result<Val> {449		let resolved = self.resolve_from(from, &path)?;450		self.import_resolved(resolved)451	}452	pub fn import(&self, path: impl AsPathLike) -> Result<Val> {453		let resolved = self.resolve_from_default(&path)?;454		self.import_resolved(resolved)455	}456457	/// Creates context with all passed global variables458	pub fn create_default_context(&self, source: Source) -> Context {459		self.context_initializer().initialize(source)460	}461462	/// Creates context with all passed global variables, calling custom modifier463	pub fn create_default_context_with(464		&self,465		source: Source,466		context_initializer: impl ContextInitializer,467	) -> Context {468		let default_initializer = self.context_initializer();469		let mut builder = ContextBuilder::with_capacity(470			default_initializer.reserve_vars() + context_initializer.reserve_vars(),471		);472		default_initializer.populate(source.clone(), &mut builder);473		context_initializer.populate(source, &mut builder);474475		builder.build()476	}477}478479/// Internals480impl State {481	fn file_cache(&self) -> RefMut<'_, FxHashMap<SourcePath, FileData>> {482		self.0.file_cache.borrow_mut()483	}484}485/// Executes code creating a new stack frame, to be replaced with try{}486pub fn in_frame<T>(487	e: CallLocation<'_>,488	frame_desc: impl FnOnce() -> String,489	f: impl FnOnce() -> Result<T>,490) -> Result<T> {491	let _guard = check_depth()?;492493	f().with_description_src(e, frame_desc)494}495496/// Executes code creating a new stack frame, to be replaced with try{}497pub fn in_description_frame<T>(498	frame_desc: impl FnOnce() -> String,499	f: impl FnOnce() -> Result<T>,500) -> Result<T> {501	let _guard = check_depth()?;502503	f().with_description(frame_desc)504}505506#[derive(Trace)]507pub struct InitialUnderscore(pub Thunk<Val>);508impl ContextInitializer for InitialUnderscore {509	fn populate(&self, _for_file: Source, builder: &mut ContextBuilder) {510		builder.bind("_", self.0.clone());511	}512513	fn as_any(&self) -> &dyn Any {514		self515	}516}517518/// Raw methods evaluate passed values but don't perform TLA execution519impl State {520	/// Parses and evaluates the given snippet521	pub fn evaluate_snippet(&self, name: impl Into<IStr>, code: impl Into<IStr>) -> Result<Val> {522		let code = code.into();523		let source = Source::new_virtual(name.into(), code.clone());524		let parsed = parse_jsonnet(&code, source.clone()).map_err(|e| ImportSyntaxError {525			path: source.clone(),526			error: Box::new(e),527		})?;528		evaluate(self.create_default_context(source), &parsed)529	}530	/// Parses and evaluates the given snippet with custom context modifier531	pub fn evaluate_snippet_with(532		&self,533		name: impl Into<IStr>,534		code: impl Into<IStr>,535		context_initializer: impl ContextInitializer,536	) -> Result<Val> {537		let code = code.into();538		let source = Source::new_virtual(name.into(), code.clone());539		let parsed = parse_jsonnet(&code, source.clone()).map_err(|e| ImportSyntaxError {540			path: source.clone(),541			error: Box::new(e),542		})?;543		evaluate(544			self.create_default_context_with(source, context_initializer),545			&parsed,546		)547	}548}549550/// Settings utilities551impl State {552	// Only panics in case of [`ImportResolver`] contract violation553	#[allow(clippy::missing_panics_doc)]554	pub fn resolve_from(&self, from: &SourcePath, path: &dyn AsPathLike) -> Result<SourcePath> {555		self.import_resolver().resolve_from(from, path)556	}557	#[allow(clippy::missing_panics_doc)]558	pub fn resolve_from_default(&self, path: &dyn AsPathLike) -> Result<SourcePath> {559		self.import_resolver().resolve_from_default(path)560	}561	pub fn import_resolver(&self) -> &dyn ImportResolver {562		&*self.0.import_resolver563	}564	pub fn context_initializer(&self) -> &dyn ContextInitializer {565		&*self.0.context_initializer.0566	}567}568569impl State {570	pub fn builder() -> StateBuilder {571		StateBuilder::default()572	}573}574575impl Default for State {576	fn default() -> Self {577		Self::builder().build()578	}579}580581#[derive(Default)]582pub struct StateBuilder {583	import_resolver: Option<Rc<dyn ImportResolver>>,584	context_initializer: Option<CcContextInitializer>,585}586impl StateBuilder {587	pub fn import_resolver(&mut self, import_resolver: impl ImportResolver) -> &mut Self {588		let _ = self.import_resolver.insert(Rc::new(import_resolver));589		self590	}591	pub fn context_initializer(592		&mut self,593		context_initializer: impl ContextInitializer,594	) -> &mut Self {595		let _ = self596			.context_initializer597			.insert(CcContextInitializer::new(context_initializer));598		self599	}600	pub fn build(mut self) -> State {601		State(Cc::new(EvaluationStateInternals {602			file_cache: RefCell::new(FxHashMap::new()),603			context_initializer: self604				.context_initializer605				.take()606				.unwrap_or_else(|| CcContextInitializer::new(())),607			import_resolver: self608				.import_resolver609				.take()610				.unwrap_or_else(|| Rc::new(DummyImportResolver)),611		}))612	}613}
modifiedcrates/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;
modifiedcrates/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)]
modifiedcrates/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) => {}
modifiedcrates/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()
 }
modifiedcrates/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 {
modifiedxtask/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(),