git.delta.rocks / jrsonnet / refs/commits / 4ad9956e5f9b

difftreelog

refactor keep source code alongside source path

Yaroslav Bolyukin2022-08-05parent: #68c8ac0.patch.diff
in: master

18 files changed

modifiedbindings/jsonnet/src/import.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -16,6 +16,7 @@
 	error::{Error::*, Result},
 	throw, ImportResolver, State,
 };
+use jrsonnet_parser::SourcePath;
 
 pub type JsonnetImportCallback = unsafe extern "C" fn(
 	ctx: *mut c_void,
@@ -29,10 +30,10 @@
 pub struct CallbackImportResolver {
 	cb: JsonnetImportCallback,
 	ctx: *mut c_void,
-	out: RefCell<HashMap<PathBuf, Vec<u8>>>,
+	out: RefCell<HashMap<SourcePath, Vec<u8>>>,
 }
 impl ImportResolver for CallbackImportResolver {
-	fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf> {
+	fn resolve_file_relative(&self, from: &Path, path: &str) -> Result<SourcePath> {
 		let base = CString::new(from.to_str().unwrap()).unwrap().into_raw();
 		let rel = CString::new(path).unwrap().into_raw();
 		let found_here: *mut c_char = null_mut();
@@ -61,7 +62,7 @@
 		}
 
 		let found_here_raw = unsafe { CStr::from_ptr(found_here) };
-		let found_here_buf = PathBuf::from(found_here_raw.to_str().unwrap());
+		let found_here_buf = SourcePath::Path(PathBuf::from(found_here_raw.to_str().unwrap()));
 		unsafe {
 			let _ = CString::from_raw(found_here);
 		}
@@ -74,7 +75,7 @@
 
 		Ok(found_here_buf)
 	}
-	fn load_file_contents(&self, resolved: &Path) -> Result<Vec<u8>> {
+	fn load_file_contents(&self, resolved: &SourcePath) -> Result<Vec<u8>> {
 		Ok(self.out.borrow().get(resolved).unwrap().clone())
 	}
 
@@ -108,24 +109,28 @@
 	}
 }
 impl ImportResolver for NativeImportResolver {
-	fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf> {
+	fn resolve_file_relative(&self, from: &Path, path: &str) -> Result<SourcePath> {
 		let mut new_path = from.to_owned();
 		new_path.push(path);
 		if new_path.exists() {
-			Ok(new_path)
+			Ok(SourcePath::Path(new_path))
 		} else {
 			for library_path in self.library_paths.borrow().iter() {
 				let mut cloned = library_path.clone();
 				cloned.push(path);
 				if cloned.exists() {
-					return Ok(cloned);
+					return Ok(SourcePath::Path(cloned));
 				}
 			}
 			throw!(ImportFileNotFound(from.to_owned(), path.to_owned()))
 		}
 	}
-	fn load_file_contents(&self, id: &Path) -> Result<Vec<u8>> {
-		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.to_owned()))?;
+	fn load_file_contents(&self, id: &SourcePath) -> Result<Vec<u8>> {
+		let path = match id {
+			SourcePath::Path(path) => path,
+			_ => unreachable!("NativeImportResolver::resolve_file may only return plain paths"),
+		};
+		let mut file = File::open(path).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
 		let mut out = Vec::new();
 		file.read_to_end(&mut out)
 			.map_err(|e| ImportIo(e.to_string()))?;
modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -10,9 +10,9 @@
 
 use std::{
 	alloc::Layout,
+	env,
 	ffi::{CStr, CString},
 	os::raw::{c_char, c_double, c_int, c_uint},
-	path::PathBuf,
 };
 
 use import::NativeImportResolver;
@@ -112,7 +112,10 @@
 ) -> *const c_char {
 	let filename = CStr::from_ptr(filename);
 	match vm
-		.import(PathBuf::from(filename.to_str().unwrap()))
+		.import(
+			&env::current_dir().expect("cwd"),
+			filename.to_str().unwrap(),
+		)
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest(v))
 	{
@@ -141,10 +144,7 @@
 	let filename = CStr::from_ptr(filename);
 	let snippet = CStr::from_ptr(snippet);
 	match vm
-		.evaluate_snippet(
-			filename.to_str().unwrap().into(),
-			snippet.to_str().unwrap().into(),
-		)
+		.evaluate_snippet(filename.to_str().unwrap().into(), snippet.to_str().unwrap())
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest(v))
 	{
@@ -186,7 +186,10 @@
 ) -> *const c_char {
 	let filename = CStr::from_ptr(filename);
 	match vm
-		.import(PathBuf::from(filename.to_str().unwrap()))
+		.import(
+			&env::current_dir().expect("cwd"),
+			filename.to_str().unwrap(),
+		)
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest_multi(v))
 	{
@@ -213,10 +216,7 @@
 	let filename = CStr::from_ptr(filename);
 	let snippet = CStr::from_ptr(snippet);
 	match vm
-		.evaluate_snippet(
-			filename.to_str().unwrap().into(),
-			snippet.to_str().unwrap().into(),
-		)
+		.evaluate_snippet(filename.to_str().unwrap().into(), snippet.to_str().unwrap())
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest_multi(v))
 	{
@@ -256,7 +256,10 @@
 ) -> *const c_char {
 	let filename = CStr::from_ptr(filename);
 	match vm
-		.import(PathBuf::from(filename.to_str().unwrap()))
+		.import(
+			&env::current_dir().expect("cwd"),
+			filename.to_str().unwrap(),
+		)
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest_stream(v))
 	{
@@ -283,10 +286,7 @@
 	let filename = CStr::from_ptr(filename);
 	let snippet = CStr::from_ptr(snippet);
 	match vm
-		.evaluate_snippet(
-			filename.to_str().unwrap().into(),
-			snippet.to_str().unwrap().into(),
-		)
+		.evaluate_snippet(filename.to_str().unwrap().into(), snippet.to_str().unwrap())
 		.and_then(|v| vm.with_tla(v))
 		.and_then(|v| vm.manifest_stream(v))
 	{
modifiedbindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/vars_tlas.rs
+++ b/bindings/jsonnet/src/vars_tlas.rs
@@ -32,7 +32,7 @@
 		.as_any()
 		.downcast_ref::<jrsonnet_stdlib::ContextInitializer>()
 		.expect("only stdlib context initializer supported")
-		.add_ext_code(name.to_str().unwrap(), value.to_str().unwrap().into())
+		.add_ext_code(name.to_str().unwrap(), value.to_str().unwrap())
 		.unwrap()
 }
 /// # Safety
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -133,14 +133,14 @@
 
 	let input = opts.input.input.ok_or(Error::MissingInputArgument)?;
 	let val = if opts.input.exec {
-		s.evaluate_snippet("<cmdline>".to_owned(), (&input as &str).into())?
+		s.evaluate_snippet("<cmdline>".to_owned(), &input as &str)?
 	} else if input == "-" {
 		let mut input = Vec::new();
 		std::io::stdin().read_to_end(&mut input)?;
-		let input_str = std::str::from_utf8(&input)?.into();
+		let input_str = std::str::from_utf8(&input)?;
 		s.evaluate_snippet("<stdin>".to_owned(), input_str)?
 	} else {
-		s.import(s.resolve_file(&current_dir().expect("cwd"), &input)?)?
+		s.import(&current_dir().expect("cwd"), &input)?
 	};
 
 	let val = s.with_tla(val)?;
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -118,10 +118,10 @@
 			ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
 		}
 		for ext in self.ext_code.iter() {
-			ctx.add_ext_code(&ext.name as &str, (&ext.value as &str).into())?;
+			ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
 		}
 		for ext in self.ext_code_file.iter() {
-			ctx.add_ext_code(&ext.name as &str, (&ext.value as &str).into())?;
+			ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
 		}
 		s.settings_mut().context_initializer = Box::new(ctx);
 		Ok(())
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/error.rs
1use std::{fmt::Debug, path::PathBuf};23use jrsonnet_gcmodule::Trace;4use jrsonnet_interner::IStr;5use jrsonnet_parser::{BinaryOpType, ExprLocation, Source, UnaryOpType};6use jrsonnet_types::ValType;7use thiserror::Error;89use crate::{stdlib::format::FormatError, typed::TypeLocError};1011fn format_found(list: &[IStr], what: &str) -> String {12	if list.is_empty() {13		return String::new();14	}15	let mut out = String::new();16	out.push_str("\nThere is ");17	out.push_str(what);18	if list.len() > 1 {19		out.push('s');20	}21	out.push_str(" with similar name");22	if list.len() > 1 {23		out.push('s');24	}25	out.push_str(" present: ");26	for (i, v) in list.iter().enumerate() {27		if i != 0 {28			out.push_str(", ");29		}30		out.push_str(v as &str);31	}32	out33}3435fn format_signature(sig: &FunctionSignature) -> String {36	let mut out = String::new();37	out.push_str("\nFunction has the following signature: ");38	out.push('(');39	if sig.is_empty() {40		out.push_str("/*no arguments*/");41	} else {42		for (i, (name, has_default)) in sig.iter().enumerate() {43			if i != 0 {44				out.push_str(", ");45			}46			if let Some(name) = name {47				out.push_str(name);48			} else {49				out.push_str("<unnamed>");50			}51			if *has_default {52				out.push_str(" = <default>");53			}54		}55	}56	out.push(')');57	out58}5960const fn format_empty_str(str: &str) -> &str {61	if str.is_empty() {62		"\"\" (empty string)"63	} else {64		str65	}66}6768type FunctionSignature = Vec<(Option<IStr>, bool)>;6970#[derive(Error, Debug, Clone, Trace)]71pub enum Error {72	#[error("intrinsic not found: {0}")]73	IntrinsicNotFound(IStr),7475	#[error("operator {0} does not operate on type {1}")]76	UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),77	#[error("binary operation {1} {0} {2} is not implemented")]78	BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),7980	#[error("no top level object in this context")]81	NoTopLevelObjectFound,82	#[error("self is only usable inside objects")]83	CantUseSelfOutsideOfObject,84	#[error("no super found")]85	NoSuperFound,8687	#[error("for loop can only iterate over arrays")]88	InComprehensionCanOnlyIterateOverArray,8990	#[error("array out of bounds: {0} is not within [0,{1})")]91	ArrayBoundsError(usize, usize),92	#[error("string out of bounds: {0} is not within [0,{1})")]93	StringBoundsError(usize, usize),9495	#[error("assert failed: {}", format_empty_str(.0))]96	AssertionFailed(IStr),9798	#[error("variable is not defined: {0}{}", format_found(.1, "variable"))]99	VariableIsNotDefined(IStr, Vec<IStr>),100	#[error("duplicate local var: {0}")]101	DuplicateLocalVar(IStr),102103	#[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]104	TypeMismatch(&'static str, Vec<ValType>, ValType),105	#[error("no such field: {}{}", format_empty_str(.0), format_found(.1, "field"))]106	NoSuchField(IStr, Vec<IStr>),107108	#[error("only functions can be called, got {0}")]109	OnlyFunctionsCanBeCalledGot(ValType),110	#[error("parameter {0} is not defined")]111	UnknownFunctionParameter(String),112	#[error("argument {0} is already bound")]113	BindingParameterASecondTime(IStr),114	#[error("too many args, function has {0}{}", format_signature(.1))]115	TooManyArgsFunctionHas(usize, FunctionSignature),116	#[error("function argument is not passed: {0}{}", format_signature(.1))]117	FunctionParameterNotBoundInCall(IStr, FunctionSignature),118119	#[error("external variable is not defined: {0}")]120	UndefinedExternalVariable(IStr),121122	#[error("field name should be string, got {0}")]123	FieldMustBeStringGot(ValType),124	#[error("duplicate field name: {}", format_empty_str(.0))]125	DuplicateFieldName(IStr),126127	#[error("attempted to index array with string {}", format_empty_str(.0))]128	AttemptedIndexAnArrayWithString(IStr),129	#[error("{0} index type should be {1}, got {2}")]130	ValueIndexMustBeTypeGot(ValType, ValType, ValType),131	#[error("cant index into {0}")]132	CantIndexInto(ValType),133	#[error("{0} is not indexable")]134	ValueIsNotIndexable(ValType),135136	#[error("super can't be used standalone")]137	StandaloneSuper,138139	#[error("can't resolve {1} from {0}")]140	ImportFileNotFound(PathBuf, String),141	#[error("resolved file not found: {0}")]142	ResolvedFileNotFound(PathBuf),143	#[error("imported file is not valid utf-8: {0:?}")]144	ImportBadFileUtf8(PathBuf),145	#[error("import io error: {0}")]146	ImportIo(String),147	#[error("tried to import {1} from {0}, but imports is not supported")]148	ImportNotSupported(PathBuf, PathBuf),149	#[error("can't import from virtual file")]150	CantImportFromVirtualFile,151	#[error(152		"syntax error: expected {}, got {:?}",153		.error.expected,154		.source_code.chars().nth(error.location.offset)155		.map_or_else(|| "EOF".into(), |c| c.to_string())156	)]157	ImportSyntaxError {158		path: Source,159		source_code: IStr,160		#[trace(skip)]161		error: Box<jrsonnet_parser::ParseError>,162	},163164	#[error("runtime error: {}", format_empty_str(.0))]165	RuntimeError(IStr),166	#[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]167	StackOverflow,168	#[error("infinite recursion detected")]169	InfiniteRecursionDetected,170	#[error("tried to index by fractional value")]171	FractionalIndex,172	#[error("attempted to divide by zero")]173	DivisionByZero,174175	#[error("string manifest output is not an string")]176	StringManifestOutputIsNotAString,177	#[error("stream manifest output is not an array")]178	StreamManifestOutputIsNotAArray,179	#[error("multi manifest output is not an object")]180	MultiManifestOutputIsNotAObject,181182	#[error("cant recurse stream manifest")]183	StreamManifestOutputCannotBeRecursed,184	#[error("stream manifest output cannot consist of raw strings")]185	StreamManifestCannotNestString,186187	#[error("{}", format_empty_str(.0))]188	ImportCallbackError(String),189	#[error("invalid unicode codepoint: {0}")]190	InvalidUnicodeCodepointGot(u32),191192	#[error("format error: {0}")]193	Format(#[from] FormatError),194	#[error("type error: {0}")]195	TypeError(TypeLocError),196197	#[cfg(feature = "anyhow-error")]198	#[error(transparent)]199	Other(Rc<anyhow::Error>),200}201202#[cfg(feature = "anyhow-error")]203impl From<anyhow::Error> for LocError {204	fn from(e: anyhow::Error) -> Self {205		Self::new(Error::Other(Rc::new(e)))206	}207}208209impl From<Error> for LocError {210	fn from(e: Error) -> Self {211		Self::new(e)212	}213}214215#[derive(Clone, Debug, Trace)]216pub struct StackTraceElement {217	pub location: Option<ExprLocation>,218	pub desc: String,219}220#[derive(Debug, Clone, Trace)]221pub struct StackTrace(pub Vec<StackTraceElement>);222223#[derive(Clone, Trace)]224pub struct LocError(Box<(Error, StackTrace)>);225impl LocError {226	pub fn new(e: Error) -> Self {227		Self(Box::new((e, StackTrace(vec![]))))228	}229230	pub const fn error(&self) -> &Error {231		&(self.0).0232	}233	pub fn error_mut(&mut self) -> &mut Error {234		&mut (self.0).0235	}236	pub const fn trace(&self) -> &StackTrace {237		&(self.0).1238	}239	pub fn trace_mut(&mut self) -> &mut StackTrace {240		&mut (self.0).1241	}242}243impl Debug for LocError {244	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {245		writeln!(f, "{}", self.0 .0)?;246		for el in &self.0 .1 .0 {247			writeln!(f, "\t{:?}", el)?;248		}249		Ok(())250	}251}252253pub type Result<V, E = LocError> = std::result::Result<V, E>;254255#[macro_export]256macro_rules! throw {257	($e: expr) => {258		return Err($e.into())259	};260}261262#[macro_export]263macro_rules! throw_runtime {264	($($tt:tt)*) => {265		return Err($crate::error::Error::RuntimeError(format!($($tt)*).into()).into())266	};267}
after · crates/jrsonnet-evaluator/src/error.rs
1use std::{fmt::Debug, path::PathBuf};23use jrsonnet_gcmodule::Trace;4use jrsonnet_interner::IStr;5use jrsonnet_parser::{BinaryOpType, ExprLocation, Source, SourcePath, UnaryOpType};6use jrsonnet_types::ValType;7use thiserror::Error;89use crate::{stdlib::format::FormatError, typed::TypeLocError};1011fn format_found(list: &[IStr], what: &str) -> String {12	if list.is_empty() {13		return String::new();14	}15	let mut out = String::new();16	out.push_str("\nThere is ");17	out.push_str(what);18	if list.len() > 1 {19		out.push('s');20	}21	out.push_str(" with similar name");22	if list.len() > 1 {23		out.push('s');24	}25	out.push_str(" present: ");26	for (i, v) in list.iter().enumerate() {27		if i != 0 {28			out.push_str(", ");29		}30		out.push_str(v as &str);31	}32	out33}3435fn format_signature(sig: &FunctionSignature) -> String {36	let mut out = String::new();37	out.push_str("\nFunction has the following signature: ");38	out.push('(');39	if sig.is_empty() {40		out.push_str("/*no arguments*/");41	} else {42		for (i, (name, has_default)) in sig.iter().enumerate() {43			if i != 0 {44				out.push_str(", ");45			}46			if let Some(name) = name {47				out.push_str(name);48			} else {49				out.push_str("<unnamed>");50			}51			if *has_default {52				out.push_str(" = <default>");53			}54		}55	}56	out.push(')');57	out58}5960const fn format_empty_str(str: &str) -> &str {61	if str.is_empty() {62		"\"\" (empty string)"63	} else {64		str65	}66}6768type FunctionSignature = Vec<(Option<IStr>, bool)>;6970#[derive(Error, Debug, Clone, Trace)]71pub enum Error {72	#[error("intrinsic not found: {0}")]73	IntrinsicNotFound(IStr),7475	#[error("operator {0} does not operate on type {1}")]76	UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),77	#[error("binary operation {1} {0} {2} is not implemented")]78	BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),7980	#[error("no top level object in this context")]81	NoTopLevelObjectFound,82	#[error("self is only usable inside objects")]83	CantUseSelfOutsideOfObject,84	#[error("no super found")]85	NoSuperFound,8687	#[error("for loop can only iterate over arrays")]88	InComprehensionCanOnlyIterateOverArray,8990	#[error("array out of bounds: {0} is not within [0,{1})")]91	ArrayBoundsError(usize, usize),92	#[error("string out of bounds: {0} is not within [0,{1})")]93	StringBoundsError(usize, usize),9495	#[error("assert failed: {}", format_empty_str(.0))]96	AssertionFailed(IStr),9798	#[error("variable is not defined: {0}{}", format_found(.1, "variable"))]99	VariableIsNotDefined(IStr, Vec<IStr>),100	#[error("duplicate local var: {0}")]101	DuplicateLocalVar(IStr),102103	#[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]104	TypeMismatch(&'static str, Vec<ValType>, ValType),105	#[error("no such field: {}{}", format_empty_str(.0), format_found(.1, "field"))]106	NoSuchField(IStr, Vec<IStr>),107108	#[error("only functions can be called, got {0}")]109	OnlyFunctionsCanBeCalledGot(ValType),110	#[error("parameter {0} is not defined")]111	UnknownFunctionParameter(String),112	#[error("argument {0} is already bound")]113	BindingParameterASecondTime(IStr),114	#[error("too many args, function has {0}{}", format_signature(.1))]115	TooManyArgsFunctionHas(usize, FunctionSignature),116	#[error("function argument is not passed: {0}{}", format_signature(.1))]117	FunctionParameterNotBoundInCall(IStr, FunctionSignature),118119	#[error("external variable is not defined: {0}")]120	UndefinedExternalVariable(IStr),121122	#[error("field name should be string, got {0}")]123	FieldMustBeStringGot(ValType),124	#[error("duplicate field name: {}", format_empty_str(.0))]125	DuplicateFieldName(IStr),126127	#[error("attempted to index array with string {}", format_empty_str(.0))]128	AttemptedIndexAnArrayWithString(IStr),129	#[error("{0} index type should be {1}, got {2}")]130	ValueIndexMustBeTypeGot(ValType, ValType, ValType),131	#[error("cant index into {0}")]132	CantIndexInto(ValType),133	#[error("{0} is not indexable")]134	ValueIsNotIndexable(ValType),135136	#[error("super can't be used standalone")]137	StandaloneSuper,138139	#[error("can't resolve {1} from {0}")]140	ImportFileNotFound(PathBuf, String),141	#[error("resolved file not found: {:?}", .0)]142	ResolvedFileNotFound(SourcePath),143	#[error("imported file is not valid utf-8: {0:?}")]144	ImportBadFileUtf8(SourcePath),145	#[error("import io error: {0}")]146	ImportIo(String),147	#[error("tried to import {1} from {0}, but imports is not supported")]148	ImportNotSupported(PathBuf, PathBuf),149	#[error("can't import from virtual file")]150	CantImportFromVirtualFile,151	#[error(152		"syntax error: expected {}, got {:?}",153		.error.expected,154		.path.code().chars().nth(error.location.offset)155		.map_or_else(|| "EOF".into(), |c| c.to_string())156	)]157	ImportSyntaxError {158		path: Source,159		#[trace(skip)]160		error: Box<jrsonnet_parser::ParseError>,161	},162163	#[error("runtime error: {}", format_empty_str(.0))]164	RuntimeError(IStr),165	#[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]166	StackOverflow,167	#[error("infinite recursion detected")]168	InfiniteRecursionDetected,169	#[error("tried to index by fractional value")]170	FractionalIndex,171	#[error("attempted to divide by zero")]172	DivisionByZero,173174	#[error("string manifest output is not an string")]175	StringManifestOutputIsNotAString,176	#[error("stream manifest output is not an array")]177	StreamManifestOutputIsNotAArray,178	#[error("multi manifest output is not an object")]179	MultiManifestOutputIsNotAObject,180181	#[error("cant recurse stream manifest")]182	StreamManifestOutputCannotBeRecursed,183	#[error("stream manifest output cannot consist of raw strings")]184	StreamManifestCannotNestString,185186	#[error("{}", format_empty_str(.0))]187	ImportCallbackError(String),188	#[error("invalid unicode codepoint: {0}")]189	InvalidUnicodeCodepointGot(u32),190191	#[error("format error: {0}")]192	Format(#[from] FormatError),193	#[error("type error: {0}")]194	TypeError(TypeLocError),195196	#[cfg(feature = "anyhow-error")]197	#[error(transparent)]198	Other(Rc<anyhow::Error>),199}200201#[cfg(feature = "anyhow-error")]202impl From<anyhow::Error> for LocError {203	fn from(e: anyhow::Error) -> Self {204		Self::new(Error::Other(Rc::new(e)))205	}206}207208impl From<Error> for LocError {209	fn from(e: Error) -> Self {210		Self::new(e)211	}212}213214#[derive(Clone, Debug, Trace)]215pub struct StackTraceElement {216	pub location: Option<ExprLocation>,217	pub desc: String,218}219#[derive(Debug, Clone, Trace)]220pub struct StackTrace(pub Vec<StackTraceElement>);221222#[derive(Clone, Trace)]223pub struct LocError(Box<(Error, StackTrace)>);224impl LocError {225	pub fn new(e: Error) -> Self {226		Self(Box::new((e, StackTrace(vec![]))))227	}228229	pub const fn error(&self) -> &Error {230		&(self.0).0231	}232	pub fn error_mut(&mut self) -> &mut Error {233		&mut (self.0).0234	}235	pub const fn trace(&self) -> &StackTrace {236		&(self.0).1237	}238	pub fn trace_mut(&mut self) -> &mut StackTrace {239		&mut (self.0).1240	}241}242impl Debug for LocError {243	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {244		writeln!(f, "{}", self.0 .0)?;245		for el in &self.0 .1 .0 {246			writeln!(f, "\t{:?}", el)?;247		}248		Ok(())249	}250}251252pub type Result<V, E = LocError> = std::result::Result<V, E>;253254#[macro_export]255macro_rules! throw {256	($e: expr) => {257		return Err($e.into())258	};259}260261#[macro_export]262macro_rules! throw_runtime {263	($($tt:tt)*) => {264		return Err($crate::error::Error::RuntimeError(format!($($tt)*).into()).into())265	};266}
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -416,13 +416,13 @@
 		Literal(LiteralType::This) => {
 			Val::Obj(ctx.this().clone().ok_or(CantUseSelfOutsideOfObject)?)
 		}
-		Literal(LiteralType::Super) => {
-			Val::Obj(ctx.super_obj().clone().ok_or(NoSuperFound)?.with_this(
+		Literal(LiteralType::Super) => Val::Obj(
+			ctx.super_obj().clone().ok_or(NoSuperFound)?.with_this(
 				ctx.this()
 					.clone()
 					.expect("if super exists - then this should to"),
-			))
-		}
+			),
+		),
 		Literal(LiteralType::Dollar) => {
 			Val::Obj(ctx.dollar().clone().ok_or(NoTopLevelObjectFound)?)
 		}
@@ -643,10 +643,10 @@
 				Import(_) => s.push(
 					CallLocation::new(loc),
 					|| format!("import {:?}", path.clone()),
-					|| s.import(resolved_path.clone()),
+					|| s.import_resolved(resolved_path),
 				)?,
-				ImportStr(_) => Val::Str(s.import_str(resolved_path)?),
-				ImportBin(_) => Val::Arr(ArrValue::Bytes(s.import_bin(resolved_path)?)),
+				ImportStr(_) => Val::Str(s.import_resolved_str(resolved_path)?),
+				ImportBin(_) => Val::Arr(ArrValue::Bytes(s.import_resolved_bin(resolved_path)?)),
 				_ => unreachable!(),
 			}
 		}
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -6,6 +6,7 @@
 };
 
 use fs::File;
