From c607d6bc4efe4447492fe4520fc4734a38aac2f8 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 03 Nov 2022 22:16:41 +0000 Subject: [PATCH] refactor: unwrap Unbound thunk value --- --- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs +++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs @@ -147,17 +147,13 @@ name: IStr, } impl> Unbound for UnboundValue { - type Bound = Thunk; - fn bind( - &self, - sup: Option, - this: Option, - ) -> Result> { - Ok(Thunk::evaluated(evaluate_named( + type Bound = Val; + fn bind(&self, sup: Option, this: Option) -> Result { + Ok(evaluate_named( self.uctx.bind(sup, this)?, &self.value, self.name.clone(), - )?)) + )?) } } @@ -191,24 +187,18 @@ name: IStr, } impl> Unbound for UnboundMethod { - type Bound = Thunk; - fn bind( - &self, - sup: Option, - this: Option, - ) -> Result> { - Ok(Thunk::evaluated(evaluate_method( + type Bound = Val; + fn bind(&self, sup: Option, this: Option) -> Result { + Ok(evaluate_method( self.uctx.bind(sup, this)?, self.name.clone(), self.params.clone(), self.value.clone(), - ))) + )) } } - let name = if let Some(name) = evaluate_field_name(ctx.clone(), name)? { - name - } else { + let Some(name) = evaluate_field_name(ctx.clone(), name)? else { continue; }; @@ -276,13 +266,13 @@ value: LocExpr, } impl> Unbound for UnboundValue { - type Bound = Thunk; + type Bound = Val; fn bind( &self, sup: Option, this: Option, - ) -> Result> { - Ok(Thunk::evaluated(evaluate( + ) -> Result { + Ok(evaluate( self.uctx.bind(sup, this.clone())?.extend( GcHashMap::new(), None, @@ -290,7 +280,7 @@ this, ), &self.value, - )?)) + )?) } } builder --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -98,7 +98,7 @@ #[derive(Clone, Trace)] pub enum MaybeUnbound { /// Value needs to be bound to `this`/`super` - Unbound(Cc>>>), + Unbound(Cc>>), /// Value is object-independent Bound(Thunk), } @@ -110,10 +110,10 @@ } impl MaybeUnbound { /// Attach object context to value, if required - pub fn evaluate(&self, sup: Option, this: Option) -> Result> { + pub fn evaluate(&self, sup: Option, this: Option) -> Result { match self { Self::Unbound(v) => v.bind(sup, this), - Self::Bound(v) => Ok(v.clone()), + Self::Bound(v) => Ok(v.evaluate()?), } } } --- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -440,9 +440,7 @@ } } fn evaluate_this(&self, v: &ObjMember, real_this: Self) -> Result { - v.invoke - .evaluate(self.0.sup.clone(), Some(real_this))? - .evaluate() + v.invoke.evaluate(self.0.sup.clone(), Some(real_this)) } fn run_assertions_raw(&self, real_this: &Self) -> Result<()> { @@ -605,7 +603,7 @@ pub fn thunk(self, value: Thunk) -> Result<()> { self.binding(MaybeUnbound::Bound(value)) } - pub fn bindable(self, bindable: TraceBox>>) -> Result<()> { + pub fn bindable(self, bindable: TraceBox>) -> Result<()> { self.binding(MaybeUnbound::Unbound(Cc::new(bindable))) } pub fn binding(self, binding: MaybeUnbound) -> Result<()> { @@ -628,7 +626,7 @@ pub fn value(self, value: Val) { self.binding(MaybeUnbound::Bound(Thunk::evaluated(value))); } - pub fn bindable(self, bindable: TraceBox>>) { + pub fn bindable(self, bindable: TraceBox>) { self.binding(MaybeUnbound::Unbound(Cc::new(bindable))); } pub fn binding(self, binding: MaybeUnbound) { -- gitstuff