difftreelog
perf reimplement AST codegen
in: master
10 files changed
Cargo.lockdiffbeforeafterboth78 packageslockfile v3
Might be heavy and slow!
ahash
0.7.6crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumfcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47used byannotate-snippets
0.9.1crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc3b9d411ecbaf79885c6df4d75fff75858d5995ff25385657a28af47e82f9c36depends onused byanyhow
1.0.57crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdcused byatty
0.2.14crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8depends onused byautocfg
1.1.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97faused bybase64
0.13.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fdused bybincode
1.3.3crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumb1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcaddepends onbitflags
1.3.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718aused bycc
1.0.73crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11used bycfg-if
0.1.10crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822used bycfg-if
1.0.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbaf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fdused byclap
3.2.8crates.io↘ 9↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83depends onclap_complete
3.2.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1depends onused byclap_derive
3.2.7crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902used byclap_lex
0.2.4crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5depends onused bycloudabi
0.0.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4fdepends onused bygetrandom
0.2.6crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205adused byhashbrown
0.11.2crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726eused byhashbrown
0.12.1crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumdb0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3depends onheck
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9used byhermit-abi
0.1.19crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33depends onused byindexmap
1.8.2crates.io↘ 2↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5adepends onitoa
1.0.2crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578dused byjrsonnet
0.4.2workspace↘ 8↖ 0jrsonnet-cli
0.4.2workspace↘ 5↖ 1jrsonnet-evaluator
0.4.2workspace↘ 16↖ 4depends onjrsonnet-gcmodule
0.3.4crates.io↘ 2↖ 8sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum22d4e1572e4b61e4f5deb3701312a330df0e69b48805a540d740e5e53ac8c78ajrsonnet-gcmodule-derive
0.3.4crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumae2f3bf7d38e0a9098b5b9062a7d9e7a97a206bc3c91118d76e7e37f2e0f1202depends onused byjrsonnet-interner
0.4.2workspace↘ 4↖ 2jrsonnet-macros
0.4.2workspace↘ 3↖ 2jrsonnet-parser
0.4.2workspace↘ 6↖ 5jrsonnet-types
0.4.2workspace↘ 2↖ 1depends onused byjsonnet
0.4.2workspace↘ 4↖ 0libc
0.2.126crates.io↘ 0↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836linked-hash-map
0.5.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770fused bylock_api
0.3.4crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75depends onused bymd5
0.7.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771used bymimalloc-sys
0.1.6crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4aa3cefb626f6ae3d0b2f71c5378c89d2b1d4d7bc246b0ca9a7ee61a4daad291depends onused bymimallocator
0.1.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2d44fe4ebf6b538fcf39d9975c2b90bb3232d1ba8e8bffeacd004f27b20c577adepends onused byonce_cell
1.12.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225used byos_str_bytes
6.1.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afaused byparking_lot
0.10.2crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505edepends onused byparking_lot_core
0.7.2crates.io↘ 6↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3used bypathdiff
0.2.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44ddused bypeg
0.8.0crates.io↘ 2↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumaf728fe826811af3b38c37e93de6d104485953ea373d656eebae53d6987fcd2cdepends onpeg-macros
0.8.0crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4536be147b770b824895cbad934fccce8e49f14b4c4946eaa46a6e4a12fcdc16used bypeg-runtime
0.8.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf9b0efd3ba03c3a409d44d60425f279ec442bcf0b9e63ff4e410da31c8b0f69fused byproc-macro-error
1.0.4crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumda25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38cused byproc-macro-error-attr
1.0.4crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869used byproc-macro2
1.0.39crates.io↘ 1↖ 10sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56fdepends onquote
1.0.18crates.io↘ 1↖ 9sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1depends onredox_syscall
0.1.57crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ceused byrustc-hash
1.1.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2ryu
1.0.10crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695scopeguard
1.1.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cdused byserde
1.0.137crates.io↘ 1↖ 7sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1depends onserde_derive
1.0.137crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578bedepends onused byserde_json
1.0.82crates.io↘ 4↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7serde_yaml_with_quirks
0.8.24crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum47c5983eba86eae2d0058c35fb1065ccffb23af7f8965871069269088098321aused bysmallvec
1.8.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83used bystatic_assertions
1.1.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543fstrsim
0.10.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623syn
1.0.96crates.io↘ 3↖ 6sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebftermcolor
1.1.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755depends onused bythiserror
1.0.31crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069adepends onthiserror-impl
1.0.31crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79adepends onused byunicode-ident
1.0.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493eeused byunicode-width
0.1.9crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973used byversion_check
0.9.4crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483fwasi
0.10.2+wasi-snapshot-preview1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumfd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6used bywinapi
0.3.9crates.io↘ 2↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419winapi-i686-pc-windows-gnu
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6used bywinapi-util
0.1.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178depends onused bywinapi-x86_64-pc-windows-gnu
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183fused byyaml-rust
0.4.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85depends onused byyansi-term
0.1.2crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumfe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1depends onused by
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,6 @@
opt-level = 3
lto = "fat"
codegen-units = 1
-debug = 0
+# debug = 0
panic = "abort"
-strip = true
+# strip = true
crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -7,12 +7,19 @@
edition = "2021"
[features]
-default = ["serde"]
+default = []
+# Implement value serialization using structdump
+structdump = ["dep:structdump"]
+# Implement value serialization using serde
+#
+# Warning: serialized values won't be deduplicated
serde = ["dep:serde"]
[dependencies]
jrsonnet-gcmodule = { version = "0.3.4" }
serde = { version = "1.0", optional = true }
+structdump = { version = "0.2.0", optional = true }
+
rustc-hash = "1.1"
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
@@ -205,6 +205,7 @@
}
}
+#[cfg(feature = "serde")]
impl serde::Serialize for IStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -214,6 +215,7 @@
}
}
+#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for IStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -224,6 +226,24 @@
}
}
+#[cfg(feature = "structdump")]
+impl structdump::Codegen for IStr {
+ fn gen_code(
+ &self,
+ res: &mut structdump::CodegenResult,
+ _unique: bool,
+ ) -> structdump::TokenStream {
+ let s: &str = self;
+ res.add_code(
+ structdump::quote! {
+ structdump_import::IStr::from(#s)
+ },
+ Some(structdump::quote![structdump_import::IStr]),
+ false,
+ )
+ }
+}
+
thread_local! {
static POOL: RefCell<HashMap<Inner, (), BuildHasherDefault<FxHasher>>> = RefCell::new(HashMap::with_capacity_and_hasher(200, BuildHasherDefault::default()));
}
crates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -7,7 +7,23 @@
edition = "2021"
[features]
+default = []
exp-destruct = []
+# Implement serialization of AST using structdump
+#
+# Structdump generates code, which exactly replicated passed AST
+# Contrary to serde, has no code bloat problem, and is recommended
+#
+# The only limitation is serialized form is only useable if built from build script
+structdump = ["dep:structdump", "jrsonnet-interner/structdump"]
+# Implement serialization of AST using serde
+#
+# Warning: as serde doesn't deduplicate strings, `Source` struct will bloat
+# output binary with repeating source code. To resolve this issue, you should either
+# override serialization of this struct using custom `Serializer`/`Deserializer`,
+# not rely on Source, and fill its `source_code` with empty value, or use `structdump`
+# instead
+serde = ["dep:serde"]
[dependencies]
jrsonnet-interner = { path = "../jrsonnet-interner", version = "0.4.2" }
@@ -18,6 +34,4 @@
peg = "0.8.0"
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
-
-[dev-dependencies]
-jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.4.2" }
+structdump = { version = "0.2.0", features = ["derive"], optional = true }
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -8,10 +8,13 @@
use jrsonnet_interner::IStr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
+#[cfg(feature = "structdump")]
+use structdump::Codegen;
use crate::source::Source;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[derive(Debug, PartialEq, Trace)]
pub enum FieldName {
/// {fixed: 2}
@@ -20,6 +23,7 @@
Dyn(LocExpr),
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum Visibility {
@@ -37,10 +41,12 @@
}
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Trace)]
pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct FieldMember {
@@ -51,6 +57,7 @@
pub value: LocExpr,
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum Member {
@@ -59,6 +66,7 @@
AssertStmt(AssertStmt),
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum UnaryOpType {
@@ -84,6 +92,7 @@
}
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum BinaryOpType {
@@ -150,11 +159,13 @@
}
/// name, default value
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct Param(pub Destruct, pub Option<LocExpr>);
/// Defined function parameters
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Trace)]
pub struct ParamsDesc(pub Rc<Vec<Param>>);
@@ -166,6 +177,7 @@
}
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct ArgsDesc {
@@ -187,6 +199,7 @@
Drop,
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Trace)]
pub enum Destruct {
@@ -216,6 +229,7 @@
}
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Trace)]
pub enum BindSpec {
@@ -230,14 +244,17 @@
},
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct IfSpecData(pub LocExpr);
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct ForSpecData(pub IStr, pub LocExpr);
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum CompSpec {
@@ -245,6 +262,7 @@
ForSpec(ForSpecData),
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct ObjComp {
@@ -256,6 +274,7 @@
pub compspecs: Vec<CompSpec>,
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum ObjBody {
@@ -263,6 +282,7 @@
ObjComp(ObjComp),
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]
pub enum LiteralType {
@@ -274,6 +294,7 @@
False,
}
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct SliceDesc {
@@ -283,6 +304,7 @@
}
/// Syntax base
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum Expr {
@@ -351,6 +373,7 @@
}
/// file, begin offset, end offset
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Trace)]
#[trace(skip)]
@@ -373,6 +396,7 @@
/// Holds AST expression and its location in source file
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[derive(Clone, PartialEq, Trace)]
pub struct LocExpr(pub Rc<Expr>, pub ExprLocation);
crates/jrsonnet-parser/src/source.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/source.rs
+++ b/crates/jrsonnet-parser/src/source.rs
@@ -9,9 +9,12 @@
use jrsonnet_interner::IStr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
+#[cfg(feature = "structdump")]
+use structdump::Codegen;
use crate::location::{location_to_offset, offset_to_location, CodeLocation};
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
pub enum SourcePath {
@@ -39,9 +42,10 @@
/// Either real file, or virtual
/// Hash of FileName always have same value as raw Path, to make it possible to use with raw_entry_mut
+#[cfg_attr(feature = "structdump", derive(Codegen))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Source(Rc<(SourcePath, IStr)>);
+pub struct Source(pub Rc<(SourcePath, IStr)>);
static_assertions::assert_eq_size!(Source, *const ());
impl Trace for Source {
crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -7,9 +7,10 @@
edition = "2021"
[features]
-default = []
-# Serializes standard library AST, and deserialize on start, instead of parsing it every run from text
-serialized-stdlib = ["bincode", "jrsonnet-parser/serde"]
+default = ["codegenerated-stdlib"]
+# Speed-up initialization by generating code for parsed stdlib, instead
+# of invoking parser for it
+codegenerated-stdlib = ["jrsonnet-parser/structdump"]
# Enables legacy `std.thisFile` support, at the cost of worse caching
legacy-this-file = []
# Add order preservation flag to some functions
@@ -45,8 +46,5 @@
serde_yaml_with_quirks = "0.8.24"
[build-dependencies]
-jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2", features = [
- "serde",
-] }
-serde = "1.0"
-bincode = "1.3"
+jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2" }
+structdump = { version = "0.2.0", features = ["derive"] }
crates/jrsonnet-stdlib/build.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/build.rs
+++ b/crates/jrsonnet-stdlib/build.rs
@@ -1,7 +1,7 @@
use std::{borrow::Cow, env, fs::File, io::Write, path::Path};
-use bincode::serialize;
use jrsonnet_parser::{parse, ParserSettings, Source};
+use structdump::CodegenResult;
fn main() {
let parsed = parse(
@@ -15,10 +15,15 @@
)
.expect("parse");
+ let mut out = CodegenResult::default();
+
+ let v = out.codegen(&parsed, true);
+
{
let out_dir = env::var("OUT_DIR").unwrap();
- let dest_path = Path::new(&out_dir).join("stdlib.bincode");
+ let dest_path = Path::new(&out_dir).join("stdlib.rs");
let mut f = File::create(&dest_path).unwrap();
- f.write_all(&serialize(&parsed).unwrap()).unwrap();
+ f.write_all(v.to_string().replace(';', ";\n").as_bytes())
+ .unwrap();
}
}
crates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/expr.rs
+++ b/crates/jrsonnet-stdlib/src/expr.rs
@@ -1,22 +1,103 @@
-use std::borrow::Cow;
+use jrsonnet_parser::LocExpr;
-use jrsonnet_parser::{LocExpr, ParserSettings, Source};
+mod structdump_import {
+ pub(super) use std::{borrow::Cow, rc::Rc};
-pub const STDLIB_STR: &str = include_str!("./std.jsonnet");
+ pub(super) use jrsonnet_parser::*;
+ pub(super) use vec;
+ pub(super) use Option;
+}
pub fn stdlib_expr() -> LocExpr {
#[cfg(feature = "serialized-stdlib")]
{
+ use bincode::{BincodeRead, DefaultOptions, Options};
+ use serde::{Deserialize, Deserializer};
+
+ struct LocDeserializer<R, O: Options> {
+ source: Source,
+ wrapped: bincode::Deserializer<R, O>,
+ }
+ macro_rules! delegate {
+ ($(fn $name:ident($($arg:ident: $ty:ty),*))+) => {$(
+ fn $name<V>(mut self $(, $arg: $ty)*, visitor: V) -> Result<V::Value, Self::Error>
+ where V: serde::de::Visitor<'de>,
+ {
+ self.wrapped.$name($($arg,)* visitor)
+ }
+ )+};
+ }
+ impl<'de, R, O> Deserializer<'de> for LocDeserializer<R, O>
+ where
+ R: BincodeRead<'de>,
+ O: Options,
+ {
+ type Error = <&'de mut bincode::Deserializer<R, O> as Deserializer<'de>>::Error;
+
+ delegate! {
+ fn deserialize_any()
+ fn deserialize_bool()
+ fn deserialize_u16()
+ fn deserialize_u32()
+ fn deserialize_u64()
+ fn deserialize_i16()
+ fn deserialize_i32()
+ fn deserialize_i64()
+ fn deserialize_f32()
+ fn deserialize_f64()
+ fn deserialize_u128()
+ fn deserialize_i128()
+ fn deserialize_u8()
+ fn deserialize_i8()
+ fn deserialize_unit()
+ fn deserialize_char()
+ fn deserialize_str()
+ fn deserialize_string()
+ fn deserialize_bytes()
+ fn deserialize_byte_buf()
+ fn deserialize_enum(name: &'static str, variants: &'static [&'static str])
+ fn deserialize_tuple(len: usize)
+ fn deserialize_option()
+ fn deserialize_seq()
+ fn deserialize_map()
+ fn deserialize_struct(name: &'static str, fields: &'static [&'static str])
+ fn deserialize_identifier()
+ fn deserialize_newtype_struct(name: &'static str)
+ fn deserialize_unit_struct(name: &'static str)
+ fn deserialize_tuple_struct(name: &'static str, len: usize)
+ fn deserialize_ignored_any()
+ }
+
+ fn is_human_readable(&self) -> bool {
+ false
+ }
+ }
+
+ // In build.rs, Source object is populated with empty values, deserializer wrapper loads correct values on deserialize
+ let mut deserializer = bincode::Deserializer::from_slice(
+ include_bytes!(concat!(env!("OUT_DIR"), "/stdlib.bincode")),
+ DefaultOptions::new()
+ .with_fixint_encoding()
+ .allow_trailing_bytes(),
+ );
+
// Should not panic, stdlib.bincode is generated in build.rs
- return bincode::deserialize(include_bytes!(concat!(env!("OUT_DIR"), "/stdlib.bincode")))
- .unwrap();
+ LocExpr::deserialize(&mut deserializer).unwrap()
}
- jrsonnet_parser::parse(
- STDLIB_STR,
- &ParserSettings {
- file_name: Source::new_virtual(Cow::Borrowed("<std>"), STDLIB_STR.into()),
- },
- )
- .unwrap()
+ #[cfg(feature = "codegenerated-stdlib")]
+ {
+ include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
+ }
+
+ #[cfg(not(feature = "codegenerated-stdlib"))]
+ {
+ jrsonnet_parser::parse(
+ STDLIB_STR,
+ &ParserSettings {
+ file_name: Source::new_virtual(Cow::Borrowed("<std>"), STDLIB_STR.into()),
+ },
+ )
+ .unwrap()
+ }
}