difftreelog
feat enable std.thisFile by default
in: master
6 files changed
cmds/jrsonnet/Cargo.tomldiffbeforeafterboth1[package]2name = "jrsonnet"3description = "Rust jsonnet implementation"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14experimental = [15 "exp-preserve-order",16 "exp-destruct",17 "exp-null-coaelse",18 "exp-object-iteration",19 "exp-bigint",20 "exp-apply",21 "exp-regex",22]23# Use mimalloc as allocator24mimalloc = ["mimallocator"]25# Experimental feature, which allows to preserve order of object fields26exp-preserve-order = [27 "jrsonnet-evaluator/exp-preserve-order",28 "jrsonnet-cli/exp-preserve-order",29]30# Destructuring of locals31exp-destruct = ["jrsonnet-evaluator/exp-destruct"]32# Iteration over objects yields [key, value] elements33exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]34# Bigint type35exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]36# std.regex and co.37exp-regex = ["jrsonnet-cli/exp-regex"]38# obj?.field, obj?.['field']39exp-null-coaelse = [40 "jrsonnet-evaluator/exp-null-coaelse",41 "jrsonnet-parser/exp-null-coaelse",42 "jrsonnet-cli/exp-null-coaelse",43]44# --exp-apply45exp-apply = []4647# std.thisFile support48legacy-this-file = ["jrsonnet-cli/legacy-this-file"]4950nightly = ["jrsonnet-evaluator/nightly"]5152[dependencies]53jrsonnet-evaluator.workspace = true54jrsonnet-parser.workspace = true55jrsonnet-cli.workspace = true56jrsonnet-gcmodule.workspace = true5758mimallocator = { workspace = true, optional = true }59thiserror.workspace = true60clap = { workspace = true, features = ["derive"] }61clap_complete.workspace = true62serde_json.workspace = true63serde = { workspace = true, features = ["derive"] }64hi-doc.workspace = true1[package]2name = "jrsonnet"3description = "Rust jsonnet implementation"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14experimental = [15 "exp-preserve-order",16 "exp-destruct",17 "exp-null-coaelse",18 "exp-object-iteration",19 "exp-bigint",20 "exp-apply",21 "exp-regex",22]23# Use mimalloc as allocator24mimalloc = ["mimallocator"]25# Experimental feature, which allows to preserve order of object fields26exp-preserve-order = [27 "jrsonnet-evaluator/exp-preserve-order",28 "jrsonnet-cli/exp-preserve-order",29]30# Destructuring of locals31exp-destruct = ["jrsonnet-evaluator/exp-destruct"]32# Iteration over objects yields [key, value] elements33exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]34# Bigint type35exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]36# std.regex and co.37exp-regex = ["jrsonnet-cli/exp-regex"]38# obj?.field, obj?.['field']39exp-null-coaelse = [40 "jrsonnet-evaluator/exp-null-coaelse",41 "jrsonnet-parser/exp-null-coaelse",42 "jrsonnet-cli/exp-null-coaelse",43]44# --exp-apply45exp-apply = []4647nightly = ["jrsonnet-evaluator/nightly"]4849[dependencies]50jrsonnet-evaluator.workspace = true51jrsonnet-parser.workspace = true52jrsonnet-cli.workspace = true53jrsonnet-gcmodule.workspace = true5455mimallocator = { workspace = true, optional = true }56thiserror.workspace = true57clap = { workspace = true, features = ["derive"] }58clap_complete.workspace = true59serde_json.workspace = true60serde = { workspace = true, features = ["derive"] }61hi-doc.workspace = truecmds/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.tomldiffbeforeafterboth--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -26,7 +26,6 @@
exp-regex = [
"jrsonnet-stdlib/exp-regex",
]
-legacy-this-file = ["jrsonnet-stdlib/legacy-this-file"]
[dependencies]
jrsonnet-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);
}
}