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
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 }