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

difftreelog

feat wire jrsonnet-web for experimental features

mqyzspnqYaroslav Bolyukin2026-05-06parent: #7324ad9.patch.diff
in: master

11 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2695,6 +2695,7 @@
  "jrsonnet-stdlib",
  "jrsonnet-types",
  "js-sys",
+ "num-bigint",
  "rustc-hash 2.1.2",
  "url",
  "wasm-bindgen",
modifiedbindings/jrsonnet-web/Cargo.tomldiffbeforeafterboth
--- a/bindings/jrsonnet-web/Cargo.toml
+++ b/bindings/jrsonnet-web/Cargo.toml
@@ -9,6 +9,19 @@
 repository.workspace = true
 version.workspace = true
 
+[features]
+experimental = ["exp-preserve-order", "exp-bigint"]
+exp-preserve-order = [
+  "jrsonnet-evaluator/exp-preserve-order",
+  "jrsonnet-stdlib/exp-preserve-order",
+]
+exp-bigint = [
+  "dep:num-bigint",
+  "jrsonnet-evaluator/exp-bigint",
+  "jrsonnet-stdlib/exp-bigint",
+  "jrsonnet-types/exp-bigint",
+]
+
 [dependencies]
 console_error_panic_hook.workspace = true
 getrandom = { workspace = true, features = ["wasm_js"] }
@@ -19,6 +32,7 @@
 jrsonnet-stdlib.workspace = true
 jrsonnet-types.workspace = true
 js-sys.workspace = true
+num-bigint = { workspace = true, optional = true }
 rustc-hash.workspace = true
 url.workspace = true
 wasm-bindgen.workspace = true
modifiedbindings/jrsonnet-web/src/lib.rsdiffbeforeafterboth
--- a/bindings/jrsonnet-web/src/lib.rs
+++ b/bindings/jrsonnet-web/src/lib.rs
@@ -31,6 +31,7 @@
 	Arr,
 	Obj,
 	Func,
+	BigInt,
 }
 
 thread_local! {
@@ -132,6 +133,8 @@
 			ValType::Arr => Self::Arr,
 			ValType::Obj => Self::Obj,
 			ValType::Func => Self::Func,
+			#[cfg(feature = "exp-bigint")]
+			ValType::BigInt => Self::BigInt,
 		}
 	}
 }
@@ -182,6 +185,26 @@
 	pub fn string(s: String) -> Self {
 		Self::new(Val::string(s))
 	}
