git.delta.rocks / jrsonnet / refs/commits / 258e35110c81

difftreelog

refactor cache assertions ran

nqvyyxmlYaroslav Bolyukin2026-03-23parent: #94c438b.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth
231struct ObjValueInner {231struct ObjValueInner {
232 cores: Vec<CcObjectCore>,232 cores: Vec<CcObjectCore>,
233 assertions_ran: Cell<bool>,233 assertions_ran: Cell<bool>,
234 has_assertions: bool,
234 value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,235 value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
235}236}
236237
258 static EMPTY_OBJ: ObjValue = ObjValue(Cc::new(ObjValueInner {259 static EMPTY_OBJ: ObjValue = ObjValue(Cc::new(ObjValueInner {
259 cores: vec![],260 cores: vec![],
260 assertions_ran: Cell::new(true),261 assertions_ran: Cell::new(true),
262 has_assertions: false,
261 value_cache: RefCell::default(),263 value_cache: RefCell::default(),
262 }))264 }))
263}265}
475 pub fn extend_from(&self, sup: Self) -> Self {477 pub fn extend_from(&self, sup: Self) -> Self {
476 let mut cores = sup.0.cores.clone();478 let mut cores = sup.0.cores.clone();
477 cores.extend(self.0.cores.iter().cloned());479 cores.extend(self.0.cores.iter().cloned());
480 let has_assertions = sup.0.has_assertions || self.0.has_assertions;
478 ObjValue(Cc::new(ObjValueInner {481 ObjValue(Cc::new(ObjValueInner {
479 cores,482 cores,
480 value_cache: RefCell::default(),483 value_cache: RefCell::default(),
481 assertions_ran: Cell::new(false),484 assertions_ran: Cell::new(!has_assertions),
485 has_assertions,
482 }))486 }))
483 }487 }
484 // #[must_use]488 // #[must_use]
modifiedcrates/jrsonnet-evaluator/src/obj/oop.rsdiffbeforeafterboth
--- 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<CcObjectCore>,
+	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(),
 		}))
 	}