Migrate most of wasmtime from lazy_static to once_cell (#4368)

* Update tracing-core to a version which doesn't depend on lazy-static.

* Update crossbeam-utils to a version that doesn't depend on lazy-static.

* Update crossbeam-epoch to a version that doesn't depend on lazy-static.

* Update clap to a version that doesn't depend on lazy-static.

* Convert Wasmtime's own use of lazy_static to once_cell.

* Make `GDB_REGISTRATION`'s comment a doc comment.

* Fix compilation on Windows.
This commit is contained in:
Dan Gohman
2022-07-05 10:52:48 -07:00
committed by GitHub
parent d9e0e6a6a9
commit 371ae80ac3
25 changed files with 123 additions and 138 deletions

View File

@@ -31,7 +31,7 @@ rustix = { version = "0.35.6", features = ["process"] }
[dev-dependencies]
filetime = "0.2.7"
lazy_static = "1.3.0"
once_cell = "1.12.0"
more-asserts = "0.2.1"
pretty_env_logger = "0.4.0"
tempfile = "3"

View File

@@ -1,9 +1,7 @@
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::time::{Duration, SystemTime, SystemTimeError};
lazy_static! {
pub static ref NOW: SystemTime = SystemTime::now(); // no need for RefCell and set_now() for now
}
pub static NOW: Lazy<SystemTime> = Lazy::new(SystemTime::now);
#[derive(PartialOrd, PartialEq, Ord, Eq)]
pub struct SystemTimeStub(SystemTime);

View File

@@ -10,7 +10,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.19"
clap = { version = "3.1.12", features = ["color", "suggestions", "derive"] }
clap = { version = "3.2.0", features = ["color", "suggestions", "derive"] }
file-per-thread-logger = "0.1.1"
pretty_env_logger = "0.4.0"
rayon = "1.5.0"

View File

@@ -13,10 +13,10 @@ license = "Apache-2.0 WITH LLVM-exception"
# `build-libinterpret` feature set by this crate's parent).
[dependencies]
ocaml-interop = { version = "0.8", optional = true }
lazy_static = { version = "1.4", optional = true }
once_cell = { version = "1.12.0", optional = true }
[dev-dependencies]
wat = "1.0"
[features]
build-libinterpret = ["ocaml-interop", "lazy_static"]
build-libinterpret = ["ocaml-interop", "once_cell"]

View File

@@ -7,13 +7,11 @@
//! assert_eq!(results, &[Value::I32(43)]);
//! ```
use crate::Value;
use lazy_static::lazy_static;
use ocaml_interop::{OCamlRuntime, ToOCaml};
use once_cell::sync::Lazy;
use std::sync::Mutex;
lazy_static! {
static ref INTERPRET: Mutex<()> = Mutex::new(());
}
static INTERPRET: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
/// Interpret the first function in the passed WebAssembly module (in Wasm form,
/// currently, not WAT), optionally with the given parameters. If no parameters

View File

@@ -11,7 +11,7 @@ readme = "README.md"
edition = "2021"
[dependencies]
lazy_static = {version = "1.3.0", optional = true }
once_cell = {version = "1.12.0", optional = true }
object = { version = "0.28.0", default-features = false, features = ["std", "read_core"], optional = true }
[target.'cfg(target_os = "linux")'.dependencies]
@@ -21,5 +21,5 @@ rustix = { version = "0.35.6", features = ["mm", "param", "time"], optional = tr
maintenance = { status = "actively-developed" }
[features]
gdb_jit_int = ["lazy_static"]
gdb_jit_int = ["once_cell"]
perf_jitdump = ["rustix", "object"]

View File

@@ -2,7 +2,7 @@
//! the __jit_debug_register_code() and __jit_debug_descriptor to register
//! or unregister generated object images with debuggers.
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::pin::Pin;
use std::ptr;
use std::sync::Mutex;
@@ -32,15 +32,13 @@ extern "C" {
fn __jit_debug_register_code();
}
lazy_static! {
// The process controls access to the __jit_debug_descriptor by itself --
// the GDB/LLDB accesses this structure and its data at the process startup
// and when paused in __jit_debug_register_code.
//
// The GDB_REGISTRATION lock is needed for GdbJitImageRegistration to protect
// access to the __jit_debug_descriptor within this process.
pub static ref GDB_REGISTRATION: Mutex<()> = Mutex::new(Default::default());
}
/// The process controls access to the __jit_debug_descriptor by itself --
/// the GDB/LLDB accesses this structure and its data at the process startup
/// and when paused in __jit_debug_register_code.
///
/// The GDB_REGISTRATION lock is needed for GdbJitImageRegistration to protect
/// access to the __jit_debug_descriptor within this process.
static GDB_REGISTRATION: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(Default::default()));
/// Registeration for JIT image
pub struct GdbJitImageRegistration {

View File

@@ -1,10 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
version = 3
[[package]]
name = "libc"
@@ -18,6 +14,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "once_cell"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
@@ -28,8 +30,8 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
name = "wasi-tests"
version = "0.19.0"
dependencies = [
"lazy_static",
"libc",
"more-asserts",
"once_cell",
"wasi",
]

View File

@@ -10,7 +10,7 @@ publish = false
libc = "0.2.65"
wasi = "0.10.2"
more-asserts = "0.2.1"
lazy_static = "1.4"
once_cell = "1.12.0"
# This crate is built with the wasm32-wasi target, so it's separate
# from the main Wasmtime build, so use this directive to exclude it

View File

@@ -1,9 +1,8 @@
use more_asserts::assert_gt;
pub mod config;
use once_cell::sync::Lazy;
lazy_static::lazy_static! {
pub static ref TESTCONFIG: config::TestConfig = config::TestConfig::from_env();
}
pub static TESTCONFIG: Lazy<config::TestConfig> = Lazy::new(config::TestConfig::from_env);
// The `wasi` crate version 0.9.0 and beyond, doesn't
// seem to define these constants, so we do it ourselves.

View File

@@ -29,7 +29,7 @@ is-terminal = "0.3.0"
rustix = { version = "0.35.6", features = ["fs"] }
[target.'cfg(windows)'.dependencies]
lazy_static = "1.4"
once_cell = "1.12.0"
io-extras = "0.15.0"
[target.'cfg(windows)'.dependencies.windows-sys]

View File

@@ -9,6 +9,7 @@
// taken the time to improve it. See bug #2880.
use anyhow::Context;
use once_cell::sync::Lazy;
use std::ops::Deref;
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
use std::sync::Mutex;
@@ -145,9 +146,7 @@ struct StdinPoll {
notify_rx: Receiver<PollState>,
}
lazy_static::lazy_static! {
static ref STDIN_POLL: Mutex<StdinPoll> = StdinPoll::new();
}
static STDIN_POLL: Lazy<Mutex<StdinPoll>> = Lazy::new(StdinPoll::new);
impl StdinPoll {
pub fn new() -> Mutex<Self> {

View File

@@ -23,7 +23,6 @@ io-lifetimes = { version = "0.7.0", default-features = false }
rustix = { version = "0.35.6", features = ["fs"] }
[target.'cfg(windows)'.dependencies]
lazy_static = "1.4"
io-extras = "0.15.0"
[dev-dependencies]

View File

@@ -34,11 +34,10 @@ bincode = "1.2.1"
indexmap = "1.6"
paste = "1.0.3"
psm = "0.1.11"
lazy_static = "1.4"
once_cell = "1.12.0"
rayon = { version = "1.0", optional = true }
object = { version = "0.28", default-features = false, features = ['read_core', 'elf'] }
async-trait = { version = "0.1.51", optional = true }
once_cell = "1.12"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.36.0"

View File

@@ -3,6 +3,7 @@
#[cfg(feature = "component-model")]
use crate::component::Component;
use crate::{FrameInfo, Module};
use once_cell::sync::Lazy;
use std::{
collections::BTreeMap,
sync::{Arc, RwLock},
@@ -201,9 +202,7 @@ impl ModuleRegistry {
// it is also automatically registered with the singleton global module
// registry. When a `ModuleRegistry` is destroyed then all of its entries
// are removed from the global module registry.
lazy_static::lazy_static! {
static ref GLOBAL_MODULES: RwLock<GlobalModuleRegistry> = Default::default();
}
static GLOBAL_MODULES: Lazy<RwLock<GlobalModuleRegistry>> = Lazy::new(Default::default);
type GlobalModuleRegistry = BTreeMap<usize, (usize, TrapInfo)>;