Skip to content

Commit b79a96a

Browse files
authored
Leverage Rust 1.79, 1.80 (#9498)
This commit is a follow-up to #9496 to leverage various APIs that the workspace now has access to. For example most dependencies on the `once_cell` crate are now removed in favor of the types stabilized in the standard library: `LazyLock` and `LazyCell`. One dependency remains in the `wasmtime` crate due to the `get_or_try_init` not being stable yet. Some additional helper methods on raw pointer slices are also available for removing a few minor `unsafe` blocks.
1 parent a40776c commit b79a96a

File tree

32 files changed

+46
-73
lines changed

32 files changed

+46
-73
lines changed

Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ clap = { workspace = true }
6161
clap_complete = { workspace = true, optional = true }
6262
anyhow = { workspace = true, features = ['std'] }
6363
target-lexicon = { workspace = true }
64-
once_cell = { workspace = true }
6564
listenfd = { version = "1.0.0", optional = true }
6665
wat = { workspace = true, optional = true }
6766
serde = { workspace = true }
@@ -299,7 +298,6 @@ clap = { version = "4.5.17", default-features = false, features = ["std", "deriv
299298
clap_complete = "4.4.7"
300299
hashbrown = { version = "0.14", default-features = false }
301300
capstone = "0.12.0"
302-
once_cell = { version = "1.12.0", default-features = false }
303301
smallvec = { version = "1.6.1", features = ["union"] }
304302
tracing = "0.1.26"
305303
bitflags = "2.0"

benches/instantiation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
3-
use once_cell::unsync::Lazy;
3+
use std::cell::LazyCell;
44
use std::path::Path;
55
use std::process::Command;
66
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst};
@@ -35,7 +35,7 @@ fn bench_sequential(c: &mut Criterion, path: &Path) {
3535
benchmark_name(&strategy),
3636
path.file_name().unwrap().to_str().unwrap(),
3737
);
38-
let state = Lazy::new(|| {
38+
let state = LazyCell::new(|| {
3939
let mut config = Config::default();
4040
config.allocation_strategy(strategy.clone());
4141

@@ -70,7 +70,7 @@ fn bench_parallel(c: &mut Criterion, path: &Path) {
7070
let mut group = c.benchmark_group("parallel");
7171

7272
for strategy in strategies() {
73-
let state = Lazy::new(|| {
73+
let state = LazyCell::new(|| {
7474
let mut config = Config::default();
7575
config.allocation_strategy(strategy.clone());
7676

@@ -153,7 +153,7 @@ fn bench_deserialize_module(c: &mut Criterion, path: &Path) {
153153

154154
let name = path.file_name().unwrap().to_str().unwrap();
155155
let tmpfile = tempfile::NamedTempFile::new().unwrap();
156-
let state = Lazy::new(|| {
156+
let state = LazyCell::new(|| {
157157
let engine = Engine::default();
158158
let module = Module::from_file(&engine, path).expect("failed to load WASI example module");
159159
let bytes = module.serialize().unwrap();

cranelift/fuzzgen/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ workspace = true
1717
cranelift = { workspace = true }
1818
cranelift-native = { workspace = true }
1919

20-
anyhow = { workspace = true }
20+
anyhow = { workspace = true, features = ['std'] }
2121
arbitrary = { workspace = true }
22-
once_cell = { workspace = true }
2322
target-lexicon = { workspace = true, features = ["std"] }

cranelift/fuzzgen/src/function_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use cranelift::prelude::{
1919
EntityRef, ExtFuncData, FloatCC, InstBuilder, IntCC, JumpTableData, MemFlags, StackSlotData,
2020
StackSlotKind,
2121
};
22-
use once_cell::sync::Lazy;
2322
use std::collections::HashMap;
2423
use std::ops::RangeInclusive;
2524
use std::str::FromStr;
25+
use std::sync::LazyLock;
2626
use target_lexicon::{Architecture, Triple};
2727

2828
type BlockSignature = Vec<Type>;
@@ -789,7 +789,7 @@ fn valid_for_target(triple: &Triple, op: Opcode, args: &[Type], rets: &[Type]) -
789789

790790
type OpcodeSignature = (Opcode, Vec<Type>, Vec<Type>);
791791

792-
static OPCODE_SIGNATURES: Lazy<Vec<OpcodeSignature>> = Lazy::new(|| {
792+
static OPCODE_SIGNATURES: LazyLock<Vec<OpcodeSignature>> = LazyLock::new(|| {
793793
let types = &[
794794
I8, I16, I32, I64, I128, // Scalar Integers
795795
F32, F64, // Scalar Floats

crates/c-api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ doctest = false
2222
[dependencies]
2323
env_logger = { workspace = true, optional = true }
2424
anyhow = { workspace = true }
25-
once_cell = { workspace = true }
2625
wasmtime = { workspace = true, features = ['runtime', 'gc', 'std'] }
2726
wasmtime-c-api-macros = { workspace = true }
2827
log = { workspace = true }

crates/c-api/src/trap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{wasm_frame_vec_t, wasm_instance_t, wasm_name_t, wasm_store_t};
22
use anyhow::{anyhow, Error};
3-
use once_cell::unsync::OnceCell;
3+
use std::cell::OnceCell;
44
use wasmtime::{Trap, WasmBacktrace};
55

66
#[repr(C)]

crates/c-api/src/types/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_name_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33

44
#[repr(C)]
55
#[derive(Clone)]

crates/c-api/src/types/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_valtype_t, wasm_valtype_vec_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33
use std::{
44
mem,
55
sync::{Arc, Mutex},

crates/c-api/src/types/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_valtype_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33
use wasmtime::GlobalType;
44

55
pub type wasm_mutability_t = u8;

crates/c-api/src/types/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_name_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33

44
#[repr(C)]
55
#[derive(Clone)]

crates/c-api/src/types/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_limits_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33
use std::convert::TryFrom;
44
use wasmtime::MemoryType;
55

crates/c-api/src/types/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{wasm_externtype_t, wasm_limits_t, wasm_valtype_t, CExternType};
2-
use once_cell::unsync::OnceCell;
2+
use std::cell::OnceCell;
33
use wasmtime::{TableType, ValType};
44

55
#[repr(transparent)]

crates/cache/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ rustix = { workspace = true, features = ["process"] }
3535

3636
[dev-dependencies]
3737
filetime = "0.2.7"
38-
once_cell = { workspace = true }
3938
pretty_env_logger = { workspace = true }
4039
tempfile = "3"

crates/cache/src/worker/tests/system_time_stub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22
use std::time::{Duration, SystemTime, SystemTimeError};
33

4-
pub static NOW: Lazy<SystemTime> = Lazy::new(SystemTime::now);
4+
pub static NOW: LazyLock<SystemTime> = LazyLock::new(SystemTime::now);
55

66
#[derive(PartialOrd, PartialEq, Ord, Eq)]
77
pub struct SystemTimeStub(SystemTime);

crates/fuzzing/wasm-spec-interpreter/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ workspace = true
1717
# `build-libinterpret` feature set by this crate's parent).
1818
[dependencies]
1919
ocaml-interop = { version = "0.8", optional = true }
20-
once_cell = { workspace = true, optional = true }
2120

2221
[dev-dependencies]
2322
wat = { workspace = true }
2423

2524
[features]
26-
build-libinterpret = ["ocaml-interop", "once_cell"]
25+
build-libinterpret = ["ocaml-interop"]

crates/fuzzing/wasm-spec-interpreter/src/with_library.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
3535
use crate::{SpecExport, SpecInstance, SpecValue};
3636
use ocaml_interop::{BoxRoot, OCamlRuntime, ToOCaml};
37-
use once_cell::sync::Lazy;
3837
use std::sync::Mutex;
3938

40-
static INTERPRET: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
39+
static INTERPRET: Mutex<()> = Mutex::new(());
4140

4241
/// Instantiate the WebAssembly module in the spec interpreter.
4342
pub fn instantiate(module: &[u8]) -> Result<SpecInstance, String> {

crates/jit-debug/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ rust-version.workspace = true
1515
workspace = true
1616

1717
[dependencies]
18-
once_cell = { workspace = true, optional = true }
1918
object = { workspace = true, optional = true }
2019
wasmtime-versioned-export-macros = { workspace = true }
2120

2221
[target.'cfg(target_os = "linux")'.dependencies]
2322
rustix = { workspace = true, features = ["mm", "param", "time"], optional = true }
2423

2524
[features]
26-
gdb_jit_int = ["once_cell"]
25+
gdb_jit_int = []
2726
perf_jitdump = ["rustix", "object"]

crates/jit-debug/src/gdb_jit_int.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! the __jit_debug_register_code() and __jit_debug_descriptor to register
33
//! or unregister generated object images with debuggers.
44
5-
use once_cell::sync::Lazy;
65
use std::pin::Pin;
76
use std::ptr;
87
use std::sync::Mutex;
@@ -40,7 +39,7 @@ extern "C" {
4039
///
4140
/// The GDB_REGISTRATION lock is needed for GdbJitImageRegistration to protect
4241
/// access to the __jit_debug_descriptor within this process.
43-
static GDB_REGISTRATION: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(Default::default()));
42+
static GDB_REGISTRATION: Mutex<()> = Mutex::new(());
4443

4544
/// Registration for JIT image
4645
pub struct GdbJitImageRegistration {

crates/wasi-common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ libc = { workspace = true, optional = true }
4343
rustix = { workspace = true, features = ["fs", "event"] }
4444

4545
[target.'cfg(windows)'.dependencies]
46-
once_cell = { workspace = true }
4746
io-extras = { workspace = true }
4847
rustix = { workspace = true, features = ["net"] }
4948

crates/wasi-common/src/sync/sched/windows.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
use crate::sched::subscription::{RwEventFlags, Subscription};
1212
use crate::{file::WasiFile, sched::Poll, Error, ErrorExt};
13-
use once_cell::sync::Lazy;
1413
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
15-
use std::sync::Mutex;
14+
use std::sync::{LazyLock, Mutex};
1615
use std::thread;
1716
use std::time::Duration;
1817

@@ -144,7 +143,7 @@ struct StdinPoll {
144143
notify_rx: Receiver<PollState>,
145144
}
146145

147-
static STDIN_POLL: Lazy<Mutex<StdinPoll>> = Lazy::new(StdinPoll::new);
146+
static STDIN_POLL: LazyLock<Mutex<StdinPoll>> = LazyLock::new(StdinPoll::new);
148147

149148
impl StdinPoll {
150149
pub fn new() -> Mutex<Self> {

crates/wasi/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ async-trait = { workspace = true }
3535
system-interface = { workspace = true}
3636
futures = { workspace = true }
3737
url = { workspace = true }
38-
once_cell = { workspace = true }
3938

4039
[dev-dependencies]
4140
tokio = { workspace = true, features = ["time", "sync", "io-std", "io-util", "rt", "rt-multi-thread", "net", "macros", "fs"] }

crates/wasi/src/runtime.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
2222
use std::future::Future;
2323
use std::pin::Pin;
24+
use std::sync::LazyLock;
2425
use std::task::{Context, Poll};
2526

26-
pub(crate) static RUNTIME: once_cell::sync::Lazy<tokio::runtime::Runtime> =
27-
once_cell::sync::Lazy::new(|| {
28-
tokio::runtime::Builder::new_multi_thread()
29-
.enable_time()
30-
.enable_io()
31-
.build()
32-
.unwrap()
33-
});
27+
pub(crate) static RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| {
28+
tokio::runtime::Builder::new_multi_thread()
29+
.enable_time()
30+
.enable_io()
31+
.build()
32+
.unwrap()
33+
});
3434

3535
/// Exactly like a [`tokio::task::JoinHandle`], except that it aborts the task when
3636
/// the handle is dropped.

crates/wasmtime/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sptr = { workspace = true }
4646
postcard = { workspace = true }
4747
indexmap = { workspace = true }
4848
paste = "1.0.3"
49-
once_cell = { workspace = true }
49+
once_cell = { version = "1.12.0", optional = true }
5050
rayon = { version = "1.0", optional = true }
5151
object = { workspace = true }
5252
async-trait = { workspace = true, optional = true }
@@ -267,7 +267,7 @@ std = [
267267
'wasmtime-component-macro?/std',
268268
'wasmtime-environ/std',
269269
'object/std',
270-
'once_cell/std',
270+
'once_cell',
271271
]
272272

273273
# Enables support for the `Store::call_hook` API which enables injecting custom

crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Mmap {
6767

6868
#[inline]
6969
pub fn len(&self) -> usize {
70-
unsafe { (*self.memory.as_ptr()).len() }
70+
self.memory.as_ptr().len()
7171
}
7272

7373
pub unsafe fn make_executable(
@@ -102,7 +102,7 @@ impl Drop for Mmap {
102102
fn drop(&mut self) {
103103
unsafe {
104104
let ptr = self.memory.as_ptr().cast();
105-
let len = (*self.memory.as_ptr()).len();
105+
let len = self.memory.as_ptr().len();
106106
if len == 0 {
107107
return;
108108
}

crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Mmap {
6868
}
6969

7070
pub fn len(&self) -> usize {
71-
unsafe { (*self.memory.as_ptr()).len() }
71+
self.memory.as_ptr().len()
7272
}
7373

7474
pub unsafe fn make_executable(

0 commit comments

Comments
 (0)