refactor(tvix/eval): remove usage of lazy_static
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
This commit is contained in:
parent
b7a6fc2812
commit
b21cb11b7f
6 changed files with 26 additions and 38 deletions
1
tvix/Cargo.lock
generated
1
tvix/Cargo.lock
generated
|
@ -4673,7 +4673,6 @@ dependencies = [
|
||||||
"dirs",
|
"dirs",
|
||||||
"genawaiter",
|
"genawaiter",
|
||||||
"itertools 0.12.1",
|
"itertools 0.12.1",
|
||||||
"lazy_static",
|
|
||||||
"lexical-core",
|
"lexical-core",
|
||||||
"md-5",
|
"md-5",
|
||||||
"mimalloc",
|
"mimalloc",
|
||||||
|
|
|
@ -15555,10 +15555,6 @@ rec {
|
||||||
name = "itertools";
|
name = "itertools";
|
||||||
packageId = "itertools 0.12.1";
|
packageId = "itertools 0.12.1";
|
||||||
}
|
}
|
||||||
{
|
|
||||||
name = "lazy_static";
|
|
||||||
packageId = "lazy_static";
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
name = "lexical-core";
|
name = "lexical-core";
|
||||||
packageId = "lexical-core";
|
packageId = "lexical-core";
|
||||||
|
|
|
@ -15,7 +15,6 @@ codemap-diagnostic = { workspace = true }
|
||||||
dirs = { workspace = true }
|
dirs = { workspace = true }
|
||||||
genawaiter = { workspace = true }
|
genawaiter = { workspace = true }
|
||||||
itertools = { workspace = true }
|
itertools = { workspace = true }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
lexical-core = { workspace = true, features = ["format", "parse-floats"] }
|
lexical-core = { workspace = true, features = ["format", "parse-floats"] }
|
||||||
os_str_bytes = { workspace = true, features = ["conversions"] }
|
os_str_bytes = { workspace = true, features = ["conversions"] }
|
||||||
path-clean = { workspace = true }
|
path-clean = { workspace = true }
|
||||||
|
|
|
@ -9,9 +9,9 @@ use std::borrow::Borrow;
|
||||||
use std::collections::{btree_map, BTreeMap};
|
use std::collections::{btree_map, BTreeMap};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use bstr::BStr;
|
use bstr::BStr;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::de::{Deserializer, Error, Visitor};
|
use serde::de::{Deserializer, Error, Visitor};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -22,12 +22,8 @@ use super::Value;
|
||||||
use crate::errors::ErrorKind;
|
use crate::errors::ErrorKind;
|
||||||
use crate::CatchableErrorKind;
|
use crate::CatchableErrorKind;
|
||||||
|
|
||||||
lazy_static! {
|
static NAME: LazyLock<NixString> = LazyLock::new(|| "name".into());
|
||||||
static ref NAME_S: NixString = "name".into();
|
static VALUE: LazyLock<NixString> = LazyLock::new(|| "value".into());
|
||||||
static ref NAME_REF: &'static NixString = &NAME_S;
|
|
||||||
static ref VALUE_S: NixString = "value".into();
|
|
||||||
static ref VALUE_REF: &'static NixString = &VALUE_S;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -201,13 +197,13 @@ impl NixAttrs {
|
||||||
// Slightly more advanced, but still optimised updates
|
// Slightly more advanced, but still optimised updates
|
||||||
match (Rc::unwrap_or_clone(self.0), Rc::unwrap_or_clone(other.0)) {
|
match (Rc::unwrap_or_clone(self.0), Rc::unwrap_or_clone(other.0)) {
|
||||||
(AttrsRep::Map(mut m), AttrsRep::KV { name, value }) => {
|
(AttrsRep::Map(mut m), AttrsRep::KV { name, value }) => {
|
||||||
m.insert(NAME_S.clone(), name);
|
m.insert(NAME.clone(), name);
|
||||||
m.insert(VALUE_S.clone(), value);
|
m.insert(VALUE.clone(), value);
|
||||||
AttrsRep::Map(m).into()
|
AttrsRep::Map(m).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(AttrsRep::KV { name, value }, AttrsRep::Map(mut m)) => {
|
(AttrsRep::KV { name, value }, AttrsRep::Map(mut m)) => {
|
||||||
match m.entry(NAME_S.clone()) {
|
match m.entry(NAME.clone()) {
|
||||||
btree_map::Entry::Vacant(e) => {
|
btree_map::Entry::Vacant(e) => {
|
||||||
e.insert(name);
|
e.insert(name);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +211,7 @@ impl NixAttrs {
|
||||||
btree_map::Entry::Occupied(_) => { /* name from `m` has precedence */ }
|
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) => {
|
btree_map::Entry::Vacant(e) => {
|
||||||
e.insert(value);
|
e.insert(value);
|
||||||
}
|
}
|
||||||
|
@ -387,7 +383,7 @@ impl IntoIterator for NixAttrs {
|
||||||
match Rc::unwrap_or_clone(self.0) {
|
match Rc::unwrap_or_clone(self.0) {
|
||||||
AttrsRep::Empty => OwnedAttrsIterator(IntoIterRepr::Empty),
|
AttrsRep::Empty => OwnedAttrsIterator(IntoIterRepr::Empty),
|
||||||
AttrsRep::KV { name, value } => OwnedAttrsIterator(IntoIterRepr::Finite(
|
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())),
|
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> {
|
fn attempt_optimise_kv(slice: &mut [Value]) -> Option<NixAttrs> {
|
||||||
let (name_idx, value_idx) = {
|
let (name_idx, value_idx) = {
|
||||||
match (&slice[2], &slice[0]) {
|
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 == *NAME && *s2 == *VALUE) => (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 == *VALUE && *s2 == *NAME) => (1, 3),
|
||||||
|
|
||||||
// Technically this branch lets type errors pass,
|
// Technically this branch lets type errors pass,
|
||||||
// but they will be caught during normal attribute
|
// 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 {
|
KeyValue::KV { name, value, at } => match at {
|
||||||
IterKV::Name => {
|
IterKV::Name => {
|
||||||
at.next();
|
at.next();
|
||||||
Some((&NAME_REF, name))
|
Some((&NAME, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
IterKV::Value => {
|
IterKV::Value => {
|
||||||
at.next();
|
at.next();
|
||||||
Some((&VALUE_REF, value))
|
Some((&VALUE, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
IterKV::Done => None,
|
IterKV::Done => None,
|
||||||
|
@ -536,11 +532,11 @@ impl<'a> Iterator for Keys<'a> {
|
||||||
KeysInner::Empty => None,
|
KeysInner::Empty => None,
|
||||||
KeysInner::KV(at @ IterKV::Name) => {
|
KeysInner::KV(at @ IterKV::Name) => {
|
||||||
at.next();
|
at.next();
|
||||||
Some(&NAME_REF)
|
Some(&NAME)
|
||||||
}
|
}
|
||||||
KeysInner::KV(at @ IterKV::Value) => {
|
KeysInner::KV(at @ IterKV::Value) => {
|
||||||
at.next();
|
at.next();
|
||||||
Some(&VALUE_REF)
|
Some(&VALUE)
|
||||||
}
|
}
|
||||||
KeysInner::KV(IterKV::Done) => None,
|
KeysInner::KV(IterKV::Done) => None,
|
||||||
KeysInner::Map(m) => m.next(),
|
KeysInner::Map(m) => m.next(),
|
||||||
|
|
|
@ -84,10 +84,10 @@ fn test_kv_attrs_iter() {
|
||||||
|
|
||||||
let mut iter = kv_attrs.iter().collect::<Vec<_>>().into_iter();
|
let mut iter = kv_attrs.iter().collect::<Vec<_>>().into_iter();
|
||||||
let (k, v) = iter.next().unwrap();
|
let (k, v) = iter.next().unwrap();
|
||||||
assert!(k == *NAME_REF);
|
assert!(*k == *NAME);
|
||||||
assert!(v.to_str().unwrap() == meaning_val.to_str().unwrap());
|
assert!(v.to_str().unwrap() == meaning_val.to_str().unwrap());
|
||||||
let (k, v) = iter.next().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!(v.as_int().unwrap() == forty_two_val.as_int().unwrap());
|
||||||
assert!(iter.next().is_none());
|
assert!(iter.next().is_none());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::fmt::Display;
|
||||||
use std::num::{NonZeroI32, NonZeroUsize};
|
use std::num::{NonZeroI32, NonZeroUsize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use bstr::{BString, ByteVec};
|
use bstr::{BString, ByteVec};
|
||||||
use codemap::Span;
|
use codemap::Span;
|
||||||
|
@ -37,8 +38,6 @@ pub use thunk::Thunk;
|
||||||
|
|
||||||
pub use self::thunk::ThunkSet;
|
pub use self::thunk::ThunkSet;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
#[warn(variant_size_differences)]
|
#[warn(variant_size_differences)]
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
|
@ -107,16 +106,15 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static WRITE_FLOAT_OPTIONS: LazyLock<lexical_core::WriteFloatOptions> = LazyLock::new(|| {
|
||||||
static ref WRITE_FLOAT_OPTIONS: lexical_core::WriteFloatOptions =
|
lexical_core::WriteFloatOptionsBuilder::new()
|
||||||
lexical_core::WriteFloatOptionsBuilder::new()
|
.trim_floats(true)
|
||||||
.trim_floats(true)
|
.round_mode(lexical_core::write_float_options::RoundMode::Round)
|
||||||
.round_mode(lexical_core::write_float_options::RoundMode::Round)
|
.positive_exponent_break(Some(NonZeroI32::new(5).unwrap()))
|
||||||
.positive_exponent_break(Some(NonZeroI32::new(5).unwrap()))
|
.max_significant_digits(Some(NonZeroUsize::new(6).unwrap()))
|
||||||
.max_significant_digits(Some(NonZeroUsize::new(6).unwrap()))
|
.build()
|
||||||
.build()
|
.unwrap()
|
||||||
.unwrap();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Helper macros to generate the to_*/as_* macros while accounting for
|
// Helper macros to generate the to_*/as_* macros while accounting for
|
||||||
// thunks.
|
// thunks.
|
||||||
|
|
Loading…
Reference in a new issue