Skip to content

Commit

Permalink
Adjust no_std usage in Wasmi workspace crates (#1307)
Browse files Browse the repository at this point in the history
* adjust no_std usage in wasmi_core

* adjust no_std usage for wasmi_collections

* adjust no_std usage for wasmi_ir

* adjust no_std usage in wasmi

* apply rustfmt
  • Loading branch information
Robbepop authored Nov 13, 2024
1 parent 2b1d912 commit 6081afc
Show file tree
Hide file tree
Showing 49 changed files with 61 additions and 71 deletions.
2 changes: 1 addition & 1 deletion crates/collections/src/arena/component_vec.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::arena::ArenaIndex;
use alloc::vec::Vec;
use core::{
fmt::{self, Debug},
marker::PhantomData,
ops::{Index, IndexMut},
};
use std::vec::Vec;

/// Stores components for entities backed by a [`Vec`].
pub struct ComponentVec<Idx, T> {
Expand Down
2 changes: 1 addition & 1 deletion crates/collections/src/arena/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ mod dedup;
mod guarded;

pub use self::{component_vec::ComponentVec, dedup::DedupArena, guarded::GuardedEntity};
use alloc::vec::Vec;
use core::{
iter::Enumerate,
marker::PhantomData,
ops::{Index, IndexMut, Range},
slice,
};
use std::vec::Vec;

/// Types that can be used as indices for arenas.
pub trait ArenaIndex: Copy {
Expand Down
2 changes: 1 addition & 1 deletion crates/collections/src/head_vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec::Vec;
use core::mem;
use std::vec::Vec;

/// A [`Vec`]-like data structure with fast access to the last item.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
4 changes: 1 addition & 3 deletions crates/collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
clippy::items_after_statements
)]

#[cfg(not(feature = "std"))]
extern crate alloc as std;

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

Expand Down
5 changes: 2 additions & 3 deletions crates/collections/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Type definitions for a default map.

use core::{borrow::Borrow, hash::Hash, iter::FusedIterator, ops::Index};
use std::fmt::Debug;
use core::{borrow::Borrow, fmt::Debug, hash::Hash, iter::FusedIterator, ops::Index};

#[cfg(all(
feature = "hash-collections",
Expand Down Expand Up @@ -30,7 +29,7 @@ mod detail {
feature = "prefer-btree-collections"
))]
mod detail {
use std::collections::btree_map;
use alloc::collections::btree_map;

pub type MapImpl<K, V> = btree_map::BTreeMap<K, V>;
pub type EntryImpl<'a, K, V> = btree_map::Entry<'a, K, V>;
Expand Down
2 changes: 1 addition & 1 deletion crates/collections/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod detail {
feature = "prefer-btree-collections"
))]
mod detail {
use std::collections::btree_set;
use alloc::collections::btree_set;

pub type SetImpl<T> = btree_set::BTreeSet<T>;
pub type IterImpl<'a, T> = btree_set::Iter<'a, T>;
Expand Down
4 changes: 2 additions & 2 deletions crates/collections/src/string_interner/detail.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{GetOrInternWithHint, InternHint, Sym};
use core::{cmp::Ordering, mem, ops::Deref};
use std::{
use alloc::{
borrow::Borrow,
collections::{btree_map::Entry, BTreeMap},
sync::Arc,
vec::Vec,
};
use core::{cmp::Ordering, mem, ops::Deref};

pub type StringInternerImpl = StringInterner;

Expand Down
4 changes: 1 addition & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ mod units;
mod untyped;
mod value;

#[cfg(not(feature = "std"))]
extern crate alloc as std;

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/trap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::HostError;
use alloc::{boxed::Box, string::String};
use core::fmt::{self, Display};
use std::{boxed::Box, string::String};

#[cfg(feature = "std")]
use std::error::Error as StdError;
Expand Down
6 changes: 2 additions & 4 deletions crates/ir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc as std;
#![no_std]

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

Expand Down
2 changes: 1 addition & 1 deletion crates/ir/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ::core::{
num::{NonZeroI32, NonZeroI64, NonZeroU32, NonZeroU64},
slice,
};
use std::{boxed::Box, vec::Vec};
use alloc::{boxed::Box, vec::Vec};

/// A sequence of [`Instruction`]s.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/code_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
Config,
Error,
};
use alloc::boxed::Box;
use core::{
fmt,
mem::{self, MaybeUninit},
Expand All @@ -30,7 +31,6 @@ use core::{
slice,
};
use spin::Mutex;
use std::boxed::Box;
use wasmparser::{FuncToValidate, ValidatorResources, WasmFeatures};

/// A reference to a compiled function stored in the [`CodeMap`] of an [`Engine`](crate::Engine).
Expand Down
3 changes: 1 addition & 2 deletions crates/wasmi/src/engine/executor/instrs/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use crate::{
Instance,
Store,
};
use core::array;
use std::fmt;
use core::{array, fmt};

/// Dispatches and executes the host function.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/executor/stack/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
ir::RegSpan,
Instance,
};
use std::vec::Vec;
use alloc::vec::Vec;

#[cfg(doc)]
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/executor/stack/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::{
engine::code_map::CompiledFuncRef,
ir::Reg,
};
use alloc::vec::Vec;
use core::{
fmt::{self, Debug},
mem::{self, MaybeUninit},
ops::Range,
ptr,
slice,
};
use std::vec::Vec;

#[cfg(doc)]
use super::calls::CallFrame;
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmi/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ use crate::{
FuncType,
StoreContextMut,
};
use core::sync::atomic::{AtomicU32, Ordering};
use spin::{Mutex, RwLock};
use std::{
use alloc::{
sync::{Arc, Weak},
vec::Vec,
};
use core::sync::atomic::{AtomicU32, Ordering};
use spin::{Mutex, RwLock};
use wasmparser::{FuncToValidate, FuncValidatorAllocations, ValidatorResources};

#[cfg(doc)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/control_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
engine::translator::{Provider, ProviderSliceStack},
Error,
};
use std::vec::{Drain, Vec};
use alloc::vec::{Drain, Vec};

/// An acquired branch target.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/instr_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use crate::{
module::ModuleHeader,
Error,
};
use alloc::vec::{Drain, Vec};
use core::mem;
use std::vec::{Drain, Vec};

