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.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.tomldiffbeforeafterboth1[package]2name = "jrsonnet-stdlib"3description = "jsonnet standard library packaged as crate"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14# Enables legacy `std.thisFile` support, at the cost of worse caching15legacy-this-file = []16# Add order preservation flag to some functions17exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]18# Bigint type19exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"]2021exp-null-coaelse = ["jrsonnet-parser/exp-null-coaelse", "jrsonnet-evaluator/exp-null-coaelse"]22# std.regexMatch and other helpers23exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"]2425[dependencies]26jrsonnet-evaluator.workspace = true27jrsonnet-macros.workspace = true28jrsonnet-parser.workspace = true29jrsonnet-gcmodule.workspace = true3031# Used for std.parseJson/std.parseYaml32serde.workspace = true3334# std.md535md5.workspace = true36# std.sha137sha1.workspace = true38# std.sha256, std.sha51239sha2.workspace = true40# std.sha341sha3.workspace = true42# std.base6443base64.workspace = true44# std.parseJson45serde_json.workspace = true46# std.parseYaml, custom library fork is used for C++/golang compatibility47serde_yaml_with_quirks.workspace = true4849num-bigint = { workspace = true, optional = true }5051# regex52regex = { workspace = true, optional = true }53lru = { workspace = true, optional = true }54rustc-hash = { workspace = true, optional = true }5556[build-dependencies]57jrsonnet-parser.workspace = true1[package]2name = "jrsonnet-stdlib"3description = "jsonnet standard library packaged as crate"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14# Add order preservation flag to some functions15exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]16# Bigint type17exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"]1819exp-null-coaelse = ["jrsonnet-parser/exp-null-coaelse", "jrsonnet-evaluator/exp-null-coaelse"]20# std.regexMatch and other helpers21exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"]2223[dependencies]24jrsonnet-evaluator.workspace = true25jrsonnet-macros.workspace = true26jrsonnet-parser.workspace = true27jrsonnet-gcmodule.workspace = true2829# Used for std.parseJson/std.parseYaml30serde.workspace = true3132# std.md533md5.workspace = true34# std.sha135sha1.workspace = true36# std.sha256, std.sha51237sha2.workspace = true38# std.sha339sha3.workspace = true40# std.base6441base64.workspace = true42# std.parseJson43serde_json.workspace = true44# std.parseYaml, custom library fork is used for C++/golang compatibility45serde_yaml_with_quirks.workspace = true4647num-bigint = { workspace = true, optional = true }4849# regex50regex = { workspace = true, optional = true }51lru = { workspace = true, optional = true }52rustc-hash = { workspace = true, optional = true }5354[build-dependencies]55jrsonnet-parser.workspace = truecrates/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);
}
}