--- a/crates/jrsonnet-evaluator/src/obj/mod.rs +++ b/crates/jrsonnet-evaluator/src/obj/mod.rs @@ -231,6 +231,7 @@ struct ObjValueInner { cores: Vec, assertions_ran: Cell, + has_assertions: bool, value_cache: RefCell>, } @@ -258,6 +259,7 @@ static EMPTY_OBJ: ObjValue = ObjValue(Cc::new(ObjValueInner { cores: vec![], assertions_ran: Cell::new(true), + has_assertions: false, value_cache: RefCell::default(), })) } @@ -475,10 +477,12 @@ pub fn extend_from(&self, sup: Self) -> Self { let mut cores = sup.0.cores.clone(); cores.extend(self.0.cores.iter().cloned()); + let has_assertions = sup.0.has_assertions || self.0.has_assertions; ObjValue(Cc::new(ObjValueInner { cores, value_cache: RefCell::default(), - assertions_ran: Cell::new(false), + assertions_ran: Cell::new(!has_assertions), + has_assertions, })) } // #[must_use] --- a/crates/jrsonnet-evaluator/src/obj/oop.rs +++ b/crates/jrsonnet-evaluator/src/obj/oop.rs @@ -114,6 +114,7 @@ #[allow(clippy::module_name_repetitions)] pub struct ObjValueBuilder { sup: Vec, + has_assertions: bool, new: OopObject, next_field_index: FieldIndex, @@ -125,6 +126,7 @@ pub fn with_capacity(capacity: usize) -> Self { Self { sup: vec![], + has_assertions: false, new: OopObject::new(FxHashMap::with_capacity(capacity), None), next_field_index: FieldIndex::default(), } @@ -134,6 +136,7 @@ self } pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self { + self.has_assertions |= super_obj.0.has_assertions; self.sup.clone_from(&super_obj.0.cores); self } @@ -143,6 +146,7 @@ self.new.assertion.is_none(), "one OopObject can only have one assertion" ); + self.has_assertions = true; self.new.assertion = Some(CcObjectAssertion::new(assertion)); self } @@ -193,9 +197,11 @@ if self.sup.is_empty() { return ObjValue::empty(); } + let has_assertions = self.has_assertions; ObjValue(Cc::new(ObjValueInner { cores: self.sup, - assertions_ran: Cell::new(false), + assertions_ran: Cell::new(!has_assertions), + has_assertions, value_cache: RefCell::default(), })) }