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.rsdiffbeforeafterboth1use crate::{2 error::Error::*, future_wrapper, map::LayeredHashMap, rc_fn_helper, resolved_lazy_val,3 LazyBinding, LazyVal, ObjValue, Result, Val,4};5use std::{6 cell::RefCell,7 collections::HashMap,8 fmt::Debug,9 rc::{Rc, Weak},10};1112rc_fn_helper!(13 ContextCreator,14 context_creator,15 dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<Context>16);1718future_wrapper!(Context, FutureContext);1920struct ContextInternals {21 dollar: Option<ObjValue>,22 this: Option<ObjValue>,23 super_obj: Option<ObjValue>,24 bindings: LayeredHashMap<Rc<str>, LazyVal>,25}26impl Debug for ContextInternals {27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {28 f.debug_struct("Context")29 .field("this", &self.this.as_ref().map(|e| Rc::as_ptr(&e.0)))30 .field("bindings", &self.bindings)31 .finish()32 }33}3435#[derive(Debug, Clone)]36pub struct Context(Rc<ContextInternals>);37impl Context {38 pub fn new_future() -> FutureContext {39 FutureContext(Rc::new(RefCell::new(None)))40 }4142 pub fn dollar(&self) -> &Option<ObjValue> {43 &self.0.dollar44 }4546 pub fn this(&self) -> &Option<ObjValue> {47 &self.0.this48 }4950 pub fn super_obj(&self) -> &Option<ObjValue> {51 &self.0.super_obj52 }5354 pub fn new() -> Context {55 Context(Rc::new(ContextInternals {56 dollar: None,57 this: None,58 super_obj: None,59 bindings: LayeredHashMap::default(),60 }))61 }6263 pub fn binding(&self, name: Rc<str>) -> Result<LazyVal> {64 Ok(self65 .066 .bindings67 .get(&name)68 .cloned()69 .ok_or_else(|| UnknownVariable(name))?)70 }71 pub fn into_future(self, ctx: FutureContext) -> Context {72 {73 ctx.0.borrow_mut().replace(self);74 }75 ctx.unwrap()76 }7778 pub fn with_var(self, name: Rc<str>, value: Val) -> Context {79 let mut new_bindings = HashMap::with_capacity(1);80 new_bindings.insert(name, resolved_lazy_val!(value));81 self.extend(new_bindings, None, None, None)82 }8384 pub fn extend(85 self,86 new_bindings: HashMap<Rc<str>, LazyVal>,87 new_dollar: Option<ObjValue>,88 new_this: Option<ObjValue>,89 new_super_obj: Option<ObjValue>,90 ) -> Context {91 match Rc::try_unwrap(self.0) {92 Ok(mut ctx) => {93 // Extended context aren't used by anything else, we can freely mutate it without cloning94 if let Some(dollar) = new_dollar {95 ctx.dollar = Some(dollar);96 }97 if let Some(this) = new_this {98 ctx.this = Some(this);99 }100 if let Some(super_obj) = new_super_obj {101 ctx.super_obj = Some(super_obj);102 }103 if !new_bindings.is_empty() {104 ctx.bindings = ctx.bindings.extend(new_bindings);105 }106 Context(Rc::new(ctx))107 }108 Err(ctx) => {109 let dollar = new_dollar.or_else(|| ctx.dollar.clone());110 let this = new_this.or_else(|| ctx.this.clone());111 let super_obj = new_super_obj.or_else(|| ctx.super_obj.clone());112 let bindings = if new_bindings.is_empty() {113 ctx.bindings.clone()114 } else {115 ctx.bindings.clone().extend(new_bindings)116 };117 Context(Rc::new(ContextInternals {118 dollar,119 this,120 super_obj,121 bindings,122 }))123 }124 }125 }126 pub fn extend_unbound(127 self,128 new_bindings: HashMap<Rc<str>, LazyBinding>,129 new_dollar: Option<ObjValue>,130 new_this: Option<ObjValue>,131 new_super_obj: Option<ObjValue>,132 ) -> Result<Context> {133 let this = new_this.or_else(|| self.0.this.clone());134 let super_obj = new_super_obj.or_else(|| self.0.super_obj.clone());135 let mut new = HashMap::with_capacity(new_bindings.len());136 for (k, v) in new_bindings.into_iter() {137 new.insert(k, v.evaluate(this.clone(), super_obj.clone())?);138 }139 Ok(self.extend(new, new_dollar, this, super_obj))140 }141 pub fn into_weak(self) -> WeakContext {142 WeakContext(Rc::downgrade(&self.0))143 }144}145146impl Default for Context {147 fn default() -> Self {148 Self::new()149 }150}151152impl PartialEq for Context {153 fn eq(&self, other: &Self) -> bool {154 Rc::ptr_eq(&self.0, &other.0)155 }156}157158#[derive(Debug, Clone)]159pub struct WeakContext(Weak<ContextInternals>);160impl WeakContext {161 pub fn upgrade(&self) -> Context {162 Context(self.0.upgrade().expect("context is removed"))163 }164}165impl PartialEq for WeakContext {166 fn eq(&self, other: &Self) -> bool {167 self.0.ptr_eq(&other.0)168 }169}1use crate::{2 error::Error::*, future_wrapper, map::LayeredHashMap, rc_fn_helper, resolved_lazy_val,3 LazyBinding, LazyVal, ObjValue, Result, Val,4};5use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};67rc_fn_helper!(8 ContextCreator,9 context_creator,10 dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<Context>11);1213future_wrapper!(Context, FutureContext);1415struct ContextInternals {16 dollar: Option<ObjValue>,17 this: Option<ObjValue>,18 super_obj: Option<ObjValue>,19 bindings: LayeredHashMap<Rc<str>, LazyVal>,20}21impl Debug for ContextInternals {22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {23 f.debug_struct("Context")24 .field("this", &self.this.as_ref().map(|e| Rc::as_ptr(&e.0)))25 .field("bindings", &self.bindings)26 .finish()27 }28}2930#[derive(Debug, Clone)]31pub struct Context(Rc<ContextInternals>);32impl Context {33 pub fn new_future() -> FutureContext {34 FutureContext(Rc::new(RefCell::new(None)))35 }3637 pub fn dollar(&self) -> &Option<ObjValue> {38 &self.0.dollar39 }4041 pub fn this(&self) -> &Option<ObjValue> {42 &self.0.this43 }4445 pub fn super_obj(&self) -> &Option<ObjValue> {46 &self.0.super_obj47 }4849 pub fn new() -> Context {50 Context(Rc::new(ContextInternals {51 dollar: None,52 this: None,53 super_obj: None,54 bindings: LayeredHashMap::default(),55 }))56 }5758 pub fn binding(&self, name: Rc<str>) -> Result<LazyVal> {59 Ok(self60 .061 .bindings62 .get(&name)63 .cloned()64 .ok_or_else(|| UnknownVariable(name))?)65 }66 pub fn into_future(self, ctx: FutureContext) -> Context {67 {68 ctx.0.borrow_mut().replace(self);69 }70 ctx.unwrap()71 }7273 pub fn with_var(self, name: Rc<str>, value: Val) -> Context {74 let mut new_bindings = HashMap::with_capacity(1);75 new_bindings.insert(name, resolved_lazy_val!(value));76 self.extend(new_bindings, None, None, None)77 }7879 pub fn extend(80 self,81 new_bindings: HashMap<Rc<str>, LazyVal>,82 new_dollar: Option<ObjValue>,83 new_this: Option<ObjValue>,84 new_super_obj: Option<ObjValue>,85 ) -> Context {86 match Rc::try_unwrap(self.0) {87 Ok(mut ctx) => {88 // Extended context aren't used by anything else, we can freely mutate it without cloning89 if let Some(dollar) = new_dollar {90 ctx.dollar = Some(dollar);91 }92 if let Some(this) = new_this {93 ctx.this = Some(this);94 }95 if let Some(super_obj) = new_super_obj {96 ctx.super_obj = Some(super_obj);97 }98 if !new_bindings.is_empty() {99 ctx.bindings = ctx.bindings.extend(new_bindings);100 }101 Context(Rc::new(ctx))102 }103 Err(ctx) => {104 let dollar = new_dollar.or_else(|| ctx.dollar.clone());105 let this = new_this.or_else(|| ctx.this.clone());106 let super_obj = new_super_obj.or_else(|| ctx.super_obj.clone());107 let bindings = if new_bindings.is_empty() {108 ctx.bindings.clone()109 } else {110 ctx.bindings.clone().extend(new_bindings)111 };112 Context(Rc::new(ContextInternals {113 dollar,114 this,115 super_obj,116 bindings,117 }))118 }119 }120 }121 pub fn extend_unbound(122 self,123 new_bindings: HashMap<Rc<str>, LazyBinding>,124 new_dollar: Option<ObjValue>,125 new_this: Option<ObjValue>,126 new_super_obj: Option<ObjValue>,127 ) -> Result<Context> {128 let this = new_this.or_else(|| self.0.this.clone());129 let super_obj = new_super_obj.or_else(|| self.0.super_obj.clone());130 let mut new = HashMap::with_capacity(new_bindings.len());131 for (k, v) in new_bindings.into_iter() {132 new.insert(k, v.evaluate(this.clone(), super_obj.clone())?);133 }134 Ok(self.extend(new, new_dollar, this, super_obj))135 }136 #[cfg(feature = "unstable")]137 pub fn into_weak(self) -> WeakContext {138 WeakContext(Rc::downgrade(&self.0))139 }140}141142impl Default for Context {143 fn default() -> Self {144 Self::new()145 }146}147148impl PartialEq for Context {149 fn eq(&self, other: &Self) -> bool {150 Rc::ptr_eq(&self.0, &other.0)151 }152}153154#[cfg(feature = "unstable")]155#[derive(Debug, Clone)]156pub struct WeakContext(std::rc::Weak<ContextInternals>);157#[cfg(feature = "unstable")]158impl WeakContext {159 pub fn upgrade(&self) -> Context {160 Context(self.0.upgrade().expect("context is removed"))161 }162}163#[cfg(feature = "unstable")]164impl PartialEq for WeakContext {165 fn eq(&self, other: &Self) -> bool {166 self.0.ptr_eq(&other.0)167 }168}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.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()
+ }
}
}
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))
}
+ */
}