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

difftreelog

Merge branch 'master' into gc-v2

Yaroslav Bolyukin2021-06-14parents: #a501dd9 #ff2926d.patch.diff
in: master

17 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -242,7 +242,6 @@
 dependencies = [
  "gc",
  "jrsonnet-evaluator",
- "jrsonnet-interner",
  "jrsonnet-parser",
 ]
 
modifiedbindings/jsonnet/Cargo.tomldiffbeforeafterboth
--- a/bindings/jsonnet/Cargo.toml
+++ b/bindings/jsonnet/Cargo.toml
@@ -8,7 +8,6 @@
 publish = false
 
 [dependencies]
-jrsonnet-interner = { path = "../../crates/jrsonnet-interner", version = "0.3.8" }
 jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.3.8" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.3.8" }
 gc = { version = "0.4.1", features = ["derive"] }
modifiedbindings/jsonnet/src/import.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -2,9 +2,8 @@
 
 use jrsonnet_evaluator::{
 	error::{Error::*, Result},
-	throw, EvaluationState, ImportResolver,
+	throw, EvaluationState, IStr, ImportResolver,
 };
-use jrsonnet_interner::IStr;
 use std::{
 	any::Any,
 	cell::RefCell,
@@ -13,7 +12,7 @@
 	fs::File,
 	io::Read,
 	os::raw::{c_char, c_int},
-	path::PathBuf,
+	path::{Path, PathBuf},
 	ptr::null_mut,
 	rc::Rc,
 };
@@ -34,7 +33,7 @@
 	out: RefCell<HashMap<PathBuf, IStr>>,
 }
 impl ImportResolver for CallbackImportResolver {
-	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
 		let base = CString::new(from.to_str().unwrap()).unwrap().into_raw();
 		let rel = CString::new(path.to_str().unwrap()).unwrap().into_raw();
 		let found_here: *mut c_char = null_mut();
@@ -74,9 +73,9 @@
 			unsafe { CString::from_raw(result_ptr) };
 		}
 
-		Ok(Rc::new(found_here_buf))
+		Ok(found_here_buf.into())
 	}
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr> {
+	fn load_file_contents(&self, resolved: &Path) -> Result<IStr> {
 		Ok(self.out.borrow().get(resolved).unwrap().clone())
 	}
 	unsafe fn as_any(&self) -> &dyn Any {
@@ -109,27 +108,27 @@
 	}
 }
 impl ImportResolver for NativeImportResolver {
-	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
-		let mut new_path = from.clone();
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
+		let mut new_path = from.to_owned();
 		new_path.push(path);
 		if new_path.exists() {
-			Ok(Rc::new(new_path))
+			Ok(new_path.into())
 		} else {
 			for library_path in self.library_paths.borrow().iter() {
 				let mut cloned = library_path.clone();
 				cloned.push(path);
 				if cloned.exists() {
-					return Ok(Rc::new(cloned));
+					return Ok(cloned.into());
 				}
 			}
-			throw!(ImportFileNotFound(from.clone(), path.clone()))
+			throw!(ImportFileNotFound(from.to_owned(), path.to_owned()))
 		}
 	}
-	fn load_file_contents(&self, id: &PathBuf) -> Result<IStr> {
-		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
+	fn load_file_contents(&self, id: &Path) -> Result<IStr> {
+		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.to_owned()))?;
 		let mut out = String::new();
 		file.read_to_string(&mut out)
-			.map_err(|_e| ImportBadFileUtf8(id.clone()))?;
+			.map_err(|_e| ImportBadFileUtf8(id.to_owned()))?;
 		Ok(out.into())
 	}
 	unsafe fn as_any(&self) -> &dyn Any {
modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -9,14 +9,12 @@
 pub mod vars_tlas;
 
 use import::NativeImportResolver;
-use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Val};
-use jrsonnet_interner::IStr;
+use jrsonnet_evaluator::{EvaluationState, IStr, ManifestFormat, Val};
 use std::{
 	alloc::Layout,
 	ffi::{CStr, CString},
 	os::raw::{c_char, c_double, c_int, c_uint},
 	path::PathBuf,
-	rc::Rc,
 };
 
 /// WASM stub
@@ -145,7 +143,7 @@
 		let snippet = CStr::from_ptr(snippet);
 		match vm
 			.evaluate_snippet_raw(
-				Rc::new(PathBuf::from(filename.to_str().unwrap())),
+				PathBuf::from(filename.to_str().unwrap()).into(),
 				snippet.to_str().unwrap().into(),
 			)
 			.and_then(|v| vm.with_tla(v))
@@ -221,7 +219,7 @@
 		let snippet = CStr::from_ptr(snippet);
 		match vm
 			.evaluate_snippet_raw(
-				Rc::new(PathBuf::from(filename.to_str().unwrap())),
+				PathBuf::from(filename.to_str().unwrap()).into(),
 				snippet.to_str().unwrap().into(),
 			)
 			.and_then(|v| vm.with_tla(v))
