difftreelog
build stable rustc support
in: master
7 files changed
bindings/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;
crates/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" }
crates/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)
crates/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)()
};
}
crates/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() {
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth1use 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}crates/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))
}
+ */
}