git.delta.rocks / jrsonnet / refs/commits / a9d1e03758ef

difftreelog

refactor switch to jrsonnet-gc

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

27 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -100,27 +100,6 @@
 ]
 
 [[package]]
-name = "gc"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3edaac0f5832202ebc99520cb77c932248010c4645d20be1dc62d6579f5b3752"
-dependencies = [
- "gc_derive",
-]
-
-[[package]]
-name = "gc_derive"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "60df8444f094ff7885631d80e78eb7d88c3c2361a98daaabb06256e4500db941"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "synstructure",
-]
-
-[[package]]
 name = "hashbrown"
 version = "0.9.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -190,7 +169,7 @@
  "anyhow",
  "base64",
  "bincode",
- "gc",
+ "jrsonnet-gc",
  "jrsonnet-interner",
  "jrsonnet-parser",
  "jrsonnet-stdlib",
@@ -204,10 +183,31 @@
 ]
 
 [[package]]
+name = "jrsonnet-gc"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68da8bc2f00117b1373bb8877af03b1d391e4c4800e6585d7279e5b99c919dde"
+dependencies = [
+ "jrsonnet-gc-derive",
+]
+
+[[package]]
+name = "jrsonnet-gc-derive"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "adcba9c387b64b054f06cc4d724905296e21edeeb7506847f3299117a2d92d12"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "synstructure",
+]
+
+[[package]]
 name = "jrsonnet-interner"
 version = "0.3.8"
 dependencies = [
- "gc",
+ "jrsonnet-gc",
  "rustc-hash",
  "serde",
 ]
@@ -216,7 +216,7 @@
 name = "jrsonnet-parser"
 version = "0.3.8"
 dependencies = [
- "gc",
+ "jrsonnet-gc",
  "jrsonnet-interner",
  "jrsonnet-stdlib",
  "peg",
@@ -232,7 +232,7 @@
 name = "jrsonnet-types"
 version = "0.3.8"
 dependencies = [
- "gc",
+ "jrsonnet-gc",
  "peg",
 ]
 
@@ -240,8 +240,8 @@
 name = "jsonnet"
 version = "0.3.8"
 dependencies = [
- "gc",
  "jrsonnet-evaluator",
+ "jrsonnet-gc",
  "jrsonnet-parser",
 ]
 
modifiedbindings/jsonnet/Cargo.tomldiffbeforeafterboth
--- a/bindings/jsonnet/Cargo.toml
+++ b/bindings/jsonnet/Cargo.toml
@@ -10,7 +10,7 @@
 [dependencies]
 jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.3.8" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.3.8" }
-gc = { version = "0.4.1", features = ["derive"] }
+jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
 
 [lib]
 crate-type = ["cdylib"]
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -1,9 +1,9 @@
-use gc::{unsafe_empty_trace, Finalize, Gc, Trace};
 use jrsonnet_evaluator::{
 	error::{Error, LocError},
 	native::{NativeCallback, NativeCallbackHandler},
 	EvaluationState, Val,
 };
