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

difftreelog

build switch to released gcmodule fork

Yaroslav Bolyukin2022-06-05parent: #d76beb2.patch.diff
in: master

38 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -25,9 +25,9 @@
 
 [[package]]
 name = "anyhow"
-version = "1.0.49"
+version = "1.0.57"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a03e93e97a28fbc9f42fbc5ba0886a3c67eb637b476dbee711f80a6ffe8223d"
+checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
 
 [[package]]
 name = "atty"
@@ -42,9 +42,9 @@
 
 [[package]]
 name = "autocfg"
-version = "1.0.1"
+version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
 
 [[package]]
 name = "base64"
@@ -69,9 +69,9 @@
 
 [[package]]
 name = "cc"
-version = "1.0.72"
+version = "1.0.73"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
+checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
 
 [[package]]
 name = "cfg-if"
@@ -87,9 +87,9 @@
 
 [[package]]
 name = "clap"
-version = "3.1.13"
+version = "3.1.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4b3ee449efa0c4f95cd48b00539829d3655a98e189a90617246492788d22404"
+checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
 dependencies = [
  "atty",
  "bitflags",
@@ -104,18 +104,18 @@
 
 [[package]]
 name = "clap_complete"
-version = "3.1.3"
+version = "3.1.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1d7ca9141e27e6ebc52e3c378b0c07f3cea52db46ed1cc5861735fb697b56356"
+checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4"
 dependencies = [
  "clap",
 ]
 
 [[package]]
 name = "clap_derive"
-version = "3.1.7"
+version = "3.1.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
+checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
 dependencies = [
  "heck",
  "proc-macro-error",
@@ -147,26 +147,6 @@
 version = "0.4.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
-
-[[package]]
-name = "gcmodule"
-version = "0.3.3"
-source = "git+https://github.com/CertainLach/gcmodule?branch=jrsonnet#f72713c24c2b1bf5a78f1d01bee5a0f52bc2a094"
-dependencies = [
- "gcmodule_derive",
- "parking_lot",
-]
-
-[[package]]
-name = "gcmodule_derive"
-version = "0.3.3"
-source = "git+https://github.com/CertainLach/gcmodule?branch=jrsonnet#f72713c24c2b1bf5a78f1d01bee5a0f52bc2a094"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "synstructure",
-]
 
 [[package]]
 name = "getrandom"
@@ -211,9 +191,9 @@
 
 [[package]]
 name = "indexmap"
-version = "1.7.0"
+version = "1.8.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
+checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a"
 dependencies = [
  "autocfg",
  "hashbrown 0.11.2",
@@ -221,9 +201,9 @@
 
 [[package]]
 name = "itoa"
-version = "0.4.8"
+version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
+checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
 
 [[package]]
 name = "jrsonnet"
@@ -231,9 +211,9 @@
 dependencies = [
  "clap",
  "clap_complete",
- "gcmodule",
  "jrsonnet-cli",
  "jrsonnet-evaluator",
+ "jrsonnet-gcmodule",
  "jrsonnet-parser",
  "mimallocator",
  "thiserror",
@@ -244,8 +224,8 @@
 version = "0.4.2"
 dependencies = [
  "clap",
- "gcmodule",
  "jrsonnet-evaluator",
+ "jrsonnet-gcmodule",
  "jrsonnet-parser",
 ]
 
@@ -257,8 +237,8 @@
  "anyhow",
  "base64",
  "bincode",
- "gcmodule",
  "hashbrown 0.12.1",
+ "jrsonnet-gcmodule",
  "jrsonnet-interner",
  "jrsonnet-macros",
  "jrsonnet-parser",
@@ -276,11 +256,32 @@
 ]
 
 [[package]]
+name = "jrsonnet-gcmodule"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22d4e1572e4b61e4f5deb3701312a330df0e69b48805a540d740e5e53ac8c78a"
+dependencies = [
+ "jrsonnet-gcmodule-derive",
+ "parking_lot",
+]
+
+[[package]]
+name = "jrsonnet-gcmodule-derive"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae2f3bf7d38e0a9098b5b9062a7d9e7a97a206bc3c91118d76e7e37f2e0f1202"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
 name = "jrsonnet-interner"
 version = "0.4.2"
 dependencies = [
- "gcmodule",
  "hashbrown 0.12.1",
+ "jrsonnet-gcmodule",
  "rustc-hash",
  "serde",
 ]
@@ -298,7 +299,7 @@
 name = "jrsonnet-parser"
 version = "0.4.2"
 dependencies = [
- "gcmodule",
+ "jrsonnet-gcmodule",
  "jrsonnet-interner",
  "jrsonnet-stdlib",
  "peg",
@@ -314,7 +315,7 @@
 name = "jrsonnet-types"
 version = "0.4.2"
 dependencies = [
- "gcmodule",
+ "jrsonnet-gcmodule",
  "peg",
 ]
 
@@ -322,8 +323,8 @@
 name = "jsonnet"
 version = "0.4.2"
 dependencies = [
- "gcmodule",
  "jrsonnet-evaluator",
+ "jrsonnet-gcmodule",
  "jrsonnet-parser",
 ]
 
@@ -335,9 +336,9 @@
 
 [[package]]
 name = "libc"
-version = "0.2.125"
+version = "0.2.126"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
+checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
 
 [[package]]
 name = "linked-hash-map"
@@ -381,15 +382,15 @@
 
 [[package]]
 name = "once_cell"
-version = "1.10.0"
+version = "1.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
+checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
 
 [[package]]
 name = "os_str_bytes"
-version = "6.0.0"
+version = "6.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
+checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
 
 [[package]]
 name = "parking_lot"
@@ -474,18 +475,18 @@
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.32"
+version = "1.0.39"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
+checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
 dependencies = [
- "unicode-xid",
+ "unicode-ident",
 ]
 
 [[package]]
 name = "quote"
-version = "1.0.10"
+version = "1.0.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
+checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
 dependencies = [
  "proc-macro2",
 ]
@@ -504,9 +505,9 @@
 
 [[package]]
 name = "ryu"
-version = "1.0.5"
+version = "1.0.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
+checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
 
 [[package]]
 name = "scopeguard"
@@ -516,18 +517,18 @@
 
 [[package]]
 name = "serde"
-version = "1.0.130"
+version = "1.0.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
+checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
 dependencies = [
  "serde_derive",
 ]
 
 [[package]]
 name = "serde_derive"
-version = "1.0.130"
+version = "1.0.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
+checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -536,9 +537,9 @@
 
 [[package]]
 name = "serde_json"
-version = "1.0.72"
+version = "1.0.81"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
+checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
 dependencies = [
  "indexmap",
  "itoa",
@@ -559,9 +560,9 @@
 
 [[package]]
 name = "smallvec"
-version = "1.7.0"
+version = "1.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
+checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
 
 [[package]]
 name = "static_assertions"
@@ -577,32 +578,20 @@
 
 [[package]]
 name = "syn"
-version = "1.0.82"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-xid",
-]
-
-[[package]]
-name = "synstructure"
-version = "0.12.6"
+version = "1.0.96"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
+checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn",
- "unicode-xid",
+ "unicode-ident",
 ]
 
 [[package]]
 name = "termcolor"
-version = "1.1.2"
+version = "1.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
 dependencies = [
  "winapi-util",
 ]
@@ -615,18 +604,18 @@
 
 [[package]]
 name = "thiserror"
-version = "1.0.30"
+version = "1.0.31"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
+checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
 dependencies = [
  "thiserror-impl",
 ]
 
 [[package]]
 name = "thiserror-impl"
-version = "1.0.30"
+version = "1.0.31"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
+checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -634,22 +623,22 @@
 ]
 
 [[package]]
-name = "unicode-width"
-version = "0.1.9"
+name = "unicode-ident"
+version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
+checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
 
 [[package]]
-name = "unicode-xid"
-version = "0.2.2"
+name = "unicode-width"
+version = "0.1.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
 
 [[package]]
 name = "version_check"
-version = "0.9.3"
+version = "0.9.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
 
 [[package]]
 name = "wasi"
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.4.2" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
+jrsonnet-gcmodule = { version = "0.3.4" }
 
 [lib]
 crate-type = ["cdylib"]
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -3,7 +3,6 @@
 	os::raw::{c_char, c_int},
 };
 