@@ -295,7 +293,7 @@
 		let snippet = CStr::from_ptr(snippet);
 		match vm
 			.evaluate_snippet_raw(
-				Rc::new(PathBuf::from(filename.to_str().unwrap())),
+				PathBuf::from(filename.to_str().unwrap()).into(),
 				snippet.to_str().unwrap().into(),
 			)
 			.and_then(|v| vm.with_tla(v))
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -8,7 +8,7 @@
 use std::{
 	ffi::{c_void, CStr},
 	os::raw::{c_char, c_int},
-	path::PathBuf,
+	path::Path,
 	rc::Rc,
 };
 
@@ -27,7 +27,7 @@
 	unsafe_empty_trace!();
 }
 impl NativeCallbackHandler for JsonnetNativeCallbackHandler {
-	fn call(&self, _from: Option<Rc<PathBuf>>, args: &[Val]) -> Result<Val, LocError> {
+	fn call(&self, _from: Option<Rc<Path>>, args: &[Val]) -> Result<Val, LocError> {
 		let mut n_args = Vec::new();
 		for a in args {
 			n_args.push(Some(Box::new(a.clone())));
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -6,7 +6,6 @@
 	io::Read,
 	io::Write,
 	path::PathBuf,
-	rc::Rc,
 	str::FromStr,
 };
 
@@ -134,14 +133,14 @@
 	let val = if opts.input.exec {
 		state.set_manifest_format(ManifestFormat::ToString);
 		state.evaluate_snippet_raw(
-			Rc::new(PathBuf::from("args")),
+			PathBuf::from("args").into(),
 			(&opts.input.input as &str).into(),
 		)?
 	} else if opts.input.input == "-" {
 		let mut input = Vec::new();
 		std::io::stdin().read_to_end(&mut input)?;
 		let input_str = std::str::from_utf8(&input)?.into();
-		state.evaluate_snippet_raw(Rc::new(PathBuf::from("<stdin>")), input_str)?
+		state.evaluate_snippet_raw(PathBuf::from("<stdin>").into(), input_str)?
 	} else {
 		state.evaluate_file_raw(&PathBuf::from(opts.input.input))?
 	};
modifiedcrates/jrsonnet-evaluator/build.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/build.rs
+++ b/crates/jrsonnet-evaluator/build.rs
@@ -15,7 +15,7 @@
 	let parsed = parse(
 		STDLIB_STR,
 		&ParserSettings {
-			file_name: Rc::new(PathBuf::from("std.jsonnet")),
+			file_name: PathBuf::from("std.jsonnet").into(),
 			loc_data: true,
 		},
 	)
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -177,7 +177,7 @@
 		0, s: ty!(string) => Val::Str;
 	], {
 		let state = EvaluationState::default();
-		let path = Rc::new(PathBuf::from("std.parseJson"));
+		let path = PathBuf::from("std.parseJson").into();
 		state.evaluate_snippet_raw(path ,s)
 	})
 }
modifiedcrates/jrsonnet-evaluator/src/builtin/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
@@ -1,5 +1,5 @@
 use jrsonnet_parser::{LocExpr, ParserSettings};
-use std::{path::PathBuf, rc::Rc};
+use std::path::PathBuf;
 
 thread_local! {
 	/// To avoid parsing again when issued from the same thread
@@ -25,7 +25,7 @@
 			jrsonnet_stdlib::STDLIB_STR,
 			&ParserSettings {
 				loc_data: true,
-				file_name: Rc::new(PathBuf::from("std.jsonnet")),
+				file_name: PathBuf::from("std.jsonnet").into(),
 			},
 		)
 		.unwrap()
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -6,7 +6,10 @@
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
 use jrsonnet_types::ValType;
-use std::{path::PathBuf, rc::Rc};
+use std::{
+	path::{Path, PathBuf},
+	rc::Rc,
+};
 use thiserror::Error;
 
 #[derive(Error, Debug, Clone, Trace, Finalize)]
@@ -87,7 +90,7 @@
 		.source_code.chars().nth(error.location.offset).map(|c| c.to_string()).unwrap_or_else(|| "EOF".into())
 	)]
 	ImportSyntaxError {
-		path: Rc<PathBuf>,
+		path: Rc<Path>,
 		source_code: IStr,
 		#[unsafe_ignore_trace]
 		error: Box<jrsonnet_parser::ParseError>,
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -12,7 +12,7 @@
 };
 use jrsonnet_types::ValType;
 use rustc_hash::{FxHashMap, FxHasher};
-use std::{collections::HashMap, hash::BuildHasherDefault, rc::Rc};
+use std::{collections::HashMap, hash::BuildHasherDefault};
 
 pub fn evaluate_binding_in_future(
 	b: &BindSpec,
@@ -843,26 +843,26 @@
 			}
 		}
 		Import(path) => {
-			let mut tmp = loc
+			let tmp = loc
 				.clone()
 				.expect("imports cannot be used without loc_data")
 				.0;
-			let import_location = Rc::make_mut(&mut tmp);
+			let mut import_location = tmp.to_path_buf();
 			import_location.pop();
 			push(
 				loc.as_ref(),
 				|| format!("import {:?}", path),
-				|| with_state(|s| s.import_file(import_location, path)),
+				|| with_state(|s| s.import_file(&import_location, path)),
 			)?
 		}
 		ImportStr(path) => {
-			let mut tmp = loc
+			let tmp = loc
 				.clone()
 				.expect("imports cannot be used without loc_data")
 				.0;
-			let import_location = Rc::make_mut(&mut tmp);
+			let mut import_location = tmp.to_path_buf();
 			import_location.pop();
-			Val::Str(with_state(|s| s.import_file_str(import_location, path))?)
+			Val::Str(with_state(|s| s.import_file_str(&import_location, path))?)
 		}
 	})
 }
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -6,17 +6,23 @@
 use jrsonnet_interner::IStr;
 use std::fs;
 use std::io::Read;
