difftreelog
build switch to released gcmodule fork
in: master
38 files changed
Cargo.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"
bindings/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"]
bindings/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 {
bindings/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
///
bindings/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
///
cmds/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" }
cmds/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)?;
crates/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"] }
crates/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())
}
}
crates/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"
crates/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)
}
}
crates/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>>>);
crates/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>,
},
crates/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};
crates/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,
}
crates/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};
crates/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};
crates/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>>),
}
crates/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};
crates/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);
crates/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));
}
crates/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>>,
crates/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)
}
}
crates/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;
crates/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;
crates/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},
crates/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};
crates/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 {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth1use std::{cell::RefCell, fmt::Debug, rc::Rc};23use gcmodule::{Cc, Trace};4use jrsonnet_interner::{IBytes, IStr};5use jrsonnet_types::ValType;67use crate::{8 cc_ptr_eq,9 error::{Error::*, LocError},10 function::FuncVal,11 gc::{GcHashMap, TraceBox},12 stdlib::manifest::{13 manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,14 },15 throw, ObjValue, Result, State, Unbound, WeakObjValue,16};1718pub trait ThunkValue: Trace {19 type Output;20 fn get(self: Box<Self>, s: State) -> Result<Self::Output>;21}2223#[derive(Trace)]24enum ThunkInner<T> {25 Computed(T),26 Errored(LocError),27 Waiting(TraceBox<dyn ThunkValue<Output = T>>),28 Pending,29}3031#[allow(clippy::module_name_repetitions)]32#[derive(Clone, Trace)]33pub struct Thunk<T>(Cc<RefCell<ThunkInner<T>>>);3435impl<T> Thunk<T>36where37 T: Clone + Trace,38{39 pub fn new(f: TraceBox<dyn ThunkValue<Output = T>>) -> Self {40 Self(Cc::new(RefCell::new(ThunkInner::Waiting(f))))41 }42 pub fn evaluated(val: T) -> Self {43 Self(Cc::new(RefCell::new(ThunkInner::Computed(val))))44 }45 pub fn force(&self, s: State) -> Result<()> {46 self.evaluate(s)?;47 Ok(())48 }49 pub fn evaluate(&self, s: State) -> Result<T> {50 match &*self.0.borrow() {51 ThunkInner::Computed(v) => return Ok(v.clone()),52 ThunkInner::Errored(e) => return Err(e.clone()),53 ThunkInner::Pending => return Err(InfiniteRecursionDetected.into()),54 ThunkInner::Waiting(..) => (),55 };56 let value = if let ThunkInner::Waiting(value) =57 std::mem::replace(&mut *self.0.borrow_mut(), ThunkInner::Pending)58 {59 value60 } else {61 unreachable!()62 };63 let new_value = match value.0.get(s) {64 Ok(v) => v,65 Err(e) => {66 *self.0.borrow_mut() = ThunkInner::Errored(e.clone());67 return Err(e);68 }69 };70 *self.0.borrow_mut() = ThunkInner::Computed(new_value.clone());71 Ok(new_value)72 }73}7475type CacheKey = (Option<WeakObjValue>, Option<WeakObjValue>);7677#[derive(Trace, Clone)]78pub struct CachedUnbound<I, T>79where80 I: Unbound<Bound = T>,81{82 cache: Cc<RefCell<GcHashMap<CacheKey, T>>>,83 value: I,84}85impl<I: Unbound<Bound = T>, T: Trace> CachedUnbound<I, T> {86 pub fn new(value: I) -> Self {87 Self {88 cache: Cc::new(RefCell::new(GcHashMap::new())),89 value,90 }91 }92}93impl<I: Unbound<Bound = T>, T: Clone + Trace> Unbound for CachedUnbound<I, T> {94 type Bound = T;95 fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<T> {96 let cache_key = (97 sup.as_ref().map(|s| s.clone().downgrade()),98 this.as_ref().map(|t| t.clone().downgrade()),99 );100 {101 if let Some(t) = self.cache.borrow().get(&cache_key) {102 return Ok(t.clone());103 }104 }105 let bound = self.value.bind(s, sup, this)?;106107 {108 let mut cache = self.cache.borrow_mut();109 cache.insert(cache_key, bound.clone());110 }111112 Ok(bound)113 }114}115116impl<T: Debug> Debug for Thunk<T> {117 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {118 write!(f, "Lazy")119 }120}121impl<T> PartialEq for Thunk<T> {122 fn eq(&self, other: &Self) -> bool {123 cc_ptr_eq(&self.0, &other.0)124 }125}126127#[derive(Clone)]128pub enum ManifestFormat {129 YamlStream(Box<ManifestFormat>),130 Yaml {131 padding: usize,132 #[cfg(feature = "exp-preserve-order")]133 preserve_order: bool,134 },135 Json {136 padding: usize,137 #[cfg(feature = "exp-preserve-order")]138 preserve_order: bool,139 },140 ToString,141 String,142}143impl ManifestFormat {144 #[cfg(feature = "exp-preserve-order")]145 fn preserve_order(&self) -> bool {146 match self {147 ManifestFormat::YamlStream(s) => s.preserve_order(),148 ManifestFormat::Yaml { preserve_order, .. } => *preserve_order,149 ManifestFormat::Json { preserve_order, .. } => *preserve_order,150 ManifestFormat::ToString => false,151 ManifestFormat::String => false,152 }153 }154}155156#[derive(Debug, Clone, Trace)]157pub struct Slice {158 pub(crate) inner: ArrValue,159 pub(crate) from: u32,160 pub(crate) to: u32,161 pub(crate) step: u32,162}163impl Slice {164 const fn from(&self) -> usize {165 self.from as usize166 }167 const fn to(&self) -> usize {168 self.to as usize169 }170 const fn step(&self) -> usize {171 self.step as usize172 }173 const fn len(&self) -> usize {174 // TODO: use div_ceil175 let diff = self.to() - self.from();176 let rem = diff % self.step();177 let div = diff / self.step();178179 if rem == 0 {180 div181 } else {182 div + 1183 }184 }185}186187#[derive(Debug, Clone, Trace)]188#[force_tracking]189pub enum ArrValue {190 Bytes(#[skip_trace] IBytes),191 Lazy(Cc<Vec<Thunk<Val>>>),192 Eager(Cc<Vec<Val>>),193 Extended(Box<(Self, Self)>),194 Range(i32, i32),195 Slice(Box<Slice>),196 Reversed(Box<Self>),197}198199#[cfg(target_pointer_width = "64")]200static_assertions::assert_eq_size!(ArrValue, [u8; 16]);201202impl ArrValue {203 pub fn new_eager() -> Self {204 Self::Eager(Cc::new(Vec::new()))205 }206207 /// # Panics208 /// If a > b209 pub fn new_range(a: i32, b: i32) -> Self {210 assert!(a <= b);211 Self::Range(a, b)212 }213214 /// # Panics215 /// If passed numbers are incorrect216 #[must_use]217 pub fn slice(self, from: Option<usize>, to: Option<usize>, step: Option<usize>) -> Self {218 let len = self.len();219 let from = from.unwrap_or(0);220 let to = to.unwrap_or(len).min(len);221 let step = step.unwrap_or(1);222 assert!(from < to);223 assert!(step > 0);224225 Self::Slice(Box::new(Slice {226 inner: self,227 from: from as u32,228 to: to as u32,229 step: step as u32,230 }))231 }232233 pub fn len(&self) -> usize {234 match self {235 Self::Bytes(i) => i.len(),236 Self::Lazy(l) => l.len(),237 Self::Eager(e) => e.len(),238 Self::Extended(v) => v.0.len() + v.1.len(),239 Self::Range(a, b) => a.abs_diff(*b) as usize + 1,240 Self::Reversed(i) => i.len(),241 Self::Slice(s) => s.len(),242 }243 }244245 pub fn is_empty(&self) -> bool {246 self.len() == 0247 }248249 pub fn get(&self, s: State, index: usize) -> Result<Option<Val>> {250 match self {251 Self::Bytes(i) => i252 .get(index)253 .map_or(Ok(None), |v| Ok(Some(Val::Num(f64::from(*v))))),254 Self::Lazy(vec) => {255 if let Some(v) = vec.get(index) {256 Ok(Some(v.evaluate(s)?))257 } else {258 Ok(None)259 }260 }261 Self::Eager(vec) => Ok(vec.get(index).cloned()),262 Self::Extended(v) => {263 let a_len = v.0.len();264 if a_len > index {265 v.0.get(s, index)266 } else {267 v.1.get(s, index - a_len)268 }269 }270 Self::Range(a, _) => {271 if index >= self.len() {272 return Ok(None);273 }274 Ok(Some(Val::Num(((*a as isize) + index as isize) as f64)))275 }276 Self::Reversed(v) => {277 let len = v.len();278 if index >= len {279 return Ok(None);280 }281 v.get(s, len - index - 1)282 }283 Self::Slice(v) => {284 let index = v.from() + index * v.step();285 if index >= v.to() {286 return Ok(None);287 }288 v.inner.get(s, index as usize)289 }290 }291 }292293 pub fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {294 match self {295 Self::Bytes(i) => i296 .get(index)297 .map(|b| Thunk::evaluated(Val::Num(f64::from(*b)))),298 Self::Lazy(vec) => vec.get(index).cloned(),299 Self::Eager(vec) => vec.get(index).cloned().map(Thunk::evaluated),300 Self::Extended(v) => {301 let a_len = v.0.len();302 if a_len > index {303 v.0.get_lazy(index)304 } else {305 v.1.get_lazy(index - a_len)306 }307 }308 Self::Range(a, _) => {309 if index >= self.len() {310 return None;311 }312 Some(Thunk::evaluated(Val::Num(313 ((*a as isize) + index as isize) as f64,314 )))315 }316 Self::Reversed(v) => {317 let len = v.len();318 if index >= len {319 return None;320 }321 v.get_lazy(len - index - 1)322 }323 Self::Slice(s) => {324 let index = s.from() + index * s.step();325 if index >= s.to() {326 return None;327 }328 s.inner.get_lazy(index as usize)329 }330 }331 }332333 pub fn evaluated(&self, s: State) -> Result<Cc<Vec<Val>>> {334 Ok(match self {335 Self::Bytes(i) => {336 let mut out = Vec::with_capacity(i.len());337 for v in i.iter() {338 out.push(Val::Num(f64::from(*v)));339 }340 Cc::new(out)341 }342 Self::Lazy(vec) => {343 let mut out = Vec::with_capacity(vec.len());344 for item in vec.iter() {345 out.push(item.evaluate(s.clone())?);346 }347 Cc::new(out)348 }349 Self::Eager(vec) => vec.clone(),350 Self::Extended(_v) => {351 let mut out = Vec::with_capacity(self.len());352 for item in self.iter(s) {353 out.push(item?);354 }355 Cc::new(out)356 }357 Self::Range(a, b) => {358 let mut out = Vec::with_capacity(self.len());359 for i in *a..*b {360 out.push(Val::Num(f64::from(i)));361 }362 Cc::new(out)363 }364 Self::Reversed(r) => {365 let mut r = r.evaluated(s)?;366 Cc::update_with(&mut r, |v| v.reverse());367 r368 }369 Self::Slice(v) => {370 let mut out = Vec::with_capacity(v.inner.len());371 for v in v372 .inner373 .iter_lazy()374 .skip(v.from())375 .take(v.to() - v.from())376 .step_by(v.step())377 {378 out.push(v.evaluate(s.clone())?);379 }380 Cc::new(out)381 }382 })383 }384385 pub fn iter(&self, s: State) -> impl DoubleEndedIterator<Item = Result<Val>> + '_ {386 (0..self.len()).map(move |idx| match self {387 Self::Bytes(b) => Ok(Val::Num(f64::from(b[idx]))),388 Self::Lazy(l) => l[idx].evaluate(s.clone()),389 Self::Eager(e) => Ok(e[idx].clone()),390 Self::Extended(..) | Self::Range(..) | Self::Reversed(..) | Self::Slice(..) => {391 self.get(s.clone(), idx).map(|e| e.expect("idx < len"))392 }393 })394 }395396 pub fn iter_lazy(&self) -> impl DoubleEndedIterator<Item = Thunk<Val>> + '_ {397 (0..self.len()).map(move |idx| match self {398 Self::Bytes(b) => Thunk::evaluated(Val::Num(f64::from(b[idx]))),399 Self::Lazy(l) => l[idx].clone(),400 Self::Eager(e) => Thunk::evaluated(e[idx].clone()),401 Self::Slice(..) | Self::Extended(..) | Self::Range(..) | Self::Reversed(..) => {402 self.get_lazy(idx).expect("idx < len")403 }404 })405 }406407 #[must_use]408 pub fn reversed(self) -> Self {409 Self::Reversed(Box::new(self))410 }411412 pub fn map(self, s: State, mapper: impl Fn(Val) -> Result<Val>) -> Result<Self> {413 let mut out = Vec::with_capacity(self.len());414415 for value in self.iter(s) {416 out.push(mapper(value?)?);417 }418419 Ok(Self::Eager(Cc::new(out)))420 }421422 pub fn filter(self, s: State, filter: impl Fn(&Val) -> Result<bool>) -> Result<Self> {423 let mut out = Vec::with_capacity(self.len());424425 for value in self.iter(s) {426 let value = value?;427 if filter(&value)? {428 out.push(value);429 }430 }431432 Ok(Self::Eager(Cc::new(out)))433 }434435 pub fn ptr_eq(a: &Self, b: &Self) -> bool {436 match (a, b) {437 (Self::Lazy(a), Self::Lazy(b)) => cc_ptr_eq(a, b),438 (Self::Eager(a), Self::Eager(b)) => cc_ptr_eq(a, b),439 _ => false,440 }441 }442}443444impl From<Vec<Thunk<Val>>> for ArrValue {445 fn from(v: Vec<Thunk<Val>>) -> Self {446 Self::Lazy(Cc::new(v))447 }448}449450impl From<Vec<Val>> for ArrValue {451 fn from(v: Vec<Val>) -> Self {452 Self::Eager(Cc::new(v))453 }454}455456#[allow(clippy::module_name_repetitions)]457pub enum IndexableVal {458 Str(IStr),459 Arr(ArrValue),460}461462#[derive(Debug, Clone, Trace)]463pub enum Val {464 Bool(bool),465 Null,466 Str(IStr),467 Num(f64),468 Arr(ArrValue),469 Obj(ObjValue),470 Func(FuncVal),471}472473#[cfg(target_pointer_width = "64")]474static_assertions::assert_eq_size!(Val, [u8; 32]);475476impl Val {477 pub const fn as_bool(&self) -> Option<bool> {478 match self {479 Self::Bool(v) => Some(*v),480 _ => None,481 }482 }483 pub const fn as_null(&self) -> Option<()> {484 match self {485 Self::Null => Some(()),486 _ => None,487 }488 }489 pub fn as_str(&self) -> Option<IStr> {490 match self {491 Self::Str(s) => Some(s.clone()),492 _ => None,493 }494 }495 pub const fn as_num(&self) -> Option<f64> {496 match self {497 Self::Num(n) => Some(*n),498 _ => None,499 }500 }501 pub fn as_arr(&self) -> Option<ArrValue> {502 match self {503 Self::Arr(a) => Some(a.clone()),504 _ => None,505 }506 }507 pub fn as_obj(&self) -> Option<ObjValue> {508 match self {509 Self::Obj(o) => Some(o.clone()),510 _ => None,511 }512 }513 pub fn as_func(&self) -> Option<FuncVal> {514 match self {515 Self::Func(f) => Some(f.clone()),516 _ => None,517 }518 }519520 /// Creates `Val::Num` after checking for numeric overflow.521 /// As numbers are `f64`, we can just check for their finity.522 pub fn new_checked_num(num: f64) -> Result<Self> {523 if num.is_finite() {524 Ok(Self::Num(num))525 } else {526 throw!(RuntimeError("overflow".into()))527 }528 }529530 pub const fn value_type(&self) -> ValType {531 match self {532 Self::Str(..) => ValType::Str,533 Self::Num(..) => ValType::Num,534 Self::Arr(..) => ValType::Arr,535 Self::Obj(..) => ValType::Obj,536 Self::Bool(_) => ValType::Bool,537 Self::Null => ValType::Null,538 Self::Func(..) => ValType::Func,539 }540 }541542 pub fn to_string(&self, s: State) -> Result<IStr> {543 Ok(match self {544 Self::Bool(true) => "true".into(),545 Self::Bool(false) => "false".into(),546 Self::Null => "null".into(),547 Self::Str(s) => s.clone(),548 v => manifest_json_ex(549 s,550 v,551 &ManifestJsonOptions {552 padding: "",553 mtype: ManifestType::ToString,554 newline: "\n",555 key_val_sep: ": ",556 #[cfg(feature = "exp-preserve-order")]557 preserve_order: false,558 },559 )?560 .into(),561 })562 }563564 /// Expects value to be object, outputs (key, manifested value) pairs565 pub fn manifest_multi(&self, s: State, ty: &ManifestFormat) -> Result<Vec<(IStr, IStr)>> {566 let obj = match self {567 Self::Obj(obj) => obj,568 _ => throw!(MultiManifestOutputIsNotAObject),569 };570 let keys = obj.fields(571 #[cfg(feature = "exp-preserve-order")]572 ty.preserve_order(),573 );574 let mut out = Vec::with_capacity(keys.len());575 for key in keys {576 let value = obj577 .get(s.clone(), key.clone())?578 .expect("item in object")579 .manifest(s.clone(), ty)?;580 out.push((key, value));581 }582 Ok(out)583 }584585 /// Expects value to be array, outputs manifested values586 pub fn manifest_stream(&self, s: State, ty: &ManifestFormat) -> Result<Vec<IStr>> {587 let arr = match self {588 Self::Arr(a) => a,589 _ => throw!(StreamManifestOutputIsNotAArray),590 };591 let mut out = Vec::with_capacity(arr.len());592 for i in arr.iter(s.clone()) {593 out.push(i?.manifest(s.clone(), ty)?);594 }595 Ok(out)596 }597598 pub fn manifest(&self, s: State, ty: &ManifestFormat) -> Result<IStr> {599 Ok(match ty {600 ManifestFormat::YamlStream(format) => {601 let arr = match self {602 Self::Arr(a) => a,603 _ => throw!(StreamManifestOutputIsNotAArray),604 };605 let mut out = String::new();606607 match format as &ManifestFormat {608 ManifestFormat::YamlStream(_) => throw!(StreamManifestOutputCannotBeRecursed),609 ManifestFormat::String => throw!(StreamManifestCannotNestString),610 _ => {}611 };612613 if !arr.is_empty() {614 for v in arr.iter(s.clone()) {615 out.push_str("---\n");616 out.push_str(&v?.manifest(s.clone(), format)?);617 out.push('\n');618 }619 out.push_str("...");620 }621622 out.into()623 }624 ManifestFormat::Yaml {625 padding,626 #[cfg(feature = "exp-preserve-order")]627 preserve_order,628 } => self.to_yaml(629 s,630 *padding,631 #[cfg(feature = "exp-preserve-order")]632 *preserve_order,633 )?,634 ManifestFormat::Json {635 padding,636 #[cfg(feature = "exp-preserve-order")]637 preserve_order,638 } => self.to_json(639 s,640 *padding,641 #[cfg(feature = "exp-preserve-order")]642 *preserve_order,643 )?,644 ManifestFormat::ToString => self.to_string(s)?,645 ManifestFormat::String => match self {646 Self::Str(s) => s.clone(),647 _ => throw!(StringManifestOutputIsNotAString),648 },649 })650 }651652 /// For manifestification653 pub fn to_json(654 &self,655 s: State,656 padding: usize,657 #[cfg(feature = "exp-preserve-order")] preserve_order: bool,658 ) -> Result<IStr> {659 manifest_json_ex(660 s,661 self,662 &ManifestJsonOptions {663 padding: &" ".repeat(padding),664 mtype: if padding == 0 {665 ManifestType::Minify666 } else {667 ManifestType::Manifest668 },669 newline: "\n",670 key_val_sep: ": ",671 #[cfg(feature = "exp-preserve-order")]672 preserve_order,673 },674 )675 .map(Into::into)676 }677678 /// Calls `std.manifestJson`679 pub fn to_std_json(680 &self,681 s: State,682 padding: usize,683 #[cfg(feature = "exp-preserve-order")] preserve_order: bool,684 ) -> Result<Rc<str>> {685 manifest_json_ex(686 s,687 self,688 &ManifestJsonOptions {689 padding: &" ".repeat(padding),690 mtype: ManifestType::Std,691 newline: "\n",692 key_val_sep: ": ",693 #[cfg(feature = "exp-preserve-order")]694 preserve_order,695 },696 )697 .map(Into::into)698 }699700 pub fn to_yaml(701 &self,702 s: State,703 padding: usize,704 #[cfg(feature = "exp-preserve-order")] preserve_order: bool,705 ) -> Result<IStr> {706 let padding = &" ".repeat(padding);707 manifest_yaml_ex(708 s,709 self,710 &ManifestYamlOptions {711 padding,712 arr_element_padding: padding,713 quote_keys: false,714 #[cfg(feature = "exp-preserve-order")]715 preserve_order,716 },717 )718 .map(Into::into)719 }720 pub fn into_indexable(self) -> Result<IndexableVal> {721 Ok(match self {722 Val::Str(s) => IndexableVal::Str(s),723 Val::Arr(arr) => IndexableVal::Arr(arr),724 _ => throw!(ValueIsNotIndexable(self.value_type())),725 })726 }727}728729const fn is_function_like(val: &Val) -> bool {730 matches!(val, Val::Func(_))731}732733/// Native implementation of `std.primitiveEquals`734pub fn primitive_equals(val_a: &Val, val_b: &Val) -> Result<bool> {735 Ok(match (val_a, val_b) {736 (Val::Bool(a), Val::Bool(b)) => a == b,737 (Val::Null, Val::Null) => true,738 (Val::Str(a), Val::Str(b)) => a == b,739 (Val::Num(a), Val::Num(b)) => (a - b).abs() <= f64::EPSILON,740 (Val::Arr(_), Val::Arr(_)) => throw!(RuntimeError(741 "primitiveEquals operates on primitive types, got array".into(),742 )),743 (Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(744 "primitiveEquals operates on primitive types, got object".into(),745 )),746 (a, b) if is_function_like(a) && is_function_like(b) => {747 throw!(RuntimeError("cannot test equality of functions".into()))748 }749 (_, _) => false,750 })751}752753/// Native implementation of `std.equals`754pub fn equals(s: State, val_a: &Val, val_b: &Val) -> Result<bool> {755 if val_a.value_type() != val_b.value_type() {756 return Ok(false);757 }758 match (val_a, val_b) {759 (Val::Arr(a), Val::Arr(b)) => {760 if ArrValue::ptr_eq(a, b) {761 return Ok(true);762 }763 if a.len() != b.len() {764 return Ok(false);765 }766 for (a, b) in a.iter(s.clone()).zip(b.iter(s.clone())) {767 if !equals(s.clone(), &a?, &b?)? {768 return Ok(false);769 }770 }771 Ok(true)772 }773 (Val::Obj(a), Val::Obj(b)) => {774 if ObjValue::ptr_eq(a, b) {775 return Ok(true);776 }777 let fields = a.fields(778 #[cfg(feature = "exp-preserve-order")]779 false,780 );781 if fields782 != b.fields(783 #[cfg(feature = "exp-preserve-order")]784 false,785 ) {786 return Ok(false);787 }788 for field in fields {789 if !equals(790 s.clone(),791 &a.get(s.clone(), field.clone())?.expect("field exists"),792 &b.get(s.clone(), field)?.expect("field exists"),793 )? {794 return Ok(false);795 }796 }797 Ok(true)798 }799 (a, b) => Ok(primitive_equals(a, b)?),800 }801}crates/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> {
crates/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"] }
crates/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;
crates/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)*
}
crates/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" }
crates/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 {
crates/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};
crates/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" }
crates/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,