git.delta.rocks / jrsonnet / refs/commits / 3c9d13d48c21

difftreelog

feat OOP-aware objectRemoveKey

zkxotrvkYaroslav Bolyukin2026-02-08parent: #5ac33cf.patch.diff
in: master

17 files changed

modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -56,5 +56,5 @@
 /// Make a `JsonnetJsonValue` representing an object.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_object(_vm: &VM) -> *mut Val {
-	Box::into_raw(Box::new(Val::Obj(ObjValue::new_empty())))
+	Box::into_raw(Box::new(Val::Obj(ObjValue::empty())))
 }
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -1,5 +1,7 @@
 use clap::Parser;
-use jrsonnet_evaluator::{IStr, error::Result, function::TlaArg, gc::WithCapacityExt as _, rustc_hash::FxHashMap};
+use jrsonnet_evaluator::{
+	error::Result, function::TlaArg, gc::WithCapacityExt as _, rustc_hash::FxHashMap, IStr,
+};
 
 use crate::{ExtFile, ExtStr};
 
modifiedcrates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/dynamic.rs
+++ b/crates/jrsonnet-evaluator/src/dynamic.rs
@@ -1,5 +1,4 @@
-use std::ptr::addr_of;
-use std::{cell::OnceCell, hash::Hasher};
+use std::{cell::OnceCell, hash::Hasher, ptr::addr_of};
 
 use educe::Educe;
 use jrsonnet_gcmodule::{Cc, Trace};
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/evaluate/mod.rs
1use std::rc::Rc;23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;5use jrsonnet_parser::{6	ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, FieldMember, FieldName,7	ForSpecData, IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc,8};9use jrsonnet_types::ValType;10use rustc_hash::FxHashMap;1112use self::destructure::destruct;13use crate::{14	Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, ResultExt, SupThis, Unbound, Val, arr::ArrValue, bail, destructure::evaluate_dest, error::{ErrorKind::*, suggest_object_fields}, evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op}, function::{CallLocation, FuncDesc, FuncVal}, gc::WithCapacityExt as _, in_frame, typed::Typed, val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk}, with_state15};16pub mod destructure;17pub mod operator;1819// This is the amount of bytes that need to be left on the stack before increasing the size.20// It must be at least as large as the stack required by any code that does not call21// `ensure_sufficient_stack`.22const RED_ZONE: usize = 100 * 1024; // 100k2324// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then25// on. This flag has performance relevant characteristics. Don't set it too high.26const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB2728/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations29/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit30/// from this.31///32/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.33#[inline]34pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {35	stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)36}3738pub fn evaluate_trivial(expr: &LocExpr) -> Option<Val> {39	fn is_trivial(expr: &LocExpr) -> bool {40		match expr.expr() {41			Expr::Str(_)42			| Expr::Num(_)43			| Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,44			Expr::Arr(a) => a.iter().all(is_trivial),45			Expr::Parened(e) => is_trivial(e),46			_ => false,47		}48	}49	Some(match expr.expr() {50		Expr::Str(s) => Val::string(s.clone()),51		Expr::Num(n) => {52			Val::Num(NumValue::new(*n).expect("parser will not allow non-finite values"))53		}54		Expr::Literal(LiteralType::False) => Val::Bool(false),55		Expr::Literal(LiteralType::True) => Val::Bool(true),56		Expr::Literal(LiteralType::Null) => Val::Null,57		Expr::Arr(n) => {58			if n.iter().any(|e| !is_trivial(e)) {59				return None;60			}61			Val::Arr(ArrValue::eager(62				n.iter()63					.map(evaluate_trivial)64					.map(|e| e.expect("checked trivial"))65					.collect(),66			))67		}68		Expr::Parened(e) => evaluate_trivial(e)?,69		_ => return None,70	})71}7273pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {74	Val::Func(FuncVal::Normal(Cc::new(FuncDesc {75		name,76		ctx,77		params,78		body,79	})))80}8182pub fn evaluate_field_name(ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {83	Ok(match field_name {84		FieldName::Fixed(n) => Some(n.clone()),85		FieldName::Dyn(expr) => in_frame(86			CallLocation::new(&expr.span()),87			|| "evaluating field name".to_string(),88			|| {89				let value = evaluate(ctx, expr)?;90				if matches!(value, Val::Null) {91					Ok(None)92				} else {93					Ok(Some(IStr::from_untyped(value)?))94				}95			},96		)?,97	})98}99100pub fn evaluate_comp(101	ctx: Context,102	specs: &[CompSpec],103	callback: &mut impl FnMut(Context) -> Result<()>,104) -> Result<()> {105	match specs.first() {106		None => callback(ctx)?,107		Some(CompSpec::IfSpec(IfSpecData(cond))) => {108			if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {109				evaluate_comp(ctx, &specs[1..], callback)?;110			}111		}112		Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(ctx.clone(), expr)? {113			Val::Arr(list) => {114				for item in list.iter_lazy() {115					let fctx = Pending::new();116					let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());117					destruct(var, item, fctx.clone(), &mut new_bindings)?;118					let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);119120					evaluate_comp(ctx, &specs[1..], callback)?;121				}122			}123			#[cfg(feature = "exp-object-iteration")]124			Val::Obj(obj) => {125				for field in obj.fields(126					// TODO: Should there be ability to preserve iteration order?127					#[cfg(feature = "exp-preserve-order")]128					false,129				) {130					let fctx = Pending::new();131					let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());132					let obj = obj.clone();133					let value = Thunk::evaluated(Val::Arr(ArrValue::lazy(vec![134						Thunk::evaluated(Val::string(field.clone())),135						Thunk!(move || obj.get(field).transpose().expect(136							"field exists, as field name was obtained from object.fields()",137						)),138					])));139					destruct(var, value, fctx.clone(), &mut new_bindings)?;140					let ctx = ctx141						.clone()142						.extend(new_bindings, None, None, None)143						.into_future(fctx);144145					evaluate_comp(ctx, &specs[1..], callback)?;146				}147			}148			_ => bail!(InComprehensionCanOnlyIterateOverArray),149		},150	}151	Ok(())152}153154trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}155impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}156157fn evaluate_object_locals(158	fctx: Context,159	locals: Rc<Vec<BindSpec>>,160) -> impl CloneableUnbound<Context> {161	#[derive(Trace, Clone)]162	struct UnboundLocals {163		fctx: Context,164		locals: Rc<Vec<BindSpec>>,165	}166	impl Unbound for UnboundLocals {167		type Bound = Context;168169		fn bind(&self, sup_this: SupThis) -> Result<Context> {170			let fctx = Context::new_future();171			let mut new_bindings =172				FxHashMap::with_capacity(self.locals.iter().map(BindSpec::capacity_hint).sum());173			for b in self.locals.iter() {174				evaluate_dest(b, fctx.clone(), &mut new_bindings)?;175			}176177			let ctx = self.fctx.clone();178179			let ctx = ctx180				.extend_bindings_sup_this(new_bindings, sup_this)181				.into_future(fctx);182183			Ok(ctx)184		}185	}186187	UnboundLocals { fctx, locals }188}189190pub fn evaluate_field_member<B: Unbound<Bound = Context> + Clone>(191	builder: &mut ObjValueBuilder,192	ctx: Context,193	uctx: B,194	field: &FieldMember,195) -> Result<()> {196	let name = evaluate_field_name(ctx, &field.name)?;197	let Some(name) = name else {198		return Ok(());199	};200201	match field {202		FieldMember {203			plus,204			params: None,205			visibility,206			value,207			..208		} => {209			#[derive(Trace)]210			struct UnboundValue<B: Trace> {211				uctx: B,212				value: LocExpr,213				name: IStr,214			}215			impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {216				type Bound = Val;217				fn bind(&self, sup_this: SupThis) -> Result<Val> {218					evaluate_named(self.uctx.bind(sup_this)?, &self.value, self.name.clone())219				}220			}221222			builder223				.field(name.clone())224				.with_add(*plus)225				.with_visibility(*visibility)226				.with_location(value.span())227				.bindable(UnboundValue {228					uctx,229					value: value.clone(),230					name,231				})?;232		}233		FieldMember {234			params: Some(params),235			visibility,236			value,237			..238		} => {239			#[derive(Trace)]240			struct UnboundMethod<B: Trace> {241				uctx: B,242				value: LocExpr,243				params: ParamsDesc,244				name: IStr,245			}246			impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {247				type Bound = Val;248				fn bind(&self, sup_this: SupThis) -> Result<Val> {249					Ok(evaluate_method(250						self.uctx.bind(sup_this)?,251						self.name.clone(),252						self.params.clone(),253						self.value.clone(),254					))255				}256			}257258			builder259				.field(name.clone())260				.with_visibility(*visibility)261				.with_location(value.span())262				.bindable(UnboundMethod {263					uctx,264					value: value.clone(),265					params: params.clone(),266					name,267				})?;268		}269	}270	Ok(())271}272273#[allow(clippy::too_many_lines)]274pub fn evaluate_member_list_object(ctx: Context, members: &[Member]) -> Result<ObjValue> {275	let mut builder = ObjValueBuilder::new();276	let locals = Rc::new(277		members278			.iter()279			.filter_map(|m| match m {280				Member::BindStmt(bind) => Some(bind.clone()),281				_ => None,282			})283			.collect::<Vec<_>>(),284	);285286	// We have single context for all fields, so we can cache binds287	let uctx = CachedUnbound::new(evaluate_object_locals(ctx.clone(), locals));288289	for member in members {290		match member {291			Member::Field(field) => {292				evaluate_field_member(&mut builder, ctx.clone(), uctx.clone(), field)?;293			}294			Member::AssertStmt(stmt) => {295				#[derive(Trace)]296				struct ObjectAssert<B: Trace> {297					uctx: B,298					assert: AssertStmt,299				}300				impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {301					fn run(&self, sup_this: SupThis) -> Result<()> {302						let ctx = self.uctx.bind(sup_this)?;303						evaluate_assert(ctx, &self.assert)304					}305				}306				builder.assert(ObjectAssert {307					uctx: uctx.clone(),308					assert: stmt.clone(),309				});310			}311			Member::BindStmt(_) => {312				// Already handled313			}314		}315	}316	Ok(builder.build())317}318319pub fn evaluate_object(ctx: Context, object: &ObjBody) -> Result<ObjValue> {320	Ok(match object {321		ObjBody::MemberList(members) => evaluate_member_list_object(ctx, members)?,322		ObjBody::ObjComp(obj) => {323			let mut builder = ObjValueBuilder::new();324			let locals = Rc::new(325				obj.pre_locals326					.iter()327					.chain(obj.post_locals.iter())328					.cloned()329					.collect::<Vec<_>>(),330			);331			evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {332				let uctx = evaluate_object_locals(ctx.clone(), locals.clone());333334				evaluate_field_member(&mut builder, ctx, uctx, &obj.field)335			})?;336337			builder.build()338		}339	})340}341342pub fn evaluate_apply(343	ctx: Context,344	value: &LocExpr,345	args: &ArgsDesc,346	loc: CallLocation<'_>,347	tailstrict: bool,348) -> Result<Val> {349	let value = evaluate(ctx.clone(), value)?;350	Ok(match value {351		Val::Func(f) => {352			let body = || f.evaluate(ctx, loc, args, tailstrict);353			if tailstrict {354				body()?355			} else {356				in_frame(loc, || format!("function <{}> call", f.name()), body)?357			}358		}359		v => bail!(OnlyFunctionsCanBeCalledGot(v.value_type())),360	})361}362363pub fn evaluate_assert(ctx: Context, assertion: &AssertStmt) -> Result<()> {364	let value = &assertion.0;365	let msg = &assertion.1;366	let assertion_result = in_frame(367		CallLocation::new(&value.span()),368		|| "assertion condition".to_owned(),369		|| bool::from_untyped(evaluate(ctx.clone(), value)?),370	)?;371	if !assertion_result {372		in_frame(373			CallLocation::new(&value.span()),374			|| "assertion failure".to_owned(),375			|| {376				if let Some(msg) = msg {377					bail!(AssertionFailed(evaluate(ctx, msg)?.to_string()?));378				}379				bail!(AssertionFailed(Val::Null.to_string()?));380			},381		)?;382	}383	Ok(())384}385386pub fn evaluate_named(ctx: Context, expr: &LocExpr, name: IStr) -> Result<Val> {387	use Expr::*;388	Ok(match expr.expr() {389		Function(params, body) => evaluate_method(ctx, name, params.clone(), body.clone()),390		_ => evaluate(ctx, expr)?,391	})392}393394#[allow(clippy::too_many_lines)]395pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {396	use Expr::*;397398	if let Some(trivial) = evaluate_trivial(expr) {399		return Ok(trivial);400	}401	let loc = expr.span();402	Ok(match expr.expr() {403		Literal(LiteralType::This) => Val::Obj(ctx.try_this()?),404		Literal(LiteralType::Super) => Val::Obj(ctx.try_sup_this()?.standalone_super()?),405		Literal(LiteralType::Dollar) => Val::Obj(ctx.try_dollar()?),406		Literal(LiteralType::True) => Val::Bool(true),407		Literal(LiteralType::False) => Val::Bool(false),408		Literal(LiteralType::Null) => Val::Null,409		Parened(e) => evaluate(ctx, e)?,410		Str(v) => Val::string(v.clone()),411		Num(v) => Val::try_num(*v)?,412		// I have tried to remove special behavior from super by implementing standalone-super413		// expresion, but looks like this case still needs special treatment.414		//415		// Note that other jsonnet implementations will fail on `if value in (super)` expression,416		// because the standalone super literal is not supported, that is because in other417		// implementations `in super` treated differently from `in smth_else`.418		BinaryOp(field, BinaryOpType::In, e)419			if matches!(e.expr(), Expr::Literal(LiteralType::Super)) =>420		{421			let sup_this = ctx.try_sup_this()?;422			// In jsonnet, "field" in e is eager, LHS expression is always executed regardless of super existence.423			// In jrsonnet, however, this wasn't true, this was kept here for compatibility.424			if !sup_this.has_super() {425				return Ok(Val::Bool(false));426			}427			let field = evaluate(ctx, field)?;428			Val::Bool(sup_this.field_in_super(field.to_string()?))429		}430		BinaryOp(v1, o, v2) => evaluate_binary_op_special(ctx, v1, *o, v2)?,431		UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,432		Var(name) => in_frame(433			CallLocation::new(&loc),434			|| format!("local <{name}> access"),435			|| ctx.binding(name.clone())?.evaluate(),436		)?,437		Index { indexable, parts } => ensure_sufficient_stack(|| {438			let mut parts = parts.iter();439			let mut indexable = if matches!(indexable.expr(), Expr::Literal(LiteralType::Super)) {440				let part = parts.next().expect("at least part should exist");441				// sup_this existence check might also be skipped here for null-coalesce...442				// But I believe this might cause errors.443				let sup_this = ctx.try_sup_this()?;444				if !sup_this.has_super() {445					#[cfg(feature = "exp-null-coaelse")]446					if part.null_coaelse {447						return Ok(Val::Null);448					}449					bail!(NoSuperFound)450				}451				let name = evaluate(ctx.clone(), &part.value)?;452453				let Val::Str(name) = name else {454					bail!(ValueIndexMustBeTypeGot(455						ValType::Obj,456						ValType::Str,457						name.value_type(),458					))459				};460461				let name = name.into_flat();462				match sup_this463					.get_super(name.clone())464					.with_description_src(&part.value, || format!("field <{name}> access"))?465				{466					Some(v) => v,467					#[cfg(feature = "exp-null-coaelse")]468					None if part.null_coaelse => return Ok(Val::Null),469					None => {470						let suggestions = suggest_object_fields(471							&sup_this.standalone_super().expect("super exists"),472							name.clone(),473						);474475						bail!(NoSuchField(name, suggestions))476					}477				}478			} else {479				evaluate(ctx.clone(), indexable)?480			};481482			for part in parts {483				indexable = match (indexable, evaluate(ctx.clone(), &part.value)?) {484					(Val::Obj(v), Val::Str(key)) => match v485						.get(key.clone().into_flat())486						.with_description_src(&part.value, || format!("field <{key}> access"))?487					{488						Some(v) => v,489						#[cfg(feature = "exp-null-coaelse")]490						None if part.null_coaelse => return Ok(Val::Null),491						None => {492							let suggestions = suggest_object_fields(&v, key.clone().into_flat());493494							return Err(Error::from(NoSuchField(495								key.clone().into_flat(),496								suggestions,497							)))498							.with_description_src(&part.value, || format!("field <{key}> access"));499						}500					},501					(Val::Obj(_), n) => bail!(ValueIndexMustBeTypeGot(502						ValType::Obj,503						ValType::Str,504						n.value_type(),505					)),506					(Val::Arr(v), Val::Num(n)) => {507						let n = n.get();508						if n.fract() > f64::EPSILON {509							bail!(FractionalIndex)510						}511						if n < 0.0 {512							bail!(ArrayBoundsError(n as isize, v.len()));513						}514						v.get(n as usize)?515							.ok_or_else(|| ArrayBoundsError(n as isize, v.len()))?516					}517					(Val::Arr(_), Val::Str(n)) => {518						bail!(AttemptedIndexAnArrayWithString(n.into_flat()))519					}520					(Val::Arr(_), n) => bail!(ValueIndexMustBeTypeGot(521						ValType::Arr,522						ValType::Num,523						n.value_type(),524					)),525526					(Val::Str(s), Val::Num(n)) => Val::Str({527						let v: IStr = s528							.clone()529							.into_flat()530							.chars()531							.skip(n.get() as usize)532							.take(1)533							.collect::<String>()534							.into();535						if v.is_empty() {536							let size = s.into_flat().chars().count();537							bail!(StringBoundsError(n.get() as usize, size))538						}539						StrValue::Flat(v)540					}),541					(Val::Str(_), n) => bail!(ValueIndexMustBeTypeGot(542						ValType::Str,543						ValType::Num,544						n.value_type(),545					)),546					#[cfg(feature = "exp-null-coaelse")]547					(Val::Null, _) if part.null_coaelse => return Ok(Val::Null),548					(v, _) => bail!(CantIndexInto(v.value_type())),549				};550			}551			Ok(indexable)552		})?,553		LocalExpr(bindings, returned) => {554			let mut new_bindings: FxHashMap<IStr, Thunk<Val>> =555				FxHashMap::with_capacity(bindings.iter().map(BindSpec::capacity_hint).sum());556			let fctx = Context::new_future();557			for b in bindings {558				evaluate_dest(b, fctx.clone(), &mut new_bindings)?;559			}560			let ctx = ctx.extend_bindings(new_bindings).into_future(fctx);561			evaluate(ctx, &returned.clone())?562		}563		Arr(items) => {564			if items.is_empty() {565				Val::Arr(ArrValue::empty())566			} else if items.len() == 1 {567				let item = items[0].clone();568				Val::Arr(ArrValue::lazy(vec![Thunk!(move || evaluate(ctx, &item))]))569			} else {570				Val::Arr(ArrValue::expr(ctx, items.iter().cloned()))571			}572		}573		ArrComp(expr, comp_specs) => {574			let mut out = Vec::new();575			evaluate_comp(ctx, comp_specs, &mut |ctx| {576				let expr = expr.clone();577				out.push(Thunk!(move || evaluate(ctx, &expr)));578				Ok(())579			})?;580			Val::Arr(ArrValue::lazy(out))581		}582		Obj(body) => Val::Obj(evaluate_object(ctx, body)?),583		ObjExtend(a, b) => evaluate_add_op(584			&evaluate(ctx.clone(), a)?,585			&Val::Obj(evaluate_object(ctx, b)?),586		)?,587		Apply(value, args, tailstrict) => ensure_sufficient_stack(|| {588			evaluate_apply(ctx, value, args, CallLocation::new(&loc), *tailstrict)589		})?,590		Function(params, body) => {591			evaluate_method(ctx, "anonymous".into(), params.clone(), body.clone())592		}593		AssertExpr(assert, returned) => {594			evaluate_assert(ctx.clone(), assert)?;595			evaluate(ctx, returned)?596		}597		ErrorStmt(e) => in_frame(598			CallLocation::new(&loc),599			|| "error statement".to_owned(),600			|| bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),601		)?,602		IfElse {603			cond,604			cond_then,605			cond_else,606		} => {607			if in_frame(608				CallLocation::new(&loc),609				|| "if condition".to_owned(),610				|| bool::from_untyped(evaluate(ctx.clone(), &cond.0)?),611			)? {612				evaluate(ctx, cond_then)?613			} else {614				match cond_else {615					Some(v) => evaluate(ctx, v)?,616					None => Val::Null,617				}618			}619		}620		Slice(value, desc) => {621			fn parse_idx<T: Typed>(622				loc: CallLocation<'_>,623				ctx: Context,624				expr: Option<&LocExpr>,625				desc: &'static str,626			) -> Result<Option<T>> {627				if let Some(value) = expr {628					Ok(in_frame(629						loc,630						|| format!("slice {desc}"),631						|| <Option<T>>::from_untyped(evaluate(ctx, value)?),632					)?)633				} else {634					Ok(None)635				}636			}637638			let indexable = evaluate(ctx.clone(), value)?;639			let loc = CallLocation::new(&loc);640641			let start = parse_idx(loc, ctx.clone(), desc.start.as_ref(), "start")?;642			let end = parse_idx(loc, ctx.clone(), desc.end.as_ref(), "end")?;643			let step = parse_idx(loc, ctx, desc.step.as_ref(), "step")?;644645			IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?646		}647		i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {648			let Expr::Str(path) = &path.expr() else {649				bail!("computed imports are not supported")650			};651			let tmp = loc.clone().0;652			with_state(|s| {653				let resolved_path = s.resolve_from(tmp.source_path(), path)?;654				Ok(match i {655					Import(_) => in_frame(656						CallLocation::new(&loc),657						|| format!("import {:?}", path.clone()),658						|| s.import_resolved(resolved_path),659					)?,660					ImportStr(_) => Val::string(s.import_resolved_str(resolved_path)?),661					ImportBin(_) => {662						Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?))663					}664					_ => unreachable!(),665				}) as Result<Val>666			})?667		}668	})669}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -27,11 +27,11 @@
 use std::{
 	any::Any,
 	cell::{RefCell, RefMut},
+	clone::Clone,
 	collections::hash_map::Entry,
-	clone::Clone,
 	fmt::{self, Debug},
+	marker::PhantomData,
 	rc::Rc,
-	marker::PhantomData,
 };
 
 pub use ctx::*;
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -4,10 +4,12 @@
 	collections::hash_map::Entry,
 	fmt::{self, Debug},
 	hash::{Hash, Hasher},
