difftreelog
refactor unwrap Unbound thunk value
in: master
3 files changed
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth147 name: IStr,147 name: IStr,148 }148 }149 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {149 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {150 type Bound = Thunk<Val>;150 type Bound = Val;151 fn bind(151 fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {152 &self,153 sup: Option<ObjValue>,154 this: Option<ObjValue>,155 ) -> Result<Thunk<Val>> {156 Ok(Thunk::evaluated(evaluate_named(152 Ok(evaluate_named(157 self.uctx.bind(sup, this)?,153 self.uctx.bind(sup, this)?,158 &self.value,154 &self.value,159 self.name.clone(),155 self.name.clone(),160 )?))156 )?)161 }157 }162 }158 }163159191 name: IStr,187 name: IStr,192 }188 }193 impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {189 impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {194 type Bound = Thunk<Val>;190 type Bound = Val;195 fn bind(191 fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {196 &self,197 sup: Option<ObjValue>,198 this: Option<ObjValue>,199 ) -> Result<Thunk<Val>> {200 Ok(Thunk::evaluated(evaluate_method(192 Ok(evaluate_method(201 self.uctx.bind(sup, this)?,193 self.uctx.bind(sup, this)?,202 self.name.clone(),194 self.name.clone(),203 self.params.clone(),195 self.params.clone(),204 self.value.clone(),196 self.value.clone(),205 )))197 ))206 }198 }207 }199 }208200209 let name = if let Some(name) = evaluate_field_name(ctx.clone(), name)? {201 let Some(name) = evaluate_field_name(ctx.clone(), name)? else {210 name211 } else {212 continue;202 continue;213 };203 };214204276 value: LocExpr,266 value: LocExpr,277 }267 }278 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {268 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {279 type Bound = Thunk<Val>;269 type Bound = Val;280 fn bind(270 fn bind(281 &self,271 &self,282 sup: Option<ObjValue>,272 sup: Option<ObjValue>,283 this: Option<ObjValue>,273 this: Option<ObjValue>,284 ) -> Result<Thunk<Val>> {274 ) -> Result<Val> {285 Ok(Thunk::evaluated(evaluate(275 Ok(evaluate(286 self.uctx.bind(sup, this.clone())?.extend(276 self.uctx.bind(sup, this.clone())?.extend(287 GcHashMap::new(),277 GcHashMap::new(),288 None,278 None,289 None,279 None,290 this,280 this,291 ),281 ),292 &self.value,282 &self.value,293 )?))283 )?)294 }284 }295 }285 }296 builder286 buildercrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- 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<TraceBox<dyn Unbound<Bound = Thunk<Val>>>>),
+ Unbound(Cc<TraceBox<dyn Unbound<Bound = Val>>>),
/// Value is object-independent
Bound(Thunk<Val>),
}
@@ -110,10 +110,10 @@
}
impl MaybeUnbound {
/// Attach object context to value, if required
- pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Thunk<Val>> {
+ pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
match self {
Self::Unbound(v) => v.bind(sup, this),
- Self::Bound(v) => Ok(v.clone()),
+ Self::Bound(v) => Ok(v.evaluate()?),
}
}
}
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- 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<Val> {
- 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<Val>) -> Result<()> {
self.binding(MaybeUnbound::Bound(value))
}
- pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) -> Result<()> {
+ pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Val>>) -> 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<dyn Unbound<Bound = Thunk<Val>>>) {
+ pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Val>>) {
self.binding(MaybeUnbound::Unbound(Cc::new(bindable)));
}
pub fn binding(self, binding: MaybeUnbound) {