git.delta.rocks / jrsonnet / refs/commits / ac5b435d4caa

difftreelog

refactor split OopObject into different file

lzyssmtoYaroslav Bolyukin2026-03-21parent: #b3f009b.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/error.rs
1use std::{2	cmp::Ordering,3	convert::Infallible,4	fmt::{self, Debug, Display},5};67use jrsonnet_gcmodule::{Acyclic, Trace};8use jrsonnet_interner::IStr;9use jrsonnet_parser::{BinaryOpType, Source, SourcePath, Span, Spanned, UnaryOpType};10use jrsonnet_types::ValType;11use thiserror::Error;1213use crate::{14	function::{CallLocation, FunctionSignature, ParamDefault, ParamName},15	stdlib::format::FormatError,16	typed::TypeLocError,17	val::ConvertNumValueError,18	ObjValue, ResolvePathOwned,19};2021pub(crate) fn format_found(list: &[IStr], what: &str) -> String {22	if list.is_empty() {23		return String::new();24	}25	let mut out = String::new();26	out.push_str("\nThere ");27	if list.len() > 1 {28		out.push_str("are ");29	} else {30		out.push_str("is a ");31	}32	out.push_str(what);33	if list.len() > 1 {34		out.push('s');35	}36	out.push_str(" with similar name");37	if list.len() > 1 {38		out.push('s');39	}40	out.push_str(" present: ");41	for (i, v) in list.iter().enumerate() {42		if i != 0 {43			out.push_str(", ");44		}45		out.push_str(v as &str);46	}47	out48}4950const fn format_empty_str(str: &str) -> &str {51	if str.is_empty() {52		"\"\" (empty string)"53	} else {54		str55	}56}5758pub(crate) fn suggest_object_fields(v: &ObjValue, key: IStr) -> Vec<IStr> {59	let mut heap = Vec::new();60	for field in v.fields_ex(61		true,62		#[cfg(feature = "exp-preserve-order")]63		false,64	) {65		let conf = strsim::jaro_winkler(field.as_str(), key.as_str());66		if conf < 0.8 {67			continue;68		}69		assert!(field.as_str() != key.as_str(), "looks like string pooling failure, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!");7071		heap.push((conf, field));72	}73	heap.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap_or(Ordering::Equal));74	heap.into_iter().map(|v| v.1).collect()75}7677/// Possible errors78#[allow(missing_docs)]79#[derive(Error, Debug, Clone, Trace)]80#[non_exhaustive]81pub enum ErrorKind {82	#[error("intrinsic not found: {0}")]83	IntrinsicNotFound(IStr),8485	#[error("operator {0} does not operate on type {1}")]86	UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),87	#[error("binary operation {1} {0} {2} is not implemented")]88	BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),8990	#[error("self/super/$ are only usable inside objects")]91	CantUseSelfSupOutsideOfObject,92	#[error("no super found")]93	NoSuperFound,9495	#[error("for loop can only iterate over arrays")]96	InComprehensionCanOnlyIterateOverArray,9798	#[error("array out of bounds: {0} is not within [0,{1})")]99	ArrayBoundsError(isize, usize),100	#[error("string out of bounds: {0} is not within [0,{1})")]101	StringBoundsError(usize, usize),102103	#[error("assert failed: {}", format_empty_str(.0))]104	AssertionFailed(IStr),105106	#[error("local is not defined: {0}{found}", found = format_found(.1, "local"))]107	VariableIsNotDefined(IStr, Vec<IStr>),108	#[error("duplicate local var: {0}")]109	DuplicateLocalVar(IStr),110111	#[error("type mismatch: expected {expected}, got {2} {0}", expected = .1.iter().map(|e| format!("{e}")).collect::<Vec<_>>().join(", "))]112	TypeMismatch(&'static str, Vec<ValType>, ValType),113	#[error("no such field: {}{}", format_empty_str(.0), format_found(.1, "field"))]114	NoSuchField(IStr, Vec<IStr>),115116	#[error("only functions can be called, got {0}")]117	OnlyFunctionsCanBeCalledGot(ValType),118	#[error("parameter {0} is not defined")]119	UnknownFunctionParameter(IStr),120	#[error("argument {0} is already bound")]121	BindingParameterASecondTime(IStr),122	#[error("too many args, function has {0}\nFunction has the following signature: {1}")]123	TooManyArgsFunctionHas(usize, FunctionSignature),124	#[error("function argument is not passed: {0}\nFunction has the following signature: {1}")]125	FunctionParameterNotBoundInCall(ParamName, FunctionSignature),126127	#[error("external variable is not defined: {0}")]128	UndefinedExternalVariable(IStr),129130	#[error("field name should be string, got {0}")]131	FieldMustBeStringGot(ValType),132	#[error("duplicate field name: {}", format_empty_str(.0))]133	DuplicateFieldName(IStr),134135	#[error("attempted to index array with string {}", format_empty_str(.0))]136	AttemptedIndexAnArrayWithString(IStr),137	#[error("{0} index type should be {1}, got {2}")]138	ValueIndexMustBeTypeGot(ValType, ValType, ValType),139	#[error("cant index into {0}")]140	CantIndexInto(ValType),141	#[error("{0} is not indexable")]142	ValueIsNotIndexable(ValType),143144	#[error("super can't be used standalone")]145	StandaloneSuper,146147	#[error("can't resolve {1} from {0}")]148	ImportFileNotFound(SourcePath, ResolvePathOwned),149	#[error("resolved file not found: {:?}", .0)]150	ResolvedFileNotFound(SourcePath),151	#[error("can't import {0}: is a directory")]152	ImportIsADirectory(SourcePath),153	#[error("imported file is not valid utf-8: {0:?}")]154	ImportBadFileUtf8(SourcePath),155	#[error("import io error: {0}")]156	ImportIo(String),157	#[error("tried to import {1} from {0}, but imports are not supported")]158	ImportNotSupported(SourcePath, ResolvePathOwned),159	#[error("can't import from virtual file")]160	CantImportFromVirtualFile,161	#[error(162		"syntax error: {}",163		// Peg has no fancier way to handle critical parsing errors https://github.com/kevinmehall/rust-peg/issues/225164		{.error.expected.tokens().find(|t| t.starts_with("!!!")).map_or_else(|| {165			format!(166				"expected {}, got {:?}",167				.error.expected,168				.path.code().chars().nth(error.location.offset)169				.map_or_else(|| "EOF".into(), |c| c.to_string())170			)171		}, |v| v[3..].into())}172	)]173	ImportSyntaxError {174		path: Source,175		#[trace(skip)]176		error: Box<jrsonnet_parser::ParseError>,177	},178179	#[error("runtime error: {}", format_empty_str(.0))]180	RuntimeError(IStr),181	#[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]182	StackOverflow,183	#[error("infinite recursion detected")]184	InfiniteRecursionDetected,185	#[error("tried to index by fractional value")]186	FractionalIndex,187	#[error("attempted to divide by zero")]188	DivisionByZero,189190	#[error("string manifest output is not an string")]191	StringManifestOutputIsNotAString,192	#[error("stream manifest output is not an array")]193	StreamManifestOutputIsNotAArray,194	#[error("multi manifest output is not an object")]195	MultiManifestOutputIsNotAObject,196197	#[error("cant recurse stream manifest")]198	StreamManifestOutputCannotBeRecursed,199	#[error("stream manifest output cannot consist of raw strings")]200	StreamManifestCannotNestString,201202	#[error("{}", format_empty_str(.0))]203	ImportCallbackError(String),204	#[error("invalid unicode codepoint: {0}")]205	InvalidUnicodeCodepointGot(u32),206207	#[error("convert num value: {0}")]208	ConvertNumValue(#[from] ConvertNumValueError),209210	#[error("format error: {0}")]211	Format(#[from] FormatError),212	#[error("type error: {0}")]213	TypeError(TypeLocError),214215	#[cfg(feature = "anyhow-error")]216	#[error(transparent)]217	Other(#[trace(skip)] std::rc::Rc<anyhow::Error>),218}219220#[cfg(feature = "anyhow-error")]221impl From<anyhow::Error> for Error {222	fn from(e: anyhow::Error) -> Self {223		Self::new(ErrorKind::Other(std::rc::Rc::new(e)))224	}225}226227impl From<ErrorKind> for Error {228	fn from(e: ErrorKind) -> Self {229		Self::new(e)230	}231}232233impl From<Infallible> for Error {234	fn from(_value: Infallible) -> Self {235		unreachable!()236	}237}238239/// Single stack trace frame240#[derive(Clone, Debug, Trace)]241pub struct StackTraceElement {242	/// Source of this frame243	/// Some frames only act as description, without attached source244	pub location: Option<Span>,245	/// Frame description246	pub desc: String,247}248#[derive(Debug, Clone, Trace)]249pub struct StackTrace(pub Vec<StackTraceElement>);250251#[derive(Clone, Trace)]252pub struct Error(Box<(ErrorKind, StackTrace)>);253impl Error {254	pub fn new(e: ErrorKind) -> Self {255		Self(Box::new((e, StackTrace(vec![]))))256	}257258	pub const fn error(&self) -> &ErrorKind {259		&(self.0).0260	}261	pub fn error_mut(&mut self) -> &mut ErrorKind {262		&mut (self.0).0263	}264	pub const fn trace(&self) -> &StackTrace {265		&(self.0).1266	}267	pub fn trace_mut(&mut self) -> &mut StackTrace {268		&mut (self.0).1269	}270}271impl Display for Error {272	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {273		writeln!(f, "{}", self.0 .0)?;274		for el in &self.0 .1 .0 {275			write!(f, "\t{}", el.desc)?;276			if let Some(loc) = &el.location {277				write!(f, "at {}", loc.0 .0 .0)?;278				loc.0.map_source_locations(&[loc.1, loc.2]);279			}280			writeln!(f)?;281		}282		Ok(())283	}284}285impl Debug for Error {286	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {287		f.debug_tuple("LocError").field(&self.0).finish()288	}289}290impl std::error::Error for Error {}291292pub trait ErrorSource {293	fn to_location(self) -> Option<Span>;294}295impl<T: Acyclic> ErrorSource for &Spanned<T> {296	fn to_location(self) -> Option<Span> {297		Some(self.span())298	}299}300impl ErrorSource for &Span {301	fn to_location(self) -> Option<Span> {302		Some(self.clone())303	}304}305impl ErrorSource for CallLocation<'_> {306	fn to_location(self) -> Option<Span> {307		self.0.cloned()308	}309}310311pub type Result<V, E = Error> = std::result::Result<V, E>;312pub trait ResultExt: Sized {313	#[must_use]314	fn with_description<O: Into<String>>(self, msg: impl FnOnce() -> O) -> Self;315	#[must_use]316	fn description(self, msg: &str) -> Self {317		self.with_description(|| msg)318	}319320	#[must_use]321	fn with_description_src<O: Into<String>>(322		self,323		src: impl ErrorSource,324		msg: impl FnOnce() -> O,325	) -> Self;326	#[must_use]327	fn description_src(self, src: impl ErrorSource, msg: &str) -> Self {328		self.with_description_src(src, || msg)329	}330}331impl<T> ResultExt for Result<T, Error> {332	fn with_description<O: Into<String>>(mut self, msg: impl FnOnce() -> O) -> Self {333		if let Err(e) = &mut self {334			let trace = e.trace_mut();335			trace.0.push(StackTraceElement {336				location: None,337				desc: msg().into(),338			});339		}340		self341	}342343	fn with_description_src<O: Into<String>>(344		mut self,345		src: impl ErrorSource,346		msg: impl FnOnce() -> O,347	) -> Self {348		if let Err(e) = &mut self {349			let trace = e.trace_mut();350			trace.0.push(StackTraceElement {351				location: src.to_location(),352				desc: msg().into(),353			});354		}355		self356	}357}358359#[macro_export]360macro_rules! bail {361	($w:ident$(::$i:ident)*$(($($tt:tt)*))?) => {362		return Err($w$(::$i)*$(($($tt)*))?.into())363	};364	($w:ident$(::$i:ident)*$({$($tt:tt)*})?) => {365		return Err($w$(::$i)*$({$($tt)*})?.into())366	};367	($l:literal$(, $($tt:tt)*)?) => {368		return Err($crate::error::ErrorKind::RuntimeError($crate::jrsonnet_macros::format_istr!($l$(, $($tt)*)?)).into())369	};370}371372#[macro_export]373macro_rules! runtime_error {374	($l:literal$(, $($tt:tt)*)?) => {375		$crate::error::Error::from($crate::error::ErrorKind::RuntimeError($crate::jrsonnet_macros::format_istr!($l$(, $($tt)*)?)))376	};377}
deletedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ /dev/null
@@ -1,1260 +0,0 @@
-use std::{
-	any::Any,
-	cell::{Cell, RefCell},
-	collections::hash_map::Entry,
-	fmt::{self, Debug},
-	hash::{Hash, Hasher},
-	mem,
-	num::Saturating,
-	ops::ControlFlow,
-};
-
-use educe::Educe;
-use jrsonnet_gcmodule::{cc_dyn, Acyclic, Cc, Trace, Weak};
-use jrsonnet_interner::IStr;
-use jrsonnet_parser::{Span, Visibility};
-use rustc_hash::{FxHashMap, FxHashSet};
-
-use crate::{
-	arr::{PickObjectKeyValues, PickObjectValues},
-	bail,
-	error::{suggest_object_fields, ErrorKind::*},
-	function::{CallLocation, FuncVal},
-	gc::WithCapacityExt as _,
-	identity_hash, in_frame,
-	operator::evaluate_add_op,
-	val::{ArrValue, ThunkValue},
-	CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
-};
-
-#[cfg(not(feature = "exp-preserve-order"))]
-mod ordering {
-	#![allow(
-		// This module works as stub for preserve-order feature
-		clippy::unused_self,
-	)]
-
-	use jrsonnet_gcmodule::Trace;
-
-	#[derive(Clone, Copy, Default, Debug, Trace)]
-	pub struct FieldIndex(());
-	impl FieldIndex {
-		pub const fn next(self) -> Self {
-			Self(())
-		}
-	}
-
-	#[derive(Clone, Copy, Default, Debug, Trace)]
-	pub struct SuperDepth(());
-	impl SuperDepth {
-		pub(super) fn deepen(self) {}
-	}
-}
-
-#[cfg(feature = "exp-preserve-order")]
-mod ordering {
-	use std::cmp::Reverse;
-
-	use jrsonnet_gcmodule::Trace;
-
-	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
-	pub struct FieldIndex(u32);
-	impl FieldIndex {
-		pub fn next(self) -> Self {
-			Self(self.0 + 1)
-		}
-	}
-
-	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]
-	pub struct SuperDepth(u32);
-	impl SuperDepth {
-		pub(super) fn deepen(&mut self) {
-			self.0 += 1
-		}
-	}
-
-	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
-	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);
-	impl FieldSortKey {
-		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {
-			Self(Reverse(depth), index)
-		}
-	}
-}
-
-#[cfg(feature = "exp-preserve-order")]
-use ordering::FieldSortKey;
-use ordering::{FieldIndex, SuperDepth};
-
-// 0 - add
-//  12 - visibility
-#[derive(Clone, Copy)]
-pub struct ObjFieldFlags(u8);
-impl ObjFieldFlags {
-	fn new(add: bool, visibility: Visibility) -> Self {
-		let mut v = 0;
-		if add {
-			v |= 1;
-		}
-		v |= match visibility {
-			Visibility::Normal => 0b000,
-			Visibility::Hidden => 0b010,
-			Visibility::Unhide => 0b100,
-		};
-		Self(v)
-	}
-	pub fn add(&self) -> bool {
-		self.0 & 1 != 0
-	}
-	pub fn visibility(&self) -> Visibility {
-		match (self.0 & 0b110) >> 1 {
-			0b00 => Visibility::Normal,
-			0b01 => Visibility::Hidden,
-			0b10 => Visibility::Unhide,
-			_ => unreachable!(),
-		}
-	}
-}
-impl Debug for ObjFieldFlags {
-	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-		f.debug_struct("ObjFieldFlags")
-			.field("add", &self.add())
-			.field("visibility", &self.visibility())
-			.finish()
-	}
-}
-
-#[allow(clippy::module_name_repetitions)]
-#[derive(Debug, Trace)]
-pub struct ObjMember {
-	#[trace(skip)]
-	flags: ObjFieldFlags,
-	original_index: FieldIndex,
-	pub invoke: MaybeUnbound,
-	pub location: Option<Span>,
-}
-
-cc_dyn!(CcObjectAssertion, ObjectAssertion);
-pub trait ObjectAssertion: Trace {
-	fn run(&self, sup_this: SupThis) -> Result<()>;
-}
-
-// Field => This
-
-#[derive(Trace, Debug)]
-enum CacheValue {
-	Cached(Result<Option<Val>>),
-	Pending,
-}
-
-#[allow(clippy::module_name_repetitions)]
-#[derive(Trace, Default)]
-#[trace(tracking(force))]
-pub struct OopObject {
-	assertion: Option<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("this_entries", &self.this_entries)
-			.finish_non_exhaustive()
-	}
-}
-impl OopObject {
-	fn is_empty(&self) -> bool {
-		self.assertion.is_none() && self.this_entries.is_empty()
-	}
-}
-
-type EnumFieldsHandler<'a> =
-	dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;
-
-pub enum EnumFields {
-	Normal(Visibility),
-	Omit(Skip),
-}
-
-#[derive(Trace, Clone)]
-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(#[trace(skip)] Skip),
-	NotFound,
-}
-
-#[derive(Acyclic, Clone)]
-pub enum FieldVisibility {
-	Found(Visibility),
-	Omit(Skip),
-	NotFound,
-}
-
-#[derive(Acyclic, Clone)]
-pub enum HasFieldIncludeHidden {
-	Exists,
-	NotFound,
-	Omit(Skip),
-}
-
-type Skip = Saturating<usize>;
-
-pub trait ObjectCore: Trace + Any + Debug {
-	// If callback returns false, iteration stops, and this call returns false.
-	fn enum_fields_core(
-		&self,
-		super_depth: &mut SuperDepth,
-		handler: &mut EnumFieldsHandler<'_>,
-	) -> bool;
-
-	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden;
-
-	fn get_for_core(&self, key: IStr, sup_this: SupThis, omit_only: bool) -> Result<GetFor>;
-	fn field_visibility_core(&self, field: IStr) -> FieldVisibility;
-
-	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()>;
-}
-
-#[derive(Clone, Trace)]
-pub struct WeakObjValue(#[trace(skip)] Weak<ObjValueInner>);
-impl Debug for WeakObjValue {
-	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-		f.debug_tuple("WeakObjValue").finish()
-	}
-}
-
-impl PartialEq for WeakObjValue {
-	fn eq(&self, other: &Self) -> bool {
-		Weak::ptr_eq(&self.0, &other.0)
-	}
-}
-
-impl Eq for WeakObjValue {}
-impl Hash for WeakObjValue {
-	fn hash<H: Hasher>(&self, hasher: &mut H) {
-		// Safety: usize is POD
-		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };
-		hasher.write_usize(addr);
-	}
-}
-
-cc_dyn!(
-	#[derive(Clone, Debug)]
-	CcObjectCore, ObjectCore,
-	pub fn new() {...}
-);
-#[derive(Trace, Educe)]
-#[educe(Debug)]
-struct ObjValueInner {
-	cores: Vec<CcObjectCore>,
-	assertions_ran: Cell<bool>,
-	value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
-}
-
-thread_local! {
-	static RUNNING_ASSERTIONS: RefCell<FxHashSet<ObjValue>> = RefCell::default();
-}
-fn is_asserting(obj: &ObjValue) -> bool {
-	RUNNING_ASSERTIONS.with_borrow(|v| v.contains(obj))
-}
-/// Returns false if already asserting
-fn start_asserting(obj: &ObjValue) -> bool {
-	RUNNING_ASSERTIONS.with_borrow_mut(|v| v.insert(obj.clone()))
-}
-fn finish_asserting(obj: &ObjValue) {
-	RUNNING_ASSERTIONS.with_borrow_mut(|v| {
-		let r = v.remove(obj);
-		debug_assert!(
-			r,
-			"finish_asserting was called before start_asserting or twice"
-		);
-	});
-}
-
-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)]
-pub struct ObjValue(
-	#[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,
-	this: ObjValue,
-}
-impl ObjectCore for StandaloneSuperCore {
-	fn enum_fields_core(
-		&self,
-		super_depth: &mut SuperDepth,
-		handler: &mut EnumFieldsHandler<'_>,
-	) -> bool {
-		self.this.enum_fields_idx(super_depth, handler, 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_core(&self, key: IStr, _sup_this: SupThis, omit_only: bool) -> Result<GetFor> {
-		if omit_only {
-			return Ok(GetFor::NotFound);
-		}
-		let v = self.this.get_idx(key, self.sup)?;
-		Ok(v.map_or(GetFor::NotFound, |v| GetFor::Final(v)))
-	}
-
-	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_core(&self, _sup_this: SupThis) -> Result<()> {
-		self.this.run_assertions()
-	}
-}
-
-#[derive(Debug, Acyclic)]
-struct OmitFieldsCore {
-	omit: FxHashSet<IStr>,
-	prev_layers: usize,
-}
-impl ObjectCore for OmitFieldsCore {
-	fn enum_fields_core(
-		&self,
-		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(Saturating(self.prev_layers)),
-			) {
-				return false;
-			}
-			fi = fi.next();
-		}
-		true
-	}
-
-	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
-		if self.omit.contains(&name) {
-			return HasFieldIncludeHidden::Omit(Saturating(self.prev_layers));
-		}
-		HasFieldIncludeHidden::NotFound
-	}
-
-	fn get_for_core(&self, key: IStr, _sup_this: SupThis, _omit_only: bool) -> Result<GetFor> {
-		if self.omit.contains(&key) {
-			return Ok(GetFor::Omit(Saturating(self.prev_layers)));
-		}
-		Ok(GetFor::NotFound)
-	}
-
-	fn field_visibility_core(&self, field: IStr) -> FieldVisibility {
-		if self.omit.contains(&field) {
-			return FieldVisibility::Omit(Saturating(self.prev_layers));
-		}
-		FieldVisibility::NotFound
-	}
-
-	fn run_assertions_core(&self, _sup_this: SupThis) -> Result<()> {
-		Ok(())
-	}
-}
-
-#[derive(Hash, PartialEq, Eq, Trace, Clone, Copy, Debug)]
-struct CoreIdx {
-	idx: usize,
-}
-impl CoreIdx {
-	fn super_exists(self) -> bool {
-		self.idx != 0
-	}
-}
-#[derive(Trace, Clone, PartialEq, Eq, Hash, Debug)]
-pub struct SupThis {
-	sup: CoreIdx,
-	this: ObjValue,
-}
-impl SupThis {
-	pub fn has_super(&self) -> bool {
-		self.sup.super_exists()
-	}
-	/// Implementation of `"field" in super` operation,
-	/// works faster than standalone super path.
-	///
-	/// In case of no `super` existence, returns false.
-	pub fn field_in_super(&self, field: IStr) -> bool {
-		self.this.has_field_include_hidden_idx(field, self.sup)
-	}
-	/// Implementation of `super.field` operation,
-	/// works faster than standalone super path.
-	///
-	/// In case of no `super` existence, returns `NoSuperFound`
-	pub fn get_super(&self, field: IStr) -> Result<Option<Val>> {
-		if !self.sup.super_exists() {
-			bail!(NoSuperFound);
-		}
-		self.this.get_idx(field, self.sup)
-	}
-	/// `super` with `self` overriden for top-level lookups.
-	/// Exists when super appears outside of `super.field`/`"field" in super` expressions
-	/// Exclusive to jrsonnet.
-	///
-	/// Might return `NoSuperFound` error.
-	pub fn standalone_super(&self) -> Result<ObjValue> {
-		if !self.sup.super_exists() {
-			bail!(NoSuperFound)
-		}
-		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
-	}
-	pub fn downgrade(self) -> WeakSupThis {
-		WeakSupThis {
-			sup: self.sup,
-			this: self.this.downgrade(),
-		}
-	}
-}
-#[derive(Trace, PartialEq, Eq, Hash, Debug)]
-pub struct WeakSupThis {
-	sup: CoreIdx,
-	this: WeakObjValue,
-}
-
-impl ObjValue {
-	pub fn builder() -> ObjValueBuilder {
-		ObjValueBuilder::new()
-	}
-	pub fn builder_with_capacity(capacity: usize) -> ObjValueBuilder {
-		ObjValueBuilder::with_capacity(capacity)
-	}
-	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {
-		let mut out = ObjValueBuilder::with_capacity(1);
-		out.with_super(self);
-		let mut member = out.field(key);
-		if value.flags.add() {
-			member = member.add();
-		}
-		if let Some(loc) = value.location {
-			member = member.with_location(loc);
-		}
-		let _ = member
-			.with_visibility(value.flags.visibility())
-			.binding(value.invoke);
-		out.build()
-	}
-	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder<'_>> {
-		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();
-		cores.extend(self.0.cores.iter().cloned());
-		ObjValue(Cc::new(ObjValueInner {
-			cores,
-			value_cache: RefCell::default(),
-			assertions_ran: Cell::new(false),
-		}))
-	}
-	// #[must_use]
-	// pub fn with_this(&self, this: Self) -> Self {
-	// 	self.0.with_this(self.clone(), this)
-	// }
-	/// Returns amount of visible object fields
-	/// If object only contains hidden fields - may return zero.
-	pub fn len(&self) -> usize {
-		self.fields_visibility()
-			.values()
-			.filter(|d| d.visible())
-			.count()
-	}
-	/// 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_idx(
-			&mut super_depth,
-			handler,
-			CoreIdx {
-				idx: self.0.cores.len(),
-			},
-		)
-	}
-	fn enum_fields_idx(
-		&self,
-		super_depth: &mut SuperDepth,
-		handler: &mut EnumFieldsHandler<'_>,
-		idx: CoreIdx,
-	) -> bool {
-		for core in self.0.cores[..idx.idx].iter().rev() {
-			if !core.0.enum_fields_core(super_depth, handler) {
-				return false;
-			}
-			super_depth.deepen();
-		}
-		true
-	}
-
-	pub fn has_field_include_hidden(&self, name: IStr) -> bool {
-		self.has_field_include_hidden_idx(
-			name,
-			CoreIdx {
-				idx: self.0.cores.len(),
-			},
-		)
-	}
-	fn has_field_include_hidden_idx(&self, name: IStr, core: CoreIdx) -> bool {
-		let mut skip = Saturating(0usize);
-		for ele in self.0.cores[..core.idx].iter().rev() {
-			match ele.0.has_field_include_hidden_core(name.clone()) {
-				HasFieldIncludeHidden::Exists => {
-					if skip.0 == 0 {
-						return true;
-					}
-				}
-				HasFieldIncludeHidden::Omit(new_skip) => {
-					// +1 including this core
-					skip = skip.max(new_skip + Saturating(1));
-				}
-				HasFieldIncludeHidden::NotFound => {}
-			}
-			skip -= 1;
-		}
-		false
-	}
-	pub fn has_field(&self, name: IStr) -> bool {
-		match self.field_visibility(name) {
-			Some(Visibility::Unhide | Visibility::Normal) => true,
-			Some(Visibility::Hidden) | None => false,
-		}
-	}
-	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {
-		if include_hidden {
-			self.has_field_include_hidden(name)
-		} else {
-			self.has_field(name)
-		}
-	}
-	pub fn get(&self, key: IStr) -> Result<Option<Val>> {
-		self.get_idx(
-			key,
-			CoreIdx {
-				idx: self.0.cores.len(),
-			},
-		)
-	}
-
-	fn get_idx(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
-		let cache_key = (key.clone(), core);
-		{
-			let mut cache = self.0.value_cache.borrow_mut();
-			// entry_ref candidate?
-			match cache.entry(cache_key.clone()) {
-				Entry::Occupied(v) => match v.get() {
-					CacheValue::Cached(v) => return v.clone(),
-					CacheValue::Pending => {
-						if !is_asserting(self) {
-							bail!(InfiniteRecursionDetected);
-						}
-					}
-				},
-				Entry::Vacant(v) => {
-					v.insert(CacheValue::Pending);
-				}
-			};
-		}
-		let result = self.get_idx_uncached(key, core);
-		{
-			let mut cache = self.0.value_cache.borrow_mut();
-			cache.insert(cache_key, CacheValue::Cached(result.clone()));
-		}
-		result
-	}
-	fn get_idx_uncached(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
-		self.run_assertions()?;
-		let mut add_stack = Vec::with_capacity(2);
-		let mut skip = Saturating(0);
-		for (sup, core) in self.0.cores[..core.idx].iter().enumerate().rev() {
-			let sup_this = SupThis {
-				sup: CoreIdx { idx: sup },
-				this: self.clone(),
-			};
-			match core.0.get_for_core(key.clone(), sup_this, skip.0 != 0)? {
-				GetFor::Final(val) if add_stack.is_empty() => {
-					if skip.0 == 0 {
-						return Ok(Some(val));
-					}
-				}
-				GetFor::Final(val) => {
-					if skip.0 == 0 {
-						add_stack.push(val);
-						break;
-					}
-				}
-				GetFor::SuperPlus(val) => {
-					if skip.0 == 0 {
-						add_stack.push(val);
-					}
-				}
-				GetFor::Omit(new_skip) => {
-					// +1 including this core
-					skip = skip.max(new_skip + Saturating(1));
-				}
-				GetFor::NotFound => {}
-			}
-			skip -= 1;
-		}
-		if add_stack.is_empty() {
-			// None of layers had this field
-			return Ok(None);
-		} else if add_stack.len() == 1 {
-			// A layer had this field, but it wanted this field to be added with super.
-			// However, no super had this field, fail-safe
-			return Ok(Some(add_stack.pop().expect("single element on stack")));
-		}
-		let mut values = add_stack.into_iter().rev();
-		let init = values.next().expect("at least 2 elements");
-
-		values
-			.try_fold(init, |a, b| evaluate_add_op(&a, &b))
-			.map(Some)
-
-		// self.0.get_raw(key, this)
-	}
-
-	pub fn get_or_bail(&self, key: IStr) -> Result<Val> {
-		let Some(value) = self.get(key.clone())? else {
-			let suggestions = suggest_object_fields(self, key.clone());
-			bail!(NoSuchField(key, suggestions))
-		};
-		Ok(value)
-	}
-
-	fn field_visibility(&self, field: IStr) -> Option<Visibility> {
-		self.field_visibility_idx(
-			field,
-			CoreIdx {
-				idx: self.0.cores.len(),
-			},
-		)
-	}
-	fn field_visibility_idx(&self, field: IStr, core: CoreIdx) -> Option<Visibility> {
-		let mut exists = false;
-		let mut skip = Saturating(0usize);
-		for ele in self.0.cores[..core.idx].iter().rev() {
-			let vis = ele.0.field_visibility_core(field.clone());
-			match vis {
-				FieldVisibility::Found(vis @ (Visibility::Unhide | Visibility::Hidden)) => {
-					if skip.0 == 0 {
-						return Some(vis);
-					}
-				}
-				FieldVisibility::Found(Visibility::Normal) => {
-					if skip.0 == 0 {
-						exists = true
-					}
-				}
-				FieldVisibility::NotFound => {}
-				FieldVisibility::Omit(new_skip) => {
-					// +1 including this core
-					skip = skip.max(new_skip + Saturating(1));
-				}
-			}
-			skip -= 1;
-		}
-		exists.then_some(Visibility::Normal)
-	}
-
-	pub fn run_assertions(&self) -> Result<()> {
-		if self.0.assertions_ran.get() {
-			return Ok(());
-		}
-		if !start_asserting(self) {
-			return Ok(());
-		}
-		for (idx, ele) in self.0.cores.iter().enumerate() {
-			let sup_this = SupThis {
-				sup: CoreIdx { idx },
-				this: self.clone(),
-			};
-			ele.0.run_assertions_core(sup_this).inspect_err(|_e| {
-				finish_asserting(self);
-			})?;
-		}
-		finish_asserting(self);
-		self.0.assertions_ran.set(true);
-		Ok(())
-	}
-
-	pub fn iter(
-		&self,
-		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
-	) -> impl Iterator<Item = (IStr, Result<Val>)> + '_ {
-		let fields = self.fields(
-			#[cfg(feature = "exp-preserve-order")]
-			preserve_order,
-		);
-		fields.into_iter().map(|field| {
-			(
-				field.clone(),
-				self.get(field)
-					.map(|opt| opt.expect("iterating over keys, field exists")),
-			)
-		})
-	}
-	pub fn get_lazy(&self, key: IStr) -> Option<Thunk<Val>> {
-		if !self.has_field_ex(key.clone(), true) {
-			return None;
-		}
-		#[derive(Trace)]
-		struct ObjFieldThunk {
-			obj: ObjValue,
-			key: IStr,
-		}
-		impl ThunkValue for ObjFieldThunk {
-			type Output = Val;
-
-			fn get(&self) -> Result<Self::Output> {
-				self.obj
-					.get(self.key.clone())
-					.transpose()
-					.expect("field existence checked")
-			}
-		}
-
-		Some(Thunk::new(ObjFieldThunk {
-			obj: self.clone(),
-			key,
-		}))
-	}
-	pub fn get_lazy_or_bail(&self, key: IStr) -> Thunk<Val> {
-		#[derive(Trace)]
-		struct ObjFieldThunk {
-			obj: ObjValue,
-			key: IStr,
-		}
-		impl ThunkValue for ObjFieldThunk {
-			type Output = Val;
-
-			fn get(&self) -> Result<Self::Output> {
-				self.obj.get_or_bail(self.key.clone())
-			}
-		}
-
-		Thunk::new(ObjFieldThunk {
-			obj: self.clone(),
-			key,
-		})
-	}
-	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
-		Cc::ptr_eq(&a.0, &b.0)
-	}
-	pub fn downgrade(self) -> WeakObjValue {
-		WeakObjValue(self.0.downgrade())
-	}
-}
-
-#[derive(Debug)]
-struct FieldVisibilityData {
-	omitted_until: Saturating<usize>,
-	exists_visible: Option<Visibility>,
-	#[cfg(feature = "exp-preserve-order")]
-	key: FieldSortKey,
-}
-impl FieldVisibilityData {
-	fn visible(&self) -> bool {
-		self.exists_visible
-			.expect("non-existing fields shall be dropped at the end of fn fields_visibility()")
-			.is_visible()
-	}
-	#[cfg(feature = "exp-preserve-order")]
-	fn sort_key(&self) -> FieldSortKey {
-		self.key
-	}
-}
-
-impl ObjValue {
-	fn fields_visibility(&self) -> FxHashMap<IStr, FieldVisibilityData> {
-		let mut out = FxHashMap::default();
-
-		let mut super_depth = SuperDepth::default();
-		let mut omit_index = Saturating(0);
-		for core in self.0.cores.iter().rev() {
-			core.0
-				.enum_fields_core(&mut super_depth, &mut |_depth, _index, name, visibility| {
-					let entry = out.entry(name);
-					let data = entry.or_insert(FieldVisibilityData {
-						exists_visible: None,
-						#[cfg(feature = "exp-preserve-order")]
-						key: FieldSortKey::new(_depth, _index),
-						omitted_until: omit_index,
-					});
-					match visibility {
-						EnumFields::Omit(new_skip) => {
-							// +1 including this core
-							data.omitted_until = data
-								.omitted_until
-								.max(omit_index + new_skip + Saturating(1));
-						}
-						EnumFields::Normal(Visibility::Normal) => {
-							if data.omitted_until <= omit_index {
-								if data.exists_visible.is_none() {
-									data.exists_visible = Some(Visibility::Normal);
-								}
-							}
-						}
-						EnumFields::Normal(Visibility::Hidden) => {
-							if data.omitted_until <= omit_index {
-								data.exists_visible = Some(match data.exists_visible {
-									// We're iterating in reverse, later unhide is preserved
-									Some(Visibility::Unhide) => Visibility::Unhide,
-									_ => Visibility::Hidden,
-								});
-							}
-						}
-						EnumFields::Normal(Visibility::Unhide) => {
-							if data.omitted_until <= omit_index {
-								data.exists_visible = Some(match data.exists_visible {
-									// We're iterating in reverse, later hide is preserved
-									Some(Visibility::Hidden) => Visibility::Hidden,
-									_ => Visibility::Unhide,
-								});
-							}
-						}
-					};
-					return ControlFlow::Continue(());
-				});
-
-			super_depth.deepen();
-			omit_index += 1;
-		}
-
-		out.retain(|_, v| v.exists_visible.is_some());
-
-		out
-	}
-	pub fn fields_ex(
-		&self,
-		include_hidden: bool,
-		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
-	) -> Vec<IStr> {
-		#[cfg(feature = "exp-preserve-order")]
-		if preserve_order {
-			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self
-				.fields_visibility()
-				.into_iter()
-				.filter(|(_, d)| include_hidden || d.visible())
-				.enumerate()
-				.map(|(idx, (k, d))| (k, (d.sort_key(), idx)))
-				.unzip();
-			keys.sort_unstable_by_key(|v| v.0);
-			// Reorder in-place by resulting indexes
-			for i in 0..fields.len() {
-				let x = fields[i].clone();
-				let mut j = i;
-				loop {
-					let k = keys[j].1;
-					keys[j].1 = j;
-					if k == i {
-						break;
-					}
-					fields[j] = fields[k].clone();
-					j = k;
-				}
-				fields[j] = x;
-			}
-			return fields;
-		}
-
-		let mut fields: Vec<_> = self
-			.fields_visibility()
-			.into_iter()
-			.filter(|(_, d)| include_hidden || d.visible())
-			.map(|(k, _)| k)
-			.collect();
-		fields.sort_unstable();
-		fields
-	}
-	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {
-		self.fields_ex(
-			false,
-			#[cfg(feature = "exp-preserve-order")]
-			preserve_order,
-		)
-	}
-	pub fn values_ex(
-		&self,
-		include_hidden: bool,
-		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
-	) -> ArrValue {
-		ArrValue::new(PickObjectValues::new(
-			self.clone(),
-			self.fields_ex(
-				include_hidden,
-				#[cfg(feature = "exp-preserve-order")]
-				preserve_order,
-			),
-		))
-	}
-	pub fn values(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> ArrValue {
-		self.values_ex(
-			false,
-			#[cfg(feature = "exp-preserve-order")]
-			preserve_order,
-		)
-	}
-	pub fn key_values_ex(
-		&self,
-		include_hidden: bool,
-		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
-	) -> ArrValue {
-		ArrValue::new(PickObjectKeyValues::new(
-			self.clone(),
-			self.fields_ex(
-				include_hidden,
-				#[cfg(feature = "exp-preserve-order")]
-				preserve_order,
-			),
-		))
-	}
-	pub fn key_values(
-		&self,
-		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
-	) -> ArrValue {
-		self.key_values_ex(
-			false,
-			#[cfg(feature = "exp-preserve-order")]
-			preserve_order,
-		)
-	}
-}
-
-impl OopObject {
-	pub fn new(
-		this_entries: FxHashMap<IStr, ObjMember>,
-		assertion: Option<CcObjectAssertion>,
-	) -> Self {
-		Self {
-			this_entries,
-			assertion,
-		}
-	}
-}
-
-impl ObjectCore for OopObject {
-	fn enum_fields_core(
-		&self,
-		super_depth: &mut SuperDepth,
-		handler: &mut EnumFieldsHandler<'_>,
-	) -> bool {
-		for (name, member) in self.this_entries.iter() {
-			if matches!(
-				handler(
-					*super_depth,
-					member.original_index,
-					name.clone(),
-					EnumFields::Normal(member.flags.visibility()),
-				),
-				ControlFlow::Break(())
-			) {
-				return false;
-			}
-		}
-		true
-	}
-
-	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_core(&self, key: IStr, sup_this: SupThis, omit_only: bool) -> Result<GetFor> {
-		if omit_only {
-			return Ok(GetFor::NotFound);
-		}
-		match self.this_entries.get(&key) {
-			Some(k) => {
-				let v = k.invoke.evaluate(sup_this)?;
-				Ok(if k.flags.add() {
-					GetFor::SuperPlus(v)
-				} else {
-					GetFor::Final(v)
-				})
-			}
-			None => Ok(GetFor::NotFound),
-		}
-	}
-	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_core(&self, sup_this: SupThis) -> Result<()> {
-		if let Some(assertion) = &self.assertion {
-			assertion.0.run(sup_this.clone())?;
-		}
-		Ok(())
-	}
-}
-
-#[allow(clippy::module_name_repetitions)]
-pub struct ObjValueBuilder {
-	sup: Vec<CcObjectCore>,
-
-	new: OopObject,
-	next_field_index: FieldIndex,
-}
-impl ObjValueBuilder {
-	pub fn new() -> Self {
-		Self::with_capacity(0)
-	}
-	pub fn with_capacity(capacity: usize) -> Self {
-		Self {
-			sup: vec![],
-			new: OopObject {
-				assertion: None,
-				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 with_super(&mut self, super_obj: ObjValue) -> &mut Self {
-		self.sup = super_obj.0.cores.clone();
-		self
-	}
-
-	pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {
-		assert!(
-			self.new.assertion.is_none(),
-			"one OopObject can only have one assertion"
-		);
-		self.new.assertion = Some(CcObjectAssertion::new(assertion));
-		self
-	}
-	pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {
-		let field_index = self.next_field_index;
-		self.next_field_index = self.next_field_index.next();
-		ObjMemberBuilder::new(ValueBuilder(self), name.into(), field_index)
-	}
-	/// Preset for common method definiton pattern:
-	/// Create a hidden field with the function value.
-	///
-	/// `.field(name).hide().value(Val::function(value))`
-	pub fn method(&mut self, name: impl Into<IStr>, value: impl Into<FuncVal>) -> &mut Self {
-		self.field(name).hide().value(Val::Func(value.into()));
-		self
-	}
-	pub fn try_method(
-		&mut self,
-		name: impl Into<IStr>,
-		value: impl Into<FuncVal>,
-	) -> Result<&mut Self> {
-		self.field(name).hide().try_value(Val::Func(value.into()))?;
-		Ok(self)
-	}
-
-	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,
-			prev_layers: self.sup.len(),
-		}));
-	}
-
-	pub fn build(mut self) -> ObjValue {
-		self.commit();
-		if self.sup.is_empty() {
-			return ObjValue::empty();
-		}
-		ObjValue(Cc::new(ObjValueInner {
-			cores: self.sup,
-			assertions_ran: Cell::new(false),
-			value_cache: Default::default(),
-		}))
-	}
-}
-impl Default for ObjValueBuilder {
-	fn default() -> Self {
-		Self::with_capacity(0)
-	}
-}
-
-#[allow(clippy::module_name_repetitions)]
-#[must_use = "value not added unless binding() was called"]
-pub struct ObjMemberBuilder<Kind> {
-	kind: Kind,
-	name: IStr,
-	add: bool,
-	visibility: Visibility,
-	original_index: FieldIndex,
-	location: Option<Span>,
-}
-
-#[allow(clippy::missing_const_for_fn)]
-impl<Kind> ObjMemberBuilder<Kind> {
-	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {
-		Self {
-			kind,
-			name,
-			original_index,
-			add: false,
-			visibility: Visibility::Normal,
-			location: None,
-		}
-	}
-
-	pub const fn with_add(mut self, add: bool) -> Self {
-		self.add = add;
-		self
-	}
-	pub fn add(self) -> Self {
-		self.with_add(true)
-	}
-	pub fn with_visibility(mut self, visibility: Visibility) -> Self {
-		self.visibility = visibility;
-		self
-	}
-	pub fn hide(self) -> Self {
-		self.with_visibility(Visibility::Hidden)
-	}
-	pub fn with_location(mut self, location: Span) -> Self {
-		self.location = Some(location);
-		self
-	}
-	fn build_member(self, binding: MaybeUnbound) -> (Kind, IStr, ObjMember) {
-		(
-			self.kind,
-			self.name,
-			ObjMember {
-				flags: ObjFieldFlags::new(self.add, self.visibility),
-				original_index: self.original_index,
-				invoke: binding,
-				location: self.location,
-			},
-		)
-	}
-}
-
-pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);
-impl ObjMemberBuilder<ValueBuilder<'_>> {
-	/// Inserts value, replacing if it is already defined
-	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.new.this_entries.entry(name);
-		entry.insert_entry(member);
-	}
-	/// Inserts thunk, replacing if it is already defined
-	pub fn thunk(self, value: impl Into<Thunk<Val>>) {
-		let (receiver, name, member) = self.build_member(MaybeUnbound::Bound(value.into()));
-		let entry = receiver.0.new.this_entries.entry(name);
-		entry.insert_entry(member);
-	}
-
-	/// Tries to insert value, returns an error if it was already defined
-	pub fn try_value(self, value: impl Into<Val>) -> Result<()> {
-		self.try_thunk(Thunk::evaluated(value.into()))
-	}
-	pub fn try_thunk(self, value: impl Into<Thunk<Val>>) -> Result<()> {
-		self.binding(MaybeUnbound::Bound(value.into()))
-	}
-	pub fn bindable(self, bindable: impl Unbound<Bound = Val>) -> Result<()> {
-		self.binding(MaybeUnbound::Unbound(CcUnbound::new(bindable)))
-	}
-	pub fn binding(self, binding: MaybeUnbound) -> Result<()> {
-		let (receiver, name, member) = self.build_member(binding);
-		let location = member.location.clone();
-		let old = receiver.0.new.this_entries.insert(name.clone(), member);
-		if old.is_some() {
-			in_frame(
-				CallLocation(location.as_ref()),
-				|| format!("field <{}> initializtion", name.clone()),
-				|| bail!(DuplicateFieldName(name.clone())),
-			)?;
-		}
-		Ok(())
-	}
-}
-
-pub struct ExtendBuilder<'v>(&'v mut ObjValue);
-impl ObjMemberBuilder<ExtendBuilder<'_>> {
-	pub fn value(self, value: impl Into<Val>) {
-		self.binding(MaybeUnbound::Bound(Thunk::evaluated(value.into())));
-	}
-	pub fn bindable(self, bindable: impl Unbound<Bound = Val>) {
-		self.binding(MaybeUnbound::Unbound(CcUnbound::new(bindable)));
-	}
-	pub fn binding(self, binding: MaybeUnbound) {
-		let (receiver, name, member) = self.build_member(binding);
-		let new = receiver.0.clone();
-		*receiver.0 = new.extend_with_raw_member(name, member);
-	}
-}
addedcrates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -0,0 +1,1029 @@
+use std::{
+	any::Any,
+	cell::{Cell, RefCell},
+	collections::hash_map::Entry,
+	fmt::{self, Debug},
+	hash::{Hash, Hasher},
+	num::Saturating,
+	ops::ControlFlow,
+};
+
+use educe::Educe;
+use jrsonnet_gcmodule::{cc_dyn, Acyclic, Cc, Trace, Weak};
+use jrsonnet_interner::IStr;
+use jrsonnet_parser::{Span, Visibility};
+use rustc_hash::{FxHashMap, FxHashSet};
+
+mod oop;
+
+pub use oop::ObjValueBuilder;
+
+use crate::{
+	arr::{PickObjectKeyValues, PickObjectValues},
+	bail,
+	error::{suggest_object_fields, ErrorKind::*},
+	identity_hash,
+	operator::evaluate_add_op,
+	val::{ArrValue, ThunkValue},
+	CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
+};
+
+#[cfg(not(feature = "exp-preserve-order"))]
+mod ordering {
+	#![allow(
+		// This module works as stub for preserve-order feature
+		clippy::unused_self,
+	)]
+
+	use jrsonnet_gcmodule::Trace;
+
+	#[derive(Clone, Copy, Default, Debug, Trace)]
+	pub struct FieldIndex(());
+	impl FieldIndex {
+		pub const fn next(self) -> Self {
+			Self(())
+		}
+	}
+
+	#[derive(Clone, Copy, Default, Debug, Trace)]
+	pub struct SuperDepth(());
+	impl SuperDepth {
+		pub(super) fn deepen(self) {}
+	}
+}
+
+#[cfg(feature = "exp-preserve-order")]
+mod ordering {
+	use std::cmp::Reverse;
+
+	use jrsonnet_gcmodule::Trace;
+
+	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
+	pub struct FieldIndex(u32);
+	impl FieldIndex {
+		pub fn next(self) -> Self {
+			Self(self.0 + 1)
+		}
+	}
+
+	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]
+	pub struct SuperDepth(u32);
+	impl SuperDepth {
+		pub(super) fn deepen(&mut self) {
+			self.0 += 1
+		}
+	}
+
+	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
+	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);
+	impl FieldSortKey {
+		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {
+			Self(Reverse(depth), index)
+		}
+	}
+}
+
+#[cfg(feature = "exp-preserve-order")]
+use ordering::FieldSortKey;
+use ordering::{FieldIndex, SuperDepth};
+
+// 0 - add
+//  12 - visibility
+#[derive(Clone, Copy)]
+pub struct ObjFieldFlags(u8);
+impl ObjFieldFlags {
+	fn new(add: bool, visibility: Visibility) -> Self {
+		let mut v = 0;
+		if add {
+			v |= 1;
+		}
+		v |= match visibility {
+			Visibility::Normal => 0b000,
+			Visibility::Hidden => 0b010,
+			Visibility::Unhide => 0b100,
+		};
+		Self(v)
+	}
+	pub fn add(&self) -> bool {
+		self.0 & 1 != 0
+	}
+	pub fn visibility(&self) -> Visibility {
+		match (self.0 & 0b110) >> 1 {
+			0b00 => Visibility::Normal,
+			0b01 => Visibility::Hidden,
+			0b10 => Visibility::Unhide,
+			_ => unreachable!(),
+		}
+	}
+}
+impl Debug for ObjFieldFlags {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.debug_struct("ObjFieldFlags")
+			.field("add", &self.add())
+			.field("visibility", &self.visibility())
+			.finish()
+	}
+}
+
+#[allow(clippy::module_name_repetitions)]
+#[derive(Debug, Trace)]
+pub struct ObjMember {
+	#[trace(skip)]
+	flags: ObjFieldFlags,
+	original_index: FieldIndex,
+	pub invoke: MaybeUnbound,
+	pub location: Option<Span>,
+}
+
+cc_dyn!(CcObjectAssertion, ObjectAssertion);
+pub trait ObjectAssertion: Trace {
+	fn run(&self, sup_this: SupThis) -> Result<()>;
+}
+
+// Field => This
+
+#[derive(Trace, Debug)]
+enum CacheValue {
+	Cached(Result<Option<Val>>),
+	Pending,
+}
+
+type EnumFieldsHandler<'a> =
+	dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;
+
+pub enum EnumFields {
+	Normal(Visibility),
+	Omit(Skip),
+}
+
+#[derive(Trace, Clone)]
+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(#[trace(skip)] Skip),
+	NotFound,
+}
+
+#[derive(Acyclic, Clone)]
+pub enum FieldVisibility {
+	Found(Visibility),
+	Omit(Skip),
+	NotFound,
+}
+
+#[derive(Acyclic, Clone)]
+pub enum HasFieldIncludeHidden {
+	Exists,
+	NotFound,
+	Omit(Skip),
+}
+
+type Skip = Saturating<usize>;
+
+pub trait ObjectCore: Trace + Any + Debug {
+	// If callback returns false, iteration stops, and this call returns false.
+	fn enum_fields_core(
+		&self,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
+	) -> bool;
+
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden;
+
+	fn get_for_core(&self, key: IStr, sup_this: SupThis, omit_only: bool) -> Result<GetFor>;
+	fn field_visibility_core(&self, field: IStr) -> FieldVisibility;
+
+	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()>;
+}
+
+#[derive(Clone, Trace)]
+pub struct WeakObjValue(#[trace(skip)] Weak<ObjValueInner>);
+impl Debug for WeakObjValue {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.debug_tuple("WeakObjValue").finish()
+	}
+}
+
+impl PartialEq for WeakObjValue {
+	fn eq(&self, other: &Self) -> bool {
+		Weak::ptr_eq(&self.0, &other.0)
+	}
+}
+
+impl Eq for WeakObjValue {}
+impl Hash for WeakObjValue {
+	fn hash<H: Hasher>(&self, hasher: &mut H) {
+		// Safety: usize is POD
+		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };
+		hasher.write_usize(addr);
+	}
+}
+
+cc_dyn!(
+	#[derive(Clone, Debug)]
+	CcObjectCore, ObjectCore,
+	pub fn new() {...}
+);
+#[derive(Trace, Educe)]
+#[educe(Debug)]
+struct ObjValueInner {
+	cores: Vec<CcObjectCore>,
+	assertions_ran: Cell<bool>,
+	value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
+}
+
+thread_local! {
+	static RUNNING_ASSERTIONS: RefCell<FxHashSet<ObjValue>> = RefCell::default();
+}
+fn is_asserting(obj: &ObjValue) -> bool {
+	RUNNING_ASSERTIONS.with_borrow(|v| v.contains(obj))
+}
+/// Returns false if already asserting
+fn start_asserting(obj: &ObjValue) -> bool {
+	RUNNING_ASSERTIONS.with_borrow_mut(|v| v.insert(obj.clone()))
+}
+fn finish_asserting(obj: &ObjValue) {
+	RUNNING_ASSERTIONS.with_borrow_mut(|v| {
+		let r = v.remove(obj);
+		debug_assert!(
+			r,
+			"finish_asserting was called before start_asserting or twice"
+		);
+	});
+}
+
+thread_local! {
+	static EMPTY_OBJ: ObjValue = ObjValue(Cc::new(ObjValueInner {
+		cores: vec![],
+		assertions_ran: Cell::new(true),
+		value_cache: RefCell::default(),
+	}))
+}
+
+#[allow(clippy::module_name_repetitions)]
+#[derive(Clone, Trace, Debug, Educe)]
+#[educe(PartialEq, Hash, Eq)]
+pub struct ObjValue(
+	#[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,
+	this: ObjValue,
+}
+impl ObjectCore for StandaloneSuperCore {
+	fn enum_fields_core(
+		&self,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
+	) -> bool {
+		self.this.enum_fields_idx(super_depth, handler, 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_core(&self, key: IStr, _sup_this: SupThis, omit_only: bool) -> Result<GetFor> {
+		if omit_only {
+			return Ok(GetFor::NotFound);
+		}
+		let v = self.this.get_idx(key, self.sup)?;
+		Ok(v.map_or(GetFor::NotFound, |v| GetFor::Final(v)))
+	}
+
+	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_core(&self, _sup_this: SupThis) -> Result<()> {
+		self.this.run_assertions()
+	}
+}
+
+#[derive(Debug, Acyclic)]
+struct OmitFieldsCore {
+	omit: FxHashSet<IStr>,
+	prev_layers: usize,
+}
+impl ObjectCore for OmitFieldsCore {
+	fn enum_fields_core(
+		&self,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
+	) -> bool {
+		let mut fi = FieldIndex::default();
+		for f in &self.omit {
+			if handler(
+				*super_depth,
+				fi,
+				f.clone(),
+				EnumFields::Omit(Saturating(self.prev_layers)),
+			) == ControlFlow::Break(())
+			{
+				return false;
+			}
+			fi = fi.next();
+		}
+		true
+	}
+
+	fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
+		if self.omit.contains(&name) {
+			return HasFieldIncludeHidden::Omit(Saturating(self.prev_layers));
+		}
+		HasFieldIncludeHidden::NotFound
+	}
+
+	fn get_for_core(&self, key: IStr, _sup_this: SupThis, _omit_only: bool) -> Result<GetFor> {
+		if self.omit.contains(&key) {
+			return Ok(GetFor::Omit(Saturating(self.prev_layers)));
+		}
+		Ok(GetFor::NotFound)
+	}
+
+	fn field_visibility_core(&self, field: IStr) -> FieldVisibility {
+		if self.omit.contains(&field) {
+			return FieldVisibility::Omit(Saturating(self.prev_layers));
+		}
+		FieldVisibility::NotFound
+	}
+
+	fn run_assertions_core(&self, _sup_this: SupThis) -> Result<()> {
+		Ok(())
+	}
+}
+
+#[derive(Hash, PartialEq, Eq, Trace, Clone, Copy, Debug)]
+struct CoreIdx {
+	idx: usize,
+}
+impl CoreIdx {
+	fn super_exists(self) -> bool {
+		self.idx != 0
+	}
+}
+#[derive(Trace, Clone, PartialEq, Eq, Hash, Debug)]
+pub struct SupThis {
+	sup: CoreIdx,
+	this: ObjValue,
+}
+impl SupThis {
+	pub fn has_super(&self) -> bool {
+		self.sup.super_exists()
+	}
+	/// Implementation of `"field" in super` operation,
+	/// works faster than standalone super path.
+	///
+	/// In case of no `super` existence, returns false.
+	pub fn field_in_super(&self, field: IStr) -> bool {
+		self.this.has_field_include_hidden_idx(field, self.sup)
+	}
+	/// Implementation of `super.field` operation,
+	/// works faster than standalone super path.
+	///
+	/// In case of no `super` existence, returns `NoSuperFound`
+	pub fn get_super(&self, field: IStr) -> Result<Option<Val>> {
+		if !self.sup.super_exists() {
+			bail!(NoSuperFound);
+		}
+		self.this.get_idx(field, self.sup)
+	}
+	/// `super` with `self` overriden for top-level lookups.
+	/// Exists when super appears outside of `super.field`/`"field" in super` expressions
+	/// Exclusive to jrsonnet.
+	///
+	/// Might return `NoSuperFound` error.
+	pub fn standalone_super(&self) -> Result<ObjValue> {
+		if !self.sup.super_exists() {
+			bail!(NoSuperFound)
+		}
+		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
+	}
+	pub fn downgrade(self) -> WeakSupThis {
+		WeakSupThis {
+			sup: self.sup,
+			this: self.this.downgrade(),
+		}
+	}
+}
+#[derive(Trace, PartialEq, Eq, Hash, Debug)]
+pub struct WeakSupThis {
+	sup: CoreIdx,
+	this: WeakObjValue,
+}
+
+impl ObjValue {
+	pub fn builder() -> ObjValueBuilder {
+		ObjValueBuilder::new()
+	}
+	pub fn builder_with_capacity(capacity: usize) -> ObjValueBuilder {
+		ObjValueBuilder::with_capacity(capacity)
+	}
+	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {
+		let mut out = ObjValueBuilder::with_capacity(1);
+		out.with_super(self);
+		let mut member = out.field(key);
+		if value.flags.add() {
+			member = member.add();
+		}
+		if let Some(loc) = value.location {
+			member = member.with_location(loc);
+		}
+		let _ = member
+			.with_visibility(value.flags.visibility())
+			.binding(value.invoke);
+		out.build()
+	}
+	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder<'_>> {
+		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();
+		cores.extend(self.0.cores.iter().cloned());
+		ObjValue(Cc::new(ObjValueInner {
+			cores,
+			value_cache: RefCell::default(),
+			assertions_ran: Cell::new(false),
+		}))
+	}
+	// #[must_use]
+	// pub fn with_this(&self, this: Self) -> Self {
+	// 	self.0.with_this(self.clone(), this)
+	// }
+	/// Returns amount of visible object fields
+	/// If object only contains hidden fields - may return zero.
+	pub fn len(&self) -> usize {
+		self.fields_visibility()
+			.values()
+			.filter(|d| d.visible())
+			.count()
+	}
+	/// 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_idx(
+			&mut super_depth,
+			handler,
+			CoreIdx {
+				idx: self.0.cores.len(),
+			},
+		)
+	}
+	fn enum_fields_idx(
+		&self,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
+		idx: CoreIdx,
+	) -> bool {
+		for core in self.0.cores[..idx.idx].iter().rev() {
+			if !core.0.enum_fields_core(super_depth, handler) {
+				return false;
+			}
+			super_depth.deepen();
+		}
+		true
+	}
+
+	pub fn has_field_include_hidden(&self, name: IStr) -> bool {
+		self.has_field_include_hidden_idx(
+			name,
+			CoreIdx {
+				idx: self.0.cores.len(),
+			},
+		)
+	}
+	fn has_field_include_hidden_idx(&self, name: IStr, core: CoreIdx) -> bool {
+		let mut skip = Saturating(0usize);
+		for ele in self.0.cores[..core.idx].iter().rev() {
+			match ele.0.has_field_include_hidden_core(name.clone()) {
+				HasFieldIncludeHidden::Exists => {
+					if skip.0 == 0 {
+						return true;
+					}
+				}
+				HasFieldIncludeHidden::Omit(new_skip) => {
+					// +1 including this core
+					skip = skip.max(new_skip + Saturating(1));
+				}
+				HasFieldIncludeHidden::NotFound => {}
+			}
+			skip -= 1;
+		}
+		false
+	}
+	pub fn has_field(&self, name: IStr) -> bool {
+		match self.field_visibility(name) {
+			Some(Visibility::Unhide | Visibility::Normal) => true,
+			Some(Visibility::Hidden) | None => false,
+		}
+	}
+	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {
+		if include_hidden {
+			self.has_field_include_hidden(name)
+		} else {
+			self.has_field(name)
+		}
+	}
+	pub fn get(&self, key: IStr) -> Result<Option<Val>> {
+		self.get_idx(
+			key,
+			CoreIdx {
+				idx: self.0.cores.len(),
+			},
+		)
+	}
+
+	fn get_idx(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
+		let cache_key = (key.clone(), core);
+		{
+			let mut cache = self.0.value_cache.borrow_mut();
+			// entry_ref candidate?
+			match cache.entry(cache_key.clone()) {
+				Entry::Occupied(v) => match v.get() {
+					CacheValue::Cached(v) => return v.clone(),
+					CacheValue::Pending => {
+						if !is_asserting(self) {
+							bail!(InfiniteRecursionDetected);
+						}
+					}
+				},
+				Entry::Vacant(v) => {
+					v.insert(CacheValue::Pending);
+				}
+			};
+		}
+		let result = self.get_idx_uncached(key, core);
+		{
+			let mut cache = self.0.value_cache.borrow_mut();
+			cache.insert(cache_key, CacheValue::Cached(result.clone()));
+		}
+		result
+	}
+	fn get_idx_uncached(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
+		self.run_assertions()?;
+		let mut add_stack = Vec::with_capacity(2);
+		let mut skip = Saturating(0);
+		for (sup, core) in self.0.cores[..core.idx].iter().enumerate().rev() {
+			let sup_this = SupThis {
+				sup: CoreIdx { idx: sup },
+				this: self.clone(),
+			};
+			match core.0.get_for_core(key.clone(), sup_this, skip.0 != 0)? {
+				GetFor::Final(val) if add_stack.is_empty() => {
+					if skip.0 == 0 {
+						return Ok(Some(val));
+					}
+				}
+				GetFor::Final(val) => {
+					if skip.0 == 0 {
+						add_stack.push(val);
+						break;
+					}
+				}
+				GetFor::SuperPlus(val) => {
+					if skip.0 == 0 {
+						add_stack.push(val);
+					}
+				}
+				GetFor::Omit(new_skip) => {
+					// +1 including this core
+					skip = skip.max(new_skip + Saturating(1));
+				}
+				GetFor::NotFound => {}
+			}
+			skip -= 1;
+		}
+		if add_stack.is_empty() {
+			// None of layers had this field
+			return Ok(None);
+		} else if add_stack.len() == 1 {
+			// A layer had this field, but it wanted this field to be added with super.
+			// However, no super had this field, fail-safe
+			return Ok(Some(add_stack.pop().expect("single element on stack")));
+		}
+		let mut values = add_stack.into_iter().rev();
+		let init = values.next().expect("at least 2 elements");
+
+		values
+			.try_fold(init, |a, b| evaluate_add_op(&a, &b))
+			.map(Some)
+
+		// self.0.get_raw(key, this)
+	}
+
+	pub fn get_or_bail(&self, key: IStr) -> Result<Val> {
+		let Some(value) = self.get(key.clone())? else {
+			let suggestions = suggest_object_fields(self, key.clone());
+			bail!(NoSuchField(key, suggestions))
+		};
+		Ok(value)
+	}
+
+	fn field_visibility(&self, field: IStr) -> Option<Visibility> {
+		self.field_visibility_idx(
+			field,
+			CoreIdx {
+				idx: self.0.cores.len(),
+			},
+		)
+	}
+	fn field_visibility_idx(&self, field: IStr, core: CoreIdx) -> Option<Visibility> {
+		let mut exists = false;
+		let mut skip = Saturating(0usize);
+		for ele in self.0.cores[..core.idx].iter().rev() {
+			let vis = ele.0.field_visibility_core(field.clone());
+			match vis {
+				FieldVisibility::Found(vis @ (Visibility::Unhide | Visibility::Hidden)) => {
+					if skip.0 == 0 {
+						return Some(vis);
+					}
+				}
+				FieldVisibility::Found(Visibility::Normal) => {
+					if skip.0 == 0 {
+						exists = true;
+					}
+				}
+				FieldVisibility::NotFound => {}
+				FieldVisibility::Omit(new_skip) => {
+					// +1 including this core
+					skip = skip.max(new_skip + Saturating(1));
+				}
+			}
+			skip -= 1;
+		}
+		exists.then_some(Visibility::Normal)
+	}
+
+	pub fn run_assertions(&self) -> Result<()> {
+		if self.0.assertions_ran.get() {
+			return Ok(());
+		}
+		if !start_asserting(self) {
+			return Ok(());
+		}
+		for (idx, ele) in self.0.cores.iter().enumerate() {
+			let sup_this = SupThis {
+				sup: CoreIdx { idx },
+				this: self.clone(),
+			};
+			ele.0.run_assertions_core(sup_this).inspect_err(|_e| {
+				finish_asserting(self);
+			})?;
+		}
+		finish_asserting(self);
+		self.0.assertions_ran.set(true);
+		Ok(())
+	}
+
+	pub fn iter(
+		&self,
+		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
+	) -> impl Iterator<Item = (IStr, Result<Val>)> + '_ {
+		let fields = self.fields(
+			#[cfg(feature = "exp-preserve-order")]
+			preserve_order,
+		);
+		fields.into_iter().map(|field| {
+			(
+				field.clone(),
+				self.get(field)
+					.map(|opt| opt.expect("iterating over keys, field exists")),
+			)
+		})
+	}
+	pub fn get_lazy(&self, key: IStr) -> Option<Thunk<Val>> {
+		#[derive(Trace)]
+		struct ObjFieldThunk {
+			obj: ObjValue,
+			key: IStr,
+		}
+		impl ThunkValue for ObjFieldThunk {
+			type Output = Val;
+
+			fn get(&self) -> Result<Self::Output> {
+				self.obj
+					.get(self.key.clone())
+					.transpose()
+					.expect("field existence checked")
+			}
+		}
+
+		if !self.has_field_ex(key.clone(), true) {
+			return None;
+		}
+
+		Some(Thunk::new(ObjFieldThunk {
+			obj: self.clone(),
+			key,
+		}))
+	}
+	pub fn get_lazy_or_bail(&self, key: IStr) -> Thunk<Val> {
+		#[derive(Trace)]
+		struct ObjFieldThunk {
+			obj: ObjValue,
+			key: IStr,
+		}
+		impl ThunkValue for ObjFieldThunk {
+			type Output = Val;
+
+			fn get(&self) -> Result<Self::Output> {
+				self.obj.get_or_bail(self.key.clone())
+			}
+		}
+
+		Thunk::new(ObjFieldThunk {
+			obj: self.clone(),
+			key,
+		})
+	}
+	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
+		Cc::ptr_eq(&a.0, &b.0)
+	}
+	pub fn downgrade(self) -> WeakObjValue {
+		WeakObjValue(self.0.downgrade())
+	}
+}
+
+#[derive(Debug)]
+struct FieldVisibilityData {
+	omitted_until: Saturating<usize>,
+	exists_visible: Option<Visibility>,
+	#[cfg(feature = "exp-preserve-order")]
+	key: FieldSortKey,
+}
+impl FieldVisibilityData {
+	fn visible(&self) -> bool {
+		self.exists_visible
+			.expect("non-existing fields shall be dropped at the end of fn fields_visibility()")
+			.is_visible()
+	}
+	#[cfg(feature = "exp-preserve-order")]
+	fn sort_key(&self) -> FieldSortKey {
+		self.key
+	}
+}
+
+impl ObjValue {
+	fn fields_visibility(&self) -> FxHashMap<IStr, FieldVisibilityData> {
+		let mut out = FxHashMap::default();
+
+		let mut super_depth = SuperDepth::default();
+		let mut omit_index = Saturating(0);
+		for core in self.0.cores.iter().rev() {
+			core.0
+				.enum_fields_core(&mut super_depth, &mut |_depth, _index, name, visibility| {
+					let entry = out.entry(name);
+					let data = entry.or_insert(FieldVisibilityData {
+						exists_visible: None,
+						#[cfg(feature = "exp-preserve-order")]
+						key: FieldSortKey::new(_depth, _index),
+						omitted_until: omit_index,
+					});
+					match visibility {
+						EnumFields::Omit(new_skip) => {
+							// +1 including this core
+							data.omitted_until = data
+								.omitted_until
+								.max(omit_index + new_skip + Saturating(1));
+						}
+						EnumFields::Normal(Visibility::Normal) => {
+							if data.omitted_until <= omit_index && data.exists_visible.is_none() {
+								data.exists_visible = Some(Visibility::Normal);
+							}
+						}
+						EnumFields::Normal(Visibility::Hidden) => {
+							if data.omitted_until <= omit_index {
+								data.exists_visible = Some(match data.exists_visible {
+									// We're iterating in reverse, later unhide is preserved
+									Some(Visibility::Unhide) => Visibility::Unhide,
+									_ => Visibility::Hidden,
+								});
+							}
+						}
+						EnumFields::Normal(Visibility::Unhide) => {
+							if data.omitted_until <= omit_index {
+								data.exists_visible = Some(match data.exists_visible {
+									// We're iterating in reverse, later hide is preserved
+									Some(Visibility::Hidden) => Visibility::Hidden,
+									_ => Visibility::Unhide,
+								});
+							}
+						}
+					}
+					ControlFlow::Continue(())
+				});
+
+			super_depth.deepen();
+			omit_index += 1;
+		}
+
+		out.retain(|_, v| v.exists_visible.is_some());
+
+		out
+	}
+	pub fn fields_ex(
+		&self,
+		include_hidden: bool,
+		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
+	) -> Vec<IStr> {
+		#[cfg(feature = "exp-preserve-order")]
+		if preserve_order {
+			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self
+				.fields_visibility()
+				.into_iter()
+				.filter(|(_, d)| include_hidden || d.visible())
+				.enumerate()
+				.map(|(idx, (k, d))| (k, (d.sort_key(), idx)))
+				.unzip();
+			keys.sort_unstable_by_key(|v| v.0);
+			// Reorder in-place by resulting indexes
+			for i in 0..fields.len() {
+				let x = fields[i].clone();
+				let mut j = i;
+				loop {
+					let k = keys[j].1;
+					keys[j].1 = j;
+					if k == i {
+						break;
+					}
+					fields[j] = fields[k].clone();
+					j = k;
+				}
+				fields[j] = x;
+			}
+			return fields;
+		}
+
+		let mut fields: Vec<_> = self
+			.fields_visibility()
+			.into_iter()
+			.filter(|(_, d)| include_hidden || d.visible())
+			.map(|(k, _)| k)
+			.collect();
+		fields.sort_unstable();
+		fields
+	}
+	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {
+		self.fields_ex(
+			false,
+			#[cfg(feature = "exp-preserve-order")]
+			preserve_order,
+		)
+	}
+	pub fn values_ex(
+		&self,
+		include_hidden: bool,
+		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
+	) -> ArrValue {
+		ArrValue::new(PickObjectValues::new(
+			self.clone(),
+			self.fields_ex(
+				include_hidden,
+				#[cfg(feature = "exp-preserve-order")]
+				preserve_order,
+			),
+		))
+	}
+	pub fn values(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> ArrValue {
+		self.values_ex(
+			false,
+			#[cfg(feature = "exp-preserve-order")]
+			preserve_order,
+		)
+	}
+	pub fn key_values_ex(
+		&self,
+		include_hidden: bool,
+		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
+	) -> ArrValue {
+		ArrValue::new(PickObjectKeyValues::new(
+			self.clone(),
+			self.fields_ex(
+				include_hidden,
+				#[cfg(feature = "exp-preserve-order")]
+				preserve_order,
+			),
+		))
+	}
+	pub fn key_values(
+		&self,
+		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,
+	) -> ArrValue {
+		self.key_values_ex(
+			false,
+			#[cfg(feature = "exp-preserve-order")]
+			preserve_order,
+		)
+	}
+}
+
+#[allow(clippy::module_name_repetitions)]
+#[must_use = "value not added unless binding() was called"]
+pub struct ObjMemberBuilder<Kind> {
+	kind: Kind,
+	name: IStr,
+	add: bool,
+	visibility: Visibility,
+	original_index: FieldIndex,
+	location: Option<Span>,
+}
+
+#[allow(clippy::missing_const_for_fn)]
+impl<Kind> ObjMemberBuilder<Kind> {
+	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {
+		Self {
+			kind,
+			name,
+			original_index,
+			add: false,
+			visibility: Visibility::Normal,
+			location: None,
+		}
+	}
+
+	pub const fn with_add(mut self, add: bool) -> Self {
+		self.add = add;
+		self
+	}
+	pub fn add(self) -> Self {
+		self.with_add(true)
+	}
+	pub fn with_visibility(mut self, visibility: Visibility) -> Self {
+		self.visibility = visibility;
+		self
+	}
+	pub fn hide(self) -> Self {
+		self.with_visibility(Visibility::Hidden)
+	}
+	pub fn with_location(mut self, location: Span) -> Self {
+		self.location = Some(location);
+		self
+	}
+	fn build_member(self, binding: MaybeUnbound) -> (Kind, IStr, ObjMember) {
+		(
+			self.kind,
+			self.name,
+			ObjMember {
+				flags: ObjFieldFlags::new(self.add, self.visibility),
+				original_index: self.original_index,
+				invoke: binding,
+				location: self.location,
+			},
+		)
+	}
+}
+
+pub struct ExtendBuilder<'v>(&'v mut ObjValue);
+impl ObjMemberBuilder<ExtendBuilder<'_>> {
+	pub fn value(self, value: impl Into<Val>) {
+		self.binding(MaybeUnbound::Bound(Thunk::evaluated(value.into())));
+	}
+	pub fn bindable(self, bindable: impl Unbound<Bound = Val>) {
+		self.binding(MaybeUnbound::Unbound(CcUnbound::new(bindable)));
+	}
+	pub fn binding(self, binding: MaybeUnbound) {
+		let (receiver, name, member) = self.build_member(binding);
+		let new = receiver.0.clone();
+		*receiver.0 = new.extend_with_raw_member(name, member);
+	}
+}
addedcrates/jrsonnet-evaluator/src/obj/oop.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/src/obj/oop.rs
@@ -0,0 +1,248 @@
+use std::cell::Cell;
+use std::ops::ControlFlow;
+use std::{fmt, mem};
+
+use crate::function::{CallLocation, FuncVal};
+use crate::gc::WithCapacityExt as _;
+use crate::{
+	bail, error::ErrorKind::*, in_frame, CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
+};
+use jrsonnet_gcmodule::{Cc, Trace};
+use jrsonnet_parser::IStr;
+use rustc_hash::{FxHashMap, FxHashSet};
+
+use super::ordering::{FieldIndex, SuperDepth};
+use super::{
+	CcObjectAssertion, CcObjectCore, EnumFields, EnumFieldsHandler, FieldVisibility, GetFor,
+	HasFieldIncludeHidden, ObjMember, ObjMemberBuilder, ObjValue, ObjValueInner, ObjectAssertion,
+	ObjectCore, OmitFieldsCore, SupThis,
+};
+
+#[allow(clippy::module_name_repetitions)]
+#[derive(Trace, Default)]
+#[trace(tracking(force))]
+pub struct OopObject {
+	assertion: Option<CcObjectAssertion>,
+	this_entries: FxHashMap<IStr, ObjMember>,
+}
+impl fmt::Debug for OopObject {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.debug_struct("OopObject")
+			.field("this_entries", &self.this_entries)
+			.finish_non_exhaustive()
+	}
+}
+impl OopObject {
+	fn is_empty(&self) -> bool {
+		self.assertion.is_none() && self.this_entries.is_empty()
+	}
+}
+impl OopObject {
+	pub fn new(
+		this_entries: FxHashMap<IStr, ObjMember>,
+		assertion: Option<CcObjectAssertion>,
+	) -> Self {
+		Self {
+			assertion,
+			this_entries,
+		}
+	}
+}
+
+impl ObjectCore for OopObject {
+	fn enum_fields_core(
+		&self,
+		super_depth: &mut SuperDepth,
+		handler: &mut EnumFieldsHandler<'_>,
+	) -> bool {
+		for (name, member) in &self.this_entries {
+			if matches!(
+				handler(
+					*super_depth,
+					member.original_index,
+					name.clone(),
+					EnumFields::Normal(member.flags.visibility()),
+				),
+				ControlFlow::Break(())
+			) {
+				return false;
+			}
+		}
+		true
+	}
+
+	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_core(&self, key: IStr, sup_this: SupThis, omit_only: bool) -> Result<GetFor> {
+		if omit_only {
+			return Ok(GetFor::NotFound);
+		}
+		match self.this_entries.get(&key) {
+			Some(k) => {
+				let v = k.invoke.evaluate(sup_this)?;
+				Ok(if k.flags.add() {
+					GetFor::SuperPlus(v)
+				} else {
+					GetFor::Final(v)
+				})
+			}
+			None => Ok(GetFor::NotFound),
+		}
+	}
+	fn field_visibility_core(&self, name: IStr) -> FieldVisibility {
+		self.this_entries
+			.get(&name)
+			.map_or(FieldVisibility::NotFound, |f| {
+				FieldVisibility::Found(f.flags.visibility())
+			})
+	}
+
+	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {
+		if let Some(assertion) = &self.assertion {
+			assertion.0.run(sup_this.clone())?;
+		}
+		Ok(())
+	}
+}
+
+#[allow(clippy::module_name_repetitions)]
+pub struct ObjValueBuilder {
+	sup: Vec<CcObjectCore>,
+
+	new: OopObject,
+	next_field_index: FieldIndex,
+}
+impl ObjValueBuilder {
+	pub fn new() -> Self {
+		Self::with_capacity(0)
+	}
+	pub fn with_capacity(capacity: usize) -> Self {
+		Self {
+			sup: vec![],
+			new: OopObject::new(FxHashMap::with_capacity(capacity), None),
+			next_field_index: FieldIndex::default(),
+		}
+	}
+	pub fn reserve_cores(&mut self, capacity: usize) -> &mut Self {
+		self.sup.reserve_exact(capacity);
+		self
+	}
+	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {
+		self.sup.clone_from(&super_obj.0.cores);
+		self
+	}
+
+	pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {
+		assert!(
+			self.new.assertion.is_none(),
+			"one OopObject can only have one assertion"
+		);
+		self.new.assertion = Some(CcObjectAssertion::new(assertion));
+		self
+	}
+	pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {
+		let field_index = self.next_field_index;
+		self.next_field_index = self.next_field_index.next();
+		ObjMemberBuilder::new(ValueBuilder(self), name.into(), field_index)
+	}
+	/// Preset for common method definiton pattern:
+	/// Create a hidden field with the function value.
+	///
+	/// `.field(name).hide().value(Val::function(value))`
+	pub fn method(&mut self, name: impl Into<IStr>, value: impl Into<FuncVal>) -> &mut Self {
+		self.field(name).hide().value(Val::Func(value.into()));
+		self
+	}
+	pub fn try_method(
+		&mut self,
+		name: impl Into<IStr>,
+		value: impl Into<FuncVal>,
+	) -> Result<&mut Self> {
+		self.field(name).hide().try_value(Val::Func(value.into()))?;
+		Ok(self)
+	}
+
+	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,
+			prev_layers: self.sup.len(),
+		}));
+	}
+
+	pub fn build(mut self) -> ObjValue {
+		self.commit();
+		if self.sup.is_empty() {
+			return ObjValue::empty();
+		}
+		ObjValue(Cc::new(ObjValueInner {
+			cores: self.sup,
+			assertions_ran: Cell::new(false),
+			value_cache: Default::default(),
+		}))
+	}
+}
+impl Default for ObjValueBuilder {
+	fn default() -> Self {
+		Self::with_capacity(0)
+	}
+}
+
+pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);
+impl ObjMemberBuilder<ValueBuilder<'_>> {
+	/// Inserts value, replacing if it is already defined
+	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.new.this_entries.entry(name);
+		entry.insert_entry(member);
+	}
+	/// Inserts thunk, replacing if it is already defined
+	pub fn thunk(self, value: impl Into<Thunk<Val>>) {
+		let (receiver, name, member) = self.build_member(MaybeUnbound::Bound(value.into()));
+		let entry = receiver.0.new.this_entries.entry(name);
+		entry.insert_entry(member);
+	}
+
+	/// Tries to insert value, returns an error if it was already defined
+	pub fn try_value(self, value: impl Into<Val>) -> Result<()> {
+		self.try_thunk(Thunk::evaluated(value.into()))
+	}
+	pub fn try_thunk(self, value: impl Into<Thunk<Val>>) -> Result<()> {
+		self.binding(MaybeUnbound::Bound(value.into()))
+	}
+	pub fn bindable(self, bindable: impl Unbound<Bound = Val>) -> Result<()> {
+		self.binding(MaybeUnbound::Unbound(CcUnbound::new(bindable)))
+	}
+	pub fn binding(self, binding: MaybeUnbound) -> Result<()> {
+		let (receiver, name, member) = self.build_member(binding);
+		let location = member.location.clone();
+		let old = receiver.0.new.this_entries.insert(name.clone(), member);
+		if old.is_some() {
+			in_frame(
+				CallLocation(location.as_ref()),
+				|| format!("field <{}> initializtion", name.clone()),
+				|| bail!(DuplicateFieldName(name.clone())),
+			)?;
+		}
+		Ok(())
+	}
+}