difftreelog
refactor unwrap Unbound thunk value
in: master
3 files changed
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -147,17 +147,13 @@
name: IStr,
}
impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
- type Bound = Thunk<Val>;
- fn bind(
- &self,
- sup: Option<ObjValue>,
- this: Option<ObjValue>,
- ) -> Result<Thunk<Val>> {
- Ok(Thunk::evaluated(evaluate_named(
+ type Bound = Val;
+ fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
+ Ok(evaluate_named(
self.uctx.bind(sup, this)?,
&self.value,
self.name.clone(),
- )?))
+ )?)
}
}
@@ -191,24 +187,18 @@
name: IStr,
}
impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {
- type Bound = Thunk<Val>;
- fn bind(
- &self,
- sup: Option<ObjValue>,
- this: Option<ObjValue>,
- ) -> Result<Thunk<Val>> {
- Ok(Thunk::evaluated(evaluate_method(
+ type Bound = Val;
+ fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
+ 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<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
- type Bound = Thunk<Val>;
+ type Bound = Val;
fn bind(
&self,
sup: Option<ObjValue>,
this: Option<ObjValue>,
- ) -> Result<Thunk<Val>> {
- Ok(Thunk::evaluated(evaluate(
+ ) -> Result<Val> {
+ Ok(evaluate(
self.uctx.bind(sup, this.clone())?.extend(
GcHashMap::new(),
None,
@@ -290,7 +280,7 @@
this,
),
&self.value,
- )?))
+ )?)
}
}
builder
crates/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.rsdiffbeforeafterboth441 }441 }442 fn evaluate_this(&self, v: &ObjMember, real_this: Self) -> Result<Val> {442 fn evaluate_this(&self, v: &ObjMember, real_this: Self) -> Result<Val> {443 v.invoke443 v.invoke.evaluate(self.0.sup.clone(), Some(real_this))444 .evaluate(self.0.sup.clone(), Some(real_this))?445 .evaluate()446 }444 }447445448 fn run_assertions_raw(&self, real_this: &Self) -> Result<()> {446 fn run_assertions_raw(&self, real_this: &Self) -> Result<()> {605 pub fn thunk(self, value: Thunk<Val>) -> Result<()> {603 pub fn thunk(self, value: Thunk<Val>) -> Result<()> {606 self.binding(MaybeUnbound::Bound(value))604 self.binding(MaybeUnbound::Bound(value))607 }605 }608 pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) -> Result<()> {606 pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Val>>) -> Result<()> {609 self.binding(MaybeUnbound::Unbound(Cc::new(bindable)))607 self.binding(MaybeUnbound::Unbound(Cc::new(bindable)))610 }608 }611 pub fn binding(self, binding: MaybeUnbound) -> Result<()> {609 pub fn binding(self, binding: MaybeUnbound) -> Result<()> {628 pub fn value(self, value: Val) {626 pub fn value(self, value: Val) {629 self.binding(MaybeUnbound::Bound(Thunk::evaluated(value)));627 self.binding(MaybeUnbound::Bound(Thunk::evaluated(value)));630 }628 }631 pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {629 pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Val>>) {632 self.binding(MaybeUnbound::Unbound(Cc::new(bindable)));630 self.binding(MaybeUnbound::Unbound(Cc::new(bindable)));633 }631 }634 pub fn binding(self, binding: MaybeUnbound) {632 pub fn binding(self, binding: MaybeUnbound) {