git.delta.rocks / jrsonnet / refs/commits / 695a2f8d51fa

difftreelog

feat string interning

Yaroslav Bolyukin2021-01-06parent: #b55d14a.patch.diff
in: master

20 files changed

modifiedbindings/jsonnet/Cargo.tomldiffbeforeafterboth
--- a/bindings/jsonnet/Cargo.toml
+++ b/bindings/jsonnet/Cargo.toml
@@ -5,6 +5,7 @@
 edition = "2018"
 
 [dependencies]
+jrsonnet-interner = { path = "../../crates/jrsonnet-interner", version = "0.3.3" }
 jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.3.3" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.3.3" }
 
modifiedbindings/jsonnet/src/import.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -4,6 +4,7 @@
 	error::{Error::*, Result},
 	throw, EvaluationState, ImportResolver,
 };
+use jrsonnet_interner::IStr;
 use std::{
 	any::Any,
 	cell::RefCell,
@@ -30,7 +31,7 @@
 	cb: JsonnetImportCallback,
 	ctx: *mut c_void,
 
-	out: RefCell<HashMap<PathBuf, Rc<str>>>,
+	out: RefCell<HashMap<PathBuf, IStr>>,
 }
 impl ImportResolver for CallbackImportResolver {
 	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
@@ -75,7 +76,7 @@
 
 		Ok(Rc::new(found_here_buf))
 	}
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<Rc<str>> {
+	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr> {
 		Ok(self.out.borrow().get(resolved).unwrap().clone())
 	}
 	unsafe fn as_any(&self) -> &dyn Any {
@@ -124,7 +125,7 @@
 			throw!(ImportFileNotFound(from.clone(), path.clone()))
 		}
 	}
-	fn load_file_contents(&self, id: &PathBuf) -> Result<Rc<str>> {
+	fn load_file_contents(&self, id: &PathBuf) -> Result<IStr> {
 		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
 		let mut out = String::new();
 		file.read_to_string(&mut out)
modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -8,6 +8,7 @@
 
 use import::NativeImportResolver;
 use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Val};
+use jrsonnet_interner::IStr;
 use std::{
 	alloc::Layout,
 	ffi::{CStr, CString},
@@ -161,7 +162,7 @@
 	})
 }
 
-fn multi_to_raw(multi: Vec<(Rc<str>, Rc<str>)>) -> *const c_char {
+fn multi_to_raw(multi: Vec<(IStr, IStr)>) -> *const c_char {
 	let mut out = Vec::new();
 	for (i, (k, v)) in multi.iter().enumerate() {
 		if i != 0 {
@@ -237,7 +238,7 @@
 	})
 }
 
-fn stream_to_raw(multi: Vec<Rc<str>>) -> *const c_char {
+fn stream_to_raw(multi: Vec<IStr>) -> *const c_char {
 	let mut out = Vec::new();
 	for (i, v) in multi.iter().enumerate() {
 		if i != 0 {
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -12,8 +12,6 @@
 serialized-stdlib = ["serde", "bincode", "jrsonnet-parser/deserialize"]
 # Allow to convert Val into serde_json::Value and backwards
 serde-json = ["serde", "serde_json"]
-# Same as above, but with generated code instead of serde. Reduces memory usage, but increases binary size and compilation time
-codegenerated-stdlib = []
 # Replace some standard library functions with faster implementations (I.e manifestJsonEx)
 # Library works fine without this feature, but requires more memory and time for std function calls
 faster = []
@@ -24,6 +22,7 @@
 unstable = []
 
 [dependencies]
+jrsonnet-interner = { path = "../jrsonnet-interner" }
 jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.3.3" }
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.3" }
 jrsonnet-types = { path = "../jrsonnet-types", version = "0.3.3" }
@@ -58,8 +57,7 @@
 optional = true
 
 [build-dependencies]
-jrsonnet-parser = { path = "../jrsonnet-parser", features = ["dump", "serialize", "deserialize"], version = "0.3.3" }
+jrsonnet-parser = { path = "../jrsonnet-parser", features = ["serialize", "deserialize"], version = "0.3.3" }
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.3" }
-structdump = "0.1.2"
 serde = "1.0"
 bincode = "1.3.1"
modifiedcrates/jrsonnet-evaluator/build.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/build.rs
+++ b/crates/jrsonnet-evaluator/build.rs
@@ -10,7 +10,6 @@
 	path::{Path, PathBuf},
 	rc::Rc,
 };
-use structdump::CodegenResult;
 
 fn main() {
 	let parsed = parse(
@@ -36,11 +35,11 @@
 									name: FieldName::Fixed(name),
 									..
 								})
-								if **name == *"join" || **name == *"manifestJsonEx" ||
-								**name == *"escapeStringJson" || **name == *"equals" ||
-								**name == *"base64" || **name == *"foldl" || **name == *"foldr" ||
-								**name == *"sortImpl" || **name == *"format" || **name == *"range" ||
-								**name == *"reverse" || **name == *"slice" || **name == *"mod"
+								if name == "join" || name == "manifestJsonEx" ||
+								name == "escapeStringJson" || name == "equals" ||
+								name == "base64" || name == "foldl" || name == "foldr" ||
+								name == "sortImpl" || name == "format" || name == "range" ||
+								name == "reverse" || name == "slice" || name == "mod"
 							)
 						})
 						.collect(),
@@ -52,15 +51,6 @@
 	} else {
 		parsed
 	};
