difftreelog
perf remove AST (de)serialization
in: master
12 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -543,8 +543,6 @@
"hashbrown 0.14.5",
"jrsonnet-gcmodule",
"rustc-hash",
- "serde",
- "structdump",
]
[[package]]
@@ -563,9 +561,7 @@
"jrsonnet-gcmodule",
"jrsonnet-interner",
"peg",
- "serde",
"static_assertions",
- "structdump",
]
[[package]]
@@ -586,7 +582,6 @@
version = "0.5.0-pre96"
dependencies = [
"base64",
- "bincode",
"jrsonnet-evaluator",
"jrsonnet-gcmodule",
"jrsonnet-macros",
@@ -602,7 +597,6 @@
"sha1",
"sha2",
"sha3",
- "structdump",
]
[[package]]
@@ -1102,28 +1096,6 @@
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
-
-[[package]]
-name = "structdump"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0570327507bf281d8a6e6b0d4c082b12cb6bcee27efce755aa5efacd44076c1"
-dependencies = [
- "proc-macro2",
- "quote",
- "structdump-derive",
-]
-
-[[package]]
-name = "structdump-derive"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "29cc0b59cfa11f1bceda09a9a7e37e6a6c3138575fd24ade8aa9af6d09aedf28"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
[[package]]
name = "syn"
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -79,7 +79,6 @@
num-bigint = "0.4.5"
derivative = "2.2.0"
strsim = "0.11.0"
-structdump = "0.2.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -10,20 +10,8 @@
[lints]
workspace = true
-[features]
-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.workspace = true
-
-serde = { workspace = true, optional = true }
-structdump = { workspace = true, optional = true }
rustc-hash.workspace = true
hashbrown = { workspace = true, features = ["inline-more"] }
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth1#![deny(2 unsafe_op_in_unsafe_fn,3 clippy::missing_safety_doc,4 clippy::undocumented_unsafe_blocks5)]6#![warn(clippy::pedantic, clippy::nursery)]7#![allow(clippy::missing_const_for_fn)]8use std::{9 borrow::Cow,10 cell::RefCell,11 fmt::{self, Display},12 hash::{BuildHasherDefault, Hash, Hasher},13 ops::Deref,14 str,15};1617use hashbrown::{hash_map::RawEntryMut, HashMap};18use jrsonnet_gcmodule::Trace;19use rustc_hash::FxHasher;2021mod inner;22use inner::Inner;2324/// Interned string25///26/// Provides O(1) comparsions and hashing, cheap copy, and cheap conversion to [`IBytes`]27#[derive(Clone, PartialOrd, Ord, Eq)]28pub struct IStr(Inner);29impl Trace for IStr {30 fn is_type_tracked() -> bool {31 false32 }33}3435impl IStr {36 #[must_use]37 pub fn empty() -> Self {38 "".into()39 }40 #[must_use]41 pub fn as_str(&self) -> &str {42 self as &str43 }4445 #[must_use]46 pub fn cast_bytes(self) -> IBytes {47 IBytes(self.0.clone())48 }49}5051impl Deref for IStr {52 type Target = str;5354 fn deref(&self) -> &Self::Target {55 // SAFETY: Inner::check_utf8 is called on IStr construction, data is utf-856 unsafe { self.0.as_str_unchecked() }57 }58}5960impl PartialEq for IStr {61 fn eq(&self, other: &Self) -> bool {62 // all IStr should be inlined into same pool63 Inner::ptr_eq(&self.0, &other.0)64 }65}6667impl PartialEq<str> for IStr {68 fn eq(&self, other: &str) -> bool {69 self as &str == other70 }71}7273impl Hash for IStr {74 fn hash<H: Hasher>(&self, state: &mut H) {75 // IStr is always obtained from pool, where no string have duplicate, thus every unique string has unique address76 state.write_usize(Inner::as_ptr(&self.0).cast::<()>() as usize);77 }78}7980impl Drop for IStr {81 fn drop(&mut self) {82 maybe_unpool(&self.0);83 }84}8586impl fmt::Debug for IStr {87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {88 fmt::Debug::fmt(self as &str, f)89 }90}9192impl Display for IStr {93 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {94 fmt::Display::fmt(self as &str, f)95 }96}9798/// Interned byte array99#[derive(Clone, PartialOrd, Ord, Eq)]100pub struct IBytes(Inner);101impl Trace for IBytes {102 fn is_type_tracked() -> bool {103 false104 }105}106107impl IBytes {108 #[must_use]109 pub fn cast_str(self) -> Option<IStr> {110 if Inner::check_utf8(&self.0) {111 Some(IStr(self.0.clone()))112 } else {113 None114 }115 }116 /// # Safety117 /// data should be valid utf8118 unsafe fn cast_str_unchecked(self) -> IStr {119 // SAFETY: data is utf8120 unsafe { Inner::assume_utf8(&self.0) };121 IStr(self.0.clone())122 }123124 #[must_use]125 pub fn as_slice(&self) -> &[u8] {126 self.0.as_slice()127 }128}129130impl Deref for IBytes {131 type Target = [u8];132133 fn deref(&self) -> &Self::Target {134 self.0.as_slice()135 }136}137138impl PartialEq for IBytes {139 fn eq(&self, other: &Self) -> bool {140 // all IStr should be inlined into same pool141 Inner::ptr_eq(&self.0, &other.0)142 }143}144145impl Hash for IBytes {146 fn hash<H: Hasher>(&self, state: &mut H) {147 // IBytes is always obtained from pool, where no string have duplicate, thus every unique string has unique address148 state.write_usize(Inner::as_ptr(&self.0).cast::<()>() as usize);149 }150}151152impl Drop for IBytes {153 fn drop(&mut self) {154 maybe_unpool(&self.0);155 }156}157158fn maybe_unpool(inner: &Inner) {159 #[cold]160 #[inline(never)]161 fn unpool(inner: &Inner) {162 // May fail on program termination163 let _ = POOL.try_with(|pool| {164 let mut pool = pool.borrow_mut();165166 if pool.remove(inner).is_none() {167 // On some platforms (i.e i686-windows), try_with will not fail after TLS168 // destructor is called, but instead re-initialize the TLS with the empty pool.169 // Allow non-pooled Drop in this case.170 // https://github.com/CertainLach/jrsonnet/issues/98#issuecomment-1591624016171 //172 // However, if pool is not empty, most likely this is issue #113, and then I don't173 // have any explainations for now.174 assert!(pool.is_empty(), "received an unpooled string not during the program termination, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!");175 }176 });177 }178 // First reference - current object, second - POOL179 if Inner::strong_count(inner) <= 2 {180 unpool(inner);181 }182}183184impl fmt::Debug for IBytes {185 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {186 fmt::Debug::fmt(self as &[u8], f)187 }188}189190impl<'c> From<Cow<'c, str>> for IStr {191 fn from(v: Cow<'c, str>) -> Self {192 intern_str(&v)193 }194}195impl From<&str> for IStr {196 fn from(v: &str) -> Self {197 intern_str(v)198 }199}200impl From<String> for IStr {201 fn from(s: String) -> Self {202 s.as_str().into()203 }204}205impl From<&String> for IStr {206 fn from(s: &String) -> Self {207 s.as_str().into()208 }209}210impl From<char> for IStr {211 fn from(value: char) -> Self {212 let mut buf = [0; 5];213 Self::from(&*value.encode_utf8(&mut buf))214 }215}216impl From<&[u8]> for IBytes {217 fn from(v: &[u8]) -> Self {218 intern_bytes(v)219 }220}221222#[cfg(feature = "serde")]223impl serde::Serialize for IStr {224 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>225 where226 S: serde::Serializer,227 {228 self.as_str().serialize(serializer)229 }230}231232#[cfg(feature = "serde")]233impl<'de> serde::Deserialize<'de> for IStr {234 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>235 where236 D: serde::Deserializer<'de>,237 {238 let str = <&str>::deserialize(deserializer)?;239 Ok(intern_str(str))240 }241}242243#[cfg(feature = "structdump")]244impl structdump::Codegen for IStr {245 fn gen_code(246 &self,247 res: &mut structdump::CodegenResult,248 _unique: bool,249 ) -> structdump::TokenStream {250 let s: &str = self;251 res.add_code(252 structdump::quote! {253 structdump_import::IStr::from(#s)254 },255 Some(structdump::quote![structdump_import::IStr]),256 false,257 )258 }259}260261thread_local! {262 static POOL: RefCell<HashMap<Inner, (), BuildHasherDefault<FxHasher>>> = RefCell::new(HashMap::with_capacity_and_hasher(200, BuildHasherDefault::default()));263}264265#[must_use]266pub fn intern_bytes(bytes: &[u8]) -> IBytes {267 POOL.with(|pool| {268 let mut pool = pool.borrow_mut();269 let entry = pool.raw_entry_mut().from_key(bytes);270 match entry {271 RawEntryMut::Occupied(i) => IBytes(i.get_key_value().0.clone()),272 RawEntryMut::Vacant(e) => {273 let (k, ()) = e.insert(Inner::new_bytes(bytes), ());274 IBytes(k.clone())275 }276 }277 })278}279280#[must_use]281pub fn intern_str(str: &str) -> IStr {282 // SAFETY: Rust strings always utf8283 unsafe { intern_bytes(str.as_bytes()).cast_str_unchecked() }284}285286#[cfg(test)]287mod tests {288 use crate::IStr;289290 #[test]291 fn simple() {292 let a = IStr::from("a");293 let b = IStr::from("a");294295 assert_eq!(a.as_ptr(), b.as_ptr());296 }297}crates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -11,21 +11,6 @@
default = []
exp-destruct = []
exp-null-coaelse = []
-# 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.workspace = true
@@ -34,6 +19,3 @@
static_assertions.workspace = true
peg.workspace = true
-
-serde = { workspace = true, features = ["derive", "rc"], optional = true }
-structdump = { workspace = true, features = ["derive"], optional = true }
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -6,15 +6,9 @@
use jrsonnet_gcmodule::Trace;
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}
@@ -23,8 +17,6 @@
Dyn(LocExpr),
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
#[repr(u8)]
pub enum Visibility {
@@ -42,13 +34,9 @@
}
}
-#[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 {
pub name: FieldName,
@@ -58,8 +46,6 @@
pub value: LocExpr,
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum Member {
Field(FieldMember),
@@ -67,8 +53,6 @@
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 {
Plus,
@@ -93,8 +77,6 @@
}
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum BinaryOpType {
Mul,
@@ -164,14 +146,10 @@
}
/// 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>>);
@@ -182,8 +160,6 @@
}
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct ArgsDesc {
pub unnamed: Vec<LocExpr>,
@@ -195,8 +171,6 @@
}
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Trace)]
pub enum DestructRest {
/// ...rest
@@ -205,8 +179,6 @@
Drop,
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Trace)]
pub enum Destruct {
Full(IStr),
@@ -268,8 +240,6 @@
}
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Trace)]
pub enum BindSpec {
Field {
@@ -291,26 +261,18 @@
}
}
-#[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 Destruct, pub LocExpr);
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum CompSpec {
IfSpec(IfSpecData),
ForSpec(ForSpecData),
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct ObjComp {
pub pre_locals: Vec<BindSpec>,
@@ -319,16 +281,12 @@
pub compspecs: Vec<CompSpec>,
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum ObjBody {
MemberList(Vec<Member>),
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 {
This,
@@ -339,8 +297,6 @@
False,
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct SliceDesc {
pub start: Option<LocExpr>,
@@ -349,8 +305,6 @@
}
/// Syntax base
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub enum Expr {
Literal(LiteralType),
@@ -420,8 +374,6 @@
Slice(LocExpr, SliceDesc),
}
-#[cfg_attr(feature = "structdump", derive(Codegen))]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Trace)]
pub struct IndexPart {
pub value: LocExpr,
@@ -430,8 +382,6 @@
}
/// 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)]
#[repr(C)]
@@ -452,8 +402,6 @@
}
/// 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
@@ -8,10 +8,6 @@
use jrsonnet_gcmodule::{Trace, Tracer};
use jrsonnet_interner::{IBytes, IStr};
-#[cfg(feature = "serde")]
-use serde::{Deserialize, Serialize};
-#[cfg(feature = "structdump")]
-use structdump::Codegen;
use crate::location::{location_to_offset, offset_to_location, CodeLocation};
@@ -130,31 +126,6 @@
impl Default for SourcePath {
fn default() -> Self {
Self(Rc::new(SourceDefault))
- }
-}
-
-#[cfg(feature = "structdump")]
-impl Codegen for SourcePath {
- fn gen_code(
- &self,
- res: &mut structdump::CodegenResult,
- unique: bool,
- ) -> structdump::TokenStream {
- let source_virtual = self
- .0
- .as_any()
- .downcast_ref::<SourceVirtual>()
- .expect("can only codegen for virtual source paths!")
- .0
- .clone();
- let val = res.add_value(source_virtual, false);
- res.add_code(
- structdump::quote! {
- structdump_import::SourcePath::new(structdump_import::SourceVirtual(#val))
- },
- Some(structdump::quote!(SourcePath)),
- unique,
- )
}
}
@@ -237,7 +208,6 @@
///
/// It is used for --ext-code=.../--tla-code=.../standard library source code by default,
/// and user can construct arbitrary values by hand, without asking import resolver
-#[cfg_attr(feature = "structdump", derive(Codegen))]
#[derive(Trace, Hash, PartialEq, Eq, Debug, Clone)]
pub struct SourceVirtual(pub IStr);
impl Display for SourceVirtual {
@@ -288,8 +258,6 @@
/// 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(pub Rc<(SourcePath, IStr)>);
crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -11,14 +11,6 @@
workspace = true
[features]
-default = ["codegenerated-stdlib"]
-# Speed-up initialization by generating code for parsed stdlib,
-# instead of invoking parser for it.
-# This is mutually exclusive with `serialized-stdlib`.
-codegenerated-stdlib = ["jrsonnet-parser/structdump"]
-# Use the embedded serialized stdlib.
-# This is mutually exclusive with `codegenerated-stdlib`.
-serialized-stdlib = []
# Enables legacy `std.thisFile` support, at the cost of worse caching
legacy-this-file = []
# Add order preservation flag to some functions
@@ -36,9 +28,7 @@
jrsonnet-parser.workspace = true
jrsonnet-gcmodule.workspace = true
-# Used for stdlib AST serialization
-bincode = { workspace = true, optional = true }
-# Used both for stdlib AST serialization and std.parseJson/std.parseYaml
+# Used for std.parseJson/std.parseYaml
serde.workspace = true
# std.md5
@@ -65,4 +55,3 @@
[build-dependencies]
jrsonnet-parser.workspace = true
-structdump = { workspace = true, features = ["derive"] }
crates/jrsonnet-stdlib/build.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/build.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-fn main() {
- #[cfg(feature = "codegenerated-stdlib")]
- {
- use std::{env, fs::File, io::Write, path::Path};
-
- use jrsonnet_parser::{parse, ParserSettings, Source};
- use structdump::CodegenResult;
-
- let parsed = parse(
- include_str!("./src/std.jsonnet"),
- &ParserSettings {
- source: Source::new_virtual(
- "<std>".into(),
- include_str!("./src/std.jsonnet").into(),
- ),
- },
- )
- .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.rs");
- let mut f = File::create(dest_path).unwrap();
- f.write_all(
- ("#[allow(clippy::redundant_clone, clippy::similar_names)]".to_owned()
- + &v.to_string())
- .as_bytes(),
- )
- .unwrap();
- }
- }
-}
crates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/expr.rs
+++ /dev/null
@@ -1,109 +0,0 @@
-use jrsonnet_parser::LocExpr;
-
-pub fn stdlib_expr() -> LocExpr {
- #[cfg(all(feature = "serialized-stdlib", feature = "codegenerated-stdlib"))]
- compile_error!(
- "features `serialized-stdlib` and `codegenerated-stdlib` are mutually exclusive"
- );
- #[cfg(all(feature = "serialized-stdlib", not(feature = "codegenerated-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
- LocExpr::deserialize(&mut deserializer).unwrap()
- }
-
- #[cfg(all(feature = "codegenerated-stdlib", not(feature = "serialized-stdlib")))]
- {
- mod structdump_import {
- pub(super) use std::{option::Option, rc::Rc, vec};
-
- pub(super) use jrsonnet_parser::*;
- }
-
- include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
- }
-
- #[cfg(not(any(feature = "serialized-stdlib", feature = "codegenerated-stdlib")))]
- {
- use jrsonnet_parser::Source;
-
- const STDLIB_STR: &str = include_str!("./std.jsonnet");
-
- jrsonnet_parser::parse(
- STDLIB_STR,
- &jrsonnet_parser::ParserSettings {
- source: Source::new_virtual("<std>".into(), STDLIB_STR.into()),
- },
- )
- .unwrap()
- }
-}
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -36,7 +36,6 @@
mod arrays;
mod compat;
mod encoding;
-mod expr;
mod hash;
mod manifest;
mod math;
@@ -54,14 +53,6 @@
#[allow(clippy::too_many_lines)]
pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
let mut builder = ObjValueBuilder::new();
-
- let expr = expr::stdlib_expr();
- let eval = jrsonnet_evaluator::evaluate(ContextBuilder::dangerous_empty_state().build(), &expr)
- .expect("stdlib.jsonnet should have no errors")
- .as_obj()
- .expect("stdlib.jsonnet should evaluate to object");
-
- builder.with_super(eval);
// FIXME: Use PHF
for (name, builtin) in [
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- local std = self,
-
- thisFile:: error 'std.thisFile is deprecated, to enable its support in jrsonnet - recompile it with "legacy-this-file" support.\nThis will slow down stdlib caching a bit, though',
-}