/// A reference to an instruction of the partially
/// constructed function body of the [`InstrEncoder`].
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/labels.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::Instr;
use crate::{ir::BranchOffset, Error};
use alloc::vec::Vec;
use core::{
fmt::{self, Display},
slice::Iter as SliceIter,
};
use std::vec::Vec;

/// A label during the Wasmi compilation process.
#[derive(Debug, Copy, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ use crate::{
FuncRef,
FuncType,
};
use alloc::vec::Vec;
use core::fmt;
use stack::RegisterSpace;
use std::vec::Vec;
use utils::Wrap;
use wasmparser::{
BinaryReaderError,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ir::{AnyConst32, Reg},
Error,
};
use std::vec::{Drain, Vec};
use alloc::vec::{Drain, Vec};

#[cfg(doc)]
use super::Instruction;
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/translator/stack/consts.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::Reg;
use crate::{core::UntypedVal, engine::TranslationError, Error};
use core::{iter::Rev, slice::Iter as SliceIter};
use std::{
use alloc::{
collections::{btree_map, BTreeMap},
vec::Vec,
};
use core::{iter::Rev, slice::Iter as SliceIter};

/// A pool of deduplicated function local constant values.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/translator/stack/locals.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{ir::Reg, Error};
use core::mem;
use std::{
use alloc::{
collections::{btree_map, BTreeMap},
vec::Vec,
};
use core::mem;

#[cfg(doc)]
use super::ProviderStack;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
ir::{Reg, RegSpan},
Error,
};
use std::vec::Vec;
use alloc::vec::Vec;

/// Typed inputs to Wasmi bytecode instructions.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/stack/provider.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{LocalRefs, RegisterAlloc, TypedVal};
use crate::{engine::translator::PreservedLocal, ir::Reg, Error};
use alloc::vec::Vec;
use arrayvec::ArrayVec;
use std::vec::Vec;

#[cfg(doc)]
use crate::core::UntypedVal;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/translator/stack/register_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::{
ir::{Reg, RegSpan},
Error,
};
use alloc::collections::BTreeSet;
use core::{
cmp::{max, min},
num::NonZeroUsize,
};
use multi_stash::{Key, Key as StashKey, MultiStash};
use std::collections::BTreeSet;

#[cfg(doc)]
use crate::engine::translator::InstrEncoder;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
engine::{ResumableHostError, TranslationError},
module::ReadError,
};
use alloc::{boxed::Box, string::String};
use core::{fmt, fmt::Display};
use std::{boxed::Box, string::String};
use wasmparser::BinaryReaderError as WasmError;

/// The generic Wasmi root error type.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/externref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
AsContextMut,
StoreContext,
};
use alloc::boxed::Box;
use core::{any::Any, mem, num::NonZeroU32};
use std::boxed::Box;

/// A raw index to a function entity.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/func/func_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{core::ValType, func::FuncError, Val};
use alloc::{sync::Arc, vec::Vec};
use core::fmt;
use std::{sync::Arc, vec::Vec};

/// A function type representing a function's parameter and result types.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/func/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use super::{
Stored,
};
use crate::{collections::arena::ArenaIndex, engine::ResumableCall, Engine, Error, Val};
use alloc::{boxed::Box, sync::Arc};
use core::{fmt, fmt::Debug, num::NonZeroU32};
use std::{boxed::Box, sync::Arc};

/// A raw index to a function entity.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/instance/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
Module,
Table,
};
use std::{boxed::Box, sync::Arc, vec::Vec};
use alloc::{boxed::Box, sync::Arc, vec::Vec};

/// A module instance entity builder.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/instance/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
Table,
TableType,
};
use alloc::boxed::Box;
use core::iter::FusedIterator;
use std::boxed::Box;

/// An external item to a WebAssembly module.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
WasmParams,
WasmResults,
};
use std::{boxed::Box, sync::Arc};
use alloc::{boxed::Box, sync::Arc};

mod builder;
mod exports;
Expand Down
4 changes: 1 addition & 3 deletions crates/wasmi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@
)]
#![recursion_limit = "750"]

#[cfg(not(feature = "std"))]
extern crate alloc as std;

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

Expand Down
10 changes: 5 additions & 5 deletions crates/wasmi/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use crate::{
TableType,
Val,
};
use core::{
fmt::{self, Debug, Display},
marker::PhantomData,
};
use std::{
use alloc::{
collections::{btree_map::Entry, BTreeMap},
sync::Arc,
vec::Vec,
};
use core::{
fmt::{self, Debug, Display},
marker::PhantomData,
};

/// An error that may occur upon operating with [`Linker`] instances.
#[derive(Debug)]
Expand Down
Loading

0 comments on commit 6081afc

Please sign in to comment.