git.delta.rocks / jrsonnet / refs/commits / 8d448f754f46

difftreelog

feat(evaluator) propogate EvaluationState

Лач2020-06-01parent: #1450eba.patch.diff
in: master

4 files changed

addedcrates/jsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jsonnet-evaluator/src/error.rs
@@ -0,0 +1 @@
+pub enum Error {}
modifiedcrates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/evaluate.rs
+++ b/crates/jsonnet-evaluator/src/evaluate.rs
@@ -1,7 +1,7 @@
 use crate::{
 	binding, bool_val, context_creator, function_default, function_rhs, future_wrapper,
-	lazy_binding, lazy_val, Context, ContextCreator, FuncDesc, LazyBinding, ObjMember, ObjValue,
-	Val,
+	lazy_binding, lazy_val, Context, ContextCreator, EvaluationState, FuncDesc, LazyBinding,
+	ObjMember, ObjValue, Val,
 };
 use closure::closure;
 use jsonnet_parser::{
@@ -13,15 +13,20 @@
 	rc::Rc,
 };
 
-pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (String, LazyBinding) {
+pub fn evaluate_binding(
+	eval_state: EvaluationState,
+	b: &BindSpec,
+	context_creator: ContextCreator,
+) -> (String, LazyBinding) {
 	let b = b.clone();
 	if let Some(args) = &b.params {
 		let args = args.clone();
 		(
 			b.name.clone(),
 			lazy_binding!(move |this, super_obj| lazy_val!(
-				closure!(clone b, clone args, clone context_creator, || evaluate_method(
+				closure!(clone b, clone args, clone context_creator, clone eval_state, || evaluate_method(
 					context_creator.0(this.clone(), super_obj.clone()),
+					eval_state.clone(),
 					&b.value,
 					args.clone()
 				))
@@ -31,29 +36,45 @@
 		(
 			b.name.clone(),
 			lazy_binding!(move |this, super_obj| {
-				lazy_val!(closure!(clone context_creator, clone b, || evaluate(
-					context_creator.0(this.clone(), super_obj.clone()),
-					&b.value
-				)))
+				lazy_val!(
+					closure!(clone context_creator, clone b, clone eval_state, || evaluate(
+						context_creator.0(this.clone(), super_obj.clone()),
+						eval_state.clone(),
+						&b.value
+					))
+				)
 			}),
 		)
 	}
 }
 
-pub fn evaluate_method(ctx: Context, expr: &LocExpr, arg_spec: ParamsDesc) -> Val {
+pub fn evaluate_method(
+	ctx: Context,
+	eval_state: EvaluationState,
+	expr: &LocExpr,
+	arg_spec: ParamsDesc,
+) -> Val {
 	Val::Func(FuncDesc {
 		ctx,
 		params: arg_spec,
-		eval_rhs: function_rhs!(closure!(clone expr, |ctx| evaluate(ctx, &expr))),
-		eval_default: function_default!(|ctx, default| evaluate(ctx, &default)),
+		eval_rhs: function_rhs!(
+			closure!(clone expr, clone eval_state, |ctx| evaluate(ctx, eval_state.clone(), &expr))
+		),
+		eval_default: function_default!(
+			closure!(clone eval_state, |ctx, default| evaluate(ctx, eval_state.clone(), &default))
+		),
 	})
 }
 
-pub fn evaluate_field_name(context: Context, field_name: &jsonnet_parser::FieldName) -> String {
+pub fn evaluate_field_name(
+	context: Context,
+	eval_state: EvaluationState,
+	field_name: &jsonnet_parser::FieldName,
+) -> String {
 	match field_name {
 		jsonnet_parser::FieldName::Fixed(n) => n.clone(),
 		jsonnet_parser::FieldName::Dyn(expr) => {
-			let name = evaluate(context, expr).unwrap_if_lazy();
+			let name = evaluate(context, eval_state, expr).unwrap_if_lazy();
 			match name {
 				Val::Str(n) => n,
 				_ => panic!(
@@ -132,7 +153,7 @@
 future_wrapper!(ObjValue, FutureObjValue);
 
 // TODO: Asserts
-pub fn evaluate_object(context: Context, object: ObjBody) -> ObjValue {
+pub fn evaluate_object(context: Context, eval_state: EvaluationState, object: ObjBody) -> ObjValue {
 	match object {
 		ObjBody::MemberList(members) => {
 			let new_bindings = FutureNewBindings::new();
@@ -155,7 +176,7 @@
 						Member::BindStmt(b) => Some(b.clone()),
 						_ => None,
 					})
-					.map(|b| evaluate_binding(&b, context_creator.clone()))
+					.map(|b| evaluate_binding(eval_state.clone(), &b, context_creator.clone()))
 				{
 					bindings.insert(n, b);
 				}
@@ -172,18 +193,19 @@
 						visibility,
 						value,
 					}) => {
-						let name = evaluate_field_name(context.clone(), &name);
+						let name = evaluate_field_name(context.clone(), eval_state.clone(), &name);
 						new_members.insert(
 							name,
 							ObjMember {
 								add: plus,
 								visibility: visibility.clone(),
 								invoke: binding!(
-									closure!(clone value, clone context_creator, |this, super_obj| {
+									closure!(clone value, clone context_creator, clone eval_state, |this, super_obj| {
 										let context = context_creator.0(this, super_obj);
 										// TODO: Assert
 										evaluate(
 											context,
+											eval_state.clone(),
 											&value,
 										).unwrap_if_lazy()
 									})
@@ -197,17 +219,18 @@
 						value,
 						..
 					}) => {
-						let name = evaluate_field_name(context.clone(), &name);
+						let name = evaluate_field_name(context.clone(), eval_state.clone(), &name);
 						new_members.insert(
 							name,
 							ObjMember {
 								add: false,
 								visibility: Visibility::Hidden,
 								invoke: binding!(
-									closure!(clone value, clone context_creator, |this, super_obj| {
+									closure!(clone value, clone context_creator, clone eval_state, |this, super_obj| {
 										// TODO: Assert
 										evaluate_method(
 											context_creator.0(this, super_obj),
+											eval_state.clone(),
 											&value.clone(),
 											params.clone(),
 										)
@@ -226,165 +249,171 @@
 	}
 }
 
-pub fn evaluate(context: Context, expr: &LocExpr) -> Val {
+pub fn evaluate(context: Context, eval_state: EvaluationState, expr: &LocExpr) -> Val {
+	println!("===");
+	eval_state.print_stack_trace();
 	use Expr::*;
-	let LocExpr(expr, loc) = expr;
-	match &**expr {
-		Literal(LiteralType::This) => Val::Obj(
-			context
-				.this()
-				.clone()
-				.unwrap_or_else(|| panic!("this not found")),
-		),
-		Literal(LiteralType::Super) => Val::Obj(
-			context
-				.super_obj()
-				.clone()
-				.unwrap_or_else(|| panic!("super not found")),
-		),
-		Literal(LiteralType::True) => Val::Bool(true),
-		Literal(LiteralType::False) => Val::Bool(false),
-		Literal(LiteralType::Null) => Val::Null,
-		Parened(e) => evaluate(context, e),
-		Str(v) => Val::Str(v.clone()),
-		Num(v) => Val::Num(*v),
-		BinaryOp(v1, o, v2) => {
-			evaluate_binary_op(&evaluate(context.clone(), v1), *o, &evaluate(context, v2))
-		}
-		UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(context, v)),
-		Var(name) => Val::Lazy(context.binding(&name)).unwrap_if_lazy(),
-		Index(value, index) => {
-			match (
-				evaluate(context.clone(), value).unwrap_if_lazy(),
-				evaluate(context.clone(), index),
-			) {
-				(Val::Obj(v), Val::Str(s)) => v
-					.get(&s)
-					.unwrap_or_else(closure!(clone context, || {
-						if let Some(n) = v.get("__intristic_namespace__") {
-							if let Val::Str(n) = n.unwrap_if_lazy() {
-								Val::Intristic(n, s)
+	eval_state.clone().push(expr.clone(), "expr".to_owned(), || {
+		let LocExpr(expr, loc) = expr;
+		match &**expr {
+			Literal(LiteralType::This) => Val::Obj(
+				context
+					.this()
+					.clone()
+					.unwrap_or_else(|| panic!("this not found")),
+			),
+			Literal(LiteralType::Super) => Val::Obj(
+				context
+					.super_obj()
+					.clone()
+					.unwrap_or_else(|| panic!("super not found")),
+			),
+			Literal(LiteralType::True) => Val::Bool(true),
+			Literal(LiteralType::False) => Val::Bool(false),
+			Literal(LiteralType::Null) => Val::Null,
+			Parened(e) => evaluate(context, eval_state.clone(), e),
+			Str(v) => Val::Str(v.clone()),
+			Num(v) => Val::Num(*v),
+			BinaryOp(v1, o, v2) => evaluate_binary_op(
+				&evaluate(context.clone(), eval_state.clone(), v1),
+				*o,
+				&evaluate(context, eval_state.clone(), v2),
+			),
+			UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(context, eval_state, v)),
+			Var(name) => Val::Lazy(context.binding(&name)).unwrap_if_lazy(),
+			Index(value, index) => {
+				match (
+					evaluate(context.clone(), eval_state.clone(), value).unwrap_if_lazy(),
+					evaluate(context.clone(), eval_state.clone(), index),
+				) {
+					(Val::Obj(v), Val::Str(s)) => v
+						.get(&s)
+						.unwrap_or_else(closure!(clone context, || {
+							if let Some(n) = v.get("__intristic_namespace__") {
+								if let Val::Str(n) = n.unwrap_if_lazy() {
+									Val::Intristic(n, s)
+								} else {
+									panic!("__intristic_namespace__ should be string");
+								}
 							} else {
-								panic!("__intristic_namespace__ should be string");
+								panic!("{} not found in {:?}", s, v)
 							}
-						} else {
-							panic!("{} not found in {:?}", s, v)
-						}
-					}))
-					.unwrap_if_lazy(),
-				(Val::Arr(v), Val::Num(n)) => v
-					.get(n as usize)
-					.unwrap_or_else(|| panic!("out of bounds"))
-					.clone(),
-				(Val::Str(s), Val::Num(n)) => {
-					Val::Str(s.chars().skip(n as usize).take(1).collect())
+						}))
+						.unwrap_if_lazy(),
+					(Val::Arr(v), Val::Num(n)) => v
+						.get(n as usize)
+						.unwrap_or_else(|| panic!("out of bounds"))
+						.clone(),
+					(Val::Str(s), Val::Num(n)) => {
+						Val::Str(s.chars().skip(n as usize).take(1).collect())
+					}
+					(v, i) => todo!("not implemented: {:?}[{:?}]", v, i.unwrap_if_lazy()),
 				}
-				(v, i) => todo!("not implemented: {:?}[{:?}]", v, i.unwrap_if_lazy()),
 			}
-		}
-		LocalExpr(bindings, returned) => {
-			let mut new_bindings: HashMap<String, LazyBinding> = HashMap::new();
-			let future_context = Context::new_future();
+			LocalExpr(bindings, returned) => {
+				let mut new_bindings: HashMap<String, LazyBinding> = HashMap::new();
+				let future_context = Context::new_future();
 
-			let context_creator = context_creator!(
-				closure!(clone future_context, |_, _| future_context.clone().unwrap())
-			);
+				let context_creator = context_creator!(
+					closure!(clone future_context, |_, _| future_context.clone().unwrap())
+				);
 
-			for (k, v) in bindings
-				.iter()
-				.map(move |b| evaluate_binding(b, context_creator.clone()))
-			{
-				new_bindings.insert(k, v);
-			}
+				for (k, v) in bindings
+					.iter()
+					.map(|b| evaluate_binding(eval_state.clone(), b, context_creator.clone()))
+				{
+					new_bindings.insert(k, v);
+				}
 
-			let context = context
-				.extend(new_bindings, None, None, None)
-				.into_future(future_context);
-			evaluate(context, &returned.clone())
-		}
-		Obj(body) => Val::Obj(evaluate_object(context, body.clone())),
-		Apply(value, ArgsDesc(args)) => {
-			let value = evaluate(context.clone(), value).unwrap_if_lazy();
-			match value {
-				// TODO: Capture context of application
-				Val::Intristic(ns, name) => match (&ns as &str, &name as &str) {
-					("std", "length") => {
-						assert_eq!(args.len(), 1);
-						let expr = &args.get(0).unwrap().1;
-						match evaluate(context, expr) {
-							Val::Str(n) => Val::Num(n.chars().count() as f64),
-							Val::Arr(i) => Val::Num(i.len() as f64),
-							v => panic!("can't get length of {:?}", v),
+				let context = context
+					.extend(new_bindings, None, None, None)
+					.into_future(future_context);
+				evaluate(context, eval_state.clone(), &returned.clone())
+			}
+			Obj(body) => Val::Obj(evaluate_object(context, eval_state, body.clone())),
+			Apply(value, ArgsDesc(args)) => {
+				let value = evaluate(context.clone(), eval_state.clone(), value).unwrap_if_lazy();
+				match value {
+					// TODO: Capture context of application
+					Val::Intristic(ns, name) => match (&ns as &str, &name as &str) {
+						("std", "length") => {
+							assert_eq!(args.len(), 1);
+							let expr = &args.get(0).unwrap().1;
+							match evaluate(context, eval_state.clone(), expr) {
+								Val::Str(n) => Val::Num(n.chars().count() as f64),
+								Val::Arr(i) => Val::Num(i.len() as f64),
+								v => panic!("can't get length of {:?}", v),
+							}
+						}
+						("std", "type") => {
+							assert_eq!(args.len(), 1);
+							let expr = &args.get(0).unwrap().1;
+							Val::Str(evaluate(context, eval_state, expr).type_of().to_owned())
 						}
-					}
-					("std", "type") => {
-						assert_eq!(args.len(), 1);
-						let expr = &args.get(0).unwrap().1;
-						Val::Str(evaluate(context, expr).type_of().to_owned())
-					}
-					("std", "makeArray") => {
-						assert_eq!(args.len(), 2);
-						if let (Val::Num(v), Val::Func(d)) = (
-							evaluate(context.clone(), &args[0].1),
-							evaluate(context, &args[1].1),
-						) {
-							assert!(v > 0.0);
-							let mut out = Vec::with_capacity(v as usize);
-							for i in 0..v as usize {
-								out.push(d.evaluate(vec![(None, Val::Num(i as f64))]))
+						("std", "makeArray") => {
+							assert_eq!(args.len(), 2);
+							if let (Val::Num(v), Val::Func(d)) = (
+								evaluate(context.clone(), eval_state.clone(), &args[0].1),
+								evaluate(context, eval_state, &args[1].1),
+							) {
+								assert!(v > 0.0);
+								let mut out = Vec::with_capacity(v as usize);
+								for i in 0..v as usize {
+									out.push(d.evaluate(vec![(None, Val::Num(i as f64))]))
+								}
+								Val::Arr(out)
+							} else {
+								panic!("bad makeArray call");
 							}
-							Val::Arr(out)
-						} else {
-							panic!("bad makeArray call");
 						}
-					}
-					("std", "codepoint") => {
-						assert_eq!(args.len(), 1);
-						if let Val::Str(s) = evaluate(context, &args[0].1) {
-							assert!(
-								s.chars().count() == 1,
-								"std.codepoint should receive single char string"
-							);
-							Val::Num(s.chars().take(1).next().unwrap() as u32 as f64)
-						} else {
-							panic!("bad codepoint call");
+						("std", "codepoint") => {
+							assert_eq!(args.len(), 1);
+							if let Val::Str(s) = evaluate(context, eval_state, &args[0].1) {
+								assert!(
+									s.chars().count() == 1,
+									"std.codepoint should receive single char string"
+								);
+								Val::Num(s.chars().take(1).next().unwrap() as u32 as f64)
+							} else {
+								panic!("bad codepoint call");
+							}
 						}
-					}
-					(ns, name) => panic!("Intristic not found: {}.{}", ns, name),
+						(ns, name) => panic!("Intristic not found: {}.{}", ns, name),
+					},
+					Val::Func(f) => f.evaluate(
+						args.clone()
+							.into_iter()
+							.map(move |a| {
+								(
+									a.clone().0,
+									Val::Lazy(lazy_val!(
+										closure!(clone context, clone a, clone eval_state, || evaluate(context.clone(), eval_state.clone(), &a.clone().1))
+									)),
+								)
+							})
+							.collect(),
+					),
+					_ => panic!("{:?} is not a function", value),
+				}
+			}
+			Function(params, body) => evaluate_method(context, eval_state, body, params.clone()),
+			Error(e) => panic!("error: {}", evaluate(context, eval_state, e)),
+			IfElse {
+				cond,
+				cond_then,
+				cond_else,
+			} => match evaluate(context.clone(), eval_state.clone(), &cond.0).unwrap_if_lazy() {
+				Val::Bool(true) => evaluate(context, eval_state.clone(), cond_then),
+				Val::Bool(false) => match cond_else {
+					Some(v) => evaluate(context, eval_state, v),
+					None => Val::Bool(false),
 				},
-				Val::Func(f) => f.evaluate(
-					args.clone()
-						.into_iter()
-						.map(|a| {
-							(
-								a.clone().0,
-								Val::Lazy(lazy_val!(
-									closure!(clone context, clone a, || evaluate(context.clone(), &a.clone().1))
-								)),
-							)
-						})
-						.collect(),
-				),
-				_ => panic!("{:?} is not a function", value),
-			}
-		}
-		Function(params, body) => evaluate_method(context, body, params.clone()),
-		Error(e) => panic!("error: {}", evaluate(context, e)),
-		IfElse {
-			cond,
-			cond_then,
-			cond_else,
-		} => match evaluate(context.clone(), &cond.0).unwrap_if_lazy() {
-			Val::Bool(true) => evaluate(context, cond_then),
-			Val::Bool(false) => match cond_else {
-				Some(v) => evaluate(context, v),
-				None => Val::Bool(false),
+				v => panic!("if condition evaluated to {:?} (boolean needed instead)", v),
 			},
-			v => panic!("if condition evaluated to {:?} (boolean needed instead)", v),
-		},
-		_ => panic!(
-			"evaluation not implemented: {:?}",
-			LocExpr(expr.clone(), loc.clone())
-		),
-	}
+			_ => panic!(
+				"evaluation not implemented: {:?}",
+				LocExpr(expr.clone(), loc.clone())
+			),
+		}
+	})
 }
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
4#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]4#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
5mod ctx;5mod ctx;
6mod dynamic;6mod dynamic;
7mod error;
7mod evaluate;8mod evaluate;
8mod obj;9mod obj;
9mod val;10mod val;
1011
11pub use ctx::*;12pub use ctx::*;
12pub use dynamic::*;13pub use dynamic::*;
14pub use error::*;
13pub use evaluate::*;15pub use evaluate::*;
14use jsonnet_parser::*;16use jsonnet_parser::*;
15pub use obj::*;17pub use obj::*;
33 dyn Fn(Context, LocExpr) -> Val35 dyn Fn(Context, LocExpr) -> Val
34);36);
3537
36pub struct ExitGuard<'s>(&'s EvaluationState);38#[derive(Default, Clone)]
37impl<'s> Drop for ExitGuard<'s> {
38 fn drop(&mut self) {
39 self.0.stack.borrow_mut().pop();
40 }
41}
42
43pub struct EvaluationState {39pub struct EvaluationState {
40 /// Used for stack-overflows and stacktraces
44 pub stack: Rc<RefCell<Vec<LocExpr>>>,41 pub stack: Rc<RefCell<Vec<(LocExpr, String)>>>,
42 /// Contains file source codes and evaluated results for imports and pretty printing stacktraces
45 pub files: Rc<RefCell<HashMap<String, String>>>,43 pub files: Rc<RefCell<HashMap<String, (String, Option<Val>)>>>,
46}44}
47impl EvaluationState {45impl EvaluationState {
48 #[must_use = "should keep exit guard before exit from function"]
49 pub fn push(&self, e: LocExpr) -> ExitGuard {46 pub fn push<T>(&self, e: LocExpr, comment: String, f: impl FnOnce() -> T) -> T {
50 self.stack.borrow_mut().push(e);47 self.stack.borrow_mut().push((e, comment));
48 let result = f();
51 ExitGuard(self)49 self.stack.borrow_mut().pop();
50 result
52 }51 }
53 pub fn print_stack_trace(&self) {52 pub fn print_stack_trace(&self) {
54 for e in self53 for e in self
55 .stack54 .stack
56 .borrow()55 .borrow()
57 .iter()56 .iter()
58 .rev()57 .rev()
59 .map(|e| e.1.clone())58 .map(|(loc, comment)| loc.1.clone().map(|v| (v, comment.clone())))
60 .flatten()59 .flatten()
61 {60 {
62 println!("{:?}", e)61 println!("{:?} - {:?}", e.0, e.1)
63 }62 }
64 }63 }
64 pub fn stack_trace(&self) -> Vec<(LocExpr, String)> {
65 self.stack
66 .borrow()
67 .iter()
68 .rev()
69 .map(|e| e.clone())
70 .collect()
71 }
65}72}
66impl Default for EvaluationState {
67 fn default() -> Self {
68 EvaluationState {
69 stack: Rc::new(RefCell::new(Vec::new())),
70 files: Rc::new(RefCell::new(HashMap::new())),
71 }
72 }
73}
7473
75#[cfg(test)]74#[cfg(test)]
76pub mod tests {75pub mod tests {
81 #[test]80 #[test]
82 fn eval_state_stacktrace() {81 fn eval_state_stacktrace() {
83 let state = EvaluationState::default();82 let state = EvaluationState::default();
84 let _v = state.push(loc_expr!(83 state.push(
85 Expr::Num(0.0),84 loc_expr!(Expr::Num(0.0), true, ("test1.jsonnet".to_owned(), 10, 20)),
86 true,85 "outer".to_owned(),
87 ("test.jsonnet".to_owned(), 10, 20)86 || {
87 state.push(
88 loc_expr!(Expr::Num(0.0), true, ("test2.jsonnet".to_owned(), 30, 40)),
89 "inner".to_owned(),
90 || state.print_stack_trace(),
91 );
92 },
88 ));93 );
89
90 state.print_stack_trace()
91 }94 }
9295
93 macro_rules! eval {96 macro_rules! eval {
94 ($str: expr) => {97 ($str: expr) => {
95 evaluate(98 evaluate(
96 Context::new(),99 Context::new(),
100 EvaluationState::default(),
97 &parse(101 &parse(
98 $str,102 $str,
99 &ParserSettings {103 &ParserSettings {
111 let std = "local std = ".to_owned() + jsonnet_stdlib::STDLIB_STR + ";";115 let std = "local std = ".to_owned() + jsonnet_stdlib::STDLIB_STR + ";";
112 evaluate(116 evaluate(
113 Context::new(),117 Context::new(),
118 EvaluationState::default(),
114 &parse(119 &parse(
115 &(std + $str),120 &(std + $str),
116 &ParserSettings {121 &ParserSettings {
128 assert_eq!(133 assert_eq!(
129 evaluate(134 evaluate(
130 Context::new(),135 Context::new(),
136 EvaluationState::default(),
131 &parse(137 &parse(
132 $str,138 $str,
133 &ParserSettings {139 &ParserSettings {
148 "{}",154 "{}",
149 evaluate(155 evaluate(
150 Context::new(),156 Context::new(),
157 EvaluationState::default(),
151 &parse(158 &parse(
152 $str,159 $str,
153 &ParserSettings {160 &ParserSettings {
172 assert_eq!(179 assert_eq!(
173 evaluate(180 evaluate(
174 Context::new(),181 Context::new(),
182 EvaluationState::default(),
175 &parse(183 &parse(
176 $str,184 $str,
177 &ParserSettings {185 &ParserSettings {
357 #[test]365 #[test]
358 fn sjsonnet() {366 fn sjsonnet() {
359 eval!(367 eval!(
360 r#"368 r#"
361 local x0 = {k: 1};369 local x0 = {k: 1};
362 local x1 = {k: x0.k + x0.k};370 local x1 = {k: x0.k + x0.k};
363 local x2 = {k: x1.k + x1.k};371 local x2 = {k: x1.k + x1.k};
364 local x3 = {k: x2.k + x2.k};372 local x3 = {k: x2.k + x2.k};
365 local x4 = {k: x3.k + x3.k};373 local x4 = {k: x3.k + x3.k};
366 local x5 = {k: x4.k + x4.k};374 local x5 = {k: x4.k + x4.k};
367 local x6 = {k: x5.k + x5.k};375 local x6 = {k: x5.k + x5.k};
368 local x7 = {k: x6.k + x6.k};376 local x7 = {k: x6.k + x6.k};
369 local x8 = {k: x7.k + x7.k};377 local x8 = {k: x7.k + x7.k};
370 local x9 = {k: x8.k + x8.k};378 local x9 = {k: x8.k + x8.k};
371 local x10 = {k: x9.k + x9.k};379 local x10 = {k: x9.k + x9.k};
372 local x11 = {k: x10.k + x10.k};380 local x11 = {k: x10.k + x10.k};
373 local x12 = {k: x11.k + x11.k};381 local x12 = {k: x11.k + x11.k};
374 local x13 = {k: x12.k + x12.k};382 local x13 = {k: x12.k + x12.k};
375 local x14 = {k: x13.k + x13.k};383 local x14 = {k: x13.k + x13.k};
376 local x15 = {k: x14.k + x14.k};384 local x15 = {k: x14.k + x14.k};
377 local x16 = {k: x15.k + x15.k};385 local x16 = {k: x15.k + x15.k};
378 local x17 = {k: x16.k + x16.k};386 local x17 = {k: x16.k + x16.k};
379 local x18 = {k: x17.k + x17.k};387 local x18 = {k: x17.k + x17.k};
380 local x19 = {k: x18.k + x18.k};388 local x19 = {k: x18.k + x18.k};
381 local x20 = {k: x19.k + x19.k};389 local x20 = {k: x19.k + x19.k};
382 local x21 = {k: x20.k + x20.k};390 local x21 = {k: x20.k + x20.k};
383 x21.k391 "#
384 "#
385 );392 );
386 }393 }
387}394}
modifiedcrates/jsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jsonnet-parser/src/expr.rs
+++ b/crates/jsonnet-parser/src/expr.rs
@@ -246,7 +246,11 @@
 		LocExpr(
 			std::rc::Rc::new($expr),
 			if $need_loc {
-				Some(std::rc::Rc::new(ExprLocation($name.to_owned(), $start, $end)))
+				Some(std::rc::Rc::new(ExprLocation(
+					$name.to_owned(),
+					$start,
+					$end,
+				)))
 			} else {
 				None
 				},