+	mem,
+	ops::ControlFlow,
 };
 
 use educe::Educe;
-use jrsonnet_gcmodule::{cc_dyn, Cc, Trace, Weak};
+use jrsonnet_gcmodule::{cc_dyn, Acyclic, Cc, Trace, Weak};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{Span, Visibility};
 use rustc_hash::{FxHashMap, FxHashSet};
@@ -74,7 +76,7 @@
 	pub struct SuperDepth(u32);
 	impl SuperDepth {
 		pub(super) fn deepen(&mut self) {
-			*self.0 += 1
+			self.0 += 1
 		}
 	}
 
@@ -151,31 +153,56 @@
 }
 
 #[allow(clippy::module_name_repetitions)]
-#[derive(Trace)]
+#[derive(Trace, Default)]
 #[trace(tracking(force))]
 pub struct OopObject {
-	// this: Option<ObjValue>,
-	assertions: Cc<Vec<CcObjectAssertion>>,
-	this_entries: Cc<FxHashMap<IStr, ObjMember>>,
-	value_cache: RefCell<FxHashMap<(IStr, Option<WeakObjValue>), CacheValue>>,
+	assertions: Vec<CcObjectAssertion>,
+	this_entries: FxHashMap<IStr, ObjMember>,
 }
 impl Debug for OopObject {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		f.debug_struct("OopObject")
-			// .field("assertions", &self.assertions)
-			// .field("assertions_ran", &self.assertions_ran)
 			.field("this_entries", &self.this_entries)
-			// .field("value_cache", &self.value_cache)
 			.finish_non_exhaustive()
 	}
 }
