git.delta.rocks / jrsonnet / refs/commits / 1d4b842070e4

difftreelog

build stable rustc support

Lach2020-08-03parent: #bb6d643.patch.diff
in: master

7 files changed

modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -1,5 +1,3 @@
-#![feature(custom_inner_attributes)]
-
 pub mod import;
 pub mod interop;
 pub mod val_extract;
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -20,6 +20,9 @@
 # Rustc-like trace visualization
 explaining-traces = ["annotate-snippets"]
 
+# Unlocks extra features, but works only on unstable
+unstable = []
+
 [dependencies]
 jrsonnet-parser = { path = "../jrsonnet-parser", version = "1.0.0" }
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "1.0.0" }
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -2,12 +2,7 @@
 	error::Error::*, future_wrapper, map::LayeredHashMap, rc_fn_helper, resolved_lazy_val,
 	LazyBinding, LazyVal, ObjValue, Result, Val,
 };
-use std::{
-	cell::RefCell,
-	collections::HashMap,
-	fmt::Debug,
-	rc::{Rc, Weak},
-};
+use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
 
 rc_fn_helper!(
 	ContextCreator,
@@ -138,6 +133,7 @@
 		}
 		Ok(self.extend(new, new_dollar, this, super_obj))
 	}
+	#[cfg(feature = "unstable")]
 	pub fn into_weak(self) -> WeakContext {
 		WeakContext(Rc::downgrade(&self.0))
 	}
@@ -155,13 +151,16 @@
 	}
 }
 
+#[cfg(feature = "unstable")]
 #[derive(Debug, Clone)]
-pub struct WeakContext(Weak<ContextInternals>);
+pub struct WeakContext(std::rc::Weak<ContextInternals>);
+#[cfg(feature = "unstable")]
 impl WeakContext {
 	pub fn upgrade(&self) -> Context {
 		Context(self.0.upgrade().expect("context is removed"))
 	}
 }
