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
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -42,7 +42,6 @@
 				Self::Object(out)
 			}
 			Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),
-			Val::DebugGcTraceValue(v) => Self::try_from(&*v.value as &Val)?,
 		})
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
9 native::NativeCallback,9 native::NativeCallback,
10 throw, with_state, Context, ObjValue, Result,10 throw, with_state, Context, ObjValue, Result,
11};11};
12use jrsonnet_gc::{Finalize, Gc, GcCell, Trace};12use jrsonnet_gc::{Gc, GcCell, Trace};
13use jrsonnet_interner::IStr;13use jrsonnet_interner::IStr;
14use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};14use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};
15use jrsonnet_types::ValType;15use jrsonnet_types::ValType;
345 }345 }
346}346}
347
348#[derive(Debug)]
349pub struct DebugGcTraceValue {
350 name: IStr,
351 pub value: Box<Val>,
352}
353impl DebugGcTraceValue {
354 fn print(&self, action: &str) {
355 println!("{} {}#{:?}", action, self.name, &*self.value as *const _)
356 }
357}
358impl Finalize for DebugGcTraceValue {
359 fn finalize(&self) {
360 self.print("Garbage-collecting")
361 }
362}
363impl Drop for DebugGcTraceValue {
364 fn drop(&mut self) {
365 self.print("Garbage-collected")
366 }
367}
368unsafe impl Trace for DebugGcTraceValue {
369 unsafe fn trace(&self) {
370 self.print("Traced");
371 self.value.trace()
372 }
373 unsafe fn root(&self) {
374 self.print("Rooted");
375 self.value.root()
376 }
377 unsafe fn unroot(&self) {
378 self.print("Unrooted");
379 self.value.unroot()
380 }
381 fn finalize_glue(&self) {
382 Finalize::finalize(self)
383 }
384}
385impl Clone for DebugGcTraceValue {
386 fn clone(&self) -> Self {
387 self.print("Cloned");
388 let value = Self {
389 name: self.name.clone(),
390 value: self.value.clone(),
391 };
392 value.print("I'm clone");
393 value
394 }
395}
396impl DebugGcTraceValue {
397 pub fn create(name: IStr, value: Val) -> Val {
398 let value = Self {
399 name,
400 value: Box::new(value),
401 };
402 value.print("Constructed");
403 Val::DebugGcTraceValue(value)
404 }
405}
406347
407#[derive(Debug, Clone, Trace)]348#[derive(Debug, Clone, Trace)]
408#[trivially_drop]349#[trivially_drop]
414 Arr(ArrValue),355 Arr(ArrValue),
415 Obj(ObjValue),356 Obj(ObjValue),
416 Func(Gc<FuncVal>),357 Func(Gc<FuncVal>),
417 DebugGcTraceValue(DebugGcTraceValue),
418}358}
419359
420macro_rules! matches_unwrap {360macro_rules! matches_unwrap {
471 Self::Bool(_) => ValType::Bool,411 Self::Bool(_) => ValType::Bool,
472 Self::Null => ValType::Null,412 Self::Null => ValType::Null,
473 Self::Func(..) => ValType::Func,413 Self::Func(..) => ValType::Func,
474 Self::DebugGcTraceValue(v) => v.value.value_type(),
475 }414 }
476 }415 }
477416