diff options
author | Vincent Ambo <mail@tazj.in> | 2024-10-12T22·30+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-10-12T23·02+0000 |
commit | b21cb11b7f65d84baca62a0492d63d184e4f5095 (patch) | |
tree | f54370e33f25e71449dd3daf4c5ffc6edbeec4b4 | |
parent | b7a6fc2812f3ed281ba1a0b985a2ae150095f7b1 (diff) |
refactor(tvix/eval): remove usage of lazy_static r/8797
Equivalent logic is now in the standard library, and this dependency is no longer needed for eval. Change-Id: Iaa4410d89fdaa5b84cbd9e6bc6ae479c659d92f2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12602 Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: edef <edef@edef.eu> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/Cargo.lock | 1 | ||||
-rw-r--r-- | tvix/Cargo.nix | 4 | ||||
-rw-r--r-- | tvix/eval/Cargo.toml | 1 | ||||
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 32 | ||||
-rw-r--r-- | tvix/eval/src/value/attrs/tests.rs | 4 | ||||
-rw-r--r-- | tvix/eval/src/value/mod.rs | 22 |
6 files changed, 26 insertions, 38 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock index b151628be634..badc48a2ca31 100644 --- a/tvix/Cargo.lock +++ b/tvix/Cargo.lock @@ -4673,7 +4673,6 @@ dependencies = [ "dirs", "genawaiter", "itertools 0.12.1", - "lazy_static", "lexical-core", "md-5", "mimalloc", diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix index 24f97de7dc21..deeb10171f29 100644 --- a/tvix/Cargo.nix +++ b/tvix/Cargo.nix @@ -15556,10 +15556,6 @@ rec { packageId = "itertools 0.12.1"; } { - name = "lazy_static"; - packageId = "lazy_static"; - } - { name = "lexical-core"; packageId = "lexical-core"; features = [ "format" "parse-floats" ]; diff --git a/tvix/eval/Cargo.toml b/tvix/eval/Cargo.toml index 29862f97d8e4..c413e1780f21 100644 --- a/tvix/eval/Cargo.toml +++ b/tvix/eval/Cargo.toml @@ -15,7 +15,6 @@ codemap-diagnostic = { workspace = true } dirs = { workspace = true } genawaiter = { workspace = true } itertools = { workspace = true } -lazy_static = { workspace = true } lexical-core = { workspace = true, features = ["format", "parse-floats"] } os_str_bytes = { workspace = true, features = ["conversions"] } path-clean = { workspace = true } diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 00b913347418..8d06240c65f5 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -9,9 +9,9 @@ use std::borrow::Borrow; use std::collections::{btree_map, BTreeMap}; use std::iter::FromIterator; use std::rc::Rc; +use std::sync::LazyLock; use bstr::BStr; -use lazy_static::lazy_static; use serde::de::{Deserializer, Error, Visitor}; use serde::Deserialize; @@ -22,12 +22,8 @@ use super::Value; use crate::errors::ErrorKind; use crate::CatchableErrorKind; -lazy_static! { - static ref NAME_S: NixString = "name".into(); - static ref NAME_REF: &'static NixString = &NAME_S; - static ref VALUE_S: NixString = "value".into(); - static ref VALUE_REF: &'static NixString = &VALUE_S; -} +static NAME: LazyLock<NixString> = LazyLock::new(|| "name".into()); +static VALUE: LazyLock<NixString> = LazyLock::new(|| "value".into()); #[cfg(test)] mod tests; @@ -201,13 +197,13 @@ impl NixAttrs { // Slightly more advanced, but still optimised updates match (Rc::unwrap_or_clone(self.0), Rc::unwrap_or_clone(other.0)) { (AttrsRep::Map(mut m), AttrsRep::KV { name, value }) => { - m.insert(NAME_S.clone(), name); - m.insert(VALUE_S.clone(), value); + m.insert(NAME.clone(), name); + m.insert(VALUE.clone(), value); AttrsRep::Map(m).into() } (AttrsRep::KV { name, value }, AttrsRep::Map(mut m)) => { - match m.entry(NAME_S.clone()) { + match m.entry(NAME.clone()) { btree_map::Entry::Vacant(e) => { e.insert(name); } @@ -215,7 +211,7 @@ impl NixAttrs { btree_map::Entry::Occupied(_) => { /* name from `m` has precedence */ } }; - match m.entry(VALUE_S.clone()) { + match m.entry(VALUE.clone()) { btree_map::Entry::Vacant(e) => { e.insert(value); } @@ -387,7 +383,7 @@ impl IntoIterator for NixAttrs { match Rc::unwrap_or_clone(self.0) { AttrsRep::Empty => OwnedAttrsIterator(IntoIterRepr::Empty), AttrsRep::KV { name, value } => OwnedAttrsIterator(IntoIterRepr::Finite( - vec![(NAME_REF.clone(), name), (VALUE_REF.clone(), value)].into_iter(), + vec![(NAME.clone(), name), (VALUE.clone(), value)].into_iter(), )), AttrsRep::Map(map) => OwnedAttrsIterator(IntoIterRepr::Map(map.into_iter())), } @@ -410,8 +406,8 @@ impl IntoIterator for NixAttrs { fn attempt_optimise_kv(slice: &mut [Value]) -> Option<NixAttrs> { let (name_idx, value_idx) = { match (&slice[2], &slice[0]) { - (Value::String(s1), Value::String(s2)) if (*s1 == *NAME_S && *s2 == *VALUE_S) => (3, 1), - (Value::String(s1), Value::String(s2)) if (*s1 == *VALUE_S && *s2 == *NAME_S) => (1, 3), + (Value::String(s1), Value::String(s2)) if (*s1 == *NAME && *s2 == *VALUE) => (3, 1), + (Value::String(s1), Value::String(s2)) if (*s1 == *VALUE && *s2 == *NAME) => (1, 3), // Technically this branch lets type errors pass, // but they will be caught during normal attribute @@ -496,12 +492,12 @@ impl<'a> Iterator for Iter<KeyValue<'a>> { KeyValue::KV { name, value, at } => match at { IterKV::Name => { at.next(); - Some((&NAME_REF, name)) + Some((&NAME, name)) } IterKV::Value => { at.next(); - Some((&VALUE_REF, value)) + Some((&VALUE, value)) } IterKV::Done => None, @@ -536,11 +532,11 @@ impl<'a> Iterator for Keys<'a> { KeysInner::Empty => None, KeysInner::KV(at @ IterKV::Name) => { at.next(); - Some(&NAME_REF) + Some(&NAME) } KeysInner::KV(at @ IterKV::Value) => { at.next(); - Some(&VALUE_REF) + Some(&VALUE) } KeysInner::KV(IterKV::Done) => None, KeysInner::Map(m) => m.next(), diff --git a/tvix/eval/src/value/attrs/tests.rs b/tvix/eval/src/value/attrs/tests.rs index b79f45a71b28..e8798797fda7 100644 --- a/tvix/eval/src/value/attrs/tests.rs +++ b/tvix/eval/src/value/attrs/tests.rs @@ -84,10 +84,10 @@ fn test_kv_attrs_iter() { let mut iter = kv_attrs.iter().collect::<Vec<_>>().into_iter(); let (k, v) = iter.next().unwrap(); - assert!(k == *NAME_REF); + assert!(*k == *NAME); assert!(v.to_str().unwrap() == meaning_val.to_str().unwrap()); let (k, v) = iter.next().unwrap(); - assert!(k == *VALUE_REF); + assert!(*k == *VALUE); assert!(v.as_int().unwrap() == forty_two_val.as_int().unwrap()); assert!(iter.next().is_none()); } diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 2e78f20b49a0..19ff17feab51 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -5,6 +5,7 @@ use std::fmt::Display; use std::num::{NonZeroI32, NonZeroUsize}; use std::path::PathBuf; use std::rc::Rc; +use std::sync::LazyLock; use bstr::{BString, ByteVec}; use codemap::Span; @@ -37,8 +38,6 @@ pub use thunk::Thunk; pub use self::thunk::ThunkSet; -use lazy_static::lazy_static; - #[warn(variant_size_differences)] #[derive(Clone, Debug, Deserialize)] #[serde(untagged)] @@ -107,16 +106,15 @@ where } } -lazy_static! { - static ref WRITE_FLOAT_OPTIONS: lexical_core::WriteFloatOptions = - lexical_core::WriteFloatOptionsBuilder::new() - .trim_floats(true) - .round_mode(lexical_core::write_float_options::RoundMode::Round) - .positive_exponent_break(Some(NonZeroI32::new(5).unwrap())) - .max_significant_digits(Some(NonZeroUsize::new(6).unwrap())) - .build() - .unwrap(); -} +static WRITE_FLOAT_OPTIONS: LazyLock<lexical_core::WriteFloatOptions> = LazyLock::new(|| { + lexical_core::WriteFloatOptionsBuilder::new() + .trim_floats(true) + .round_mode(lexical_core::write_float_options::RoundMode::Round) + .positive_exponent_break(Some(NonZeroI32::new(5).unwrap())) + .max_significant_digits(Some(NonZeroUsize::new(6).unwrap())) + .build() + .unwrap() +}); // Helper macros to generate the to_*/as_* macros while accounting for // thunks. |