difftreelog
perf remove AST (de)serialization
in: master
12 files changed
Cargo.lockdiffbeforeafterboth543 "hashbrown 0.14.5",543 "hashbrown 0.14.5",544 "jrsonnet-gcmodule",544 "jrsonnet-gcmodule",545 "rustc-hash",545 "rustc-hash",546 "serde",547 "structdump",548]546]549547550[[package]]548[[package]]563 "jrsonnet-gcmodule",561 "jrsonnet-gcmodule",564 "jrsonnet-interner",562 "jrsonnet-interner",565 "peg",563 "peg",566 "serde",567 "static_assertions",564 "static_assertions",568 "structdump",569]565]570566571[[package]]567[[package]]586version = "0.5.0-pre96"582version = "0.5.0-pre96"587dependencies = [583dependencies = [588 "base64",584 "base64",589 "bincode",590 "jrsonnet-evaluator",585 "jrsonnet-evaluator",591 "jrsonnet-gcmodule",586 "jrsonnet-gcmodule",592 "jrsonnet-macros",587 "jrsonnet-macros",602 "sha1",597 "sha1",603 "sha2",598 "sha2",604 "sha3",599 "sha3",605 "structdump",606]600]607601608[[package]]602[[package]]1103source = "registry+https://github.com/rust-lang/crates.io-index"1097source = "registry+https://github.com/rust-lang/crates.io-index"1104checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"1098checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"11051106[[package]]1107name = "structdump"1108version = "0.2.0"1109source = "registry+https://github.com/rust-lang/crates.io-index"1110checksum = "b0570327507bf281d8a6e6b0d4c082b12cb6bcee27efce755aa5efacd44076c1"1111dependencies = [1112 "proc-macro2",1113 "quote",1114 "structdump-derive",1115]11161117[[package]]1118name = "structdump-derive"1119version = "0.2.0"1120source = "registry+https://github.com/rust-lang/crates.io-index"1121checksum = "29cc0b59cfa11f1bceda09a9a7e37e6a6c3138575fd24ade8aa9af6d09aedf28"1122dependencies = [1123 "proc-macro2",1124 "quote",1125 "syn 1.0.109",1126]112710991128[[package]]1100[[package]]1129name = "syn"1101name = "syn"Cargo.tomldiffbeforeafterboth79num-bigint = "0.4.5"79num-bigint = "0.4.5"80derivative = "2.2.0"80derivative = "2.2.0"81strsim = "0.11.0"81strsim = "0.11.0"82structdump = "0.2.0"83proc-macro2 = "1.0"82proc-macro2 = "1.0"84quote = "1.0"83quote = "1.0"85syn = "2.0"84syn = "2.0"crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth10[lints]10[lints]11workspace = true11workspace = true1213[features]14default = []15# Implement value serialization using structdump16structdump = ["dep:structdump"]17# Implement value serialization using serde18#19# Warning: serialized values won't be deduplicated20serde = ["dep:serde"]211222[dependencies]13[dependencies]23jrsonnet-gcmodule.workspace = true14jrsonnet-gcmodule.workspace = true2425serde = { workspace = true, optional = true }26structdump = { workspace = true, optional = true }271528rustc-hash.workspace = true16rustc-hash.workspace = true29hashbrown = { workspace = true, features = ["inline-more"] }17hashbrown = { workspace = true, features = ["inline-more"] }crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth219 }219 }220}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}260221261thread_local! {222thread_local! {262 static POOL: RefCell<HashMap<Inner, (), BuildHasherDefault<FxHasher>>> = RefCell::new(HashMap::with_capacity_and_hasher(200, BuildHasherDefault::default()));223 static POOL: RefCell<HashMap<Inner, (), BuildHasherDefault<FxHasher>>> = RefCell::new(HashMap::with_capacity_and_hasher(200, BuildHasherDefault::default()));crates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth11default = []11default = []12exp-destruct = []12exp-destruct = []13exp-null-coaelse = []13exp-null-coaelse = []14# Implement serialization of AST using structdump15#16# Structdump generates code, which exactly replicated passed AST17# Contrary to serde, has no code bloat problem, and is recommended18#19# The only limitation is serialized form is only useable if built from build script20structdump = ["dep:structdump", "jrsonnet-interner/structdump"]21# Implement serialization of AST using serde22#23# Warning: as serde doesn't deduplicate strings, `Source` struct will bloat24# output binary with repeating source code. To resolve this issue, you should either25# override serialization of this struct using custom `Serializer`/`Deserializer`,26# not rely on Source, and fill its `source_code` with empty value, or use `structdump`27# instead28serde = ["dep:serde"]291430[dependencies]15[dependencies]31jrsonnet-interner.workspace = true16jrsonnet-interner.workspace = true352036peg.workspace = true21peg.workspace = true3738serde = { workspace = true, features = ["derive", "rc"], optional = true }39structdump = { workspace = true, features = ["derive"], optional = true }4022crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth667use jrsonnet_gcmodule::Trace;7use jrsonnet_gcmodule::Trace;8use jrsonnet_interner::IStr;8use jrsonnet_interner::IStr;9#[cfg(feature = "serde")]10use serde::{Deserialize, Serialize};11#[cfg(feature = "structdump")]12use structdump::Codegen;13914use crate::source::Source;10use crate::source::Source;151116#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]17#[cfg_attr(feature = "structdump", derive(Codegen))]18#[derive(Debug, PartialEq, Trace)]12#[derive(Debug, PartialEq, Trace)]19pub enum FieldName {13pub enum FieldName {20 /// {fixed: 2}14 /// {fixed: 2}23 Dyn(LocExpr),17 Dyn(LocExpr),24}18}251926#[cfg_attr(feature = "structdump", derive(Codegen))]27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]28#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]20#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]29#[repr(u8)]21#[repr(u8)]30pub enum Visibility {22pub enum Visibility {42 }34 }43}35}443645#[cfg_attr(feature = "structdump", derive(Codegen))]46#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]47#[derive(Clone, Debug, PartialEq, Trace)]37#[derive(Clone, Debug, PartialEq, Trace)]48pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);38pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);493950#[cfg_attr(feature = "structdump", derive(Codegen))]51#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]52#[derive(Debug, PartialEq, Trace)]40#[derive(Debug, PartialEq, Trace)]53pub struct FieldMember {41pub struct FieldMember {54 pub name: FieldName,42 pub name: FieldName,58 pub value: LocExpr,46 pub value: LocExpr,59}47}604861#[cfg_attr(feature = "structdump", derive(Codegen))]62#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]63#[derive(Debug, PartialEq, Trace)]49#[derive(Debug, PartialEq, Trace)]64pub enum Member {50pub enum Member {65 Field(FieldMember),51 Field(FieldMember),66 BindStmt(BindSpec),52 BindStmt(BindSpec),67 AssertStmt(AssertStmt),53 AssertStmt(AssertStmt),68}54}695570#[cfg_attr(feature = "structdump", derive(Codegen))]71#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]72#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]56#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]73pub enum UnaryOpType {57pub enum UnaryOpType {74 Plus,58 Plus,93 }77 }94}78}957996#[cfg_attr(feature = "structdump", derive(Codegen))]97#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]98#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]80#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]99pub enum BinaryOpType {81pub enum BinaryOpType {100 Mul,82 Mul,164}146}165147166/// name, default value148/// name, default value167#[cfg_attr(feature = "structdump", derive(Codegen))]168#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]169#[derive(Debug, PartialEq, Trace)]149#[derive(Debug, PartialEq, Trace)]170pub struct Param(pub Destruct, pub Option<LocExpr>);150pub struct Param(pub Destruct, pub Option<LocExpr>);171151172/// Defined function parameters152/// Defined function parameters173#[cfg_attr(feature = "structdump", derive(Codegen))]174#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]175#[derive(Debug, Clone, PartialEq, Trace)]153#[derive(Debug, Clone, PartialEq, Trace)]176pub struct ParamsDesc(pub Rc<Vec<Param>>);154pub struct ParamsDesc(pub Rc<Vec<Param>>);177155182 }160 }183}161}184162185#[cfg_attr(feature = "structdump", derive(Codegen))]186#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]187#[derive(Debug, PartialEq, Trace)]163#[derive(Debug, PartialEq, Trace)]188pub struct ArgsDesc {164pub struct ArgsDesc {189 pub unnamed: Vec<LocExpr>,165 pub unnamed: Vec<LocExpr>,195 }171 }196}172}197173198#[cfg_attr(feature = "structdump", derive(Codegen))]199#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]200#[derive(Debug, Clone, PartialEq, Eq, Trace)]174#[derive(Debug, Clone, PartialEq, Eq, Trace)]201pub enum DestructRest {175pub enum DestructRest {202 /// ...rest176 /// ...rest205 Drop,179 Drop,206}180}207181208#[cfg_attr(feature = "structdump", derive(Codegen))]209#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]210#[derive(Debug, Clone, PartialEq, Trace)]182#[derive(Debug, Clone, PartialEq, Trace)]211pub enum Destruct {183pub enum Destruct {212 Full(IStr),184 Full(IStr),268 }240 }269}241}270242271#[cfg_attr(feature = "structdump", derive(Codegen))]272#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]273#[derive(Debug, Clone, PartialEq, Trace)]243#[derive(Debug, Clone, PartialEq, Trace)]274pub enum BindSpec {244pub enum BindSpec {275 Field {245 Field {291 }261 }292}262}293263294#[cfg_attr(feature = "structdump", derive(Codegen))]295#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]296#[derive(Debug, PartialEq, Trace)]264#[derive(Debug, PartialEq, Trace)]297pub struct IfSpecData(pub LocExpr);265pub struct IfSpecData(pub LocExpr);298266299#[cfg_attr(feature = "structdump", derive(Codegen))]300#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]301#[derive(Debug, PartialEq, Trace)]267#[derive(Debug, PartialEq, Trace)]302pub struct ForSpecData(pub Destruct, pub LocExpr);268pub struct ForSpecData(pub Destruct, pub LocExpr);303269304#[cfg_attr(feature = "structdump", derive(Codegen))]305#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]306#[derive(Debug, PartialEq, Trace)]270#[derive(Debug, PartialEq, Trace)]307pub enum CompSpec {271pub enum CompSpec {308 IfSpec(IfSpecData),272 IfSpec(IfSpecData),309 ForSpec(ForSpecData),273 ForSpec(ForSpecData),310}274}311275312#[cfg_attr(feature = "structdump", derive(Codegen))]313#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]314#[derive(Debug, PartialEq, Trace)]276#[derive(Debug, PartialEq, Trace)]315pub struct ObjComp {277pub struct ObjComp {316 pub pre_locals: Vec<BindSpec>,278 pub pre_locals: Vec<BindSpec>,319 pub compspecs: Vec<CompSpec>,281 pub compspecs: Vec<CompSpec>,320}282}321283322#[cfg_attr(feature = "structdump", derive(Codegen))]323#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]324#[derive(Debug, PartialEq, Trace)]284#[derive(Debug, PartialEq, Trace)]325pub enum ObjBody {285pub enum ObjBody {326 MemberList(Vec<Member>),286 MemberList(Vec<Member>),327 ObjComp(ObjComp),287 ObjComp(ObjComp),328}288}329289330#[cfg_attr(feature = "structdump", derive(Codegen))]331#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]332#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]290#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]333pub enum LiteralType {291pub enum LiteralType {334 This,292 This,339 False,297 False,340}298}341299342#[cfg_attr(feature = "structdump", derive(Codegen))]343#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]344#[derive(Debug, PartialEq, Trace)]300#[derive(Debug, PartialEq, Trace)]345pub struct SliceDesc {301pub struct SliceDesc {346 pub start: Option<LocExpr>,302 pub start: Option<LocExpr>,349}305}350306351/// Syntax base307/// Syntax base352#[cfg_attr(feature = "structdump", derive(Codegen))]353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]354#[derive(Debug, PartialEq, Trace)]308#[derive(Debug, PartialEq, Trace)]355pub enum Expr {309pub enum Expr {356 Literal(LiteralType),310 Literal(LiteralType),420 Slice(LocExpr, SliceDesc),374 Slice(LocExpr, SliceDesc),421}375}422376423#[cfg_attr(feature = "structdump", derive(Codegen))]424#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]425#[derive(Debug, PartialEq, Trace)]377#[derive(Debug, PartialEq, Trace)]426pub struct IndexPart {378pub struct IndexPart {427 pub value: LocExpr,379 pub value: LocExpr,430}382}431383432/// file, begin offset, end offset384/// file, begin offset, end offset433#[cfg_attr(feature = "structdump", derive(Codegen))]434#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]435#[derive(Clone, PartialEq, Eq, Trace)]385#[derive(Clone, PartialEq, Eq, Trace)]436#[trace(skip)]386#[trace(skip)]437#[repr(C)]387#[repr(C)]452}402}453403454/// Holds AST expression and its location in source file404/// Holds AST expression and its location in source file455#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]456#[cfg_attr(feature = "structdump", derive(Codegen))]457#[derive(Clone, PartialEq, Trace)]405#[derive(Clone, PartialEq, Trace)]458pub struct LocExpr(pub Rc<Expr>, pub ExprLocation);406pub struct LocExpr(pub Rc<Expr>, pub ExprLocation);459407crates/jrsonnet-parser/src/source.rsdiffbeforeafterboth889use jrsonnet_gcmodule::{Trace, Tracer};9use jrsonnet_gcmodule::{Trace, Tracer};10use jrsonnet_interner::{IBytes, IStr};10use jrsonnet_interner::{IBytes, IStr};11#[cfg(feature = "serde")]12use serde::{Deserialize, Serialize};13#[cfg(feature = "structdump")]14use structdump::Codegen;151116use crate::location::{location_to_offset, offset_to_location, CodeLocation};12use crate::location::{location_to_offset, offset_to_location, CodeLocation};1713133 }129 }134}130}135136#[cfg(feature = "structdump")]137impl Codegen for SourcePath {138 fn gen_code(139 &self,140 res: &mut structdump::CodegenResult,141 unique: bool,142 ) -> structdump::TokenStream {143 let source_virtual = self144 .0145 .as_any()146 .downcast_ref::<SourceVirtual>()147 .expect("can only codegen for virtual source paths!")148 .0149 .clone();150 let val = res.add_value(source_virtual, false);151 res.add_code(152 structdump::quote! {153 structdump_import::SourcePath::new(structdump_import::SourceVirtual(#val))154 },155 Some(structdump::quote!(SourcePath)),156 unique,157 )158 }159}160131161#[derive(Trace, Hash, PartialEq, Eq, Debug)]132#[derive(Trace, Hash, PartialEq, Eq, Debug)]162struct SourceDefault;133struct SourceDefault;237///208///238/// It is used for --ext-code=.../--tla-code=.../standard library source code by default,209/// It is used for --ext-code=.../--tla-code=.../standard library source code by default,239/// and user can construct arbitrary values by hand, without asking import resolver210/// and user can construct arbitrary values by hand, without asking import resolver240#[cfg_attr(feature = "structdump", derive(Codegen))]241#[derive(Trace, Hash, PartialEq, Eq, Debug, Clone)]211#[derive(Trace, Hash, PartialEq, Eq, Debug, Clone)]242pub struct SourceVirtual(pub IStr);212pub struct SourceVirtual(pub IStr);243impl Display for SourceVirtual {213impl Display for SourceVirtual {288258289/// Either real file, or virtual259/// Either real file, or virtual290/// Hash of FileName always have same value as raw Path, to make it possible to use with raw_entry_mut260/// Hash of FileName always have same value as raw Path, to make it possible to use with raw_entry_mut291#[cfg_attr(feature = "structdump", derive(Codegen))]292#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]293#[derive(Clone, PartialEq, Eq, Debug)]261#[derive(Clone, PartialEq, Eq, Debug)]294pub struct Source(pub Rc<(SourcePath, IStr)>);262pub struct Source(pub Rc<(SourcePath, IStr)>);295263crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth11workspace = true11workspace = true121213[features]13[features]14default = ["codegenerated-stdlib"]15# Speed-up initialization by generating code for parsed stdlib,16# instead of invoking parser for it.17# This is mutually exclusive with `serialized-stdlib`.18codegenerated-stdlib = ["jrsonnet-parser/structdump"]19# Use the embedded serialized stdlib.20# This is mutually exclusive with `codegenerated-stdlib`.21serialized-stdlib = []22# Enables legacy `std.thisFile` support, at the cost of worse caching14# Enables legacy `std.thisFile` support, at the cost of worse caching23legacy-this-file = []15legacy-this-file = []24# Add order preservation flag to some functions16# Add order preservation flag to some functions36jrsonnet-parser.workspace = true28jrsonnet-parser.workspace = true37jrsonnet-gcmodule.workspace = true29jrsonnet-gcmodule.workspace = true383039# Used for stdlib AST serialization40bincode = { workspace = true, optional = true }41# Used both for stdlib AST serialization and std.parseJson/std.parseYaml31# Used for std.parseJson/std.parseYaml42serde.workspace = true32serde.workspace = true433344# std.md534# std.md5655566[build-dependencies]56[build-dependencies]67jrsonnet-parser.workspace = true57jrsonnet-parser.workspace = true68structdump = { workspace = true, features = ["derive"] }6958crates/jrsonnet-stdlib/build.rsdiffbeforeafterbothno changes
crates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterbothno changes
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth36mod arrays;36mod arrays;37mod compat;37mod compat;38mod encoding;38mod encoding;39mod expr;40mod hash;39mod hash;41mod manifest;40mod manifest;42mod math;41mod math;55pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {54pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {56 let mut builder = ObjValueBuilder::new();55 let mut builder = ObjValueBuilder::new();5758 let expr = expr::stdlib_expr();59 let eval = jrsonnet_evaluator::evaluate(ContextBuilder::dangerous_empty_state().build(), &expr)60 .expect("stdlib.jsonnet should have no errors")61 .as_obj()62 .expect("stdlib.jsonnet should evaluate to object");6364 builder.with_super(eval);655666 // FIXME: Use PHF57 // FIXME: Use PHF67 for (name, builtin) in [58 for (name, builtin) in [crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterbothno changes