-use std::{any::Any, cell::RefCell, collections::HashMap, path::PathBuf, rc::Rc};
+use std::{
+	any::Any,
+	cell::RefCell,
+	collections::HashMap,
+	path::{Path, PathBuf},
+	rc::Rc,
+};
 
 /// Implements file resolution logic for `import` and `importStr`
 pub trait ImportResolver {
 	/// 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: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>>;
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>>;
 
 	/// Reads file from filesystem, should be used only with path received from `resolve_file`
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr>;
+	fn load_file_contents(&self, resolved: &Path) -> Result<IStr>;
 
 	/// # Safety
 	///
@@ -29,11 +35,11 @@
 /// Dummy resolver, can't resolve/load any file
 pub struct DummyImportResolver;
 impl ImportResolver for DummyImportResolver {
-	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
-		throw!(ImportNotSupported(from.clone(), path.clone()))
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
+		throw!(ImportNotSupported(from.into(), path.into()))
 	}
 
-	fn load_file_contents(&self, _resolved: &PathBuf) -> Result<IStr> {
+	fn load_file_contents(&self, _resolved: &Path) -> Result<IStr> {
 		// Can be only caused by library direct consumer, not by supplied jsonnet
 		panic!("dummy resolver can't load any file")
 	}
@@ -57,27 +63,27 @@
 	pub library_paths: Vec<PathBuf>,
 }
 impl ImportResolver for FileImportResolver {
-	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
-		let mut new_path = from.clone();
-		new_path.push(path);
-		if new_path.exists() {
-			Ok(Rc::new(new_path))
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
+		let mut direct = from.to_path_buf();
+		direct.push(path);
+		if direct.exists() {
+			Ok(direct.into())
 		} else {
 			for library_path in self.library_paths.iter() {
 				let mut cloned = library_path.clone();
 				cloned.push(path);
 				if cloned.exists() {
-					return Ok(Rc::new(cloned));
+					return Ok(cloned.into());
 				}
 			}
-			throw!(ImportFileNotFound(from.clone(), path.clone()))
+			throw!(ImportFileNotFound(from.to_owned(), path.to_owned()))
 		}
 	}
-	fn load_file_contents(&self, id: &PathBuf) -> Result<IStr> {
-		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.clone()))?;
+	fn load_file_contents(&self, id: &Path) -> Result<IStr> {
+		let mut file = File::open(id).map_err(|_e| ResolvedFileNotFound(id.to_owned()))?;
 		let mut out = String::new();
 		file.read_to_string(&mut out)
-			.map_err(|_e| ImportBadFileUtf8(id.clone()))?;
+			.map_err(|_e| ImportBadFileUtf8(id.to_owned()))?;
 		Ok(out.into())
 	}
 	unsafe fn as_any(&self) -> &dyn Any {
@@ -89,23 +95,23 @@
 
 /// Caches results of the underlying resolver
 pub struct CachingImportResolver {
-	resolution_cache: RefCell<HashMap<ResolutionData, Result<Rc<PathBuf>>>>,
+	resolution_cache: RefCell<HashMap<ResolutionData, Result<Rc<Path>>>>,
 	loading_cache: RefCell<HashMap<PathBuf, Result<IStr>>>,
 	inner: Box<dyn ImportResolver>,
 }
 impl ImportResolver for CachingImportResolver {
-	fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
+	fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
 		self.resolution_cache
 			.borrow_mut()
-			.entry((from.clone(), path.clone()))
+			.entry((from.to_owned(), path.to_owned()))
 			.or_insert_with(|| self.inner.resolve_file(from, path))
 			.clone()
 	}
 
-	fn load_file_contents(&self, resolved: &PathBuf) -> Result<IStr> {
+	fn load_file_contents(&self, resolved: &Path) -> Result<IStr> {
 		self.loading_cache
 			.borrow_mut()
-			.entry(resolved.clone())
+			.entry(resolved.to_owned())
 			.or_insert_with(|| self.inner.load_file_contents(resolved))
 			.clone()
 	}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -27,7 +27,7 @@
 pub use function::parse_function_call;
 use gc::{Finalize, Gc, Trace};
 pub use import::*;
-use jrsonnet_interner::IStr;
+pub use jrsonnet_interner::IStr;
 use jrsonnet_parser::*;
 use native::NativeCallback;
 pub use obj::*;
@@ -37,7 +37,7 @@
 	collections::HashMap,
 	fmt::Debug,
 	hash::BuildHasherDefault,
-	path::PathBuf,
+	path::{Path, PathBuf},
 	rc::Rc,
 };
 use trace::{offset_to_location, CodeLocation, CompactFormat, TraceFormat};
@@ -110,8 +110,8 @@
 	/// Used for stack overflow detection, stacktrace is populated on unwind
 	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>, IStr>,
+	files: HashMap<Rc<Path>, FileData>,
+	str_files: HashMap<Rc<Path>, IStr>,
 }
 
 pub struct FileData {
@@ -157,7 +157,7 @@
 
 impl EvaluationState {
 	/// Parses and adds file as loaded
-	pub fn add_file(&self, path: Rc<PathBuf>, source_code: IStr) -> Result<()> {
+	pub fn add_file(&self, path: Rc<Path>, source_code: IStr) -> Result<()> {
 		self.add_parsed_file(
 			path.clone(),
 			source_code.clone(),
@@ -170,7 +170,7 @@
 			)
 			.map_err(|error| ImportSyntaxError {
 				error: Box::new(error),
-				path,
+				path: path.to_owned(),
 				source_code,
 			})?,
 		)?;
@@ -181,7 +181,7 @@
 	/// Adds file by source code and parsed expr
 	pub fn add_parsed_file(
 		&self,
-		name: Rc<PathBuf>,
+		name: Rc<Path>,
 		source_code: IStr,
 		parsed: LocExpr,
 	) -> Result<()> {
@@ -196,20 +196,20 @@
 
 		Ok(())
 	}
-	pub fn get_source(&self, name: &PathBuf) -> Option<IStr> {
+	pub fn get_source(&self, name: &Path) -> Option<IStr> {
 		let ro_map = &self.data().files;
 		ro_map.get(name).map(|value| value.source_code.clone())
 	}
-	pub fn map_source_locations(&self, file: &PathBuf, locs: &[usize]) -> Vec<CodeLocation> {
+	pub fn map_source_locations(&self, file: &Path, locs: &[usize]) -> Vec<CodeLocation> {
 		offset_to_location(&self.get_source(file).unwrap(), locs)
 	}
 
-	pub(crate) fn import_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Val> {
+	pub(crate) fn import_file(&self, from: &Path, path: &Path) -> Result<Val> {
 		let file_path = self.resolve_file(from, path)?;
 		{
 			let data = self.data();
 			let files = &data.files;
-			if files.contains_key(&file_path) {
+			if files.contains_key(&file_path as &Path) {
 				drop(data);
 				return self.evaluate_loaded_file_raw(&file_path);
 			}
@@ -218,7 +218,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<IStr> {
+	pub(crate) fn import_file_str(&self, from: &Path, path: &Path) -> 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)?;
@@ -227,7 +227,7 @@
 		Ok(self.data().str_files.get(&path).cloned().unwrap())
 	}
 
-	fn evaluate_loaded_file_raw(&self, name: &PathBuf) -> Result<Val> {
+	fn evaluate_loaded_file_raw(&self, name: &Path) -> Result<Val> {
 		let expr: LocExpr = {
 			let ro_map = &self.data().files;
 			let value = ro_map
@@ -253,7 +253,7 @@
 	/// Adds standard library global variable (std) to this evaluator
 	pub fn with_stdlib(&self) -> &Self {
 		use jrsonnet_stdlib::STDLIB_STR;
-		let std_path = Rc::new(PathBuf::from("std.jsonnet"));
+		let std_path: Rc<Path> = PathBuf::from("std.jsonnet").into();
 		self.run_in_state(|| {
 			self.add_parsed_file(
 				std_path.clone(),
@@ -381,14 +381,14 @@
 
 /// Raw methods evaluate passed values but don't perform TLA execution
 impl EvaluationState {
-	pub fn evaluate_file_raw(&self, name: &PathBuf) -> Result<Val> {
+	pub fn evaluate_file_raw(&self, name: &Path) -> Result<Val> {
 		self.run_in_state(|| self.import_file(&std::env::current_dir().expect("cwd"), name))
 	}
-	pub fn evaluate_file_raw_nocwd(&self, name: &PathBuf) -> Result<Val> {
+	pub fn evaluate_file_raw_nocwd(&self, name: &Path) -> Result<Val> {
 		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: IStr) -> Result<Val> {
+	pub fn evaluate_snippet_raw(&self, source: Rc<Path>, code: IStr) -> Result<Val> {
 		let parsed = parse(
 			&code,
 			&ParserSettings {
@@ -420,7 +420,7 @@
 	}
 	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.evaluate_snippet_raw(PathBuf::from(format!("ext_code {}", name)).into(), code)?;
 		self.add_ext_var(name, value);
 		Ok(())
 	}
@@ -433,15 +433,15 @@
 	}
 	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.evaluate_snippet_raw(PathBuf::from(format!("tla_code {}", name)).into(), code)?;
 		self.add_tla(name, value);
 		Ok(())
 	}
 
-	pub fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
+	pub fn resolve_file(&self, from: &Path, path: &Path) -> Result<Rc<Path>> {
 		self.settings().import_resolver.resolve_file(from, path)
 	}
-	pub fn load_file_contents(&self, path: &PathBuf) -> Result<IStr> {
+	pub fn load_file_contents(&self, path: &Path) -> Result<IStr> {
 		self.settings().import_resolver.load_file_contents(path)
 	}
 
@@ -494,7 +494,10 @@
 	use gc::Gc;
 	use jrsonnet_interner::IStr;
 	use jrsonnet_parser::*;
-	use std::{path::PathBuf, rc::Rc};
+	use std::{
+		path::{Path, PathBuf},
+		rc::Rc,
+	};
 
 	#[test]
 	#[should_panic]
@@ -503,19 +506,11 @@
 		state.run_in_state(|| {
 			state
 				.push(
-					Some(&ExprLocation(
-						Rc::new(PathBuf::from("test1.jsonnet")),
-						10,
-						20,
-					)),
+					Some(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
 					|| "outer".to_owned(),
 					|| {
 						state.push(
-							Some(&ExprLocation(
-								Rc::new(PathBuf::from("test2.jsonnet")),
-								30,
-								40,
-							)),
+							Some(&ExprLocation(PathBuf::from("test2.jsonnet").into(), 30, 40)),
 							|| "inner".to_owned(),
 							|| Err(RuntimeError("".into()).into()),
 						)?;
@@ -533,7 +528,7 @@
 		assert!(primitive_equals(
 			&state
 				.evaluate_snippet_raw(
-					Rc::new(PathBuf::from("raw.jsonnet")),
+					PathBuf::from("raw.jsonnet").into(),
 					r#"std.assertEqual(std.base64("test"), "dGVzdA==")"#.into()
 				)
 				.unwrap(),
@@ -546,7 +541,7 @@
 		($str: expr) => {
 			EvaluationState::default()
 				.with_stdlib()
-				.evaluate_snippet_raw(Rc::new(PathBuf::from("raw.jsonnet")), $str.into())
+				.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
 				.unwrap()
 		};
 	}
@@ -556,7 +551,7 @@
 			evaluator.with_stdlib();
 			evaluator.run_in_state(|| {
 				evaluator
-					.evaluate_snippet_raw(Rc::new(PathBuf::from("raw.jsonnet")), $str.into())
+					.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
 					.unwrap()
 					.to_json(0)
 					.unwrap()
@@ -913,7 +908,10 @@
 			"{:?}",
 			jrsonnet_parser::parse(
 				"{ x: 1, y: 2 } == { x: 1, y: 2 }",
-				&ParserSettings::default()
+				&ParserSettings {
+					file_name: PathBuf::from("equality").into(),
+					loc_data: true,
+				}
 			)
 		);
 		assert_eval!("{ x: 1, y: 2 } == { x: 1, y: 2 }")
@@ -929,10 +927,10 @@
 		#[derive(gc::Trace, gc::Finalize)]
 		struct NativeAdd;
 		impl NativeCallbackHandler for NativeAdd {
-			fn call(&self, from: Option<Rc<PathBuf>>, args: &[Val]) -> crate::error::Result<Val> {
+			fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> crate::error::Result<Val> {
 				assert_eq!(
-					from.unwrap(),
-					Rc::new(PathBuf::from("native_caller.jsonnet"))
+					&from.unwrap() as &Path,
+					&PathBuf::from("native_caller.jsonnet")
 				);
 				match (&args[0], &args[1]) {
 					(Val::Num(a), Val::Num(b)) => Ok(Val::Num(a + b)),
@@ -951,7 +949,7 @@
 			)),
 		);
 		evaluator.evaluate_snippet_raw(
-			Rc::new(PathBuf::from("native_caller.jsonnet")),
+			PathBuf::from("native_caller.jsonnet").into(),
 			"std.assertEqual(std.native(\"native_add\")(1, 2), 3)".into(),
 		)?;
 		Ok(())
@@ -1003,11 +1001,11 @@
 
 	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 resolve_file(&self, _: &Path, _: &Path) -> crate::error::Result<Rc<Path>> {
+			Ok(PathBuf::from("/test").into())
 		}
 
-		fn load_file_contents(&self, _: &PathBuf) -> crate::error::Result<IStr> {
+		fn load_file_contents(&self, _: &Path) -> crate::error::Result<IStr> {
 			Ok(self.0.clone())
 		}
 
@@ -1030,7 +1028,7 @@
 
 		let error = state
 			.evaluate_snippet_raw(
-				Rc::new(PathBuf::from("issue40.jsonnet")),
+				PathBuf::from("issue40.jsonnet").into(),
 				r#"
 				local conf = {
 					n: ""
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -4,11 +4,11 @@
 use gc::{Finalize, Trace};
 use jrsonnet_parser::ParamsDesc;
 use std::fmt::Debug;
-use std::path::PathBuf;
+use std::path::Path;
 use std::rc::Rc;
 
 pub trait NativeCallbackHandler: Trace {
-	fn call(&self, from: Option<Rc<PathBuf>>, args: &[Val]) -> Result<Val>;
+	fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> Result<Val>;
 }
 
 #[derive(Trace, Finalize)]
@@ -20,7 +20,7 @@
 	pub fn new(params: ParamsDesc, handler: Box<dyn NativeCallbackHandler>) -> Self {
 		Self { params, handler }
 	}
-	pub fn call(&self, caller: Option<Rc<PathBuf>>, args: &[Val]) -> Result<Val> {
+	pub fn call(&self, caller: Option<Rc<Path>>, args: &[Val]) -> Result<Val> {
 		self.handler.call(caller, args)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -2,7 +2,7 @@
 
 use crate::{error::Error, EvaluationState, LocError};
 pub use location::*;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 
 /// The way paths should be displayed
 pub enum PathResolver {
@@ -15,7 +15,7 @@
 }
 
 impl PathResolver {
-	pub fn resolve(&self, from: &PathBuf) -> String {
+	pub fn resolve(&self, from: &Path) -> String {
 		match self {
 			Self::FileName => from.file_name().unwrap().to_string_lossy().into_owned(),
 			Self::Absolute => from.to_string_lossy().into_owned(),
@@ -255,7 +255,7 @@
 		&self,
 		out: &mut dyn std::fmt::Write,
 		source: &str,
-		origin: &PathBuf,
+		origin: &Path,
 		start: &CodeLocation,
 		end: &CodeLocation,
 		desc: &str,
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
before · crates/jrsonnet-parser/src/expr.rs
1use gc::{unsafe_empty_trace, Finalize, Trace};2use jrsonnet_interner::IStr;3#[cfg(feature = "deserialize")]4use serde::Deserialize;5#[cfg(feature = "serialize")]6use serde::Serialize;7use std::{8	fmt::{Debug, Display},9	ops::Deref,10	path::PathBuf,11	rc::Rc,12};1314#[cfg_attr(feature = "serialize", derive(Serialize))]15#[cfg_attr(feature = "deserialize", derive(Deserialize))]16#[derive(Debug, PartialEq)]17pub enum FieldName {18	/// {fixed: 2}19	Fixed(IStr),20	/// {["dyn"+"amic"]: 3}21	Dyn(LocExpr),22}23impl Finalize for FieldName {}24unsafe impl Trace for FieldName {25	unsafe_empty_trace!();26}2728#[cfg_attr(feature = "serialize", derive(Serialize))]29#[cfg_attr(feature = "deserialize", derive(Deserialize))]30#[derive(Debug, Clone, Copy, PartialEq)]31pub enum Visibility {32	/// :33	Normal,34	/// ::35	Hidden,36	/// :::37	Unhide,38}39impl Finalize for Visibility {}40unsafe impl Trace for Visibility {41	unsafe_empty_trace!();42}4344impl Visibility {45	pub fn is_visible(&self) -> bool {46		matches!(self, Self::Normal | Self::Unhide)47	}48}4950#[cfg_attr(feature = "serialize", derive(Serialize))]51#[cfg_attr(feature = "deserialize", derive(Deserialize))]52#[derive(Clone, Debug, PartialEq)]53pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);54impl Finalize for AssertStmt {}55unsafe impl Trace for AssertStmt {56	unsafe_empty_trace!();57}5859#[cfg_attr(feature = "serialize", derive(Serialize))]60#[cfg_attr(feature = "deserialize", derive(Deserialize))]61#[derive(Debug, PartialEq)]62pub struct FieldMember {63	pub name: FieldName,64	pub plus: bool,65	pub params: Option<ParamsDesc>,66	pub visibility: Visibility,67	pub value: LocExpr,68}69impl Finalize for FieldMember {}70unsafe impl Trace for FieldMember {71	unsafe_empty_trace!();72}7374#[cfg_attr(feature = "serialize", derive(Serialize))]75#[cfg_attr(feature = "deserialize", derive(Deserialize))]76#[derive(Debug, PartialEq)]77pub enum Member {78	Field(FieldMember),79	BindStmt(BindSpec),80	AssertStmt(AssertStmt),81}82impl Finalize for Member {}83unsafe impl Trace for Member {84	unsafe_empty_trace!();85}8687#[cfg_attr(feature = "serialize", derive(Serialize))]88#[cfg_attr(feature = "deserialize", derive(Deserialize))]89#[derive(Debug, Clone, Copy, PartialEq)]90pub enum UnaryOpType {91	Plus,92	Minus,93	BitNot,94	Not,95}96impl Finalize for UnaryOpType {}97unsafe impl Trace for UnaryOpType {98	unsafe_empty_trace!();99}100101impl Display for UnaryOpType {102	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {103		use UnaryOpType::*;104		write!(105			f,106			"{}",107			match self {108				Plus => "+",109				Minus => "-",110				BitNot => "~",111				Not => "!",112			}113		)114	}115}116117#[cfg_attr(feature = "serialize", derive(Serialize))]118#[cfg_attr(feature = "deserialize", derive(Deserialize))]119#[derive(Debug, Clone, Copy, PartialEq)]120pub enum BinaryOpType {121	Mul,122	Div,123124	/// Implemented as intrinsic, put here for completeness125	Mod,126127	Add,128	Sub,129130	Lhs,131	Rhs,132133	Lt,134	Gt,135	Lte,136	Gte,137138	BitAnd,139	BitOr,140	BitXor,141142	Eq,143	Neq,144145	And,146	Or,147}148impl Finalize for BinaryOpType {}149unsafe impl Trace for BinaryOpType {150	unsafe_empty_trace!();151}152153impl Display for BinaryOpType {154	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {155		use BinaryOpType::*;156		write!(157			f,158			"{}",159			match self {160				Mul => "*",161				Div => "/",162				Mod => "%",163				Add => "+",164				Sub => "-",165				Lhs => "<<",166				Rhs => ">>",167				Lt => "<",168				Gt => ">",169				Lte => "<=",170				Gte => ">=",171				BitAnd => "&",172				BitOr => "|",173				BitXor => "^",174				Eq => "==",175				Neq => "!=",176				And => "&&",177				Or => "||",178			}179		)180	}181}182183/// name, default value184#[cfg_attr(feature = "serialize", derive(Serialize))]185#[cfg_attr(feature = "deserialize", derive(Deserialize))]186#[derive(Debug, PartialEq)]187pub struct Param(pub IStr, pub Option<LocExpr>);188impl Finalize for Param {}189unsafe impl Trace for Param {190	unsafe_empty_trace!();191}192193/// Defined function parameters194#[cfg_attr(feature = "serialize", derive(Serialize))]195#[cfg_attr(feature = "deserialize", derive(Deserialize))]196#[derive(Debug, Clone, PartialEq)]197pub struct ParamsDesc(pub Rc<Vec<Param>>);198impl Finalize for ParamsDesc {}199unsafe impl Trace for ParamsDesc {200	unsafe_empty_trace!();201}202203impl Deref for ParamsDesc {204	type Target = Vec<Param>;205	fn deref(&self) -> &Self::Target {206		&self.0207	}208}209210#[cfg_attr(feature = "serialize", derive(Serialize))]211#[cfg_attr(feature = "deserialize", derive(Deserialize))]212#[derive(Debug, PartialEq)]213pub struct Arg(pub Option<String>, pub LocExpr);214impl Finalize for Arg {}215unsafe impl Trace for Arg {216	unsafe_empty_trace!();217}218219#[cfg_attr(feature = "serialize", derive(Serialize))]220#[cfg_attr(feature = "deserialize", derive(Deserialize))]221#[derive(Debug, PartialEq)]222pub struct ArgsDesc(pub Vec<Arg>);223impl Finalize for ArgsDesc {}224unsafe impl Trace for ArgsDesc {225	unsafe_empty_trace!();226}227228impl Deref for ArgsDesc {229	type Target = Vec<Arg>;230	fn deref(&self) -> &Self::Target {231		&self.0232	}233}234235#[cfg_attr(feature = "serialize", derive(Serialize))]236#[cfg_attr(feature = "deserialize", derive(Deserialize))]237#[derive(Debug, Clone, PartialEq)]238pub struct BindSpec {239	pub name: IStr,240	pub params: Option<ParamsDesc>,241	pub value: LocExpr,242}243impl Finalize for BindSpec {}244unsafe impl Trace for BindSpec {245	unsafe_empty_trace!();246}247248#[cfg_attr(feature = "serialize", derive(Serialize))]249#[cfg_attr(feature = "deserialize", derive(Deserialize))]250#[derive(Debug, PartialEq)]251pub struct IfSpecData(pub LocExpr);252impl Finalize for IfSpecData {}253unsafe impl Trace for IfSpecData {254	unsafe_empty_trace!();255}256257#[cfg_attr(feature = "serialize", derive(Serialize))]258#[cfg_attr(feature = "deserialize", derive(Deserialize))]259#[derive(Debug, PartialEq)]260pub struct ForSpecData(pub IStr, pub LocExpr);261impl Finalize for ForSpecData {}262unsafe impl Trace for ForSpecData {263	unsafe_empty_trace!();264}265266#[cfg_attr(feature = "serialize", derive(Serialize))]267#[cfg_attr(feature = "deserialize", derive(Deserialize))]268#[derive(Debug, PartialEq)]269pub enum CompSpec {270	IfSpec(IfSpecData),271	ForSpec(ForSpecData),272}273impl Finalize for CompSpec {}274unsafe impl Trace for CompSpec {275	unsafe_empty_trace!();276}277278#[cfg_attr(feature = "serialize", derive(Serialize))]279#[cfg_attr(feature = "deserialize", derive(Deserialize))]280#[derive(Debug, PartialEq)]281pub struct ObjComp {282	pub pre_locals: Vec<BindSpec>,283	pub key: LocExpr,284	pub value: LocExpr,285	pub post_locals: Vec<BindSpec>,286	pub compspecs: Vec<CompSpec>,287}288impl Finalize for ObjComp {}289unsafe impl Trace for ObjComp {290	unsafe_empty_trace!();291}292293#[cfg_attr(feature = "serialize", derive(Serialize))]294#[cfg_attr(feature = "deserialize", derive(Deserialize))]295#[derive(Debug, PartialEq)]296pub enum ObjBody {297	MemberList(Vec<Member>),298	ObjComp(ObjComp),299}300impl Finalize for ObjBody {}301unsafe impl Trace for ObjBody {302	unsafe_empty_trace!();303}304305#[cfg_attr(feature = "serialize", derive(Serialize))]306#[cfg_attr(feature = "deserialize", derive(Deserialize))]307#[derive(Debug, PartialEq, Clone, Copy)]308pub enum LiteralType {309	This,310	Super,311	Dollar,312	Null,313	True,314	False,315}316impl Finalize for LiteralType {}317unsafe impl Trace for LiteralType {318	unsafe_empty_trace!();319}320321#[derive(Debug, PartialEq)]322pub struct SliceDesc {323	pub start: Option<LocExpr>,324	pub end: Option<LocExpr>,325	pub step: Option<LocExpr>,326}327impl Finalize for SliceDesc {}328unsafe impl Trace for SliceDesc {329	unsafe_empty_trace!();330}331332/// Syntax base333#[cfg_attr(feature = "serialize", derive(Serialize))]334#[cfg_attr(feature = "deserialize", derive(Deserialize))]335#[derive(Debug, PartialEq)]336pub enum Expr {337	Literal(LiteralType),338339	/// String value: "hello"340	Str(IStr),341	/// Number: 1, 2.0, 2e+20342	Num(f64),343	/// Variable name: test344	Var(IStr),345346	/// Array of expressions: [1, 2, "Hello"]347	Arr(Vec<LocExpr>),348	/// Array comprehension:349	/// ```jsonnet350	///  ingredients: [351	///    { kind: kind, qty: 4 / 3 }352	///    for kind in [353	///      'Honey Syrup',354	///      'Lemon Juice',355	///      'Farmers Gin',356	///    ]357	///  ],358	/// ```359	ArrComp(LocExpr, Vec<CompSpec>),360361	/// Object: {a: 2}362	Obj(ObjBody),363	/// Object extension: var1 {b: 2}364	ObjExtend(LocExpr, ObjBody),365366	/// (obj)367	Parened(LocExpr),368369	/// -2370	UnaryOp(UnaryOpType, LocExpr),371	/// 2 - 2372	BinaryOp(LocExpr, BinaryOpType, LocExpr),373	/// assert 2 == 2 : "Math is broken"374	AssertExpr(AssertStmt, LocExpr),375	/// local a = 2; { b: a }376	LocalExpr(Vec<BindSpec>, LocExpr),377378	/// import "hello"379	Import(PathBuf),380	/// importStr "file.txt"381	ImportStr(PathBuf),382	/// error "I'm broken"383	ErrorStmt(LocExpr),384	/// a(b, c)385	Apply(LocExpr, ArgsDesc, bool),386	/// a[b]387	Index(LocExpr, LocExpr),388	/// function(x) x389	Function(ParamsDesc, LocExpr),390	/// std.primitiveEquals391	Intrinsic(IStr),392	/// if true == false then 1 else 2393	IfElse {394		cond: IfSpecData,395		cond_then: LocExpr,396		cond_else: Option<LocExpr>,397	},398}399impl Finalize for Expr {}400unsafe impl Trace for Expr {401	unsafe_empty_trace!();402}403404/// file, begin offset, end offset405#[cfg_attr(feature = "serialize", derive(Serialize))]406#[cfg_attr(feature = "deserialize", derive(Deserialize))]407#[derive(Clone, PartialEq)]408pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);409impl Finalize for ExprLocation {}410unsafe impl Trace for ExprLocation {411	unsafe_empty_trace!();412}413414impl Debug for ExprLocation {415	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {416		write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)417	}418}419420/// Holds AST expression and its location in source file421#[cfg_attr(feature = "serialize", derive(Serialize))]422#[cfg_attr(feature = "deserialize", derive(Deserialize))]423#[derive(Clone, PartialEq)]424pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);425impl Finalize for LocExpr {}426unsafe impl Trace for LocExpr {427	unsafe_empty_trace!();428}429430impl Debug for LocExpr {431	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {432		if f.alternate() {433			write!(f, "{:#?}", self.0)?;434		} else {435			write!(f, "{:?}", self.0)?;436		}437		if let Some(loc) = &self.1 {438			write!(f, " from {:?}", loc)?;439		}440		Ok(())441	}442}443444/// Creates LocExpr from Expr and ExprLocation components445#[macro_export]446macro_rules! loc_expr {447	($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {448		LocExpr(449			std::rc::Rc::new($expr),450			if $need_loc {451				Some(ExprLocation($name, $start, $end))452			} else {453				None454			},455		)456	};457}458459/// Creates LocExpr without location info460#[macro_export]461macro_rules! loc_expr_todo {462	($expr:expr) => {463		LocExpr(Rc::new($expr), None)464	};465}
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -1,15 +1,17 @@
 #![allow(clippy::redundant_closure_call)]
 
 use peg::parser;
-use std::{path::PathBuf, rc::Rc};
+use std::{
+	path::{Path, PathBuf},
+	rc::Rc,
+};
 mod expr;
 pub use expr::*;
 pub use peg;
 
-#[derive(Default)]
 pub struct ParserSettings {
 	pub loc_data: bool,
-	pub file_name: Rc<PathBuf>,
+	pub file_name: Rc<Path>,
 }
 
 parser! {
@@ -304,7 +306,6 @@
 	use super::{expr::*, parse};
 	use crate::ParserSettings;
 	use std::path::PathBuf;
-	use std::rc::Rc;
 
 	macro_rules! parse {
 		($s:expr) => {
@@ -312,7 +313,7 @@
 				$s,
 				&ParserSettings {
 					loc_data: false,
-					file_name: Rc::new(PathBuf::from("/test.jsonnet")),
+					file_name: PathBuf::from("/test.jsonnet").into(),
 				},
 			)
 			.unwrap()