+impl OopObject {
+	fn is_empty(&self) -> bool {
+		self.assertions.is_empty() && self.this_entries.is_empty()
+	}
+}
 
-type EnumFieldsHandler<'a> = dyn FnMut(SuperDepth, FieldIndex, IStr, Visibility) -> bool + 'a;
+type EnumFieldsHandler<'a> =
+	dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;
 
+pub enum EnumFields {
+	Normal(Visibility),
+	Omit,
+}
+
 #[derive(Trace, Clone)]
-pub enum ValueProcess {
-	None,
-	SuperPlus,
+pub enum GetFor {
+	// Return value
+	Final(Val),
+	// Continue iterating over cores, add current value to sum stack
+	SuperPlus(Val),
+	// Ignore the field value, stop at this layer instead
+	Omit,
+	NotFound,
+}
+
+#[derive(Acyclic, Clone)]
+pub enum FieldVisibility {
+	Found(Visibility),
+	Omit,
+	NotFound,
+}
+
+#[derive(Acyclic, Clone)]
+pub enum HasFieldIncludeHidden {
+	Exists,
+	NotFound,
+	Omit,
 }
 
 pub trait ObjectCore: Trace + Any + Debug {
@@ -186,13 +213,12 @@
 		handler: &mut EnumFieldsHandler<'_>,
 	) -> bool;
 
-	fn has_field_include_hidden(&self, name: IStr) -> bool;
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden;
 
-	fn get_for(&self, key: IStr, sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>>;
-	// fn get_for_uncached(&self, key: IStr, this: ObjValue) -> Result<Option<(Val, ValueProcess)>>;
-	fn field_visibility(&self, field: IStr) -> Option<Visibility>;
+	fn get_for_core(&self, key: IStr, sup_this: SupThis) -> Result<GetFor>;
+	fn field_visibility_core(&self, field: IStr) -> FieldVisibility;
 
-	fn run_assertions_raw(&self, sup_this: SupThis) -> Result<()>;
+	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()>;
 }
 
 #[derive(Clone, Trace)]
@@ -220,13 +246,13 @@
 
 cc_dyn!(
 	#[derive(Clone, Debug)]
-	ObjCore, ObjectCore,
+	CcObjectCore, ObjectCore,
 	pub fn new() {...}
 );
 #[derive(Trace, Educe)]
 #[educe(Debug)]
 struct ObjValueInner {
-	cores: Vec<ObjCore>,
+	cores: Vec<CcObjectCore>,
 	assertions_ran: Cell<bool>,
 	value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
 }
@@ -251,6 +277,14 @@
 	});
 }
 
