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
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -5,18 +5,17 @@
 	ptr::addr_of,
 };
 
-use gcmodule::{Cc, Trace, Weak};
+use jrsonnet_gcmodule::{Cc, Trace, Weak};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ExprLocation, Visibility};
 use rustc_hash::FxHashMap;
 
 use crate::{
-	cc_ptr_eq,
 	error::{Error::*, LocError},
 	function::CallLocation,
 	gc::{GcHashMap, GcHashSet, TraceBox},
 	operator::evaluate_add_op,
-	throw, weak_ptr_eq, weak_raw, LazyBinding, Result, State, Thunk, Unbound, Val,
+	throw, LazyBinding, Result, State, Thunk, Unbound, Val,
 };
 
 #[cfg(not(feature = "exp-preserve-order"))]
@@ -26,7 +25,7 @@
 		clippy::unused_self,
 	)]
 
-	use gcmodule::Trace;
+	use jrsonnet_gcmodule::Trace;
 
 	#[derive(Clone, Copy, Default, Debug, Trace)]
 	pub struct FieldIndex;
@@ -57,7 +56,7 @@
 mod ordering {
 	use std::cmp::Reverse;
 
-	use gcmodule::Trace;
+	use jrsonnet_gcmodule::Trace;
 
 	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
 	pub struct FieldIndex(u32);
@@ -122,7 +121,7 @@
 
 #[allow(clippy::module_name_repetitions)]
 #[derive(Trace)]
-#[force_tracking]
+#[trace(tracking(force))]
 pub struct ObjValueInternals {
 	sup: Option<ObjValue>,
 	this: Option<ObjValue>,
@@ -134,18 +133,20 @@
 }
 
 #[derive(Clone, Trace)]
-pub struct WeakObjValue(#[skip_trace] pub(crate) Weak<ObjValueInternals>);
+pub struct WeakObjValue(#[trace(skip)] pub(crate) Weak<ObjValueInternals>);
 
 impl PartialEq for WeakObjValue {
 	fn eq(&self, other: &Self) -> bool {
-		weak_ptr_eq(self.0.clone(), other.0.clone())
+		Weak::ptr_eq(&self.0, &other.0)
 	}
 }
 
 impl Eq for WeakObjValue {}
 impl Hash for WeakObjValue {
 	fn hash<H: Hasher>(&self, hasher: &mut H) {
-		hasher.write_usize(weak_raw(self.0.clone()) as usize);
+		// Safety: usize is POD
+		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };
+		hasher.write_usize(addr);
 	}
 }
 
@@ -454,7 +455,7 @@
 	}
 
 	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
-		cc_ptr_eq(&a.0, &b.0)
+		Cc::ptr_eq(&a.0, &b.0)
 	}
 	pub fn downgrade(self) -> WeakObjValue {
 		WeakObjValue(self.0.downgrade())
@@ -463,7 +464,7 @@
 
 impl PartialEq for ObjValue {
 	fn eq(&self, other: &Self) -> bool {
-		cc_ptr_eq(&self.0, &other.0)
+		Cc::ptr_eq(&self.0, &other.0)
 	}
 }
 
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/stdlib/format.rs
1//! faster std.format impl2#![allow(clippy::too_many_arguments)]34use gcmodule::Trace;5use jrsonnet_interner::IStr;6use jrsonnet_types::ValType;7use thiserror::Error;89use crate::{error::Error::*, throw, typed::Typed, LocError, ObjValue, Result, State, Val};1011#[derive(Debug, Clone, Error, Trace)]12pub enum FormatError {13	#[error("truncated format code")]14	TruncatedFormatCode,15	#[error("unrecognized conversion type: {0}")]16	UnrecognizedConversionType(char),1718	#[error("not enough values")]19	NotEnoughValues,2021	#[error("cannot use * width with object")]22	CannotUseStarWidthWithObject,23	#[error("mapping keys required")]24	MappingKeysRequired,25	#[error("no such format field: {0}")]26	NoSuchFormatField(IStr),27}2829impl From<FormatError> for LocError {30	fn from(e: FormatError) -> Self {31		Self::new(Format(e))32	}33}3435use FormatError::*;3637type ParseResult<'t, T> = std::result::Result<(T, &'t str), FormatError>;3839pub fn try_parse_mapping_key(str: &str) -> ParseResult<&str> {40	if str.is_empty() {41		return Err(TruncatedFormatCode);42	}43	let bytes = str.as_bytes();44	if bytes[0] == b'(' {45		let mut i = 1;46		while i < bytes.len() {47			if bytes[i] == b')' {48				return Ok((&str[1..i as usize], &str[i as usize + 1..]));49			}50			i += 1;51		}52		Err(TruncatedFormatCode)53	} else {54		Ok(("", str))55	}56}5758#[cfg(test)]59pub mod tests_key {60	use super::*;6162	#[test]63	fn parse_key() {64		assert_eq!(65			try_parse_mapping_key("(hello ) world").unwrap(),66			("hello ", " world")67		);68		assert_eq!(try_parse_mapping_key("() world").unwrap(), ("", " world"));69		assert_eq!(try_parse_mapping_key(" world").unwrap(), ("", " world"));70		assert_eq!(71			try_parse_mapping_key(" () world").unwrap(),72			("", " () world")73		);74	}7576	#[test]77	#[should_panic]78	fn parse_key_missing_start() {79		try_parse_mapping_key("").unwrap();80	}8182	#[test]83	#[should_panic]84	fn parse_key_missing_end() {85		try_parse_mapping_key("(   ").unwrap();86	}87}8889#[allow(clippy::struct_excessive_bools)]90#[derive(Default, Debug)]91pub struct CFlags {92	pub alt: bool,93	pub zero: bool,94	pub left: bool,95	pub blank: bool,96	pub sign: bool,97}9899pub fn try_parse_cflags(str: &str) -> ParseResult<CFlags> {100	if str.is_empty() {101		return Err(TruncatedFormatCode);102	}103	let bytes = str.as_bytes();104	let mut i = 0;105	let mut out = CFlags::default();106	loop {107		if bytes.len() == i {108			return Err(TruncatedFormatCode);109		}110		match bytes[i] {111			b'#' => out.alt = true,112			b'0' => out.zero = true,113			b'-' => out.left = true,114			b' ' => out.blank = true,115			b'+' => out.sign = true,116			_ => break,117		}118		i += 1;119	}120	Ok((out, &str[i..]))121}122123#[derive(Debug, PartialEq, Eq)]124pub enum Width {125	Star,126	Fixed(usize),127}128pub fn try_parse_field_width(str: &str) -> ParseResult<Width> {129	if str.is_empty() {130		return Err(TruncatedFormatCode);131	}132	let bytes = str.as_bytes();133	if bytes[0] == b'*' {134		return Ok((Width::Star, &str[1..]));135	}136	let mut out: usize = 0;137	let mut digits = 0;138	while let Some(digit) = (bytes[digits] as char).to_digit(10) {139		out *= 10;140		out += digit as usize;141		digits += 1;142		if digits == bytes.len() {143			return Err(TruncatedFormatCode);144		}145	}146	Ok((Width::Fixed(out), &str[digits..]))147}148149pub fn try_parse_precision(str: &str) -> ParseResult<Option<Width>> {150	if str.is_empty() {151		return Err(TruncatedFormatCode);152	}153	let bytes = str.as_bytes();154	if bytes[0] == b'.' {155		try_parse_field_width(&str[1..]).map(|(r, s)| (Some(r), s))156	} else {157		Ok((None, str))158	}159}160161// Only skips162pub fn try_parse_length_modifier(str: &str) -> ParseResult<()> {163	if str.is_empty() {164		return Err(TruncatedFormatCode);165	}166	let bytes = str.as_bytes();167	let mut idx = 0;168	while bytes[idx] == b'h' || bytes[idx] == b'l' || bytes[idx] == b'L' {169		idx += 1;170		if bytes.len() == idx {171			return Err(TruncatedFormatCode);172		}173	}174	Ok(((), &str[idx..]))175}176177#[derive(Debug, PartialEq, Eq)]178pub enum ConvTypeV {179	Decimal,180	Octal,181	Hexadecimal,182	Scientific,183	Float,184	Shorter,185	Char,186	String,187	Percent,188}189pub struct ConvType {190	v: ConvTypeV,191	caps: bool,192}193194pub fn parse_conversion_type(str: &str) -> ParseResult<ConvType> {195	if str.is_empty() {196		return Err(TruncatedFormatCode);197	}198199	let code = str.as_bytes()[0];200	let v: (ConvTypeV, bool) = match code {201		b'd' | b'i' | b'u' => (ConvTypeV::Decimal, false),202		b'o' => (ConvTypeV::Octal, false),203		b'x' => (ConvTypeV::Hexadecimal, false),204		b'X' => (ConvTypeV::Hexadecimal, true),205		b'e' => (ConvTypeV::Scientific, false),206		b'E' => (ConvTypeV::Scientific, true),207		b'f' => (ConvTypeV::Float, false),208		b'F' => (ConvTypeV::Float, true),209		b'g' => (ConvTypeV::Shorter, false),210		b'G' => (ConvTypeV::Shorter, true),211		b'c' => (ConvTypeV::Char, false),212		b's' => (ConvTypeV::String, false),213		b'%' => (ConvTypeV::Percent, false),214		c => return Err(UnrecognizedConversionType(c as char)),215	};216217	Ok((ConvType { v: v.0, caps: v.1 }, &str[1..]))218}219220#[derive(Debug)]221pub struct Code<'s> {222	mkey: &'s str,223	cflags: CFlags,224	width: Width,225	precision: Option<Width>,226	convtype: ConvTypeV,227	caps: bool,228}229pub fn parse_code(str: &str) -> ParseResult<Code> {230	if str.is_empty() {231		return Err(TruncatedFormatCode);232	}233	let (mkey, str) = try_parse_mapping_key(str)?;234	let (cflags, str) = try_parse_cflags(str)?;235	let (width, str) = try_parse_field_width(str)?;236	let (precision, str) = try_parse_precision(str)?;237	let (_, str) = try_parse_length_modifier(str)?;238	let (convtype, str) = parse_conversion_type(str)?;239240	Ok((241		Code {242			mkey,243			cflags,244			width,245			precision,246			convtype: convtype.v,247			caps: convtype.caps,248		},249		str,250	))251}252253#[derive(Debug)]254pub enum Element<'s> {255	String(&'s str),256	Code(Code<'s>),257}258pub fn parse_codes(mut str: &str) -> Result<Vec<Element>> {259	let mut bytes = str.as_bytes();260	let mut out = vec![];261	let mut offset = 0;262263	loop {264		while offset != bytes.len() && bytes[offset] != b'%' {265			offset += 1;266		}267		if offset != 0 {268			out.push(Element::String(&str[0..offset]));269		}270		if offset == bytes.len() {271			return Ok(out);272		}273		str = &str[offset + 1..];274		let code;275		(code, str) = parse_code(str)?;276		bytes = str.as_bytes();277		offset = 0;278279		out.push(Element::Code(code));280	}281}282283const NUMBERS: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";284285#[inline]286pub fn render_integer(287	out: &mut String,288	iv: i64,289	padding: usize,290	precision: usize,291	blank: bool,292	sign: bool,293	radix: i64,294	prefix: &str,295	caps: bool,296) {297	// Digit char indexes in reverse order, i.e298	// for radix = 16 and n = 12f: [15, 2, 1]299	let digits = if iv == 0 {300		vec![0u8]301	} else {302		let mut v = iv.abs();303		let mut nums = Vec::with_capacity(1);304		while v > 0 {305			nums.push((v % radix) as u8);306			v /= radix;307		}308		nums309	};310	let neg = iv < 0;311	let zp = padding.saturating_sub(if neg || blank || sign { 1 } else { 0 });312	let zp2 = zp313		.max(precision)314		.saturating_sub(prefix.len() + digits.len());315316	if neg {317		out.push('-');318	} else if sign {319		out.push('+');320	} else if blank {321		out.push(' ');322	}323324	out.reserve(zp2);325	for _ in 0..zp2 {326		out.push('0');327	}328	out.push_str(prefix);329330	for digit in digits.into_iter().rev() {331		let ch = NUMBERS[digit as usize] as char;332		out.push(if caps { ch.to_ascii_uppercase() } else { ch });333	}334}335336pub fn render_decimal(337	out: &mut String,338	iv: i64,339	padding: usize,340	precision: usize,341	blank: bool,342	sign: bool,343) {344	render_integer(out, iv, padding, precision, blank, sign, 10, "", false);345}346pub fn render_octal(347	out: &mut String,348	iv: i64,349	padding: usize,350	precision: usize,351	alt: bool,352	blank: bool,353	sign: bool,354) {355	render_integer(356		out,357		iv,358		padding,359		precision,360		blank,361		sign,362		8,363		if alt && iv != 0 { "0" } else { "" },364		false,365	);366}367368#[allow(clippy::fn_params_excessive_bools)]369pub fn render_hexadecimal(370	out: &mut String,371	iv: i64,372	padding: usize,373	precision: usize,374	alt: bool,375	blank: bool,376	sign: bool,377	caps: bool,378) {379	render_integer(380		out,381		iv,382		padding,383		precision,384		blank,385		sign,386		16,387		match (alt, caps) {388			(true, true) => "0X",389			(true, false) => "0x",390			(false, _) => "",391		},392		caps,393	);394}395396#[allow(clippy::fn_params_excessive_bools)]397pub fn render_float(398	out: &mut String,399	n: f64,400	mut padding: usize,401	precision: usize,402	blank: bool,403	sign: bool,404	ensure_pt: bool,405	trailing: bool,406) {407	let dot_size = if precision == 0 && !ensure_pt { 0 } else { 1 };408	padding = padding.saturating_sub(dot_size + precision);409	render_decimal(out, n.floor() as i64, padding, 0, blank, sign);410	if precision == 0 {411		if ensure_pt {412			out.push('.');413		}414		return;415	}416	let frac = n417		.fract()418		.mul_add(10.0_f64.powf(precision as f64), 0.5)419		.floor();420	if trailing || frac > 0.0 {421		out.push('.');422		let mut frac_str = String::new();423		render_decimal(&mut frac_str, frac as i64, precision, 0, false, false);424		let mut trim = frac_str.len();425		if !trailing {426			for b in frac_str.as_bytes().iter().rev() {427				if *b == b'0' {428					trim -= 1;429				}430			}431		}432		out.push_str(&frac_str[..trim]);433	} else if ensure_pt {434		out.push('.');435	}436}437438#[allow(clippy::fn_params_excessive_bools)]439pub fn render_float_sci(440	out: &mut String,441	n: f64,442	mut padding: usize,443	precision: usize,444	blank: bool,445	sign: bool,446	ensure_pt: bool,447	trailing: bool,448	caps: bool,449) {450	let exponent = n.log10().floor();451	let mantissa = if exponent as i16 == -324 {452		n * 10.0 / 10.0_f64.powf(exponent + 1.0)453	} else {454		n / 10.0_f64.powf(exponent)455	};456	let mut exponent_str = String::new();457	render_decimal(&mut exponent_str, exponent as i64, 3, 0, false, true);458459	// +1 for e460	padding = padding.saturating_sub(exponent_str.len() + 1);461462	render_float(463		out, mantissa, padding, precision, blank, sign, ensure_pt, trailing,464	);465	out.push(if caps { 'E' } else { 'e' });466	out.push_str(&exponent_str);467}468469#[allow(clippy::too_many_lines)]470pub fn format_code(471	s: State,472	out: &mut String,473	value: &Val,474	code: &Code,475	width: usize,476	precision: Option<usize>,477) -> Result<()> {478	let clfags = &code.cflags;479	let (fpprec, iprec) = match precision {480		Some(v) => (v, v),481		None => (6, 0),482	};483	let padding = if clfags.zero && !clfags.left {484		width485	} else {486		0487	};488489	// TODO: If left padded, can optimize by writing directly to out490	let mut tmp_out = String::new();491492	match code.convtype {493		ConvTypeV::String => tmp_out.push_str(&value.clone().to_string(s)?),494		ConvTypeV::Decimal => {495			let value = f64::from_untyped(value.clone(), s)?;496			render_decimal(497				&mut tmp_out,498				value as i64,499				padding,500				iprec,501				clfags.blank,502				clfags.sign,503			);504		}505		ConvTypeV::Octal => {506			let value = f64::from_untyped(value.clone(), s)?;507			render_octal(508				&mut tmp_out,509				value as i64,510				padding,511				iprec,512				clfags.alt,513				clfags.blank,514				clfags.sign,515			);516		}517		ConvTypeV::Hexadecimal => {518			let value = f64::from_untyped(value.clone(), s)?;519			render_hexadecimal(520				&mut tmp_out,521				value as i64,522				padding,523				iprec,524				clfags.alt,525				clfags.blank,526				clfags.sign,527				code.caps,528			);529		}530		ConvTypeV::Scientific => {531			let value = f64::from_untyped(value.clone(), s)?;532			render_float_sci(533				&mut tmp_out,534				value,535				padding,536				fpprec,537				clfags.blank,538				clfags.sign,539				clfags.alt,540				true,541				code.caps,542			);543		}544		ConvTypeV::Float => {545			let value = f64::from_untyped(value.clone(), s)?;546			render_float(547				&mut tmp_out,548				value,549				padding,550				fpprec,551				clfags.blank,552				clfags.sign,553				clfags.alt,554				true,555			);556		}557		ConvTypeV::Shorter => {558			let value = f64::from_untyped(value.clone(), s)?;559			let exponent = value.log10().floor();560			if exponent < -4.0 || exponent >= fpprec as f64 {561				render_float_sci(562					&mut tmp_out,563					value,564					padding,565					fpprec - 1,566					clfags.blank,567					clfags.sign,568					clfags.alt,569					clfags.alt,570					code.caps,571				);572			} else {573				let digits_before_pt = 1.max(exponent as usize + 1);574				render_float(575					&mut tmp_out,576					value,577					padding,578					fpprec - digits_before_pt,579					clfags.blank,580					clfags.sign,581					clfags.alt,582					clfags.alt,583				);584			}585		}586		ConvTypeV::Char => match value.clone() {587			Val::Num(n) => tmp_out588				.push(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?),589			Val::Str(s) => {590				if s.chars().count() != 1 {591					throw!(RuntimeError(592						format!("%c expected 1 char string, got {}", s.chars().count()).into(),593					));594				}595				tmp_out.push_str(&s);596			}597			_ => {598				throw!(TypeMismatch(599					"%c requires number/string",600					vec![ValType::Num, ValType::Str],601					value.value_type(),602				));603			}604		},605		ConvTypeV::Percent => tmp_out.push('%'),606	};607608	let padding = width.saturating_sub(tmp_out.len());609610	if !clfags.left {611		for _ in 0..padding {612			out.push(' ');613		}614	}615	out.push_str(&tmp_out);616	if clfags.left {617		for _ in 0..padding {618			out.push(' ');619		}620	}621622	Ok(())623}624625pub fn format_arr(s: State, str: &str, mut values: &[Val]) -> Result<String> {626	let codes = parse_codes(str)?;627	let mut out = String::new();628629	for code in codes {630		match code {631			Element::String(s) => {632				out.push_str(s);633			}634			Element::Code(c) => {635				let width = match c.width {636					Width::Star => {637						if values.is_empty() {638							throw!(NotEnoughValues);639						}640						let value = &values[0];641						values = &values[1..];642						usize::from_untyped(value.clone(), s.clone())?643					}644					Width::Fixed(n) => n,645				};646				let precision = match c.precision {647					Some(Width::Star) => {648						if values.is_empty() {649							throw!(NotEnoughValues);650						}651						let value = &values[0];652						values = &values[1..];653						Some(usize::from_untyped(value.clone(), s.clone())?)654					}655					Some(Width::Fixed(n)) => Some(n),656					None => None,657				};658659				// %% should not consume a value660				let value = if c.convtype == ConvTypeV::Percent {661					&Val::Null662				} else {663					if values.is_empty() {664						throw!(NotEnoughValues);665					}666					let value = &values[0];667					values = &values[1..];668					value669				};670671				format_code(s.clone(), &mut out, value, &c, width, precision)?;672			}673		}674	}675676	Ok(out)677}678679pub fn format_obj(s: State, str: &str, values: &ObjValue) -> Result<String> {680	let codes = parse_codes(str)?;681	let mut out = String::new();682683	for code in codes {684		match code {685			Element::String(s) => {686				out.push_str(s);687			}688			Element::Code(c) => {689				// TODO: Operate on ref690				let f: IStr = c.mkey.into();691				let width = match c.width {692					Width::Star => {693						throw!(CannotUseStarWidthWithObject);694					}695					Width::Fixed(n) => n,696				};697				let precision = match c.precision {698					Some(Width::Star) => {699						throw!(CannotUseStarWidthWithObject);700					}701					Some(Width::Fixed(n)) => Some(n),702					None => None,703				};704705				let value = if c.convtype == ConvTypeV::Percent {706					Val::Null707				} else {708					if f.is_empty() {709						throw!(MappingKeysRequired);710					}711					if let Some(v) = values.get(s.clone(), f.clone())? {712						v713					} else {714						throw!(NoSuchFormatField(f));715					}716				};717718				format_code(s.clone(), &mut out, &value, &c, width, precision)?;719			}720		}721	}722723	Ok(out)724}725726#[cfg(test)]727pub mod test_format {728	use super::*;729730	#[test]731	fn parse() {732		assert_eq!(733			parse_codes(734				"How much error budget is left looking at our %.3f%% availability gurantees?"735			)736			.unwrap()737			.len(),738			4739		);740	}741742	#[test]743	fn octals() {744		let s = State::default();745		assert_eq!(746			format_arr(s.clone(), "%#o", &[Val::Num(8.0)]).unwrap(),747			"010"748		);749		assert_eq!(750			format_arr(s.clone(), "%#4o", &[Val::Num(8.0)]).unwrap(),751			" 010"752		);753		assert_eq!(754			format_arr(s.clone(), "%4o", &[Val::Num(8.0)]).unwrap(),755			"  10"756		);757		assert_eq!(758			format_arr(s.clone(), "%04o", &[Val::Num(8.0)]).unwrap(),759			"0010"760		);761		assert_eq!(762			format_arr(s.clone(), "%+4o", &[Val::Num(8.0)]).unwrap(),763			" +10"764		);765		assert_eq!(766			format_arr(s.clone(), "%+04o", &[Val::Num(8.0)]).unwrap(),767			"+010"768		);769		assert_eq!(770			format_arr(s.clone(), "%-4o", &[Val::Num(8.0)]).unwrap(),771			"10  "772		);773		assert_eq!(774			format_arr(s.clone(), "%+-4o", &[Val::Num(8.0)]).unwrap(),775			"+10 "776		);777		assert_eq!(778			format_arr(s.clone(), "%+-04o", &[Val::Num(8.0)]).unwrap(),779			"+10 "780		);781	}782783	#[test]784	fn percent_doesnt_consumes_values() {785		let s = State::default();786		assert_eq!(787			format_arr(788				s,789				"How much error budget is left looking at our %.3f%% availability gurantees?",790				&[Val::Num(4.0)]791			)792			.unwrap(),793			"How much error budget is left looking at our 4.000% availability gurantees?"794		);795	}796}
after · crates/jrsonnet-evaluator/src/stdlib/format.rs
1//! faster std.format impl2#![allow(clippy::too_many_arguments)]34use jrsonnet_gcmodule::Trace;5use jrsonnet_interner::IStr;6use jrsonnet_types::ValType;7use thiserror::Error;89use crate::{error::Error::*, throw, typed::Typed, LocError, ObjValue, Result, State, Val};1011#[derive(Debug, Clone, Error, Trace)]12pub enum FormatError {13	#[error("truncated format code")]14	TruncatedFormatCode,15	#[error("unrecognized conversion type: {0}")]16	UnrecognizedConversionType(char),1718	#[error("not enough values")]19	NotEnoughValues,2021	#[error("cannot use * width with object")]22	CannotUseStarWidthWithObject,23	#[error("mapping keys required")]24	MappingKeysRequired,25	#[error("no such format field: {0}")]26	NoSuchFormatField(IStr),27}2829impl From<FormatError> for LocError {30	fn from(e: FormatError) -> Self {31		Self::new(Format(e))32	}33}3435use FormatError::*;3637type ParseResult<'t, T> = std::result::Result<(T, &'t str), FormatError>;3839pub fn try_parse_mapping_key(str: &str) -> ParseResult<&str> {40	if str.is_empty() {41		return Err(TruncatedFormatCode);42	}43	let bytes = str.as_bytes();44	if bytes[0] == b'(' {45		let mut i = 1;46		while i < bytes.len() {47			if bytes[i] == b')' {48				return Ok((&str[1..i as usize], &str[i as usize + 1..]));49			}50			i += 1;51		}52		Err(TruncatedFormatCode)53	} else {54		Ok(("", str))55	}56}5758#[cfg(test)]59pub mod tests_key {60	use super::*;6162	#[test]63	fn parse_key() {64		assert_eq!(65			try_parse_mapping_key("(hello ) world").unwrap(),66			("hello ", " world")67		);68		assert_eq!(try_parse_mapping_key("() world").unwrap(), ("", " world"));69		assert_eq!(try_parse_mapping_key(" world").unwrap(), ("", " world"));70		assert_eq!(71			try_parse_mapping_key(" () world").unwrap(),72			("", " () world")73		);74	}7576	#[test]77	#[should_panic]78	fn parse_key_missing_start() {79		try_parse_mapping_key("").unwrap();80	}8182	#[test]83	#[should_panic]84	fn parse_key_missing_end() {85		try_parse_mapping_key("(   ").unwrap();86	}87}8889#[allow(clippy::struct_excessive_bools)]90#[derive(Default, Debug)]91pub struct CFlags {92	pub alt: bool,93	pub zero: bool,94	pub left: bool,95	pub blank: bool,96	pub sign: bool,97}9899pub fn try_parse_cflags(str: &str) -> ParseResult<CFlags> {100	if str.is_empty() {101		return Err(TruncatedFormatCode);102	}103	let bytes = str.as_bytes();104	let mut i = 0;105	let mut out = CFlags::default();106	loop {107		if bytes.len() == i {108			return Err(TruncatedFormatCode);109		}110		match bytes[i] {111			b'#' => out.alt = true,112			b'0' => out.zero = true,113			b'-' => out.left = true,114			b' ' => out.blank = true,115			b'+' => out.sign = true,116			_ => break,117		}118		i += 1;119	}120	Ok((out, &str[i..]))121}122123#[derive(Debug, PartialEq, Eq)]124pub enum Width {125	Star,126	Fixed(usize),127}128pub fn try_parse_field_width(str: &str) -> ParseResult<Width> {129	if str.is_empty() {130		return Err(TruncatedFormatCode);131	}132	let bytes = str.as_bytes();133	if bytes[0] == b'*' {134		return Ok((Width::Star, &str[1..]));135	}136	let mut out: usize = 0;137	let mut digits = 0;138	while let Some(digit) = (bytes[digits] as char).to_digit(10) {139		out *= 10;140		out += digit as usize;141		digits += 1;142		if digits == bytes.len() {143			return Err(TruncatedFormatCode);144		}145	}146	Ok((Width::Fixed(out), &str[digits..]))147}148149pub fn try_parse_precision(str: &str) -> ParseResult<Option<Width>> {150	if str.is_empty() {151		return Err(TruncatedFormatCode);152	}153	let bytes = str.as_bytes();154	if bytes[0] == b'.' {155		try_parse_field_width(&str[1..]).map(|(r, s)| (Some(r), s))156	} else {157		Ok((None, str))158	}159}160161// Only skips162pub fn try_parse_length_modifier(str: &str) -> ParseResult<()> {163	if str.is_empty() {164		return Err(TruncatedFormatCode);165	}166	let bytes = str.as_bytes();167	let mut idx = 0;168	while bytes[idx] == b'h' || bytes[idx] == b'l' || bytes[idx] == b'L' {169		idx += 1;170		if bytes.len() == idx {171			return Err(TruncatedFormatCode);172		}173	}174	Ok(((), &str[idx..]))175}176177#[derive(Debug, PartialEq, Eq)]178pub enum ConvTypeV {179	Decimal,180	Octal,181	Hexadecimal,182	Scientific,183	Float,184	Shorter,185	Char,186	String,187	Percent,188}189pub struct ConvType {190	v: ConvTypeV,191	caps: bool,192}193194pub fn parse_conversion_type(str: &str) -> ParseResult<ConvType> {195	if str.is_empty() {196		return Err(TruncatedFormatCode);197	}198199	let code = str.as_bytes()[0];200	let v: (ConvTypeV, bool) = match code {201		b'd' | b'i' | b'u' => (ConvTypeV::Decimal, false),202		b'o' => (ConvTypeV::Octal, false),203		b'x' => (ConvTypeV::Hexadecimal, false),204		b'X' => (ConvTypeV::Hexadecimal, true),205		b'e' => (ConvTypeV::Scientific, false),206		b'E' => (ConvTypeV::Scientific, true),207		b'f' => (ConvTypeV::Float, false),208		b'F' => (ConvTypeV::Float, true),209		b'g' => (ConvTypeV::Shorter, false),210		b'G' => (ConvTypeV::Shorter, true),211		b'c' => (ConvTypeV::Char, false),212		b's' => (ConvTypeV::String, false),213		b'%' => (ConvTypeV::Percent, false),214		c => return Err(UnrecognizedConversionType(c as char)),215	};216217	Ok((ConvType { v: v.0, caps: v.1 }, &str[1..]))218}219220#[derive(Debug)]221pub struct Code<'s> {222	mkey: &'s str,223	cflags: CFlags,224	width: Width,225	precision: Option<Width>,226	convtype: ConvTypeV,227	caps: bool,228}229pub fn parse_code(str: &str) -> ParseResult<Code> {230	if str.is_empty() {231		return Err(TruncatedFormatCode);232	}233	let (mkey, str) = try_parse_mapping_key(str)?;234	let (cflags, str) = try_parse_cflags(str)?;235	let (width, str) = try_parse_field_width(str)?;236	let (precision, str) = try_parse_precision(str)?;237	let (_, str) = try_parse_length_modifier(str)?;238	let (convtype, str) = parse_conversion_type(str)?;239240	Ok((241		Code {242			mkey,243			cflags,244			width,245			precision,246			convtype: convtype.v,247			caps: convtype.caps,248		},249		str,250	))251}252253#[derive(Debug)]254pub enum Element<'s> {255	String(&'s str),256	Code(Code<'s>),257}258pub fn parse_codes(mut str: &str) -> Result<Vec<Element>> {259	let mut bytes = str.as_bytes();260	let mut out = vec![];261	let mut offset = 0;262263	loop {264		while offset != bytes.len() && bytes[offset] != b'%' {265			offset += 1;266		}267		if offset != 0 {268			out.push(Element::String(&str[0..offset]));269		}270		if offset == bytes.len() {271			return Ok(out);272		}273		str = &str[offset + 1..];274		let code;275		(code, str) = parse_code(str)?;276		bytes = str.as_bytes();277		offset = 0;278279		out.push(Element::Code(code));280	}281}282283const NUMBERS: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";284285#[inline]286pub fn render_integer(287	out: &mut String,288	iv: i64,289	padding: usize,290	precision: usize,291	blank: bool,292	sign: bool,293	radix: i64,294	prefix: &str,295	caps: bool,296) {297	// Digit char indexes in reverse order, i.e298	// for radix = 16 and n = 12f: [15, 2, 1]299	let digits = if iv == 0 {300		vec![0u8]301	} else {302		let mut v = iv.abs();303		let mut nums = Vec::with_capacity(1);304		while v > 0 {305			nums.push((v % radix) as u8);306			v /= radix;307		}308		nums309	};310	let neg = iv < 0;311	let zp = padding.saturating_sub(if neg || blank || sign { 1 } else { 0 });312	let zp2 = zp313		.max(precision)314		.saturating_sub(prefix.len() + digits.len());315316	if neg {317		out.push('-');318	} else if sign {319		out.push('+');320	} else if blank {321		out.push(' ');322	}323324	out.reserve(zp2);325	for _ in 0..zp2 {326		out.push('0');327	}328	out.push_str(prefix);329330	for digit in digits.into_iter().rev() {331		let ch = NUMBERS[digit as usize] as char;332		out.push(if caps { ch.to_ascii_uppercase() } else { ch });333	}334}335336pub fn render_decimal(337	out: &mut String,338	iv: i64,339	padding: usize,340	precision: usize,341	blank: bool,342	sign: bool,343) {344	render_integer(out, iv, padding, precision, blank, sign, 10, "", false);345}346pub fn render_octal(347	out: &mut String,348	iv: i64,349	padding: usize,350	precision: usize,351	alt: bool,352	blank: bool,353	sign: bool,354) {355	render_integer(356		out,357		iv,358		padding,359		precision,360		blank,361		sign,362		8,363		if alt && iv != 0 { "0" } else { "" },364		false,365	);366}367368#[allow(clippy::fn_params_excessive_bools)]369pub fn render_hexadecimal(370	out: &mut String,371	iv: i64,372	padding: usize,373	precision: usize,374	alt: bool,375	blank: bool,376	sign: bool,377	caps: bool,378) {379	render_integer(380		out,381		iv,382		padding,383		precision,384		blank,385		sign,386		16,387		match (alt, caps) {388			(true, true) => "0X",389			(true, false) => "0x",390			(false, _) => "",391		},392		caps,393	);394}395396#[allow(clippy::fn_params_excessive_bools)]397pub fn render_float(398	out: &mut String,399	n: f64,400	mut padding: usize,401	precision: usize,402	blank: bool,403	sign: bool,404	ensure_pt: bool,405	trailing: bool,406) {407	let dot_size = if precision == 0 && !ensure_pt { 0 } else { 1 };408	padding = padding.saturating_sub(dot_size + precision);409	render_decimal(out, n.floor() as i64, padding, 0, blank, sign);410	if precision == 0 {411		if ensure_pt {412			out.push('.');413		}414		return;415	}416	let frac = n417		.fract()418		.mul_add(10.0_f64.powf(precision as f64), 0.5)419		.floor();420	if trailing || frac > 0.0 {421		out.push('.');422		let mut frac_str = String::new();423		render_decimal(&mut frac_str, frac as i64, precision, 0, false, false);424		let mut trim = frac_str.len();425		if !trailing {426			for b in frac_str.as_bytes().iter().rev() {427				if *b == b'0' {428					trim -= 1;429				}430			}431		}432		out.push_str(&frac_str[..trim]);433	} else if ensure_pt {434		out.push('.');435	}436}437438#[allow(clippy::fn_params_excessive_bools)]439pub fn render_float_sci(440	out: &mut String,441	n: f64,442	mut padding: usize,443	precision: usize,444	blank: bool,445	sign: bool,446	ensure_pt: bool,447	trailing: bool,448	caps: bool,449) {450	let exponent = n.log10().floor();451	let mantissa = if exponent as i16 == -324 {452		n * 10.0 / 10.0_f64.powf(exponent + 1.0)453	} else {454		n / 10.0_f64.powf(exponent)455	};456	let mut exponent_str = String::new();457	render_decimal(&mut exponent_str, exponent as i64, 3, 0, false, true);458459	// +1 for e460	padding = padding.saturating_sub(exponent_str.len() + 1);461462	render_float(463		out, mantissa, padding, precision, blank, sign, ensure_pt, trailing,464	);465	out.push(if caps { 'E' } else { 'e' });466	out.push_str(&exponent_str);467}468469#[allow(clippy::too_many_lines)]470pub fn format_code(471	s: State,472	out: &mut String,473	value: &Val,474	code: &Code,475	width: usize,476	precision: Option<usize>,477) -> Result<()> {478	let clfags = &code.cflags;479	let (fpprec, iprec) = match precision {480		Some(v) => (v, v),481		None => (6, 0),482	};483	let padding = if clfags.zero && !clfags.left {484		width485	} else {486		0487	};488489	// TODO: If left padded, can optimize by writing directly to out490	let mut tmp_out = String::new();491492	match code.convtype {493		ConvTypeV::String => tmp_out.push_str(&value.clone().to_string(s)?),494		ConvTypeV::Decimal => {495			let value = f64::from_untyped(value.clone(), s)?;496			render_decimal(497				&mut tmp_out,498				value as i64,499				padding,500				iprec,501				clfags.blank,502				clfags.sign,503			);504		}505		ConvTypeV::Octal => {506			let value = f64::from_untyped(value.clone(), s)?;507			render_octal(508				&mut tmp_out,509				value as i64,510				padding,511				iprec,512				clfags.alt,513				clfags.blank,514				clfags.sign,515			);516		}517		ConvTypeV::Hexadecimal => {518			let value = f64::from_untyped(value.clone(), s)?;519			render_hexadecimal(520				&mut tmp_out,521				value as i64,522				padding,523				iprec,524				clfags.alt,525				clfags.blank,526				clfags.sign,527				code.caps,528			);529		}530		ConvTypeV::Scientific => {531			let value = f64::from_untyped(value.clone(), s)?;532			render_float_sci(533				&mut tmp_out,534				value,535				padding,536				fpprec,537				clfags.blank,538				clfags.sign,539				clfags.alt,540				true,541				code.caps,542			);543		}544		ConvTypeV::Float => {545			let value = f64::from_untyped(value.clone(), s)?;546			render_float(547				&mut tmp_out,548				value,549				padding,550				fpprec,551				clfags.blank,552				clfags.sign,553				clfags.alt,554				true,555			);556		}557		ConvTypeV::Shorter => {558			let value = f64::from_untyped(value.clone(), s)?;559			let exponent = value.log10().floor();560			if exponent < -4.0 || exponent >= fpprec as f64 {561				render_float_sci(562					&mut tmp_out,563					value,564					padding,565					fpprec - 1,566					clfags.blank,567					clfags.sign,568					clfags.alt,569					clfags.alt,570					code.caps,571				);572			} else {573				let digits_before_pt = 1.max(exponent as usize + 1);574				render_float(575					&mut tmp_out,576					value,577					padding,578					fpprec - digits_before_pt,579					clfags.blank,580					clfags.sign,581					clfags.alt,582					clfags.alt,583				);584			}585		}586		ConvTypeV::Char => match value.clone() {587			Val::Num(n) => tmp_out588				.push(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?),589			Val::Str(s) => {590				if s.chars().count() != 1 {591					throw!(RuntimeError(592						format!("%c expected 1 char string, got {}", s.chars().count()).into(),593					));594				}595				tmp_out.push_str(&s);596			}597			_ => {598				throw!(TypeMismatch(599					"%c requires number/string",600					vec![ValType::Num, ValType::Str],601					value.value_type(),602				));603			}604		},605		ConvTypeV::Percent => tmp_out.push('%'),606	};607608	let padding = width.saturating_sub(tmp_out.len());609610	if !clfags.left {611		for _ in 0..padding {612			out.push(' ');613		}614	}615	out.push_str(&tmp_out);616	if clfags.left {617		for _ in 0..padding {618			out.push(' ');619		}620	}621622	Ok(())623}624625pub fn format_arr(s: State, str: &str, mut values: &[Val]) -> Result<String> {626	let codes = parse_codes(str)?;627	let mut out = String::new();628629	for code in codes {630		match code {631			Element::String(s) => {632				out.push_str(s);633			}634			Element::Code(c) => {635				let width = match c.width {636					Width::Star => {637						if values.is_empty() {638							throw!(NotEnoughValues);639						}640						let value = &values[0];641						values = &values[1..];642						usize::from_untyped(value.clone(), s.clone())?643					}644					Width::Fixed(n) => n,645				};646				let precision = match c.precision {647					Some(Width::Star) => {648						if values.is_empty() {649							throw!(NotEnoughValues);650						}651						let value = &values[0];652						values = &values[1..];653						Some(usize::from_untyped(value.clone(), s.clone())?)654					}655					Some(Width::Fixed(n)) => Some(n),656					None => None,657				};658659				// %% should not consume a value660				let value = if c.convtype == ConvTypeV::Percent {661					&Val::Null662				} else {663					if values.is_empty() {664						throw!(NotEnoughValues);665					}666					let value = &values[0];667					values = &values[1..];668					value669				};670671				format_code(s.clone(), &mut out, value, &c, width, precision)?;672			}673		}674	}675676	Ok(out)677}678679pub fn format_obj(s: State, str: &str, values: &ObjValue) -> Result<String> {680	let codes = parse_codes(str)?;681	let mut out = String::new();682683	for code in codes {684		match code {685			Element::String(s) => {686				out.push_str(s);687			}688			Element::Code(c) => {689				// TODO: Operate on ref690				let f: IStr = c.mkey.into();691				let width = match c.width {692					Width::Star => {693						throw!(CannotUseStarWidthWithObject);694					}695					Width::Fixed(n) => n,696				};697				let precision = match c.precision {698					Some(Width::Star) => {699						throw!(CannotUseStarWidthWithObject);700					}701					Some(Width::Fixed(n)) => Some(n),702					None => None,703				};704705				let value = if c.convtype == ConvTypeV::Percent {706					Val::Null707				} else {708					if f.is_empty() {709						throw!(MappingKeysRequired);710					}711					if let Some(v) = values.get(s.clone(), f.clone())? {712						v713					} else {714						throw!(NoSuchFormatField(f));715					}716				};717718				format_code(s.clone(), &mut out, &value, &c, width, precision)?;719			}720		}721	}722723	Ok(out)724}725726#[cfg(test)]727pub mod test_format {728	use super::*;729730	#[test]731	fn parse() {732		assert_eq!(733			parse_codes(734				"How much error budget is left looking at our %.3f%% availability gurantees?"735			)736			.unwrap()737			.len(),738			4739		);740	}741742	#[test]743	fn octals() {744		let s = State::default();745		assert_eq!(746			format_arr(s.clone(), "%#o", &[Val::Num(8.0)]).unwrap(),747			"010"748		);749		assert_eq!(750			format_arr(s.clone(), "%#4o", &[Val::Num(8.0)]).unwrap(),751			" 010"752		);753		assert_eq!(754			format_arr(s.clone(), "%4o", &[Val::Num(8.0)]).unwrap(),755			"  10"756		);757		assert_eq!(758			format_arr(s.clone(), "%04o", &[Val::Num(8.0)]).unwrap(),759			"0010"760		);761		assert_eq!(762			format_arr(s.clone(), "%+4o", &[Val::Num(8.0)]).unwrap(),763			" +10"764		);765		assert_eq!(766			format_arr(s.clone(), "%+04o", &[Val::Num(8.0)]).unwrap(),767			"+010"768		);769		assert_eq!(770			format_arr(s.clone(), "%-4o", &[Val::Num(8.0)]).unwrap(),771			"10  "772		);773		assert_eq!(774			format_arr(s.clone(), "%+-4o", &[Val::Num(8.0)]).unwrap(),775			"+10 "776		);777		assert_eq!(778			format_arr(s.clone(), "%+-04o", &[Val::Num(8.0)]).unwrap(),779			"+10 "780		);781	}782783	#[test]784	fn percent_doesnt_consumes_values() {785		let s = State::default();786		assert_eq!(787			format_arr(788				s,789				"How much error budget is left looking at our %.3f%% availability gurantees?",790				&[Val::Num(4.0)]791			)792			.unwrap(),793			"How much error budget is left looking at our 4.000% availability gurantees?"794		);795	}796}
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,