git.delta.rocks / jrsonnet / refs/commits / a9d1e03758ef

difftreelog

refactor switch to jrsonnet-gc

Yaroslav Bolyukin2021-07-04parent: #c36aa5c.patch.diff
in: master

27 files changed

modifiedCargo.lockdiffbeforeafterboth
99 "clap",99 "clap",
100]100]
101
102[[package]]
103name = "gc"
104version = "0.4.1"
105source = "registry+https://github.com/rust-lang/crates.io-index"
106checksum = "3edaac0f5832202ebc99520cb77c932248010c4645d20be1dc62d6579f5b3752"
107dependencies = [
108 "gc_derive",
109]
110
111[[package]]
112name = "gc_derive"
113version = "0.4.1"
114source = "registry+https://github.com/rust-lang/crates.io-index"
115checksum = "60df8444f094ff7885631d80e78eb7d88c3c2361a98daaabb06256e4500db941"
116dependencies = [
117 "proc-macro2",
118 "quote",
119 "syn",
120 "synstructure",
121]
122101
123[[package]]102[[package]]
124name = "hashbrown"103name = "hashbrown"
190 "anyhow",169 "anyhow",
191 "base64",170 "base64",
192 "bincode",171 "bincode",
193 "gc",172 "jrsonnet-gc",
194 "jrsonnet-interner",173 "jrsonnet-interner",
195 "jrsonnet-parser",174 "jrsonnet-parser",
196 "jrsonnet-stdlib",175 "jrsonnet-stdlib",
203 "thiserror",182 "thiserror",
204]183]
184
185[[package]]
186name = "jrsonnet-gc"
187version = "0.4.2"
188source = "registry+https://github.com/rust-lang/crates.io-index"
189checksum = "68da8bc2f00117b1373bb8877af03b1d391e4c4800e6585d7279e5b99c919dde"
190dependencies = [
191 "jrsonnet-gc-derive",
192]
193
194[[package]]
195name = "jrsonnet-gc-derive"
196version = "0.4.1"
197source = "registry+https://github.com/rust-lang/crates.io-index"
198checksum = "adcba9c387b64b054f06cc4d724905296e21edeeb7506847f3299117a2d92d12"
199dependencies = [
200 "proc-macro2",
201 "quote",
202 "syn",
203 "synstructure",
204]
205205
206[[package]]206[[package]]
207name = "jrsonnet-interner"207name = "jrsonnet-interner"
208version = "0.3.8"208version = "0.3.8"
209dependencies = [209dependencies = [
210 "gc",210 "jrsonnet-gc",
211 "rustc-hash",211 "rustc-hash",
212 "serde",212 "serde",
213]213]
216name = "jrsonnet-parser"216name = "jrsonnet-parser"
217version = "0.3.8"217version = "0.3.8"
218dependencies = [218dependencies = [
219 "gc",219 "jrsonnet-gc",
220 "jrsonnet-interner",220 "jrsonnet-interner",
221 "jrsonnet-stdlib",221 "jrsonnet-stdlib",
222 "peg",222 "peg",
232name = "jrsonnet-types"232name = "jrsonnet-types"
233version = "0.3.8"233version = "0.3.8"
234dependencies = [234dependencies = [
235 "gc",235 "jrsonnet-gc",
236 "peg",236 "peg",
237]237]
238238
239[[package]]239[[package]]
240name = "jsonnet"240name = "jsonnet"
241version = "0.3.8"241version = "0.3.8"
242dependencies = [242dependencies = [
243 "gc",
244 "jrsonnet-evaluator",243 "jrsonnet-evaluator",
244 "jrsonnet-gc",
245 "jrsonnet-parser",245 "jrsonnet-parser",
246]246]
247247
modifiedbindings/jsonnet/Cargo.tomldiffbeforeafterboth
10[dependencies]10[dependencies]
11jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.3.8" }11jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.3.8" }
12jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.3.8" }12jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.3.8" }
13gc = { version = "0.4.1", features = ["derive"] }13jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
1414
15[lib]15[lib]
16crate-type = ["cdylib"]16crate-type = ["cdylib"]
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
1use gc::{unsafe_empty_trace, Finalize, Gc, Trace};
2use jrsonnet_evaluator::{1use jrsonnet_evaluator::{
3 error::{Error, LocError},2 error::{Error, LocError},
4 native::{NativeCallback, NativeCallbackHandler},3 native::{NativeCallback, NativeCallbackHandler},
5 EvaluationState, Val,4 EvaluationState, Val,
6};5};
6use jrsonnet_gc::{unsafe_empty_trace, Finalize, Gc, Trace};
7use jrsonnet_parser::{Param, ParamsDesc};7use jrsonnet_parser::{Param, ParamsDesc};
8use std::{8use std::{
9 ffi::{c_void, CStr},9 ffi::{c_void, CStr},
modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
1//! Create values in VM1//! Create values in VM
22
3use gc::Gc;
4use jrsonnet_evaluator::{ArrValue, EvaluationState, ObjValue, Val};3use jrsonnet_evaluator::{ArrValue, EvaluationState, ObjValue, Val};
4use jrsonnet_gc::Gc;
5use std::{5use std::{
6 ffi::CStr,6 ffi::CStr,
7 os::raw::{c_char, c_double, c_int},7 os::raw::{c_char, c_double, c_int},
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
2//! Only tested with variables, which haven't altered by code before appearing here2//! Only tested with variables, which haven't altered by code before appearing here
3//! In jrsonnet every value is immutable, and this code is probally broken3//! In jrsonnet every value is immutable, and this code is probally broken
44
5use gc::Gc;
6use jrsonnet_evaluator::{ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};5use jrsonnet_evaluator::{ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
6use jrsonnet_gc::Gc;
7use jrsonnet_parser::Visibility;7use jrsonnet_parser::Visibility;
8use std::{ffi::CStr, os::raw::c_char};8use std::{ffi::CStr, os::raw::c_char};
99
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
35rustc-hash = "1.1.0"35rustc-hash = "1.1.0"
3636
37thiserror = "1.0"37thiserror = "1.0"
38gc = { version = "0.4.1", features = ["derive"] }38jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
3939
40[dependencies.anyhow]40[dependencies.anyhow]
41version = "1.0"41version = "1.0"
modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
2#![allow(clippy::too_many_arguments)]2#![allow(clippy::too_many_arguments)]
33
4use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};4use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
5use gc::{Finalize, Trace};5use jrsonnet_gc::Trace;
6use jrsonnet_interner::IStr;6use jrsonnet_interner::IStr;
7use jrsonnet_types::ValType;7use jrsonnet_types::ValType;
8use thiserror::Error;8use thiserror::Error;
99
10#[derive(Debug, Clone, Error, Trace, Finalize)]10#[derive(Debug, Clone, Error, Trace)]
11#[trivially_drop]
11pub enum FormatError {12pub enum FormatError {
12 #[error("truncated format code")]13 #[error("truncated format code")]
13 TruncatedFormatCode,14 TruncatedFormatCode,
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
5 EvaluationState, FuncVal, LazyVal, Val,5 EvaluationState, FuncVal, LazyVal, Val,
6};6};
7use format::{format_arr, format_obj};7use format::{format_arr, format_obj};
8use gc::Gc;8use jrsonnet_gc::Gc;
9use jrsonnet_interner::IStr;9use jrsonnet_interner::IStr;
10use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};10use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};
11use jrsonnet_types::ty;11use jrsonnet_types::ty;
454 0, rest: ty!(any);454 0, rest: ty!(any);
455 ], {455 ], {
456 println!("GC start");456 println!("GC start");
457 gc::force_collect();457 jrsonnet_gc::force_collect();
458 println!("GC done");458 println!("GC done");
459459
460 Ok(rest)460 Ok(rest)
modifiedcrates/jrsonnet-evaluator/src/builtin/sort.rsdiffbeforeafterboth
2 error::{Error, LocError, Result},2 error::{Error, LocError, Result},
3 throw, Context, FuncVal, Val,3 throw, Context, FuncVal, Val,
4};4};
5use gc::{Finalize, Gc, Trace};5use jrsonnet_gc::{Finalize, Gc, Trace};
66
7#[derive(Debug, Clone, thiserror::Error, Trace, Finalize)]7#[derive(Debug, Clone, thiserror::Error, Trace, Finalize)]
8pub enum SortError {8pub enum SortError {
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
2 error::Error::*, map::LayeredHashMap, FutureWrapper, LazyBinding, LazyVal, ObjValue, Result,2 error::Error::*, map::LayeredHashMap, FutureWrapper, LazyBinding, LazyVal, ObjValue, Result,
3 Val,3 Val,
4};4};
5use gc::{Finalize, Gc, Trace};5use jrsonnet_gc::{Gc, Trace};
6use jrsonnet_interner::IStr;6use jrsonnet_interner::IStr;
7use rustc_hash::FxHashMap;7use rustc_hash::FxHashMap;
8use std::fmt::Debug;8use std::fmt::Debug;
9use std::hash::BuildHasherDefault;9use std::hash::BuildHasherDefault;
1010
11#[derive(Clone, Trace, Finalize)]11#[derive(Clone, Trace)]
12#[trivially_drop]
12pub struct ContextCreator(pub Context, pub FutureWrapper<FxHashMap<IStr, LazyBinding>>);13pub struct ContextCreator(pub Context, pub FutureWrapper<FxHashMap<IStr, LazyBinding>>);
13impl ContextCreator {14impl ContextCreator {
14 pub fn create(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<Context> {15 pub fn create(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<Context> {
21 }22 }
22}23}
2324
24#[derive(Trace, Finalize)]25#[derive(Trace)]
26#[trivially_drop]
25struct ContextInternals {27struct ContextInternals {
26 dollar: Option<ObjValue>,28 dollar: Option<ObjValue>,
27 this: Option<ObjValue>,29 this: Option<ObjValue>,
28 super_obj: Option<ObjValue>,30 super_obj: Option<ObjValue>,
29 bindings: LayeredHashMap<LazyVal>,31 bindings: LayeredHashMap,
30}32}
31impl Debug for ContextInternals {33impl Debug for ContextInternals {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 f.debug_struct("Context").finish()35 f.debug_struct("Context").finish()
34 }36 }
35}37}
3638
37#[derive(Debug, Clone, Trace, Finalize)]39#[derive(Debug, Clone, Trace)]
40#[trivially_drop]
38pub struct Context(Gc<ContextInternals>);41pub struct Context(Gc<ContextInternals>);
39impl Context {42impl Context {
40 pub fn new_future() -> FutureWrapper<Self> {43 pub fn new_future() -> FutureWrapper<Self> {
modifiedcrates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth
1use gc::{Finalize, Gc, GcCell, Trace};1use jrsonnet_gc::{Gc, GcCell, Trace};
22
3#[derive(Clone, Trace, Finalize)]3#[derive(Clone, Trace)]
4#[trivially_drop]
4pub struct FutureWrapper<V: Trace + 'static>(pub Gc<GcCell<Option<V>>>);5pub struct FutureWrapper<V: Trace + 'static>(pub Gc<GcCell<Option<V>>>);
5impl<T: Trace + 'static> FutureWrapper<T> {6impl<T: Trace + 'static> FutureWrapper<T> {
6 pub fn new() -> Self {7 pub fn new() -> Self {
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
2 builtin::{format::FormatError, sort::SortError},2 builtin::{format::FormatError, sort::SortError},
3 typed::TypeLocError,3 typed::TypeLocError,
4};4};
5use gc::{Finalize, Trace};5use jrsonnet_gc::Trace;
6use jrsonnet_interner::IStr;6use jrsonnet_interner::IStr;
7use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};7use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
8use jrsonnet_types::ValType;8use jrsonnet_types::ValType;
12};12};
13use thiserror::Error;13use thiserror::Error;
1414
15#[derive(Error, Debug, Clone, Trace, Finalize)]15#[derive(Error, Debug, Clone, Trace)]
16#[trivially_drop]
16pub enum Error {17pub enum Error {
17 #[error("intrinsic not found: {0}")]18 #[error("intrinsic not found: {0}")]
18 IntrinsicNotFound(IStr),19 IntrinsicNotFound(IStr),
149 }150 }
150}151}
151152
152#[derive(Clone, Debug, Trace, Finalize)]153#[derive(Clone, Debug, Trace)]
154#[trivially_drop]
153pub struct StackTraceElement {155pub struct StackTraceElement {
154 pub location: Option<ExprLocation>,156 pub location: Option<ExprLocation>,
155 pub desc: String,157 pub desc: String,
156}158}
157#[derive(Debug, Clone, Trace, Finalize)]159#[derive(Debug, Clone, Trace)]
160#[trivially_drop]
158pub struct StackTrace(pub Vec<StackTraceElement>);161pub struct StackTrace(pub Vec<StackTraceElement>);
159162
160#[derive(Debug, Clone, Trace, Finalize)]163#[derive(Debug, Clone, Trace)]
164#[trivially_drop]
161pub struct LocError(Box<(Error, StackTrace)>);165pub struct LocError(Box<(Error, StackTrace)>);
162impl LocError {166impl LocError {
163 pub fn new(e: Error) -> Self {167 pub fn new(e: Error) -> Self {
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
3 FuncDesc, FuncVal, FutureWrapper, LazyBinding, LazyVal, LazyValValue, ObjMember, ObjValue,3 FuncDesc, FuncVal, FutureWrapper, LazyBinding, LazyVal, LazyValValue, ObjMember, ObjValue,
4 ObjectAssertion, Result, Val,4 ObjectAssertion, Result, Val,
5};5};
6use gc::{custom_trace, Finalize, Gc, Trace};6use jrsonnet_gc::{Gc, Trace};
7use jrsonnet_interner::IStr;7use jrsonnet_interner::IStr;
8use jrsonnet_parser::{8use jrsonnet_parser::{
9 ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, ExprLocation, FieldMember,9 ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, ExprLocation, FieldMember,
22 if let Some(params) = &b.params {22 if let Some(params) = &b.params {
23 let params = params.clone();23 let params = params.clone();
2424
25 #[derive(Trace)]
26 #[trivially_drop]
25 struct LazyMethodBinding {27 struct LazyMethodBinding {
26 context_creator: FutureWrapper<Context>,28 context_creator: FutureWrapper<Context>,
27 name: IStr,29 name: IStr,
28 params: ParamsDesc,30 params: ParamsDesc,
29 value: LocExpr,31 value: LocExpr,
30 }32 }
31 impl Finalize for LazyMethodBinding {}
32 unsafe impl Trace for LazyMethodBinding {
33 custom_trace!(this, {
34 mark(&this.context_creator);
35 mark(&this.name);
36 mark(&this.params);
37 mark(&this.value);
38 });
39 }
40 impl LazyValValue for LazyMethodBinding {33 impl LazyValValue for LazyMethodBinding {
41 fn get(self: Box<Self>) -> Result<Val> {34 fn get(self: Box<Self>) -> Result<Val> {
42 Ok(evaluate_method(35 Ok(evaluate_method(
55 value: b.value.clone(),48 value: b.value.clone(),
56 }))49 }))
57 } else {50 } else {
51 #[derive(Trace)]
52 #[trivially_drop]
58 struct LazyNamedBinding {53 struct LazyNamedBinding {
59 context_creator: FutureWrapper<Context>,54 context_creator: FutureWrapper<Context>,
60 name: IStr,55 name: IStr,
61 value: LocExpr,56 value: LocExpr,
62 }57 }
63 impl Finalize for LazyNamedBinding {}
64 unsafe impl Trace for LazyNamedBinding {
65 custom_trace!(this, {
66 mark(&this.context_creator);
67 mark(&this.name);
68 mark(&this.value);
69 });
70 }
71 impl LazyValValue for LazyNamedBinding {58 impl LazyValValue for LazyNamedBinding {
72 fn get(self: Box<Self>) -> Result<Val> {59 fn get(self: Box<Self>) -> Result<Val> {
73 evaluate_named(self.context_creator.unwrap(), &self.value, self.name)60 evaluate_named(self.context_creator.unwrap(), &self.value, self.name)
86 if let Some(params) = &b.params {73 if let Some(params) = &b.params {
87 let params = params.clone();74 let params = params.clone();
8875
76 #[derive(Trace)]
77 #[trivially_drop]
89 struct BindableMethodLazyVal {78 struct BindableMethodLazyVal {
90 this: Option<ObjValue>,79 this: Option<ObjValue>,
91 super_obj: Option<ObjValue>,80 super_obj: Option<ObjValue>,
95 params: ParamsDesc,84 params: ParamsDesc,
96 value: LocExpr,85 value: LocExpr,
97 }86 }
98 impl Finalize for BindableMethodLazyVal {}
99 unsafe impl Trace for BindableMethodLazyVal {
100 custom_trace!(this, {
101 mark(&this.this);
102 mark(&this.super_obj);
103 mark(&this.context_creator);
104 mark(&this.name);
105 mark(&this.params);
106 mark(&this.value);
107 });
108 }
109 impl LazyValValue for BindableMethodLazyVal {87 impl LazyValValue for BindableMethodLazyVal {
110 fn get(self: Box<Self>) -> Result<Val> {88 fn get(self: Box<Self>) -> Result<Val> {
111 Ok(evaluate_method(89 Ok(evaluate_method(
117 }95 }
118 }96 }
11997
120 #[derive(Trace, Finalize)]98 #[derive(Trace)]
99 #[trivially_drop]
121 struct BindableMethod {100 struct BindableMethod {
122 context_creator: ContextCreator,101 context_creator: ContextCreator,
123 name: IStr,102 name: IStr,
148 }))),127 }))),
149 )128 )
150 } else {129 } else {
130 #[derive(Trace)]
131 #[trivially_drop]
151 struct BindableNamedLazyVal {132 struct BindableNamedLazyVal {
152 this: Option<ObjValue>,133 this: Option<ObjValue>,
153 super_obj: Option<ObjValue>,134 super_obj: Option<ObjValue>,
156 name: IStr,137 name: IStr,
157 value: LocExpr,138 value: LocExpr,
158 }139 }
159 impl Finalize for BindableNamedLazyVal {}
160 unsafe impl Trace for BindableNamedLazyVal {
161 custom_trace!(this, {
162 mark(&this.this);
163 mark(&this.super_obj);
164 mark(&this.context_creator);
165 mark(&this.name);
166 mark(&this.value);
167 });
168 }
169 impl LazyValValue for BindableNamedLazyVal {140 impl LazyValValue for BindableNamedLazyVal {
170 fn get(self: Box<Self>) -> Result<Val> {141 fn get(self: Box<Self>) -> Result<Val> {
171 evaluate_named(142 evaluate_named(
176 }147 }
177 }148 }
178149
179 #[derive(Trace, Finalize)]150 #[derive(Trace)]
151 #[trivially_drop]
180 struct BindableNamed {152 struct BindableNamed {
181 context_creator: ContextCreator,153 context_creator: ContextCreator,
182 name: IStr,154 name: IStr,
414 }386 }
415 let name = name.unwrap();387 let name = name.unwrap();
416388
417 #[derive(Trace, Finalize)]389 #[derive(Trace)]
390 #[trivially_drop]
418 struct ObjMemberBinding {391 struct ObjMemberBinding {
419 context_creator: ContextCreator,392 context_creator: ContextCreator,
420 value: LocExpr,393 value: LocExpr,
458 continue;431 continue;
459 }432 }
460 let name = name.unwrap();433 let name = name.unwrap();
461 #[derive(Trace, Finalize)]434 #[derive(Trace)]
435 #[trivially_drop]
462 struct ObjMemberBinding {436 struct ObjMemberBinding {
463 context_creator: ContextCreator,437 context_creator: ContextCreator,
464 value: LocExpr,438 value: LocExpr,
496 }470 }
497 Member::BindStmt(_) => {}471 Member::BindStmt(_) => {}
498 Member::AssertStmt(stmt) => {472 Member::AssertStmt(stmt) => {
473 #[derive(Trace)]
474 #[trivially_drop]
499 struct ObjectAssert {475 struct ObjectAssert {
500 context_creator: ContextCreator,476 context_creator: ContextCreator,
501 assert: AssertStmt,477 assert: AssertStmt,
502 }478 }
503 impl Finalize for ObjectAssert {}
504 unsafe impl Trace for ObjectAssert {
505 custom_trace!(this, {
506 mark(&this.context_creator);
507 mark(&this.assert);
508 });
509 }
510 impl ObjectAssertion for ObjectAssert {479 impl ObjectAssertion for ObjectAssert {
511 fn run(480 fn run(
512 &self,481 &self,
558 match key {527 match key {
559 Val::Null => {}528 Val::Null => {}
560 Val::Str(n) => {529 Val::Str(n) => {
561 #[derive(Trace, Finalize)]530 #[derive(Trace)]
531 #[trivially_drop]
562 struct ObjCompBinding {532 struct ObjCompBinding {
563 context: Context,533 context: Context,
564 value: LocExpr,534 value: LocExpr,
768 let mut out = Vec::with_capacity(items.len());738 let mut out = Vec::with_capacity(items.len());
769 for item in items {739 for item in items {
770 // TODO: Implement ArrValue::Lazy with same context for every element?740 // TODO: Implement ArrValue::Lazy with same context for every element?
741 #[derive(Trace)]
742 #[trivially_drop]
771 struct ArrayElement {743 struct ArrayElement {
772 context: Context,744 context: Context,
773 item: LocExpr,745 item: LocExpr,
774 }746 }
775 impl Finalize for ArrayElement {}
776 unsafe impl Trace for ArrayElement {
777 custom_trace!(this, {
778 mark(&this.context);
779 mark(&this.item);
780 });
781 }
782 impl LazyValValue for ArrayElement {747 impl LazyValValue for ArrayElement {
783 fn get(self: Box<Self>) -> Result<Val> {748 fn get(self: Box<Self>) -> Result<Val> {
784 evaluate(self.context, &self.item)749 evaluate(self.context, &self.item)
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
1use crate::{error::Error::*, evaluate, throw, Context, LazyVal, LazyValValue, Result, Val};1use crate::{error::Error::*, evaluate, throw, Context, LazyVal, LazyValValue, Result, Val};
2use gc::{custom_trace, Finalize, Trace};2use jrsonnet_gc::Trace;
3use jrsonnet_interner::IStr;3use jrsonnet_interner::IStr;
4use jrsonnet_parser::{ArgsDesc, LocExpr, ParamsDesc};4use jrsonnet_parser::{ArgsDesc, LocExpr, ParamsDesc};
5use rustc_hash::FxHashMap;5use rustc_hash::FxHashMap;
55 let val = if tailstrict {55 let val = if tailstrict {
56 LazyVal::new_resolved(evaluate(ctx, expr)?)56 LazyVal::new_resolved(evaluate(ctx, expr)?)
57 } else {57 } else {
58 #[derive(Trace)]
59 #[trivially_drop]
58 struct EvaluateLazyVal {60 struct EvaluateLazyVal {
59 context: Context,61 context: Context,
60 expr: LocExpr,62 expr: LocExpr,
61 }63 }
62 impl Finalize for EvaluateLazyVal {}
63 unsafe impl Trace for EvaluateLazyVal {
64 custom_trace!(this, {
65 mark(&this.context);
66 mark(&this.expr);
67 });
68 }
69 impl LazyValValue for EvaluateLazyVal {64 impl LazyValValue for EvaluateLazyVal {
70 fn get(self: Box<Self>) -> Result<Val> {65 fn get(self: Box<Self>) -> Result<Val> {
71 evaluate(self.context, &self.expr)66 evaluate(self.context, &self.expr)
119 } else {114 } else {
120 let body_ctx = body_ctx.clone();115 let body_ctx = body_ctx.clone();
121 let default = default.clone();116 let default = default.clone();
122 #[derive(Trace, Finalize)]117 #[derive(Trace)]
118 #[trivially_drop]
123 struct EvaluateLazyVal {119 struct EvaluateLazyVal {
124 body_ctx: Option<Context>,120 body_ctx: Option<Context>,
125 default: LocExpr,121 default: LocExpr,
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
2 error::{Error::*, LocError, Result},2 error::{Error::*, LocError, Result},
3 throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,3 throw, LazyBinding, LazyVal, ObjMember, ObjValue, Val,
4};4};
5use gc::Gc;5use jrsonnet_gc::Gc;
6use jrsonnet_parser::Visibility;6use jrsonnet_parser::Visibility;
7use rustc_hash::FxHasher;7use rustc_hash::FxHasher;
8use serde_json::{Map, Number, Value};8use serde_json::{Map, Number, Value};
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
25use error::{Error::*, LocError, Result, StackTraceElement};25use error::{Error::*, LocError, Result, StackTraceElement};
26pub use evaluate::*;26pub use evaluate::*;
27pub use function::parse_function_call;27pub use function::parse_function_call;
28pub use import::*;
28use gc::{Finalize, Gc, Trace};29use jrsonnet_gc::{Finalize, Gc, Trace};
29pub use import::*;
30pub use jrsonnet_interner::IStr;30pub use jrsonnet_interner::IStr;
31use jrsonnet_parser::*;31use jrsonnet_parser::*;
32use native::NativeCallback;32use native::NativeCallback;
modifiedcrates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth
1use gc::{Finalize, Gc, Trace};1use jrsonnet_gc::{Gc, Trace};
2use jrsonnet_interner::IStr;2use jrsonnet_interner::IStr;
3use rustc_hash::FxHashMap;3use rustc_hash::FxHashMap;
44
5use crate::LazyVal;
6
7#[derive(Trace)]
8#[trivially_drop]
5pub struct LayeredHashMapInternals<V: Trace + Finalize + 'static> {9pub struct LayeredHashMapInternals {
6 parent: Option<LayeredHashMap<V>>,10 parent: Option<LayeredHashMap>,
7 current: FxHashMap<IStr, V>,11 current: FxHashMap<IStr, LazyVal>,
8}12}
9
10unsafe impl<V: Trace + Finalize + 'static> Trace for LayeredHashMapInternals<V> {
11 gc::custom_trace!(this, {
12 mark(&this.parent);
13 mark(&this.current);
14 });
15}
16impl<V: Trace + Finalize + 'static> Finalize for LayeredHashMapInternals<V> {}
1713
18#[derive(Trace, Finalize)]14#[derive(Trace)]
15#[trivially_drop]
19pub struct LayeredHashMap<V: Trace + Finalize + 'static>(Gc<LayeredHashMapInternals<V>>);16pub struct LayeredHashMap(Gc<LayeredHashMapInternals>);
2017
21impl<V: Trace + 'static> LayeredHashMap<V> {18impl LayeredHashMap {
22 pub fn extend(self, new_layer: FxHashMap<IStr, V>) -> Self {19 pub fn extend(self, new_layer: FxHashMap<IStr, LazyVal>) -> Self {
23 Self(Gc::new(LayeredHashMapInternals {20 Self(Gc::new(LayeredHashMapInternals {
24 parent: Some(self),21 parent: Some(self),
25 current: new_layer,22 current: new_layer,
26 }))23 }))
27 }24 }
2825
29 pub fn get(&self, key: &IStr) -> Option<&V> {26 pub fn get(&self, key: &IStr) -> Option<&LazyVal> {
30 (self.0)27 (self.0)
31 .current28 .current
32 .get(key)29 .get(key)
33 .or_else(|| self.0.parent.as_ref().and_then(|p| p.get(key)))30 .or_else(|| self.0.parent.as_ref().and_then(|p| p.get(key)))
34 }31 }
35}32}
3633
37impl<V: Trace + 'static> Clone for LayeredHashMap<V> {34impl Clone for LayeredHashMap {
38 fn clone(&self) -> Self {35 fn clone(&self) -> Self {
39 Self(self.0.clone())36 Self(self.0.clone())
40 }37 }
41}38}
4239
43impl<V: Trace + 'static> Default for LayeredHashMap<V> {40impl Default for LayeredHashMap {
44 fn default() -> Self {41 fn default() -> Self {
45 Self(Gc::new(LayeredHashMapInternals {42 Self(Gc::new(LayeredHashMapInternals {
46 parent: None,43 parent: None,
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
1#![allow(clippy::type_complexity)]1#![allow(clippy::type_complexity)]
22
3use crate::{error::Result, Val};3use crate::{error::Result, Val};
4use gc::{Finalize, Trace};4use jrsonnet_gc::Trace;
5use jrsonnet_parser::ParamsDesc;5use jrsonnet_parser::ParamsDesc;
6use std::fmt::Debug;6use std::fmt::Debug;
7use std::path::Path;7use std::path::Path;
11 fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> Result<Val>;11 fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> Result<Val>;
12}12}
1313
14#[derive(Trace, Finalize)]14#[derive(Trace)]
15#[trivially_drop]
15pub struct NativeCallback {16pub struct NativeCallback {
16 pub params: ParamsDesc,17 pub params: ParamsDesc,
17 handler: Box<dyn NativeCallbackHandler>,18 handler: Box<dyn NativeCallbackHandler>,
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
1use crate::{evaluate_add_op, LazyBinding, Result, Val};1use crate::{evaluate_add_op, LazyBinding, Result, Val};
2use gc::{Finalize, Gc, GcCell, Trace};2use jrsonnet_gc::{Gc, GcCell, Trace};
3use jrsonnet_interner::IStr;3use jrsonnet_interner::IStr;
4use jrsonnet_parser::{ExprLocation, Visibility};4use jrsonnet_parser::{ExprLocation, Visibility};
5use rustc_hash::{FxHashMap, FxHashSet};5use rustc_hash::{FxHashMap, FxHashSet};
6use std::hash::{Hash, Hasher};6use std::hash::{Hash, Hasher};
7use std::{fmt::Debug, hash::BuildHasherDefault};7use std::{fmt::Debug, hash::BuildHasherDefault};
88
9#[derive(Debug, Trace, Finalize)]9#[derive(Debug, Trace)]
10#[trivially_drop]
10pub struct ObjMember {11pub struct ObjMember {
11 pub add: bool,12 pub add: bool,
12 pub visibility: Visibility,13 pub visibility: Visibility,
2021
21// Field => This22// Field => This
22type CacheKey = (IStr, ObjValue);23type CacheKey = (IStr, ObjValue);
23#[derive(Trace, Finalize)]24#[derive(Trace)]
25#[trivially_drop]
24pub struct ObjValueInternals {26pub struct ObjValueInternals {
25 super_obj: Option<ObjValue>,27 super_obj: Option<ObjValue>,
26 assertions: Gc<Vec<Box<dyn ObjectAssertion>>>,28 assertions: Gc<Vec<Box<dyn ObjectAssertion>>>,
30 value_cache: GcCell<FxHashMap<CacheKey, Option<Val>>>,32 value_cache: GcCell<FxHashMap<CacheKey, Option<Val>>>,
31}33}
3234
33#[derive(Clone, Trace, Finalize)]35#[derive(Clone, Trace)]
36#[trivially_drop]
34pub struct ObjValue(pub(crate) Gc<ObjValueInternals>);37pub struct ObjValue(pub(crate) Gc<ObjValueInternals>);
35impl Debug for ObjValue {38impl Debug for ObjValue {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
4 error::{Error, LocError, Result},4 error::{Error, LocError, Result},
5 push, Val,5 push, Val,
6};6};
7use gc::{Finalize, Trace};7use jrsonnet_gc::Trace;
8use jrsonnet_parser::ExprLocation;8use jrsonnet_parser::ExprLocation;
9use jrsonnet_types::{ComplexValType, ValType};9use jrsonnet_types::{ComplexValType, ValType};
10use thiserror::Error;10use thiserror::Error;
21 }};21 }};
22}22}
2323
24#[derive(Debug, Error, Clone, Trace, Finalize)]24#[derive(Debug, Error, Clone, Trace)]
25#[trivially_drop]
25pub enum TypeError {26pub enum TypeError {
26 #[error("expected {0}, got {1}")]27 #[error("expected {0}, got {1}")]
27 ExpectedGot(ComplexValType, ValType),28 ExpectedGot(ComplexValType, ValType),
38 }39 }
39}40}
4041
41#[derive(Debug, Clone, Trace, Finalize)]42#[derive(Debug, Clone, Trace)]
43#[trivially_drop]
42pub struct TypeLocError(Box<TypeError>, ValuePathStack);44pub struct TypeLocError(Box<TypeError>, ValuePathStack);
43impl From<TypeError> for TypeLocError {45impl From<TypeError> for TypeLocError {
44 fn from(e: TypeError) -> Self {46 fn from(e: TypeError) -> Self {
60 }62 }
61}63}
6264
63#[derive(Debug, Clone, Trace, Finalize)]65#[derive(Debug, Clone, Trace)]
66#[trivially_drop]
64pub struct TypeLocErrorList(Vec<TypeLocError>);67pub struct TypeLocErrorList(Vec<TypeLocError>);
65impl Display for TypeLocErrorList {68impl Display for TypeLocErrorList {
66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123 }126 }
124}127}
125128
126#[derive(Clone, Debug, Trace, Finalize)]129#[derive(Clone, Debug, Trace)]
130#[trivially_drop]
127enum ValuePathItem {131enum ValuePathItem {
128 Field(Rc<str>),132 Field(Rc<str>),
129 Index(u64),133 Index(u64),
138 }142 }
139}143}
140144
141#[derive(Clone, Debug, Trace, Finalize)]145#[derive(Clone, Debug, Trace)]
146#[trivially_drop]
142struct ValuePathStack(Vec<ValuePathItem>);147struct ValuePathStack(Vec<ValuePathItem>);
143impl Display for ValuePathStack {148impl Display for ValuePathStack {
144 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {149 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
9 native::NativeCallback,9 native::NativeCallback,
10 throw, with_state, Context, ObjValue, Result,10 throw, with_state, Context, ObjValue, Result,
11};11};
12use gc::{custom_trace, Finalize, Gc, GcCell, Trace};12use jrsonnet_gc::{Finalize, Gc, GcCell, Trace};
13use jrsonnet_interner::IStr;13use jrsonnet_interner::IStr;
14use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};14use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};
15use jrsonnet_types::ValType;15use jrsonnet_types::ValType;
19 fn get(self: Box<Self>) -> Result<Val>;19 fn get(self: Box<Self>) -> Result<Val>;
20}20}
2121
22#[derive(Trace)]
23#[trivially_drop]
22enum LazyValInternals {24enum LazyValInternals {
23 Computed(Val),25 Computed(Val),
24 Errored(LocError),26 Errored(LocError),
25 Waiting(Box<dyn LazyValValue>),27 Waiting(Box<dyn LazyValValue>),
26 Pending,28 Pending,
27}29}
28impl Finalize for LazyValInternals {}
29unsafe impl Trace for LazyValInternals {
30 custom_trace!(this, {
31 match &this {
32 LazyValInternals::Computed(v) => mark(v),
33 LazyValInternals::Errored(e) => mark(e),
34 LazyValInternals::Waiting(w) => mark(w),
35 LazyValInternals::Pending => {}
36 }
37 });
38}
3930
40#[derive(Clone, Trace, Finalize)]31#[derive(Clone, Trace)]
32#[trivially_drop]
41pub struct LazyVal(Gc<GcCell<LazyValInternals>>);33pub struct LazyVal(Gc<GcCell<LazyValInternals>>);
42impl LazyVal {34impl LazyVal {
43 pub fn new(f: Box<dyn LazyValValue>) -> Self {35 pub fn new(f: Box<dyn LazyValValue>) -> Self {
83 }75 }
84}76}
8577
86#[derive(Debug, PartialEq, Trace, Finalize)]78#[derive(Debug, PartialEq, Trace)]
79#[trivially_drop]
87pub struct FuncDesc {80pub struct FuncDesc {
88 pub name: IStr,81 pub name: IStr,
89 pub ctx: Context,82 pub ctx: Context,
90 pub params: ParamsDesc,83 pub params: ParamsDesc,
91 pub body: LocExpr,84 pub body: LocExpr,
92}85}
9386
94#[derive(Debug, Trace, Finalize)]87#[derive(Debug, Trace)]
88#[trivially_drop]
95pub enum FuncVal {89pub enum FuncVal {
96 /// Plain function implemented in jsonnet90 /// Plain function implemented in jsonnet
97 Normal(FuncDesc),91 Normal(FuncDesc),
195 String,189 String,
196}190}
197191
198#[derive(Debug, Clone)]192#[derive(Debug, Clone, Trace)]
193#[trivially_drop]
199pub enum ArrValue {194pub enum ArrValue {
200 Lazy(Gc<Vec<LazyVal>>),195 Lazy(Gc<Vec<LazyVal>>),
201 Eager(Gc<Vec<Val>>),196 Eager(Gc<Vec<Val>>),
202 Extended(Box<(Self, Self)>),197 Extended(Box<(Self, Self)>),
203}198}
204impl Finalize for ArrValue {}
205unsafe impl Trace for ArrValue {
206 custom_trace!(this, {
207 match &this {
208 ArrValue::Lazy(l) => mark(l),
209 ArrValue::Eager(e) => mark(e),
210 ArrValue::Extended(x) => mark(x),
211 }
212 });
213}
214impl ArrValue {199impl ArrValue {
215 pub fn new_eager() -> Self {200 pub fn new_eager() -> Self {
216 Self::Eager(Gc::new(Vec::new()))201 Self::Eager(Gc::new(Vec::new()))
419 }404 }
420}405}
421406
422#[derive(Debug, Clone)]407#[derive(Debug, Clone, Trace)]
408#[trivially_drop]
423pub enum Val {409pub enum Val {
424 Bool(bool),410 Bool(bool),
425 Null,411 Null,
430 Func(Gc<FuncVal>),416 Func(Gc<FuncVal>),
431 DebugGcTraceValue(DebugGcTraceValue),417 DebugGcTraceValue(DebugGcTraceValue),
432}418}
433impl Finalize for Val {}
434unsafe impl Trace for Val {
435 custom_trace!(this, {
436 match &this {
437 Val::Bool(_) => {}
438 Val::Null => {}
439 Val::Str(_) => {}
440 Val::Num(_) => {}
441 Val::Arr(a) => mark(a),
442 Val::Obj(o) => mark(o),
443 Val::Func(f) => mark(f),
444 Val::DebugGcTraceValue(v) => mark(v),
445 }
446 });
447}
448419
449macro_rules! matches_unwrap {420macro_rules! matches_unwrap {
450 ($e: expr, $p: pat, $r: expr) => {421 ($e: expr, $p: pat, $r: expr) => {
modifiedcrates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth
9[dependencies]9[dependencies]
10serde = { version = "1.0" }10serde = { version = "1.0" }
11rustc-hash = "1.1.0"11rustc-hash = "1.1.0"
12gc = { version = "0.4.1", features = ["derive"] }12jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
1313
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
1use gc::{unsafe_empty_trace, Finalize, Trace};1use jrsonnet_gc::{unsafe_empty_trace, Finalize, Trace};
2use rustc_hash::FxHashMap;2use rustc_hash::FxHashMap;
3use serde::{Deserialize, Serialize};3use serde::{Deserialize, Serialize};
4use std::{4use std::{
modifiedcrates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth
18unescape = "0.1.0"18unescape = "0.1.0"
1919
20serde = { version = "1.0", features = ["derive", "rc"], optional = true }20serde = { version = "1.0", features = ["derive", "rc"], optional = true }
21gc = { version = "0.4.1", features = ["derive"] }21jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
2222
23[dev-dependencies]23[dev-dependencies]
24jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.8" }24jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.8" }
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
1use gc::{unsafe_empty_trace, Finalize, Trace};1use jrsonnet_gc::{unsafe_empty_trace, Finalize, Trace};
2use jrsonnet_interner::IStr;2use jrsonnet_interner::IStr;
3#[cfg(feature = "deserialize")]3#[cfg(feature = "deserialize")]
4use serde::Deserialize;4use serde::Deserialize;
1313
14#[cfg_attr(feature = "serialize", derive(Serialize))]14#[cfg_attr(feature = "serialize", derive(Serialize))]
15#[cfg_attr(feature = "deserialize", derive(Deserialize))]15#[cfg_attr(feature = "deserialize", derive(Deserialize))]
16#[derive(Debug, PartialEq)]16#[derive(Debug, PartialEq, Trace)]
17#[trivially_drop]
17pub enum FieldName {18pub enum FieldName {
18 /// {fixed: 2}19 /// {fixed: 2}
19 Fixed(IStr),20 Fixed(IStr),
20 /// {["dyn"+"amic"]: 3}21 /// {["dyn"+"amic"]: 3}
21 Dyn(LocExpr),22 Dyn(LocExpr),
22}23}
23impl Finalize for FieldName {}
24unsafe impl Trace for FieldName {
25 unsafe_empty_trace!();
26}
2724
28#[cfg_attr(feature = "serialize", derive(Serialize))]25#[cfg_attr(feature = "serialize", derive(Serialize))]
29#[cfg_attr(feature = "deserialize", derive(Deserialize))]26#[cfg_attr(feature = "deserialize", derive(Deserialize))]
30#[derive(Debug, Clone, Copy, PartialEq)]27#[derive(Debug, Clone, Copy, PartialEq, Trace)]
28#[trivially_drop]
31pub enum Visibility {29pub enum Visibility {
32 /// :30 /// :
33 Normal,31 Normal,
36 /// :::34 /// :::
37 Unhide,35 Unhide,
38}36}
39impl Finalize for Visibility {}
40unsafe impl Trace for Visibility {
41 unsafe_empty_trace!();
42}
4337
44impl Visibility {38impl Visibility {
45 pub fn is_visible(&self) -> bool {39 pub fn is_visible(&self) -> bool {
4943
50#[cfg_attr(feature = "serialize", derive(Serialize))]44#[cfg_attr(feature = "serialize", derive(Serialize))]
51#[cfg_attr(feature = "deserialize", derive(Deserialize))]45#[cfg_attr(feature = "deserialize", derive(Deserialize))]
52#[derive(Clone, Debug, PartialEq)]46#[derive(Clone, Debug, PartialEq, Trace)]
47#[trivially_drop]
53pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);48pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);
54impl Finalize for AssertStmt {}
55unsafe impl Trace for AssertStmt {
56 unsafe_empty_trace!();
57}
5849
59#[cfg_attr(feature = "serialize", derive(Serialize))]50#[cfg_attr(feature = "serialize", derive(Serialize))]
60#[cfg_attr(feature = "deserialize", derive(Deserialize))]51#[cfg_attr(feature = "deserialize", derive(Deserialize))]
61#[derive(Debug, PartialEq)]52#[derive(Debug, PartialEq, Trace)]
53#[trivially_drop]
62pub struct FieldMember {54pub struct FieldMember {
63 pub name: FieldName,55 pub name: FieldName,
64 pub plus: bool,56 pub plus: bool,
65 pub params: Option<ParamsDesc>,57 pub params: Option<ParamsDesc>,
66 pub visibility: Visibility,58 pub visibility: Visibility,
67 pub value: LocExpr,59 pub value: LocExpr,
68}60}
69impl Finalize for FieldMember {}
70unsafe impl Trace for FieldMember {
71 unsafe_empty_trace!();
72}
7361
74#[cfg_attr(feature = "serialize", derive(Serialize))]62#[cfg_attr(feature = "serialize", derive(Serialize))]
75#[cfg_attr(feature = "deserialize", derive(Deserialize))]63#[cfg_attr(feature = "deserialize", derive(Deserialize))]
76#[derive(Debug, PartialEq)]64#[derive(Debug, PartialEq, Trace)]
65#[trivially_drop]
77pub enum Member {66pub enum Member {
78 Field(FieldMember),67 Field(FieldMember),
79 BindStmt(BindSpec),68 BindStmt(BindSpec),
80 AssertStmt(AssertStmt),69 AssertStmt(AssertStmt),
81}70}
82impl Finalize for Member {}
83unsafe impl Trace for Member {
84 unsafe_empty_trace!();
85}
8671
87#[cfg_attr(feature = "serialize", derive(Serialize))]72#[cfg_attr(feature = "serialize", derive(Serialize))]
88#[cfg_attr(feature = "deserialize", derive(Deserialize))]73#[cfg_attr(feature = "deserialize", derive(Deserialize))]
89#[derive(Debug, Clone, Copy, PartialEq)]74#[derive(Debug, Clone, Copy, PartialEq, Trace)]
75#[trivially_drop]
90pub enum UnaryOpType {76pub enum UnaryOpType {
91 Plus,77 Plus,
92 Minus,78 Minus,
93 BitNot,79 BitNot,
94 Not,80 Not,
95}81}
96impl Finalize for UnaryOpType {}
97unsafe impl Trace for UnaryOpType {
98 unsafe_empty_trace!();
99}
10082
101impl Display for UnaryOpType {83impl Display for UnaryOpType {
102 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11698
117#[cfg_attr(feature = "serialize", derive(Serialize))]99#[cfg_attr(feature = "serialize", derive(Serialize))]
118#[cfg_attr(feature = "deserialize", derive(Deserialize))]100#[cfg_attr(feature = "deserialize", derive(Deserialize))]
119#[derive(Debug, Clone, Copy, PartialEq)]101#[derive(Debug, Clone, Copy, PartialEq, Trace)]
102#[trivially_drop]
120pub enum BinaryOpType {103pub enum BinaryOpType {
121 Mul,104 Mul,
122 Div,105 Div,
145 And,128 And,
146 Or,129 Or,
147}130}
148impl Finalize for BinaryOpType {}
149unsafe impl Trace for BinaryOpType {
150 unsafe_empty_trace!();
151}
152131
153impl Display for BinaryOpType {132impl Display for BinaryOpType {
154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {133 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
183/// name, default value162/// name, default value
184#[cfg_attr(feature = "serialize", derive(Serialize))]163#[cfg_attr(feature = "serialize", derive(Serialize))]
185#[cfg_attr(feature = "deserialize", derive(Deserialize))]164#[cfg_attr(feature = "deserialize", derive(Deserialize))]
186#[derive(Debug, PartialEq)]165#[derive(Debug, PartialEq, Trace)]
166#[trivially_drop]
187pub struct Param(pub IStr, pub Option<LocExpr>);167pub struct Param(pub IStr, pub Option<LocExpr>);
188impl Finalize for Param {}
189unsafe impl Trace for Param {
190 unsafe_empty_trace!();
191}
192168
193/// Defined function parameters169/// Defined function parameters
194#[cfg_attr(feature = "serialize", derive(Serialize))]170#[cfg_attr(feature = "serialize", derive(Serialize))]
195#[cfg_attr(feature = "deserialize", derive(Deserialize))]171#[cfg_attr(feature = "deserialize", derive(Deserialize))]
196#[derive(Debug, Clone, PartialEq)]172#[derive(Debug, Clone, PartialEq)]
197pub struct ParamsDesc(pub Rc<Vec<Param>>);173pub struct ParamsDesc(pub Rc<Vec<Param>>);
198impl Finalize for ParamsDesc {}174
175/// Safety:
176/// AST is acyclic, and there should be no gc pointers
199unsafe impl Trace for ParamsDesc {177unsafe impl Trace for ParamsDesc {
200 unsafe_empty_trace!();178 unsafe_empty_trace!();
201}179}
180impl Finalize for ParamsDesc {}
202181
203impl Deref for ParamsDesc {182impl Deref for ParamsDesc {
204 type Target = Vec<Param>;183 type Target = Vec<Param>;
209188
210#[cfg_attr(feature = "serialize", derive(Serialize))]189#[cfg_attr(feature = "serialize", derive(Serialize))]
211#[cfg_attr(feature = "deserialize", derive(Deserialize))]190#[cfg_attr(feature = "deserialize", derive(Deserialize))]
212#[derive(Debug, PartialEq)]191#[derive(Debug, PartialEq, Trace)]
192#[trivially_drop]
213pub struct Arg(pub Option<String>, pub LocExpr);193pub struct Arg(pub Option<String>, pub LocExpr);
214impl Finalize for Arg {}
215unsafe impl Trace for Arg {
216 unsafe_empty_trace!();
217}
218194
219#[cfg_attr(feature = "serialize", derive(Serialize))]195#[cfg_attr(feature = "serialize", derive(Serialize))]
220#[cfg_attr(feature = "deserialize", derive(Deserialize))]196#[cfg_attr(feature = "deserialize", derive(Deserialize))]
221#[derive(Debug, PartialEq)]197#[derive(Debug, PartialEq, Trace)]
198#[trivially_drop]
222pub struct ArgsDesc(pub Vec<Arg>);199pub struct ArgsDesc(pub Vec<Arg>);
223impl Finalize for ArgsDesc {}
224unsafe impl Trace for ArgsDesc {
225 unsafe_empty_trace!();
226}
227200
228impl Deref for ArgsDesc {201impl Deref for ArgsDesc {
229 type Target = Vec<Arg>;202 type Target = Vec<Arg>;
234207
235#[cfg_attr(feature = "serialize", derive(Serialize))]208#[cfg_attr(feature = "serialize", derive(Serialize))]
236#[cfg_attr(feature = "deserialize", derive(Deserialize))]209#[cfg_attr(feature = "deserialize", derive(Deserialize))]
237#[derive(Debug, Clone, PartialEq)]210#[derive(Debug, Clone, PartialEq, Trace)]
211#[trivially_drop]
238pub struct BindSpec {212pub struct BindSpec {
239 pub name: IStr,213 pub name: IStr,
240 pub params: Option<ParamsDesc>,214 pub params: Option<ParamsDesc>,
241 pub value: LocExpr,215 pub value: LocExpr,
242}216}
243impl Finalize for BindSpec {}
244unsafe impl Trace for BindSpec {
245 unsafe_empty_trace!();
246}
247217
248#[cfg_attr(feature = "serialize", derive(Serialize))]218#[cfg_attr(feature = "serialize", derive(Serialize))]
249#[cfg_attr(feature = "deserialize", derive(Deserialize))]219#[cfg_attr(feature = "deserialize", derive(Deserialize))]
250#[derive(Debug, PartialEq)]220#[derive(Debug, PartialEq, Trace)]
221#[trivially_drop]
251pub struct IfSpecData(pub LocExpr);222pub struct IfSpecData(pub LocExpr);
252impl Finalize for IfSpecData {}
253unsafe impl Trace for IfSpecData {
254 unsafe_empty_trace!();
255}
256223
257#[cfg_attr(feature = "serialize", derive(Serialize))]224#[cfg_attr(feature = "serialize", derive(Serialize))]
258#[cfg_attr(feature = "deserialize", derive(Deserialize))]225#[cfg_attr(feature = "deserialize", derive(Deserialize))]
259#[derive(Debug, PartialEq)]226#[derive(Debug, PartialEq, Trace)]
227#[trivially_drop]
260pub struct ForSpecData(pub IStr, pub LocExpr);228pub struct ForSpecData(pub IStr, pub LocExpr);
261impl Finalize for ForSpecData {}
262unsafe impl Trace for ForSpecData {
263 unsafe_empty_trace!();
264}
265229
266#[cfg_attr(feature = "serialize", derive(Serialize))]230#[cfg_attr(feature = "serialize", derive(Serialize))]
267#[cfg_attr(feature = "deserialize", derive(Deserialize))]231#[cfg_attr(feature = "deserialize", derive(Deserialize))]
268#[derive(Debug, PartialEq)]232#[derive(Debug, PartialEq, Trace)]
233#[trivially_drop]
269pub enum CompSpec {234pub enum CompSpec {
270 IfSpec(IfSpecData),235 IfSpec(IfSpecData),
271 ForSpec(ForSpecData),236 ForSpec(ForSpecData),
272}237}
273impl Finalize for CompSpec {}
274unsafe impl Trace for CompSpec {
275 unsafe_empty_trace!();
276}
277238
278#[cfg_attr(feature = "serialize", derive(Serialize))]239#[cfg_attr(feature = "serialize", derive(Serialize))]
279#[cfg_attr(feature = "deserialize", derive(Deserialize))]240#[cfg_attr(feature = "deserialize", derive(Deserialize))]
280#[derive(Debug, PartialEq)]241#[derive(Debug, PartialEq, Trace)]
242#[trivially_drop]
281pub struct ObjComp {243pub struct ObjComp {
282 pub pre_locals: Vec<BindSpec>,244 pub pre_locals: Vec<BindSpec>,
283 pub key: LocExpr,245 pub key: LocExpr,
284 pub value: LocExpr,246 pub value: LocExpr,
285 pub post_locals: Vec<BindSpec>,247 pub post_locals: Vec<BindSpec>,
286 pub compspecs: Vec<CompSpec>,248 pub compspecs: Vec<CompSpec>,
287}249}
288impl Finalize for ObjComp {}
289unsafe impl Trace for ObjComp {
290 unsafe_empty_trace!();
291}
292250
293#[cfg_attr(feature = "serialize", derive(Serialize))]251#[cfg_attr(feature = "serialize", derive(Serialize))]
294#[cfg_attr(feature = "deserialize", derive(Deserialize))]252#[cfg_attr(feature = "deserialize", derive(Deserialize))]
295#[derive(Debug, PartialEq)]253#[derive(Debug, PartialEq, Trace)]
254#[trivially_drop]
296pub enum ObjBody {255pub enum ObjBody {
297 MemberList(Vec<Member>),256 MemberList(Vec<Member>),
298 ObjComp(ObjComp),257 ObjComp(ObjComp),
299}258}
300impl Finalize for ObjBody {}
301unsafe impl Trace for ObjBody {
302 unsafe_empty_trace!();
303}
304259
305#[cfg_attr(feature = "serialize", derive(Serialize))]260#[cfg_attr(feature = "serialize", derive(Serialize))]
306#[cfg_attr(feature = "deserialize", derive(Deserialize))]261#[cfg_attr(feature = "deserialize", derive(Deserialize))]
307#[derive(Debug, PartialEq, Clone, Copy)]262#[derive(Debug, PartialEq, Clone, Copy, Trace)]
263#[trivially_drop]
308pub enum LiteralType {264pub enum LiteralType {
309 This,265 This,
310 Super,266 Super,
313 True,269 True,
314 False,270 False,
315}271}
316impl Finalize for LiteralType {}
317unsafe impl Trace for LiteralType {
318 unsafe_empty_trace!();
319}
320272
321#[derive(Debug, PartialEq)]273#[derive(Debug, PartialEq, Trace)]
274#[trivially_drop]
322pub struct SliceDesc {275pub struct SliceDesc {
323 pub start: Option<LocExpr>,276 pub start: Option<LocExpr>,
324 pub end: Option<LocExpr>,277 pub end: Option<LocExpr>,
325 pub step: Option<LocExpr>,278 pub step: Option<LocExpr>,
326}279}
327impl Finalize for SliceDesc {}
328unsafe impl Trace for SliceDesc {
329 unsafe_empty_trace!();
330}
331280
332/// Syntax base281/// Syntax base
333#[cfg_attr(feature = "serialize", derive(Serialize))]282#[cfg_attr(feature = "serialize", derive(Serialize))]
334#[cfg_attr(feature = "deserialize", derive(Deserialize))]283#[cfg_attr(feature = "deserialize", derive(Deserialize))]
335#[derive(Debug, PartialEq)]284#[derive(Debug, PartialEq, Trace)]
285#[trivially_drop]
336pub enum Expr {286pub enum Expr {
337 Literal(LiteralType),287 Literal(LiteralType),
338288
396 cond_else: Option<LocExpr>,346 cond_else: Option<LocExpr>,
397 },347 },
398}348}
399impl Finalize for Expr {}
400unsafe impl Trace for Expr {
401 unsafe_empty_trace!();
402}
403349
404/// file, begin offset, end offset350/// file, begin offset, end offset
405#[cfg_attr(feature = "serialize", derive(Serialize))]351#[cfg_attr(feature = "serialize", derive(Serialize))]
406#[cfg_attr(feature = "deserialize", derive(Deserialize))]352#[cfg_attr(feature = "deserialize", derive(Deserialize))]
407#[derive(Clone, PartialEq)]353#[derive(Clone, PartialEq, Trace)]
354#[trivially_drop]
408pub struct ExprLocation(pub Rc<Path>, pub usize, pub usize);355pub struct ExprLocation(pub Rc<Path>, pub usize, pub usize);
409impl Finalize for ExprLocation {}
410unsafe impl Trace for ExprLocation {
411 unsafe_empty_trace!();
412}
413356
414impl Debug for ExprLocation {357impl Debug for ExprLocation {
415 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {358 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
422#[cfg_attr(feature = "deserialize", derive(Deserialize))]365#[cfg_attr(feature = "deserialize", derive(Deserialize))]
423#[derive(Clone, PartialEq)]366#[derive(Clone, PartialEq)]
424pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);367pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);
425impl Finalize for LocExpr {}368/// Safety:
369/// AST is acyclic, and there should be no gc pointers
426unsafe impl Trace for LocExpr {370unsafe impl Trace for LocExpr {
427 unsafe_empty_trace!();371 unsafe_empty_trace!();
428}372}
373impl Finalize for LocExpr {}
429374
430impl Debug for LocExpr {375impl Debug for LocExpr {
431 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {376 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
88
9[dependencies]9[dependencies]
10peg = "0.7.0"10peg = "0.7.0"
11gc = { version = "0.4.1", features = ["derive"] }11jrsonnet-gc = { version = "0.4.2", features = ["derive"] }
1212
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
1#![allow(clippy::redundant_closure_call)]1#![allow(clippy::redundant_closure_call)]
22
3use gc::{unsafe_empty_trace, Finalize, Trace};3use jrsonnet_gc::Trace;
4use std::fmt::Display;4use std::fmt::Display;
55
6#[macro_export]6#[macro_export]
78 );78 );
79}79}
8080
81#[derive(Debug, Clone, Copy, PartialEq, Eq)]81#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
82#[trivially_drop]
82pub enum ValType {83pub enum ValType {
83 Bool,84 Bool,
84 Null,85 Null,
88 Obj,89 Obj,
89 Func,90 Func,
90}91}
91impl Finalize for ValType {}
92unsafe impl Trace for ValType {
93 unsafe_empty_trace!();
94}
9592
96impl ValType {93impl ValType {
97 pub const fn name(&self) -> &'static str {94 pub const fn name(&self) -> &'static str {
114 }111 }
115}112}
116113
117#[derive(Debug, Clone, PartialEq)]114#[derive(Debug, Clone, PartialEq, Trace)]
115#[trivially_drop]
118pub enum ComplexValType {116pub enum ComplexValType {
119 Any,117 Any,
120 Char,118 Char,
128 Sum(Vec<ComplexValType>),126 Sum(Vec<ComplexValType>),
129 SumRef(&'static [ComplexValType]),127 SumRef(&'static [ComplexValType]),
130}128}
131impl Finalize for ComplexValType {}
132unsafe impl Trace for ComplexValType {
133 unsafe_empty_trace!();
134}
135129
136impl From<ValType> for ComplexValType {130impl From<ValType> for ComplexValType {
137 fn from(s: ValType) -> Self {131 fn from(s: ValType) -> Self {