difftreelog
build stable rustc support
in: master
7 files changed
bindings/jsonnet/src/lib.rsdiffbeforeafterboth1#![feature(custom_inner_attributes)]23pub mod import;4pub mod interop;5pub mod val_extract;6pub mod val_make;7pub mod val_modify;8pub mod vars_tlas;910use import::NativeImportResolver;11use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Val};12use std::{13 alloc::Layout,14 ffi::{CStr, CString},15 os::raw::{c_char, c_double, c_int, c_uint},16 path::PathBuf,17 rc::Rc,18};1920/// WASM stub21#[cfg(target_arch = "wasm32")]22#[no_mangle]23pub extern "C" fn _start() {}2425#[no_mangle]26pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {27 b"v0.16.0\0"28}2930#[no_mangle]31pub extern "C" fn jsonnet_make() -> *mut EvaluationState {32 let state = EvaluationState::default();33 state.with_stdlib();34 state.settings_mut().import_resolver = Box::new(NativeImportResolver::default());35 Box::into_raw(Box::new(state))36}3738/// # Safety39#[no_mangle]40#[allow(clippy::boxed_local)]41pub unsafe extern "C" fn jsonnet_destroy(vm: *mut EvaluationState) {42 Box::from_raw(vm);43}4445#[no_mangle]46pub extern "C" fn jsonnet_max_stack(vm: &EvaluationState, v: c_uint) {47 vm.settings_mut().max_stack = v as usize;48}4950// jrsonnet currently have no GC, so these functions is no-op51#[no_mangle]52pub extern "C" fn jsonnet_gc_min_objects(_vm: &EvaluationState, _v: c_uint) {}53#[no_mangle]54pub extern "C" fn jsonnet_gc_growth_trigger(_vm: &EvaluationState, _v: c_double) {}5556#[no_mangle]57pub extern "C" fn jsonnet_string_output(vm: &EvaluationState, v: c_int) {58 match v {59 1 => vm.set_manifest_format(ManifestFormat::None),60 0 => vm.set_manifest_format(ManifestFormat::Json(4)),61 _ => panic!("incorrect output format"),62 }63}6465/// # Safety66///67/// This function is most definitely broken, but it works somehow, see TODO inside68#[no_mangle]69pub unsafe extern "C" fn jsonnet_realloc(70 _vm: &EvaluationState,71 buf: *mut u8,72 sz: usize,73) -> *mut u8 {74 if buf.is_null() {75 assert!(sz != 0);76 return std::alloc::alloc(Layout::from_size_align(sz, std::mem::align_of::<u8>()).unwrap());77 }78 // TODO: Somehow store size of allocation, because its real size is probally not 16 :D79 // OR (Alternative way of fixing this TODO)80 // TODO: Standard allocator uses malloc, and it doesn't uses allocation size,81 // TODO: so it should work in normal cases. Maybe force allocator for this library?82 let old_layout = Layout::from_size_align(16, std::mem::align_of::<u8>()).unwrap();83 if sz == 0 {84 std::alloc::dealloc(buf, old_layout);85 return std::ptr::null_mut();86 }87 std::alloc::realloc(buf, old_layout, sz)88}8990/// # Safety91#[no_mangle]92#[allow(clippy::boxed_local)]93pub unsafe extern "C" fn jsonnet_json_destroy(_vm: &EvaluationState, v: *mut Val) {94 Box::from_raw(v);95}9697#[no_mangle]98pub extern "C" fn jsonnet_native_callback() {99 todo!()100}101102#[no_mangle]103pub extern "C" fn jsonnet_max_trace(vm: &EvaluationState, v: c_uint) {104 vm.set_max_trace(v as usize)105}106107/// # Safety108///109/// This function is safe, if received v is a pointer to normal C string110#[no_mangle]111pub unsafe extern "C" fn jsonnet_evaluate_file(112 vm: &EvaluationState,113 filename: *const c_char,114 error: &mut c_int,115) -> *const c_char {116 vm.run_in_state(|| {117 let filename = CStr::from_ptr(filename);118 match vm119 .evaluate_file_raw_nocwd(&PathBuf::from(filename.to_str().unwrap()))120 .and_then(|v| vm.with_tla(v))121 .and_then(|v| vm.manifest(v))122 {123 Ok(v) => {124 *error = 0;125 CString::new(&*v as &str).unwrap().into_raw()126 }127 Err(e) => {128 *error = 1;129 let out = vm.stringify_err(&e);130 CString::new(&out as &str).unwrap().into_raw()131 }132 }133 })134}135136/// # Safety137///138/// This function is safe, if received v is a pointer to normal C string139#[no_mangle]140pub unsafe extern "C" fn jsonnet_evaluate_snippet(141 vm: &EvaluationState,142 filename: *const c_char,143 snippet: *const c_char,144 error: &mut c_int,145) -> *const c_char {146 vm.run_in_state(|| {147 let filename = CStr::from_ptr(filename);148 let snippet = CStr::from_ptr(snippet);149 match vm150 .evaluate_snippet_raw(151 Rc::new(PathBuf::from(filename.to_str().unwrap())),152 snippet.to_str().unwrap().into(),153 )154 .and_then(|v| vm.with_tla(v))155 .and_then(|v| vm.manifest(v))156 {157 Ok(v) => {158 *error = 0;159 CString::new(&*v as &str).unwrap().into_raw()160 }161 Err(e) => {162 *error = 1;163 let out = vm.stringify_err(&e);164 CString::new(&out as &str).unwrap().into_raw()165 }166 }167 })168}169170#[no_mangle]171pub extern "C" fn jsonnet_evaluate_file_multi() {172 todo!()173}174#[no_mangle]175pub extern "C" fn jsonnet_evaluate_snippet_multi() {176 todo!()177}178#[no_mangle]179pub extern "C" fn jsonnet_evaluate_file_stream() {180 todo!()181}182#[no_mangle]183pub extern "C" fn jsonnet_evaluate_snippet_stream() {184 todo!()185}1pub mod import;2pub mod interop;3pub mod val_extract;4pub mod val_make;5pub mod val_modify;6pub mod vars_tlas;78use import::NativeImportResolver;9use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Val};10use std::{11 alloc::Layout,12 ffi::{CStr, CString},13 os::raw::{c_char, c_double, c_int, c_uint},14 path::PathBuf,15 rc::Rc,16};1718/// WASM stub19#[cfg(target_arch = "wasm32")]20#[no_mangle]21pub extern "C" fn _start() {}2223#[no_mangle]24pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {25 b"v0.16.0\0"26}2728#[no_mangle]29pub extern "C" fn jsonnet_make() -> *mut EvaluationState {30 let state = EvaluationState::default();31 state.with_stdlib();32 state.settings_mut().import_resolver = Box::new(NativeImportResolver::default());33 Box::into_raw(Box::new(state))34}3536/// # Safety37#[no_mangle]38#[allow(clippy::boxed_local)]39pub unsafe extern "C" fn jsonnet_destroy(vm: *mut EvaluationState) {40 Box::from_raw(vm);41}4243#[no_mangle]44pub extern "C" fn jsonnet_max_stack(vm: &EvaluationState, v: c_uint) {45 vm.settings_mut().max_stack = v as usize;46}4748// jrsonnet currently have no GC, so these functions is no-op49#[no_mangle]50pub extern "C" fn jsonnet_gc_min_objects(_vm: &EvaluationState, _v: c_uint) {}51#[no_mangle]52pub extern "C" fn jsonnet_gc_growth_trigger(_vm: &EvaluationState, _v: c_double) {}5354#[no_mangle]55pub extern "C" fn jsonnet_string_output(vm: &EvaluationState, v: c_int) {56 match v {57 1 => vm.set_manifest_format(ManifestFormat::None),58 0 => vm.set_manifest_format(ManifestFormat::Json(4)),59 _ => panic!("incorrect output format"),60 }61}6263/// # Safety64///65/// This function is most definitely broken, but it works somehow, see TODO inside66#[no_mangle]67pub unsafe extern "C" fn jsonnet_realloc(68 _vm: &EvaluationState,69 buf: *mut u8,70 sz: usize,71) -> *mut u8 {72 if buf.is_null() {73 assert!(sz != 0);74 return std::alloc::alloc(Layout::from_size_align(sz, std::mem::align_of::<u8>()).unwrap());75 }76 // TODO: Somehow store size of allocation, because its real size is probally not 16 :D77 // OR (Alternative way of fixing this TODO)78 // TODO: Standard allocator uses malloc, and it doesn't uses allocation size,79 // TODO: so it should work in normal cases. Maybe force allocator for this library?80 let old_layout = Layout::from_size_align(16, std::mem::align_of::<u8>()).unwrap();81 if sz == 0 {82 std::alloc::dealloc(buf, old_layout);83 return std::ptr::null_mut();84 }85 std::alloc::realloc(buf, old_layout, sz)86}8788/// # Safety89#[no_mangle]90#[allow(clippy::boxed_local)]91pub unsafe extern "C" fn jsonnet_json_destroy(_vm: &EvaluationState, v: *mut Val) {92 Box::from_raw(v);93}9495#[no_mangle]96pub extern "C" fn jsonnet_native_callback() {97 todo!()98}99100#[no_mangle]101pub extern "C" fn jsonnet_max_trace(vm: &EvaluationState, v: c_uint) {102 vm.set_max_trace(v as usize)103}104105/// # Safety106///107/// This function is safe, if received v is a pointer to normal C string108#[no_mangle]109pub unsafe extern "C" fn jsonnet_evaluate_file(110 vm: &EvaluationState,111 filename: *const c_char,112 error: &mut c_int,113) -> *const c_char {114 vm.run_in_state(|| {115 let filename = CStr::from_ptr(filename);116 match vm117 .evaluate_file_raw_nocwd(&PathBuf::from(filename.to_str().unwrap()))118 .and_then(|v| vm.with_tla(v))119 .and_then(|v| vm.manifest(v))120 {121 Ok(v) => {122 *error = 0;123 CString::new(&*v as &str).unwrap().into_raw()124 }125 Err(e) => {126 *error = 1;127 let out = vm.stringify_err(&e);128 CString::new(&out as &str).unwrap().into_raw()129 }130 }131 })132}133134/// # Safety135///136/// This function is safe, if received v is a pointer to normal C string137#[no_mangle]138pub unsafe extern "C" fn jsonnet_evaluate_snippet(139 vm: &EvaluationState,140 filename: *const c_char,141 snippet: *const c_char,142 error: &mut c_int,143) -> *const c_char {144 vm.run_in_state(|| {145 let filename = CStr::from_ptr(filename);146 let snippet = CStr::from_ptr(snippet);147 match vm148 .evaluate_snippet_raw(149 Rc::new(PathBuf::from(filename.to_str().unwrap())),150 snippet.to_str().unwrap().into(),151 )152 .and_then(|v| vm.with_tla(v))153 .and_then(|v| vm.manifest(v))154 {155 Ok(v) => {156 *error = 0;157 CString::new(&*v as &str).unwrap().into_raw()158 }159 Err(e) => {160 *error = 1;161 let out = vm.stringify_err(&e);162 CString::new(&out as &str).unwrap().into_raw()163 }164 }165 })166}167168#[no_mangle]169pub extern "C" fn jsonnet_evaluate_file_multi() {170 todo!()171}172#[no_mangle]173pub extern "C" fn jsonnet_evaluate_snippet_multi() {174 todo!()175}176#[no_mangle]177pub extern "C" fn jsonnet_evaluate_file_stream() {178 todo!()179}180#[no_mangle]181pub extern "C" fn jsonnet_evaluate_snippet_stream() {182 todo!()183}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.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))
}
+ */
}