git.delta.rocks / jrsonnet / refs/commits / 8d08861d28f9

difftreelog

refactor remove debug gc trace

Yaroslav Bolyukin2021-07-04parent: #b2b77e5.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -126,7 +126,6 @@
 			buf.push('}');
 		}
 		Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),
-		Val::DebugGcTraceValue(v) => manifest_json_ex_buf(&v.value, buf, cur_padding, options)?,
 	};
 	Ok(())
 }
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,8 +1,8 @@
 use crate::{
 	equals,
 	error::{Error::*, Result},
-	parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, DebugGcTraceValue,
-	EvaluationState, FuncVal, LazyVal, Val,
+	parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, EvaluationState,
+	FuncVal, LazyVal, Val,
 };
 use format::{format_arr, format_obj};
 use jrsonnet_gc::Gc;
@@ -69,8 +69,6 @@
 			("md5".into(), builtin_md5),
 			("base64".into(), builtin_base64),
 			("trace".into(), builtin_trace),
-			("gc".into(), builtin_gc),
-			("gcTrace".into(), builtin_gc_trace),
 			("join".into(), builtin_join),
 			("escapeStringJson".into(), builtin_escape_string_json),
 			("manifestJsonEx".into(), builtin_manifest_json_ex),
@@ -446,27 +444,6 @@
 		}
 		eprintln!(" {}", str);
 		Ok(rest)
-	})
-}
-
-fn builtin_gc(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
-	parse_args!(context, "gc", args, 1, [
-		0, rest: ty!(any);
-	], {
-		println!("GC start");
-		jrsonnet_gc::force_collect();
-		println!("GC done");
-
-		Ok(rest)
-	})
-}
-
-fn builtin_gc_trace(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
-	parse_args!(context, "gcTrace", args, 2, [
-		0, name: ty!(string) => Val::Str;
-		1, rest: ty!(any);
-	], {
-		Ok(DebugGcTraceValue::create(name, rest))
 	})
 }
 
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -215,9 +215,6 @@
 
 pub fn evaluate_add_op(a: &Val, b: &Val) -> Result<Val> {
 	Ok(match (a, b) {
-		(Val::DebugGcTraceValue(v1), Val::DebugGcTraceValue(v2)) => {
-			evaluate_add_op(&v1.value, &v2.value)?
-		}
 		(Val::Str(v1), Val::Str(v2)) => Val::Str(((**v1).to_owned() + v2).into()),
 
 		// Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,4};5use jrsonnet_gc::Gc;6use jrsonnet_parser::Visibility;7use rustc_hash::FxHasher;8use serde_json::{Map, Number, Value};9use std::{10	collections::HashMap,11	convert::{TryFrom, TryInto},12	hash::BuildHasherDefault,13};1415impl TryFrom<&Val> for Value {16	type Error = LocError;17	fn try_from(v: &Val) -> Result<Self> {18		Ok(match v {19			Val::Bool(b) => Self::Bool(*b),20			Val::Null => Self::Null,21			Val::Str(s) => Self::String((s as &str).into()),22			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {23				(*n as i64).into()24			} else {25				Number::from_f64(*n).expect("to json number")26			}),27			Val::Arr(a) => {28				let mut out = Vec::with_capacity(a.len());29				for item in a.iter() {30					out.push((&item?).try_into()?);31				}32				Self::Array(out)33			}34			Val::Obj(o) => {35				let mut out = Map::new();36				for key in o.fields() {37					out.insert(38						(&key as &str).into(),39						(&o.get(key)?.expect("field exists")).try_into()?,40					);41				}42				Self::Object(out)43			}44			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),45			Val::DebugGcTraceValue(v) => Self::try_from(&*v.value as &Val)?,46		})47	}48}4950impl From<&Value> for Val {51	fn from(v: &Value) -> Self {52		match v {53			Value::Null => Self::Null,54			Value::Bool(v) => Self::Bool(*v),55			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),56			Value::String(s) => Self::Str((s as &str).into()),57			Value::Array(a) => {58				let mut out = Vec::with_capacity(a.len());59				for v in a {60					out.push(LazyVal::new_resolved(v.into()));61				}62				Self::Arr(out.into())63			}64			Value::Object(o) => {65				let mut entries = HashMap::with_capacity_and_hasher(66					o.len(),67					BuildHasherDefault::<FxHasher>::default(),68				);69				for (k, v) in o {70					entries.insert(71						(k as &str).into(),72						ObjMember {73							add: false,74							visibility: Visibility::Normal,75							invoke: LazyBinding::Bound(LazyVal::new_resolved(v.into())),76							location: None,77						},78					);79				}80				Self::Obj(ObjValue::new(None, Gc::new(entries), Gc::new(Vec::new())))81			}82		}83	}84}
after · crates/jrsonnet-evaluator/src/integrations/serde.rs
1use crate::{2	error::{Error::*, LocError, Result},3	throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,4};5use jrsonnet_gc::Gc;6use jrsonnet_parser::Visibility;7use rustc_hash::FxHasher;8use serde_json::{Map, Number, Value};9use std::{10	collections::HashMap,11	convert::{TryFrom, TryInto},12	hash::BuildHasherDefault,13};1415impl TryFrom<&Val> for Value {16	type Error = LocError;17	fn try_from(v: &Val) -> Result<Self> {18		Ok(match v {19			Val::Bool(b) => Self::Bool(*b),20			Val::Null => Self::Null,21			Val::Str(s) => Self::String((s as &str).into()),22			Val::Num(n) => Self::Number(if n.fract() <= f64::EPSILON {23				(*n as i64).into()24			} else {25				Number::from_f64(*n).expect("to json number")26			}),27			Val::Arr(a) => {28				let mut out = Vec::with_capacity(a.len());29				for item in a.iter() {30					out.push((&item?).try_into()?);31				}32				Self::Array(out)33			}34			Val::Obj(o) => {35				let mut out = Map::new();36				for key in o.fields() {37					out.insert(38						(&key as &str).into(),39						(&o.get(key)?.expect("field exists")).try_into()?,40					);41				}42				Self::Object(out)43			}44			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),45		})46	}47}4849impl From<&Value> for Val {50	fn from(v: &Value) -> Self {51		match v {52			Value::Null => Self::Null,53			Value::Bool(v) => Self::Bool(*v),54			Value::Number(n) => Self::Num(n.as_f64().expect("as f64")),55			Value::String(s) => Self::Str((s as &str).into()),56			Value::Array(a) => {57				let mut out = Vec::with_capacity(a.len());58				for v in a {59					out.push(LazyVal::new_resolved(v.into()));60				}61				Self::Arr(out.into())62			}63			Value::Object(o) => {64				let mut entries = HashMap::with_capacity_and_hasher(65					o.len(),66					BuildHasherDefault::<FxHasher>::default(),67				);68				for (k, v) in o {69					entries.insert(70						(k as &str).into(),71						ObjMember {72							add: false,73							visibility: Visibility::Normal,74							invoke: LazyBinding::Bound(LazyVal::new_resolved(v.into())),75							location: None,76						},77					);78				}79				Self::Obj(ObjValue::new(None, Gc::new(entries), Gc::new(Vec::new())))80			}81		}82	}83}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -9,7 +9,7 @@
 	native::NativeCallback,
 	throw, with_state, Context, ObjValue, Result,
 };
-use jrsonnet_gc::{Finalize, Gc, GcCell, Trace};
+use jrsonnet_gc::{Gc, GcCell, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};
 use jrsonnet_types::ValType;
@@ -345,65 +345,6 @@
 	}
 }
 
