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
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -1,12 +1,6 @@
-#![feature(box_syntax, box_patterns)]
-#![feature(type_alias_impl_trait)]
-#![feature(debug_non_exhaustive)]
-#![feature(test)]
-#![feature(stmt_expr_attributes)]
+#![cfg_attr(feature = "unstable", feature(stmt_expr_attributes))]
 #![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
 
-extern crate test;
-
 mod builtin;
 mod ctx;
 mod dynamic;
@@ -820,8 +814,6 @@
 		"#
 		);
 	}
-
-	use test::Bencher;
 
 	// This test is commented out by default, because of huge compilation slowdown
 	// #[bench]
@@ -836,6 +828,7 @@
 	// 	})
 	// }
 
+	/*
 	#[bench]
 	fn bench_serialize(b: &mut Bencher) {
 		b.iter(|| {
@@ -859,6 +852,7 @@
 			)
 		})
 	}
+	*/
 
 	#[test]
 	fn equality() {
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/obj.rs
1use crate::{evaluate_add_op, LazyBinding, Result, Val};2use indexmap::IndexMap;3use jrsonnet_parser::{ExprLocation, Visibility};4use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};56#[derive(Debug)]7pub struct ObjMember {8	pub add: bool,9	pub visibility: Visibility,10	pub invoke: LazyBinding,11	pub location: Option<ExprLocation>,12}1314// Field => This15type CacheKey = (Rc<str>, usize);16#[derive(Debug)]17pub struct ObjValueInternals {18	super_obj: Option<ObjValue>,19	this_entries: Rc<HashMap<Rc<str>, ObjMember>>,20	value_cache: RefCell<HashMap<CacheKey, Option<Val>>>,21}22#[derive(Clone)]23pub struct ObjValue(pub(crate) Rc<ObjValueInternals>);24impl Debug for ObjValue {25	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {26		if let Some(super_obj) = self.0.super_obj.as_ref() {27			if f.alternate() {28				write!(f, "{:#?}", super_obj)?;29			} else {30				write!(f, "{:?}", super_obj)?;31			}32			write!(f, " + ")?;33		}34		let mut debug = f.debug_struct("ObjValue");35		for (name, member) in self.0.this_entries.iter() {36			debug.field(name, member);37		}38		debug.finish_non_exhaustive()39	}40}4142impl ObjValue {43	pub fn new(44		super_obj: Option<ObjValue>,45		this_entries: Rc<HashMap<Rc<str>, ObjMember>>,46	) -> ObjValue {47		ObjValue(Rc::new(ObjValueInternals {48			super_obj,49			this_entries,50			value_cache: RefCell::new(HashMap::new()),51		}))52	}53	pub fn new_empty() -> ObjValue {54		Self::new(None, Rc::new(HashMap::new()))55	}56	pub fn with_super(&self, super_obj: ObjValue) -> ObjValue {57		match &self.0.super_obj {58			None => ObjValue::new(Some(super_obj), self.0.this_entries.clone()),59			Some(v) => ObjValue::new(Some(v.with_super(super_obj)), self.0.this_entries.clone()),60		}61	}62	pub fn enum_fields(&self, handler: &impl Fn(&Rc<str>, &Visibility)) {63		if let Some(s) = &self.0.super_obj {64			s.enum_fields(handler);65		}66		for (name, member) in self.0.this_entries.iter() {67			handler(&name, &member.visibility);68		}69	}70	pub fn fields_visibility(&self) -> IndexMap<Rc<str>, bool> {71		let out = Rc::new(RefCell::new(IndexMap::new()));72		self.enum_fields(&|name, visibility| {73			let mut out = out.borrow_mut();74			match visibility {75				Visibility::Normal => {76					if !out.contains_key(name) {77						out.insert(name.to_owned(), true);78					}79				}80				Visibility::Hidden => {81					out.insert(name.to_owned(), false);82				}83				Visibility::Unhide => {84					out.insert(name.to_owned(), true);85				}86			};87		});88		Rc::try_unwrap(out).unwrap().into_inner()89	}90	pub fn visible_fields(&self) -> Vec<Rc<str>> {91		let mut visible_fields: Vec<_> = self92			.fields_visibility()93			.into_iter()94			.filter(|(_k, v)| *v)95			.map(|(k, _)| k)96			.collect();97		visible_fields.sort();98		visible_fields99	}100	pub fn get(&self, key: Rc<str>) -> Result<Option<Val>> {101		Ok(self.get_raw(key, self)?)102	}103	pub(crate) fn get_raw(&self, key: Rc<str>, real_this: &ObjValue) -> Result<Option<Val>> {104		let cache_key = (key.clone(), Rc::as_ptr(&real_this.0) as usize);105106		if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {107			return Ok(v.clone());108		}109		let value = match (self.0.this_entries.get(&key), &self.0.super_obj) {110			(Some(k), None) => Ok(Some(self.evaluate_this(k, real_this)?)),111			(Some(k), Some(s)) => {112				let our = self.evaluate_this(k, real_this)?;113				if k.add {114					s.get_raw(key, real_this)?115						.map_or(Ok(Some(our.clone())), |v| {116							Ok(Some(evaluate_add_op(&v, &our)?))117						})118				} else {119					Ok(Some(our))120				}121			}122			(None, Some(s)) => s.get_raw(key, real_this),123			(None, None) => Ok(None),124		}?;125		self.0126			.value_cache127			.borrow_mut()128			.insert(cache_key, value.clone());129		Ok(value)130	}131	fn evaluate_this(&self, v: &ObjMember, real_this: &ObjValue) -> Result<Val> {132		Ok(v.invoke133			.evaluate(Some(real_this.clone()), self.0.super_obj.clone())?134			.evaluate()?)135	}136}137impl PartialEq for ObjValue {138	fn eq(&self, other: &Self) -> bool {139		Rc::ptr_eq(&self.0, &other.0)140	}141}
after · crates/jrsonnet-evaluator/src/obj.rs
1use crate::{evaluate_add_op, LazyBinding, Result, Val};2use indexmap::IndexMap;3use jrsonnet_parser::{ExprLocation, Visibility};4use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};56#[derive(Debug)]7pub struct ObjMember {8	pub add: bool,9	pub visibility: Visibility,10	pub invoke: LazyBinding,11	pub location: Option<ExprLocation>,12}1314// Field => This15type CacheKey = (Rc<str>, usize);16#[derive(Debug)]17pub struct ObjValueInternals {18	super_obj: Option<ObjValue>,19	this_entries: Rc<HashMap<Rc<str>, ObjMember>>,20	value_cache: RefCell<HashMap<CacheKey, Option<Val>>>,21}22#[derive(Clone)]23pub struct ObjValue(pub(crate) Rc<ObjValueInternals>);24impl Debug for ObjValue {25	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {26		if let Some(super_obj) = self.0.super_obj.as_ref() {27			if f.alternate() {28				write!(f, "{:#?}", super_obj)?;29			} else {30				write!(f, "{:?}", super_obj)?;31			}32			write!(f, " + ")?;33		}34		let mut debug = f.debug_struct("ObjValue");35		for (name, member) in self.0.this_entries.iter() {36			debug.field(name, member);37		}38		#[cfg(feature = "unstable")]39		{40			debug.finish_non_exhaustive()41		}42		#[cfg(not(feature = "unstable"))]43		{44			debug.finish()45		}46	}47}4849impl ObjValue {50	pub fn new(51		super_obj: Option<ObjValue>,52		this_entries: Rc<HashMap<Rc<str>, ObjMember>>,53	) -> ObjValue {54		ObjValue(Rc::new(ObjValueInternals {55			super_obj,56			this_entries,57			value_cache: RefCell::new(HashMap::new()),58		}))59	}60	pub fn new_empty() -> ObjValue {61		Self::new(None, Rc::new(HashMap::new()))62	}63	pub fn with_super(&self, super_obj: ObjValue) -> ObjValue {64		match &self.0.super_obj {65			None => ObjValue::new(Some(super_obj), self.0.this_entries.clone()),66			Some(v) => ObjValue::new(Some(v.with_super(super_obj)), self.0.this_entries.clone()),67		}68	}69	pub fn enum_fields(&self, handler: &impl Fn(&Rc<str>, &Visibility)) {70		if let Some(s) = &self.0.super_obj {71			s.enum_fields(handler);72		}73		for (name, member) in self.0.this_entries.iter() {74			handler(&name, &member.visibility);75		}76	}77	pub fn fields_visibility(&self) -> IndexMap<Rc<str>, bool> {78		let out = Rc::new(RefCell::new(IndexMap::new()));79		self.enum_fields(&|name, visibility| {80			let mut out = out.borrow_mut();81			match visibility {82				Visibility::Normal => {83					if !out.contains_key(name) {84						out.insert(name.to_owned(), true);85					}86				}87				Visibility::Hidden => {88					out.insert(name.to_owned(), false);89				}90				Visibility::Unhide => {91					out.insert(name.to_owned(), true);92				}93			};94		});95		Rc::try_unwrap(out).unwrap().into_inner()96	}97	pub fn visible_fields(&self) -> Vec<Rc<str>> {98		let mut visible_fields: Vec<_> = self99			.fields_visibility()100			.into_iter()101			.filter(|(_k, v)| *v)102			.map(|(k, _)| k)103			.collect();104		visible_fields.sort();105		visible_fields106	}107	pub fn get(&self, key: Rc<str>) -> Result<Option<Val>> {108		Ok(self.get_raw(key, self)?)109	}110	pub(crate) fn get_raw(&self, key: Rc<str>, real_this: &ObjValue) -> Result<Option<Val>> {111		let cache_key = (key.clone(), Rc::as_ptr(&real_this.0) as usize);112113		if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {114			return Ok(v.clone());115		}116		let value = match (self.0.this_entries.get(&key), &self.0.super_obj) {117			(Some(k), None) => Ok(Some(self.evaluate_this(k, real_this)?)),118			(Some(k), Some(s)) => {119				let our = self.evaluate_this(k, real_this)?;120				if k.add {121					s.get_raw(key, real_this)?122						.map_or(Ok(Some(our.clone())), |v| {123							Ok(Some(evaluate_add_op(&v, &our)?))124						})125				} else {126					Ok(Some(our))127				}128			}129			(None, Some(s)) => s.get_raw(key, real_this),130			(None, None) => Ok(None),131		}?;132		self.0133			.value_cache134			.borrow_mut()135			.insert(cache_key, value.clone());136		Ok(value)137	}138	fn evaluate_this(&self, v: &ObjMember, real_this: &ObjValue) -> Result<Val> {139		Ok(v.invoke140			.evaluate(Some(real_this.clone()), self.0.super_obj.clone())?141			.evaluate()?)142	}143}144impl PartialEq for ObjValue {145	fn eq(&self, other: &Self) -> bool {146		Rc::ptr_eq(&self.0, &other.0)147	}148}
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))
 	}
+	*/
 }