diff --git a/crates/c-api/src/trap.rs b/crates/c-api/src/trap.rs index 44b9dfb6043b..4d354077595f 100644 --- a/crates/c-api/src/trap.rs +++ b/crates/c-api/src/trap.rs @@ -1,6 +1,6 @@ use crate::{wasm_frame_vec_t, wasm_instance_t, wasm_name_t, wasm_store_t}; use anyhow::{anyhow, Error}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::{Trap, WasmBacktrace}; #[repr(C)] diff --git a/crates/c-api/src/types/export.rs b/crates/c-api/src/types/export.rs index 3d83cc41faca..0f3a63a4e468 100644 --- a/crates/c-api/src/types/export.rs +++ b/crates/c-api/src/types/export.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_name_t}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::ExternType; #[repr(C)] diff --git a/crates/c-api/src/types/func.rs b/crates/c-api/src/types/func.rs index 1b4ca752febf..2d8ebb540320 100644 --- a/crates/c-api/src/types/func.rs +++ b/crates/c-api/src/types/func.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_valtype_t, wasm_valtype_vec_t, CExternType}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::FuncType; #[repr(transparent)] diff --git a/crates/c-api/src/types/global.rs b/crates/c-api/src/types/global.rs index 9fde1f304dc1..3b8eccdf561b 100644 --- a/crates/c-api/src/types/global.rs +++ b/crates/c-api/src/types/global.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_valtype_t, CExternType}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::GlobalType; pub type wasm_mutability_t = u8; diff --git a/crates/c-api/src/types/import.rs b/crates/c-api/src/types/import.rs index f9e97a287074..99331fc555c9 100644 --- a/crates/c-api/src/types/import.rs +++ b/crates/c-api/src/types/import.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_name_t}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::ExternType; #[repr(C)] diff --git a/crates/c-api/src/types/memory.rs b/crates/c-api/src/types/memory.rs index 45f9a5c19f99..6683bef52d63 100644 --- a/crates/c-api/src/types/memory.rs +++ b/crates/c-api/src/types/memory.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_limits_t, CExternType}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use std::convert::TryFrom; use wasmtime::MemoryType; diff --git a/crates/c-api/src/types/table.rs b/crates/c-api/src/types/table.rs index 6599baecd10d..eac0791d9d62 100644 --- a/crates/c-api/src/types/table.rs +++ b/crates/c-api/src/types/table.rs @@ -1,5 +1,5 @@ use crate::{wasm_externtype_t, wasm_limits_t, wasm_valtype_t, CExternType}; -use once_cell::unsync::OnceCell; +use std::cell::OnceCell; use wasmtime::TableType; #[repr(transparent)] diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rs index 521aa118afbb..d6f92a5a72b2 100644 --- a/crates/wasmtime/src/engine.rs +++ b/crates/wasmtime/src/engine.rs @@ -3,12 +3,12 @@ use crate::Config; use anyhow::{Context, Result}; use object::write::{Object, StandardSegment}; use object::SectionKind; -use once_cell::sync::OnceCell; #[cfg(feature = "parallel-compilation")] use rayon::prelude::*; use std::path::Path; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; +use std::sync::OnceLock; #[cfg(feature = "cache")] use wasmtime_cache::CacheConfig; use wasmtime_environ::obj; @@ -57,7 +57,7 @@ struct EngineInner { // One-time check of whether the compiler's settings, if present, are // compatible with the native host. - compatible_with_native_host: OnceCell>, + compatible_with_native_host: OnceLock>, } impl Engine { @@ -100,7 +100,7 @@ impl Engine { signatures: registry, epoch: AtomicU64::new(0), unique_id_allocator: CompiledModuleIdAllocator::new(), - compatible_with_native_host: OnceCell::new(), + compatible_with_native_host: OnceLock::new(), }), }) } diff --git a/crates/wasmtime/src/module.rs b/crates/wasmtime/src/module.rs index 71c1237e7ad9..f345b7d07125 100644 --- a/crates/wasmtime/src/module.rs +++ b/crates/wasmtime/src/module.rs @@ -5,13 +5,13 @@ use crate::{ Engine, }; use anyhow::{bail, Context, Result}; -use once_cell::sync::OnceCell; use std::fs; use std::mem; use std::ops::Range; use std::path::Path; use std::ptr::NonNull; use std::sync::Arc; +use std::sync::OnceLock; use wasmparser::{Parser, ValidPayload, Validator}; use wasmtime_environ::{ DefinedFuncIndex, DefinedMemoryIndex, HostPtr, ModuleEnvironment, ModuleTypes, ObjectKind, @@ -115,12 +115,12 @@ struct ModuleInner { /// A set of initialization images for memories, if any. /// - /// Note that this is behind a `OnceCell` to lazily create this image. On + /// Note that this is behind a `OnceLock` to lazily create this image. On /// Linux where `memfd_create` may be used to create the backing memory /// image this is a pretty expensive operation, so by deferring it this /// improves memory usage for modules that are created but may not ever be /// instantiated. - memory_images: OnceCell>, + memory_images: OnceLock>, /// Flag indicating whether this module can be serialized or not. serializable: bool, @@ -586,7 +586,7 @@ impl Module { inner: Arc::new(ModuleInner { engine: engine.clone(), code, - memory_images: OnceCell::new(), + memory_images: OnceLock::new(), module, serializable, offsets, @@ -1026,7 +1026,10 @@ impl ModuleInner { fn memory_images(&self) -> Result> { let images = self .memory_images - .get_or_try_init(|| memory_images(&self.engine, &self.module))? + .get_or_init(|| match memory_images(&self.engine, &self.module) { + Ok(v) => v, + Err(_e) => None, + }) .as_ref(); Ok(images) }