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
--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -231,6 +231,7 @@
 struct ObjValueInner {
 	cores: Vec<CcObjectCore>,
 	assertions_ran: Cell<bool>,
+	has_assertions: bool,
 	value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
 }
 
@@ -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]
modifiedcrates/jrsonnet-evaluator/src/obj/oop.rsdiffbeforeafterboth
114#[allow(clippy::module_name_repetitions)]114#[allow(clippy::module_name_repetitions)]
115pub struct ObjValueBuilder {115pub struct ObjValueBuilder {
116 sup: Vec<CcObjectCore>,116 sup: Vec<CcObjectCore>,
117 has_assertions: bool,
117118
118 new: OopObject,119 new: OopObject,
119 next_field_index: FieldIndex,120 next_field_index: FieldIndex,
125 pub fn with_capacity(capacity: usize) -> Self {126 pub fn with_capacity(capacity: usize) -> Self {
126 Self {127 Self {
127 sup: vec![],128 sup: vec![],
129 has_assertions: false,
128 new: OopObject::new(FxHashMap::with_capacity(capacity), None),130 new: OopObject::new(FxHashMap::with_capacity(capacity), None),
129 next_field_index: FieldIndex::default(),131 next_field_index: FieldIndex::default(),
130 }132 }
134 self136 self
135 }137 }
136 pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {138 pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {
139 self.has_assertions |= super_obj.0.has_assertions;
137 self.sup.clone_from(&super_obj.0.cores);140 self.sup.clone_from(&super_obj.0.cores);
138 self141 self
139 }142 }
143 self.new.assertion.is_none(),146 self.new.assertion.is_none(),
144 "one OopObject can only have one assertion"147 "one OopObject can only have one assertion"
145 );148 );
149 self.has_assertions = true;
146 self.new.assertion = Some(CcObjectAssertion::new(assertion));150 self.new.assertion = Some(CcObjectAssertion::new(assertion));
147 self151 self
148 }152 }
193 if self.sup.is_empty() {197 if self.sup.is_empty() {
194 return ObjValue::empty();198 return ObjValue::empty();
195 }199 }
200 let has_assertions = self.has_assertions;
196 ObjValue(Cc::new(ObjValueInner {201 ObjValue(Cc::new(ObjValueInner {
197 cores: self.sup,202 cores: self.sup,
198 assertions_ran: Cell::new(false),203 assertions_ran: Cell::new(!has_assertions),
204 has_assertions,
199 value_cache: RefCell::default(),205 value_cache: RefCell::default(),
200 }))206 }))
201 }207 }