difftreelog
feat enable std.thisFile by default
in: master
6 files changed
cmds/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]
cmds/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);
}
crates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth26exp-regex = [26exp-regex = [27 "jrsonnet-stdlib/exp-regex",27 "jrsonnet-stdlib/exp-regex",28]28]29legacy-this-file = ["jrsonnet-stdlib/legacy-this-file"]302931[dependencies]30[dependencies]32jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }31jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }crates/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());
}
crates/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
crates/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);
}
}