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
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -60,14 +60,14 @@
 use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};
 pub use val::{ManifestFormat, Thunk, Val};
 
-pub trait Bindable: Trace + 'static {
+pub trait Unbound: Trace {
 	type Bound;
 	fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Self::Bound>;
 }
 
 #[derive(Clone, Trace)]
 pub enum LazyBinding {
-	Bindable(Cc<TraceBox<dyn Bindable<Bound = Thunk<Val>>>>),
+	Bindable(Cc<TraceBox<dyn Unbound<Bound = Thunk<Val>>>>),
 	Bound(Thunk<Val>),
 }
 
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -16,7 +16,7 @@
 	function::CallLocation,
 	gc::{GcHashMap, GcHashSet, TraceBox},
 	operator::evaluate_add_op,
-	throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, Result, State, Thunk, Val,
+	throw, weak_ptr_eq, weak_raw, LazyBinding, Result, State, Thunk, Unbound, Val,
 };
 
 #[cfg(not(feature = "exp-preserve-order"))]
@@ -589,7 +589,7 @@
 	pub fn bindable(
 		self,
 		s: State,
-		bindable: TraceBox<dyn Bindable<Bound = Thunk<Val>>>,
+		bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>,
 	) -> Result<()> {
 		self.binding(s, LazyBinding::Bindable(Cc::new(bindable)))
 	}
@@ -613,7 +613,7 @@
 	pub fn value(self, value: Val) {
 		self.binding(LazyBinding::Bound(Thunk::evaluated(value)));
 	}
-	pub fn bindable(self, bindable: TraceBox<dyn Bindable<Bound = Thunk<Val>>>) {
+	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {
 		self.binding(LazyBinding::Bindable(Cc::new(bindable)));
 	}
 	pub fn binding(self, binding: LazyBinding) {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -12,7 +12,7 @@
 	stdlib::manifest::{
 		manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,
 	},
-	throw, Bindable, ObjValue, Result, State, WeakObjValue,
+	throw, ObjValue, Result, State, Unbound, WeakObjValue,
 };
 
 pub trait ThunkValue: Trace {
@@ -74,14 +74,14 @@
 type CacheKey = (Option<WeakObjValue>, Option<WeakObjValue>);
 
 #[derive(Trace, Clone)]
-pub struct CachedBindable<I, T>
+pub struct CachedUnbound<I, T>
 where
-	I: Bindable<Bound = T>,
+	I: Unbound<Bound = T>,
 {
 	cache: Cc<RefCell<GcHashMap<CacheKey, T>>>,
 	value: I,
 }
-impl<I: Bindable<Bound = T>, T: Trace> CachedBindable<I, T> {
+impl<I: Unbound<Bound = T>, T: Trace> CachedUnbound<I, T> {
 	pub fn new(value: I) -> Self {
 		Self {
 			cache: Cc::new(RefCell::new(GcHashMap::new())),
@@ -89,7 +89,7 @@
 		}
 	}
 }
-impl<I: Bindable<Bound = T>, T: Clone + Trace> Bindable for CachedBindable<I, T> {
+impl<I: Unbound<Bound = T>, T: Clone + Trace> Unbound for CachedUnbound<I, T> {
 	type Bound = T;
 	fn bind(&self, s: State, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<T> {
 		let cache_key = (