+	pub fn bigint(value: js_sys::BigInt) -> Result<Self, JsError> {
+		#[cfg(feature = "exp-bigint")]
+		{
+			let s: String = value
+				.to_string(10)
+				.map_err(|_| JsError::new("invalid bigint"))?
+				.into();
+			let bi = s
+				.parse::<num_bigint::BigInt>()
+				.map_err(|e| JsError::new(&format!("failed to parse bigint: {e}")))?;
+			Ok(Self::new(Val::BigInt(Box::new(bi))))
+		}
+		#[cfg(not(feature = "exp-bigint"))]
+		{
+			let _ = value;
+			Err(JsError::new(
+				"bigint support is not enabled in this build (exp-bigint feature)",
+			))
+		}
+	}
 	pub fn arr(items: Vec<WasmVal>) -> Self {
 		Self::new(Val::arr(
 			items.into_iter().map(|v| v.val).collect::<Vec<_>>(),
@@ -212,6 +235,24 @@
 	pub fn as_num(&self) -> Option<f64> {
 		self.val.as_num()
 	}
+	#[wasm_bindgen(js_name = asBigint)]
+	pub fn as_bigint(&self) -> Result<Option<js_sys::BigInt>, JsError> {
+		#[cfg(feature = "exp-bigint")]
+		{
+			let Some(bi) = self.val.as_bigint() else {
+				return Ok(None);
+			};
+			let big = js_sys::BigInt::new(&JsValue::from_str(&bi.to_string()))
+				.map_err(|e| JsError::new(&format!("{e:?}")))?;
+			Ok(Some(big))
+		}
+		#[cfg(not(feature = "exp-bigint"))]
+		{
+			Err(JsError::new(
+				"bigint support is not enabled in this build (exp-bigint feature)",
+			))
+		}
+	}
 	#[wasm_bindgen(js_name = asString)]
 	pub fn as_string(&self) -> Option<String> {
 		self.val.as_str().map(|s| s.to_string())
@@ -259,7 +300,11 @@
 
 	#[wasm_bindgen(js_name = manifestJson)]
 	pub fn manifest_json(&self, indent: u32) -> Result<String, JsValue> {
-		self.manifest_with(JsonFormat::cli(indent as usize))
+		self.manifest_with(JsonFormat::cli(
+			indent as usize,
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		))
 	}
 	#[wasm_bindgen(js_name = manifestToString)]
 	pub fn manifest_to_string(&self) -> Result<String, JsValue> {
@@ -271,7 +316,12 @@
 	}
 	#[wasm_bindgen(js_name = manifestYaml)]
 	pub fn manifest_yaml(&self, indent: u32, quote_keys: bool) -> Result<String, JsValue> {
-		self.manifest_with(YamlFormat::std_to_yaml(indent != 0, quote_keys))
+		self.manifest_with(YamlFormat::std_to_yaml(
+			indent != 0,
+			quote_keys,
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		))
 	}
 	#[wasm_bindgen(js_name = manifestYamlStream)]
 	pub fn manifest_yaml_stream(
@@ -281,7 +331,12 @@
 		c_document_end: bool,
 	) -> Result<String, JsValue> {
 		self.manifest_with(YamlStreamFormat::std_yaml_stream(
-			YamlFormat::std_to_yaml(indent != 0, quote_keys),
+			YamlFormat::std_to_yaml(
+				indent != 0,
+				quote_keys,
+				#[cfg(feature = "exp-preserve-order")]
+				false,
+			),
 			c_document_end,
 		))
 	}
@@ -291,11 +346,18 @@
 	}
 	#[wasm_bindgen(js_name = manifestToml)]
 	pub fn manifest_toml(&self, indent: u32) -> Result<String, JsValue> {
-		self.manifest_with(TomlFormat::std_to_toml(" ".repeat(indent as usize)))
+		self.manifest_with(TomlFormat::std_to_toml(
+			" ".repeat(indent as usize),
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		))
 	}
 	#[wasm_bindgen(js_name = manifestIni)]
 	pub fn manifest_ini(&self) -> Result<String, JsValue> {
-		self.manifest_with(IniFormat::std())
+		self.manifest_with(IniFormat::std(
+			#[cfg(feature = "exp-preserve-order")]
+			false,
+		))
 	}
 }
 
@@ -340,7 +402,10 @@
 impl WasmObjValue {
 	pub fn keys(&self) -> Vec<String> {
 		self.obj
-			.fields()
+			.fields(
+				#[cfg(feature = "exp-preserve-order")]
+				false,
+			)
 			.into_iter()
 			.map(|s| s.to_string())
 			.collect()
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -13,6 +13,12 @@
 workspace = true
 
 [features]
+experimental = [
+  "exp-preserve-order",
+  "exp-bigint",
+  "exp-null-coaelse",
+  "exp-regex",
+]
 exp-preserve-order = [
   "jrsonnet-evaluator/exp-preserve-order",
   "jrsonnet-stdlib/exp-preserve-order",
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -26,6 +26,13 @@
 # Use PEG parser
 peg-parser = ["dep:jrsonnet-peg-parser"]
 
+experimental = [
+  "exp-preserve-order",
+  "exp-destruct",
+  "exp-object-iteration",
+  "exp-bigint",
+  "exp-null-coaelse",
+]
 # Allows to preserve field order in objects
 exp-preserve-order = []
 # Implements field destructuring
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/lib.rs
1//! jsonnet interpreter implementation2#![cfg_attr(nightly, feature(thread_local))]34// For jrsonnet-macros5extern crate self as jrsonnet_evaluator;67mod arr;8pub mod async_import;9mod ctx;10mod dynamic;11pub mod error;12mod evaluate;13pub mod function;14pub mod gc;15mod import;16mod integrations;17pub mod manifest;18mod obj;19pub mod stack;20pub mod stdlib;21pub mod tla;22pub mod trace;23pub mod typed;24pub mod val;2526use std::{27	any::Any,28	cell::{RefCell, RefMut},29	clone::Clone,30	collections::hash_map::Entry,31	fmt::{self, Debug},32	marker::PhantomData,33	rc::Rc,34};3536pub use ctx::*;37pub use dynamic::*;38pub use error::{Error, ErrorKind::*, Result, ResultExt, StackTraceElement};39pub use evaluate::ensure_sufficient_stack;40use function::CallLocation;41pub use import::*;42use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};43pub use jrsonnet_interner::{IBytes, IStr};44use jrsonnet_ir::Expr;45pub use jrsonnet_ir::{NumValue, Source, SourcePath, SourceUrl, SourceVirtual, Span};46#[doc(hidden)]47pub use jrsonnet_macros;4849#[cfg(not(any(feature = "ir-parser", feature = "peg-parser")))]50compile_error!("at least one of `ir-parser` or `peg-parser` features must be enabled");5152pub use error::SyntaxError;53pub use obj::*;54pub use rustc_hash;55use rustc_hash::FxHashMap;56use stack::check_depth;57pub use tla::apply_tla;58pub use val::{Thunk, Val};5960pub mod analyze;61use self::analyze::{LExpr, analyze_root};62use crate::gc::WithCapacityExt as _;6364#[allow(clippy::needless_return)]65pub(crate) fn parse_jsonnet(code: &str, source: Source) -> Result<Expr, SyntaxError> {66	#[cfg(feature = "peg-parser")]67	{68		use std::sync::LazyLock;69		static USE_LEGACY_PARSER: LazyLock<bool> =70			LazyLock::new(|| std::env::var_os("JRSONNET_LEGACY_PARSER").is_some());7172		if *USE_LEGACY_PARSER {73			return parse_peg(code, source);74		}75	}76	#[cfg(feature = "ir-parser")]77	{78		return parse_ir(code, source);79	}80	#[cfg(feature = "peg-parser")]81	{82		return parse_peg(code, source);83	}84}8586#[cfg(feature = "ir-parser")]87fn parse_ir(code: &str, source: Source) -> Result<Expr, SyntaxError> {88	jrsonnet_ir_parser::parse(code, &jrsonnet_ir_parser::ParserSettings { source }).map_err(|e| {89		SyntaxError {90			message: e.message,91			location: e.location,92		}93	})94}9596#[cfg(feature = "peg-parser")]97fn parse_peg(code: &str, source: Source) -> Result<Expr, SyntaxError> {98	jrsonnet_peg_parser::parse(code, &jrsonnet_peg_parser::ParserSettings { source }).map_err(|e| {99		let message = e100			.expected101			.tokens()102			.find(|t| t.starts_with("!!!"))103			.map_or_else(104				|| {105					format!(106						"expected {}, got {:?}",107						e.expected,108						code.chars()109							.nth(e.location.0)110							.map_or_else(|| "EOF".into(), |c: char| c.to_string())111					)112				},113				|v| v[3..].into(),114			);115		SyntaxError {116			message,117			location: e.location,118		}119	})120}121122cc_dyn!(123	#[derive(Clone)]124	CcUnbound<V>,125	Unbound<Bound = V>126);127128/// Thunk without bound `super`/`this`129/// object inheritance may be overriden multiple times, and will be fixed only on field read130pub trait Unbound: Trace {131	/// Type of value after object context is bound132	type Bound;133	/// Create value bound to specified object context134	fn bind(&self, sup_this: SupThis) -> Result<Self::Bound>;135}136137/// Object fields may, or may not depend on `this`/`super`, this enum allows cheaper reuse of object-independent fields for native code138/// Standard jsonnet fields are always unbound139#[derive(Clone, Trace)]140pub enum MaybeUnbound {141	/// Value needs to be bound to `this`/`super`142	Unbound(CcUnbound<Val>),143	/// Value is object-independent144	Bound(Thunk<Val>),145}146147impl Debug for MaybeUnbound {148	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {149		write!(f, "MaybeUnbound")150	}151}152impl MaybeUnbound {153	/// Attach object context to value, if required154	pub fn evaluate(&self, sup_this: SupThis) -> Result<Val> {155		match self {156			Self::Unbound(v) => v.0.bind(sup_this),157			Self::Bound(v) => Ok(v.evaluate()?),158		}159	}160}161162cc_dyn!(CcContextInitializer, ContextInitializer);163164/// During import, this trait will be called to create initial context for file.165/// It may initialize global variables, stdlib for example.166pub trait ContextInitializer {167	/// For composability: extend builder. May panic if this initialization is not supported,168	/// and the context may only be created via `initialize`.169	fn populate(&self, for_file: Source, builder: &mut InitialContextBuilder);170	/// Allows upcasting from abstract to concrete context initializer.171	/// jrsonnet by itself doesn't use this method, it is allowed for it to panic.172	fn as_any(&self) -> &dyn Any;173}174impl<T> ContextInitializer for &T175where176	T: ContextInitializer,177{178	fn populate(&self, for_file: Source, builder: &mut InitialContextBuilder) {179		(*self).populate(for_file, builder);180	}181182	fn as_any(&self) -> &dyn Any {183		(*self).as_any()184	}185}186187/// Context initializer which adds nothing.188impl ContextInitializer for () {189	fn populate(&self, _for_file: Source, _builder: &mut InitialContextBuilder) {}190	fn as_any(&self) -> &dyn Any {191		self192	}193}194195impl<T> ContextInitializer for Option<T>196where197	T: ContextInitializer + 'static,198{199	fn populate(&self, for_file: Source, builder: &mut InitialContextBuilder) {200		if let Some(ctx) = self {201			ctx.populate(for_file, builder);202		}203	}204205	fn as_any(&self) -> &dyn Any {206		self207	}208}209210macro_rules! impl_context_initializer {211	($($gen:ident)*) => {212		#[allow(non_snake_case)]213		impl<$($gen: ContextInitializer + Trace,)*> ContextInitializer for ($($gen,)*) {214			fn populate(&self, for_file: Source, builder: &mut InitialContextBuilder) {215				let ($($gen,)*) = self;216				$($gen.populate(for_file.clone(), builder);)*217			}218			fn as_any(&self) -> &dyn Any {219				self220			}221		}222	};223	($($cur:ident)* @ $c:ident $($rest:ident)*) => {224		impl_context_initializer!($($cur)*);225		impl_context_initializer!($($cur)* $c @ $($rest)*);226	};227	($($cur:ident)* @) => {228		impl_context_initializer!($($cur)*);229	}230}231impl_context_initializer! {232	A @ B C D E F G233}234235#[derive(Trace)]236struct FileData {237	string: Option<IStr>,238	bytes: Option<IBytes>,239	parsed: Option<Rc<Expr>>,240	evaluated: Option<Val>,241242	evaluating: bool,243}244impl FileData {245	fn new_string(data: IStr) -> Self {246		Self {247			string: Some(data),248			bytes: None,249			parsed: None,250			evaluated: None,251			evaluating: false,252		}253	}254	fn new_bytes(data: IBytes) -> Self {255		Self {256			string: None,257			bytes: Some(data),258			parsed: None,259			evaluated: None,260			evaluating: false,261		}262	}263	pub(crate) fn get_string(&mut self) -> Option<IStr> {264		if self.string.is_none() {265			self.string = Some(266				self.bytes267					.as_ref()268					.expect("either string or bytes should be set")269					.clone()270					.cast_str()?,271			);272		}273		Some(self.string.clone().expect("just set"))274	}275}276277#[derive(Trace)]278pub struct EvaluationStateInternals {279	/// Internal state280	file_cache: RefCell<FxHashMap<SourcePath, FileData>>,281	/// Context initializer, which will be used for imports and everything282	/// [`NoopContextInitializer`] is used by default, most likely you want to have `jrsonnet-stdlib`283	context_initializer: CcContextInitializer,284	/// Used to resolve file locations/contents285	import_resolver: Rc<dyn ImportResolver>,286}287288/// Maintains stack trace and import resolution289#[derive(Clone, Trace)]290pub struct State(Cc<EvaluationStateInternals>);291292thread_local! {293	pub static DEFAULT_STATE: State = State::builder().build();294	pub static STATE: RefCell<Option<State>> = const {RefCell::new(None)};295}296pub struct StateEnterGuard(PhantomData<()>);297impl Drop for StateEnterGuard {298	fn drop(&mut self) {299		STATE.with_borrow_mut(|v| *v = None);300	}301}302303pub fn with_state<V>(v: impl FnOnce(State) -> V) -> V {304	if let Some(state) = STATE.with_borrow(Clone::clone) {305		v(state)306	} else {307		let s = DEFAULT_STATE.with(Clone::clone);308		v(s)309	}310}311312impl State {313	pub fn enter(&self) -> StateEnterGuard {314		self.try_enter().expect("entered state already exists")315	}316	pub fn try_enter(&self) -> Option<StateEnterGuard> {317		STATE.with_borrow_mut(|v| {318			if v.is_none() {319				*v = Some(self.clone());320				Some(StateEnterGuard(PhantomData))321			} else {322				None323			}324		})325	}326	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise327	pub fn import_resolved_str(&self, path: SourcePath) -> Result<IStr> {328		let mut file_cache = self.file_cache();329		let mut file = file_cache.entry(path.clone());330331		let file = match file {332			Entry::Occupied(ref mut d) => d.get_mut(),333			Entry::Vacant(v) => {334				let data = self.import_resolver().load_file_contents(&path)?;335				v.insert(FileData::new_string(336					std::str::from_utf8(&data)337						.map_err(|_| ImportBadFileUtf8(path.clone()))?338						.into(),339				))340			}341		};342		Ok(file343			.get_string()344			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?)345	}346	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise347	pub fn import_resolved_bin(&self, path: SourcePath) -> Result<IBytes> {348		let mut file_cache = self.file_cache();349		let mut file = file_cache.entry(path.clone());350351		let file = match file {352			Entry::Occupied(ref mut d) => d.get_mut(),353			Entry::Vacant(v) => {354				let data = self.import_resolver().load_file_contents(&path)?;355				v.insert(FileData::new_bytes(data.as_slice().into()))356			}357		};358		if let Some(str) = &file.bytes {359			return Ok(str.clone());360		}361		if file.bytes.is_none() {362			file.bytes = Some(363				file.string364					.as_ref()365					.expect("either string or bytes should be set")366					.clone()367					.cast_bytes(),368			);369		}370		Ok(file.bytes.as_ref().expect("just set").clone())371	}372	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise373	pub fn import_resolved(&self, path: SourcePath) -> Result<Val> {374		let mut file_cache = self.file_cache();375		let mut file = file_cache.entry(path.clone());376377		let file = match file {378			Entry::Occupied(ref mut d) => d.get_mut(),379			Entry::Vacant(v) => {380				let data = self.import_resolver().load_file_contents(&path)?;381				v.insert(FileData::new_string(382					std::str::from_utf8(&data)383						.map_err(|_| ImportBadFileUtf8(path.clone()))?384						.into(),385				))386			}387		};388		if let Some(val) = &file.evaluated {389			return Ok(val.clone());390		}391		let code = file392			.get_string()393			.ok_or_else(|| ImportBadFileUtf8(path.clone()))?;394		let file_name = Source::new(path.clone(), code.clone());395		if file.parsed.is_none() {396			file.parsed = Some(397				parse_jsonnet(&code, file_name.clone())398					.map(Rc::new)399					.map_err(|e| {400						let span = e.location.clone();401						let mut err = Error::from(ImportSyntaxError {402							path: file_name.clone(),403							error: Box::new(e),404						});405						err.trace_mut().0.push(StackTraceElement {406							location: Some(span),407							desc: "parse imported".to_string(),408						});409						err410					})?,411			);412		}413		let parsed = file.parsed.as_ref().expect("just set").clone();414		if file.evaluating {415			bail!(InfiniteRecursionDetected)416		}417		file.evaluating = true;418		// Dropping file cache guard here, as evaluation may use this map too419		drop(file_cache);420		let (externals, thunks) = self.create_default_context(file_name).build();421		let report = analyze_root(&parsed, externals);422		if report.errored {423			return Err(StaticAnalysisError(report.diagnostics_list).into());424		}425		debug_assert_eq!(report.root_shape.n_locals as usize, thunks.len());426		debug_assert!(report.root_shape.captures.is_empty());427		let ctx = Context::root(thunks);428		let res = evaluate::evaluate(ctx, &report.lir);429430		let mut file_cache = self.file_cache();431		let mut file = file_cache.entry(path);432433		let Entry::Occupied(file) = &mut file else {434			unreachable!("this file was just here")435		};436		let file = file.get_mut();437		file.evaluating = false;438		match res {439			Ok(v) => {440				file.evaluated = Some(v.clone());441				Ok(v)442			}443			Err(e) => Err(e),444		}445	}446447	/// Has same semantics as `import 'path'` called from `from` file448	pub fn import_from(&self, from: &SourcePath, path: impl AsPathLike) -> Result<Val> {449		let resolved = self.resolve_from(from, &path)?;450		self.import_resolved(resolved)451	}452	pub fn import(&self, path: impl AsPathLike) -> Result<Val> {453		let resolved = self.resolve_from_default(&path)?;454		self.import_resolved(resolved)455	}456457	/// Creates context with all passed global variables458	pub fn create_default_context(&self, source: Source) -> InitialContextBuilder {459		self.create_default_context_with(source, &())460	}461462	/// Creates context with all passed global variables, calling custom modifier463	pub fn create_default_context_with(464		&self,465		source: Source,466		context_initializer: &dyn ContextInitializer,467	) -> InitialContextBuilder {468		let default_initializer = self.context_initializer();469		let mut builder = InitialContextBuilder::new();470		default_initializer.populate(source.clone(), &mut builder);471		context_initializer.populate(source, &mut builder);472473		builder474	}475}476477/// Internals478impl State {479	fn file_cache(&self) -> RefMut<'_, FxHashMap<SourcePath, FileData>> {480		self.0.file_cache.borrow_mut()481	}482}483/// Executes code creating a new stack frame, to be replaced with try{}484pub fn in_frame<T>(485	e: CallLocation<'_>,486	frame_desc: impl FnOnce() -> String,487	f: impl FnOnce() -> Result<T>,488) -> Result<T> {489	let _guard = check_depth()?;490491	f().with_description_src(e, frame_desc)492}493494/// Executes code creating a new stack frame, to be replaced with try{}495pub fn in_description_frame<T>(496	frame_desc: impl FnOnce() -> String,497	f: impl FnOnce() -> Result<T>,498) -> Result<T> {499	let _guard = check_depth()?;500501	f().with_description(frame_desc)502}503504#[derive(Trace)]505pub struct InitialUnderscore(pub Thunk<Val>);506impl ContextInitializer for InitialUnderscore {507	fn populate(&self, _for_file: Source, builder: &mut InitialContextBuilder) {508		builder.bind("_", self.0.clone());509	}510511	fn as_any(&self) -> &dyn Any {512		self513	}514}515516pub struct PreparedSnippet {517	lir: LExpr,518	thunks: Vec<Thunk<Val>>,519}520521/// Raw methods evaluate passed values but don't perform TLA execution522impl State {523	/// Parses and analyses the given snippet with a custom context524	/// modifier.525	pub fn prepare_snippet_with(526		&self,527		name: impl Into<IStr>,528		code: impl Into<IStr>,529		context_initializer: &dyn ContextInitializer,530	) -> Result<PreparedSnippet> {531		let code = code.into();532		let source = Source::new_virtual(name.into(), code.clone());533		let parsed = parse_jsonnet(&code, source.clone()).map_err(|e| ImportSyntaxError {534			path: source.clone(),535			error: Box::new(e),536		})?;537		let (externals, thunks) = self538			.create_default_context_with(source, context_initializer)539			.build();540		let report = analyze_root(&parsed, externals);541		if report.errored {542			return Err(StaticAnalysisError(report.diagnostics_list).into());543		}544		debug_assert_eq!(report.root_shape.n_locals as usize, thunks.len());545		debug_assert!(report.root_shape.captures.is_empty());546		Ok(PreparedSnippet {547			lir: report.lir,548			thunks,549		})550	}551	/// Parses and analyses the given snippet552	pub fn prepare_snippet(553		&self,554		name: impl Into<IStr>,555		code: impl Into<IStr>,556	) -> Result<PreparedSnippet> {557		self.prepare_snippet_with(name, code, &())558	}559	pub fn evaluate_prepared_snippet(&self, prepared: &PreparedSnippet) -> Result<Val> {560		let ctx = Context::root(prepared.thunks.clone());561		evaluate::evaluate(ctx, &prepared.lir)562	}563	/// Parses and evaluates the given snippet with custom context modifier564	pub fn evaluate_snippet_with(565		&self,566		name: impl Into<IStr>,567		code: impl Into<IStr>,568		context_initializer: &dyn ContextInitializer,569	) -> Result<Val> {570		let prepared = self.prepare_snippet_with(name, code, context_initializer)?;571		self.evaluate_prepared_snippet(&prepared)572	}573	/// Parses and evaluates the given snippet574	pub fn evaluate_snippet(&self, name: impl Into<IStr>, code: impl Into<IStr>) -> Result<Val> {575		self.evaluate_snippet_with(name, code, &())576	}577}578579/// Settings utilities580impl State {581	// Only panics in case of [`ImportResolver`] contract violation582	#[allow(clippy::missing_panics_doc)]583	pub fn resolve_from(&self, from: &SourcePath, path: &dyn AsPathLike) -> Result<SourcePath> {584		self.import_resolver().resolve_from(from, path)585	}586	#[allow(clippy::missing_panics_doc)]587	pub fn resolve_from_default(&self, path: &dyn AsPathLike) -> Result<SourcePath> {588		self.import_resolver().resolve_from_default(path)589	}590	pub fn import_resolver(&self) -> &dyn ImportResolver {591		&*self.0.import_resolver592	}593	pub fn context_initializer(&self) -> &dyn ContextInitializer {594		&*self.0.context_initializer.0595	}596}597598impl State {599	pub fn builder() -> StateBuilder {600		StateBuilder::default()601	}602}603604impl Default for State {605	fn default() -> Self {606		Self::builder().build()607	}608}609610#[derive(Default)]611pub struct StateBuilder {612	import_resolver: Option<Rc<dyn ImportResolver>>,613	context_initializer: Option<CcContextInitializer>,614}615impl StateBuilder {616	pub fn import_resolver(&mut self, import_resolver: impl ImportResolver) -> &mut Self {617		let _ = self.import_resolver.insert(Rc::new(import_resolver));618		self619	}620	pub fn context_initializer(621		&mut self,622		context_initializer: impl ContextInitializer + Trace,623	) -> &mut Self {624		let _ = self625			.context_initializer626			.insert(CcContextInitializer::new(context_initializer));627		self628	}629	pub fn build(mut self) -> State {630		State(Cc::new(EvaluationStateInternals {631			file_cache: RefCell::new(FxHashMap::new()),632			context_initializer: self633				.context_initializer634				.take()635				.unwrap_or_else(|| CcContextInitializer::new(())),636			import_resolver: self637				.import_resolver638				.take()639				.unwrap_or_else(|| Rc::new(DummyImportResolver)),640		}))641	}642}
modifiedcrates/jrsonnet-ir-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-ir-parser/Cargo.toml
+++ b/crates/jrsonnet-ir-parser/Cargo.toml
@@ -10,6 +10,8 @@
 version.workspace = true
 
 [features]
+default = []
+experimental = ["exp-null-coaelse", "exp-destruct"]
 exp-null-coaelse = ["jrsonnet-ir/exp-null-coaelse"]
 exp-destruct = ["jrsonnet-ir/exp-destruct"]
 
modifiedcrates/jrsonnet-ir/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-ir/Cargo.toml
+++ b/crates/jrsonnet-ir/Cargo.toml
@@ -12,6 +12,7 @@
 
 [features]
 default = []
+experimental = ["exp-destruct", "exp-null-coaelse"]
 exp-destruct = []
 exp-null-coaelse = []
 
modifiedcrates/jrsonnet-peg-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-peg-parser/Cargo.toml
+++ b/crates/jrsonnet-peg-parser/Cargo.toml
@@ -22,5 +22,6 @@
 
 [features]
 default = []
+experimental = ["exp-destruct", "exp-null-coaelse"]
 exp-destruct = ["jrsonnet-ir/exp-destruct"]
 exp-null-coaelse = ["jrsonnet-ir/exp-null-coaelse"]
modifiedcrates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -13,6 +13,12 @@
 workspace = true
 
 [features]
+experimental = [
+  "exp-preserve-order",
+  "exp-bigint",
+  "exp-null-coaelse",
+  "exp-regex",
+]
 # Add order preservation flag to some functions
 exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]
 # Bigint type
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -18,4 +18,5 @@
 peg.workspace = true
 
 [features]
+experimental = ["exp-bigint"]
 exp-bigint = []