-	{
-		let mut codegen = CodegenResult::default();
-		let code = codegen.codegen(&parsed);
-
-		let out_dir = env::var("OUT_DIR").unwrap();
-		let dest_path = Path::new(&out_dir).join("stdlib.rs");
-		let mut f = File::create(&dest_path).unwrap();
-		f.write_all(&code.as_bytes()).unwrap();
-	}
 	{
 		let out_dir = env::var("OUT_DIR").unwrap();
 		let dest_path = Path::new(&out_dir).join("stdlib.bincode");
modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/builtin/format.rs
1//! faster std.format impl2#![allow(clippy::too_many_arguments)]34use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};5use jrsonnet_types::ValType;6use thiserror::Error;78#[derive(Debug, Clone, Error)]9pub enum FormatError {10	#[error("truncated format code")]11	TruncatedFormatCode,12	#[error("unrecognized conversion type: {0}")]13	UnrecognizedConversionType(char),1415	#[error("not enough values")]16	NotEnoughValues,1718	#[error("cannot use * width with object")]19	CannotUseStarWidthWithObject,20	#[error("mapping keys required")]21	MappingKeysRequired,22	#[error("no such format field: {0}")]23	NoSuchFormatField(Rc<str>),24}2526impl From<FormatError> for LocError {27	fn from(e: FormatError) -> Self {28		Self::new(Format(e))29	}30}3132use std::rc::Rc;33use FormatError::*;3435type ParseResult<'t, T> = std::result::Result<(T, &'t str), FormatError>;3637pub fn try_parse_mapping_key(str: &str) -> ParseResult<&str> {38	if str.is_empty() {39		return Err(TruncatedFormatCode);40	}41	let bytes = str.as_bytes();42	if bytes[0] == b'(' {43		let mut i = 1;44		while i < bytes.len() {45			if bytes[i] == b')' {46				return Ok((&str[1..i as usize], &str[i as usize + 1..]));47			}48			i += 1;49		}50		Err(TruncatedFormatCode)51	} else {52		Ok(("", str))53	}54}5556#[cfg(test)]57pub mod tests_key {58	use super::*;5960	#[test]61	fn parse_key() {62		assert_eq!(63			try_parse_mapping_key("(hello ) world").unwrap(),64			("hello ", " world")65		);66		assert_eq!(try_parse_mapping_key("() world").unwrap(), ("", " world"));67		assert_eq!(try_parse_mapping_key(" world").unwrap(), ("", " world"));68		assert_eq!(69			try_parse_mapping_key(" () world").unwrap(),70			("", " () world")71		);72	}7374	#[test]75	#[should_panic]76	fn parse_key_missing_start() {77		try_parse_mapping_key("").unwrap();78	}7980	#[test]81	#[should_panic]82	fn parse_key_missing_end() {83		try_parse_mapping_key("(   ").unwrap();84	}85}8687#[derive(Default, Debug)]88pub struct CFlags {89	pub alt: bool,90	pub zero: bool,91	pub left: bool,92	pub blank: bool,93	pub sign: bool,94}9596pub fn try_parse_cflags(str: &str) -> ParseResult<CFlags> {97	if str.is_empty() {98		return Err(TruncatedFormatCode);99	}100	let bytes = str.as_bytes();101	let mut i = 0;102	let mut out = CFlags::default();103	loop {104		if bytes.len() == i {105			return Err(TruncatedFormatCode);106		}107		match bytes[i] {108			b'#' => out.alt = true,109			b'0' => out.zero = true,110			b'-' => out.left = true,111			b' ' => out.blank = true,112			b'+' => out.sign = true,113			_ => break,114		}115		i += 1;116	}117	Ok((out, &str[i..]))118}119120#[derive(Debug, PartialEq)]121pub enum Width {122	Star,123	Fixed(usize),124}125pub fn try_parse_field_width(str: &str) -> ParseResult<Width> {126	if str.is_empty() {127		return Err(TruncatedFormatCode);128	}129	let bytes = str.as_bytes();130	if bytes[0] == b'*' {131		return Ok((Width::Star, &str[1..]));132	}133	let mut out: usize = 0;134	let mut digits = 0;135	while let Some(digit) = (bytes[digits] as char).to_digit(10) {136		out *= 10;137		out += digit as usize;138		digits += 1;139		if digits == bytes.len() {140			return Err(TruncatedFormatCode);141		}142	}143	Ok((Width::Fixed(out), &str[digits..]))144}145146pub fn try_parse_precision(str: &str) -> ParseResult<Option<Width>> {147	if str.is_empty() {148		return Err(TruncatedFormatCode);149	}150	let bytes = str.as_bytes();151	if bytes[0] == b'.' {152		try_parse_field_width(&str[1..]).map(|(r, s)| (Some(r), s))153	} else {154		Ok((None, str))155	}156}157158// Only skips159pub fn try_parse_length_modifier(str: &str) -> ParseResult<()> {160	if str.is_empty() {161		return Err(TruncatedFormatCode);162	}163	let bytes = str.as_bytes();164	let mut idx = 0;165	while bytes[idx] == b'h' || bytes[idx] == b'l' || bytes[idx] == b'L' {166		idx += 1;167		if bytes.len() == idx {168			return Err(TruncatedFormatCode);169		}170	}171	Ok(((), &str[idx..]))172}173174#[derive(Debug, PartialEq)]175pub enum ConvTypeV {176	Decimal,177	Octal,178	Hexadecimal,179	Scientific,180	Float,181	Shorter,182	Char,183	String,184	Percent,185}186pub struct ConvType {187	v: ConvTypeV,188	caps: bool,189}190191pub fn parse_conversion_type(str: &str) -> ParseResult<ConvType> {192	if str.is_empty() {193		return Err(TruncatedFormatCode);194	}195196	let code = str.as_bytes()[0];197	let v: (ConvTypeV, bool) = match code {198		b'd' | b'i' | b'u' => (ConvTypeV::Decimal, false),199		b'o' => (ConvTypeV::Octal, false),200		b'x' => (ConvTypeV::Hexadecimal, false),201		b'X' => (ConvTypeV::Hexadecimal, true),202		b'e' => (ConvTypeV::Scientific, false),203		b'E' => (ConvTypeV::Scientific, true),204		b'f' => (ConvTypeV::Float, false),205		b'F' => (ConvTypeV::Float, true),206		b'g' => (ConvTypeV::Shorter, false),207		b'G' => (ConvTypeV::Shorter, true),208		b'c' => (ConvTypeV::Char, false),209		b's' => (ConvTypeV::String, false),210		b'%' => (ConvTypeV::Percent, false),211		c => return Err(UnrecognizedConversionType(c as char)),212	};213214	Ok((ConvType { v: v.0, caps: v.1 }, &str[1..]))215}216217#[derive(Debug)]218pub struct Code<'s> {219	mkey: &'s str,220	cflags: CFlags,221	width: Width,222	precision: Option<Width>,223	convtype: ConvTypeV,224	caps: bool,225}226pub fn parse_code(str: &str) -> ParseResult<Code> {227	if str.is_empty() {228		return Err(TruncatedFormatCode);229	}230	let (mkey, str) = try_parse_mapping_key(str)?;231	let (cflags, str) = try_parse_cflags(str)?;232	let (width, str) = try_parse_field_width(str)?;233	let (precision, str) = try_parse_precision(str)?;234	let (_, str) = try_parse_length_modifier(str)?;235	let (convtype, str) = parse_conversion_type(str)?;236237	Ok((238		Code {239			mkey,240			cflags,241			width,242			precision,243			convtype: convtype.v,244			caps: convtype.caps,245		},246		str,247	))248}249250#[derive(Debug)]251pub enum Element<'s> {252	String(&'s str),253	Code(Code<'s>),254}255pub fn parse_codes(mut str: &str) -> Result<Vec<Element>> {256	let mut bytes = str.as_bytes();257	let mut out = vec![];258	let mut offset = 0;259260	loop {261		while offset != bytes.len() && bytes[offset] != b'%' {262			offset += 1;263		}264		if offset != 0 {265			out.push(Element::String(&str[0..offset]));266		}267		if offset == bytes.len() {268			return Ok(out);269		}270		str = &str[offset + 1..];271		let (code, nstr) = parse_code(str)?;272		str = nstr;273		bytes = str.as_bytes();274		offset = 0;275276		out.push(Element::Code(code))277	}278}279280const NUMBERS: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";281282#[inline]283pub fn render_integer(284	out: &mut String,285	iv: i64,286	padding: usize,287	precision: usize,288	blank: bool,289	sign: bool,290	radix: i64,291	prefix: &str,292	caps: bool,293) {294	// Digit char indexes in reverse order, i.e295	// for radix = 16 and n = 12f: [15, 2, 1]296	let digits = if iv == 0 {297		vec![0u8]298	} else {299		let mut v = iv.abs();300		let mut nums = Vec::with_capacity(1);301		while v > 0 {302			nums.push((v % radix) as u8);303			v /= radix;304		}305		nums306	};307	let neg = iv < 0;308	let zp = padding.saturating_sub(if neg || blank || sign { 1 } else { 0 });309	let zp2 = zp310		.max(precision)311		.saturating_sub(prefix.len() + digits.len());312313	if neg {314		out.push('-')315	} else if sign {316		out.push('+');317	} else if blank {318		out.push(' ');319	}320321	out.reserve(zp2);322	for _ in 0..zp2 {323		out.push('0');324	}325	out.push_str(prefix);326327	for digit in digits.into_iter().rev() {328		let ch = NUMBERS[digit as usize] as char;329		out.push(if caps { ch.to_ascii_uppercase() } else { ch });330	}331}332333pub fn render_decimal(334	out: &mut String,335	iv: i64,336	padding: usize,337	precision: usize,338	blank: bool,339	sign: bool,340) {341	render_integer(out, iv, padding, precision, blank, sign, 10, "", false)342}343pub fn render_octal(344	out: &mut String,345	iv: i64,346	padding: usize,347	precision: usize,348	alt: bool,349	blank: bool,350	sign: bool,351) {352	render_integer(353		out,354		iv,355		padding,356		precision,357		blank,358		sign,359		8,360		if alt && iv != 0 { "0" } else { "" },361		false,362	)363}364pub fn render_hexadecimal(365	out: &mut String,366	iv: i64,367	padding: usize,368	precision: usize,369	alt: bool,370	blank: bool,371	sign: bool,372	caps: bool,373) {374	render_integer(375		out,376		iv,377		padding,378		precision,379		blank,380		sign,381		16,382		match (alt, caps) {383			(true, true) => "0X",384			(true, false) => "0x",385			(false, _) => "",386		},387		caps,388	)389}390391pub fn render_float(392	out: &mut String,393	n: f64,394	mut padding: usize,395	precision: usize,396	blank: bool,397	sign: bool,398	ensure_pt: bool,399	trailing: bool,400) {401	let dot_size = if precision == 0 && !ensure_pt { 0 } else { 1 };402	padding = padding.saturating_sub(dot_size + precision);403	render_decimal(out, n.floor() as i64, padding, 0, blank, sign);404	if precision == 0 {405		if ensure_pt {406			out.push('.');407		}408		return;409	}410	let frac = n411		.fract()412		.mul_add(10.0_f64.powf(precision as f64), 0.5)413		.floor();414	if trailing || frac > 0.0 {415		out.push('.');416		let mut frac_str = String::new();417		render_decimal(&mut frac_str, frac as i64, precision, 0, false, false);418		let mut trim = frac_str.len();419		if !trailing {420			for b in frac_str.as_bytes().iter().rev() {421				if *b == b'0' {422					trim -= 1;423				}424			}425		}426		out.push_str(&frac_str[..trim]);427	} else if ensure_pt {428		out.push('.');429	}430}431432pub fn render_float_sci(433	out: &mut String,434	n: f64,435	mut padding: usize,436	precision: usize,437	blank: bool,438	sign: bool,439	ensure_pt: bool,440	trailing: bool,441	caps: bool,442) {443	let exponent = n.log10().floor();444	let mantissa = if exponent as i16 == -324 {445		n * 10.0 / 10.0_f64.powf(exponent + 1.0)446	} else {447		n / 10.0_f64.powf(exponent)448	};449	let mut exponent_str = String::new();450	render_decimal(&mut exponent_str, exponent as i64, 3, 0, false, true);451452	// +1 for e453	padding = padding.saturating_sub(exponent_str.len() + 1);454455	render_float(456		out, mantissa, padding, precision, blank, sign, ensure_pt, trailing,457	);458	out.push(if caps { 'E' } else { 'e' });459	out.push_str(&exponent_str);460}461462pub fn format_code(463	out: &mut String,464	value: &Val,465	code: &Code,466	width: usize,467	precision: Option<usize>,468) -> Result<()> {469	let clfags = &code.cflags;470	let (fpprec, iprec) = match precision {471		Some(v) => (v, v),472		None => (6, 0),473	};474	let padding = if clfags.zero && !clfags.left {475		width476	} else {477		0478	};479480	// TODO: If left padded, can optimize by writing directly to out481	let mut tmp_out = String::new();482483	match code.convtype {484		ConvTypeV::String => tmp_out.push_str(&value.clone().to_string()?),485		ConvTypeV::Decimal => {486			let value = value.clone().try_cast_num("%d/%u/%i requires number")?;487			render_decimal(488				&mut tmp_out,489				value as i64,490				padding,491				iprec,492				clfags.blank,493				clfags.sign,494			);495		}496		ConvTypeV::Octal => {497			let value = value.clone().try_cast_num("%o requires number")?;498			render_octal(499				&mut tmp_out,500				value as i64,501				padding,502				iprec,503				clfags.alt,504				clfags.blank,505				clfags.sign,506			);507		}508		ConvTypeV::Hexadecimal => {509			let value = value.clone().try_cast_num("%x/%X requires number")?;510			render_hexadecimal(511				&mut tmp_out,512				value as i64,513				padding,514				iprec,515				clfags.alt,516				clfags.blank,517				clfags.sign,518				code.caps,519			);520		}521		ConvTypeV::Scientific => {522			let value = value.clone().try_cast_num("%e/%E requires number")?;523			render_float_sci(524				&mut tmp_out,525				value,526				padding,527				fpprec,528				clfags.blank,529				clfags.sign,530				clfags.alt,531				true,532				code.caps,533			);534		}535		ConvTypeV::Float => {536			let value = value.clone().try_cast_num("%e/%E requires number")?;537			render_float(538				&mut tmp_out,539				value,540				padding,541				fpprec,542				clfags.blank,543				clfags.sign,544				clfags.alt,545				true,546			);547		}548		ConvTypeV::Shorter => {549			let value = value.clone().try_cast_num("%g/%G requires number")?;550			let exponent = value.log10().floor();551			if exponent < -4.0 || exponent >= fpprec as f64 {552				render_float_sci(553					&mut tmp_out,554					value,555					padding,556					fpprec - 1,557					clfags.blank,558					clfags.sign,559					clfags.alt,560					clfags.alt,561					code.caps,562				);563			} else {564				let digits_before_pt = 1.max(exponent as usize + 1);565				render_float(566					&mut tmp_out,567					value,568					padding,569					fpprec - digits_before_pt,570					clfags.blank,571					clfags.sign,572					clfags.alt,573					clfags.alt,574				);575			}576		}577		ConvTypeV::Char => match value.clone() {578			Val::Num(n) => tmp_out.push(579				std::char::from_u32(n as u32)580					.ok_or_else(|| InvalidUnicodeCodepointGot(n as u32))?,581			),582			Val::Str(s) => {583				if s.chars().count() != 1 {584					throw!(RuntimeError(585						format!("%c expected 1 char string, got {}", s.chars().count()).into(),586					));587				}588				tmp_out.push_str(&s);589			}590			_ => {591				throw!(TypeMismatch(592					"%c requires number/string",593					vec![ValType::Num, ValType::Str],594					value.value_type(),595				));596			}597		},598		ConvTypeV::Percent => tmp_out.push('%'),599	};600601	let padding = width.saturating_sub(tmp_out.len());602603	if !clfags.left {604		for _ in 0..padding {605			out.push(' ');606		}607	}608	out.push_str(&tmp_out);609	if clfags.left {610		for _ in 0..padding {611			out.push(' ');612		}613	}614615	Ok(())616}617618pub fn format_arr(str: &str, mut values: &[Val]) -> Result<String> {619	let codes = parse_codes(str)?;620	let mut out = String::new();621622	for code in codes {623		match code {624			Element::String(s) => {625				out.push_str(s);626			}627			Element::Code(c) => {628				let width = match c.width {629					Width::Star => {630						if values.is_empty() {631							throw!(NotEnoughValues);632						}633						let value = &values[0];634						values = &values[1..];635						value.clone().try_cast_num("field width")? as usize636					}637					Width::Fixed(n) => n,638				};639				let precision = match c.precision {640					Some(Width::Star) => {641						if values.is_empty() {642							throw!(NotEnoughValues);643						}644						let value = &values[0];645						values = &values[1..];646						Some(value.clone().try_cast_num("field precision")? as usize)647					}648					Some(Width::Fixed(n)) => Some(n),649					None => None,650				};651652				// %% should not consume a value653				let value = if c.convtype == ConvTypeV::Percent {654					&Val::Null655				} else {656					if values.is_empty() {657						throw!(NotEnoughValues);658					}659					let value = &values[0];660					values = &values[1..];661					value662				};663664				format_code(&mut out, value, &c, width, precision)?;665			}666		}667	}668669	Ok(out)670}671672pub fn format_obj(str: &str, values: &ObjValue) -> Result<String> {673	let codes = parse_codes(str)?;674	let mut out = String::new();675676	for code in codes {677		match code {678			Element::String(s) => {679				out.push_str(s);680			}681			Element::Code(c) => {682				// TODO: Operate on ref683				let f: Rc<str> = c.mkey.into();684				let width = match c.width {685					Width::Star => {686						throw!(CannotUseStarWidthWithObject);687					}688					Width::Fixed(n) => n,689				};690				let precision = match c.precision {691					Some(Width::Star) => {692						throw!(CannotUseStarWidthWithObject);693					}694					Some(Width::Fixed(n)) => Some(n),695					None => None,696				};697698				let value = if c.convtype == ConvTypeV::Percent {699					Val::Null700				} else {701					if f.is_empty() {702						throw!(MappingKeysRequired);703					}704					if let Some(v) = values.get(f.clone())? {705						v706					} else {707						throw!(NoSuchFormatField(f));708					}709				};710711				format_code(&mut out, &value, &c, width, precision)?;712			}713		}714	}715716	Ok(out)717}718719#[cfg(test)]720pub mod test_format {721	use super::*;722723	#[test]724	fn parse() {725		assert_eq!(726			parse_codes(727				"How much error budget is left looking at our %.3f%% availability gurantees?"728			)729			.unwrap()730			.len(),731			4732		);733	}734735	#[test]736	fn octals() {737		assert_eq!(format_arr("%#o", &[Val::Num(8.0)]).unwrap(), "010");738		assert_eq!(format_arr("%#4o", &[Val::Num(8.0)]).unwrap(), " 010");739		assert_eq!(format_arr("%4o", &[Val::Num(8.0)]).unwrap(), "  10");740		assert_eq!(format_arr("%04o", &[Val::Num(8.0)]).unwrap(), "0010");741		assert_eq!(format_arr("%+4o", &[Val::Num(8.0)]).unwrap(), " +10");742		assert_eq!(format_arr("%+04o", &[Val::Num(8.0)]).unwrap(), "+010");743		assert_eq!(format_arr("%-4o", &[Val::Num(8.0)]).unwrap(), "10  ");744		assert_eq!(format_arr("%+-4o", &[Val::Num(8.0)]).unwrap(), "+10 ");745		assert_eq!(format_arr("%+-04o", &[Val::Num(8.0)]).unwrap(), "+10 ");746	}747748	#[test]749	fn percent_doesnt_consumes_values() {750		assert_eq!(751			format_arr(752				"How much error budget is left looking at our %.3f%% availability gurantees?",753				&[Val::Num(4.0)]754			)755			.unwrap(),756			"How much error budget is left looking at our 4.000% availability gurantees?"757		);758	}759}
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -6,6 +6,7 @@
 	with_state, ArrValue, Context, FuncVal, LazyVal, Val,
 };
 use format::{format_arr, format_obj};
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};
 use jrsonnet_types::ty;
 use std::{collections::HashMap, path::PathBuf, rc::Rc};