-use gcmodule::Cc;
 use jrsonnet_evaluator::{
 	error::{Error, LocError},
 	function::builtin::{BuiltinParam, NativeCallback, NativeCallbackHandler},
@@ -11,6 +10,7 @@
 	typed::Typed,
 	IStr, State, Val,
 };
+use jrsonnet_gcmodule::Cc;
 
 type JsonnetNativeCallback = unsafe extern "C" fn(
 	ctx: *const c_void,
@@ -18,11 +18,11 @@
 	success: *mut c_int,
 ) -> *mut Val;
 
-#[derive(gcmodule::Trace)]
+#[derive(jrsonnet_gcmodule::Trace)]
 struct JsonnetNativeCallbackHandler {
-	#[skip_trace]
+	#[trace(skip)]
 	ctx: *const c_void,
-	#[skip_trace]
+	#[trace(skip)]
 	cb: JsonnetNativeCallback,
 }
 impl NativeCallbackHandler for JsonnetNativeCallbackHandler {
modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -5,8 +5,8 @@
 	os::raw::{c_char, c_double, c_int},
 };
 
-use gcmodule::Cc;
 use jrsonnet_evaluator::{val::ArrValue, ObjValue, State, Val};
+use jrsonnet_gcmodule::Cc;
 
 /// # Safety
 ///
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -4,8 +4,8 @@
 
 use std::{ffi::CStr, os::raw::c_char};
 
-use gcmodule::Cc;
 use jrsonnet_evaluator::{val::ArrValue, State, Thunk, Val};
+use jrsonnet_gcmodule::Cc;
 
 /// # Safety
 ///
modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -23,8 +23,9 @@
 jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
 jrsonnet-cli = { path = "../../crates/jrsonnet-cli", version = "0.4.2" }
+jrsonnet-gcmodule = { version = "0.3.4" }
+
 mimallocator = { version = "0.1.3", optional = true }
 thiserror = "1.0"
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
 clap = { version = "3.1", features = ["derive"] }
 clap_complete = { version = "3.1" }
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -115,7 +115,6 @@
 }
 
 fn main_real(s: &State, opts: Opts) -> Result<(), Error> {
-	opts.gc.configure_global();
 	opts.general.configure(s)?;
 	opts.manifest.configure(s)?;
 
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -14,6 +14,6 @@
     "explaining-traces",
 ] }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
+jrsonnet-gcmodule = { version = "0.3.4" }
 
 clap = { version = "3.1", features = ["derive"] }
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -8,6 +8,7 @@
 use clap::Parser;
 pub use ext::*;
 use jrsonnet_evaluator::{error::Result, FileImportResolver, State};
+use jrsonnet_gcmodule::with_thread_object_space;
 pub use manifest::*;
 pub use tla::*;
 pub use trace::*;
