difftreelog
perf specialize super.field gets
in: master
4 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -139,7 +139,7 @@
}
fn main_real(s: &State, opts: Opts) -> Result<(), Error> {
- let (_stack_guard, tla, _gc_guard) = opts.general.configure(s)?;
+ let (tla, _gc_guard) = opts.general.configure(s)?;
let manifest_format = opts.manifest.configure(s)?;
let input = opts.input.input.ok_or(Error::MissingInputArgument)?;
crates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -6,9 +6,7 @@
use std::{env, marker::PhantomData, path::PathBuf};
use clap::Parser;
-use jrsonnet_evaluator::{
- error::Result, stack::StackDepthLimitOverrideGuard, FileImportResolver, State,
-};
+use jrsonnet_evaluator::{error::Result, stack::set_stack_depth_limit, FileImportResolver, State};
use jrsonnet_gcmodule::with_thread_object_space;
pub use manifest::*;
pub use stdlib::*;
@@ -48,7 +46,7 @@
jpath: Vec<PathBuf>,
}
impl ConfigureState for MiscOpts {
- type Guards = StackDepthLimitOverrideGuard;
+ type Guards = ();
fn configure(&self, s: &State) -> Result<Self::Guards> {
let mut library_paths = self.jpath.clone();
library_paths.reverse();
@@ -58,8 +56,8 @@
s.set_import_resolver(Box::new(FileImportResolver::new(library_paths)));
- let _depth_limit = jrsonnet_evaluator::stack::limit_stack_depth(self.max_stack);
- Ok(_depth_limit)
+ set_stack_depth_limit(self.max_stack);
+ Ok(())
}
}
@@ -81,17 +79,16 @@
impl ConfigureState for GeneralOpts {
type Guards = (
- <MiscOpts as ConfigureState>::Guards,
<TlaOpts as ConfigureState>::Guards,
<GcOpts as ConfigureState>::Guards,
);
fn configure(&self, s: &State) -> Result<Self::Guards> {
// Configure trace first, because tla-code/ext-code can throw
- let misc_guards = self.misc.configure(s)?;
+ self.misc.configure(s)?;
let tla_guards = self.tla.configure(s)?;
self.std.configure(s)?;
let gc_guards = self.gc.configure(s)?;
- Ok((misc_guards, tla_guards, gc_guards))
+ Ok((tla_guards, gc_guards))
}
}
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth389 ctx.super_obj().clone().ok_or(NoSuperFound)?.with_this(389 ctx.super_obj().clone().ok_or(NoSuperFound)?.with_this(390 ctx.this()390 ctx.this()391 .clone()391 .clone()392 .expect("if super exists - then this should to"),392 .expect("if super exists - then this should too"),393 ),393 ),394 ),394 ),395 Literal(LiteralType::Dollar) => {395 Literal(LiteralType::Dollar) => {408 || format!("variable <{name}> access"),408 || format!("variable <{name}> access"),409 || ctx.binding(name.clone())?.evaluate(),409 || ctx.binding(name.clone())?.evaluate(),410 )?,410 )?,411 Index(LocExpr(v, _), index) if matches!(&**v, Expr::Literal(LiteralType::Super)) => {412 let name = evaluate(ctx.clone(), index)?;413 let Val::Str(name) = name else {414 throw!(ValueIndexMustBeTypeGot(415 ValType::Obj,416 ValType::Str,417 name.value_type(),418 ))419 };420 ctx.super_obj()421 .clone()422 .expect("no super found")423 .get_for(name, ctx.this().clone().expect("no this found"))?424 .expect("value not found")425 }411 Index(value, index) => match (evaluate(ctx.clone(), value)?, evaluate(ctx, index)?) {426 Index(value, index) => match (evaluate(ctx.clone(), value)?, evaluate(ctx, index)?) {412 (Val::Obj(v), Val::Str(key)) => State::push(427 (Val::Obj(v), Val::Str(key)) => State::push(413 CallLocation::new(loc),428 CallLocation::new(loc),crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -128,7 +128,7 @@
assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,
assertions_ran: RefCell<GcHashSet<ObjValue>>,
this_entries: Cc<GcHashMap<IStr, ObjMember>>,
- value_cache: RefCell<GcHashMap<IStr, CacheValue>>,
+ value_cache: RefCell<GcHashMap<(IStr, Option<WeakObjValue>), CacheValue>>,
}
#[derive(Clone, Trace)]
@@ -387,7 +387,8 @@
pub fn get(&self, key: IStr) -> Result<Option<Val>> {
self.run_assertions()?;
- if let Some(v) = self.0.value_cache.borrow().get(&key) {
+ let cache_key = (key.clone(), None);
+ if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {
return Ok(match v {
CacheValue::Cached(v) => Some(v.clone()),
CacheValue::NotFound => None,
@@ -398,21 +399,48 @@
self.0
.value_cache
.borrow_mut()
- .insert(key.clone(), CacheValue::Pending);
+ .insert(cache_key.clone(), CacheValue::Pending);
let value = self
- .get_raw(
- key.clone(),
- self.0.this.clone().unwrap_or_else(|| self.clone()),
- )
+ .get_raw(key, self.0.this.clone().unwrap_or_else(|| self.clone()))
.map_err(|e| {
self.0
.value_cache
.borrow_mut()
- .insert(key.clone(), CacheValue::Errored(e.clone()));
+ .insert(cache_key.clone(), CacheValue::Errored(e.clone()));
e
})?;
self.0.value_cache.borrow_mut().insert(
- key,
+ cache_key,
+ value
+ .as_ref()
+ .map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),
+ );
+ Ok(value)
+ }
+ pub fn get_for(&self, key: IStr, this: Self) -> Result<Option<Val>> {
+ self.run_assertions()?;
+ let cache_key = (key.clone(), Some(this.clone().downgrade()));
+ if let Some(v) = self.0.value_cache.borrow().get(&cache_key) {
+ return Ok(match v {
+ CacheValue::Cached(v) => Some(v.clone()),
+ CacheValue::NotFound => None,
+ CacheValue::Pending => throw!(InfiniteRecursionDetected),
+ CacheValue::Errored(e) => return Err(e.clone()),
+ });
+ }
+ self.0
+ .value_cache
+ .borrow_mut()
+ .insert(cache_key.clone(), CacheValue::Pending);
+ let value = self.get_raw(key, this).map_err(|e| {
+ self.0
+ .value_cache
+ .borrow_mut()
+ .insert(cache_key.clone(), CacheValue::Errored(e.clone()));
+ e
+ })?;
+ self.0.value_cache.borrow_mut().insert(
+ cache_key,
value
.as_ref()
.map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),