+thread_local! {
+	static EMPTY_OBJ: ObjValue = ObjValue(Cc::new(ObjValueInner {
+		cores: vec![],
+		assertions_ran: Cell::new(true),
+		value_cache: Default::default(),
+	}))
+}
+
 #[allow(clippy::module_name_repetitions)]
 #[derive(Clone, Trace, Debug, Educe)]
 #[educe(PartialEq, Hash, Eq)]
@@ -258,6 +292,15 @@
 	#[educe(PartialEq(method(Cc::ptr_eq)), Hash(method(identity_hash)))] Cc<ObjValueInner>,
 );
 
+impl ObjValue {
+	pub fn empty() -> Self {
+		EMPTY_OBJ.with(|v| v.clone())
+	}
+	pub fn is_empty(&self) -> bool {
+		self.0.cores.is_empty() || self.len() == 0
+	}
+}
+
 #[derive(Trace, Debug)]
 struct StandaloneSuperCore {
 	sup: CoreIdx,
@@ -269,53 +312,77 @@
 		super_depth: &mut SuperDepth,
 		handler: &mut EnumFieldsHandler<'_>,
 	) -> bool {
-		self.this
-			.enum_fields_internal(super_depth, handler, self.sup)
+		self.this.enum_fields_idx(super_depth, handler, self.sup)
 	}
 
