difftreelog
refactor remove debug gc trace
in: master
5 files changed
crates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth126 buf.push('}');126 buf.push('}');127 }127 }128 Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),128 Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),129 Val::DebugGcTraceValue(v) => manifest_json_ex_buf(&v.value, buf, cur_padding, options)?,130 };129 };131 Ok(())130 Ok(())132}131}crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth1use crate::{1use crate::{2 equals,2 equals,3 error::{Error::*, Result},3 error::{Error::*, Result},4 parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, DebugGcTraceValue,4 parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, EvaluationState,5 EvaluationState, FuncVal, LazyVal, Val,5 FuncVal, LazyVal, Val,6};6};7use format::{format_arr, format_obj};7use format::{format_arr, format_obj};69 ("md5".into(), builtin_md5),69 ("md5".into(), builtin_md5),70 ("base64".into(), builtin_base64),70 ("base64".into(), builtin_base64),71 ("trace".into(), builtin_trace),71 ("trace".into(), builtin_trace),72 ("gc".into(), builtin_gc),73 ("gcTrace".into(), builtin_gc_trace),74 ("join".into(), builtin_join),72 ("join".into(), builtin_join),75 ("escapeStringJson".into(), builtin_escape_string_json),73 ("escapeStringJson".into(), builtin_escape_string_json),76 ("manifestJsonEx".into(), builtin_manifest_json_ex),74 ("manifestJsonEx".into(), builtin_manifest_json_ex),449 })447 })450}448}451452fn builtin_gc(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {453 parse_args!(context, "gc", args, 1, [454 0, rest: ty!(any);455 ], {456 println!("GC start");457 jrsonnet_gc::force_collect();458 println!("GC done");459460 Ok(rest)461 })462}463464fn builtin_gc_trace(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {465 parse_args!(context, "gcTrace", args, 2, [466 0, name: ty!(string) => Val::Str;467 1, rest: ty!(any);468 ], {469 Ok(DebugGcTraceValue::create(name, rest))470 })471}472449473fn builtin_base64(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {450fn builtin_base64(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {474 parse_args!(context, "base64", args, 1, [451 parse_args!(context, "base64", args, 1, [crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth215215216pub fn evaluate_add_op(a: &Val, b: &Val) -> Result<Val> {216pub fn evaluate_add_op(a: &Val, b: &Val) -> Result<Val> {217 Ok(match (a, b) {217 Ok(match (a, b) {218 (Val::DebugGcTraceValue(v1), Val::DebugGcTraceValue(v2)) => {219 evaluate_add_op(&v1.value, &v2.value)?220 }221 (Val::Str(v1), Val::Str(v2)) => Val::Str(((**v1).to_owned() + v2).into()),218 (Val::Str(v1), Val::Str(v2)) => Val::Str(((**v1).to_owned() + v2).into()),222219223 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)220 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth42 Self::Object(out)42 Self::Object(out)43 }43 }44 Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),44 Val::Func(_) => throw!(RuntimeError("tried to manifest function".into())),45 Val::DebugGcTraceValue(v) => Self::try_from(&*v.value as &Val)?,46 })45 })47 }46 }48}47}crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth9 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}347348#[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 value394 }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}406347407#[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}419359420macro_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