+use jrsonnet_gc::{unsafe_empty_trace, Finalize, Gc, Trace};
 use jrsonnet_parser::{Param, ParamsDesc};
 use std::{
 	ffi::{c_void, CStr},
modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -1,7 +1,7 @@
 //! Create values in VM
 
-use gc::Gc;
 use jrsonnet_evaluator::{ArrValue, EvaluationState, ObjValue, Val};
+use jrsonnet_gc::Gc;
 use std::{
 	ffi::CStr,
 	os::raw::{c_char, c_double, c_int},
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -2,8 +2,8 @@
 //! Only tested with variables, which haven't altered by code before appearing here
 //! In jrsonnet every value is immutable, and this code is probally broken
 
-use gc::Gc;
 use jrsonnet_evaluator::{ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
+use jrsonnet_gc::Gc;
 use jrsonnet_parser::Visibility;
 use std::{ffi::CStr, os::raw::c_char};
 
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -35,7 +35,7 @@
 rustc-hash = "1.1.0"
 
 thiserror = "1.0"
-gc = { version = "0.4.1", features = ["derive"] }
+jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
 
 [dependencies.anyhow]
 version = "1.0"
modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/format.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/format.rs
@@ -2,12 +2,13 @@
 #![allow(clippy::too_many_arguments)]
 
 use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
-use gc::{Finalize, Trace};
+use jrsonnet_gc::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_types::ValType;
 use thiserror::Error;
 
-#[derive(Debug, Clone, Error, Trace, Finalize)]
+#[derive(Debug, Clone, Error, Trace)]
+#[trivially_drop]
 pub enum FormatError {
 	#[error("truncated format code")]
 	TruncatedFormatCode,
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -5,7 +5,7 @@
 	EvaluationState, FuncVal, LazyVal, Val,
 };
 use format::{format_arr, format_obj};
-use gc::Gc;
+use jrsonnet_gc::Gc;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};
 use jrsonnet_types::ty;
@@ -454,7 +454,7 @@
 		0, rest: ty!(any);
 	], {
 		println!("GC start");
-		gc::force_collect();
+		jrsonnet_gc::force_collect();
 		println!("GC done");
 
 		Ok(rest)
modifiedcrates/jrsonnet-evaluator/src/builtin/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/sort.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/sort.rs
@@ -2,7 +2,7 @@
 	error::{Error, LocError, Result},
 	throw, Context, FuncVal, Val,
 };
-use gc::{Finalize, Gc, Trace};
+use jrsonnet_gc::{Finalize, Gc, Trace};
 
 #[derive(Debug, Clone, thiserror::Error, Trace, Finalize)]
 pub enum SortError {
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -2,13 +2,14 @@
 	error::Error::*, map::LayeredHashMap, FutureWrapper, LazyBinding, LazyVal, ObjValue, Result,
 	Val,
 };
-use gc::{Finalize, Gc, Trace};
+use jrsonnet_gc::{Gc, Trace};
 use jrsonnet_interner::IStr;
 use rustc_hash::FxHashMap;
 use std::fmt::Debug;
 use std::hash::BuildHasherDefault;
 
-#[derive(Clone, Trace, Finalize)]
+#[derive(Clone, Trace)]
+#[trivially_drop]
 pub struct ContextCreator(pub Context, pub FutureWrapper<FxHashMap<IStr, LazyBinding>>);
 impl ContextCreator {
 	pub fn create(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<Context> {
@@ -21,12 +22,13 @@
 	}
 }
 
-#[derive(Trace, Finalize)]
+#[derive(Trace)]
+#[trivially_drop]
 struct ContextInternals {
 	dollar: Option<ObjValue>,
 	this: Option<ObjValue>,
 	super_obj: Option<ObjValue>,
-	bindings: LayeredHashMap<LazyVal>,
+	bindings: LayeredHashMap,
 }
 impl Debug for ContextInternals {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -34,7 +36,8 @@
 	}
 }
 
-#[derive(Debug, Clone, Trace, Finalize)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub struct Context(Gc<ContextInternals>);
 impl Context {
 	pub fn new_future() -> FutureWrapper<Self> {
modifiedcrates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/dynamic.rs
+++ b/crates/jrsonnet-evaluator/src/dynamic.rs
@@ -1,6 +1,7 @@
-use gc::{Finalize, Gc, GcCell, Trace};
+use jrsonnet_gc::{Gc, GcCell, Trace};
 
-#[derive(Clone, Trace, Finalize)]
+#[derive(Clone, Trace)]
+#[trivially_drop]
 pub struct FutureWrapper<V: Trace + 'static>(pub Gc<GcCell<Option<V>>>);
 impl<T: Trace + 'static> FutureWrapper<T> {
 	pub fn new() -> Self {
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -2,7 +2,7 @@
 	builtin::{format::FormatError, sort::SortError},
 	typed::TypeLocError,
 };
-use gc::{Finalize, Trace};
+use jrsonnet_gc::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
 use jrsonnet_types::ValType;
@@ -12,7 +12,8 @@
 };
 use thiserror::Error;
 
-#[derive(Error, Debug, Clone, Trace, Finalize)]
+#[derive(Error, Debug, Clone, Trace)]
+#[trivially_drop]
 pub enum Error {
 	#[error("intrinsic not found: {0}")]
 	IntrinsicNotFound(IStr),
@@ -149,15 +150,18 @@
 	}
 }
 
-#[derive(Clone, Debug, Trace, Finalize)]
+#[derive(Clone, Debug, Trace)]
+#[trivially_drop]
 pub struct StackTraceElement {
 	pub location: Option<ExprLocation>,
 	pub desc: String,
 }
-#[derive(Debug, Clone, Trace, Finalize)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub struct StackTrace(pub Vec<StackTraceElement>);
 
-#[derive(Debug, Clone, Trace, Finalize)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub struct LocError(Box<(Error, StackTrace)>);
 impl LocError {
 	pub fn new(e: Error) -> Self {
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -3,7 +3,7 @@
 	FuncDesc, FuncVal, FutureWrapper, LazyBinding, LazyVal, LazyValValue, ObjMember, ObjValue,
 	ObjectAssertion, Result, Val,
 };
-use gc::{custom_trace, Finalize, Gc, Trace};
+use jrsonnet_gc::{Gc, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{
 	ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, ExprLocation, FieldMember,
@@ -22,21 +22,14 @@
 	if let Some(params) = &b.params {
 		let params = params.clone();
 
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct LazyMethodBinding {
 			context_creator: FutureWrapper<Context>,
 			name: IStr,
 			params: ParamsDesc,
 			value: LocExpr,
 		}
-		impl Finalize for LazyMethodBinding {}
-		unsafe impl Trace for LazyMethodBinding {
-			custom_trace!(this, {
-				mark(&this.context_creator);
-				mark(&this.name);
-				mark(&this.params);
-				mark(&this.value);
-			});
-		}
 		impl LazyValValue for LazyMethodBinding {
 			fn get(self: Box<Self>) -> Result<Val> {
 				Ok(evaluate_method(
@@ -55,19 +48,13 @@
 			value: b.value.clone(),
 		}))
 	} else {
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct LazyNamedBinding {
 			context_creator: FutureWrapper<Context>,
 			name: IStr,
 			value: LocExpr,
 		}
-		impl Finalize for LazyNamedBinding {}
-		unsafe impl Trace for LazyNamedBinding {
-			custom_trace!(this, {
-				mark(&this.context_creator);
-				mark(&this.name);
-				mark(&this.value);
-			});
-		}
 		impl LazyValValue for LazyNamedBinding {
 			fn get(self: Box<Self>) -> Result<Val> {
 				evaluate_named(self.context_creator.unwrap(), &self.value, self.name)
@@ -86,6 +73,8 @@
 	if let Some(params) = &b.params {
 		let params = params.clone();
 
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct BindableMethodLazyVal {
 			this: Option<ObjValue>,
 			super_obj: Option<ObjValue>,
@@ -94,17 +83,6 @@
 			name: IStr,
 			params: ParamsDesc,
 			value: LocExpr,
-		}
-		impl Finalize for BindableMethodLazyVal {}
-		unsafe impl Trace for BindableMethodLazyVal {
-			custom_trace!(this, {
-				mark(&this.this);
-				mark(&this.super_obj);
-				mark(&this.context_creator);
-				mark(&this.name);
-				mark(&this.params);
-				mark(&this.value);
-			});
 		}
 		impl LazyValValue for BindableMethodLazyVal {
 			fn get(self: Box<Self>) -> Result<Val> {
@@ -117,7 +95,8 @@
 			}
 		}
 
-		#[derive(Trace, Finalize)]
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct BindableMethod {
 			context_creator: ContextCreator,
 			name: IStr,
@@ -148,6 +127,8 @@
 			}))),
 		)
 	} else {
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct BindableNamedLazyVal {
 			this: Option<ObjValue>,
 			super_obj: Option<ObjValue>,
@@ -156,16 +137,6 @@
 			name: IStr,
 			value: LocExpr,
 		}
-		impl Finalize for BindableNamedLazyVal {}
-		unsafe impl Trace for BindableNamedLazyVal {
-			custom_trace!(this, {
-				mark(&this.this);
-				mark(&this.super_obj);
-				mark(&this.context_creator);
-				mark(&this.name);
-				mark(&this.value);
-			});
-		}
 		impl LazyValValue for BindableNamedLazyVal {
 			fn get(self: Box<Self>) -> Result<Val> {
 				evaluate_named(
@@ -176,7 +147,8 @@
 			}
 		}
 
-		#[derive(Trace, Finalize)]
+		#[derive(Trace)]
+		#[trivially_drop]
 		struct BindableNamed {
 			context_creator: ContextCreator,
 			name: IStr,
@@ -414,7 +386,8 @@
 				}
 				let name = name.unwrap();
 
-				#[derive(Trace, Finalize)]
+				#[derive(Trace)]
+				#[trivially_drop]
 				struct ObjMemberBinding {
 					context_creator: ContextCreator,
 					value: LocExpr,
@@ -458,7 +431,8 @@
 					continue;
 				}
 				let name = name.unwrap();
-				#[derive(Trace, Finalize)]
+				#[derive(Trace)]
+				#[trivially_drop]
 				struct ObjMemberBinding {
 					context_creator: ContextCreator,
 					value: LocExpr,
@@ -496,16 +470,11 @@
 			}
 			Member::BindStmt(_) => {}
 			Member::AssertStmt(stmt) => {
+				#[derive(Trace)]
+				#[trivially_drop]
 				struct ObjectAssert {
 					context_creator: ContextCreator,
 					assert: AssertStmt,
-				}
-				impl Finalize for ObjectAssert {}
-				unsafe impl Trace for ObjectAssert {
-					custom_trace!(this, {
-						mark(&this.context_creator);
-						mark(&this.assert);
-					});
 				}
 				impl ObjectAssertion for ObjectAssert {
 					fn run(
@@ -558,7 +527,8 @@
 				match key {
 					Val::Null => {}
 					Val::Str(n) => {
-						#[derive(Trace, Finalize)]
+						#[derive(Trace)]
+						#[trivially_drop]
 						struct ObjCompBinding {
 							context: Context,
 							value: LocExpr,
@@ -768,16 +738,11 @@
 			let mut out = Vec::with_capacity(items.len());
 			for item in items {
 				// TODO: Implement ArrValue::Lazy with same context for every element?
+				#[derive(Trace)]
+				#[trivially_drop]
 				struct ArrayElement {
 					context: Context,
 					item: LocExpr,
-				}
-				impl Finalize for ArrayElement {}
-				unsafe impl Trace for ArrayElement {
-					custom_trace!(this, {
-						mark(&this.context);
-						mark(&this.item);
-					});
 				}
 				impl LazyValValue for ArrayElement {
 					fn get(self: Box<Self>) -> Result<Val> {
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -1,5 +1,5 @@
 use crate::{error::Error::*, evaluate, throw, Context, LazyVal, LazyValValue, Result, Val};
-use gc::{custom_trace, Finalize, Trace};
+use jrsonnet_gc::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ArgsDesc, LocExpr, ParamsDesc};
 use rustc_hash::FxHashMap;
@@ -55,16 +55,11 @@
 		let val = if tailstrict {
 			LazyVal::new_resolved(evaluate(ctx, expr)?)
 		} else {
+			#[derive(Trace)]
+			#[trivially_drop]
 			struct EvaluateLazyVal {
 				context: Context,
 				expr: LocExpr,
-			}
-			impl Finalize for EvaluateLazyVal {}
-			unsafe impl Trace for EvaluateLazyVal {
-				custom_trace!(this, {
-					mark(&this.context);
-					mark(&this.expr);
-				});
 			}
 			impl LazyValValue for EvaluateLazyVal {
 				fn get(self: Box<Self>) -> Result<Val> {
@@ -119,7 +114,8 @@
 			} else {
 				let body_ctx = body_ctx.clone();
 				let default = default.clone();
-				#[derive(Trace, Finalize)]
+				#[derive(Trace)]
+				#[trivially_drop]
 				struct EvaluateLazyVal {
 					body_ctx: Option<Context>,
 					default: LocExpr,
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -2,7 +2,7 @@
 	error::{Error::*, LocError, Result},
 	throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,
 };
-use gc::Gc;
+use jrsonnet_gc::Gc;
 use jrsonnet_parser::Visibility;
 use rustc_hash::FxHasher;
 use serde_json::{Map, Number, Value};
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -25,8 +25,8 @@
 use error::{Error::*, LocError, Result, StackTraceElement};
 pub use evaluate::*;
 pub use function::parse_function_call;
-use gc::{Finalize, Gc, Trace};
 pub use import::*;
+use jrsonnet_gc::{Finalize, Gc, Trace};
 pub use jrsonnet_interner::IStr;
 use jrsonnet_parser::*;
 use native::NativeCallback;
modifiedcrates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/map.rs
+++ b/crates/jrsonnet-evaluator/src/map.rs
@@ -1,32 +1,29 @@
-use gc::{Finalize, Gc, Trace};
+use jrsonnet_gc::{Gc, Trace};
 use jrsonnet_interner::IStr;
 use rustc_hash::FxHashMap;
 
-pub struct LayeredHashMapInternals<V: Trace + Finalize + 'static> {
-	parent: Option<LayeredHashMap<V>>,
-	current: FxHashMap<IStr, V>,
-}
+use crate::LazyVal;
 
-unsafe impl<V: Trace + Finalize + 'static> Trace for LayeredHashMapInternals<V> {
-	gc::custom_trace!(this, {
-		mark(&this.parent);
-		mark(&this.current);
-	});
+#[derive(Trace)]
+#[trivially_drop]
+pub struct LayeredHashMapInternals {
+	parent: Option<LayeredHashMap>,
+	current: FxHashMap<IStr, LazyVal>,
 }
-impl<V: Trace + Finalize + 'static> Finalize for LayeredHashMapInternals<V> {}
 
-#[derive(Trace, Finalize)]
-pub struct LayeredHashMap<V: Trace + Finalize + 'static>(Gc<LayeredHashMapInternals<V>>);
+#[derive(Trace)]
+#[trivially_drop]
+pub struct LayeredHashMap(Gc<LayeredHashMapInternals>);
 
-impl<V: Trace + 'static> LayeredHashMap<V> {
-	pub fn extend(self, new_layer: FxHashMap<IStr, V>) -> Self {
+impl LayeredHashMap {
+	pub fn extend(self, new_layer: FxHashMap<IStr, LazyVal>) -> Self {
 		Self(Gc::new(LayeredHashMapInternals {
 			parent: Some(self),
 			current: new_layer,
 		}))
 	}
 
-	pub fn get(&self, key: &IStr) -> Option<&V> {
+	pub fn get(&self, key: &IStr) -> Option<&LazyVal> {
 		(self.0)
 			.current
 			.get(key)
@@ -34,13 +31,13 @@
 	}
 }
 
-impl<V: Trace + 'static> Clone for LayeredHashMap<V> {
+impl Clone for LayeredHashMap {
 	fn clone(&self) -> Self {
 		Self(self.0.clone())
 	}
 }
 
-impl<V: Trace + 'static> Default for LayeredHashMap<V> {
+impl Default for LayeredHashMap {
 	fn default() -> Self {
 		Self(Gc::new(LayeredHashMapInternals {
 			parent: None,
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -1,7 +1,7 @@
 #![allow(clippy::type_complexity)]
 
 use crate::{error::Result, Val};
-use gc::{Finalize, Trace};
+use jrsonnet_gc::Trace;
 use jrsonnet_parser::ParamsDesc;
 use std::fmt::Debug;
 use std::path::Path;
@@ -11,7 +11,8 @@
 	fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> Result<Val>;
 }
 
-#[derive(Trace, Finalize)]
+#[derive(Trace)]
+#[trivially_drop]
 pub struct NativeCallback {
 	pub params: ParamsDesc,
 	handler: Box<dyn NativeCallbackHandler>,
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,12 +1,13 @@
 use crate::{evaluate_add_op, LazyBinding, Result, Val};
-use gc::{Finalize, Gc, GcCell, Trace};
+use jrsonnet_gc::{Gc, GcCell, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ExprLocation, Visibility};
 use rustc_hash::{FxHashMap, FxHashSet};
 use std::hash::{Hash, Hasher};
 use std::{fmt::Debug, hash::BuildHasherDefault};
 
-#[derive(Debug, Trace, Finalize)]
+#[derive(Debug, Trace)]
+#[trivially_drop]
 pub struct ObjMember {
 	pub add: bool,
 	pub visibility: Visibility,
@@ -20,7 +21,8 @@
 
 // Field => This
 type CacheKey = (IStr, ObjValue);
-#[derive(Trace, Finalize)]
+#[derive(Trace)]
+#[trivially_drop]
 pub struct ObjValueInternals {
 	super_obj: Option<ObjValue>,
 	assertions: Gc<Vec<Box<dyn ObjectAssertion>>>,
@@ -30,7 +32,8 @@
 	value_cache: GcCell<FxHashMap<CacheKey, Option<Val>>>,
 }
 
-#[derive(Clone, Trace, Finalize)]
+#[derive(Clone, Trace)]
+#[trivially_drop]
 pub struct ObjValue(pub(crate) Gc<ObjValueInternals>);
 impl Debug for ObjValue {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -4,7 +4,7 @@
 	error::{Error, LocError, Result},
 	push, Val,
 };
-use gc::{Finalize, Trace};
+use jrsonnet_gc::Trace;
 use jrsonnet_parser::ExprLocation;
 use jrsonnet_types::{ComplexValType, ValType};
 use thiserror::Error;
@@ -21,7 +21,8 @@
 	}};
 }
 
-#[derive(Debug, Error, Clone, Trace, Finalize)]
+#[derive(Debug, Error, Clone, Trace)]
+#[trivially_drop]
 pub enum TypeError {
 	#[error("expected {0}, got {1}")]
 	ExpectedGot(ComplexValType, ValType),
@@ -38,7 +39,8 @@
 	}
 }
 
-#[derive(Debug, Clone, Trace, Finalize)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub struct TypeLocError(Box<TypeError>, ValuePathStack);
 impl From<TypeError> for TypeLocError {
 	fn from(e: TypeError) -> Self {
@@ -60,7 +62,8 @@
 	}
 }
 
-#[derive(Debug, Clone, Trace, Finalize)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub struct TypeLocErrorList(Vec<TypeLocError>);
 impl Display for TypeLocErrorList {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -123,7 +126,8 @@
 	}
 }
 
-#[derive(Clone, Debug, Trace, Finalize)]
+#[derive(Clone, Debug, Trace)]
+#[trivially_drop]
 enum ValuePathItem {
 	Field(Rc<str>),
 	Index(u64),
@@ -138,7 +142,8 @@
 	}
 }
 
-#[derive(Clone, Debug, Trace, Finalize)]
+#[derive(Clone, Debug, Trace)]
+#[trivially_drop]
 struct ValuePathStack(Vec<ValuePathItem>);
 impl Display for ValuePathStack {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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 gc::{custom_trace, Finalize, Gc, GcCell, Trace};
+use jrsonnet_gc::{Finalize, Gc, GcCell, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};
 use jrsonnet_types::ValType;
@@ -19,25 +19,17 @@
 	fn get(self: Box<Self>) -> Result<Val>;
 }
 
+#[derive(Trace)]
+#[trivially_drop]
 enum LazyValInternals {
 	Computed(Val),
 	Errored(LocError),
 	Waiting(Box<dyn LazyValValue>),
 	Pending,
-}
-impl Finalize for LazyValInternals {}
-unsafe impl Trace for LazyValInternals {
-	custom_trace!(this, {
-		match &this {
-			LazyValInternals::Computed(v) => mark(v),
-			LazyValInternals::Errored(e) => mark(e),
-			LazyValInternals::Waiting(w) => mark(w),
-			LazyValInternals::Pending => {}
-		}
-	});
 }
 
-#[derive(Clone, Trace, Finalize)]
+#[derive(Clone, Trace)]
+#[trivially_drop]
 pub struct LazyVal(Gc<GcCell<LazyValInternals>>);
 impl LazyVal {
 	pub fn new(f: Box<dyn LazyValValue>) -> Self {
@@ -83,7 +75,8 @@
 	}
 }
 
-#[derive(Debug, PartialEq, Trace, Finalize)]
+#[derive(Debug, PartialEq, Trace)]
+#[trivially_drop]
 pub struct FuncDesc {
 	pub name: IStr,
 	pub ctx: Context,
@@ -91,7 +84,8 @@
 	pub body: LocExpr,
 }
 
-#[derive(Debug, Trace, Finalize)]
+#[derive(Debug, Trace)]
+#[trivially_drop]
 pub enum FuncVal {
 	/// Plain function implemented in jsonnet
 	Normal(FuncDesc),
@@ -195,22 +189,13 @@
 	String,
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub enum ArrValue {
 	Lazy(Gc<Vec<LazyVal>>),
 	Eager(Gc<Vec<Val>>),
 	Extended(Box<(Self, Self)>),
 }
-impl Finalize for ArrValue {}
-unsafe impl Trace for ArrValue {
-	custom_trace!(this, {
-		match &this {
-			ArrValue::Lazy(l) => mark(l),
-			ArrValue::Eager(e) => mark(e),
-			ArrValue::Extended(x) => mark(x),
-		}
-	});
-}
 impl ArrValue {
 	pub fn new_eager() -> Self {
 		Self::Eager(Gc::new(Vec::new()))
@@ -419,7 +404,8 @@
 	}
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Trace)]
+#[trivially_drop]
 pub enum Val {
 	Bool(bool),
 	Null,
@@ -429,21 +415,6 @@
 	Obj(ObjValue),
 	Func(Gc<FuncVal>),
 	DebugGcTraceValue(DebugGcTraceValue),
-}
-impl Finalize for Val {}
-unsafe impl Trace for Val {
-	custom_trace!(this, {
-		match &this {
-			Val::Bool(_) => {}
-			Val::Null => {}
-			Val::Str(_) => {}
-			Val::Num(_) => {}
-			Val::Arr(a) => mark(a),
-			Val::Obj(o) => mark(o),
-			Val::Func(f) => mark(f),
-			Val::DebugGcTraceValue(v) => mark(v),
-		}
-	});
 }
 
 macro_rules! matches_unwrap {
modifiedcrates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -9,4 +9,4 @@
 [dependencies]
 serde = { version = "1.0" }
 rustc-hash = "1.1.0"
-gc = { version = "0.4.1", features = ["derive"] }
+jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -1,4 +1,4 @@
-use gc::{unsafe_empty_trace, Finalize, Trace};
+use jrsonnet_gc::{unsafe_empty_trace, Finalize, Trace};
 use rustc_hash::FxHashMap;
 use serde::{Deserialize, Serialize};
 use std::{
modifiedcrates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -18,7 +18,7 @@
 unescape = "0.1.0"
 
 serde = { version = "1.0", features = ["derive", "rc"], optional = true }
-gc = { version = "0.4.1", features = ["derive"] }
+jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
 
 [dev-dependencies]
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.8" }
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
before · crates/jrsonnet-parser/src/expr.rs
1use gc::{unsafe_empty_trace, Finalize, Trace};2use jrsonnet_interner::IStr;3#[cfg(feature = "deserialize")]4use serde::Deserialize;5#[cfg(feature = "serialize")]6use serde::Serialize;7use std::{8	fmt::{Debug, Display},9	ops::Deref,10	path::{Path, PathBuf},11	rc::Rc,12};1314#[cfg_attr(feature = "serialize", derive(Serialize))]15#[cfg_attr(feature = "deserialize", derive(Deserialize))]16#[derive(Debug, PartialEq)]17pub enum FieldName {18	/// {fixed: 2}19	Fixed(IStr),20	/// {["dyn"+"amic"]: 3}21	Dyn(LocExpr),22}23impl Finalize for FieldName {}24unsafe impl Trace for FieldName {25	unsafe_empty_trace!();26}2728#[cfg_attr(feature = "serialize", derive(Serialize))]29#[cfg_attr(feature = "deserialize", derive(Deserialize))]30#[derive(Debug, Clone, Copy, PartialEq)]31pub enum Visibility {32	/// :33	Normal,34	/// ::35	Hidden,36	/// :::37	Unhide,38}39impl Finalize for Visibility {}40unsafe impl Trace for Visibility {41	unsafe_empty_trace!();42}4344impl Visibility {45	pub fn is_visible(&self) -> bool {46		matches!(self, Self::Normal | Self::Unhide)47	}48}4950#[cfg_attr(feature = "serialize", derive(Serialize))]51#[cfg_attr(feature = "deserialize", derive(Deserialize))]52#[derive(Clone, Debug, PartialEq)]53pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);54impl Finalize for AssertStmt {}55unsafe impl Trace for AssertStmt {56	unsafe_empty_trace!();57}5859#[cfg_attr(feature = "serialize", derive(Serialize))]60#[cfg_attr(feature = "deserialize", derive(Deserialize))]61#[derive(Debug, PartialEq)]62pub struct FieldMember {63	pub name: FieldName,64	pub plus: bool,65	pub params: Option<ParamsDesc>,66	pub visibility: Visibility,67	pub value: LocExpr,68}69impl Finalize for FieldMember {}70unsafe impl Trace for FieldMember {71	unsafe_empty_trace!();72}7374#[cfg_attr(feature = "serialize", derive(Serialize))]75#[cfg_attr(feature = "deserialize", derive(Deserialize))]76#[derive(Debug, PartialEq)]77pub enum Member {78	Field(FieldMember),79	BindStmt(BindSpec),80	AssertStmt(AssertStmt),81}82impl Finalize for Member {}83unsafe impl Trace for Member {84	unsafe_empty_trace!();85}8687#[cfg_attr(feature = "serialize", derive(Serialize))]88#[cfg_attr(feature = "deserialize", derive(Deserialize))]89#[derive(Debug, Clone, Copy, PartialEq)]90pub enum UnaryOpType {91	Plus,92	Minus,93	BitNot,94	Not,95}96impl Finalize for UnaryOpType {}97unsafe impl Trace for UnaryOpType {98	unsafe_empty_trace!();99}100101impl Display for UnaryOpType {102	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {103		use UnaryOpType::*;104		write!(105			f,106			"{}",107			match self {108				Plus => "+",109				Minus => "-",110				BitNot => "~",111				Not => "!",112			}113		)114	}115}116117#[cfg_attr(feature = "serialize", derive(Serialize))]118#[cfg_attr(feature = "deserialize", derive(Deserialize))]119#[derive(Debug, Clone, Copy, PartialEq)]120pub enum BinaryOpType {121	Mul,122	Div,123124	/// Implemented as intrinsic, put here for completeness125	Mod,126127	Add,128	Sub,129130	Lhs,131	Rhs,132133	Lt,134	Gt,135	Lte,136	Gte,137138	BitAnd,139	BitOr,140	BitXor,141142	Eq,143	Neq,144145	And,146	Or,147}148impl Finalize for BinaryOpType {}149unsafe impl Trace for BinaryOpType {150	unsafe_empty_trace!();151}152153impl Display for BinaryOpType {154	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {155		use BinaryOpType::*;156		write!(157			f,158			"{}",159			match self {160				Mul => "*",161				Div => "/",162				Mod => "%",163				Add => "+",164				Sub => "-",165				Lhs => "<<",166				Rhs => ">>",167				Lt => "<",168				Gt => ">",169				Lte => "<=",170				Gte => ">=",171				BitAnd => "&",172				BitOr => "|",173				BitXor => "^",174				Eq => "==",175				Neq => "!=",176				And => "&&",177				Or => "||",178			}179		)180	}181}182183/// name, default value184#[cfg_attr(feature = "serialize", derive(Serialize))]185#[cfg_attr(feature = "deserialize", derive(Deserialize))]186#[derive(Debug, PartialEq)]187pub struct Param(pub IStr, pub Option<LocExpr>);188impl Finalize for Param {}189unsafe impl Trace for Param {190	unsafe_empty_trace!();191}192193/// Defined function parameters194#[cfg_attr(feature = "serialize", derive(Serialize))]195#[cfg_attr(feature = "deserialize", derive(Deserialize))]196#[derive(Debug, Clone, PartialEq)]197pub struct ParamsDesc(pub Rc<Vec<Param>>);198impl Finalize for ParamsDesc {}199unsafe impl Trace for ParamsDesc {200	unsafe_empty_trace!();201}202203impl Deref for ParamsDesc {204	type Target = Vec<Param>;205	fn deref(&self) -> &Self::Target {206		&self.0207	}208}209210#[cfg_attr(feature = "serialize", derive(Serialize))]211#[cfg_attr(feature = "deserialize", derive(Deserialize))]212#[derive(Debug, PartialEq)]213pub struct Arg(pub Option<String>, pub LocExpr);214impl Finalize for Arg {}215unsafe impl Trace for Arg {216	unsafe_empty_trace!();217}218219#[cfg_attr(feature = "serialize", derive(Serialize))]220#[cfg_attr(feature = "deserialize", derive(Deserialize))]221#[derive(Debug, PartialEq)]222pub struct ArgsDesc(pub Vec<Arg>);223impl Finalize for ArgsDesc {}224unsafe impl Trace for ArgsDesc {225	unsafe_empty_trace!();226}227228impl Deref for ArgsDesc {229	type Target = Vec<Arg>;230	fn deref(&self) -> &Self::Target {231		&self.0232	}233}234235#[cfg_attr(feature = "serialize", derive(Serialize))]236#[cfg_attr(feature = "deserialize", derive(Deserialize))]237#[derive(Debug, Clone, PartialEq)]238pub struct BindSpec {239	pub name: IStr,240	pub params: Option<ParamsDesc>,241	pub value: LocExpr,242}243impl Finalize for BindSpec {}244unsafe impl Trace for BindSpec {245	unsafe_empty_trace!();246}247248#[cfg_attr(feature = "serialize", derive(Serialize))]249#[cfg_attr(feature = "deserialize", derive(Deserialize))]250#[derive(Debug, PartialEq)]251pub struct IfSpecData(pub LocExpr);252impl Finalize for IfSpecData {}253unsafe impl Trace for IfSpecData {254	unsafe_empty_trace!();255}256257#[cfg_attr(feature = "serialize", derive(Serialize))]258#[cfg_attr(feature = "deserialize", derive(Deserialize))]259#[derive(Debug, PartialEq)]260pub struct ForSpecData(pub IStr, pub LocExpr);261impl Finalize for ForSpecData {}262unsafe impl Trace for ForSpecData {263	unsafe_empty_trace!();264}265266#[cfg_attr(feature = "serialize", derive(Serialize))]267#[cfg_attr(feature = "deserialize", derive(Deserialize))]268#[derive(Debug, PartialEq)]269pub enum CompSpec {270	IfSpec(IfSpecData),271	ForSpec(ForSpecData),272}273impl Finalize for CompSpec {}274unsafe impl Trace for CompSpec {275	unsafe_empty_trace!();276}277278#[cfg_attr(feature = "serialize", derive(Serialize))]279#[cfg_attr(feature = "deserialize", derive(Deserialize))]280#[derive(Debug, PartialEq)]281pub struct ObjComp {282	pub pre_locals: Vec<BindSpec>,283	pub key: LocExpr,284	pub value: LocExpr,285	pub post_locals: Vec<BindSpec>,286	pub compspecs: Vec<CompSpec>,287}288impl Finalize for ObjComp {}289unsafe impl Trace for ObjComp {290	unsafe_empty_trace!();291}292293#[cfg_attr(feature = "serialize", derive(Serialize))]294#[cfg_attr(feature = "deserialize", derive(Deserialize))]295#[derive(Debug, PartialEq)]296pub enum ObjBody {297	MemberList(Vec<Member>),298	ObjComp(ObjComp),299}300impl Finalize for ObjBody {}301unsafe impl Trace for ObjBody {302	unsafe_empty_trace!();303}304305#[cfg_attr(feature = "serialize", derive(Serialize))]306#[cfg_attr(feature = "deserialize", derive(Deserialize))]307#[derive(Debug, PartialEq, Clone, Copy)]308pub enum LiteralType {309	This,310	Super,311	Dollar,312	Null,313	True,314	False,315}316impl Finalize for LiteralType {}317unsafe impl Trace for LiteralType {318	unsafe_empty_trace!();319}320321#[derive(Debug, PartialEq)]322pub struct SliceDesc {323	pub start: Option<LocExpr>,324	pub end: Option<LocExpr>,325	pub step: Option<LocExpr>,326}327impl Finalize for SliceDesc {}328unsafe impl Trace for SliceDesc {329	unsafe_empty_trace!();330}331332/// Syntax base333#[cfg_attr(feature = "serialize", derive(Serialize))]334#[cfg_attr(feature = "deserialize", derive(Deserialize))]335#[derive(Debug, PartialEq)]336pub enum Expr {337	Literal(LiteralType),338339	/// String value: "hello"340	Str(IStr),341	/// Number: 1, 2.0, 2e+20342	Num(f64),343	/// Variable name: test344	Var(IStr),345346	/// Array of expressions: [1, 2, "Hello"]347	Arr(Vec<LocExpr>),348	/// Array comprehension:349	/// ```jsonnet350	///  ingredients: [351	///    { kind: kind, qty: 4 / 3 }352	///    for kind in [353	///      'Honey Syrup',354	///      'Lemon Juice',355	///      'Farmers Gin',356	///    ]357	///  ],358	/// ```359	ArrComp(LocExpr, Vec<CompSpec>),360361	/// Object: {a: 2}362	Obj(ObjBody),363	/// Object extension: var1 {b: 2}364	ObjExtend(LocExpr, ObjBody),365366	/// (obj)367	Parened(LocExpr),368369	/// -2370	UnaryOp(UnaryOpType, LocExpr),371	/// 2 - 2372	BinaryOp(LocExpr, BinaryOpType, LocExpr),373	/// assert 2 == 2 : "Math is broken"374	AssertExpr(AssertStmt, LocExpr),375	/// local a = 2; { b: a }376	LocalExpr(Vec<BindSpec>, LocExpr),377378	/// import "hello"379	Import(PathBuf),380	/// importStr "file.txt"381	ImportStr(PathBuf),382	/// error "I'm broken"383	ErrorStmt(LocExpr),384	/// a(b, c)385	Apply(LocExpr, ArgsDesc, bool),386	/// a[b]387	Index(LocExpr, LocExpr),388	/// function(x) x389	Function(ParamsDesc, LocExpr),390	/// std.primitiveEquals391	Intrinsic(IStr),392	/// if true == false then 1 else 2393	IfElse {394		cond: IfSpecData,395		cond_then: LocExpr,396		cond_else: Option<LocExpr>,397	},398}399impl Finalize for Expr {}400unsafe impl Trace for Expr {401	unsafe_empty_trace!();402}403404/// file, begin offset, end offset405#[cfg_attr(feature = "serialize", derive(Serialize))]406#[cfg_attr(feature = "deserialize", derive(Deserialize))]407#[derive(Clone, PartialEq)]408pub struct ExprLocation(pub Rc<Path>, pub usize, pub usize);409impl Finalize for ExprLocation {}410unsafe impl Trace for ExprLocation {411	unsafe_empty_trace!();412}413414impl Debug for ExprLocation {415	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {416		write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)417	}418}419420/// Holds AST expression and its location in source file421#[cfg_attr(feature = "serialize", derive(Serialize))]422#[cfg_attr(feature = "deserialize", derive(Deserialize))]423#[derive(Clone, PartialEq)]424pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);425impl Finalize for LocExpr {}426unsafe impl Trace for LocExpr {427	unsafe_empty_trace!();428}429430impl Debug for LocExpr {431	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {432		if f.alternate() {433			write!(f, "{:#?}", self.0)?;434		} else {435			write!(f, "{:?}", self.0)?;436		}437		if let Some(loc) = &self.1 {438			write!(f, " from {:?}", loc)?;439		}440		Ok(())441	}442}443444/// Creates LocExpr from Expr and ExprLocation components445#[macro_export]446macro_rules! loc_expr {447	($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {448		LocExpr(449			std::rc::Rc::new($expr),450			if $need_loc {451				Some(ExprLocation($name, $start, $end))452			} else {453				None454			},455		)456	};457}458459/// Creates LocExpr without location info460#[macro_export]461macro_rules! loc_expr_todo {462	($expr:expr) => {463		LocExpr(Rc::new($expr), None)464	};465}
after · crates/jrsonnet-parser/src/expr.rs
1use jrsonnet_gc::{unsafe_empty_trace, Finalize, Trace};2use jrsonnet_interner::IStr;3#[cfg(feature = "deserialize")]4use serde::Deserialize;5#[cfg(feature = "serialize")]6use serde::Serialize;7use std::{8	fmt::{Debug, Display},9	ops::Deref,10	path::{Path, PathBuf},11	rc::Rc,12};1314#[cfg_attr(feature = "serialize", derive(Serialize))]15#[cfg_attr(feature = "deserialize", derive(Deserialize))]16#[derive(Debug, PartialEq, Trace)]17#[trivially_drop]18pub enum FieldName {19	/// {fixed: 2}20	Fixed(IStr),21	/// {["dyn"+"amic"]: 3}22	Dyn(LocExpr),23}2425#[cfg_attr(feature = "serialize", derive(Serialize))]26#[cfg_attr(feature = "deserialize", derive(Deserialize))]27#[derive(Debug, Clone, Copy, PartialEq, Trace)]28#[trivially_drop]29pub enum Visibility {30	/// :31	Normal,32	/// ::33	Hidden,34	/// :::35	Unhide,36}3738impl Visibility {39	pub fn is_visible(&self) -> bool {40		matches!(self, Self::Normal | Self::Unhide)41	}42}4344#[cfg_attr(feature = "serialize", derive(Serialize))]45#[cfg_attr(feature = "deserialize", derive(Deserialize))]46#[derive(Clone, Debug, PartialEq, Trace)]47#[trivially_drop]48pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);4950#[cfg_attr(feature = "serialize", derive(Serialize))]51#[cfg_attr(feature = "deserialize", derive(Deserialize))]52#[derive(Debug, PartialEq, Trace)]53#[trivially_drop]54pub struct FieldMember {55	pub name: FieldName,56	pub plus: bool,57	pub params: Option<ParamsDesc>,58	pub visibility: Visibility,59	pub value: LocExpr,60}6162#[cfg_attr(feature = "serialize", derive(Serialize))]63#[cfg_attr(feature = "deserialize", derive(Deserialize))]64#[derive(Debug, PartialEq, Trace)]65#[trivially_drop]66pub enum Member {67	Field(FieldMember),68	BindStmt(BindSpec),69	AssertStmt(AssertStmt),70}7172#[cfg_attr(feature = "serialize", derive(Serialize))]73#[cfg_attr(feature = "deserialize", derive(Deserialize))]74#[derive(Debug, Clone, Copy, PartialEq, Trace)]75#[trivially_drop]76pub enum UnaryOpType {77	Plus,78	Minus,79	BitNot,80	Not,81}8283impl Display for UnaryOpType {84	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {85		use UnaryOpType::*;86		write!(87			f,88			"{}",89			match self {90				Plus => "+",91				Minus => "-",92				BitNot => "~",93				Not => "!",94			}95		)96	}97}9899#[cfg_attr(feature = "serialize", derive(Serialize))]100#[cfg_attr(feature = "deserialize", derive(Deserialize))]101#[derive(Debug, Clone, Copy, PartialEq, Trace)]102#[trivially_drop]103pub enum BinaryOpType {104	Mul,105	Div,106107	/// Implemented as intrinsic, put here for completeness108	Mod,109110	Add,111	Sub,112113	Lhs,114	Rhs,115116	Lt,117	Gt,118	Lte,119	Gte,120121	BitAnd,122	BitOr,123	BitXor,124125	Eq,126	Neq,127128	And,129	Or,130}131132impl Display for BinaryOpType {133	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {134		use BinaryOpType::*;135		write!(136			f,137			"{}",138			match self {139				Mul => "*",140				Div => "/",141				Mod => "%",142				Add => "+",143				Sub => "-",144				Lhs => "<<",145				Rhs => ">>",146				Lt => "<",147				Gt => ">",148				Lte => "<=",149				Gte => ">=",150				BitAnd => "&",151				BitOr => "|",152				BitXor => "^",153				Eq => "==",154				Neq => "!=",155				And => "&&",156				Or => "||",157			}158		)159	}160}161162/// name, default value163#[cfg_attr(feature = "serialize", derive(Serialize))]164#[cfg_attr(feature = "deserialize", derive(Deserialize))]165#[derive(Debug, PartialEq, Trace)]166#[trivially_drop]167pub struct Param(pub IStr, pub Option<LocExpr>);168169/// Defined function parameters170#[cfg_attr(feature = "serialize", derive(Serialize))]171#[cfg_attr(feature = "deserialize", derive(Deserialize))]172#[derive(Debug, Clone, PartialEq)]173pub struct ParamsDesc(pub Rc<Vec<Param>>);174175/// Safety:176/// AST is acyclic, and there should be no gc pointers177unsafe impl Trace for ParamsDesc {178	unsafe_empty_trace!();179}180impl Finalize for ParamsDesc {}181182impl Deref for ParamsDesc {183	type Target = Vec<Param>;184	fn deref(&self) -> &Self::Target {185		&self.0186	}187}188189#[cfg_attr(feature = "serialize", derive(Serialize))]190#[cfg_attr(feature = "deserialize", derive(Deserialize))]191#[derive(Debug, PartialEq, Trace)]192#[trivially_drop]193pub struct Arg(pub Option<String>, pub LocExpr);194195#[cfg_attr(feature = "serialize", derive(Serialize))]196#[cfg_attr(feature = "deserialize", derive(Deserialize))]197#[derive(Debug, PartialEq, Trace)]198#[trivially_drop]199pub struct ArgsDesc(pub Vec<Arg>);200201impl Deref for ArgsDesc {202	type Target = Vec<Arg>;203	fn deref(&self) -> &Self::Target {204		&self.0205	}206}207208#[cfg_attr(feature = "serialize", derive(Serialize))]209#[cfg_attr(feature = "deserialize", derive(Deserialize))]210#[derive(Debug, Clone, PartialEq, Trace)]211#[trivially_drop]212pub struct BindSpec {213	pub name: IStr,214	pub params: Option<ParamsDesc>,215	pub value: LocExpr,216}217218#[cfg_attr(feature = "serialize", derive(Serialize))]219#[cfg_attr(feature = "deserialize", derive(Deserialize))]220#[derive(Debug, PartialEq, Trace)]221#[trivially_drop]222pub struct IfSpecData(pub LocExpr);223224#[cfg_attr(feature = "serialize", derive(Serialize))]225#[cfg_attr(feature = "deserialize", derive(Deserialize))]226#[derive(Debug, PartialEq, Trace)]227#[trivially_drop]228pub struct ForSpecData(pub IStr, pub LocExpr);229230#[cfg_attr(feature = "serialize", derive(Serialize))]231#[cfg_attr(feature = "deserialize", derive(Deserialize))]232#[derive(Debug, PartialEq, Trace)]233#[trivially_drop]234pub enum CompSpec {235	IfSpec(IfSpecData),236	ForSpec(ForSpecData),237}238239#[cfg_attr(feature = "serialize", derive(Serialize))]240#[cfg_attr(feature = "deserialize", derive(Deserialize))]241#[derive(Debug, PartialEq, Trace)]242#[trivially_drop]243pub struct ObjComp {244	pub pre_locals: Vec<BindSpec>,245	pub key: LocExpr,246	pub value: LocExpr,247	pub post_locals: Vec<BindSpec>,248	pub compspecs: Vec<CompSpec>,249}250251#[cfg_attr(feature = "serialize", derive(Serialize))]252#[cfg_attr(feature = "deserialize", derive(Deserialize))]253#[derive(Debug, PartialEq, Trace)]254#[trivially_drop]255pub enum ObjBody {256	MemberList(Vec<Member>),257	ObjComp(ObjComp),258}259260#[cfg_attr(feature = "serialize", derive(Serialize))]261#[cfg_attr(feature = "deserialize", derive(Deserialize))]262#[derive(Debug, PartialEq, Clone, Copy, Trace)]263#[trivially_drop]264pub enum LiteralType {265	This,266	Super,267	Dollar,268	Null,269	True,270	False,271}272273#[derive(Debug, PartialEq, Trace)]274#[trivially_drop]275pub struct SliceDesc {276	pub start: Option<LocExpr>,277	pub end: Option<LocExpr>,278	pub step: Option<LocExpr>,279}280281/// Syntax base282#[cfg_attr(feature = "serialize", derive(Serialize))]283#[cfg_attr(feature = "deserialize", derive(Deserialize))]284#[derive(Debug, PartialEq, Trace)]285#[trivially_drop]286pub enum Expr {287	Literal(LiteralType),288289	/// String value: "hello"290	Str(IStr),291	/// Number: 1, 2.0, 2e+20292	Num(f64),293	/// Variable name: test294	Var(IStr),295296	/// Array of expressions: [1, 2, "Hello"]297	Arr(Vec<LocExpr>),298	/// Array comprehension:299	/// ```jsonnet300	///  ingredients: [301	///    { kind: kind, qty: 4 / 3 }302	///    for kind in [303	///      'Honey Syrup',304	///      'Lemon Juice',305	///      'Farmers Gin',306	///    ]307	///  ],308	/// ```309	ArrComp(LocExpr, Vec<CompSpec>),310311	/// Object: {a: 2}312	Obj(ObjBody),313	/// Object extension: var1 {b: 2}314	ObjExtend(LocExpr, ObjBody),315316	/// (obj)317	Parened(LocExpr),318319	/// -2320	UnaryOp(UnaryOpType, LocExpr),321	/// 2 - 2322	BinaryOp(LocExpr, BinaryOpType, LocExpr),323	/// assert 2 == 2 : "Math is broken"324	AssertExpr(AssertStmt, LocExpr),325	/// local a = 2; { b: a }326	LocalExpr(Vec<BindSpec>, LocExpr),327328	/// import "hello"329	Import(PathBuf),330	/// importStr "file.txt"331	ImportStr(PathBuf),332	/// error "I'm broken"333	ErrorStmt(LocExpr),334	/// a(b, c)335	Apply(LocExpr, ArgsDesc, bool),336	/// a[b]337	Index(LocExpr, LocExpr),338	/// function(x) x339	Function(ParamsDesc, LocExpr),340	/// std.primitiveEquals341	Intrinsic(IStr),342	/// if true == false then 1 else 2343	IfElse {344		cond: IfSpecData,345		cond_then: LocExpr,346		cond_else: Option<LocExpr>,347	},348}349350/// file, begin offset, end offset351#[cfg_attr(feature = "serialize", derive(Serialize))]352#[cfg_attr(feature = "deserialize", derive(Deserialize))]353#[derive(Clone, PartialEq, Trace)]354#[trivially_drop]355pub struct ExprLocation(pub Rc<Path>, pub usize, pub usize);356357impl Debug for ExprLocation {358	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {359		write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)360	}361}362363/// Holds AST expression and its location in source file364#[cfg_attr(feature = "serialize", derive(Serialize))]365#[cfg_attr(feature = "deserialize", derive(Deserialize))]366#[derive(Clone, PartialEq)]367pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);368/// Safety:369/// AST is acyclic, and there should be no gc pointers370unsafe impl Trace for LocExpr {371	unsafe_empty_trace!();372}373impl Finalize for LocExpr {}374375impl Debug for LocExpr {376	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {377		if f.alternate() {378			write!(f, "{:#?}", self.0)?;379		} else {380			write!(f, "{:?}", self.0)?;381		}382		if let Some(loc) = &self.1 {383			write!(f, " from {:?}", loc)?;384		}385		Ok(())386	}387}388389/// Creates LocExpr from Expr and ExprLocation components390#[macro_export]391macro_rules! loc_expr {392	($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {393		LocExpr(394			std::rc::Rc::new($expr),395			if $need_loc {396				Some(ExprLocation($name, $start, $end))397			} else {398				None399			},400		)401	};402}403404/// Creates LocExpr without location info405#[macro_export]406macro_rules! loc_expr_todo {407	($expr:expr) => {408		LocExpr(Rc::new($expr), None)409	};410}
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -8,4 +8,4 @@
 
 [dependencies]
 peg = "0.7.0"
-gc = { version = "0.4.1", features = ["derive"] }
+jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -1,6 +1,6 @@
 #![allow(clippy::redundant_closure_call)]
 
-use gc::{unsafe_empty_trace, Finalize, Trace};
+use jrsonnet_gc::Trace;
 use std::fmt::Display;
 
 #[macro_export]
@@ -78,7 +78,8 @@
 	);
 }
 
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
+#[trivially_drop]
 pub enum ValType {
 	Bool,
 	Null,
@@ -87,10 +88,6 @@
 	Arr,
 	Obj,
 	Func,
-}
-impl Finalize for ValType {}
-unsafe impl Trace for ValType {
-	unsafe_empty_trace!();
 }
 
 impl ValType {
@@ -114,7 +111,8 @@
 	}
 }
 
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Trace)]
+#[trivially_drop]
 pub enum ComplexValType {
 	Any,
 	Char,
@@ -127,10 +125,6 @@
 	UnionRef(&'static [ComplexValType]),
 	Sum(Vec<ComplexValType>),
 	SumRef(&'static [ComplexValType]),
-}
-impl Finalize for ComplexValType {}
-unsafe impl Trace for ComplexValType {
-	unsafe_empty_trace!();
 }
 
 impl From<ValType> for ComplexValType {