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

difftreelog

style rename bindable -> unbound

Yaroslav Bolyukin2022-04-24parent: #c65967c.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
3use gcmodule::{Cc, Trace};3use gcmodule::{Cc, Trace};
4use jrsonnet_interner::IStr;4use jrsonnet_interner::IStr;
5use jrsonnet_parser::{5use jrsonnet_parser::{
6 ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, ForSpecData, IfSpecData,6 ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, FieldName, ForSpecData,
7 LiteralType, LocExpr, Member, ObjBody, ParamsDesc,7 IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc,
8};8};
9use jrsonnet_types::ValType;9use jrsonnet_types::ValType;
16 stdlib::{std_slice, BUILTINS},16 stdlib::{std_slice, BUILTINS},
17 tb, throw,17 tb, throw,
18 typed::Typed,18 typed::Typed,
19 val::{ArrValue, CachedBindable, Thunk, ThunkValue},19 val::{ArrValue, CachedUnbound, Thunk, ThunkValue},
20 Bindable, Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,20 Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, State,
21 State, Val,21 Unbound, Val,
22};22};
23pub mod destructure;23pub mod destructure;
24pub mod operator;24pub mod operator;
35pub fn evaluate_field_name(35pub fn evaluate_field_name(s: State, ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {
36 s: State,
37 ctx: Context,
38 field_name: &jrsonnet_parser::FieldName,
39) -> Result<Option<IStr>> {
40 Ok(match field_name {36 Ok(match field_name {
41 jrsonnet_parser::FieldName::Fixed(n) => Some(n.clone()),37 FieldName::Fixed(n) => Some(n.clone()),
42 jrsonnet_parser::FieldName::Dyn(expr) => s.push(38 FieldName::Dyn(expr) => s.push(
43 CallLocation::new(&expr.1),39 CallLocation::new(&expr.1),
44 || "evaluating field name".to_string(),40 || "evaluating field name".to_string(),
45 || {41 || {
86 Ok(())82 Ok(())
87}83}
8884
89trait CloneableBindable<T>: Bindable<Bound = T> + Clone {}85trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}
9086
91fn evaluate_object_locals(87fn evaluate_object_locals(
92 fctx: Pending<Context>,88 fctx: Pending<Context>,
93 locals: Rc<Vec<BindSpec>>,89 locals: Rc<Vec<BindSpec>>,
94) -> impl CloneableBindable<Context> {90) -> impl CloneableUnbound<Context> {
95 #[derive(Trace, Clone)]91 #[derive(Trace, Clone)]
96 struct WithObjectLocals {92 struct UnboundLocals {
97 fctx: Pending<Context>,93 fctx: Pending<Context>,
98 locals: Rc<Vec<BindSpec>>,94 locals: Rc<Vec<BindSpec>>,
99 }95 }
100 impl CloneableBindable<Context> for WithObjectLocals {}96 impl CloneableUnbound<Context> for UnboundLocals {}
101 impl Bindable for WithObjectLocals {97 impl Unbound for UnboundLocals {
102 type Bound = Context;98 type Bound = Context;
10399
104 fn bind(100 fn bind(
124 }120 }
125 }121 }
126122
127 WithObjectLocals { fctx, locals }123 UnboundLocals { fctx, locals }
128}124}
129125
130#[allow(clippy::too_many_lines)]126#[allow(clippy::too_many_lines)]
143 let fctx = Context::new_future();139 let fctx = Context::new_future();
144140
145 // We have single context for all fields, so we can cache binds141 // We have single context for all fields, so we can cache binds
146 let uctx = CachedBindable::new(evaluate_object_locals(fctx.clone(), locals));142 let uctx = CachedUnbound::new(evaluate_object_locals(fctx.clone(), locals));
147143
148 for member in members.iter() {144 for member in members.iter() {
149 match member {145 match member {
155 value,151 value,
156 }) => {152 }) => {
157 #[derive(Trace)]153 #[derive(Trace)]
158 struct ObjMemberBinding<B> {154 struct UnboundValue<B> {
159 uctx: B,155 uctx: B,
160 value: LocExpr,156 value: LocExpr,
161 name: IStr,157 name: IStr,
162 }158 }
163 impl<B: Bindable<Bound = Context>> Bindable for ObjMemberBinding<B> {159 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
164 type Bound = Thunk<Val>;160 type Bound = Thunk<Val>;
165 fn bind(161 fn bind(
166 &self,162 &self,
191 .with_location(value.1.clone())187 .with_location(value.1.clone())
192 .bindable(188 .bindable(
193 s.clone(),189 s.clone(),
194 tb!(ObjMemberBinding {190 tb!(UnboundValue {
195 uctx: uctx.clone(),191 uctx: uctx.clone(),
196 value: value.clone(),192 value: value.clone(),
197 name: name.clone()193 name: name.clone()
205 ..201 ..
206 }) => {202 }) => {
207 #[derive(Trace)]203 #[derive(Trace)]
208 struct ObjMemberBinding<B> {204 struct UnboundMethod<B> {
209 uctx: B,205 uctx: B,
210 value: LocExpr,206 value: LocExpr,
211 params: ParamsDesc,207 params: ParamsDesc,
212 name: IStr,208 name: IStr,
213 }209 }
214 impl<B: Bindable<Bound = Context>> Bindable for ObjMemberBinding<B> {210 impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {
215 type Bound = Thunk<Val>;211 type Bound = Thunk<Val>;
216 fn bind(212 fn bind(
217 &self,213 &self,
240 .with_location(value.1.clone())236 .with_location(value.1.clone())
241 .bindable(237 .bindable(
242 s.clone(),238 s.clone(),
243 tb!(ObjMemberBinding {239 tb!(UnboundMethod {
244 uctx: uctx.clone(),240 uctx: uctx.clone(),
245 value: value.clone(),241 value: value.clone(),
246 params: params.clone(),242 params: params.clone(),
255 uctx: B,251 uctx: B,
256 assert: AssertStmt,252 assert: AssertStmt,
257 }253 }
258 impl<B: Bindable<Bound = Context>> ObjectAssertion for ObjectAssert<B> {254 impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {
259 fn run(255 fn run(
260 &self,256 &self,
261 s: State,257 s: State,
303 Val::Null => {}299 Val::Null => {}
304 Val::Str(n) => {300 Val::Str(n) => {
305 #[derive(Trace)]301 #[derive(Trace)]
306 struct ObjCompBinding<B> {302 struct UnboundValue<B> {
307 uctx: B,303 uctx: B,
308 value: LocExpr,304 value: LocExpr,
309 }305 }
310 impl<B: Bindable<Bound = Context>> Bindable for ObjCompBinding<B> {306 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
311 type Bound = Thunk<Val>;307 type Bound = Thunk<Val>;
312 fn bind(308 fn bind(
313 &self,309 &self,
333 .with_add(obj.plus)329 .with_add(obj.plus)
334 .bindable(330 .bindable(
335 s.clone(),331 s.clone(),
336 tb!(ObjCompBinding {332 tb!(UnboundValue {
337 uctx,333 uctx,
338 value: obj.value.clone(),334 value: obj.value.clone(),
339 }),335 }),
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
60use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};60use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};
61pub use val::{ManifestFormat, Thunk, Val};61pub use val::{ManifestFormat, Thunk, Val};
6262
63pub trait Bindable: Trace + 'static {63pub trait Unbound: Trace {
64 type Bound;64 type Bound;
65 fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Self::Bound>;65 fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Self::Bound>;
66}66}
6767
68#[derive(Clone, Trace)]68#[derive(Clone, Trace)]
69pub enum LazyBinding {69pub enum LazyBinding {
70 Bindable(Cc<TraceBox<dyn Bindable<Bound = Thunk<Val>>>>),70 Bindable(Cc<TraceBox<dyn Unbound<Bound = Thunk<Val>>>>),
71 Bound(Thunk<Val>),71 Bound(Thunk<Val>),
72}72}
7373
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
16 function::CallLocation,16 function::CallLocation,
17 gc::{GcHashMap, GcHashSet, TraceBox},17 gc::{GcHashMap, GcHashSet, TraceBox},
18 operator::evaluate_add_op,18 operator::evaluate_add_op,
19 throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, Result, State, Thunk, Val,19 throw, weak_ptr_eq, weak_raw, LazyBinding, Result, State, Thunk, Unbound, Val,
20};20};
2121
22#[cfg(not(feature = "exp-preserve-order"))]22#[cfg(not(feature = "exp-preserve-order"))]
589 pub fn bindable(589 pub fn bindable(
590 self,590 self,
591 s: State,591 s: State,
592 bindable: TraceBox<dyn Bindable<Bound = Thunk<Val>>>,592 bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>,
593 ) -> Result<()> {593 ) -> Result<()> {
594 self.binding(s, LazyBinding::Bindable(Cc::new(bindable)))594 self.binding(s, LazyBinding::Bindable(Cc::new(bindable)))
595 }595 }
613 pub fn value(self, value: Val) {613 pub fn value(self, value: Val) {
614 self.binding(LazyBinding::Bound(Thunk::evaluated(value)));614 self.binding(LazyBinding::Bound(Thunk::evaluated(value)));
615 }615 }
616 pub fn bindable(self, bindable: TraceBox<dyn Bindable<Bound = Thunk<Val>>>) {616 pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {
617 self.binding(LazyBinding::Bindable(Cc::new(bindable)));617 self.binding(LazyBinding::Bindable(Cc::new(bindable)));
618 }618 }
619 pub fn binding(self, binding: LazyBinding) {619 pub fn binding(self, binding: LazyBinding) {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
12 stdlib::manifest::{12 stdlib::manifest::{
13 manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,13 manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,
14 },14 },
15 throw, Bindable, ObjValue, Result, State, WeakObjValue,15 throw, ObjValue, Result, State, Unbound, WeakObjValue,
16};16};
1717
18pub trait ThunkValue: Trace {18pub trait ThunkValue: Trace {
74type CacheKey = (Option<WeakObjValue>, Option<WeakObjValue>);74type CacheKey = (Option<WeakObjValue>, Option<WeakObjValue>);
7575
76#[derive(Trace, Clone)]76#[derive(Trace, Clone)]
77pub struct CachedBindable<I, T>77pub struct CachedUnbound<I, T>
78where78where
79 I: Bindable<Bound = T>,79 I: Unbound<Bound = T>,
80{80{
81 cache: Cc<RefCell<GcHashMap<CacheKey, T>>>,81 cache: Cc<RefCell<GcHashMap<CacheKey, T>>>,
82 value: I,82 value: I,
83}83}
84impl<I: Bindable<Bound = T>, T: Trace> CachedBindable<I, T> {84impl<I: Unbound<Bound = T>, T: Trace> CachedUnbound<I, T> {
85 pub fn new(value: I) -> Self {85 pub fn new(value: I) -> Self {
86 Self {86 Self {
87 cache: Cc::new(RefCell::new(GcHashMap::new())),87 cache: Cc::new(RefCell::new(GcHashMap::new())),
88 value,88 value,
89 }89 }
90 }90 }
91}91}
92impl<I: Bindable<Bound = T>, T: Clone + Trace> Bindable for CachedBindable<I, T> {92impl<I: Unbound<Bound = T>, T: Clone + Trace> Unbound for CachedUnbound<I, T> {
93 type Bound = T;93 type Bound = T;
94 fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<T> {94 fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<T> {
95 let cache_key = (95 let cache_key = (