--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs +++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs @@ -3,8 +3,8 @@ use gcmodule::{Cc, Trace}; use jrsonnet_interner::IStr; use jrsonnet_parser::{ - ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, ForSpecData, IfSpecData, - LiteralType, LocExpr, Member, ObjBody, ParamsDesc, + ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, FieldName, ForSpecData, + IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc, }; use jrsonnet_types::ValType; @@ -16,9 +16,9 @@ stdlib::{std_slice, BUILTINS}, tb, throw, typed::Typed, - val::{ArrValue, CachedBindable, Thunk, ThunkValue}, - Bindable, Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, - State, Val, + val::{ArrValue, CachedUnbound, Thunk, ThunkValue}, + Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, State, + Unbound, Val, }; pub mod destructure; pub mod operator; @@ -32,14 +32,10 @@ }))) } -pub fn evaluate_field_name( - s: State, - ctx: Context, - field_name: &jrsonnet_parser::FieldName, -) -> Result> { +pub fn evaluate_field_name(s: State, ctx: Context, field_name: &FieldName) -> Result> { Ok(match field_name { - jrsonnet_parser::FieldName::Fixed(n) => Some(n.clone()), - jrsonnet_parser::FieldName::Dyn(expr) => s.push( + FieldName::Fixed(n) => Some(n.clone()), + FieldName::Dyn(expr) => s.push( CallLocation::new(&expr.1), || "evaluating field name".to_string(), || { @@ -86,19 +82,19 @@ Ok(()) } -trait CloneableBindable: Bindable + Clone {} +trait CloneableUnbound: Unbound + Clone {} fn evaluate_object_locals( fctx: Pending, locals: Rc>, -) -> impl CloneableBindable { +) -> impl CloneableUnbound { #[derive(Trace, Clone)] - struct WithObjectLocals { + struct UnboundLocals { fctx: Pending, locals: Rc>, } - impl CloneableBindable for WithObjectLocals {} - impl Bindable for WithObjectLocals { + impl CloneableUnbound for UnboundLocals {} + impl Unbound for UnboundLocals { type Bound = Context; fn bind( @@ -124,7 +120,7 @@ } } - WithObjectLocals { fctx, locals } + UnboundLocals { fctx, locals } } #[allow(clippy::too_many_lines)] @@ -143,7 +139,7 @@ let fctx = Context::new_future(); // We have single context for all fields, so we can cache binds - let uctx = CachedBindable::new(evaluate_object_locals(fctx.clone(), locals)); + let uctx = CachedUnbound::new(evaluate_object_locals(fctx.clone(), locals)); for member in members.iter() { match member { @@ -155,12 +151,12 @@ value, }) => { #[derive(Trace)] - struct ObjMemberBinding { + struct UnboundValue { uctx: B, value: LocExpr, name: IStr, } - impl> Bindable for ObjMemberBinding { + impl> Unbound for UnboundValue { type Bound = Thunk; fn bind( &self, @@ -191,7 +187,7 @@ .with_location(value.1.clone()) .bindable( s.clone(), - tb!(ObjMemberBinding { + tb!(UnboundValue { uctx: uctx.clone(), value: value.clone(), name: name.clone() @@ -205,13 +201,13 @@ .. }) => { #[derive(Trace)] - struct ObjMemberBinding { + struct UnboundMethod { uctx: B, value: LocExpr, params: ParamsDesc, name: IStr, } - impl> Bindable for ObjMemberBinding { + impl> Unbound for UnboundMethod { type Bound = Thunk; fn bind( &self, @@ -240,7 +236,7 @@ .with_location(value.1.clone()) .bindable( s.clone(), - tb!(ObjMemberBinding { + tb!(UnboundMethod { uctx: uctx.clone(), value: value.clone(), params: params.clone(), @@ -255,7 +251,7 @@ uctx: B, assert: AssertStmt, } - impl> ObjectAssertion for ObjectAssert { + impl> ObjectAssertion for ObjectAssert { fn run( &self, s: State, @@ -303,11 +299,11 @@ Val::Null => {} Val::Str(n) => { #[derive(Trace)] - struct ObjCompBinding { + struct UnboundValue { uctx: B, value: LocExpr, } - impl> Bindable for ObjCompBinding { + impl> Unbound for UnboundValue { type Bound = Thunk; fn bind( &self, @@ -333,7 +329,7 @@ .with_add(obj.plus) .bindable( s.clone(), - tb!(ObjCompBinding { + tb!(UnboundValue { uctx, value: obj.value.clone(), }), --- 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, this: Option) -> Result; } #[derive(Clone, Trace)] pub enum LazyBinding { - Bindable(Cc>>>), + Bindable(Cc>>>), Bound(Thunk), } --- 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>>, + bindable: TraceBox>>, ) -> 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>>) { + pub fn bindable(self, bindable: TraceBox>>) { self.binding(LazyBinding::Bindable(Cc::new(bindable))); } pub fn binding(self, binding: LazyBinding) { --- 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, Option); #[derive(Trace, Clone)] -pub struct CachedBindable +pub struct CachedUnbound where - I: Bindable, + I: Unbound, { cache: Cc>>, value: I, } -impl, T: Trace> CachedBindable { +impl, T: Trace> CachedUnbound { pub fn new(value: I) -> Self { Self { cache: Cc::new(RefCell::new(GcHashMap::new())), @@ -89,7 +89,7 @@ } } } -impl, T: Clone + Trace> Bindable for CachedBindable { +impl, T: Clone + Trace> Unbound for CachedUnbound { type Bound = T; fn bind(&self, s: State, sup: Option, this: Option) -> Result { let cache_key = (