-#[derive(Debug)]
-pub struct DebugGcTraceValue {
-	name: IStr,
-	pub value: Box<Val>,
-}
-impl DebugGcTraceValue {
-	fn print(&self, action: &str) {
-		println!("{} {}#{:?}", action, self.name, &*self.value as *const _)
-	}
-}
-impl Finalize for DebugGcTraceValue {
-	fn finalize(&self) {
-		self.print("Garbage-collecting")
-	}
-}
-impl Drop for DebugGcTraceValue {
-	fn drop(&mut self) {
-		self.print("Garbage-collected")
-	}
-}
-unsafe impl Trace for DebugGcTraceValue {
-	unsafe fn trace(&self) {
-		self.print("Traced");
-		self.value.trace()
-	}
-	unsafe fn root(&self) {
-		self.print("Rooted");
-		self.value.root()
-	}
-	unsafe fn unroot(&self) {
-		self.print("Unrooted");
-		self.value.unroot()
-	}
-	fn finalize_glue(&self) {
-		Finalize::finalize(self)
-	}
-}
-impl Clone for DebugGcTraceValue {
-	fn clone(&self) -> Self {
-		self.print("Cloned");
-		let value = Self {
-			name: self.name.clone(),
-			value: self.value.clone(),
-		};
-		value.print("I'm clone");
-		value
-	}
-}
-impl DebugGcTraceValue {
-	pub fn create(name: IStr, value: Val) -> Val {
-		let value = Self {
-			name,
-			value: Box::new(value),
-		};
-		value.print("Constructed");
-		Val::DebugGcTraceValue(value)
-	}
-}
-
 #[derive(Debug, Clone, Trace)]
 #[trivially_drop]
 pub enum Val {
@@ -414,7 +355,6 @@
 	Arr(ArrValue),
 	Obj(ObjValue),
 	Func(Gc<FuncVal>),
-	DebugGcTraceValue(DebugGcTraceValue),
 }
 
 macro_rules! matches_unwrap {
@@ -471,7 +411,6 @@
 			Self::Bool(_) => ValType::Bool,
 			Self::Null => ValType::Null,
 			Self::Func(..) => ValType::Func,
-			Self::DebugGcTraceValue(v) => v.value.value_type(),
 		}
 	}