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

difftreelog

refactor only keep used spans in IR

uxonrmwzYaroslav Bolyukin2026-03-22parent: #44f6e2c.patch.diff
in: master

12 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -730,6 +730,7 @@
 version = "0.5.0-pre97"
 dependencies = [
  "insta",
+ "jrsonnet-gcmodule",
  "jrsonnet-ir",
  "peg",
 ]
modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -38,7 +38,7 @@
 		Self::new(RangeArray::empty())
 	}
 
-	pub fn expr(ctx: Context, exprs: Rc<Vec<Spanned<Expr>>>) -> Self {
+	pub fn expr(ctx: Context, exprs: Rc<Vec<Expr>>) -> Self {
 		Self::new(ExprArray::new(ctx, exprs))
 	}
 
modifiedcrates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -118,11 +118,11 @@
 #[derive(Debug, Trace, Clone)]
 pub struct ExprArray {
 	ctx: Context,
-	src: Rc<Vec<Spanned<Expr>>>,
+	src: Rc<Vec<Expr>>,
 	cached: Cc<RefCell<Vec<ArrayThunk>>>,
 }
 impl ExprArray {
-	pub fn new(ctx: Context, src: Rc<Vec<Spanned<Expr>>>) -> Self {
+	pub fn new(ctx: Context, src: Rc<Vec<Expr>>) -> Self {
 		Self {
 			ctx,
 			cached: Cc::new(RefCell::new(vec![ArrayThunk::Waiting; src.len()])),
modifiedcrates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/async_import.rs
+++ b/crates/jrsonnet-evaluator/src/async_import.rs
@@ -139,7 +139,7 @@
 			if let Expr::Str(s) = &***v {
 				out.0.push(Import {
 					path: ResolvePathOwned::Str(s.to_string()),
-					expression: matches!(&**expr, Expr::Import(ImportKind::Normal, _)),
+					expression: todo!(),
 				});
 			}
 			// Non-string import will fail in runtime
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
53 Expr::Str(_)53 Expr::Str(_)
54 | Expr::Num(_)54 | Expr::Num(_)
55 | Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,55 | Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,
56 Expr::Arr(a) => a.iter().all(|e| is_trivial(&**e)),56 Expr::Arr(a) => a.iter().all(|e| is_trivial(&*e)),
57 _ => false,57 _ => false,
58 }58 }
59 }59 }
71 }71 }
72 Val::Arr(ArrValue::eager(72 Val::Arr(ArrValue::eager(
73 n.iter()73 n.iter()
74 .map(|e| evaluate_trivial(&**e))74 .map(|e| evaluate_trivial(&*e))
75 .map(|e| e.expect("checked trivial"))75 .map(|e| e.expect("checked trivial"))
76 .collect(),76 .collect(),
77 ))77 ))
84 ctx: Context,
85 name: IStr,
86 params: ExprParams,
87 body: Rc<Spanned<Expr>>,
88) -> Val {
89 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {84 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {
90 name,85 name,
97pub fn evaluate_field_name(ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {92pub fn evaluate_field_name(ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {
98 Ok(match field_name {93 Ok(match field_name {
99 FieldName::Fixed(n) => Some(n.clone()),94 FieldName::Fixed(n) => Some(n.clone()),
100 FieldName::Dyn(expr) => in_frame(95 FieldName::Dyn(expr) => {
101 CallLocation::new(&expr.span()),96 // FIXME: Span
102 || "evaluating field name".to_string(),
103 || {
104 let value = evaluate(ctx, expr)?;97 let value = evaluate(ctx, expr)?;
105 if matches!(value, Val::Null) {98 if matches!(value, Val::Null) {
106 Ok(None)99 None
107 } else {100 } else {
108 Ok(Some(IStr::from_untyped(value)?))101 Some(IStr::from_untyped(value)?)
109 }102 }
110 },103 } //
111 )?,104 // in_frame(
105 // CallLocation::new(&expr.span()),
106 // || "evaluating field name".to_string(),
107 // || {
108 // },
109 // )?,
112 })110 })
113}111}
114112
119) -> Result<()> {117) -> Result<()> {
120 match specs.first() {118 match specs.first() {
121 None => callback(ctx)?,119 None => callback(ctx)?,
122 Some(CompSpec::IfSpec(IfSpecData(cond))) => {120 Some(CompSpec::IfSpec(Spanned(IfSpecData(cond), _))) => {
123 if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {121 if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {
124 evaluate_comp(ctx, &specs[1..], callback)?;122 evaluate_comp(ctx, &specs[1..], callback)?;
125 }123 }
126 }124 }
127 Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(ctx.clone(), expr)? {125 Some(CompSpec::ForSpec(Spanned(ForSpecData(var, expr), _))) => {
126 match evaluate(ctx.clone(), expr)? {
128 Val::Arr(list) => {127 Val::Arr(list) => {
129 for item in list.iter_lazy() {128 for item in list.iter_lazy() {
158 }157 }
159 }158 }
160 _ => bail!(InComprehensionCanOnlyIterateOverArray),159 _ => bail!(InComprehensionCanOnlyIterateOverArray),
161 },160 }
161 }
162 }162 }
163 Ok(())163 Ok(())
164}164}
221 #[derive(Trace)]221 #[derive(Trace)]
222 struct UnboundValue<B: Trace> {222 struct UnboundValue<B: Trace> {
223 uctx: B,223 uctx: B,
224 value: Rc<Spanned<Expr>>,224 value: Rc<Expr>,
225 name: IStr,225 name: IStr,
226 }226 }
227 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {227 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
235 .field(name.clone())235 .field(name.clone())
236 .with_add(*plus)236 .with_add(*plus)
237 .with_visibility(*visibility)237 .with_visibility(*visibility)
238 .with_location(value.span())238 // FIXME
239 // .with_location(value.span())
239 .bindable(UnboundValue {240 .bindable(UnboundValue {
240 uctx,241 uctx,
241 value: value.clone(),242 value: value.clone(),
251 #[derive(Trace)]252 #[derive(Trace)]
252 struct UnboundMethod<B: Trace> {253 struct UnboundMethod<B: Trace> {
253 uctx: B,254 uctx: B,
254 value: Rc<Spanned<Expr>>,255 value: Rc<Expr>,
255 params: ExprParams,256 params: ExprParams,
256 name: IStr,257 name: IStr,
257 }258 }
270 builder271 builder
271 .field(name.clone())272 .field(name.clone())
272 .with_visibility(*visibility)273 .with_visibility(*visibility)
273 .with_location(value.span())274 // .with_location(value.span())
274 .bindable(UnboundMethod {275 .bindable(UnboundMethod {
275 uctx,276 uctx,
276 value: value.clone(),277 value: value.clone(),
337338
338pub fn evaluate_apply(339pub fn evaluate_apply(
339 ctx: Context,340 ctx: Context,
340 value: &Spanned<Expr>,341 value: &Expr,
341 args: &ArgsDesc,342 args: &ArgsDesc,
342 loc: CallLocation<'_>,343 loc: CallLocation<'_>,
343 tailstrict: bool,344 tailstrict: bool,
379 Ok(())380 Ok(())
380}381}
381382
382pub fn evaluate_named_param(ctx: Context, expr: &Spanned<Expr>, name: ParamName) -> Result<Val> {383pub fn evaluate_named_param(ctx: Context, expr: &Expr, name: ParamName) -> Result<Val> {
383 match name {384 match name {
384 ParamName::Named(name) => evaluate_named(ctx, expr, name),385 ParamName::Named(name) => evaluate_named(ctx, expr, name),
385 ParamName::Unnamed => evaluate(ctx, expr),386 ParamName::Unnamed => evaluate(ctx, expr),
386 }387 }
387}388}
388389
389pub fn evaluate_named(ctx: Context, expr: &Spanned<Expr>, name: IStr) -> Result<Val> {390pub fn evaluate_named(ctx: Context, expr: &Expr, name: IStr) -> Result<Val> {
390 use Expr::*;391 use Expr::*;
391 Ok(match &**expr {392 Ok(match &*expr {
392 Function(params, body) => evaluate_method(ctx, name, params.clone(), body.clone()),393 Function(params, body) => evaluate_method(ctx, name, params.clone(), body.clone()),
393 _ => evaluate(ctx, expr)?,394 _ => evaluate(ctx, expr)?,
394 })395 })
417 // because the standalone super literal is not supported, that is because in other418 // because the standalone super literal is not supported, that is because in other
418 // implementations `in super` treated differently from `in smth_else`.419 // implementations `in super` treated differently from `in smth_else`.
419 BinaryOp(bin)420 BinaryOp(bin)
420 if matches!(&*bin.rhs, Expr::Literal(LiteralType::Super))421 if matches!(&bin.rhs, Expr::Literal(LiteralType::Super))
421 && bin.op == BinaryOpType::In =>422 && bin.op == BinaryOpType::In =>
422 {423 {
423 let sup_this = ctx.try_sup_this()?;424 let sup_this = ctx.try_sup_this()?;
433 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,434 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,
434 Var(name) => in_frame(435 Var(name) => in_frame(
435 CallLocation::new(&name.span()),436 CallLocation::new(&name.span()),
436 || format!("local <{name}> access"),437 || format!("local <{}> access", &**name),
437 || ctx.binding((**name).clone())?.evaluate(),438 || ctx.binding((**name).clone())?.evaluate(),
438 )?,439 )?,
439 Index { indexable, parts } => ensure_sufficient_stack(|| {440 Index { indexable, parts } => ensure_sufficient_stack(|| {
440 let mut parts = parts.iter();441 let mut parts = parts.iter();
441 let mut indexable = if matches!(&***indexable, Expr::Literal(LiteralType::Super)) {442 let mut indexable = if matches!(&**indexable, Expr::Literal(LiteralType::Super)) {
442 let part = parts.next().expect("at least part should exist");443 let part = parts.next().expect("at least part should exist");
443 // sup_this existence check might also be skipped here for null-coalesce...444 // sup_this existence check might also be skipped here for null-coalesce...
444 // But I believe this might cause errors.445 // But I believe this might cause errors.
463 let name = name.into_flat();464 let name = name.into_flat();
464 match sup_this465 match sup_this
465 .get_super(name.clone())466 .get_super(name.clone())
466 .with_description_src(&part.value, || format!("field <{name}> access"))?467 .with_description_src(&part.span, || format!("field <{name}> access"))?
467 {468 {
468 Some(v) => v,469 Some(v) => v,
469 #[cfg(feature = "exp-null-coaelse")]470 #[cfg(feature = "exp-null-coaelse")]
485 indexable = match (indexable, evaluate(ctx.clone(), &part.value)?) {486 indexable = match (indexable, evaluate(ctx.clone(), &part.value)?) {
486 (Val::Obj(v), Val::Str(key)) => match v487 (Val::Obj(v), Val::Str(key)) => match v
487 .get(key.clone().into_flat())488 .get(key.clone().into_flat())
488 .with_description_src(&part.value, || format!("field <{key}> access"))?489 .with_description_src(&part.span, || format!("field <{key}> access"))?
489 {490 {
490 Some(v) => v,491 Some(v) => v,
491 #[cfg(feature = "exp-null-coaelse")]492 #[cfg(feature = "exp-null-coaelse")]
497 key.clone().into_flat(),498 key.clone().into_flat(),
498 suggestions,499 suggestions,
499 )))500 )))
500 .with_description_src(&part.value, || format!("field <{key}> access"));501 .with_description_src(&part.span, || format!("field <{key}> access"));
501 }502 }
502 },503 },
503 (Val::Obj(_), n) => bail!(ValueIndexMustBeTypeGot(504 (Val::Obj(_), n) => bail!(ValueIndexMustBeTypeGot(
605 evaluate_assert(ctx.clone(), &assert.assert)?;606 evaluate_assert(ctx.clone(), &assert.assert)?;
606 evaluate(ctx, &assert.rest)?607 evaluate(ctx, &assert.rest)?
607 }608 }
608 ErrorStmt(e) => in_frame(609 ErrorStmt(s, e) => in_frame(
609 CallLocation::new(&e.span()),610 CallLocation::new(&s),
610 || "error statement".to_owned(),611 || "error statement".to_owned(),
611 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),612 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),
612 )?,613 )?,
613 IfElse(if_else) => {614 IfElse(if_else) => {
614 if in_frame(615 if
615 CallLocation::new(&if_else.cond.0.span()),616 // FIXME
616 || "if condition".to_owned(),617 //in_frame(
618 // CallLocation::new(&if_else.cond.0.span()),
619 // || "if condition".to_owned(),
620 // ||
617 || bool::from_untyped(evaluate(ctx.clone(), &if_else.cond.0)?),621 bool::from_untyped(evaluate(ctx.clone(), &if_else.cond.0)?)?
622 // )?
618 )? {623 {
619 evaluate(ctx, &if_else.cond_then)?624 evaluate(ctx, &if_else.cond_then)?
620 } else {625 } else {
621 match &if_else.cond_else {626 match &if_else.cond_else {
626 }631 }
627 Slice(slice) => {632 Slice(slice) => {
628 fn parse_idx<T: Typed + FromUntyped>(633 fn parse_idx<T: Typed + FromUntyped>(
629 loc: CallLocation<'_>,
630 ctx: Context,634 ctx: Context,
631 expr: Option<&Spanned<Expr>>,635 expr: Option<&Spanned<Expr>>,
632 desc: &'static str,636 desc: &'static str,
633 ) -> Result<Option<T>> {637 ) -> Result<Option<T>> {
634 if let Some(value) = expr {638 if let Some(value) = expr {
635 Ok(in_frame(639 Ok(in_frame(
636 loc,640 CallLocation::new(&value.span()),
637 || format!("slice {desc}"),641 || format!("slice {desc}"),
638 || <Option<T>>::from_untyped(evaluate(ctx, value)?),642 || <Option<T>>::from_untyped(evaluate(ctx, value)?),
639 )?)643 )?)
643 }647 }
644648
645 let indexable = evaluate(ctx.clone(), &slice.value)?;649 let indexable = evaluate(ctx.clone(), &slice.value)?;
646 let loc = CallLocation::new(&loc);
647650
648 let start = parse_idx(loc, ctx.clone(), slice.slice.start.as_ref(), "start")?;651 let start = parse_idx(ctx.clone(), slice.slice.start.as_ref(), "start")?;
649 let end = parse_idx(loc, ctx.clone(), slice.slice.end.as_ref(), "end")?;652 let end = parse_idx(ctx.clone(), slice.slice.end.as_ref(), "end")?;
650 let step = parse_idx(loc, ctx, slice.slice.step.as_ref(), "step")?;653 let step = parse_idx(ctx, slice.slice.step.as_ref(), "step")?;
651654
652 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?655 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?
653 }656 }
654 Import(kind, path) => {657 Import(kind, path) => {
655 let Expr::Str(path) = &***path else {658 let Expr::Str(path) = &**path else {
656 bail!("computed imports are not supported")659 bail!("computed imports are not supported")
657 };660 };
658 let tmp = loc.clone().0;
659 with_state(|s| {661 with_state(|s| {
662 let span = kind.span();
660 let resolved_path = s.resolve_from(tmp.source_path(), path)?;663 let resolved_path = s.resolve_from(span.0.source_path(), path)?;
661 Ok(match kind {664 Ok(match &**kind {
662 ImportKind::Normal => in_frame(665 ImportKind::Normal => in_frame(
663 CallLocation::new(&loc),666 CallLocation::new(&span),
664 || format!("import {:?}", path.clone()),667 || format!("import {:?}", path.clone()),
665 || s.import_resolved(resolved_path),668 || s.import_resolved(resolved_path),
666 )?,669 )?,
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -147,9 +147,9 @@
 
 pub fn evaluate_binary_op_special(
 	ctx: Context,
-	a: &Spanned<Expr>,
+	a: &Expr,
 	op: BinaryOpType,
-	b: &Spanned<Expr>,
+	b: &Expr,
 ) -> Result<Val> {
 	use BinaryOpType::*;
 	use Val::*;
modifiedcrates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -3,8 +3,8 @@
 use educe::Educe;
 use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
+use jrsonnet_ir::{ArgsDesc, Destruct, Expr, ExprParams, Span, Spanned};
 pub use jrsonnet_macros::builtin;
-use jrsonnet_ir::{ArgsDesc, Destruct, Expr, ExprParams, Span, Spanned};
 
 use self::{
 	builtin::{Builtin, StaticBuiltin},
@@ -71,7 +71,7 @@
 	/// Function parameter definition
 	pub params: ExprParams,
 	/// Function body
-	pub body: Rc<Spanned<Expr>>,
+	pub body: Rc<Expr>,
 }
 impl FuncDesc {
 	/// Create body context, but fill arguments without defaults with lazy error
@@ -256,7 +256,7 @@
 					#[cfg(feature = "exp-destruct")]
 					_ => return false,
 				};
-				**desc.body == Expr::Var(id.clone())
+				matches!(&*desc.body, Expr::Var(v) if &**v == id)
 			}
 			_ => false,
 		}
modifiedcrates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -2,7 +2,7 @@
 
 use jrsonnet_ir::{
 	function::{FunctionSignature, ParamName},
-	ArgsDesc, Expr, ExprParams, Spanned,
+	ArgsDesc, Expr, ExprParams,
 };
 use rustc_hash::FxHashMap;
 
@@ -15,7 +15,7 @@
 	Context, Pending, Thunk, Val,
 };
 
-fn eval_arg(ctx: Context, arg: &Rc<Spanned<Expr>>, tailstrict: bool) -> Result<Thunk<Val>> {
+fn eval_arg(ctx: Context, arg: &Rc<Expr>, tailstrict: bool) -> Result<Thunk<Val>> {
 	if tailstrict {
 		Ok(Thunk::evaluated(evaluate(ctx, arg)?))
 	} else {
modifiedcrates/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;
@@ -187,7 +187,7 @@
 struct FileData {
 	string: Option<IStr>,
 	bytes: Option<IBytes>,
-	parsed: Option<Rc<Spanned<Expr>>>,
+	parsed: Option<Rc<Expr>>,
 	evaluated: Option<Val>,
 
 	evaluating: bool,
modifiedcrates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-ir/src/expr.rs
+++ b/crates/jrsonnet-ir/src/expr.rs
@@ -17,7 +17,7 @@
 	/// {fixed: 2}
 	Fixed(IStr),
 	/// {["dyn"+"amic"]: 3}
-	Dyn(Spanned<Expr>),
+	Dyn(Expr),
 }
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Acyclic)]
@@ -46,7 +46,7 @@
 	pub plus: bool,
 	pub params: Option<ExprParams>,
 	pub visibility: Visibility,
-	pub value: Rc<Spanned<Expr>>,
+	pub value: Rc<Expr>,
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
@@ -152,7 +152,7 @@
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct ExprParam {
 	pub destruct: Destruct,
-	pub default: Option<Rc<Spanned<Expr>>>,
+	pub default: Option<Rc<Expr>>,
 }
 
 /// Defined function parameters
@@ -194,11 +194,11 @@
 
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct ArgsDesc {
-	pub unnamed: Vec<Rc<Spanned<Expr>>>,
-	pub named: Vec<(IStr, Rc<Spanned<Expr>>)>,
+	pub unnamed: Vec<Rc<Expr>>,
+	pub named: Vec<(IStr, Rc<Expr>)>,
 }
 impl ArgsDesc {
-	pub fn new(unnamed: Vec<Rc<Spanned<Expr>>>, named: Vec<(IStr, Rc<Spanned<Expr>>)>) -> Self {
+	pub fn new(unnamed: Vec<Rc<Expr>>, named: Vec<(IStr, Rc<Expr>)>) -> Self {
 		Self { unnamed, named }
 	}
 }
@@ -277,12 +277,12 @@
 pub enum BindSpec {
 	Field {
 		into: Destruct,
-		value: Rc<Spanned<Expr>>,
+		value: Rc<Expr>,
 	},
 	Function {
 		name: IStr,
 		params: ExprParams,
-		value: Rc<Spanned<Expr>>,
+		value: Rc<Expr>,
 	},
 }
 impl BindSpec {
@@ -295,15 +295,15 @@
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
-pub struct IfSpecData(pub Spanned<Expr>);
+pub struct IfSpecData(pub Expr);
 
 #[derive(Debug, PartialEq, Acyclic)]
-pub struct ForSpecData(pub Destruct, pub Spanned<Expr>);
+pub struct ForSpecData(pub Destruct, pub Expr);
 
 #[derive(Debug, PartialEq, Acyclic)]
 pub enum CompSpec {
-	IfSpec(IfSpecData),
-	ForSpec(ForSpecData),
+	IfSpec(Spanned<IfSpecData>),
+	ForSpec(Spanned<ForSpecData>),
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
@@ -346,14 +346,14 @@
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct AssertExpr {
 	pub assert: AssertStmt,
-	pub rest: Spanned<Expr>,
+	pub rest: Expr,
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct BinaryOp {
-	pub lhs: Spanned<Expr>,
+	pub lhs: Expr,
 	pub op: BinaryOpType,
-	pub rhs: Spanned<Expr>,
+	pub rhs: Expr,
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
@@ -366,13 +366,13 @@
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct IfElse {
 	pub cond: IfSpecData,
-	pub cond_then: Spanned<Expr>,
-	pub cond_else: Option<Spanned<Expr>>,
+	pub cond_then: Expr,
+	pub cond_else: Option<Expr>,
 }
 
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct Slice {
-	pub value: Spanned<Expr>,
+	pub value: Expr,
 	pub slice: SliceDesc,
 }
 
@@ -389,7 +389,7 @@
 	Var(Spanned<IStr>),
 
 	/// Array of expressions: [1, 2, "Hello"]
-	Arr(Rc<Vec<Spanned<Expr>>>),
+	Arr(Rc<Vec<Expr>>),
 	/// Array comprehension:
 	/// ```jsonnet
 	///  ingredients: [
@@ -401,35 +401,35 @@
 	///    ]
 	///  ],
 	/// ```
-	ArrComp(Rc<Spanned<Expr>>, Vec<CompSpec>),
+	ArrComp(Rc<Expr>, Vec<CompSpec>),
 
 	/// Object: {a: 2}
 	Obj(ObjBody),
 	/// Object extension: var1 {b: 2}
-	ObjExtend(Rc<Spanned<Expr>>, ObjBody),
+	ObjExtend(Rc<Expr>, ObjBody),
 
 	/// -2
-	UnaryOp(UnaryOpType, Box<Spanned<Expr>>),
+	UnaryOp(UnaryOpType, Box<Expr>),
 	/// 2 - 2
 	BinaryOp(Box<BinaryOp>),
 	/// assert 2 == 2 : "Math is broken"
 	AssertExpr(Rc<AssertExpr>),
 	/// local a = 2; { b: a }
-	LocalExpr(Vec<BindSpec>, Box<Spanned<Expr>>),
+	LocalExpr(Vec<BindSpec>, Box<Expr>),
 
 	/// import* "hello"
-	Import(ImportKind, Box<Spanned<Expr>>),
+	Import(Spanned<ImportKind>, Box<Expr>),
 	/// error "I'm broken"
-	ErrorStmt(Box<Spanned<Expr>>),
+	ErrorStmt(Span, Box<Expr>),
 	/// a(b, c)
-	Apply(Box<Spanned<Expr>>, Spanned<ArgsDesc>, bool),
+	Apply(Box<Expr>, Spanned<ArgsDesc>, bool),
 	/// a[b], a.b, a?.b
 	Index {
-		indexable: Box<Spanned<Expr>>,
+		indexable: Box<Expr>,
 		parts: Vec<IndexPart>,
 	},
 	/// function(x) x
-	Function(ExprParams, Rc<Spanned<Expr>>),
+	Function(ExprParams, Rc<Expr>),
 	/// if true == false then 1 else 2
 	IfElse(Box<IfElse>),
 	Slice(Box<Slice>),
@@ -437,7 +437,8 @@
 
 #[derive(Debug, PartialEq, Acyclic)]
 pub struct IndexPart {
-	pub value: Spanned<Expr>,
+	pub span: Span,
+	pub value: Expr,
 	#[cfg(feature = "exp-null-coaelse")]
 	pub null_coaelse: bool,
 }
@@ -461,7 +462,7 @@
 }
 
 #[derive(Clone, PartialEq, Acyclic)]
-pub struct Spanned<T: Acyclic>(T, Span);
+pub struct Spanned<T: Acyclic>(pub T, pub Span);
 impl<T: Acyclic> Deref for Spanned<T> {
 	type Target = T;
 	fn deref(&self) -> &Self::Target {
modifiedcrates/jrsonnet-peg-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-peg-parser/Cargo.toml
+++ b/crates/jrsonnet-peg-parser/Cargo.toml
@@ -7,6 +7,7 @@
 version.workspace = true
 
 [dependencies]
+jrsonnet-gcmodule.workspace = true
 jrsonnet-ir.workspace = true
 peg.workspace = true
 
modifiedcrates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-peg-parser/src/lib.rs
+++ b/crates/jrsonnet-peg-parser/src/lib.rs
@@ -1,7 +1,9 @@
+use jrsonnet_gcmodule::Acyclic;
 use jrsonnet_ir::{
-	BinaryOp, Expr, ExprParams, IStr, IndexPart, Member, Slice, SliceDesc, Source, Span, Spanned,
-	ExprParam, ArgsDesc, AssertExpr, ImportKind, LiteralType, IfElse, CompSpec, ForSpecData, IfSpecData, ObjMembers, ObjBody,
-	ObjComp, FieldMember, Visibility, FieldName, unescape, AssertStmt, BindSpec, Destruct, DestructRest,
+	unescape, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, 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, Visibility,
 };
 use peg::parser;
 use std::rc::Rc;
@@ -63,7 +65,7 @@
 			= params:param(s) ** comma() comma()? { ExprParams::new(params) }
 			/ { ExprParams::new(Vec::new()) }
 
-		pub rule arg(s: &ParserSettings) -> (Option<IStr>, Rc<Spanned<Expr>>)
+		pub rule arg(s: &ParserSettings) -> (Option<IStr>, Rc<Expr>)
 			= name:(quiet! { (s:id() _ "=" !['='] _ {s})? } / expected!("<argument name>")) expr:expr(s) {(name, Rc::new(expr))}
 
 		pub rule args(s: &ParserSettings) -> ArgsDesc
@@ -133,7 +135,7 @@
 			/ name:id() _ "(" _ params:params(s) _ ")" _ "=" _ value:expr(s) {BindSpec::Function{name, params, value: Rc::new(value)}}
 
 		pub rule assertion(s: &ParserSettings) -> AssertStmt
-			= keyword("assert") _ cond:expr(s) msg:(_ ":" _ e:expr(s) {e})? { AssertStmt(cond, msg) }
+			= keyword("assert") _ cond:spanned(<expr(s)>, s) msg:(_ ":" _ e:spanned(<expr(s)>, s) {e})? { AssertStmt(cond, msg) }
 
 		pub rule whole_line() -> &'input str
 			= str:$((!['\n'][_])* "\n") {str}
@@ -241,7 +243,7 @@
 		pub rule forspec(s: &ParserSettings) -> ForSpecData
 			= keyword("for") _ id:destruct(s) _ keyword("in") _ cond:expr(s) {ForSpecData(id, cond)}
 		rule compspec(s: &ParserSettings) -> CompSpec
-			= i:ifspec(s) { CompSpec::IfSpec(i) } / f:forspec(s) {CompSpec::ForSpec(f)}
+			= i:spanned(<ifspec(s)>, s) { CompSpec::IfSpec(i) } / f:spanned(<forspec(s)>, s) {CompSpec::ForSpec(f)}
 		pub rule compspecs(s: &ParserSettings) -> Vec<CompSpec>
 			= specs:compspec(s) ++ _ {?
 				if !matches!(specs[0], CompSpec::ForSpec(_)) {
@@ -267,8 +269,12 @@
 			} else {
 				Err("!!!numbers are finite")
 			}}
+
+		rule spanned<T: Acyclic>(x: rule<T>, s: &ParserSettings) -> Spanned<T>
+			= a:position!() n:x() b:position!() { Spanned::new(n, Span(s.source.clone(), a as u32, b as u32)) }
+
 		pub rule var_expr(s: &ParserSettings) -> Expr
-			= n:id() { Expr::Var(n) }
+			= n:spanned(<id()>, s) { Expr::Var(n) }
 		pub rule id_loc(s: &ParserSettings) -> Spanned<Expr>
 			= a:position!() n:id() b:position!() { Spanned::new(Expr::Str(n), Span(s.source.clone(), a as u32,b as u32)) }
 		pub rule if_then_else_expr(s: &ParserSettings) -> Expr
@@ -302,7 +308,7 @@
 			/ array_expr(s)
 			/ array_comp_expr(s)
 
-			/ kind:import_kind() _ path:expr(s) {Expr::Import(kind, Box::new(path))}
+			/ kind:spanned(<import_kind()>, s) _ path:expr(s) {Expr::Import(kind, Box::new(path))}
 
 			/ var_expr(s)
 			/ local_expr(s)
@@ -313,10 +319,10 @@
 				assert, rest
 			})) }
 
-			/ keyword("error") _ expr:expr(s) { Expr::ErrorStmt(Box::new(expr)) }
+			/ err_kw:spanned(<keyword("error")>, s) _ expr:expr(s) { Expr::ErrorStmt(err_kw.1, Box::new(expr)) }
 
 		rule slice_part(s: &ParserSettings) -> Option<Spanned<Expr>>
-			= _ e:(e:expr(s) _{e})? {e}
+			= _ e:(e:spanned(<expr(s)>, s) _{e})? {e}
 		pub rule slice_desc(s: &ParserSettings) -> SliceDesc
 			= start:slice_part(s) ":" pair:(end:slice_part(s) step:(":" e:slice_part(s){e})? {(end, step.flatten())})? {
 				let (end, step) = if let Some((end, step)) = pair {
@@ -340,11 +346,8 @@
 			}
 		use jrsonnet_ir::BinaryOpType::*;
 		use jrsonnet_ir::UnaryOpType::*;
-		rule expr(s: &ParserSettings) -> Spanned<Expr>
+		rule expr(s: &ParserSettings) -> Expr
 			= precedence! {
-				"(" _ e:expr(s) _ ")" {e}
-				start:position!() v:@ end:position!() { Spanned::new(v, Span(s.source.clone(), start as u32, end as u32)) }
-				--
 				a:(@) _ binop(<"||">) _ b:@ {expr_bin!(a Or b)}
 				a:(@) _ binop(<"??">) _ ensure_null_coaelse() b:@ {
 					#[cfg(feature = "exp-null-coaelse")] return expr_bin!(a NullCoaelse b);
@@ -385,29 +388,32 @@
 				--
 				value:(@) _ "[" _ slice:slice_desc(s) _ "]" {Expr::Slice(Box::new(Slice{value, slice}))}
 				indexable:(@) _ parts:index_part(s)+ {Expr::Index{indexable: Box::new(indexable), parts}}
-				a:(@) _ "(" _ args:args(s) _ ")" ts:(_ keyword("tailstrict"))? {Expr::Apply(Box::new(a), args, ts.is_some())}
+				a:(@) _ args:spanned(<"(" _ a:args(s) _ ")" {a}>, s) ts:(_ keyword("tailstrict"))? {Expr::Apply(Box::new(a), args, ts.is_some())}
 				a:(@) _ "{" _ body:objinside(s) _ "}" {Expr::ObjExtend(Rc::new(a), body)}
 				--
 				e:expr_basic(s) {e}
+				"(" _ e:expr(s) _ ")" {e}
 			}
 		pub rule index_part(s: &ParserSettings) -> IndexPart
 		= n:("?" _ ensure_null_coaelse())? "." _ value:id_loc(s) {IndexPart {
-			value,
+			span: value.1,
+			value: value.0,
 			#[cfg(feature = "exp-null-coaelse")]
 			null_coaelse: n.is_some(),
 		}}
-		/ n:("?" _ "." _ ensure_null_coaelse())? "[" _ value:expr(s) _ "]" {IndexPart {
-			value,
+		/ n:("?" _ "." _ ensure_null_coaelse())? value:spanned(<"[" _ v:expr(s) _ "]" {v}>, s) {IndexPart {
+			span: value.1,
+			value: value.0,
 			#[cfg(feature = "exp-null-coaelse")]
 			null_coaelse: n.is_some(),
 		}}
 
-		pub rule jsonnet(s: &ParserSettings) -> Spanned<Expr> = _ e:expr(s) _ {e}
+		pub rule jsonnet(s: &ParserSettings) -> Expr = _ e:expr(s) _ {e}
 	}
 }
 
 pub type ParseError = peg::error::ParseError<peg::str::LineCol>;
-pub fn parse(str: &str, settings: &ParserSettings) -> Result<Spanned<Expr>, ParseError> {
+pub fn parse(str: &str, settings: &ParserSettings) -> Result<Expr, ParseError> {
 	jsonnet_parser::jsonnet(str, settings)
 }
 /// Used for importstr values