-	fn has_field_include_hidden(&self, name: IStr) -> bool {
-		self.this.has_field_include_hidden_idx(name, self.sup)
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
+		if self.this.has_field_include_hidden_idx(name, self.sup) {
+			HasFieldIncludeHidden::Exists
+		} else {
+			HasFieldIncludeHidden::NotFound
+		}
 	}
 
-	fn get_for(&self, key: IStr, _sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
+	fn get_for_core(&self, key: IStr, _sup_this: SupThis) -> Result<GetFor> {
 		let v = self.this.get_idx(key, self.sup)?;
-		Ok(v.map(|v| (v, ValueProcess::None)))
+		Ok(v.map_or(GetFor::NotFound, |v| GetFor::Final(v)))
 	}
 
-	fn field_visibility(&self, field: IStr) -> Option<Visibility> {
-		self.this.field_visibility_idx(field, self.sup)
+	fn field_visibility_core(&self, field: IStr) -> FieldVisibility {
+		match self.this.field_visibility_idx(field, self.sup) {
+			Some(c) => FieldVisibility::Found(c),
+			None => FieldVisibility::NotFound,
+		}
 	}
 
-	fn run_assertions_raw(&self, _sup_this: SupThis) -> Result<()> {
+	fn run_assertions_core(&self, _sup_this: SupThis) -> Result<()> {
 		self.this.run_assertions()
 	}
 }
 
-#[derive(Debug, Trace)]
-struct EmptyObject;
-impl ObjectCore for EmptyObject {
+#[derive(Debug, Acyclic)]
+struct OmitFieldsCore {
+	omit: FxHashSet<IStr>,
+}
+impl ObjectCore for OmitFieldsCore {
 	fn enum_fields_core(
 		&self,
-		_super_depth: &mut SuperDepth,
-		_handler: &mut EnumFieldsHandler<'_>,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
 	) -> bool {
+		let mut fi = FieldIndex::default();
+		for f in &self.omit {
+			if let ControlFlow::Break(()) = handler(*super_depth, fi, f.clone(), EnumFields::Omit) {
+				return false;
+			}
+			fi = fi.next();
+		}
 		true
 	}
 
-	fn has_field_include_hidden(&self, _name: IStr) -> bool {
-		false
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
+		if self.omit.contains(&name) {
+			return HasFieldIncludeHidden::Omit;
+		}
+		HasFieldIncludeHidden::NotFound
 	}
 
-	fn get_for(&self, _key: IStr, _sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
-		Ok(None)
+	fn get_for_core(&self, key: IStr, _sup_this: SupThis) -> Result<GetFor> {
+		if self.omit.contains(&key) {
+			return Ok(GetFor::Omit);
+		}
+		Ok(GetFor::NotFound)
 	}
 
-	fn run_assertions_raw(&self, _sup_this: SupThis) -> Result<()> {
-		Ok(())
+	fn field_visibility_core(&self, field: IStr) -> FieldVisibility {
+		if self.omit.contains(&field) {
+			return FieldVisibility::Omit;
+		}
+		FieldVisibility::NotFound
 	}
 
-	fn field_visibility(&self, _field: IStr) -> Option<Visibility> {
-		None
+	fn run_assertions_core(&self, _sup_this: SupThis) -> Result<()> {
+		Ok(())
 	}
 }
 
@@ -363,10 +430,12 @@
 		if !self.sup.super_exists() {
 			bail!(NoSuperFound)
 		}
-		Ok(ObjValue::new(StandaloneSuperCore {
+		let mut out = ObjValue::builder();
+		out.reserve_cores(1).extend_with_core(StandaloneSuperCore {
 			sup: self.sup,
 			this: self.this.clone(),
-		}))
+		});
+		Ok(out.build())
 	}
 	pub fn this(&self) -> &ObjValue {
 		&self.this
@@ -385,16 +454,6 @@
 }
 
 impl ObjValue {
-	pub fn new(v: impl ObjectCore) -> Self {
-		Self(Cc::new(ObjValueInner {
-			cores: vec![ObjCore::new(v)],
-			assertions_ran: Cell::new(false),
-			value_cache: RefCell::new(FxHashMap::new()),
-		}))
-	}
-	pub fn new_empty() -> Self {
-		Self::new(EmptyObject)
-	}
 	pub fn builder() -> ObjValueBuilder {
 		ObjValueBuilder::new()
 	}
@@ -420,6 +479,12 @@
 		ObjMemberBuilder::new(ExtendBuilder(self), name, FieldIndex::default())
 	}
 
+	pub fn extend(&mut self) -> ObjValueBuilder {
+		let mut out = ObjValueBuilder::new();
+		out.with_super(self.clone());
+		out
+	}
+
 	#[must_use]
 	pub fn extend_from(&self, sup: Self) -> Self {
 		let mut cores = sup.0.cores.clone();
@@ -442,16 +507,13 @@
 			.filter(|(_, (visible, _))| *visible)
 			.count()
 	}
-	pub fn is_empty(&self) -> bool {
-		self.len() == 0
-	}
 	/// For each field, calls callback.
 	/// If callback returns false - ends iteration prematurely.
 	///
 	/// Returns false if ended prematurely
 	pub fn enum_fields(&self, handler: &mut EnumFieldsHandler<'_>) -> bool {
 		let mut super_depth = SuperDepth::default();
-		self.enum_fields_internal(
+		self.enum_fields_idx(
 			&mut super_depth,
 			handler,
 			CoreIdx {
@@ -459,7 +521,7 @@
 			},
 		)
 	}
-	fn enum_fields_internal(
+	fn enum_fields_idx(
 		&self,
 		super_depth: &mut SuperDepth,
 		handler: &mut EnumFieldsHandler<'_>,
@@ -483,10 +545,14 @@
 		)
 	}
 	fn has_field_include_hidden_idx(&self, name: IStr, core: CoreIdx) -> bool {
-		self.0.cores[..core.idx]
-			.iter()
-			.rev()
-			.any(|v| v.0.has_field_include_hidden(name.clone()))
+		for ele in self.0.cores[..core.idx].iter().rev() {
+			match ele.0.has_field_include_hidden_core(name.clone()) {
+				HasFieldIncludeHidden::Exists => return true,
+				HasFieldIncludeHidden::NotFound => {}
+				HasFieldIncludeHidden::Omit => break,
+			}
+		}
+		false
 	}
 	pub fn has_field(&self, name: IStr) -> bool {
 		match self.field_visibility(name) {
@@ -544,16 +610,20 @@
 				sup: CoreIdx { idx: sup },
 				this: self.clone(),
 			};
-			if let Some((val, proc)) = core.0.get_for(key.clone(), sup_this)? {
-				match proc {
-					ValueProcess::None if add_stack.is_empty() => return Ok(Some(val)),
-					ValueProcess::None => {
-						add_stack.push(val);
-						break;
-					}
-					ValueProcess::SuperPlus => {
-						add_stack.push(val);
-					}
+			match core.0.get_for_core(key.clone(), sup_this)? {
+				GetFor::Final(val) if add_stack.is_empty() => return Ok(Some(val)),
+				GetFor::Final(val) => {
+					add_stack.push(val);
+					break;
+				}
+				GetFor::SuperPlus(val) => {
+					add_stack.push(val);
+				}
+				GetFor::Omit => {
+					break;
+				}
+				GetFor::NotFound => {
+					continue;
 				}
 			}
 		}
@@ -594,11 +664,14 @@
 	fn field_visibility_idx(&self, field: IStr, core: CoreIdx) -> Option<Visibility> {
 		let mut exists = false;
 		for ele in self.0.cores[..core.idx].iter().rev() {
-			let vis = ele.0.field_visibility(field.clone());
+			let vis = ele.0.field_visibility_core(field.clone());
 			match vis {
-				Some(Visibility::Unhide | Visibility::Hidden) => return vis,
-				Some(Visibility::Normal) => exists = true,
-				None => {}
+				FieldVisibility::Found(vis @ (Visibility::Unhide | Visibility::Hidden)) => {
+					return Some(vis)
+				}
+				FieldVisibility::Found(Visibility::Normal) => exists = true,
+				FieldVisibility::NotFound => {}
+				FieldVisibility::Omit => break,
 			}
 		}
 		exists.then_some(Visibility::Normal)
@@ -616,7 +689,7 @@
 				sup: CoreIdx { idx },
 				this: self.clone(),
 			};
-			ele.0.run_assertions_raw(sup_this).inspect_err(|_e| {
+			ele.0.run_assertions_core(sup_this).inspect_err(|_e| {
 				finish_asserting(self);
 			})?;
 		}
@@ -664,17 +737,24 @@
 		self.enum_fields(&mut |depth, index, name, visibility| {
 			let new_sort_key = FieldSortKey::new(depth, index);
 			let entry = out.entry(name);
+			if matches!(visibility, EnumFields::Omit) {
+				if let Entry::Occupied(v) = entry {
+					v.remove();
+				}
+				return ControlFlow::Continue(());
+			}
 			let (visible, _) = entry.or_insert((true, new_sort_key));
 			match visibility {
-				Visibility::Normal => {}
-				Visibility::Hidden => {
+				EnumFields::Omit => unreachable!(),
+				EnumFields::Normal(Visibility::Normal) => {}
+				EnumFields::Normal(Visibility::Hidden) => {
 					*visible = false;
 				}
-				Visibility::Unhide => {
+				EnumFields::Normal(Visibility::Unhide) => {
 					*visible = true;
 				}
 			};
-			false
+			return ControlFlow::Continue(());
 		});
 		out
 	}
@@ -776,12 +856,11 @@
 
 impl OopObject {
 	pub fn new(
-		this_entries: Cc<FxHashMap<IStr, ObjMember>>,
-		assertions: Cc<Vec<CcObjectAssertion>>,
+		this_entries: FxHashMap<IStr, ObjMember>,
+		assertions: Vec<CcObjectAssertion>,
 	) -> Self {
 		Self {
 			this_entries,
-			value_cache: RefCell::new(FxHashMap::new()),
 			assertions,
 		}
 	}
@@ -794,11 +873,14 @@
 		handler: &mut EnumFieldsHandler<'_>,
 	) -> bool {
 		for (name, member) in self.this_entries.iter() {
-			if handler(
-				*super_depth,
-				member.original_index,
-				name.clone(),
-				member.flags.visibility(),
+			if matches!(
+				handler(
+					*super_depth,
+					member.original_index,
+					name.clone(),
+					EnumFields::Normal(member.flags.visibility()),
+				),
+				ControlFlow::Break(())
 			) {
 				return false;
 			}
@@ -806,28 +888,35 @@
 		true
 	}
 
-	fn has_field_include_hidden(&self, name: IStr) -> bool {
-		self.this_entries.contains_key(&name)
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
+		if self.this_entries.contains_key(&name) {
+			HasFieldIncludeHidden::Exists
+		} else {
+			HasFieldIncludeHidden::NotFound
+		}
 	}
 
-	fn get_for(&self, key: IStr, sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
+	fn get_for_core(&self, key: IStr, sup_this: SupThis) -> Result<GetFor> {
 		match self.this_entries.get(&key) {
-			Some(k) => Ok(Some((
-				k.invoke.evaluate(sup_this)?,
-				if k.flags.add() {
-					ValueProcess::SuperPlus
+			Some(k) => {
+				let v = k.invoke.evaluate(sup_this)?;
+				Ok(if k.flags.add() {
+					GetFor::SuperPlus(v)
 				} else {
-					ValueProcess::None
-				},
-			))),
-			None => Ok(None),
+					GetFor::Final(v)
+				})
+			}
+			None => Ok(GetFor::NotFound),
 		}
 	}
-	fn field_visibility(&self, name: IStr) -> Option<Visibility> {
-		Some(self.this_entries.get(&name)?.flags.visibility())
+	fn field_visibility_core(&self, name: IStr) -> FieldVisibility {
+		match self.this_entries.get(&name) {
+			Some(f) => FieldVisibility::Found(f.flags.visibility()),
+			None => FieldVisibility::NotFound,
+		}
 	}
 
-	fn run_assertions_raw(&self, sup_this: SupThis) -> Result<()> {
+	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {
 		if self.assertions.is_empty() {
 			return Ok(());
 		}
@@ -840,9 +929,9 @@
 
 #[allow(clippy::module_name_repetitions)]
 pub struct ObjValueBuilder {
-	sup: Option<ObjValue>,
-	map: FxHashMap<IStr, ObjMember>,
-	assertions: Vec<CcObjectAssertion>,
+	sup: Vec<CcObjectCore>,
+
+	new: OopObject,
 	next_field_index: FieldIndex,
 }
 impl ObjValueBuilder {
@@ -851,23 +940,29 @@
 	}
 	pub fn with_capacity(capacity: usize) -> Self {
 		Self {
-			sup: None,
-			map: FxHashMap::with_capacity(capacity),
-			assertions: Vec::new(),
+			sup: vec![],
+			new: OopObject {
+				assertions: vec![],
+				this_entries: FxHashMap::with_capacity(capacity),
+			},
 			next_field_index: FieldIndex::default(),
 		}
 	}
+	pub fn reserve_cores(&mut self, capacity: usize) -> &mut Self {
+		self.sup.reserve_exact(capacity);
+		self
+	}
 	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {
-		self.assertions.reserve_exact(capacity);
+		self.new.assertions.reserve_exact(capacity);
 		self
 	}
 	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {
-		self.sup = Some(super_obj);
+		self.sup = super_obj.0.cores.clone();
 		self
 	}
 
 	pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {
-		self.assertions.push(CcObjectAssertion::new(assertion));
+		self.new.assertions.push(CcObjectAssertion::new(assertion));
 		self
 	}
 	pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {
@@ -892,12 +987,33 @@
 		Ok(self)
 	}
 
-	pub fn build(self) -> ObjValue {
-		if self.sup.is_none() && self.map.is_empty() && self.assertions.is_empty() {
-			return ObjValue::new_empty();
+	pub fn extend_with_core(&mut self, core: impl ObjectCore) {
+		self.commit();
+		self.sup.push(CcObjectCore::new(core));
+	}
+
+	fn commit(&mut self) {
+		if !self.new.is_empty() {
+			self.sup.push(CcObjectCore::new(mem::take(&mut self.new)));
+		}
+		self.next_field_index = FieldIndex::default();
+	}
+
+	pub fn with_fields_omitted(&mut self, omit: FxHashSet<IStr>) {
+		self.commit();
+		self.sup.push(CcObjectCore::new(OmitFieldsCore { omit }));
+	}
+
+	pub fn build(mut self) -> ObjValue {
+		self.commit();
+		if self.sup.is_empty() {
+			return ObjValue::empty();
 		}
-		let res = ObjValue::new(OopObject::new(Cc::new(self.map), Cc::new(self.assertions)));
-		self.sup.map(|sup| res.extend_from(sup)).unwrap_or(res)
+		ObjValue(Cc::new(ObjValueInner {
+			cores: self.sup,
+			assertions_ran: Cell::new(false),
+			value_cache: Default::default(),
+		}))
 	}
 }
 impl Default for ObjValueBuilder {
@@ -968,7 +1084,7 @@
 	pub fn value(self, value: impl Into<Val>) {
 		let (receiver, name, member) =
 			self.build_member(MaybeUnbound::Bound(Thunk::evaluated(value.into())));
-		let entry = receiver.0.map.entry(name);
+		let entry = receiver.0.new.this_entries.entry(name);
 		entry.insert_entry(member);
 	}
 
@@ -985,7 +1101,7 @@
 	pub fn binding(self, binding: MaybeUnbound) -> Result<()> {
 		let (receiver, name, member) = self.build_member(binding);
 		let location = member.location.clone();
-		let old = receiver.0.map.insert(name.clone(), member);
+		let old = receiver.0.new.this_entries.insert(name.clone(), member);
 		if old.is_some() {
 			in_frame(
 				CallLocation(location.as_ref()),
modifiedcrates/jrsonnet-stdlib/src/manifest/xml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/xml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/xml.rs
@@ -62,10 +62,10 @@
 			if let Val::Obj(attrs) = maybe_attrs {
 				(true, attrs)
 			} else {
-				(false, ObjValue::new_empty())
+				(false, ObjValue::empty())
 			}
 		} else {
-			(false, ObjValue::new_empty())
+			(false, ObjValue::empty())
 		};
 		Ok(Self::Tag {
 			tag,
modifiedcrates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -172,7 +172,7 @@
 	let Some(patch) = patch.as_obj() else {
 		return Ok(patch);
 	};
-	let target = target.as_obj().unwrap_or_else(|| ObjValue::new_empty());
+	let target = target.as_obj().unwrap_or_else(|| ObjValue::empty());
 	let target_fields = target
 		.fields(
 			// FIXME: Makes no sense to preserve order for BTreeSet, it would be better to use IndexSet here?
modifiedcrates/jrsonnet-stdlib/src/objects.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/objects.rs
+++ b/crates/jrsonnet-stdlib/src/objects.rs
@@ -1,8 +1,9 @@
 use jrsonnet_evaluator::{
 	function::builtin,
+	gc::WithCapacityExt,
 	rustc_hash::FxHashSet,
 	val::{ArrValue, Val},
-	IStr, MaybeUnbound, ObjValue, ObjValueBuilder, Thunk,
+	IStr, ObjValue, ObjValueBuilder,
 };
 
 #[builtin]
@@ -156,43 +157,11 @@
 }
 
 #[builtin]
-pub fn builtin_object_remove_key(
-	obj: ObjValue,
-	key: IStr,
-
-	// Standard implementation uses std.objectFields without such argument, we can't
-	// assume order preservation should always be enabled/disabled
-	#[default(false)]
-	#[cfg(feature = "exp-preserve-order")]
-	preserve_order: bool,
-) -> ObjValue {
-	let mut new_obj = ObjValueBuilder::with_capacity(obj.len() - 1);
-	let all_fields = obj.fields_ex(
-		true,
-		#[cfg(feature = "exp-preserve-order")]
-		preserve_order,
-	);
-	let visible_fields = obj
-		.fields_ex(
-			false,
-			#[cfg(feature = "exp-preserve-order")]
-			preserve_order,
-		)
-		.into_iter()
-		.collect::<FxHashSet<_>>();
-
-	for field in &all_fields {
-		if *field == key {
-			continue;
-		}
-		let mut b = new_obj.field(field.clone());
-		if !visible_fields.contains(&field) {
-			b = b.hide();
-		}
-		let _ = b.binding(MaybeUnbound::Bound(Thunk::result(
-			obj.get(field.clone()).transpose().expect("field exists"),
-		)));
-	}
+pub fn builtin_object_remove_key(obj: ObjValue, key: IStr) -> ObjValue {
+	let mut omit = FxHashSet::with_capacity(1);
+	omit.insert(key);
 
-	new_obj.build()
+	let mut out = ObjValueBuilder::new();
+	out.with_super(obj).with_fields_omitted(omit);
+	out.build()
 }
modifiedtests/tests/as_native.rsdiffbeforeafterboth
--- a/tests/tests/as_native.rs
+++ b/tests/tests/as_native.rs
@@ -1,4 +1,4 @@
-use jrsonnet_evaluator::{trace::PathResolver, FileImportResolver, Result, State};
+use jrsonnet_evaluator::{FileImportResolver, Result, State, trace::PathResolver};
 use jrsonnet_stdlib::ContextInitializer;
 
 mod common;
modifiedtests/tests/builtin.rsdiffbeforeafterboth
--- a/tests/tests/builtin.rs
+++ b/tests/tests/builtin.rs
@@ -1,11 +1,11 @@
 mod common;
 
 use jrsonnet_evaluator::{
-	function::{builtin, builtin::Builtin, CallLocation, FuncVal},
+	ContextBuilder, ContextInitializer, FileImportResolver, Result, State, Thunk, Val,
+	function::{CallLocation, FuncVal, builtin, builtin::Builtin},
 	parser::Source,
 	trace::PathResolver,
 	typed::Typed,
-	ContextBuilder, ContextInitializer, FileImportResolver, Result, State, Thunk, Val,
 };
 use jrsonnet_gcmodule::Trace;
 use jrsonnet_stdlib::ContextInitializer as StdContextInitializer;
@@ -18,11 +18,8 @@
 #[test]
 fn basic_function() -> Result<()> {
 	let a: a = a {};
-	let v = u32::from_untyped(a.call(
-		ContextBuilder::new().build(),
-		CallLocation::native(),
-		&(),
-	)?)?;
+	let v =
+		u32::from_untyped(a.call(ContextBuilder::new().build(), CallLocation::native(), &())?)?;
 
 	ensure_eq!(v, 1);
 	Ok(())
modifiedtests/tests/common.rsdiffbeforeafterboth
--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -1,8 +1,8 @@
 use jrsonnet_evaluator::{
+	ContextBuilder, ContextInitializer as ContextInitializerT, ObjValueBuilder, Result, Thunk, Val,
 	bail,
-	function::{builtin, FuncVal},
+	function::{FuncVal, builtin},
 	parser::Source,
-	ContextBuilder, ContextInitializer as ContextInitializerT, ObjValueBuilder, Result, Thunk, Val,
 };
 use jrsonnet_gcmodule::Trace;
 
modifiedtests/tests/golden.rsdiffbeforeafterboth
--- a/tests/tests/golden.rs
+++ b/tests/tests/golden.rs
@@ -4,9 +4,9 @@
 };
 
 use jrsonnet_evaluator::{
+	FileImportResolver, State,
 	manifest::JsonFormat,
 	trace::{CompactFormat, PathResolver, TraceFormat},
-	FileImportResolver, State,
 };
 use jrsonnet_stdlib::ContextInitializer;
 mod common;
modifiedtests/tests/sanity.rsdiffbeforeafterboth
--- a/tests/tests/sanity.rs
+++ b/tests/tests/sanity.rs
@@ -1,7 +1,6 @@
 use jrsonnet_evaluator::{
-	bail,
+	FileImportResolver, Result, State, Val, bail,
 	trace::{CompactFormat, PathResolver, TraceFormat},
-	FileImportResolver, Result, State, Val,
 };
 use jrsonnet_stdlib::ContextInitializer;
 
modifiedtests/tests/std_native.rsdiffbeforeafterboth
--- a/tests/tests/std_native.rs
+++ b/tests/tests/std_native.rs
@@ -1,4 +1,4 @@
-use jrsonnet_evaluator::{function::builtin, trace::PathResolver, State};
+use jrsonnet_evaluator::{State, function::builtin, trace::PathResolver};
 use jrsonnet_stdlib::ContextInitializer;
 
 #[builtin]
@@ -14,9 +14,11 @@
 	state.context_initializer(std);
 	let state = state.build();
 
-	assert!(state
-		.evaluate_snippet("test", "std.native('example')(1, 3) == 4")
-		.unwrap()
-		.as_bool()
-		.expect("boolean output"));
+	assert!(
+		state
+			.evaluate_snippet("test", "std.native('example')(1, 3) == 4")
+			.unwrap()
+			.as_bool()
+			.expect("boolean output")
+	);
 }
modifiedtests/tests/suite.rsdiffbeforeafterboth
--- a/tests/tests/suite.rs
+++ b/tests/tests/suite.rs
@@ -4,8 +4,8 @@
 };
 
 use jrsonnet_evaluator::{
+	FileImportResolver, State, Val,
 	trace::{CompactFormat, PathResolver, TraceFormat},
-	FileImportResolver, State, Val,
 };
 use jrsonnet_stdlib::ContextInitializer;
 
modifiedtests/tests/typed_obj.rsdiffbeforeafterboth
--- a/tests/tests/typed_obj.rs
+++ b/tests/tests/typed_obj.rs
@@ -2,7 +2,7 @@
 
 use std::fmt::Debug;
 
-use jrsonnet_evaluator::{trace::PathResolver, typed::Typed, Result, State};
+use jrsonnet_evaluator::{Result, State, trace::PathResolver, typed::Typed};
 use jrsonnet_stdlib::ContextInitializer;
 
 #[derive(Clone, Typed, PartialEq, Debug)]