+use jrsonnet_parser::SourcePath;
 
 use crate::{
 	error::{Error::*, Result},
@@ -17,9 +18,12 @@
 	/// Resolves real file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond
 	/// both to `/home/user/manifests/b.libjsonnet` and to `/home/user/${vendor}/b.libjsonnet`
 	/// where `${vendor}` is a library path.
-	fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf>;
+	fn resolve_file_relative(&self, from: &Path, path: &str) -> Result<SourcePath>;
 
-	fn load_file_contents(&self, resolved: &Path) -> Result<Vec<u8>>;
+	/// Load resolved file
+	/// This should only be called with value returned from `resolve_file`, this cannot be resolved using associated type,
+	/// as evaluator uses object instead of generic for [`ImportResolver`]
+	fn load_file_contents(&self, resolved: &SourcePath) -> Result<Vec<u8>>;
 
 	/// # Safety
 	///
@@ -32,11 +36,11 @@
 /// Dummy resolver, can't resolve/load any file
 pub struct DummyImportResolver;
 impl ImportResolver for DummyImportResolver {
-	fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf> {
+	fn resolve_file_relative(&self, from: &Path, path: &str) -> Result<SourcePath> {
 		throw!(ImportNotSupported(from.into(), path.into()))
 	}
 
-	fn load_file_contents(&self, _resolved: &Path) -> Result<Vec<u8>> {
+	fn load_file_contents(&self, _resolved: &SourcePath) -> Result<Vec<u8>> {
 		panic!("dummy resolver can't load any file")
 	}
 
@@ -59,25 +63,35 @@
 	pub library_paths: Vec<PathBuf>,
 }
 impl ImportResolver for FileImportResolver {
-	fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf> {
+	fn resolve_file_relative(&self, from: &Path, path: &str) -> Result<SourcePath> {
 		let mut direct = from.to_path_buf();
 		direct.push(path);
 		if direct.exists() {
-			Ok(direct.canonicalize().map_err(|e| ImportIo(e.to_string()))?)
+			Ok(SourcePath::Path(
+				direct.canonicalize().map_err(|e| ImportIo(e.to_string()))?,
+			))
 		} else {
 			for library_path in &self.library_paths {
 				let mut cloned = library_path.clone();
 				cloned.push(path);
 				if cloned.exists() {
-					return Ok(cloned.canonicalize().map_err(|e| ImportIo(e.to_string()))?);
+					return Ok(SourcePath::Path(
+						cloned.canonicalize().map_err(|e| ImportIo(e.to_string()))?,
+					));
 				}
 			}
 			throw!(ImportFileNotFound(from.to_owned(), path.to_owned()))
 		}
 	}
 
-	fn load_file_contents(&self, id: &Path) -> Result<Vec<u8>> {
-		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.to_owned()))?;
+	fn load_file_contents(&self, id: &SourcePath) -> Result<Vec<u8>> {
+		let path = match id {
+			SourcePath::Path(path) => path,
+			_ => {
+				panic!("this resolver can only resolve to path")
+			}
+		};
+		let mut file = File::open(path).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
 		let mut out = Vec::new();
 		file.read_to_end(&mut out)
 			.map_err(|e| ImportIo(e.to_string()))?;
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -48,7 +48,7 @@
 	cell::{Ref, RefCell, RefMut},
 	collections::HashMap,
 	fmt::{self, Debug},
-	path::{Path, PathBuf},
+	path::Path,
 	rc::Rc,
 };
 
@@ -65,7 +65,7 @@
 pub use jrsonnet_parser as parser;
 use jrsonnet_parser::*;
 pub use obj::*;
-use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};
+use trace::{CompactFormat, TraceFormat};
 pub use val::{ManifestFormat, Thunk, Val};
 
 pub trait Unbound: Trace {
@@ -170,10 +170,7 @@
 	breakpoints: Breakpoints,
 
 	/// Contains file source codes and evaluation results for imports and pretty-printed stacktraces
-	files: GcHashMap<PathBuf, FileData>,
-	/// Contains tla arguments and others, which aren't needed to be obtained by name, however may be used for receiving source
-	/// TODO: look into nix approach, storing source code in `Source` object
-	volatile_files: GcHashMap<String, String>,
+	files: GcHashMap<SourcePath, FileData>,
 }
 struct FileData {
 	string: Option<IStr>,
@@ -249,7 +246,8 @@
 pub struct State(Rc<EvaluationStateInternals>);
 
 impl State {
-	pub fn import_str(&self, path: PathBuf) -> Result<IStr> {
+	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise
+	pub fn import_resolved_str(&self, path: SourcePath) -> Result<IStr> {
 		let mut data = self.data_mut();
 		let mut file = data.files.raw_entry_mut().from_key(&path);
 
@@ -283,7 +281,8 @@
 		}
 		Ok(file.string.as_ref().expect("just set").clone())
 	}
-	pub fn import_bin(&self, path: PathBuf) -> Result<IBytes> {
+	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise
+	pub fn import_resolved_bin(&self, path: SourcePath) -> Result<IBytes> {
 		let mut data = self.data_mut();
 		let mut file = data.files.raw_entry_mut().from_key(&path);
 
@@ -309,7 +308,8 @@
 		}
 		Ok(file.bytes.as_ref().expect("just set").clone())
 	}
-	pub fn import(&self, path: PathBuf) -> Result<Val> {
+	/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise
+	pub fn import_resolved(&self, path: SourcePath) -> Result<Val> {
 		let mut data = self.data_mut();
 		let mut file = data.files.raw_entry_mut().from_key(&path);
 
@@ -343,7 +343,8 @@
 			);
 		}
 		let code = file.string.as_ref().expect("just set");
-		let file_name = Source::new(path.clone()).expect("resolver should return correct name");
+		let file_name =
+			Source::new(path.clone(), code.clone()).expect("resolver should return correct name");
 		if file.parsed.is_none() {
 			file.parsed = Some(
 				jrsonnet_parser::parse(
@@ -354,7 +355,6 @@
 				)
 				.map_err(|e| ImportSyntaxError {
 					path: file_name.clone(),
-					source_code: code.clone(),
 					error: Box::new(e),
 				})?,
 			);
@@ -386,34 +386,11 @@
 				Ok(v)
 			}
 			Err(e) => Err(e),
-		}
-	}
-
-	pub fn get_source(&self, name: Source) -> Option<String> {
-		let data = self.data();
-		match name.repr() {
-			Ok(real) => data
-				.files
-				.get(real)
-				.and_then(|f| f.string.as_ref())
-				.map(ToString::to_string),
-			Err(e) => data.volatile_files.get(e).map(ToOwned::to_owned),
 		}
-	}
-	pub fn map_source_locations(&self, file: Source, locs: &[u32]) -> Vec<CodeLocation> {
-		offset_to_location(&self.get_source(file).unwrap_or_else(|| "".into()), locs)
 	}
-	pub fn map_from_source_location(
-		&self,
-		file: Source,
-		line: usize,
-		column: usize,
-	) -> Option<usize> {
-		location_to_offset(
-			&self.get_source(file).expect("file not found"),
-			line,
-			column,
-		)
+	pub fn import(&self, from: &Path, path: &str) -> Result<Val> {
+		let resolved = self.resolve_file(from, path)?;
+		self.import_resolved(resolved)
 	}
 
 	/// Creates context with all passed global variables
@@ -554,7 +531,10 @@
 				|| {
 					func.evaluate(
 						self.clone(),
-						self.create_default_context(Source::new_virtual(Cow::Borrowed("<tla>"))),
+						self.create_default_context(Source::new_virtual(
+							Cow::Borrowed("<tla>"),
+							IStr::empty(),
+						)),
 						CallLocation::native(),
 						&self.settings().tla_vars,
 						true,
@@ -568,9 +548,9 @@
 
 /// Internals
 impl State {
-	fn data(&self) -> Ref<EvaluationData> {
-		self.0.data.borrow()
-	}
+	// fn data(&self) -> Ref<EvaluationData> {
+	// 	self.0.data.borrow()
+	// }
 	fn data_mut(&self) -> RefMut<EvaluationData> {
 		self.0.data.borrow_mut()
 	}
@@ -585,8 +565,9 @@
 /// Raw methods evaluate passed values but don't perform TLA execution
 impl State {
 	/// Parses and evaluates the given snippet
-	pub fn evaluate_snippet(&self, name: String, code: String) -> Result<Val> {
-		let source = Source::new_virtual(Cow::Owned(name.clone()));
+	pub fn evaluate_snippet(&self, name: String, code: impl Into<IStr>) -> Result<Val> {
+		let code = code.into();
+		let source = Source::new_virtual(Cow::Owned(name), code.clone());
 		let parsed = jrsonnet_parser::parse(
 			&code,
 			&ParserSettings {
@@ -595,10 +576,8 @@
 		)
 		.map_err(|e| ImportSyntaxError {
 			path: source.clone(),
-			source_code: code.clone().into(),
 			error: Box::new(e),
 		})?;
-		self.data_mut().volatile_files.insert(name, code);
 		evaluate(self.clone(), self.create_default_context(source), &parsed)
 	}
 }
@@ -617,7 +596,7 @@
 	}
 	pub fn add_tla_code(&self, name: IStr, code: &str) -> Result<()> {
 		let source_name = format!("<top-level-arg:{}>", name);
-		let source = Source::new_virtual(Cow::Owned(source_name.clone()));
+		let source = Source::new_virtual(Cow::Owned(source_name.clone()), code.into());
 		let parsed = jrsonnet_parser::parse(
 			code,
 			&ParserSettings {
@@ -626,22 +605,18 @@
 		)
 		.map_err(|e| ImportSyntaxError {
 			path: source,
-			source_code: code.into(),
 			error: Box::new(e),
 		})?;
-		self.data_mut()
-			.volatile_files
-			.insert(source_name, code.to_owned());
 		self.settings_mut()
 			.tla_vars
 			.insert(name, TlaArg::Code(parsed));
 		Ok(())
 	}
 
-	pub fn resolve_file(&self, from: &Path, path: &str) -> Result<PathBuf> {
+	pub fn resolve_file(&self, from: &Path, path: &str) -> Result<SourcePath> {
 		self.settings()
 			.import_resolver
-			.resolve_file(from, path.as_ref())
+			.resolve_file_relative(from, path.as_ref())
 	}
 
 	pub fn import_resolver(&self) -> Ref<dyn ImportResolver> {
deletedcrates/jrsonnet-evaluator/src/trace/location.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/location.rs
+++ /dev/null
@@ -1,124 +0,0 @@
-#[allow(clippy::module_name_repetitions)]
-#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct CodeLocation {
-	pub offset: usize,
-
-	pub line: usize,
-	pub column: usize,
-
-	pub line_start_offset: usize,
-	pub line_end_offset: usize,
-}
-
-#[allow(clippy::module_name_repetitions)]
-pub fn location_to_offset(mut file: &str, mut line: usize, column: usize) -> Option<usize> {
-	let mut offset = 0;
-	while line > 1 {
-		let pos = file.find('\n')?;
-		offset += pos + 1;
-		file = &file[pos + 1..];
-		line -= 1;
-	}
-	offset += column - 1;
-	Some(offset)
-}
-
-#[allow(clippy::module_name_repetitions)]
-pub fn offset_to_location(file: &str, offsets: &[u32]) -> Vec<CodeLocation> {
-	if offsets.is_empty() {
-		return vec![];
-	}
-	let mut line = 1;
-	let mut column = 1;
-	let max_offset = *offsets.iter().max().expect("offsets is not empty");
-
-	let mut offset_map = offsets
-		.iter()
-		.enumerate()
-		.map(|(pos, offset)| (*offset, pos))
-		.collect::<Vec<_>>();
-	offset_map.sort_by_key(|v| v.0);
-	offset_map.reverse();
-
-	let mut out = vec![
-		CodeLocation {
-			offset: 0,
-			column: 0,
-			line: 0,
-			line_start_offset: 0,
-			line_end_offset: 0
-		};
-		offsets.len()
-	];
-	let mut with_no_known_line_ending = vec![];
-	let mut this_line_offset = 0;
-	for (pos, ch) in file
-		.chars()
-		.enumerate()
-		.chain(std::iter::once((file.len(), ' ')))
-	{
-		column += 1;
-		match offset_map.last() {
-			Some(x) if x.0 == pos as u32 => {
-				let out_idx = x.1;
-				with_no_known_line_ending.push(out_idx);
-				out[out_idx].offset = pos;
-				out[out_idx].line = line;
-				out[out_idx].column = column;
-				out[out_idx].line_start_offset = this_line_offset;
-				offset_map.pop();
-			}
-			_ => {}
-		}
-		if ch == '\n' {
-			line += 1;
-			column = 1;
-
-			for idx in with_no_known_line_ending.drain(..) {
-				out[idx].line_end_offset = pos;
-			}
-			this_line_offset = pos + 1;
-
-			if pos == max_offset as usize + 1 {
-				break;
-			}
-		}
-	}
-	let file_end = file.chars().count();
-	for idx in with_no_known_line_ending {
-		out[idx].line_end_offset = file_end;
-	}
-
-	out
-}
-
-#[cfg(test)]
-pub mod tests {
-	use super::{offset_to_location, CodeLocation};
-
-	#[test]
-	fn test() {
-		assert_eq!(
-			offset_to_location(
-				"hello world\n_______________________________________________________",
-				&[0, 14]
-			),
-			vec![
-				CodeLocation {
-					offset: 0,
-					line: 1,
-					column: 2,
-					line_start_offset: 0,
-					line_end_offset: 11,
-				},
-				CodeLocation {
-					offset: 14,
-					line: 2,
-					column: 4,
-					line_start_offset: 12,
-					line_end_offset: 67
-				}
-			]
-		)
-	}
-}
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -1,9 +1,6 @@
-mod location;
-
 use std::path::{Path, PathBuf};
 
-use jrsonnet_parser::Source;
-pub use location::*;
+use jrsonnet_parser::{CodeLocation, Source};
 
 use crate::{error::Error, LocError, State};
 
@@ -84,31 +81,27 @@
 	fn write_trace(
 		&self,
 		out: &mut dyn std::fmt::Write,
-		s: &State,
+		_s: &State,
 		error: &LocError,
 	) -> Result<(), std::fmt::Error> {
 		write!(out, "{}", error.error())?;
-		if let Error::ImportSyntaxError {
-			path,
-			source_code,
-			error,
-		} = error.error()
-		{
+		if let Error::ImportSyntaxError { path, error } = error.error() {
 			use std::fmt::Write;
 
 			writeln!(out)?;
-			let mut n = match path.repr() {
-				Ok(r) => self.resolver.resolve(r),
-				Err(v) => v.to_string(),
+			let mut n = match path.path() {
+				Some(r) => self.resolver.resolve(r),
+				None => path.short_display().to_string(),
 			};
 			let mut offset = error.location.offset;
-			let is_eof = if offset >= source_code.len() {
-				offset = source_code.len().saturating_sub(1);
+			let is_eof = if offset >= path.code().len() {
+				offset = path.code().len().saturating_sub(1);
 				true
 			} else {
 				false
 			};
-			let mut location = offset_to_location(source_code, &[offset as u32])
+			let mut location = path
+				.map_source_locations(&[offset as u32])
 				.into_iter()
 				.next()
 				.unwrap();
@@ -129,13 +122,12 @@
 				use std::fmt::Write;
 				#[allow(clippy::option_if_let_else)]
 				if let Some(location) = location {
-					let mut resolved_path = match location.0.repr() {
-						Ok(r) => self.resolver.resolve(r),
-						Err(v) => v.to_string(),
+					let mut resolved_path = match location.0.path() {
+						Some(r) => self.resolver.resolve(r),
+						None => location.0.short_display().to_string(),
 					};
 					// TODO: Process all trace elements first
-					let location =
-						s.map_source_locations(location.0.clone(), &[location.1, location.2]);
+					let location = location.0.map_source_locations(&[location.1, location.2]);
 					write!(resolved_path, ":").unwrap();
 					print_code_location(&mut resolved_path, &location[0], &location[1]).unwrap();
 					write!(resolved_path, ":").unwrap();
@@ -176,7 +168,7 @@
 	fn write_trace(
 		&self,
 		out: &mut dyn std::fmt::Write,
-		s: &State,
+		_s: &State,
 		error: &LocError,
 	) -> Result<(), std::fmt::Error> {
 		write!(out, "{}", error.error())?;
@@ -184,10 +176,10 @@
 			writeln!(out)?;
 			let desc = &item.desc;
 			if let Some(source) = &item.location {
-				let start_end = s.map_source_locations(source.0.clone(), &[source.1, source.2]);
-				let resolved_path = match source.0.repr() {
-					Ok(r) => r.display().to_string(),
-					Err(v) => v.to_string(),
+				let start_end = source.0.map_source_locations(&[source.1, source.2]);
+				let resolved_path = match source.0.path() {
+					Some(r) => r.display().to_string(),
+					None => source.0.short_display().to_string(),
 				};
 
 				write!(
@@ -213,19 +205,15 @@
 	fn write_trace(
 		&self,
 		out: &mut dyn std::fmt::Write,
-		s: &State,
+		_s: &State,
 		error: &LocError,
 	) -> Result<(), std::fmt::Error> {
 		write!(out, "{}", error.error())?;
-		if let Error::ImportSyntaxError {
-			path,
-			source_code,
-			error,
-		} = error.error()
-		{
+		if let Error::ImportSyntaxError { path, error } = error.error() {
 			writeln!(out)?;
 			let offset = error.location.offset;
-			let location = offset_to_location(source_code, &[offset as u32])
+			let location = path
+				.map_source_locations(&[offset as u32])
 				.into_iter()
 				.next()
 				.unwrap();
@@ -234,7 +222,7 @@
 
 			self.print_snippet(
 				out,
-				source_code,
+				path.code(),
 				path,
 				&location,
 				&end_location,
@@ -246,10 +234,10 @@
 			writeln!(out)?;
 			let desc = &item.desc;
 			if let Some(source) = &item.location {
-				let start_end = s.map_source_locations(source.0.clone(), &[source.1, source.2]);
+				let start_end = source.0.map_source_locations(&[source.1, source.2]);
 				self.print_snippet(
 					out,
-					&s.get_source(source.0.clone()).unwrap(),
+					&source.0.code(),
 					&source.0,
 					&start_end[0],
 					&start_end[1],
@@ -284,9 +272,9 @@
 			.take(end.line_end_offset - end.line_start_offset)
 			.collect();
 
-		let origin = match origin.repr() {
-			Ok(r) => self.resolver.resolve(r),
-			Err(v) => v.to_string(),
+		let origin = match origin.path() {
+			Some(r) => self.resolver.resolve(r),
+			None => origin.short_display().to_string(),
 		};
 		let snippet = Snippet {
 			opt: FormatOptions {
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -33,6 +33,10 @@
 
 impl IStr {
 	#[must_use]
+	pub fn empty() -> Self {
+		"".into()
+	}
+	#[must_use]
 	pub fn as_str(&self) -> &str {
 		self as &str
 	}
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -7,9 +7,11 @@
 pub use expr::*;
 pub use jrsonnet_interner::IStr;
 pub use peg;
+mod location;
 mod source;
 mod unescape;
-pub use source::Source;
+pub use location::CodeLocation;
+pub use source::{Source, SourcePath};
 
 pub struct ParserSettings {
 	pub file_name: Source,
addedcrates/jrsonnet-parser/src/location.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-parser/src/location.rs
@@ -0,0 +1,124 @@
+#[allow(clippy::module_name_repetitions)]
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct CodeLocation {
+	pub offset: usize,
+
+	pub line: usize,
+	pub column: usize,
+
+	pub line_start_offset: usize,
+	pub line_end_offset: usize,
+}
+
+#[allow(clippy::module_name_repetitions)]
+pub fn location_to_offset(mut file: &str, mut line: usize, column: usize) -> Option<usize> {
+	let mut offset = 0;
+	while line > 1 {
+		let pos = file.find('\n')?;
+		offset += pos + 1;
+		file = &file[pos + 1..];
+		line -= 1;
+	}
+	offset += column - 1;
+	Some(offset)
+}
+
+#[allow(clippy::module_name_repetitions)]
+pub fn offset_to_location(file: &str, offsets: &[u32]) -> Vec<CodeLocation> {
+	if offsets.is_empty() {
+		return vec![];
+	}
+	let mut line = 1;
+	let mut column = 1;
+	let max_offset = *offsets.iter().max().expect("offsets is not empty");
+
+	let mut offset_map = offsets
+		.iter()
+		.enumerate()
+		.map(|(pos, offset)| (*offset, pos))
+		.collect::<Vec<_>>();
+	offset_map.sort_by_key(|v| v.0);
+	offset_map.reverse();
+
+	let mut out = vec![
+		CodeLocation {
+			offset: 0,
+			column: 0,
+			line: 0,
+			line_start_offset: 0,
+			line_end_offset: 0
+		};
+		offsets.len()
+	];
+	let mut with_no_known_line_ending = vec![];
+	let mut this_line_offset = 0;
+	for (pos, ch) in file
+		.chars()
+		.enumerate()
+		.chain(std::iter::once((file.len(), ' ')))
+	{
+		column += 1;
+		match offset_map.last() {
+			Some(x) if x.0 == pos as u32 => {
+				let out_idx = x.1;
+				with_no_known_line_ending.push(out_idx);
+				out[out_idx].offset = pos;
+				out[out_idx].line = line;
+				out[out_idx].column = column;
+				out[out_idx].line_start_offset = this_line_offset;
+				offset_map.pop();
+			}
+			_ => {}
+		}
+		if ch == '\n' {
+			line += 1;
+			column = 1;
+
+			for idx in with_no_known_line_ending.drain(..) {
+				out[idx].line_end_offset = pos;
+			}
+			this_line_offset = pos + 1;
+
+			if pos == max_offset as usize + 1 {
+				break;
+			}
+		}
+	}
+	let file_end = file.chars().count();
+	for idx in with_no_known_line_ending {
+		out[idx].line_end_offset = file_end;
+	}
+
+	out
+}
+
+#[cfg(test)]
+pub mod tests {
+	use super::{offset_to_location, CodeLocation};
+
+	#[test]
+	fn test() {
+		assert_eq!(
+			offset_to_location(
+				"hello world\n_______________________________________________________",
+				&[0, 14]
+			),
+			vec![
+				CodeLocation {
+					offset: 0,
+					line: 1,
+					column: 2,
+					line_start_offset: 0,
+					line_end_offset: 11,
+				},
+				CodeLocation {
+					offset: 14,
+					line: 2,
+					column: 4,
+					line_start_offset: 12,
+					line_end_offset: 67
+				}
+			]
+		)
+	}
+}
modifiedcrates/jrsonnet-parser/src/source.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/source.rs
+++ b/crates/jrsonnet-parser/src/source.rs
@@ -6,21 +6,42 @@
 };
 
 use jrsonnet_gcmodule::{Trace, Tracer};
+use jrsonnet_interner::IStr;
 #[cfg(feature = "serde")]
 use serde::{Deserialize, Serialize};
 
+use crate::location::{location_to_offset, offset_to_location, CodeLocation};
+
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(PartialEq, Eq, Debug, Hash)]
-enum Inner {
-	Real(PathBuf),
+#[derive(PartialEq, Eq, Debug, Hash, Clone)]
+pub enum SourcePath {
+	/// This file is located on disk
+	Path(PathBuf),
+	/// This file is located somewhere else (I.e http), but it can refer to relative paths, and is egilible for caching
+	Custom(String),
+	/// This file is only located in memory, and can't be cached
 	Virtual(Cow<'static, str>),
 }
+impl Trace for SourcePath {
+	fn trace(&self, _tracer: &mut Tracer) {}
 
+	fn is_type_tracked() -> bool {
+		false
+	}
+}
+
+impl SourcePath {
+	/// Should import resolver be able to read file by this path?
+	pub fn can_load(&self) -> bool {
+		matches!(self, Self::Path(_) | Self::Custom(_))
+	}
+}
+
 /// Either real file, or virtual
 /// Hash of FileName always have same value as raw Path, to make it possible to use with raw_entry_mut
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Source(Rc<Inner>);
+pub struct Source(Rc<(SourcePath, IStr)>);
 static_assertions::assert_eq_size!(Source, *const ());
 
 impl Trace for Source {
@@ -33,55 +54,63 @@
 
 impl Source {
 	/// Fails when path contains inner /../ or /./ references, or not absolute
-	pub fn new(path: PathBuf) -> Option<Self> {
-		if !path.is_absolute()
-			|| path
-				.components()
-				.any(|c| matches!(c, Component::CurDir | Component::ParentDir))
-		{
-			return None;
+	pub fn new(path: SourcePath, code: IStr) -> Option<Self> {
+		if let SourcePath::Path(path) = &path {
+			if !path.is_absolute()
+				|| path
+					.components()
+					.any(|c| matches!(c, Component::CurDir | Component::ParentDir))
+			{
+				return None;
+			}
 		}
-		Some(Self(Rc::new(Inner::Real(path))))
+		Some(Self(Rc::new((path, code))))
 	}
 
-	pub fn new_virtual(n: Cow<'static, str>) -> Self {
-		Self(Rc::new(Inner::Virtual(n)))
+	pub fn new_virtual(n: Cow<'static, str>, code: IStr) -> Self {
+		Self(Rc::new((SourcePath::Virtual(n), code)))
 	}
 
 	pub fn short_display(&self) -> ShortDisplay {
 		ShortDisplay(self.clone())
 	}
 
-	/// Returns None if file is virtual
+	/// Returns Some if this file is loaded from FS
 	pub fn path(&self) -> Option<&Path> {
-		match self.inner() {
-			Inner::Real(r) => Some(r),
-			Inner::Virtual(_) => None,
+		match self.source_path() {
+			SourcePath::Path(r) => Some(r),
+			SourcePath::Custom(_) => None,
+			SourcePath::Virtual(_) => None,
 		}
 	}
-	pub fn repr(&self) -> Result<&Path, &str> {
-		match self.inner() {
-			Inner::Real(r) => Ok(r),
-			Inner::Virtual(v) => Err(v.as_ref()),
-		}
+	pub fn code(&self) -> &str {
+		&self.0 .1
+	}
+
+	pub fn source_path(&self) -> &SourcePath {
+		&self.0 .0 as &SourcePath
 	}
 
-	fn inner(&self) -> &Inner {
-		&self.0 as &Inner
+	pub fn map_source_locations(&self, locs: &[u32]) -> Vec<CodeLocation> {
+		offset_to_location(&self.0 .1, locs)
+	}
+	pub fn map_from_source_location(&self, line: usize, column: usize) -> Option<usize> {
+		location_to_offset(&self.0 .1, line, column)
 	}
 }
 pub struct ShortDisplay(Source);
 impl fmt::Display for ShortDisplay {
 	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-		match &self.0 .0 as &Inner {
-			Inner::Real(r) => {
+		match &self.0 .0 .0 as &SourcePath {
+			SourcePath::Path(r) => {
 				write!(
 					f,
 					"{}",
 					r.file_name().expect("path is valid").to_string_lossy()
 				)
 			}
-			Inner::Virtual(n) => write!(f, "{}", n),
+			SourcePath::Custom(r) => write!(f, "{}", r),
+			SourcePath::Virtual(n) => write!(f, "{}", n),
 		}
 	}
 }
modifiedcrates/jrsonnet-stdlib/build.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/build.rs
+++ b/crates/jrsonnet-stdlib/build.rs
@@ -7,7 +7,10 @@
 	let parsed = parse(
 		include_str!("./src/std.jsonnet"),
 		&ParserSettings {
-			file_name: Source::new_virtual(Cow::Borrowed("<std>")),
+			file_name: Source::new_virtual(
+				Cow::Borrowed("<std>"),
+				include_str!("./src/std.jsonnet").into(),
+			),
 		},
 	)
 	.expect("parse");
modifiedcrates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/expr.rs
+++ b/crates/jrsonnet-stdlib/src/expr.rs
@@ -15,7 +15,7 @@
 	jrsonnet_parser::parse(
 		STDLIB_STR,
 		&ParserSettings {
-			file_name: Source::new_virtual(Cow::Borrowed("<std>")),
+			file_name: Source::new_virtual(Cow::Borrowed("<std>"), STDLIB_STR.into()),
 		},
 	)
 	.unwrap()
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -183,10 +183,10 @@
 
 pub struct StdTracePrinter;
 impl TracePrinter for StdTracePrinter {
-	fn print_trace(&self, s: State, loc: CallLocation, value: IStr) {
+	fn print_trace(&self, _s: State, loc: CallLocation, value: IStr) {
 		eprint!("TRACE:");
 		if let Some(loc) = loc.0 {
-			let locs = s.map_source_locations(loc.0.clone(), &[loc.1]);
+			let locs = loc.0.map_source_locations(&[loc.1]);
 			eprint!(" {}:{}", loc.0.short_display(), locs[0].line);
 		}
 		eprintln!(" {}", value);
@@ -212,9 +212,9 @@
 	}
 }
 
-pub fn extvar_source(name: &str) -> Source {
+pub fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {
 	let source_name = format!("<extvar:{}>", name);
-	Source::new_virtual(Cow::Owned(source_name))
+	Source::new_virtual(Cow::Owned(source_name), code.into())
 }
 
 pub struct ContextInitializer {
@@ -260,8 +260,9 @@
 			.ext_vars
 			.insert(name, TlaArg::String(value));
 	}
-	pub fn add_ext_code(&self, name: &str, code: String) -> Result<()> {
-		let source = extvar_source(name);
+	pub fn add_ext_code(&self, name: &str, code: impl Into<IStr>) -> Result<()> {
+		let code = code.into();
+		let source = extvar_source(name, code.clone());
 		let parsed = jrsonnet_parser::parse(
 			&code,
 			&jrsonnet_parser::ParserSettings {
@@ -270,7 +271,6 @@
 		)
 		.map_err(|e| ImportSyntaxError {
 			path: source,
-			source_code: code.clone().into(),
 			error: Box::new(e),
 		})?;
 		// self.data_mut().volatile_files.insert(source_name, code);
@@ -297,11 +297,13 @@
 			.hide()
 			.value(
 				s,
-				Val::Str(match source.repr() {
-					Ok(p) => p.display().to_string().into(),
-					// Virtual files end up as empty strings in std.thisFile
-					Err(_e) => "".into(),
-				}),
+				Val::Str(
+					source
+						.path()
+						.map(|p| p.display().to_string())
+						.unwrap_or_else(String::new)
+						.into(),
+				),
 			)
 			.expect("this object builder is empty");
 		let stdlib_with_this_file = builder.build();
@@ -343,7 +345,7 @@
 	settings: Rc<RefCell<Settings>>,
 ))]
 fn builtin_ext_var(this: &builtin_ext_var, s: State, x: IStr) -> Result<Any> {
-	let ctx = s.create_default_context(extvar_source(&x));
+	let ctx = s.create_default_context(extvar_source(&x, ""));
 	Ok(Any(this
 		.settings
 		.borrow()