+#[cfg(feature = "unstable")]
 impl PartialEq for WeakContext {
 	fn eq(&self, other: &Self) -> bool {
 		self.0.ptr_eq(&other.0)
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -390,10 +390,16 @@
 
 /// Extracts code block and disables inlining for them
 /// Fixes WASM to java bytecode compilation failing because of very large method
+#[cfg(feature = "unstable")]
+macro_rules! noinline {
+	($e:expr) => {
+		(#![inline(never)] move || $e)()
+	};
+}
+#[cfg(not(feature = "unstable"))]
 macro_rules! noinline {
 	($e:expr) => {
-		(#[inline(never)]
-		move || $e)()
+		(move || $e)()
 	};
 }
 
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/lib.rs
1#![feature(box_syntax, box_patterns)]2#![feature(type_alias_impl_trait)]3#![feature(debug_non_exhaustive)]4#![feature(test)]5#![feature(stmt_expr_attributes)]6#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]78extern crate test;910mod builtin;11mod ctx;12mod dynamic;13pub mod error;14mod evaluate;15mod function;16mod import;17mod map;18mod obj;19pub mod trace;20mod val;2122pub use ctx::*;23pub use dynamic::*;24use error::{Error::*, LocError, Result, StackTraceElement};25pub use evaluate::*;26pub use function::parse_function_call;27pub use import::*;28use jrsonnet_parser::*;29pub use obj::*;30use std::{31	cell::{Ref, RefCell, RefMut},32	collections::HashMap,33	fmt::Debug,34	path::PathBuf,35	rc::Rc,36};37use trace::{offset_to_location, CodeLocation, CompactFormat, TraceFormat};38pub use val::*;3940type BindableFn = dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<LazyVal>;41#[derive(Clone)]42pub enum LazyBinding {43	Bindable(Rc<BindableFn>),44	Bound(LazyVal),45}4647impl Debug for LazyBinding {48	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {49		write!(f, "LazyBinding")50	}51}52impl LazyBinding {53	pub fn evaluate(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal> {54		match self {55			LazyBinding::Bindable(v) => v(this, super_obj),56			LazyBinding::Bound(v) => Ok(v.clone()),57		}58	}59}6061#[derive(Clone)]62pub enum ManifestFormat {63	Yaml(usize),64	Json(usize),65	None,66}6768pub struct EvaluationSettings {69	/// Limits recursion by limiting stack frames70	pub max_stack: usize,71	/// Limit amount of stack trace items preserved72	pub max_trace: usize,73	/// Used for std.extVar74	pub ext_vars: HashMap<Rc<str>, Val>,75	/// TLA vars76	pub tla_vars: HashMap<Rc<str>, Val>,77	/// Global variables are inserted in default context78	pub globals: HashMap<Rc<str>, Val>,79	/// Used to resolve file locations/contents80	pub import_resolver: Box<dyn ImportResolver>,81	/// Used in manifestification functions82	pub manifest_format: ManifestFormat,83	/// Used for bindings84	pub trace_format: Box<dyn TraceFormat>,85}86impl Default for EvaluationSettings {87	fn default() -> Self {88		EvaluationSettings {89			max_stack: 200,90			max_trace: 20,91			globals: Default::default(),92			ext_vars: Default::default(),93			tla_vars: Default::default(),94			import_resolver: Box::new(DummyImportResolver),95			manifest_format: ManifestFormat::Json(4),96			trace_format: Box::new(CompactFormat {97				padding: 4,98				resolver: trace::PathResolver::Absolute,99			}),100		}101	}102}103104#[derive(Default)]105struct EvaluationData {106	/// Used for stack overflow detection, stacktrace is now populated on unwind107	stack_depth: usize,108	/// Contains file source codes and evaluated results for imports and pretty109	/// printing stacktraces110	files: HashMap<Rc<PathBuf>, FileData>,111	str_files: HashMap<Rc<PathBuf>, Rc<str>>,112}113114pub struct FileData {115	source_code: Rc<str>,116	parsed: LocExpr,117	evaluated: Option<Val>,118}119#[derive(Default)]120pub struct EvaluationStateInternals {121	/// Internal state122	data: RefCell<EvaluationData>,123	/// Settings, safe to change at runtime124	settings: RefCell<EvaluationSettings>,125}126127thread_local! {128	/// Contains state for currently executing file129	/// Global state is fine there130	pub(crate) static EVAL_STATE: RefCell<Option<EvaluationState>> = RefCell::new(None)131}132pub(crate) fn with_state<T>(f: impl FnOnce(&EvaluationState) -> T) -> T {133	EVAL_STATE.with(|s| f(s.borrow().as_ref().unwrap()))134}135pub(crate) fn push<T>(136	e: &Option<ExprLocation>,137	frame_desc: impl FnOnce() -> String,138	f: impl FnOnce() -> Result<T>,139) -> Result<T> {140	if let Some(v) = e {141		with_state(|s| s.push(&v, frame_desc, f))142	} else {143		f()144	}145}146147/// Maintains stack trace and import resolution148#[derive(Default, Clone)]149pub struct EvaluationState(Rc<EvaluationStateInternals>);150151impl EvaluationState {152	/// Parses and adds file to loaded153	pub fn add_file(&self, path: Rc<PathBuf>, source_code: Rc<str>) -> Result<()> {154		self.add_parsed_file(155			path.clone(),156			source_code.clone(),157			parse(158				&source_code,159				&ParserSettings {160					file_name: path.clone(),161					loc_data: true,162				},163			)164			.map_err(|error| ImportSyntaxError {165				error,166				path,167				source_code,168			})?,169		)?;170171		Ok(())172	}173174	/// Adds file by source code and parsed expr175	pub fn add_parsed_file(176		&self,177		name: Rc<PathBuf>,178		source_code: Rc<str>,179		parsed: LocExpr,180	) -> Result<()> {181		self.data_mut().files.insert(182			name,183			FileData {184				source_code,185				parsed,186				evaluated: None,187			},188		);189190		Ok(())191	}192	pub fn get_source(&self, name: &PathBuf) -> Option<Rc<str>> {193		let ro_map = &self.data().files;194		ro_map.get(name).map(|value| value.source_code.clone())195	}196	pub fn map_source_locations(&self, file: &PathBuf, locs: &[usize]) -> Vec<CodeLocation> {197		offset_to_location(&self.get_source(file).unwrap(), locs)198	}199200	pub(crate) fn import_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Val> {201		let file_path = self.resolve_file(from, path)?;202		{203			let files = &self.data().files;204			if files.contains_key(&file_path) {205				return self.evaluate_loaded_file_raw(&file_path);206			}207		}208		let contents = self.load_file_contents(&file_path)?;209		self.add_file(file_path.clone(), contents)?;210		self.evaluate_loaded_file_raw(&file_path)211	}212	pub(crate) fn import_file_str(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<str>> {213		let path = self.resolve_file(from, path)?;214		if !self.data().str_files.contains_key(&path) {215			let file_str = self.load_file_contents(&path)?;216			self.data_mut().str_files.insert(path.clone(), file_str);217		}218		Ok(self.data().str_files.get(&path).cloned().unwrap())219	}220221	fn evaluate_loaded_file_raw(&self, name: &PathBuf) -> Result<Val> {222		let expr: LocExpr = {223			let ro_map = &self.data().files;224			let value = ro_map225				.get(name)226				.unwrap_or_else(|| panic!("file not added: {:?}", name));227			if let Some(ref evaluated) = value.evaluated {228				return Ok(evaluated.clone());229			}230			value.parsed.clone()231		};232		let value = evaluate(self.create_default_context()?, &expr)?;233		{234			self.data_mut()235				.files236				.get_mut(name)237				.unwrap()238				.evaluated239				.replace(value.clone());240		}241		Ok(value)242	}243244	/// Adds standard library global variable (std) to this evaluator245	pub fn with_stdlib(&self) -> &Self {246		use jrsonnet_stdlib::STDLIB_STR;247		let std_path = Rc::new(PathBuf::from("std.jsonnet"));248		self.run_in_state(|| {249			self.add_parsed_file(250				std_path.clone(),251				STDLIB_STR.to_owned().into(),252				builtin::get_parsed_stdlib(),253			)254			.unwrap();255			let val = self.evaluate_loaded_file_raw(&std_path).unwrap();256			self.settings_mut().globals.insert("std".into(), val);257		});258		self259	}260261	/// Creates context with all passed global variables262	pub fn create_default_context(&self) -> Result<Context> {263		let globals = &self.settings().globals;264		let mut new_bindings: HashMap<Rc<str>, LazyBinding> = HashMap::new();265		for (name, value) in globals.iter() {266			new_bindings.insert(267				name.clone(),268				LazyBinding::Bound(resolved_lazy_val!(value.clone())),269			);270		}271		Context::new().extend_unbound(new_bindings, None, None, None)272	}273274	/// Executes code, creating new stack frame275	pub fn push<T>(276		&self,277		e: &ExprLocation,278		frame_desc: impl FnOnce() -> String,279		f: impl FnOnce() -> Result<T>,280	) -> Result<T> {281		{282			let mut data = self.data_mut();283			let stack_depth = &mut data.stack_depth;284			if *stack_depth > self.max_stack() {285				// Error creation uses data, so i drop guard here286				drop(data);287				throw!(StackOverflow);288			} else {289				*stack_depth += 1;290			}291		}292		let result = f();293		self.data_mut().stack_depth -= 1;294		if let Err(mut err) = result {295			(err.1).0.push(StackTraceElement {296				location: e.clone(),297				desc: frame_desc(),298			});299			return Err(err);300		}301		result302	}303304	/// Runs passed function in state (required, if function needs to modify stack trace)305	pub fn run_in_state<T>(&self, f: impl FnOnce() -> T) -> T {306		EVAL_STATE.with(|v| {307			let has_state = v.borrow().is_some();308			if !has_state {309				v.borrow_mut().replace(self.clone());310			}311			let result = f();312			if !has_state {313				v.borrow_mut().take();314			}315			result316		})317	}318319	pub fn stringify_err(&self, e: &LocError) -> String {320		let mut out = String::new();321		self.settings()322			.trace_format323			.write_trace(&mut out, self, e)324			.unwrap();325		out326	}327328	pub fn manifest(&self, val: Val) -> Result<Rc<str>> {329		self.run_in_state(|| {330			Ok(match self.manifest_format() {331				ManifestFormat::Yaml(padding) => val.into_yaml(padding)?,332				ManifestFormat::Json(padding) => val.into_json(padding)?,333				ManifestFormat::None => match val {334					Val::Str(s) => s,335					_ => throw!(StringManifestOutputIsNotAString),336				},337			})338		})339	}340341	/// If passed value is function - call with set TLA342	pub fn with_tla(&self, val: Val) -> Result<Val> {343		Ok(match val {344			Val::Func(func) => func.evaluate_map(345				self.create_default_context()?,346				&self.settings().tla_vars,347				true,348			)?,349			v => v,350		})351	}352}353354/// Internals355impl EvaluationState {356	fn data(&self) -> Ref<EvaluationData> {357		self.0.data.borrow()358	}359	fn data_mut(&self) -> RefMut<EvaluationData> {360		self.0.data.borrow_mut()361	}362	pub fn settings(&self) -> Ref<EvaluationSettings> {363		self.0.settings.borrow()364	}365	pub fn settings_mut(&self) -> RefMut<EvaluationSettings> {366		self.0.settings.borrow_mut()367	}368}369370/// Raw methods evaluates passed values, but not performs TLA execution371impl EvaluationState {372	pub fn evaluate_file_raw(&self, name: &PathBuf) -> Result<Val> {373		self.run_in_state(|| self.import_file(&std::env::current_dir().expect("cwd"), &name))374	}375	pub fn evaluate_file_raw_nocwd(&self, name: &PathBuf) -> Result<Val> {376		self.run_in_state(|| self.import_file(&PathBuf::from("."), &name))377	}378	/// Parses and evaluates snippet379	pub fn evaluate_snippet_raw(&self, source: Rc<PathBuf>, code: Rc<str>) -> Result<Val> {380		let parsed = parse(381			&code,382			&ParserSettings {383				file_name: source.clone(),384				loc_data: true,385			},386		)387		.unwrap();388		self.add_parsed_file(source, code, parsed.clone())?;389		self.evaluate_expr_raw(parsed)390	}391	/// Evaluates parsed expression392	pub fn evaluate_expr_raw(&self, code: LocExpr) -> Result<Val> {393		self.run_in_state(|| evaluate(self.create_default_context()?, &code))394	}395}396397/// Settings utilities398impl EvaluationState {399	pub fn add_ext_var(&self, name: Rc<str>, value: Val) {400		self.settings_mut().ext_vars.insert(name, value);401	}402	pub fn add_ext_str(&self, name: Rc<str>, value: Rc<str>) {403		self.add_ext_var(name, Val::Str(value));404	}405	pub fn add_ext_code(&self, name: Rc<str>, code: Rc<str>) -> Result<()> {406		let value =407			self.evaluate_snippet_raw(Rc::new(PathBuf::from(format!("ext_code {}", name))), code)?;408		self.add_ext_var(name, value);409		Ok(())410	}411412	pub fn add_tla(&self, name: Rc<str>, value: Val) {413		self.settings_mut().tla_vars.insert(name, value);414	}415	pub fn add_tla_str(&self, name: Rc<str>, value: Rc<str>) {416		self.add_tla(name, Val::Str(value));417	}418	pub fn add_tla_code(&self, name: Rc<str>, code: Rc<str>) -> Result<()> {419		let value =420			self.evaluate_snippet_raw(Rc::new(PathBuf::from(format!("tla_code {}", name))), code)?;421		self.add_ext_var(name, value);422		Ok(())423	}424425	pub fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {426		Ok(self.settings().import_resolver.resolve_file(from, path)?)427	}428	pub fn load_file_contents(&self, path: &PathBuf) -> Result<Rc<str>> {429		Ok(self.settings().import_resolver.load_file_contents(path)?)430	}431432	pub fn import_resolver(&self) -> Ref<dyn ImportResolver> {433		Ref::map(self.settings(), |s| &*s.import_resolver)434	}435	pub fn set_import_resolver(&self, resolver: Box<dyn ImportResolver>) {436		self.settings_mut().import_resolver = resolver;437	}438439	pub fn manifest_format(&self) -> ManifestFormat {440		self.settings().manifest_format.clone()441	}442	pub fn set_manifest_format(&self, format: ManifestFormat) {443		self.settings_mut().manifest_format = format;444	}445446	pub fn trace_format(&self) -> Ref<dyn TraceFormat> {447		Ref::map(self.settings(), |s| &*s.trace_format)448	}449	pub fn set_trace_format(&self, format: Box<dyn TraceFormat>) {450		self.settings_mut().trace_format = format;451	}452453	pub fn max_trace(&self) -> usize {454		self.settings().max_trace455	}456	pub fn set_max_trace(&self, trace: usize) {457		self.settings_mut().max_trace = trace;458	}459460	pub fn max_stack(&self) -> usize {461		self.settings().max_stack462	}463	pub fn set_max_stack(&self, trace: usize) {464		self.settings_mut().max_stack = trace;465	}466}467468#[cfg(test)]469pub mod tests {470	use super::Val;471	use crate::{error::Error::*, primitive_equals, EvaluationState};472	use jrsonnet_parser::*;473	use std::{path::PathBuf, rc::Rc};474475	#[test]476	#[should_panic]477	fn eval_state_stacktrace() {478		let state = EvaluationState::default();479		state.run_in_state(|| {480			state481				.push(482					&ExprLocation(Rc::new(PathBuf::from("test1.jsonnet")), 10, 20),483					|| "outer".to_owned(),484					|| {485						state.push(486							&ExprLocation(Rc::new(PathBuf::from("test2.jsonnet")), 30, 40),487							|| "inner".to_owned(),488							|| Err(RuntimeError("".into()).into()),489						)?;490						Ok(())491					},492				)493				.unwrap();494		});495	}496497	#[test]498	fn eval_state_standard() {499		let state = EvaluationState::default();500		state.with_stdlib();501		assert!(primitive_equals(502			&state503				.evaluate_snippet_raw(504					Rc::new(PathBuf::from("raw.jsonnet")),505					r#"std.assertEqual(std.base64("test"), "dGVzdA==")"#.into()506				)507				.unwrap(),508			&Val::Bool(true),509		)510		.unwrap());511	}512513	macro_rules! eval {514		($str: expr) => {515			EvaluationState::default()516				.with_stdlib()517				.evaluate_snippet_raw(Rc::new(PathBuf::from("raw.jsonnet")), $str.into())518				.unwrap()519		};520	}521	macro_rules! eval_json {522		($str: expr) => {{523			let evaluator = EvaluationState::default();524			evaluator.with_stdlib();525			evaluator.run_in_state(|| {526				evaluator527					.evaluate_snippet_raw(Rc::new(PathBuf::from("raw.jsonnet")), $str.into())528					.unwrap()529					.into_json(0)530					.unwrap()531					.replace("\n", "")532				})533			}};534	}535536	/// Asserts given code returns `true`537	macro_rules! assert_eval {538		($str: expr) => {539			assert!(primitive_equals(&eval!($str), &Val::Bool(true)).unwrap())540		};541	}542543	/// Asserts given code returns `false`544	macro_rules! assert_eval_neg {545		($str: expr) => {546			assert!(primitive_equals(&eval!($str), &Val::Bool(false)).unwrap())547		};548	}549	macro_rules! assert_json {550		($str: expr, $out: expr) => {551			assert_eq!(eval_json!($str), $out.replace("\t", ""))552		};553	}554555	/// Sanity checking, before trusting to another tests556	#[test]557	fn equality_operator() {558		assert_eval!("2 == 2");559		assert_eval_neg!("2 != 2");560		assert_eval!("2 != 3");561		assert_eval_neg!("2 == 3");562		assert_eval!("'Hello' == 'Hello'");563		assert_eval_neg!("'Hello' != 'Hello'");564		assert_eval!("'Hello' != 'World'");565		assert_eval_neg!("'Hello' == 'World'");566	}567568	#[test]569	fn math_evaluation() {570		assert_eval!("2 + 2 * 2 == 6");571		assert_eval!("3 + (2 + 2 * 2) == 9");572	}573574	#[test]575	fn string_concat() {576		assert_eval!("'Hello' + 'World' == 'HelloWorld'");577		assert_eval!("'Hello' * 3 == 'HelloHelloHello'");578		assert_eval!("'Hello' + 'World' * 3 == 'HelloWorldWorldWorld'");579	}580581	#[test]582	fn faster_join() {583		assert_eval!("std.join([0,0], [[1,2],[3,4],[5,6]]) == [1,2,0,0,3,4,0,0,5,6]");584		assert_eval!("std.join(',', ['1','2','3','4']) == '1,2,3,4'");585	}586587	#[test]588	fn function_contexts() {589		assert_eval!(590			r#"591				local k = {592					t(name = self.h): [self.h, name],593					h: 3,594				};595				local f = {596					t: k.t(),597					h: 4,598				};599				f.t[0] == f.t[1]600			"#601		);602	}603604	#[test]605	fn local() {606		assert_eval!("local a = 2; local b = 3; a + b == 5");607		assert_eval!("local a = 1, b = a + 1; a + b == 3");608		assert_eval!("local a = 1; local a = 2; a == 2");609	}610611	#[test]612	fn object_lazyness() {613		assert_json!("local a = {a:error 'test'}; {}", r#"{}"#);614	}615616	#[test]617	fn object_inheritance() {618		assert_json!("{a: self.b} + {b:3}", r#"{"a": 3,"b": 3}"#);619	}620621	#[test]622	fn object_assertion_success() {623		eval!("{assert \"a\" in self} + {a:2}");624	}625626	#[test]627	fn object_assertion_error() {628		eval!("{assert \"a\" in self}");629	}630631	#[test]632	fn lazy_args() {633		eval!("local test(a) = 2; test(error '3')");634	}635636	#[test]637	#[should_panic]638	fn tailstrict_args() {639		eval!("local test(a) = 2; test(error '3') tailstrict");640	}641642	#[test]643	#[should_panic]644	fn no_binding_error() {645		eval!("a");646	}647648	#[test]649	fn test_object() {650		assert_json!("{a:2}", r#"{"a": 2}"#);651		assert_json!("{a:2+2}", r#"{"a": 4}"#);652		assert_json!("{a:2}+{b:2}", r#"{"a": 2,"b": 2}"#);653		assert_json!("{b:3}+{b:2}", r#"{"b": 2}"#);654		assert_json!("{b:3}+{b+:2}", r#"{"b": 5}"#);655		assert_json!("local test='a'; {[test]:2}", r#"{"a": 2}"#);656		assert_json!(657			r#"658				{659					name: "Alice",660					welcome: "Hello " + self.name + "!",661				}662			"#,663			r#"{"name": "Alice","welcome": "Hello Alice!"}"#664		);665		assert_json!(666			r#"667				{668					name: "Alice",669					welcome: "Hello " + self.name + "!",670				} + {671					name: "Bob"672				}673			"#,674			r#"{"name": "Bob","welcome": "Hello Bob!"}"#675		);676	}677678	#[test]679	fn functions() {680		assert_json!(r#"local a = function(b, c = 2) b + c; a(2)"#, "4");681		assert_json!(682			r#"local a = function(b, c = "Dear") b + c + d, d = "World"; a("Hello")"#,683			r#""HelloDearWorld""#684		);685	}686687	#[test]688	fn local_methods() {689		assert_json!(r#"local a(b, c = 2) = b + c; a(2)"#, "4");690		assert_json!(691			r#"local a(b, c = "Dear") = b + c + d, d = "World"; a("Hello")"#,692			r#""HelloDearWorld""#693		);694	}695696	#[test]697	fn object_locals() {698		assert_json!(r#"{local a = 3, b: a}"#, r#"{"b": 3}"#);699		assert_json!(r#"{local a = 3, local c = a, b: c}"#, r#"{"b": 3}"#);700		assert_json!(701			r#"{local a = function (b) {[b]:4}, test: a("test")}"#,702			r#"{"test": {"test": 4}}"#703		);704	}705706	#[test]707	fn object_comp() {708		assert_json!(709			r#"{local t = "a", ["h"+i+"_"+z]: if "h"+(i-1)+"_"+z in self then t+1 else 0+t for i in [1,2,3] for z in [2,3,4] if z != i}"#,710			"{\"h1_2\": \"0a\",\"h1_3\": \"0a\",\"h1_4\": \"0a\",\"h2_3\": \"a1\",\"h2_4\": \"a1\",\"h3_2\": \"0a\",\"h3_4\": \"a1\"}"711		)712	}713714	#[test]715	fn direct_self() {716		println!(717			"{:#?}",718			eval!(719				r#"720					{721						local me = self,722						a: 3,723						b(): me.a,724					}725				"#726			)727		);728	}729730	#[test]731	fn indirect_self() {732		// `self` assigned to `me` was lost when being733		// referenced from field734		eval!(735			r#"{736				local me = self,737				a: 3,738				b: me.a,739			}.b"#740		);741	}742743	// We can't trust other tests (And official jsonnet testsuite), if assert is not working correctly744	#[test]745	fn std_assert_ok() {746		eval!("std.assertEqual(4.5 << 2, 16)");747	}748749	#[test]750	#[should_panic]751	fn std_assert_failure() {752		eval!("std.assertEqual(4.5 << 2, 15)");753	}754755	#[test]756	fn string_is_string() {757		assert!(primitive_equals(758			&eval!("local arr = 'hello'; (!std.isArray(arr)) && (!std.isString(arr))"),759			&Val::Bool(false),760		)761		.unwrap());762	}763764	#[test]765	fn base64_works() {766		assert_json!(r#"std.base64("test")"#, r#""dGVzdA==""#);767	}768769	#[test]770	fn utf8_chars() {771		assert_json!(772			r#"local c="😎";{c:std.codepoint(c),l:std.length(c)}"#,773			r#"{"c": 128526,"l": 1}"#774		)775	}776777	#[test]778	fn json() {779		assert_json!(780			r#"std.manifestJsonEx({a:3, b:4, c:6},"")"#,781			r#""{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}""#782		);783	}784785	#[test]786	fn test() {787		assert_json!(788			r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,789			"[[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],[3,4],[3,5],[3,6]]"790		);791	}792793	#[test]794	fn sjsonnet() {795		eval!(796			r#"797			local x0 = {k: 1};798			local x1 = {k: x0.k + x0.k};799			local x2 = {k: x1.k + x1.k};800			local x3 = {k: x2.k + x2.k};801			local x4 = {k: x3.k + x3.k};802			local x5 = {k: x4.k + x4.k};803			local x6 = {k: x5.k + x5.k};804			local x7 = {k: x6.k + x6.k};805			local x8 = {k: x7.k + x7.k};806			local x9 = {k: x8.k + x8.k};807			local x10 = {k: x9.k + x9.k};808			local x11 = {k: x10.k + x10.k};809			local x12 = {k: x11.k + x11.k};810			local x13 = {k: x12.k + x12.k};811			local x14 = {k: x13.k + x13.k};812			local x15 = {k: x14.k + x14.k};813			local x16 = {k: x15.k + x15.k};814			local x17 = {k: x16.k + x16.k};815			local x18 = {k: x17.k + x17.k};816			local x19 = {k: x18.k + x18.k};817			local x20 = {k: x19.k + x19.k};818			local x21 = {k: x20.k + x20.k};819			x21.k820		"#821		);822	}823824	use test::Bencher;825826	// This test is commented out by default, because of huge compilation slowdown827	// #[bench]828	// fn bench_codegen(b: &mut Bencher) {829	// 	b.iter(|| {830	// 		#[allow(clippy::all)]831	// 		let stdlib = {832	// 			use jrsonnet_parser::*;833	// 			include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))834	// 		};835	// 		stdlib836	// 	})837	// }838839	#[bench]840	fn bench_serialize(b: &mut Bencher) {841		b.iter(|| {842			bincode::deserialize::<jrsonnet_parser::LocExpr>(include_bytes!(concat!(843				env!("OUT_DIR"),844				"/stdlib.bincode"845			)))846			.expect("deserialize stdlib")847		})848	}849850	#[bench]851	fn bench_parse(b: &mut Bencher) {852		b.iter(|| {853			jrsonnet_parser::parse(854				jrsonnet_stdlib::STDLIB_STR,855				&jrsonnet_parser::ParserSettings {856					loc_data: true,857					file_name: Rc::new(PathBuf::from("std.jsonnet")),858				},859			)860		})861	}862863	#[test]864	fn equality() {865		println!(866			"{:?}",867			jrsonnet_parser::parse(868				"{ x: 1, y: 2 } == { x: 1, y: 2 }",869				&ParserSettings::default()870			)871		);872		assert_eval!("{ x: 1, y: 2 } == { x: 1, y: 2 }")873	}874}
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -35,7 +35,14 @@
 		for (name, member) in self.0.this_entries.iter() {
 			debug.field(name, member);
 		}
-		debug.finish_non_exhaustive()
+		#[cfg(feature = "unstable")]
+		{
+			debug.finish_non_exhaustive()
+		}
+		#[cfg(not(feature = "unstable"))]
+		{
+			debug.finish()
+		}
 	}
 }
 
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -1,8 +1,3 @@
-#![feature(box_syntax)]
-#![feature(test)]
-
-extern crate test;
-
 use peg::parser;
 use std::{path::PathBuf, rc::Rc};
 mod expr;
@@ -581,11 +576,11 @@
 		parse!(jrsonnet_stdlib::STDLIB_STR);
 	}
 
-	use test::Bencher;
-
 	// From source code
+	/*
 	#[bench]
 	fn bench_parse_peg(b: &mut Bencher) {
 		b.iter(|| parse!(jrsonnet_stdlib::STDLIB_STR))
 	}
+	*/
 }