diff --git a/lib/environ/Cargo.toml b/lib/environ/Cargo.toml index be3cd4375c..5cd2d730f0 100644 --- a/lib/environ/Cargo.toml +++ b/lib/environ/Cargo.toml @@ -17,11 +17,12 @@ cranelift-wasm = "0.26.0" cast = { version = "0.2.2", default-features = false } failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } +hashmap_core = { version = "0.1.9", optional = true } [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-wasm/std"] -core = ["cranelift-codegen/core", "cranelift-wasm/core"] +core = ["hashmap_core", "cranelift-codegen/core", "cranelift-wasm/core"] [badges] maintenance = { status = "experimental" } diff --git a/lib/environ/src/func_environ.rs b/lib/environ/src/func_environ.rs index 2ec672f021..588546defb 100644 --- a/lib/environ/src/func_environ.rs +++ b/lib/environ/src/func_environ.rs @@ -2,6 +2,7 @@ use crate::module::{MemoryPlan, MemoryStyle, Module, TableStyle}; use crate::vmoffsets::VMOffsets; use crate::WASM_PAGE_SIZE; use cast; +use core::clone::Clone; use cranelift_codegen::cursor::FuncCursor; use cranelift_codegen::ir; use cranelift_codegen::ir::condcodes::*; @@ -16,7 +17,6 @@ use cranelift_wasm::{ self, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, SignatureIndex, TableIndex, WasmResult, }; -use std::clone::Clone; use std::vec::Vec; /// Compute an `ir::ExternalName` for a given wasm function index. diff --git a/lib/environ/src/lib.rs b/lib/environ/src/lib.rs index dc2a73f7fa..de119446c8 100644 --- a/lib/environ/src/lib.rs +++ b/lib/environ/src/lib.rs @@ -24,14 +24,23 @@ clippy::use_self ) )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(not(feature = "std"), feature(alloc))] -use cranelift_wasm; #[cfg(not(feature = "std"))] #[macro_use] -extern crate alloc; +extern crate alloc as std; +#[cfg(feature = "std")] +#[macro_use] +extern crate std; + +#[cfg(not(feature = "std"))] +use hashmap_core::HashMap; +#[cfg(feature = "std")] +use std::collections::HashMap; + use cast; +use cranelift_wasm; use failure; #[macro_use] extern crate failure_derive; @@ -63,10 +72,3 @@ pub const WASM_PAGE_SIZE: u32 = 0x10000; /// The number of pages we can have before we run out of byte index space. pub const WASM_MAX_PAGES: u32 = 0x10000; - -#[cfg(not(feature = "std"))] -mod std { - pub use alloc::{string, vec}; - pub use core::*; - pub use core::{i32, str, u32}; -} diff --git a/lib/environ/src/module.rs b/lib/environ/src/module.rs index 6ed50d7f70..7d89118019 100644 --- a/lib/environ/src/module.rs +++ b/lib/environ/src/module.rs @@ -1,5 +1,6 @@ //! Data structures for representing decoded wasm modules. +use super::HashMap; use crate::tunables::Tunables; use cranelift_codegen::ir; use cranelift_entity::{EntityRef, PrimaryMap}; @@ -7,7 +8,6 @@ use cranelift_wasm::{ DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, }; -use std::collections::HashMap; use std::string::String; use std::vec::Vec; diff --git a/lib/environ/src/module_environ.rs b/lib/environ/src/module_environ.rs index 9971b32c6c..f3e92b7f25 100644 --- a/lib/environ/src/module_environ.rs +++ b/lib/environ/src/module_environ.rs @@ -1,6 +1,7 @@ use crate::func_environ::FuncEnvironment; use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan}; use crate::tunables::Tunables; +use core::clone::Clone; use cranelift_codegen::ir; use cranelift_codegen::ir::{AbiParam, ArgumentPurpose}; use cranelift_codegen::isa::TargetFrontendConfig; @@ -9,7 +10,6 @@ use cranelift_wasm::{ self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, WasmResult, }; -use std::clone::Clone; use std::string::String; use std::vec::Vec; diff --git a/lib/jit/Cargo.toml b/lib/jit/Cargo.toml index 46ce2cd100..194479d114 100644 --- a/lib/jit/Cargo.toml +++ b/lib/jit/Cargo.toml @@ -20,12 +20,13 @@ wasmtime-runtime = { path = "../runtime" } region = "1.0.0" failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } -target-lexicon = "0.2.0" +target-lexicon = { version = "0.2.0", default-features = false } +hashmap_core = { version = "0.1.9", optional = true } [features] default = ["std"] std = ["cranelift-codegen/std", "cranelift-wasm/std"] -core = ["cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core"] +core = ["hashmap_core", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core"] [badges] maintenance = { status = "experimental" } diff --git a/lib/jit/src/action.rs b/lib/jit/src/action.rs index 3cf5024ed3..abbedde5e0 100644 --- a/lib/jit/src/action.rs +++ b/lib/jit/src/action.rs @@ -2,11 +2,11 @@ use crate::compiler::Compiler; use crate::instantiate::SetupError; +use core::cmp::max; +use core::{fmt, mem, ptr, slice}; use cranelift_codegen::ir; -use std::cmp::max; use std::string::String; use std::vec::Vec; -use std::{fmt, mem, ptr, slice}; use wasmtime_runtime::{wasmtime_call_trampoline, Export, Instance}; /// A runtime value. diff --git a/lib/jit/src/code_memory.rs b/lib/jit/src/code_memory.rs index 5374ad7800..5b24f4c768 100644 --- a/lib/jit/src/code_memory.rs +++ b/lib/jit/src/code_memory.rs @@ -1,9 +1,9 @@ //! Memory management for executable code. +use core::{cmp, mem}; use region; use std::string::String; use std::vec::Vec; -use std::{cmp, mem}; use wasmtime_runtime::{Mmap, VMFunctionBody}; /// Memory manager for executable code. diff --git a/lib/jit/src/compiler.rs b/lib/jit/src/compiler.rs index 1a3e0a2203..2fab3d5120 100644 --- a/lib/jit/src/compiler.rs +++ b/lib/jit/src/compiler.rs @@ -1,5 +1,6 @@ //! JIT compilation. +use super::HashMap; use crate::code_memory::CodeMemory; use crate::instantiate::SetupError; use crate::target_tunables::target_tunables; @@ -11,7 +12,6 @@ use cranelift_entity::PrimaryMap; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use cranelift_wasm::DefinedFuncIndex; use std::boxed::Box; -use std::collections::HashMap; use std::string::String; use std::vec::Vec; use wasmtime_environ::cranelift; @@ -95,7 +95,7 @@ impl Compiler { signature: &ir::Signature, value_size: usize, ) -> Result<*const VMFunctionBody, SetupError> { - use std::collections::hash_map::Entry::{Occupied, Vacant}; + use super::hash_map::Entry::{Occupied, Vacant}; Ok(match self.trampoline_park.entry(callee_address) { Occupied(entry) => *entry.get(), Vacant(entry) => { diff --git a/lib/jit/src/lib.rs b/lib/jit/src/lib.rs index 577fa6d71b..5c7eaf334b 100644 --- a/lib/jit/src/lib.rs +++ b/lib/jit/src/lib.rs @@ -21,18 +21,26 @@ clippy::use_self ) )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(not(feature = "std"), feature(alloc))] +#[cfg(not(feature = "std"))] +#[macro_use] +extern crate alloc as std; +#[cfg(feature = "std")] +#[macro_use] +extern crate std; + +#[cfg(not(feature = "std"))] +use hashmap_core::{map as hash_map, HashMap}; +#[cfg(feature = "std")] +use std::collections::{hash_map, HashMap}; + #[macro_use] extern crate cranelift_entity; -use region; - -#[cfg(not(feature = "std"))] -#[macro_use] -extern crate alloc; use failure; +use region; #[macro_use] extern crate failure_derive; @@ -57,10 +65,3 @@ pub use crate::target_tunables::target_tunables; // Re-export `Instance` so that users won't need to separately depend on // wasmtime-runtime in common cases. pub use wasmtime_runtime::{Instance, InstantiationError}; - -#[cfg(not(feature = "std"))] -mod std { - pub use alloc::{boxed, rc, string, vec}; - pub use core::*; - pub use core::{i32, str, u32}; -} diff --git a/lib/jit/src/link.rs b/lib/jit/src/link.rs index 9cfdef857f..47c87c1960 100644 --- a/lib/jit/src/link.rs +++ b/lib/jit/src/link.rs @@ -1,10 +1,10 @@ //! Linking for JIT-compiled code. use crate::resolver::Resolver; +use core::ptr::write_unaligned; use cranelift_codegen::binemit::Reloc; use cranelift_entity::PrimaryMap; use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType}; -use std::ptr::write_unaligned; use std::vec::Vec; use wasmtime_environ::{ MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan, diff --git a/lib/jit/src/namespace.rs b/lib/jit/src/namespace.rs index dda170f824..7794066eeb 100644 --- a/lib/jit/src/namespace.rs +++ b/lib/jit/src/namespace.rs @@ -2,12 +2,12 @@ //! to exports. This file provides one possible way to manage multiple instances //! and resolve imports to exports among them. +use super::HashMap; use crate::action::{get, inspect_memory, invoke}; use crate::action::{ActionError, ActionOutcome, RuntimeValue}; use crate::compiler::Compiler; use crate::resolver::Resolver; use cranelift_entity::PrimaryMap; -use std::collections::HashMap; use std::string::String; use wasmtime_runtime::{Export, Instance}; diff --git a/lib/jit/src/target_tunables.rs b/lib/jit/src/target_tunables.rs index 2fd5b4848f..dfeac9fbc7 100644 --- a/lib/jit/src/target_tunables.rs +++ b/lib/jit/src/target_tunables.rs @@ -1,4 +1,4 @@ -use std::cmp::min; +use core::cmp::min; use target_lexicon::{OperatingSystem, Triple}; use wasmtime_environ::Tunables; diff --git a/lib/runtime/src/instance.rs b/lib/runtime/src/instance.rs index 4959f3c67a..8fb8a36f90 100644 --- a/lib/runtime/src/instance.rs +++ b/lib/runtime/src/instance.rs @@ -13,16 +13,17 @@ use crate::vmcontext::{ VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, }; +use core::slice; +use core::{mem, ptr}; use cranelift_entity::EntityRef; use cranelift_entity::{BoxedSlice, PrimaryMap}; use cranelift_wasm::{ DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex, }; +use std::borrow::ToOwned; use std::rc::Rc; -use std::slice; use std::string::String; -use std::{mem, ptr}; use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets}; fn signature_id( diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 5086f654bd..9afcf725c1 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -21,15 +21,24 @@ clippy::use_self ) )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(not(feature = "std"), feature(alloc))] +#[cfg(not(feature = "std"))] +#[macro_use] +extern crate alloc as std; +#[cfg(feature = "std")] +#[macro_use] +extern crate std; + +#[cfg(not(feature = "std"))] +use hashmap_core::{map as hash_map, HashMap}; +#[cfg(feature = "std")] +use std::collections::{hash_map, HashMap}; + use errno; use region; -#[cfg(not(feature = "std"))] -#[macro_use] -extern crate alloc; #[macro_use] extern crate lazy_static; use libc; @@ -66,10 +75,3 @@ pub use crate::vmcontext::{ VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, }; - -#[cfg(not(feature = "std"))] -mod std { - pub use alloc::{string, vec}; - pub use core::*; - pub use core::{i32, str, u32}; -} diff --git a/lib/runtime/src/mmap.rs b/lib/runtime/src/mmap.rs index fef3004ed3..cb11aedadb 100644 --- a/lib/runtime/src/mmap.rs +++ b/lib/runtime/src/mmap.rs @@ -1,12 +1,13 @@ //! Low-level abstraction for allocating and managing zero-filled pages //! of memory. +use core::ptr; +use core::slice; use errno; use libc; use region; -use std::ptr; -use std::slice; -use std::string::String; +use std::string::{String, ToString}; +use std::vec::Vec; /// Round `size` up to the nearest multiple of `page_size`. fn round_up_to_page_size(size: usize, page_size: usize) -> usize { diff --git a/lib/runtime/src/sig_registry.rs b/lib/runtime/src/sig_registry.rs index 73d8cf1439..79a175a5e8 100644 --- a/lib/runtime/src/sig_registry.rs +++ b/lib/runtime/src/sig_registry.rs @@ -1,10 +1,10 @@ //! Implement a registry of function signatures, for fast indirect call //! signature checking. +use super::{hash_map, HashMap}; use crate::vmcontext::VMSharedSignatureIndex; use cast; use cranelift_codegen::ir; -use std::collections::{hash_map, HashMap}; /// WebAssembly requires that the caller and callee signatures in an indirect /// call must match. To implement this efficiently, keep a registry of all diff --git a/lib/runtime/src/signalhandlers.rs b/lib/runtime/src/signalhandlers.rs index ddbc8d3ecf..3a4a052969 100644 --- a/lib/runtime/src/signalhandlers.rs +++ b/lib/runtime/src/signalhandlers.rs @@ -5,8 +5,8 @@ #![allow(non_snake_case)] use crate::vmcontext::VMContext; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; +use core::borrow::{Borrow, BorrowMut}; +use core::cell::RefCell; use std::sync::RwLock; include!(concat!(env!("OUT_DIR"), "/signalhandlers.rs")); diff --git a/lib/runtime/src/table.rs b/lib/runtime/src/table.rs index 5665445b19..62c6f5db36 100644 --- a/lib/runtime/src/table.rs +++ b/lib/runtime/src/table.rs @@ -4,6 +4,7 @@ use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; use cranelift_wasm::TableElementType; +use std::vec::Vec; use wasmtime_environ::{TablePlan, TableStyle}; /// A table instance. diff --git a/lib/runtime/src/traphandlers.rs b/lib/runtime/src/traphandlers.rs index d3b34ee2f0..3339320c09 100644 --- a/lib/runtime/src/traphandlers.rs +++ b/lib/runtime/src/traphandlers.rs @@ -3,11 +3,12 @@ use crate::signalhandlers::jmp_buf; use crate::vmcontext::{VMContext, VMFunctionBody}; +use core::cell::{Cell, RefCell}; +use core::mem; +use core::ptr; use libc::c_int; -use std::cell::{Cell, RefCell}; -use std::mem; -use std::ptr; use std::string::String; +use std::vec::Vec; // Currently we uset setjmp/longjmp to unwind out of a signal handler // and back to the point where WebAssembly was called (via `call_wasm`). diff --git a/lib/runtime/src/vmcontext.rs b/lib/runtime/src/vmcontext.rs index 03013b4c9c..3d8780e170 100644 --- a/lib/runtime/src/vmcontext.rs +++ b/lib/runtime/src/vmcontext.rs @@ -2,7 +2,7 @@ //! fields that compiled wasm code accesses directly. use crate::instance::InstanceContents; -use std::{ptr, u32}; +use core::{ptr, u32}; /// An imported function. #[derive(Debug, Copy, Clone)] @@ -18,7 +18,7 @@ pub struct VMFunctionImport { #[cfg(test)] mod test_vmfunction_import { use super::VMFunctionImport; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -50,7 +50,7 @@ pub struct VMFunctionBody(u8); #[cfg(test)] mod test_vmfunction_body { use super::VMFunctionBody; - use std::mem::size_of; + use core::mem::size_of; #[test] fn check_vmfunction_body_offsets() { @@ -73,7 +73,7 @@ pub struct VMTableImport { #[cfg(test)] mod test_vmtable_import { use super::VMTableImport; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -110,7 +110,7 @@ pub struct VMMemoryImport { #[cfg(test)] mod test_vmmemory_import { use super::VMMemoryImport; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -144,7 +144,7 @@ pub struct VMGlobalImport { #[cfg(test)] mod test_vmglobal_import { use super::VMGlobalImport; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -178,7 +178,7 @@ pub struct VMMemoryDefinition { #[cfg(test)] mod test_vmmemory_definition { use super::VMMemoryDefinition; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -221,7 +221,7 @@ pub struct VMTableDefinition { #[cfg(test)] mod test_vmtable_definition { use super::VMTableDefinition; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -257,7 +257,7 @@ pub struct VMGlobalDefinition { #[cfg(test)] mod test_vmglobal_definition { use super::VMGlobalDefinition; - use std::mem::{align_of, size_of}; + use core::mem::{align_of, size_of}; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -391,7 +391,7 @@ pub struct VMSharedSignatureIndex(u32); #[cfg(test)] mod test_vmshared_signature_index { use super::VMSharedSignatureIndex; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test] @@ -427,7 +427,7 @@ pub struct VMCallerCheckedAnyfunc { #[cfg(test)] mod test_vmcaller_checked_anyfunc { use super::VMCallerCheckedAnyfunc; - use std::mem::size_of; + use core::mem::size_of; use wasmtime_environ::{Module, VMOffsets}; #[test]