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.rsdiffbeforeafterboth98#[derive(Clone, Trace)]98#[derive(Clone, Trace)]99pub enum MaybeUnbound {99pub enum MaybeUnbound {100 /// Value needs to be bound to `this`/`super`100 /// Value needs to be bound to `this`/`super`101 Unbound(Cc<TraceBox<dyn Unbound<Bound = Thunk<Val>>>>),101 Unbound(Cc<TraceBox<dyn Unbound<Bound = Val>>>),102 /// Value is object-independent102 /// Value is object-independent103 Bound(Thunk<Val>),103 Bound(Thunk<Val>),104}104}110}110}111impl MaybeUnbound {111impl MaybeUnbound {112 /// Attach object context to value, if required112 /// Attach object context to value, if required113 pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Thunk<Val>> {113 pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {114 match self {114 match self {115 Self::Unbound(v) => v.bind(sup, this),115 Self::Unbound(v) => v.bind(sup, this),116 Self::Bound(v) => Ok(v.clone()),116 Self::Bound(v) => Ok(v.evaluate()?),117 }117 }118 }118 }119}119}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) {