@@ -111,15 +112,21 @@
 	gc_collect_before_printing_stats: bool,
 }
 impl GcOpts {
-	pub fn configure_global(&self) {
-		if !self.gc_collect_on_exit {
-			gcmodule::set_thread_collect_on_drop(false)
-		}
+	pub fn stats_printer(&self) -> (Option<GcStatsPrinter>, Option<LeakSpace>) {
+		(
+			self.gc_print_stats.then(|| GcStatsPrinter {
+				collect_before_printing_stats: self.gc_collect_before_printing_stats,
+			}),
+			(!self.gc_collect_on_exit).then(|| LeakSpace {}),
+		)
 	}
-	pub fn stats_printer(&self) -> Option<GcStatsPrinter> {
-		self.gc_print_stats.then(|| GcStatsPrinter {
-			collect_before_printing_stats: self.gc_collect_before_printing_stats,
-		})
+}
+
+pub struct LeakSpace {}
+
+impl Drop for LeakSpace {
+	fn drop(&mut self) {
+		with_thread_object_space(|s| s.leak())
 	}
 }
 
@@ -130,9 +137,9 @@
 	fn drop(&mut self) {
 		eprintln!("=== GC STATS ===");
 		if self.collect_before_printing_stats {
-			let collected = gcmodule::collect_thread_cycles();
+			let collected = jrsonnet_gcmodule::collect_thread_cycles();
 			eprintln!("Collected: {}", collected);
 		}
-		eprintln!("Tracked: {}", gcmodule::count_thread_tracked())
+		eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
 	}
 }
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -30,6 +30,8 @@
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.4.2" }
 jrsonnet-types = { path = "../jrsonnet-types", version = "0.4.2" }
 jrsonnet-macros = { path = "../jrsonnet-macros", version = "0.4.2" }
+jrsonnet-gcmodule = { version = "0.3.4" }
+
 pathdiff = "0.2.1"
 hashbrown = "0.12.1"
 static_assertions = "1.1.0"
@@ -39,7 +41,6 @@
 rustc-hash = "1.1"
 
 thiserror = "1.0"
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
 
 serde = "1.0"
 serde_json = "1.0"
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -1,11 +1,10 @@
 use std::fmt::Debug;
 
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 
 use crate::{
-	cc_ptr_eq, error::Error::*, gc::GcHashMap, map::LayeredHashMap, ObjValue, Pending, Result,
-	Thunk, Val,
+	error::Error::*, gc::GcHashMap, map::LayeredHashMap, ObjValue, Pending, Result, Thunk, Val,
 };
 
 #[derive(Trace)]
@@ -136,6 +135,6 @@
 
 impl PartialEq for Context {
 	fn eq(&self, other: &Self) -> bool {
-		cc_ptr_eq(&self.0, &other.0)
+		Cc::ptr_eq(&self.0, &other.0)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/dynamic.rs
+++ b/crates/jrsonnet-evaluator/src/dynamic.rs
@@ -1,6 +1,6 @@
 use std::cell::RefCell;
 
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 
 #[derive(Clone, Trace)]
 pub struct Pending<V: Trace + 'static>(pub Cc<RefCell<Option<V>>>);
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -1,6 +1,6 @@
 use std::{fmt::Debug, path::PathBuf};
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BinaryOpType, ExprLocation, Source, UnaryOpType};
 use jrsonnet_types::ValType;
@@ -125,7 +125,7 @@
 	ImportSyntaxError {
 		path: Source,
 		source_code: IStr,
-		#[skip_trace]
+		#[trace(skip)]
 		error: Box<jrsonnet_parser::ParseError>,
 	},
 
modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -1,4 +1,4 @@
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BindSpec, Destruct, LocExpr, ParamsDesc};
 
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -1,6 +1,6 @@
 use std::{cmp::Ordering, rc::Rc};
 
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{
 	ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, FieldName, ForSpecData,
@@ -151,7 +151,7 @@
 				value,
 			}) => {
 				#[derive(Trace)]
-				struct UnboundValue<B> {
+				struct UnboundValue<B: Trace> {
 					uctx: B,
 					value: LocExpr,
 					name: IStr,
@@ -201,7 +201,7 @@
 				..
 			}) => {
 				#[derive(Trace)]
-				struct UnboundMethod<B> {
+				struct UnboundMethod<B: Trace> {
 					uctx: B,
 					value: LocExpr,
 					params: ParamsDesc,
@@ -247,7 +247,7 @@
 			Member::BindStmt(_) => {}
 			Member::AssertStmt(stmt) => {
 				#[derive(Trace)]
-				struct ObjectAssert<B> {
+				struct ObjectAssert<B: Trace> {
 					uctx: B,
 					assert: AssertStmt,
 				}
@@ -299,7 +299,7 @@
 					Val::Null => {}
 					Val::Str(n) => {
 						#[derive(Trace)]
-						struct UnboundValue<B> {
+						struct UnboundValue<B: Trace> {
 							uctx: B,
 							value: LocExpr,
 						}
modifiedcrates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/arglike.rs
+++ b/crates/jrsonnet-evaluator/src/function/arglike.rs
@@ -1,6 +1,6 @@
 use std::collections::HashMap;
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ArgsDesc, LocExpr};
 
modifiedcrates/jrsonnet-evaluator/src/function/builtin.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/builtin.rs
+++ b/crates/jrsonnet-evaluator/src/function/builtin.rs
@@ -1,6 +1,6 @@
 use std::borrow::Cow;
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 
 use super::{arglike::ArgsLike, parse::parse_builtin_call, CallLocation};
 use crate::{error::Result, gc::TraceBox, Context, State, Val};
modifiedcrates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -1,7 +1,7 @@
 use std::fmt::Debug;
 
 pub use arglike::{ArgLike, ArgsLike, TlaArg};
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 pub use jrsonnet_macros::builtin;
 use jrsonnet_parser::{ExprLocation, LocExpr, ParamsDesc};
@@ -91,7 +91,7 @@
 	/// Plain function implemented in jsonnet
 	Normal(Cc<FuncDesc>),
 	/// Standard library function
-	StaticBuiltin(#[skip_trace] &'static dyn StaticBuiltin),
+	StaticBuiltin(#[trace(skip)] &'static dyn StaticBuiltin),
 	/// User-provided function
 	Builtin(Cc<TraceBox<dyn Builtin>>),
 }
modifiedcrates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -1,4 +1,4 @@
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{LocExpr, ParamsDesc};
 
modifiedcrates/jrsonnet-evaluator/src/gc.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/gc.rs
+++ b/crates/jrsonnet-evaluator/src/gc.rs
@@ -6,8 +6,8 @@
 	ops::{Deref, DerefMut},
 };
 
-use gcmodule::{Trace, Tracer};
 use hashbrown::HashMap;
+use jrsonnet_gcmodule::{Trace, Tracer};
 use rustc_hash::{FxHashSet, FxHasher};
 
 /// Replacement for box, which assumes that the underlying type is [`Trace`]
@@ -92,7 +92,7 @@
 where
 	V: Trace,
 {
-	fn trace(&self, tracer: &mut gcmodule::Tracer) {
+	fn trace(&self, tracer: &mut jrsonnet_gcmodule::Tracer) {
 		for v in &self.0 {
 			v.trace(tracer);
 		}
@@ -133,7 +133,7 @@
 	K: Trace,
 	V: Trace,
 {
-	fn trace(&self, tracer: &mut gcmodule::Tracer) {
+	fn trace(&self, tracer: &mut jrsonnet_gcmodule::Tracer) {
 		for (k, v) in &self.0 {
 			k.trace(tracer);
 			v.trace(tracer);
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -57,9 +57,9 @@
 pub use evaluate::*;
 use function::{builtin::Builtin, CallLocation, TlaArg};
 use gc::{GcHashMap, TraceBox};
-use gcmodule::{Cc, Trace, Weak};
 use hashbrown::hash_map::RawEntryMut;
 pub use import::*;
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IBytes;
 pub use jrsonnet_interner::IStr;
 pub use jrsonnet_parser as parser;
@@ -704,32 +704,4 @@
 	pub fn set_max_stack(&self, trace: usize) {
 		self.settings_mut().max_stack = trace;
 	}
-}
-
-pub fn cc_ptr_eq<T>(a: &Cc<T>, b: &Cc<T>) -> bool {
-	let a = a as &T;
-	let b = b as &T;
-	std::ptr::eq(a, b)
-}
-
-fn weak_raw<T>(a: Weak<T>) -> *const () {
-	unsafe { std::mem::transmute(a) }
-}
-fn weak_ptr_eq<T>(a: Weak<T>, b: Weak<T>) -> bool {
-	std::ptr::eq(weak_raw(a), weak_raw(b))
-}
-
-#[test]
-fn weak_unsafe() {
-	let a = Cc::new(1);
-	let b = Cc::new(2);
-
-	let aw1 = a.clone().downgrade();
-	let aw2 = a.clone().downgrade();
-	let aw3 = a.clone().downgrade();
-
-	let bw = b.clone().downgrade();
-
-	assert!(weak_ptr_eq(aw1, aw2));
-	assert!(!weak_ptr_eq(aw3, bw));
 }
modifiedcrates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/map.rs
+++ b/crates/jrsonnet-evaluator/src/map.rs
@@ -1,10 +1,10 @@
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 
 use crate::{GcHashMap, Thunk, Val};
 
 #[derive(Trace)]
-#[force_tracking]
+#[trace(tracking(force))]
 pub struct LayeredHashMapInternals {
 	parent: Option<LayeredHashMap>,
 	current: GcHashMap<IStr, Thunk<Val>>,
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/obj.rs
1use std::{2	cell::RefCell,3	fmt::Debug,4	hash::{Hash, Hasher},5	ptr::addr_of,6};78use gcmodule::{Cc, Trace, Weak};9use jrsonnet_interner::IStr;10use jrsonnet_parser::{ExprLocation, Visibility};11use rustc_hash::FxHashMap;1213use crate::{14	cc_ptr_eq,15	error::{Error::*, LocError},16	function::CallLocation,17	gc::{GcHashMap, GcHashSet, TraceBox},18	operator::evaluate_add_op,19	throw, weak_ptr_eq, weak_raw, LazyBinding, Result, State, Thunk, Unbound, Val,20};2122#[cfg(not(feature = "exp-preserve-order"))]23mod ordering {24	#![allow(25		// This module works as stub for preserve-order feature26		clippy::unused_self,27	)]2829	use gcmodule::Trace;3031	#[derive(Clone, Copy, Default, Debug, Trace)]32	pub struct FieldIndex;33	impl FieldIndex {34		pub const fn next(self) -> Self {35			Self36		}37	}3839	#[derive(Clone, Copy, Default, Debug, Trace)]40	pub struct SuperDepth;41	impl SuperDepth {42		pub const fn deeper(self) -> Self {43			Self44		}45	}4647	#[derive(Clone, Copy)]48	pub struct FieldSortKey;49	impl FieldSortKey {50		pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {51			Self52		}53	}54}5556#[cfg(feature = "exp-preserve-order")]57mod ordering {58	use std::cmp::Reverse;5960	use gcmodule::Trace;6162	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]63	pub struct FieldIndex(u32);64	impl FieldIndex {65		pub fn next(self) -> Self {66			Self(self.0 + 1)67		}68	}6970	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]71	pub struct SuperDepth(u32);72	impl SuperDepth {73		pub fn deeper(self) -> Self {74			Self(self.0 + 1)75		}76	}7778	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]79	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);80	impl FieldSortKey {81		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {82			Self(Reverse(depth), index)83		}84		pub fn collide(self, other: Self) -> Self {85			if self.0 .0 > other.0 .0 {86				self87			} else if self.0 .0 < other.0 .0 {88				other89			} else {90				unreachable!("object can't have two fields with same name")91			}92		}93	}94}9596use ordering::*;9798#[allow(clippy::module_name_repetitions)]99#[derive(Debug, Trace)]100pub struct ObjMember {101	pub add: bool,102	pub visibility: Visibility,103	original_index: FieldIndex,104	pub invoke: LazyBinding,105	pub location: Option<ExprLocation>,106}107108pub trait ObjectAssertion: Trace {109	fn run(&self, s: State, super_obj: Option<ObjValue>, this: Option<ObjValue>) -> Result<()>;110}111112// Field => This113type CacheKey = (IStr, WeakObjValue);114115#[derive(Trace)]116enum CacheValue {117	Cached(Val),118	NotFound,119	Pending,120	Errored(LocError),121}122123#[allow(clippy::module_name_repetitions)]124#[derive(Trace)]125#[force_tracking]126pub struct ObjValueInternals {127	sup: Option<ObjValue>,128	this: Option<ObjValue>,129130	assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,131	assertions_ran: RefCell<GcHashSet<ObjValue>>,132	this_entries: Cc<GcHashMap<IStr, ObjMember>>,133	value_cache: RefCell<GcHashMap<CacheKey, CacheValue>>,134}135136#[derive(Clone, Trace)]137pub struct WeakObjValue(#[skip_trace] pub(crate) Weak<ObjValueInternals>);138139impl PartialEq for WeakObjValue {140	fn eq(&self, other: &Self) -> bool {141		weak_ptr_eq(self.0.clone(), other.0.clone())142	}143}144145impl Eq for WeakObjValue {}146impl Hash for WeakObjValue {147	fn hash<H: Hasher>(&self, hasher: &mut H) {148		hasher.write_usize(weak_raw(self.0.clone()) as usize);149	}150}151152#[allow(clippy::module_name_repetitions)]153#[derive(Clone, Trace)]154pub struct ObjValue(pub(crate) Cc<ObjValueInternals>);155impl Debug for ObjValue {156	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {157		if let Some(super_obj) = self.0.sup.as_ref() {158			if f.alternate() {159				write!(f, "{:#?}", super_obj)?;160			} else {161				write!(f, "{:?}", super_obj)?;162			}163			write!(f, " + ")?;164		}165		let mut debug = f.debug_struct("ObjValue");166		for (name, member) in self.0.this_entries.iter() {167			debug.field(name, member);168		}169		debug.finish_non_exhaustive()170	}171}172173impl ObjValue {174	pub fn new(175		sup: Option<Self>,176		this_entries: Cc<GcHashMap<IStr, ObjMember>>,177		assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,178	) -> Self {179		Self(Cc::new(ObjValueInternals {180			sup,181			this: None,182			assertions,183			assertions_ran: RefCell::new(GcHashSet::new()),184			this_entries,185			value_cache: RefCell::new(GcHashMap::new()),186		}))187	}188	pub fn new_empty() -> Self {189		Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))190	}191	#[must_use]192	pub fn extend_from(&self, sup: Self) -> Self {193		match &self.0.sup {194			None => Self::new(195				Some(sup),196				self.0.this_entries.clone(),197				self.0.assertions.clone(),198			),199			Some(v) => Self::new(200				Some(v.extend_from(sup)),201				self.0.this_entries.clone(),202				self.0.assertions.clone(),203			),204		}205	}206	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {207		let mut new = GcHashMap::with_capacity(1);208		new.insert(key, value);209		Self::new(Some(self), Cc::new(new), Cc::new(Vec::new()))210	}211	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder> {212		ObjMemberBuilder::new(ExtendBuilder(self), name, FieldIndex::default())213	}214215	#[must_use]216	pub fn with_this(&self, this: Self) -> Self {217		Self(Cc::new(ObjValueInternals {218			sup: self.0.sup.clone(),219			assertions: self.0.assertions.clone(),220			assertions_ran: RefCell::new(GcHashSet::new()),221			this: Some(this),222			this_entries: self.0.this_entries.clone(),223			value_cache: RefCell::new(GcHashMap::new()),224		}))225	}226227	pub fn len(&self) -> usize {228		self.fields_visibility()229			.into_iter()230			.filter(|(_, (visible, _))| *visible)231			.count()232	}233234	pub fn is_empty(&self) -> bool {235		if !self.0.this_entries.is_empty() {236			return false;237		}238		self.0.sup.as_ref().map_or(true, Self::is_empty)239	}240241	/// Run callback for every field found in object242	pub(crate) fn enum_fields(243		&self,244		depth: SuperDepth,245		handler: &mut impl FnMut(SuperDepth, &IStr, &ObjMember) -> bool,246	) -> bool {247		if let Some(s) = &self.0.sup {248			if s.enum_fields(depth.deeper(), handler) {249				return true;250			}251		}252		for (name, member) in self.0.this_entries.iter() {253			if handler(depth, name, member) {254				return true;255			}256		}257		false258	}259260	pub fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {261		let mut out = FxHashMap::default();262		self.enum_fields(SuperDepth::default(), &mut |depth, name, member| {263			let new_sort_key = FieldSortKey::new(depth, member.original_index);264			let entry = out.entry(name.clone());265			let (visible, _) = entry.or_insert((true, new_sort_key));266			match member.visibility {267				Visibility::Normal => {}268				Visibility::Hidden => {269					*visible = false;270				}271				Visibility::Unhide => {272					*visible = true;273				}274			};275			false276		});277		out278	}279	pub fn fields_ex(280		&self,281		include_hidden: bool,282		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,283	) -> Vec<IStr> {284		#[cfg(feature = "exp-preserve-order")]285		if preserve_order {286			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self287				.fields_visibility()288				.into_iter()289				.filter(|(_, (visible, _))| include_hidden || *visible)290				.enumerate()291				.map(|(idx, (k, (_, sk)))| (k, (sk, idx)))292				.unzip();293			keys.sort_unstable_by_key(|v| v.0);294			// Reorder in-place by resulting indexes295			for i in 0..fields.len() {296				let x = fields[i].clone();297				let mut j = i;298				loop {299					let k = keys[j].1;300					keys[j].1 = j;301					if k == i {302						break;303					}304					fields[j] = fields[k].clone();305					j = k306				}307				fields[j] = x;308			}309			return fields;310		}311312		let mut fields: Vec<_> = self313			.fields_visibility()314			.into_iter()315			.filter(|(_, (visible, _))| include_hidden || *visible)316			.map(|(k, _)| k)317			.collect();318		fields.sort_unstable();319		fields320	}321	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {322		self.fields_ex(323			false,324			#[cfg(feature = "exp-preserve-order")]325			preserve_order,326		)327	}328329	pub fn field_visibility(&self, name: IStr) -> Option<Visibility> {330		if let Some(m) = self.0.this_entries.get(&name) {331			Some(match &m.visibility {332				Visibility::Normal => self333					.0334					.sup335					.as_ref()336					.and_then(|super_obj| super_obj.field_visibility(name))337					.unwrap_or(Visibility::Normal),338				v => *v,339			})340		} else if let Some(super_obj) = &self.0.sup {341			super_obj.field_visibility(name)342		} else {343			None344		}345	}346347	fn has_field_include_hidden(&self, name: IStr) -> bool {348		if self.0.this_entries.contains_key(&name) {349			true350		} else if let Some(super_obj) = &self.0.sup {351			super_obj.has_field_include_hidden(name)352		} else {353			false354		}355	}356357	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {358		if include_hidden {359			self.has_field_include_hidden(name)360		} else {361			self.has_field(name)362		}363	}364	pub fn has_field(&self, name: IStr) -> bool {365		self.field_visibility(name)366			.map_or(false, |v| v.is_visible())367	}368369	pub fn get(&self, s: State, key: IStr) -> Result<Option<Val>> {370		self.run_assertions(s.clone())?;371		self.get_raw(s, key, self.0.this.clone().unwrap_or_else(|| self.clone()))372	}373374	// pub fn extend_with(self, key: )375376	fn get_raw(&self, s: State, key: IStr, real_this: Self) -> Result<Option<Val>> {377		let cache_key = (key.clone(), WeakObjValue(real_this.0.downgrade()));378379		if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {380			return Ok(match v {381				CacheValue::Cached(v) => Some(v.clone()),382				CacheValue::NotFound => None,383				CacheValue::Pending => throw!(InfiniteRecursionDetected),384				CacheValue::Errored(e) => return Err(e.clone()),385			});386		}387		self.0388			.value_cache389			.borrow_mut()390			.insert(cache_key.clone(), CacheValue::Pending);391		let fill_error = |e: LocError| {392			self.0393				.value_cache394				.borrow_mut()395				.insert(cache_key.clone(), CacheValue::Errored(e.clone()));396			e397		};398		let value = match (self.0.this_entries.get(&key), &self.0.sup) {399			(Some(k), None) => Ok(Some(400				self.evaluate_this(s, k, real_this).map_err(fill_error)?,401			)),402			(Some(k), Some(super_obj)) => {403				let our = self404					.evaluate_this(s.clone(), k, real_this.clone())405					.map_err(fill_error)?;406				if k.add {407					super_obj408						.get_raw(s.clone(), key, real_this)409						.map_err(fill_error)?410						.map_or(Ok(Some(our.clone())), |v| {411							Ok(Some(evaluate_add_op(s.clone(), &v, &our)?))412						})413				} else {414					Ok(Some(our))415				}416			}417			(None, Some(super_obj)) => super_obj.get_raw(s, key, real_this),418			(None, None) => Ok(None),419		}420		.map_err(fill_error)?;421		self.0.value_cache.borrow_mut().insert(422			cache_key,423			match &value {424				Some(v) => CacheValue::Cached(v.clone()),425				None => CacheValue::NotFound,426			},427		);428		Ok(value)429	}430	fn evaluate_this(&self, s: State, v: &ObjMember, real_this: Self) -> Result<Val> {431		v.invoke432			.evaluate(s.clone(), self.0.sup.clone(), Some(real_this))?433			.evaluate(s)434	}435436	fn run_assertions_raw(&self, s: State, real_this: &Self) -> Result<()> {437		if self.0.assertions_ran.borrow_mut().insert(real_this.clone()) {438			for assertion in self.0.assertions.iter() {439				if let Err(e) =440					assertion.run(s.clone(), self.0.sup.clone(), Some(real_this.clone()))441				{442					self.0.assertions_ran.borrow_mut().remove(real_this);443					return Err(e);444				}445			}446			if let Some(super_obj) = &self.0.sup {447				super_obj.run_assertions_raw(s, real_this)?;448			}449		}450		Ok(())451	}452	pub fn run_assertions(&self, s: State) -> Result<()> {453		self.run_assertions_raw(s, self)454	}455456	pub fn ptr_eq(a: &Self, b: &Self) -> bool {457		cc_ptr_eq(&a.0, &b.0)458	}459	pub fn downgrade(self) -> WeakObjValue {460		WeakObjValue(self.0.downgrade())461	}462}463464impl PartialEq for ObjValue {465	fn eq(&self, other: &Self) -> bool {466		cc_ptr_eq(&self.0, &other.0)467	}468}469470impl Eq for ObjValue {}471impl Hash for ObjValue {472	fn hash<H: Hasher>(&self, hasher: &mut H) {473		hasher.write_usize(addr_of!(*self.0) as usize);474	}475}476477#[allow(clippy::module_name_repetitions)]478pub struct ObjValueBuilder {479	sup: Option<ObjValue>,480	map: GcHashMap<IStr, ObjMember>,481	assertions: Vec<TraceBox<dyn ObjectAssertion>>,482	next_field_index: FieldIndex,483}484impl ObjValueBuilder {485	pub fn new() -> Self {486		Self::with_capacity(0)487	}488	pub fn with_capacity(capacity: usize) -> Self {489		Self {490			sup: None,491			map: GcHashMap::with_capacity(capacity),492			assertions: Vec::new(),493			next_field_index: FieldIndex::default(),494		}495	}496	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {497		self.assertions.reserve_exact(capacity);498		self499	}500	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {501		self.sup = Some(super_obj);502		self503	}504505	pub fn assert(&mut self, assertion: TraceBox<dyn ObjectAssertion>) -> &mut Self {506		self.assertions.push(assertion);507		self508	}509	pub fn member(&mut self, name: IStr) -> ObjMemberBuilder<ValueBuilder> {510		let field_index = self.next_field_index;511		self.next_field_index = self.next_field_index.next();512		ObjMemberBuilder::new(ValueBuilder(self), name, field_index)513	}514515	pub fn build(self) -> ObjValue {516		ObjValue::new(self.sup, Cc::new(self.map), Cc::new(self.assertions))517	}518}519impl Default for ObjValueBuilder {520	fn default() -> Self {521		Self::with_capacity(0)522	}523}524525#[allow(clippy::module_name_repetitions)]526#[must_use = "value not added unless binding() was called"]527pub struct ObjMemberBuilder<Kind> {528	kind: Kind,529	name: IStr,530	add: bool,531	visibility: Visibility,532	original_index: FieldIndex,533	location: Option<ExprLocation>,534}535536#[allow(clippy::missing_const_for_fn)]537impl<Kind> ObjMemberBuilder<Kind> {538	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {539		Self {540			kind,541			name,542			original_index,543			add: false,544			visibility: Visibility::Normal,545			location: None,546		}547	}548549	pub const fn with_add(mut self, add: bool) -> Self {550		self.add = add;551		self552	}553	pub fn add(self) -> Self {554		self.with_add(true)555	}556	pub fn with_visibility(mut self, visibility: Visibility) -> Self {557		self.visibility = visibility;558		self559	}560	pub fn hide(self) -> Self {561		self.with_visibility(Visibility::Hidden)562	}563	pub fn with_location(mut self, location: ExprLocation) -> Self {564		self.location = Some(location);565		self566	}567	fn build_member(self, binding: LazyBinding) -> (Kind, IStr, ObjMember) {568		(569			self.kind,570			self.name,571			ObjMember {572				add: self.add,573				visibility: self.visibility,574				original_index: self.original_index,575				invoke: binding,576				location: self.location,577			},578		)579	}580}581582pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);583impl<'v> ObjMemberBuilder<ValueBuilder<'v>> {584	pub fn value(self, s: State, value: Val) -> Result<()> {585		self.binding(s, LazyBinding::Bound(Thunk::evaluated(value)))586	}587	pub fn bindable(588		self,589		s: State,590		bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>,591	) -> Result<()> {592		self.binding(s, LazyBinding::Bindable(Cc::new(bindable)))593	}594	pub fn binding(self, s: State, binding: LazyBinding) -> Result<()> {595		let (receiver, name, member) = self.build_member(binding);596		let location = member.location.clone();597		let old = receiver.0.map.insert(name.clone(), member);598		if old.is_some() {599			s.push(600				CallLocation(location.as_ref()),601				|| format!("field <{}> initializtion", name.clone()),602				|| throw!(DuplicateFieldName(name.clone())),603			)?;604		}605		Ok(())606	}607}608609pub struct ExtendBuilder<'v>(&'v mut ObjValue);610impl<'v> ObjMemberBuilder<ExtendBuilder<'v>> {611	pub fn value(self, value: Val) {612		self.binding(LazyBinding::Bound(Thunk::evaluated(value)));613	}614	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {615		self.binding(LazyBinding::Bindable(Cc::new(bindable)));616	}617	pub fn binding(self, binding: LazyBinding) {618		let (receiver, name, member) = self.build_member(binding);619		let new = receiver.0.clone();620		*receiver.0 = new.extend_with_raw_member(name, member);621	}622}
after · crates/jrsonnet-evaluator/src/obj.rs
1use std::{2	cell::RefCell,3	fmt::Debug,4	hash::{Hash, Hasher},5	ptr::addr_of,6};78use jrsonnet_gcmodule::{Cc, Trace, Weak};9use jrsonnet_interner::IStr;10use jrsonnet_parser::{ExprLocation, Visibility};11use rustc_hash::FxHashMap;1213use crate::{14	error::{Error::*, LocError},15	function::CallLocation,16	gc::{GcHashMap, GcHashSet, TraceBox},17	operator::evaluate_add_op,18	throw, LazyBinding, Result, State, Thunk, Unbound, Val,19};2021#[cfg(not(feature = "exp-preserve-order"))]22mod ordering {23	#![allow(24		// This module works as stub for preserve-order feature25		clippy::unused_self,26	)]2728	use jrsonnet_gcmodule::Trace;2930	#[derive(Clone, Copy, Default, Debug, Trace)]31	pub struct FieldIndex;32	impl FieldIndex {33		pub const fn next(self) -> Self {34			Self35		}36	}3738	#[derive(Clone, Copy, Default, Debug, Trace)]39	pub struct SuperDepth;40	impl SuperDepth {41		pub const fn deeper(self) -> Self {42			Self43		}44	}4546	#[derive(Clone, Copy)]47	pub struct FieldSortKey;48	impl FieldSortKey {49		pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {50			Self51		}52	}53}5455#[cfg(feature = "exp-preserve-order")]56mod ordering {57	use std::cmp::Reverse;5859	use jrsonnet_gcmodule::Trace;6061	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]62	pub struct FieldIndex(u32);63	impl FieldIndex {64		pub fn next(self) -> Self {65			Self(self.0 + 1)66		}67	}6869	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]70	pub struct SuperDepth(u32);71	impl SuperDepth {72		pub fn deeper(self) -> Self {73			Self(self.0 + 1)74		}75	}7677	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]78	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);79	impl FieldSortKey {80		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {81			Self(Reverse(depth), index)82		}83		pub fn collide(self, other: Self) -> Self {84			if self.0 .0 > other.0 .0 {85				self86			} else if self.0 .0 < other.0 .0 {87				other88			} else {89				unreachable!("object can't have two fields with same name")90			}91		}92	}93}9495use ordering::*;9697#[allow(clippy::module_name_repetitions)]98#[derive(Debug, Trace)]99pub struct ObjMember {100	pub add: bool,101	pub visibility: Visibility,102	original_index: FieldIndex,103	pub invoke: LazyBinding,104	pub location: Option<ExprLocation>,105}106107pub trait ObjectAssertion: Trace {108	fn run(&self, s: State, super_obj: Option<ObjValue>, this: Option<ObjValue>) -> Result<()>;109}110111// Field => This112type CacheKey = (IStr, WeakObjValue);113114#[derive(Trace)]115enum CacheValue {116	Cached(Val),117	NotFound,118	Pending,119	Errored(LocError),120}121122#[allow(clippy::module_name_repetitions)]123#[derive(Trace)]124#[trace(tracking(force))]125pub struct ObjValueInternals {126	sup: Option<ObjValue>,127	this: Option<ObjValue>,128129	assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,130	assertions_ran: RefCell<GcHashSet<ObjValue>>,131	this_entries: Cc<GcHashMap<IStr, ObjMember>>,132	value_cache: RefCell<GcHashMap<CacheKey, CacheValue>>,133}134135#[derive(Clone, Trace)]136pub struct WeakObjValue(#[trace(skip)] pub(crate) Weak<ObjValueInternals>);137138impl PartialEq for WeakObjValue {139	fn eq(&self, other: &Self) -> bool {140		Weak::ptr_eq(&self.0, &other.0)141	}142}143144impl Eq for WeakObjValue {}145impl Hash for WeakObjValue {146	fn hash<H: Hasher>(&self, hasher: &mut H) {147		// Safety: usize is POD148		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };149		hasher.write_usize(addr);150	}151}152153#[allow(clippy::module_name_repetitions)]154#[derive(Clone, Trace)]155pub struct ObjValue(pub(crate) Cc<ObjValueInternals>);156impl Debug for ObjValue {157	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {158		if let Some(super_obj) = self.0.sup.as_ref() {159			if f.alternate() {160				write!(f, "{:#?}", super_obj)?;161			} else {162				write!(f, "{:?}", super_obj)?;163			}164			write!(f, " + ")?;165		}166		let mut debug = f.debug_struct("ObjValue");167		for (name, member) in self.0.this_entries.iter() {168			debug.field(name, member);169		}170		debug.finish_non_exhaustive()171	}172}173174impl ObjValue {175	pub fn new(176		sup: Option<Self>,177		this_entries: Cc<GcHashMap<IStr, ObjMember>>,178		assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,179	) -> Self {180		Self(Cc::new(ObjValueInternals {181			sup,182			this: None,183			assertions,184			assertions_ran: RefCell::new(GcHashSet::new()),185			this_entries,186			value_cache: RefCell::new(GcHashMap::new()),187		}))188	}189	pub fn new_empty() -> Self {190		Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))191	}192	#[must_use]193	pub fn extend_from(&self, sup: Self) -> Self {194		match &self.0.sup {195			None => Self::new(196				Some(sup),197				self.0.this_entries.clone(),198				self.0.assertions.clone(),199			),200			Some(v) => Self::new(201				Some(v.extend_from(sup)),202				self.0.this_entries.clone(),203				self.0.assertions.clone(),204			),205		}206	}207	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {208		let mut new = GcHashMap::with_capacity(1);209		new.insert(key, value);210		Self::new(Some(self), Cc::new(new), Cc::new(Vec::new()))211	}212	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder> {213		ObjMemberBuilder::new(ExtendBuilder(self), name, FieldIndex::default())214	}215216	#[must_use]217	pub fn with_this(&self, this: Self) -> Self {218		Self(Cc::new(ObjValueInternals {219			sup: self.0.sup.clone(),220			assertions: self.0.assertions.clone(),221			assertions_ran: RefCell::new(GcHashSet::new()),222			this: Some(this),223			this_entries: self.0.this_entries.clone(),224			value_cache: RefCell::new(GcHashMap::new()),225		}))226	}227228	pub fn len(&self) -> usize {229		self.fields_visibility()230			.into_iter()231			.filter(|(_, (visible, _))| *visible)232			.count()233	}234235	pub fn is_empty(&self) -> bool {236		if !self.0.this_entries.is_empty() {237			return false;238		}239		self.0.sup.as_ref().map_or(true, Self::is_empty)240	}241242	/// Run callback for every field found in object243	pub(crate) fn enum_fields(244		&self,245		depth: SuperDepth,246		handler: &mut impl FnMut(SuperDepth, &IStr, &ObjMember) -> bool,247	) -> bool {248		if let Some(s) = &self.0.sup {249			if s.enum_fields(depth.deeper(), handler) {250				return true;251			}252		}253		for (name, member) in self.0.this_entries.iter() {254			if handler(depth, name, member) {255				return true;256			}257		}258		false259	}260261	pub fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {262		let mut out = FxHashMap::default();263		self.enum_fields(SuperDepth::default(), &mut |depth, name, member| {264			let new_sort_key = FieldSortKey::new(depth, member.original_index);265			let entry = out.entry(name.clone());266			let (visible, _) = entry.or_insert((true, new_sort_key));267			match member.visibility {268				Visibility::Normal => {}269				Visibility::Hidden => {270					*visible = false;271				}272				Visibility::Unhide => {273					*visible = true;274				}275			};276			false277		});278		out279	}280	pub fn fields_ex(281		&self,282		include_hidden: bool,283		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,284	) -> Vec<IStr> {285		#[cfg(feature = "exp-preserve-order")]286		if preserve_order {287			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self288				.fields_visibility()289				.into_iter()290				.filter(|(_, (visible, _))| include_hidden || *visible)291				.enumerate()292				.map(|(idx, (k, (_, sk)))| (k, (sk, idx)))293				.unzip();294			keys.sort_unstable_by_key(|v| v.0);295			// Reorder in-place by resulting indexes296			for i in 0..fields.len() {297				let x = fields[i].clone();298				let mut j = i;299				loop {300					let k = keys[j].1;301					keys[j].1 = j;302					if k == i {303						break;304					}305					fields[j] = fields[k].clone();306					j = k307				}308				fields[j] = x;309			}310			return fields;311		}312313		let mut fields: Vec<_> = self314			.fields_visibility()315			.into_iter()316			.filter(|(_, (visible, _))| include_hidden || *visible)317			.map(|(k, _)| k)318			.collect();319		fields.sort_unstable();320		fields321	}322	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {323		self.fields_ex(324			false,325			#[cfg(feature = "exp-preserve-order")]326			preserve_order,327		)328	}329330	pub fn field_visibility(&self, name: IStr) -> Option<Visibility> {331		if let Some(m) = self.0.this_entries.get(&name) {332			Some(match &m.visibility {333				Visibility::Normal => self334					.0335					.sup336					.as_ref()337					.and_then(|super_obj| super_obj.field_visibility(name))338					.unwrap_or(Visibility::Normal),339				v => *v,340			})341		} else if let Some(super_obj) = &self.0.sup {342			super_obj.field_visibility(name)343		} else {344			None345		}346	}347348	fn has_field_include_hidden(&self, name: IStr) -> bool {349		if self.0.this_entries.contains_key(&name) {350			true351		} else if let Some(super_obj) = &self.0.sup {352			super_obj.has_field_include_hidden(name)353		} else {354			false355		}356	}357358	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {359		if include_hidden {360			self.has_field_include_hidden(name)361		} else {362			self.has_field(name)363		}364	}365	pub fn has_field(&self, name: IStr) -> bool {366		self.field_visibility(name)367			.map_or(false, |v| v.is_visible())368	}369370	pub fn get(&self, s: State, key: IStr) -> Result<Option<Val>> {371		self.run_assertions(s.clone())?;372		self.get_raw(s, key, self.0.this.clone().unwrap_or_else(|| self.clone()))373	}374375	// pub fn extend_with(self, key: )376377	fn get_raw(&self, s: State, key: IStr, real_this: Self) -> Result<Option<Val>> {378		let cache_key = (key.clone(), WeakObjValue(real_this.0.downgrade()));379380		if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {381			return Ok(match v {382				CacheValue::Cached(v) => Some(v.clone()),383				CacheValue::NotFound => None,384				CacheValue::Pending => throw!(InfiniteRecursionDetected),385				CacheValue::Errored(e) => return Err(e.clone()),386			});387		}388		self.0389			.value_cache390			.borrow_mut()391			.insert(cache_key.clone(), CacheValue::Pending);392		let fill_error = |e: LocError| {393			self.0394				.value_cache395				.borrow_mut()396				.insert(cache_key.clone(), CacheValue::Errored(e.clone()));397			e398		};399		let value = match (self.0.this_entries.get(&key), &self.0.sup) {400			(Some(k), None) => Ok(Some(401				self.evaluate_this(s, k, real_this).map_err(fill_error)?,402			)),403			(Some(k), Some(super_obj)) => {404				let our = self405					.evaluate_this(s.clone(), k, real_this.clone())406					.map_err(fill_error)?;407				if k.add {408					super_obj409						.get_raw(s.clone(), key, real_this)410						.map_err(fill_error)?411						.map_or(Ok(Some(our.clone())), |v| {412							Ok(Some(evaluate_add_op(s.clone(), &v, &our)?))413						})414				} else {415					Ok(Some(our))416				}417			}418			(None, Some(super_obj)) => super_obj.get_raw(s, key, real_this),419			(None, None) => Ok(None),420		}421		.map_err(fill_error)?;422		self.0.value_cache.borrow_mut().insert(423			cache_key,424			match &value {425				Some(v) => CacheValue::Cached(v.clone()),426				None => CacheValue::NotFound,427			},428		);429		Ok(value)430	}431	fn evaluate_this(&self, s: State, v: &ObjMember, real_this: Self) -> Result<Val> {432		v.invoke433			.evaluate(s.clone(), self.0.sup.clone(), Some(real_this))?434			.evaluate(s)435	}436437	fn run_assertions_raw(&self, s: State, real_this: &Self) -> Result<()> {438		if self.0.assertions_ran.borrow_mut().insert(real_this.clone()) {439			for assertion in self.0.assertions.iter() {440				if let Err(e) =441					assertion.run(s.clone(), self.0.sup.clone(), Some(real_this.clone()))442				{443					self.0.assertions_ran.borrow_mut().remove(real_this);444					return Err(e);445				}446			}447			if let Some(super_obj) = &self.0.sup {448				super_obj.run_assertions_raw(s, real_this)?;449			}450		}451		Ok(())452	}453	pub fn run_assertions(&self, s: State) -> Result<()> {454		self.run_assertions_raw(s, self)455	}456457	pub fn ptr_eq(a: &Self, b: &Self) -> bool {458		Cc::ptr_eq(&a.0, &b.0)459	}460	pub fn downgrade(self) -> WeakObjValue {461		WeakObjValue(self.0.downgrade())462	}463}464465impl PartialEq for ObjValue {466	fn eq(&self, other: &Self) -> bool {467		Cc::ptr_eq(&self.0, &other.0)468	}469}470471impl Eq for ObjValue {}472impl Hash for ObjValue {473	fn hash<H: Hasher>(&self, hasher: &mut H) {474		hasher.write_usize(addr_of!(*self.0) as usize);475	}476}477478#[allow(clippy::module_name_repetitions)]479pub struct ObjValueBuilder {480	sup: Option<ObjValue>,481	map: GcHashMap<IStr, ObjMember>,482	assertions: Vec<TraceBox<dyn ObjectAssertion>>,483	next_field_index: FieldIndex,484}485impl ObjValueBuilder {486	pub fn new() -> Self {487		Self::with_capacity(0)488	}489	pub fn with_capacity(capacity: usize) -> Self {490		Self {491			sup: None,492			map: GcHashMap::with_capacity(capacity),493			assertions: Vec::new(),494			next_field_index: FieldIndex::default(),495		}496	}497	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {498		self.assertions.reserve_exact(capacity);499		self500	}501	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {502		self.sup = Some(super_obj);503		self504	}505506	pub fn assert(&mut self, assertion: TraceBox<dyn ObjectAssertion>) -> &mut Self {507		self.assertions.push(assertion);508		self509	}510	pub fn member(&mut self, name: IStr) -> ObjMemberBuilder<ValueBuilder> {511		let field_index = self.next_field_index;512		self.next_field_index = self.next_field_index.next();513		ObjMemberBuilder::new(ValueBuilder(self), name, field_index)514	}515516	pub fn build(self) -> ObjValue {517		ObjValue::new(self.sup, Cc::new(self.map), Cc::new(self.assertions))518	}519}520impl Default for ObjValueBuilder {521	fn default() -> Self {522		Self::with_capacity(0)523	}524}525526#[allow(clippy::module_name_repetitions)]527#[must_use = "value not added unless binding() was called"]528pub struct ObjMemberBuilder<Kind> {529	kind: Kind,530	name: IStr,531	add: bool,532	visibility: Visibility,533	original_index: FieldIndex,534	location: Option<ExprLocation>,535}536537#[allow(clippy::missing_const_for_fn)]538impl<Kind> ObjMemberBuilder<Kind> {539	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {540		Self {541			kind,542			name,543			original_index,544			add: false,545			visibility: Visibility::Normal,546			location: None,547		}548	}549550	pub const fn with_add(mut self, add: bool) -> Self {551		self.add = add;552		self553	}554	pub fn add(self) -> Self {555		self.with_add(true)556	}557	pub fn with_visibility(mut self, visibility: Visibility) -> Self {558		self.visibility = visibility;559		self560	}561	pub fn hide(self) -> Self {562		self.with_visibility(Visibility::Hidden)563	}564	pub fn with_location(mut self, location: ExprLocation) -> Self {565		self.location = Some(location);566		self567	}568	fn build_member(self, binding: LazyBinding) -> (Kind, IStr, ObjMember) {569		(570			self.kind,571			self.name,572			ObjMember {573				add: self.add,574				visibility: self.visibility,575				original_index: self.original_index,576				invoke: binding,577				location: self.location,578			},579		)580	}581}582583pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);584impl<'v> ObjMemberBuilder<ValueBuilder<'v>> {585	pub fn value(self, s: State, value: Val) -> Result<()> {586		self.binding(s, LazyBinding::Bound(Thunk::evaluated(value)))587	}588	pub fn bindable(589		self,590		s: State,591		bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>,592	) -> Result<()> {593		self.binding(s, LazyBinding::Bindable(Cc::new(bindable)))594	}595	pub fn binding(self, s: State, binding: LazyBinding) -> Result<()> {596		let (receiver, name, member) = self.build_member(binding);597		let location = member.location.clone();598		let old = receiver.0.map.insert(name.clone(), member);599		if old.is_some() {600			s.push(601				CallLocation(location.as_ref()),602				|| format!("field <{}> initializtion", name.clone()),603				|| throw!(DuplicateFieldName(name.clone())),604			)?;605		}606		Ok(())607	}608}609610pub struct ExtendBuilder<'v>(&'v mut ObjValue);611impl<'v> ObjMemberBuilder<ExtendBuilder<'v>> {612	pub fn value(self, value: Val) {613		self.binding(LazyBinding::Bound(Thunk::evaluated(value)));614	}615	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {616		self.binding(LazyBinding::Bindable(Cc::new(bindable)));617	}618	pub fn binding(self, binding: LazyBinding) {619		let (receiver, name, member) = self.build_member(binding);620		let new = receiver.0.clone();621		*receiver.0 = new.extend_with_raw_member(name, member);622	}623}
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -1,7 +1,7 @@
 //! faster std.format impl
 #![allow(clippy::too_many_arguments)]
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_types::ValType;
 use thiserror::Error;
modifiedcrates/jrsonnet-evaluator/src/stdlib/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/mod.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/mod.rs
@@ -4,7 +4,7 @@
 use std::collections::HashMap;
 
 use format::{format_arr, format_obj};
-use gcmodule::Cc;
+use jrsonnet_gcmodule::Cc;
 use jrsonnet_interner::{IBytes, IStr};
 use serde::Deserialize;
 use serde_yaml::DeserializingQuirks;
modifiedcrates/jrsonnet-evaluator/src/stdlib/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/sort.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/sort.rs
@@ -1,4 +1,4 @@
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 
 use crate::{
 	error::{Error, LocError, Result},
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -1,6 +1,6 @@
 use std::ops::Deref;
 
-use gcmodule::Cc;
+use jrsonnet_gcmodule::Cc;
 use jrsonnet_interner::{IBytes, IStr};
 pub use jrsonnet_macros::Typed;
 use jrsonnet_types::{ComplexValType, ValType};
modifiedcrates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -2,7 +2,7 @@
 
 mod conversions;
 pub use conversions::*;
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 pub use jrsonnet_types::{ComplexValType, ValType};
 use thiserror::Error;
 
@@ -16,7 +16,7 @@
 	#[error("expected {0}, got {1}")]
 	ExpectedGot(ComplexValType, ValType),
 	#[error("missing property {0} from {1}")]
-	MissingProperty(#[skip_trace] Rc<str>, ComplexValType),
+	MissingProperty(#[trace(skip)] Rc<str>, ComplexValType),
 	#[error("every failed from {0}:\n{1}")]
 	UnionFailed(ComplexValType, TypeLocErrorList),
 	#[error(
@@ -119,7 +119,7 @@
 
 #[derive(Clone, Debug, Trace)]
 enum ValuePathItem {
-	Field(#[skip_trace] Rc<str>),
+	Field(#[trace(skip)] Rc<str>),
 	Index(u64),
 }
 impl Display for ValuePathItem {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -1,11 +1,10 @@
 use std::{cell::RefCell, fmt::Debug, rc::Rc};
 
-use gcmodule::{Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::{IBytes, IStr};
 use jrsonnet_types::ValType;
 
 use crate::{
-	cc_ptr_eq,
 	error::{Error::*, LocError},
 	function::FuncVal,
 	gc::{GcHashMap, TraceBox},
@@ -21,7 +20,7 @@
 }
 
 #[derive(Trace)]
-enum ThunkInner<T> {
+enum ThunkInner<T: Trace> {
 	Computed(T),
 	Errored(LocError),
 	Waiting(TraceBox<dyn ThunkValue<Output = T>>),
@@ -30,7 +29,7 @@
 
 #[allow(clippy::module_name_repetitions)]
 #[derive(Clone, Trace)]
-pub struct Thunk<T>(Cc<RefCell<ThunkInner<T>>>);
+pub struct Thunk<T: Trace>(Cc<RefCell<ThunkInner<T>>>);
 
 impl<T> Thunk<T>
 where
@@ -78,6 +77,7 @@
 pub struct CachedUnbound<I, T>
 where
 	I: Unbound<Bound = T>,
+	T: Trace,
 {
 	cache: Cc<RefCell<GcHashMap<CacheKey, T>>>,
 	value: I,
@@ -113,14 +113,14 @@
 	}
 }
 
-impl<T: Debug> Debug for Thunk<T> {
+impl<T: Debug + Trace> Debug for Thunk<T> {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		write!(f, "Lazy")
 	}
 }
-impl<T> PartialEq for Thunk<T> {
+impl<T: Trace> PartialEq for Thunk<T> {
 	fn eq(&self, other: &Self) -> bool {
-		cc_ptr_eq(&self.0, &other.0)
+		Cc::ptr_eq(&self.0, &other.0)
 	}
 }
 
@@ -185,9 +185,10 @@
 }
 
 #[derive(Debug, Clone, Trace)]
-#[force_tracking]
+// may contrain other ArrValue
+#[trace(tracking(force))]
 pub enum ArrValue {
-	Bytes(#[skip_trace] IBytes),
+	Bytes(#[trace(skip)] IBytes),
 	Lazy(Cc<Vec<Thunk<Val>>>),
 	Eager(Cc<Vec<Val>>),
 	Extended(Box<(Self, Self)>),
@@ -434,8 +435,8 @@
 
 	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		match (a, b) {
-			(Self::Lazy(a), Self::Lazy(b)) => cc_ptr_eq(a, b),
-			(Self::Eager(a), Self::Eager(b)) => cc_ptr_eq(a, b),
+			(Self::Lazy(a), Self::Lazy(b)) => Cc::ptr_eq(a, b),
+			(Self::Eager(a), Self::Eager(b)) => Cc::ptr_eq(a, b),
 			_ => false,
 		}
 	}
modifiedcrates/jrsonnet-evaluator/tests/builtin.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/tests/builtin.rs
+++ b/crates/jrsonnet-evaluator/tests/builtin.rs
@@ -1,6 +1,5 @@
 mod common;
 
-use gcmodule::Cc;
 use jrsonnet_evaluator::{
 	error::Result,
 	function::{builtin, builtin::Builtin, CallLocation, FuncVal},
@@ -8,6 +7,7 @@
 	typed::Typed,
 	State, Val,
 };
+use jrsonnet_gcmodule::Cc;
 
 #[builtin]
 fn a() -> Result<u32> {
modifiedcrates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -11,7 +11,8 @@
 serde = ["dep:serde"]
 
 [dependencies]
+jrsonnet-gcmodule = { version = "0.3.4" }
+
 serde = { version = "1.0", optional = true }
 rustc-hash = "1.1"
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
 hashbrown = { version = "0.12.1", features = ["inline-more"] }
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -13,8 +13,8 @@
 	str,
 };
 
-use gcmodule::Trace;
 use hashbrown::HashMap;
+use jrsonnet_gcmodule::Trace;
 use rustc_hash::FxHasher;
 
 mod inner;
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -342,7 +342,7 @@
 		#fun
 		#[doc(hidden)]
 		#[allow(non_camel_case_types)]
-		#[derive(Clone, gcmodule::Trace #static_derive_copy)]
+		#[derive(Clone, jrsonnet_gcmodule::Trace #static_derive_copy)]
 		#vis struct #name {
 			#(#fields)*
 		}
modifiedcrates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -11,12 +11,13 @@
 
 [dependencies]
 jrsonnet-interner = { path = "../jrsonnet-interner", version = "0.4.2" }
+jrsonnet-gcmodule = { version = "0.3.4" }
+
 static_assertions = "1.1.0"
 
 peg = "0.8.0"
 
 serde = { version = "1.0", features = ["derive", "rc"], optional = true }
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
 
 [dev-dependencies]
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.4.2" }
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -4,7 +4,7 @@
 	rc::Rc,
 };
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 #[cfg(feature = "serde")]
 use serde::{Deserialize, Serialize};
@@ -359,7 +359,7 @@
 /// file, begin offset, end offset
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[derive(Clone, PartialEq, Eq, Trace)]
-#[skip_trace]
+#[trace(skip)]
 #[repr(C)]
 pub struct ExprLocation(pub Source, pub u32, pub u32);
 impl ExprLocation {
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/source.rs
+++ b/crates/jrsonnet-parser/src/source.rs
@@ -5,7 +5,7 @@
 	rc::Rc,
 };
 
-use gcmodule::{Trace, Tracer};
+use jrsonnet_gcmodule::{Trace, Tracer};
 #[cfg(feature = "serde")]
 use serde::{Deserialize, Serialize};
 
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -7,5 +7,6 @@
 edition = "2021"
 
 [dependencies]
+jrsonnet-gcmodule = { version = "0.3.4" }
+
 peg = "0.8.0"
-gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -2,7 +2,7 @@
 
 use std::fmt::Display;
 
-use gcmodule::Trace;
+use jrsonnet_gcmodule::Trace;
 
 #[macro_export]
 macro_rules! ty {
@@ -115,7 +115,7 @@
 }
 
 #[derive(Debug, Clone, PartialEq, Trace)]
-#[skip_trace]
+#[trace(skip)]
 pub enum ComplexValType {
 	Any,
 	Char,