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

difftreelog

feat enable std.thisFile by default

Yaroslav Bolyukin2024-06-18parent: #4f26f96.patch.diff
in: master

6 files changed

modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -44,9 +44,6 @@
 # --exp-apply
 exp-apply = []
 
-# std.thisFile support
-legacy-this-file = ["jrsonnet-cli/legacy-this-file"]
-
 nightly = ["jrsonnet-evaluator/nightly"]
 
 [dependencies]
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -170,7 +170,7 @@
 	let import_resolver = opts.misc.import_resolver();
 	s.set_import_resolver(import_resolver);
 
-	let std = opts.std.context_initializer(s)?;
+	let std = opts.std.context_initializer()?;
 	if let Some(std) = std {
 		s.set_context_initializer(std);
 	}
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
before · crates/jrsonnet-cli/Cargo.toml
1[package]2name = "jrsonnet-cli"3description = "Utilities for building jrsonnet CLIs"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14exp-preserve-order = [15    "jrsonnet-evaluator/exp-preserve-order",16    "jrsonnet-stdlib/exp-preserve-order",17]18exp-bigint = [19    "jrsonnet-evaluator/exp-bigint",20    "jrsonnet-stdlib/exp-bigint",21]22exp-null-coaelse = [23    "jrsonnet-evaluator/exp-null-coaelse",24    "jrsonnet-stdlib/exp-null-coaelse",25]26exp-regex = [27    "jrsonnet-stdlib/exp-regex",28]29legacy-this-file = ["jrsonnet-stdlib/legacy-this-file"]3031[dependencies]32jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }33jrsonnet-parser.workspace = true34jrsonnet-stdlib.workspace = true35jrsonnet-gcmodule.workspace = true3637clap = { workspace = true, features = ["derive"] }
modifiedcrates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -1,7 +1,7 @@
 use std::{fs::read_to_string, str::FromStr};
 
 use clap::Parser;
-use jrsonnet_evaluator::{trace::PathResolver, Result, State};
+use jrsonnet_evaluator::{trace::PathResolver, Result};
 use jrsonnet_stdlib::ContextInitializer;
 
 #[derive(Clone)]
@@ -104,11 +104,11 @@
 	ext_code_file: Vec<ExtFile>,
 }
 impl StdOpts {
-	pub fn context_initializer(&self, s: &State) -> Result<Option<ContextInitializer>> {
+	pub fn context_initializer(&self) -> Result<Option<ContextInitializer>> {
 		if self.no_stdlib {
 			return Ok(None);
 		}
-		let ctx = ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
+		let ctx = ContextInitializer::new(PathResolver::new_cwd_fallback());
 		for ext in &self.ext_str {
 			ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
 		}
modifiedcrates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -11,8 +11,6 @@
 workspace = true
 
 [features]
-# Enables legacy `std.thisFile` support, at the cost of worse caching
-legacy-this-file = []
 # Add order preservation flag to some functions
 exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]
 # Bigint type
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -13,9 +13,8 @@
 use jrsonnet_evaluator::{
 	error::{ErrorKind::*, Result},
 	function::{CallLocation, FuncVal, TlaArg},
-	tb,
 	trace::PathResolver,
-	ContextBuilder, IStr, ObjValue, ObjValueBuilder, State, Thunk, Val,
+	ContextBuilder, IStr, ObjValue, ObjValueBuilder, Thunk, Val,
 };
 use jrsonnet_gcmodule::Trace;
 use jrsonnet_parser::Source;
@@ -328,19 +327,12 @@
 
 #[derive(Trace, Clone)]
 pub struct ContextInitializer {
-	/// When we don't need to support legacy-this-file, we can reuse same context for all files
-	#[cfg(not(feature = "legacy-this-file"))]
-	context: jrsonnet_evaluator::Context,
-	/// For `populate`
-	#[cfg(not(feature = "legacy-this-file"))]
-	stdlib_thunk: Thunk<Val>,
-	/// Otherwise, we can only keep first stdlib layer, and then stack thisFile on top of it
-	#[cfg(feature = "legacy-this-file")]
+	/// std without applied thisFile overlay
 	stdlib_obj: ObjValue,
 	settings: Rc<RefCell<Settings>>,
 }
 impl ContextInitializer {
-	pub fn new(s: State, resolver: PathResolver) -> Self {
+	pub fn new(resolver: PathResolver) -> Self {
 		let settings = Settings {
 			ext_vars: HashMap::new(),
 			ext_natives: HashMap::new(),
@@ -349,20 +341,7 @@
 		};
 		let settings = Rc::new(RefCell::new(settings));
 		let stdlib_obj = stdlib_uncached(settings.clone());
-		#[cfg(not(feature = "legacy-this-file"))]
-		let stdlib_thunk = Thunk::evaluated(Val::Obj(stdlib_obj));
-		#[cfg(feature = "legacy-this-file")]
-		let _ = s;
 		Self {
-			#[cfg(not(feature = "legacy-this-file"))]
-			context: {
-				let mut context = ContextBuilder::with_capacity(s, 1);
-				context.bind("std", stdlib_thunk.clone());
-				context.build()
-			},
-			#[cfg(not(feature = "legacy-this-file"))]
-			stdlib_thunk,
-			#[cfg(feature = "legacy-this-file")]
 			stdlib_obj,
 			settings,
 		}
@@ -411,16 +390,7 @@
 impl jrsonnet_evaluator::ContextInitializer for ContextInitializer {
 	fn reserve_vars(&self) -> usize {
 		1
-	}
-	#[cfg(not(feature = "legacy-this-file"))]
-	fn initialize(&self, _s: State, _source: Source) -> jrsonnet_evaluator::Context {
-		self.context.clone()
-	}
-	#[cfg(not(feature = "legacy-this-file"))]
-	fn populate(&self, _for_file: Source, builder: &mut ContextBuilder) {
-		builder.bind("std", self.stdlib_thunk.clone());
 	}
-	#[cfg(feature = "legacy-this-file")]
 	fn populate(&self, source: Source, builder: &mut ContextBuilder) {
 		let mut std = ObjValueBuilder::new();
 		std.with_super(self.stdlib_obj.clone());
@@ -437,17 +407,5 @@
 	}
 	fn as_any(&self) -> &dyn std::any::Any {
 		self
-	}
-}
-
-pub trait StateExt {
-	/// This method was previously implemented in jrsonnet-evaluator itself
-	fn with_stdlib(&self);
-}
-
-impl StateExt for State {
-	fn with_stdlib(&self) {
-		let initializer = ContextInitializer::new(self.clone(), PathResolver::new_cwd_fallback());
-		self.settings_mut().context_initializer = tb!(initializer);
 	}
 }