@@ -19,7 +20,7 @@
 pub mod manifest;
 pub mod sort;
 
-fn std_format(str: Rc<str>, vals: Val) -> Result<Val> {
+fn std_format(str: IStr, vals: Val) -> Result<Val> {
 	push(
 		&Some(ExprLocation(Rc::from(PathBuf::from("std.jsonnet")), 0, 0)),
 		|| format!("std.format of {}", str),
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -2,6 +2,7 @@
 	error::Error::*, future_wrapper, map::LayeredHashMap, rc_fn_helper, resolved_lazy_val,
 	LazyBinding, LazyVal, ObjValue, Result, Val,
 };
+use jrsonnet_interner::IStr;
 use rustc_hash::FxHashMap;
 use std::hash::BuildHasherDefault;
 use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
@@ -18,7 +19,7 @@
 	dollar: Option<ObjValue>,
 	this: Option<ObjValue>,
 	super_obj: Option<ObjValue>,
-	bindings: LayeredHashMap<Rc<str>, LazyVal>,
+	bindings: LayeredHashMap<IStr, LazyVal>,
 }
 impl Debug for ContextInternals {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -57,7 +58,7 @@
 		}))
 	}
 
-	pub fn binding(&self, name: Rc<str>) -> Result<LazyVal> {
+	pub fn binding(&self, name: IStr) -> Result<LazyVal> {
 		Ok(self
 			.0
 			.bindings
@@ -72,7 +73,7 @@
 		ctx.unwrap()
 	}
 
-	pub fn with_var(self, name: Rc<str>, value: Val) -> Self {
+	pub fn with_var(self, name: IStr, value: Val) -> Self {
 		let mut new_bindings =
 			FxHashMap::with_capacity_and_hasher(1, BuildHasherDefault::default());
 		new_bindings.insert(name, resolved_lazy_val!(value));
@@ -81,7 +82,7 @@
 
 	pub fn extend(
 		self,
-		new_bindings: FxHashMap<Rc<str>, LazyVal>,
+		new_bindings: FxHashMap<IStr, LazyVal>,
 		new_dollar: Option<ObjValue>,
 		new_this: Option<ObjValue>,
 		new_super_obj: Option<ObjValue>,
@@ -123,7 +124,7 @@
 	}
 	pub fn extend_unbound(
 		self,
-		new_bindings: HashMap<Rc<str>, LazyBinding>,
+		new_bindings: HashMap<IStr, LazyBinding>,
 		new_dollar: Option<ObjValue>,
 		new_this: Option<ObjValue>,
 		new_super_obj: Option<ObjValue>,
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -2,6 +2,7 @@
 	builtin::{format::FormatError, sort::SortError},
 	typed::TypeLocError,
 };
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
 use jrsonnet_types::ValType;
 use std::{path::PathBuf, rc::Rc};
@@ -10,7 +11,7 @@
 #[derive(Error, Debug, Clone)]
 pub enum Error {
 	#[error("intrinsic not found: {0}")]
-	IntrinsicNotFound(Rc<str>),
+	IntrinsicNotFound(IStr),
 	#[error("argument reordering in intrisics not supported yet")]
 	IntrinsicArgumentReorderingIsNotSupportedYet,
 
@@ -33,36 +34,36 @@
 	ArrayBoundsError(usize, usize),
 
 	#[error("assert failed: {0}")]
-	AssertionFailed(Rc<str>),
+	AssertionFailed(IStr),
 
 	#[error("variable is not defined: {0}")]
-	VariableIsNotDefined(Rc<str>),
+	VariableIsNotDefined(IStr),
 	#[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]
 	TypeMismatch(&'static str, Vec<ValType>, ValType),
 	#[error("no such field: {0}")]
-	NoSuchField(Rc<str>),
+	NoSuchField(IStr),
 
 	#[error("only functions can be called, got {0}")]
 	OnlyFunctionsCanBeCalledGot(ValType),
 	#[error("parameter {0} is not defined")]
 	UnknownFunctionParameter(String),
 	#[error("argument {0} is already bound")]
-	BindingParameterASecondTime(Rc<str>),
+	BindingParameterASecondTime(IStr),
 	#[error("too many args, function has {0}")]
 	TooManyArgsFunctionHas(usize),
 	#[error("founction argument is not passed: {0}")]
-	FunctionParameterNotBoundInCall(Rc<str>),
+	FunctionParameterNotBoundInCall(IStr),
 
 	#[error("external variable is not defined: {0}")]
-	UndefinedExternalVariable(Rc<str>),
+	UndefinedExternalVariable(IStr),
 	#[error("native is not defined: {0}")]
-	UndefinedExternalFunction(Rc<str>),
+	UndefinedExternalFunction(IStr),
 
 	#[error("field name should be string, got {0}")]
 	FieldMustBeStringGot(ValType),
 
 	#[error("attempted to index array with string {0}")]
-	AttemptedIndexAnArrayWithString(Rc<str>),
+	AttemptedIndexAnArrayWithString(IStr),
 	#[error("{0} index type should be {1}, got {2}")]
 	ValueIndexMustBeTypeGot(ValType, ValType, ValType),
 	#[error("cant index into {0}")]
@@ -86,12 +87,12 @@
 	)]
 	ImportSyntaxError {
 		path: Rc<PathBuf>,
-		source_code: Rc<str>,
+		source_code: IStr,
 		error: Box<jrsonnet_parser::ParseError>,
 	},
 
 	#[error("runtime error: {0}")]
-	RuntimeError(Rc<str>),
+	RuntimeError(IStr),
 	#[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]
 	StackOverflow,
 	#[error("tried to index by fractional value")]
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -3,6 +3,7 @@
 	ContextCreator, FuncDesc, FuncVal, LazyBinding, LazyVal, ObjMember, ObjValue, Result, Val,
 };
 use closure::closure;
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{
 	ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, ExprLocation, FieldMember,
 	ForSpecData, IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc, UnaryOpType,
@@ -12,7 +13,7 @@
 use rustc_hash::FxHashMap;
 use std::{collections::HashMap, rc::Rc};
 
-pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (Rc<str>, LazyBinding) {
+pub fn evaluate_binding(b: &BindSpec, context_creator: ContextCreator) -> (IStr, LazyBinding) {
 	let b = b.clone();
 	if let Some(params) = &b.params {
 		let params = params.clone();
@@ -45,7 +46,7 @@
 	}
 }
 
-pub fn evaluate_method(ctx: Context, name: Rc<str>, params: ParamsDesc, body: LocExpr) -> Val {
+pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {
 	Val::Func(Rc::new(FuncVal::Normal(FuncDesc {
 		name,
 		ctx,
@@ -57,7 +58,7 @@
 pub fn evaluate_field_name(
 	context: Context,
 	field_name: &jrsonnet_parser::FieldName,
-) -> Result<Option<Rc<str>>> {
+) -> Result<Option<IStr>> {
 	Ok(match field_name {
 		jrsonnet_parser::FieldName::Fixed(n) => Some(n.clone()),
 		jrsonnet_parser::FieldName::Dyn(expr) => {
@@ -182,7 +183,7 @@
 	})
 }
 
-future_wrapper!(HashMap<Rc<str>, LazyBinding>, FutureNewBindings);
+future_wrapper!(HashMap<IStr, LazyBinding>, FutureNewBindings);
 future_wrapper!(ObjValue, FutureObjValue);
 
 pub fn evaluate_comp<T>(
@@ -230,7 +231,7 @@
 		})
 	);
 	{
-		let mut bindings: HashMap<Rc<str>, LazyBinding> = HashMap::new();
+		let mut bindings: HashMap<IStr, LazyBinding> = HashMap::new();
 		for (n, b) in members
 			.iter()
 			.filter_map(|m| match m {
@@ -334,7 +335,7 @@
 							)?)
 						})
 					);
-					let mut bindings: HashMap<Rc<str>, LazyBinding> = HashMap::new();
+					let mut bindings: HashMap<IStr, LazyBinding> = HashMap::new();
 					for (n, b) in obj
 						.pre_locals
 						.iter()
@@ -401,7 +402,7 @@
 	})
 }
 
-pub fn evaluate_named(context: Context, lexpr: &LocExpr, name: Rc<str>) -> Result<Val> {
+pub fn evaluate_named(context: Context, lexpr: &LocExpr, name: IStr) -> Result<Val> {
 	use Expr::*;
 	let LocExpr(expr, _loc) = lexpr;
 	Ok(match &**expr {
@@ -498,7 +499,7 @@
 			}
 		}
 		LocalExpr(bindings, returned) => {
-			let mut new_bindings: HashMap<Rc<str>, LazyBinding> = HashMap::new();
+			let mut new_bindings: HashMap<IStr, LazyBinding> = HashMap::new();
 			let future_context = Context::new_future();
 
 			let context_creator = context_creator!(
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -1,8 +1,9 @@
 use crate::{error::Error::*, evaluate, lazy_val, resolved_lazy_val, throw, Context, Result, Val};
 use closure::closure;
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ArgsDesc, ParamsDesc};
 use rustc_hash::FxHashMap;
-use std::{collections::HashMap, hash::BuildHasherDefault, rc::Rc};
+use std::{collections::HashMap, hash::BuildHasherDefault};
 
 const NO_DEFAULT_CONTEXT: &str =
 	"no default context set for call with defined default parameter value";
@@ -66,7 +67,7 @@
 	ctx: Context,
 	body_ctx: Option<Context>,
 	params: &ParamsDesc,
-	args: &HashMap<Rc<str>, Val>,
+	args: &HashMap<IStr, Val>,
 	tailstrict: bool,
 ) -> Result<Context> {
 	let mut out = FxHashMap::with_capacity_and_hasher(params.len(), BuildHasherDefault::default());
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -3,6 +3,7 @@
 	throw,
 };
 use fs::File;
+use jrsonnet_interner::IStr;
 use std::fs;
 use std::io::Read;
 use std::{any::Any, cell::RefCell, collections::HashMap, path::PathBuf, rc::Rc};
@@ -15,7 +16,7 @@
 	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>>;
 
 	/// Reads file from filesystem, should be used only with path received from `resolve_file`
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<Rc<str>>;
+	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr>;
 
 	/// # Safety
 	///
@@ -32,7 +33,7 @@
 		throw!(ImportNotSupported(from.clone(), path.clone()))
 	}
 
-	fn load_file_contents(&self, _resolved: &PathBuf) -> Result<Rc<str>> {
+	fn load_file_contents(&self, _resolved: &PathBuf) -> Result<IStr> {
 		// Can be only caused by library direct consumer, not by supplied jsonnet
 		panic!("dummy resolver can't load any file")
 	}
@@ -72,7 +73,7 @@
 			throw!(ImportFileNotFound(from.clone(), path.clone()))
 		}
 	}
-	fn load_file_contents(&self, id: &PathBuf) -> Result<Rc<str>> {
+	fn load_file_contents(&self, id: &PathBuf) -> Result<IStr> {
 		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
 		let mut out = String::new();
 		file.read_to_string(&mut out)
@@ -89,7 +90,7 @@
 /// Caches results of the underlying resolver
 pub struct CachingImportResolver {
 	resolution_cache: RefCell<HashMap<ResolutionData, Result<Rc<PathBuf>>>>,
-	loading_cache: RefCell<HashMap<PathBuf, Result<Rc<str>>>>,
+	loading_cache: RefCell<HashMap<PathBuf, Result<IStr>>>,
 	inner: Box<dyn ImportResolver>,
 }
 impl ImportResolver for CachingImportResolver {
@@ -101,7 +102,7 @@
 			.clone()
 	}
 
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<Rc<str>> {
+	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr> {
 		self.loading_cache
 			.borrow_mut()
 			.entry(resolved.clone())
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -23,6 +23,7 @@
 pub use evaluate::*;
 pub use function::parse_function_call;
 pub use import::*;
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::*;
 use native::NativeCallback;
 pub use obj::*;
@@ -63,13 +64,13 @@
 	/// Limits amount of stack trace items preserved
 	pub max_trace: usize,
 	/// Used for s`td.extVar`
-	pub ext_vars: HashMap<Rc<str>, Val>,
+	pub ext_vars: HashMap<IStr, Val>,
 	/// Used for ext.native
-	pub ext_natives: HashMap<Rc<str>, Rc<NativeCallback>>,
+	pub ext_natives: HashMap<IStr, Rc<NativeCallback>>,
 	/// TLA vars
-	pub tla_vars: HashMap<Rc<str>, Val>,
+	pub tla_vars: HashMap<IStr, Val>,
 	/// Global variables are inserted in default context
-	pub globals: HashMap<Rc<str>, Val>,
+	pub globals: HashMap<IStr, Val>,
 	/// Used to resolve file locations/contents
 	pub import_resolver: Box<dyn ImportResolver>,
 	/// Used in manifestification functions
@@ -102,11 +103,11 @@
 	stack_depth: usize,
 	/// Contains file source codes and evaluation results for imports and pretty-printed stacktraces
 	files: HashMap<Rc<PathBuf>, FileData>,
-	str_files: HashMap<Rc<PathBuf>, Rc<str>>,
+	str_files: HashMap<Rc<PathBuf>, IStr>,
 }
 
 pub struct FileData {
-	source_code: Rc<str>,
+	source_code: IStr,
 	parsed: LocExpr,
 	evaluated: Option<Val>,
 }
@@ -144,7 +145,7 @@
 
 impl EvaluationState {
 	/// Parses and adds file as loaded
-	pub fn add_file(&self, path: Rc<PathBuf>, source_code: Rc<str>) -> Result<()> {
+	pub fn add_file(&self, path: Rc<PathBuf>, source_code: IStr) -> Result<()> {
 		self.add_parsed_file(
 			path.clone(),
 			source_code.clone(),
@@ -169,7 +170,7 @@
 	pub fn add_parsed_file(
 		&self,
 		name: Rc<PathBuf>,
-		source_code: Rc<str>,
+		source_code: IStr,
 		parsed: LocExpr,
 	) -> Result<()> {
 		self.data_mut().files.insert(
@@ -183,7 +184,7 @@
 
 		Ok(())
 	}
-	pub fn get_source(&self, name: &PathBuf) -> Option<Rc<str>> {
+	pub fn get_source(&self, name: &PathBuf) -> Option<IStr> {
 		let ro_map = &self.data().files;
 		ro_map.get(name).map(|value| value.source_code.clone())
 	}
@@ -205,7 +206,7 @@
 		self.add_file(file_path.clone(), contents)?;
 		self.evaluate_loaded_file_raw(&file_path)
 	}
-	pub(crate) fn import_file_str(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<str>> {
+	pub(crate) fn import_file_str(&self, from: &PathBuf, path: &PathBuf) -> Result<IStr> {
 		let path = self.resolve_file(from, path)?;
 		if !self.data().str_files.contains_key(&path) {
 			let file_str = self.load_file_contents(&path)?;
@@ -257,7 +258,7 @@
 	/// Creates context with all passed global variables
 	pub fn create_default_context(&self) -> Result<Context> {
 		let globals = &self.settings().globals;
-		let mut new_bindings: HashMap<Rc<str>, LazyBinding> = HashMap::new();
+		let mut new_bindings: HashMap<IStr, LazyBinding> = HashMap::new();
 		for (name, value) in globals.iter() {
 			new_bindings.insert(
 				name.clone(),
@@ -321,13 +322,13 @@
 		out
 	}
 
-	pub fn manifest(&self, val: Val) -> Result<Rc<str>> {
+	pub fn manifest(&self, val: Val) -> Result<IStr> {
 		self.run_in_state(|| val.manifest(&self.manifest_format()))
 	}
-	pub fn manifest_multi(&self, val: Val) -> Result<Vec<(Rc<str>, Rc<str>)>> {
+	pub fn manifest_multi(&self, val: Val) -> Result<Vec<(IStr, IStr)>> {
 		self.run_in_state(|| val.manifest_multi(&self.manifest_format()))
 	}
-	pub fn manifest_stream(&self, val: Val) -> Result<Vec<Rc<str>>> {
+	pub fn manifest_stream(&self, val: Val) -> Result<Vec<IStr>> {
 		self.run_in_state(|| val.manifest_stream(&self.manifest_format()))
 	}
 
@@ -371,7 +372,7 @@
 		self.run_in_state(|| self.import_file(&PathBuf::from("."), name))
 	}
 	/// Parses and evaluates the given snippet
-	pub fn evaluate_snippet_raw(&self, source: Rc<PathBuf>, code: Rc<str>) -> Result<Val> {
+	pub fn evaluate_snippet_raw(&self, source: Rc<PathBuf>, code: IStr) -> Result<Val> {
 		let parsed = parse(
 			&code,
 			&ParserSettings {
@@ -391,26 +392,26 @@
 
 /// Settings utilities
 impl EvaluationState {
-	pub fn add_ext_var(&self, name: Rc<str>, value: Val) {
+	pub fn add_ext_var(&self, name: IStr, value: Val) {
 		self.settings_mut().ext_vars.insert(name, value);
 	}
-	pub fn add_ext_str(&self, name: Rc<str>, value: Rc<str>) {
+	pub fn add_ext_str(&self, name: IStr, value: IStr) {
 		self.add_ext_var(name, Val::Str(value));
 	}
-	pub fn add_ext_code(&self, name: Rc<str>, code: Rc<str>) -> Result<()> {
+	pub fn add_ext_code(&self, name: IStr, code: IStr) -> Result<()> {
 		let value =
 			self.evaluate_snippet_raw(Rc::new(PathBuf::from(format!("ext_code {}", name))), code)?;
 		self.add_ext_var(name, value);
 		Ok(())
 	}
 
-	pub fn add_tla(&self, name: Rc<str>, value: Val) {
+	pub fn add_tla(&self, name: IStr, value: Val) {
 		self.settings_mut().tla_vars.insert(name, value);
 	}
-	pub fn add_tla_str(&self, name: Rc<str>, value: Rc<str>) {
+	pub fn add_tla_str(&self, name: IStr, value: IStr) {
 		self.add_tla(name, Val::Str(value));
 	}
-	pub fn add_tla_code(&self, name: Rc<str>, code: Rc<str>) -> Result<()> {
+	pub fn add_tla_code(&self, name: IStr, code: IStr) -> Result<()> {
 		let value =
 			self.evaluate_snippet_raw(Rc::new(PathBuf::from(format!("tla_code {}", name))), code)?;
 		self.add_tla(name, value);
@@ -420,7 +421,7 @@
 	pub fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
 		Ok(self.settings().import_resolver.resolve_file(from, path)?)
 	}
-	pub fn load_file_contents(&self, path: &PathBuf) -> Result<Rc<str>> {
+	pub fn load_file_contents(&self, path: &PathBuf) -> Result<IStr> {
 		Ok(self.settings().import_resolver.load_file_contents(path)?)
 	}
 
@@ -431,7 +432,7 @@
 		self.settings_mut().import_resolver = resolver;
 	}
 
-	pub fn add_native(&self, name: Rc<str>, cb: Rc<NativeCallback>) {
+	pub fn add_native(&self, name: IStr, cb: Rc<NativeCallback>) {
 		self.settings_mut().ext_natives.insert(name, cb);
 	}
 
@@ -468,6 +469,7 @@
 pub mod tests {
 	use super::Val;
 	use crate::{error::Error::*, primitive_equals, EvaluationState};
+	use jrsonnet_interner::IStr;
 	use jrsonnet_parser::*;
 	use std::{path::PathBuf, rc::Rc};
 
@@ -905,13 +907,13 @@
 		Ok(())
 	}
 
-	struct TestImportResolver(Rc<str>);
+	struct TestImportResolver(IStr);
 	impl crate::import::ImportResolver for TestImportResolver {
 		fn resolve_file(&self, _: &PathBuf, _: &PathBuf) -> crate::error::Result<Rc<PathBuf>> {
 			Ok(Rc::new(PathBuf::from("/test")))
 		}
 
-		fn load_file_contents(&self, _: &PathBuf) -> crate::error::Result<Rc<str>> {
+		fn load_file_contents(&self, _: &PathBuf) -> crate::error::Result<IStr> {
 			Ok(self.0.clone())
 		}
 
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,5 +1,6 @@
 use crate::{evaluate_add_op, LazyBinding, Result, Val};
 use indexmap::IndexMap;
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ExprLocation, Visibility};
 use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
 
@@ -12,11 +13,11 @@
 }
 
 // Field => This
-type CacheKey = (Rc<str>, usize);
+type CacheKey = (IStr, usize);
 #[derive(Debug)]
 pub struct ObjValueInternals {
 	super_obj: Option<ObjValue>,
-	this_entries: Rc<HashMap<Rc<str>, ObjMember>>,
+	this_entries: Rc<HashMap<IStr, ObjMember>>,
 	value_cache: RefCell<HashMap<CacheKey, Option<Val>>>,
 }
 #[derive(Clone)]
@@ -33,7 +34,7 @@
 		}
 		let mut debug = f.debug_struct("ObjValue");
 		for (name, member) in self.0.this_entries.iter() {
-			debug.field(name, member);
+			debug.field(&name, member);
 		}
 		#[cfg(feature = "unstable")]
 		{
@@ -47,7 +48,7 @@
 }
 
 impl ObjValue {
-	pub fn new(super_obj: Option<Self>, this_entries: Rc<HashMap<Rc<str>, ObjMember>>) -> Self {
+	pub fn new(super_obj: Option<Self>, this_entries: Rc<HashMap<IStr, ObjMember>>) -> Self {
 		Self(Rc::new(ObjValueInternals {
 			super_obj,
 			this_entries,
@@ -63,7 +64,7 @@
 			Some(v) => Self::new(Some(v.with_super(super_obj)), self.0.this_entries.clone()),
 		}
 	}
-	pub fn enum_fields(&self, handler: &impl Fn(&Rc<str>, &Visibility)) {
+	pub fn enum_fields(&self, handler: &impl Fn(&IStr, &Visibility)) {
 		if let Some(s) = &self.0.super_obj {
 			s.enum_fields(handler);
 		}
@@ -71,7 +72,7 @@
 			handler(name, &member.visibility);
 		}
 	}
-	pub fn fields_visibility(&self) -> IndexMap<Rc<str>, bool> {
+	pub fn fields_visibility(&self) -> IndexMap<IStr, bool> {
 		let out = Rc::new(RefCell::new(IndexMap::new()));
 		self.enum_fields(&|name, visibility| {
 			let mut out = out.borrow_mut();
@@ -91,7 +92,7 @@
 		});
 		Rc::try_unwrap(out).unwrap().into_inner()
 	}
-	pub fn visible_fields(&self) -> Vec<Rc<str>> {
+	pub fn visible_fields(&self) -> Vec<IStr> {
 		let mut visible_fields: Vec<_> = self
 			.fields_visibility()
 			.into_iter()
@@ -101,10 +102,10 @@
 		visible_fields.sort();
 		visible_fields
 	}
-	pub fn get(&self, key: Rc<str>) -> Result<Option<Val>> {
+	pub fn get(&self, key: IStr) -> Result<Option<Val>> {
 		Ok(self.get_raw(key, None)?)
 	}
-	pub(crate) fn get_raw(&self, key: Rc<str>, real_this: Option<&Self>) -> Result<Option<Val>> {
+	pub(crate) fn get_raw(&self, key: IStr, real_this: Option<&Self>) -> Result<Option<Val>> {
 		let real_this = real_this.unwrap_or(self);
 		let cache_key = (key.clone(), Rc::as_ptr(&real_this.0) as usize);
 
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -9,6 +9,7 @@
 	native::NativeCallback,
 	throw, with_state, Context, ObjValue, Result,
 };
+use jrsonnet_interner::IStr;
 use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};
 use jrsonnet_types::ValType;
 use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
@@ -61,7 +62,7 @@
 
 #[derive(Debug, PartialEq)]
 pub struct FuncDesc {
-	pub name: Rc<str>,
+	pub name: IStr,
 	pub ctx: Context,
 	pub params: ParamsDesc,
 	pub body: LocExpr,
@@ -72,9 +73,9 @@
 	/// Plain function implemented in jsonnet
 	Normal(FuncDesc),
 	/// Standard library function
-	Intrinsic(Rc<str>),
+	Intrinsic(IStr),
 	/// Library functions implemented in native
-	NativeExt(Rc<str>, Rc<NativeCallback>),
+	NativeExt(IStr, Rc<NativeCallback>),
 }
 
 impl PartialEq for FuncVal {
@@ -91,7 +92,7 @@
 	pub fn is_ident(&self) -> bool {
 		matches!(&self, Self::Intrinsic(n) if n as &str == "id")
 	}
-	pub fn name(&self) -> Rc<str> {
+	pub fn name(&self) -> IStr {
 		match self {
 			Self::Normal(normal) => normal.name.clone(),
 			Self::Intrinsic(name) => format!("std.{}", name).into(),
@@ -131,7 +132,7 @@
 	pub fn evaluate_map(
 		&self,
 		call_ctx: Context,
-		args: &HashMap<Rc<str>, Val>,
+		args: &HashMap<IStr, Val>,
 		tailstrict: bool,
 	) -> Result<Val> {
 		match self {
@@ -270,7 +271,7 @@
 pub enum Val {
 	Bool(bool),
 	Null,
-	Str(Rc<str>),
+	Str(IStr),
 	Num(f64),
 	Arr(ArrValue),
 	Obj(ObjValue),
@@ -314,7 +315,7 @@
 		self.assert_type(context, ValType::Bool)?;
 		Ok(matches_unwrap!(self, Self::Bool(v), v))
 	}
-	pub fn try_cast_str(self, context: &'static str) -> Result<Rc<str>> {
+	pub fn try_cast_str(self, context: &'static str) -> Result<IStr> {
 		self.assert_type(context, ValType::Str)?;
 		Ok(matches_unwrap!(self, Self::Str(v), v))
 	}
@@ -334,7 +335,7 @@
 		}
 	}
 
-	pub fn to_string(&self) -> Result<Rc<str>> {
+	pub fn to_string(&self) -> Result<IStr> {
 		Ok(match self {
 			Self::Bool(true) => "true".into(),
 			Self::Bool(false) => "false".into(),
@@ -352,7 +353,7 @@
 	}
 
 	/// Expects value to be object, outputs (key, manifested value) pairs
-	pub fn manifest_multi(&self, ty: &ManifestFormat) -> Result<Vec<(Rc<str>, Rc<str>)>> {
+	pub fn manifest_multi(&self, ty: &ManifestFormat) -> Result<Vec<(IStr, IStr)>> {
 		let obj = match self {
 			Self::Obj(obj) => obj,
 			_ => throw!(MultiManifestOutputIsNotAObject),
@@ -370,7 +371,7 @@
 	}
 
 	/// Expects value to be array, outputs manifested values
-	pub fn manifest_stream(&self, ty: &ManifestFormat) -> Result<Vec<Rc<str>>> {
+	pub fn manifest_stream(&self, ty: &ManifestFormat) -> Result<Vec<IStr>> {
 		let arr = match self {
 			Self::Arr(a) => a,
 			_ => throw!(StreamManifestOutputIsNotAArray),
@@ -382,7 +383,7 @@
 		Ok(out)
 	}
 
-	pub fn manifest(&self, ty: &ManifestFormat) -> Result<Rc<str>> {
+	pub fn manifest(&self, ty: &ManifestFormat) -> Result<IStr> {
 		Ok(match ty {
 			ManifestFormat::YamlStream(format) => {
 				let arr = match self {
@@ -419,7 +420,7 @@
 	}
 
 	/// For manifestification
-	pub fn to_json(&self, padding: usize) -> Result<Rc<str>> {
+	pub fn to_json(&self, padding: usize) -> Result<IStr> {
 		manifest_json_ex(
 			self,
 			&ManifestJsonOptions {
@@ -471,7 +472,7 @@
 			.try_cast_str("to json")?)
 		})
 	}
-	pub fn to_yaml(&self, padding: usize) -> Result<Rc<str>> {
+	pub fn to_yaml(&self, padding: usize) -> Result<IStr> {
 		with_state(|s| {
 			let ctx = s
 				.create_default_context()?
addedcrates/jrsonnet-interner/.gitignorediffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-interner/.gitignore
@@ -0,0 +1,2 @@
+/target
+Cargo.lock
addedcrates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "jrsonnet-interner"
+version = "0.3.3"
+authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
+edition = "2018"
+
+[dependencies]
+serde = { version = "1.0" }
+rustc-hash = "1.1.0"
addedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -0,0 +1,104 @@
+use rustc_hash::FxHashMap;
+use serde::{Deserialize, Serialize};
+use std::{
+	cell::RefCell,
+	fmt::{self, Display},
+	hash::{BuildHasherDefault, Hash, Hasher},
+	ops::Deref,
+	rc::Rc,
+};
+
+#[derive(Clone, PartialOrd, Ord, Eq)]
+pub struct IStr(Rc<str>);
+
+impl Deref for IStr {
+	type Target = str;
+
+	fn deref(&self) -> &Self::Target {
+		&self.0
+	}
+}
+
+impl PartialEq for IStr {
+	fn eq(&self, other: &Self) -> bool {
+		// It is ok, since all IStr should be inlined into same pool
+		Rc::ptr_eq(&self.0, &other.0)
+	}
+}
+
+impl PartialEq<str> for IStr {
+	fn eq(&self, other: &str) -> bool {
+		&self.0 as &str == other
+	}
+}
+
+impl Hash for IStr {
+	fn hash<H: Hasher>(&self, state: &mut H) {
+		state.write_usize(Rc::as_ptr(&self.0) as *const () as usize)
+	}
+}
+
+impl Drop for IStr {
+	fn drop(&mut self) {
+		// First reference - current object, second - POOL
+		if Rc::strong_count(&self.0) <= 2 {
+			STR_POOL.with(|pool| pool.borrow_mut().remove(&self.0));
+		}
+	}
+}
+
+impl fmt::Debug for IStr {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		write!(f, "{:?}", &self.0)
+	}
+}
+
+impl Display for IStr {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.write_str(&self.0)
+	}
+}
+
+thread_local! {
+	static STR_POOL: RefCell<FxHashMap<Rc<str>, ()>> = RefCell::new(FxHashMap::with_capacity_and_hasher(200, BuildHasherDefault::default()));
+}
+
+impl From<&str> for IStr {
+	fn from(str: &str) -> Self {
+		IStr(STR_POOL.with(|pool| {
+			let mut pool = pool.borrow_mut();
+			if let Some((k, _)) = pool.get_key_value(str) {
+				return k.clone();
+			} else {
+				let rc: Rc<str> = str.into();
+				pool.insert(rc.clone(), ());
+				rc
+			}
+		}))
+	}
+}
+
+impl From<String> for IStr {
+	fn from(str: String) -> Self {
+		(&str as &str).into()
+	}
+}
+
+impl Serialize for IStr {
+	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+	where
+		S: serde::Serializer,
+	{
+		(&self.0 as &str).serialize(serializer)
+	}
+}
+
+impl<'de> Deserialize<'de> for IStr {
+	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+	where
+		D: serde::Deserializer<'de>,
+	{
+		let s = <&str>::deserialize(deserializer)?;
+		Ok(s.into())
+	}
+}
modifiedcrates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -10,16 +10,14 @@
 default = []
 serialize = ["serde"]
 deserialize = ["serde"]
-# Adds ability to dump AST as source code for easy embedding
-dump = ["structdump", "structdump-derive"]
 
 [dependencies]
+jrsonnet-interner = { path = "../jrsonnet-interner" }
+
 peg = "0.6.3"
 unescape = "0.1.0"
 
 serde = { version = "1.0", features = ["derive", "rc"], optional = true }
-structdump = { version = "0.1.2", optional = true }
-structdump-derive = { version = "0.1.2", optional = true }
 
 [dev-dependencies]
 jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.3" }
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -1,3 +1,4 @@
+use jrsonnet_interner::IStr;
 #[cfg(feature = "deserialize")]
 use serde::Deserialize;
 #[cfg(feature = "serialize")]
@@ -8,21 +9,17 @@
 	path::PathBuf,
 	rc::Rc,
 };
-#[cfg(feature = "dump")]
-use structdump_derive::Codegen;
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
 pub enum FieldName {
 	/// {fixed: 2}
-	Fixed(Rc<str>),
+	Fixed(IStr),
 	/// {["dyn"+"amic"]: 3}
 	Dyn(LocExpr),
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, Clone, Copy, PartialEq)]
@@ -35,13 +32,11 @@
 	Unhide,
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
 pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -53,7 +48,6 @@
 	pub value: LocExpr,
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -63,7 +57,6 @@
 	AssertStmt(AssertStmt),
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, Clone, Copy, PartialEq)]
@@ -89,7 +82,6 @@
 	}
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, Clone, Copy, PartialEq)]
@@ -147,14 +139,12 @@
 }
 
 /// name, default value
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
-pub struct Param(pub Rc<str>, pub Option<LocExpr>);
+pub struct Param(pub IStr, pub Option<LocExpr>);
 
 /// Defined function parameters
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, Clone, PartialEq)]
@@ -166,13 +156,11 @@
 	}
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
 pub struct Arg(pub Option<String>, pub LocExpr);
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -184,29 +172,25 @@
 	}
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, Clone, PartialEq)]
 pub struct BindSpec {
-	pub name: Rc<str>,
+	pub name: IStr,
 	pub params: Option<ParamsDesc>,
 	pub value: LocExpr,
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
 pub struct IfSpecData(pub LocExpr);
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
-pub struct ForSpecData(pub Rc<str>, pub LocExpr);
+pub struct ForSpecData(pub IStr, pub LocExpr);
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -215,7 +199,6 @@
 	ForSpec(ForSpecData),
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -227,7 +210,6 @@
 	pub compspecs: Vec<CompSpec>,
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -236,7 +218,6 @@
 	ObjComp(ObjComp),
 }
 
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq, Clone, Copy)]
@@ -257,7 +238,6 @@
 }
 
 /// Syntax base
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Debug, PartialEq)]
@@ -265,11 +245,11 @@
 	Literal(LiteralType),
 
 	/// String value: "hello"
-	Str(Rc<str>),
+	Str(IStr),
 	/// Number: 1, 2.0, 2e+20
 	Num(f64),
 	/// Variable name: test
-	Var(Rc<str>),
+	Var(IStr),
 
 	/// Array of expressions: [1, 2, "Hello"]
 	Arr(Vec<LocExpr>),
@@ -316,7 +296,7 @@
 	/// function(x) x
 	Function(ParamsDesc, LocExpr),
 	/// std.primitiveEquals
-	Intrinsic(Rc<str>),
+	Intrinsic(IStr),
 	/// if true == false then 1 else 2
 	IfElse {
 		cond: IfSpecData,
@@ -326,7 +306,6 @@
 }
 
 /// file, begin offset, end offset
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Clone, PartialEq)]
@@ -338,7 +317,6 @@
 }
 
 /// Holds AST expression and its location in source file
-#[cfg_attr(feature = "dump", derive(Codegen))]
 #[cfg_attr(feature = "serialize", derive(Serialize))]
 #[cfg_attr(feature = "deserialize", derive(Deserialize))]
 #[derive(Clone, PartialEq)]