Skip to content

Commit

Permalink
refactor: Replace once_cell to std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Jun 3, 2023
1 parent f7ae056 commit f88d75e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/c-api/src/trap.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/export.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/func.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/global.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/import.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/memory.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/types/table.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Result<(), String>>,
compatible_with_native_host: OnceLock<Result<(), String>>,
}

impl Engine {
Expand Down Expand Up @@ -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(),
}),
})
}
Expand Down
13 changes: 8 additions & 5 deletions crates/wasmtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Option<ModuleMemoryImages>>,
memory_images: OnceLock<Option<ModuleMemoryImages>>,

/// Flag indicating whether this module can be serialized or not.
serializable: bool,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1026,7 +1026,10 @@ impl ModuleInner {
fn memory_images(&self) -> Result<Option<&ModuleMemoryImages>> {
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)
}
Expand Down

0 comments on commit f88d75e

Please sign in to comment.