Migrate back to std:: stylistically (#554)

* Migrate back to `std::` stylistically

This commit moves away from idioms such as `alloc::` and `core::` as
imports of standard data structures and types. Instead it migrates all
crates to uniformly use `std::` for importing standard data structures
and types. This also removes the `std` and `core` features from all
crates to and removes any conditional checking for `feature = "std"`

All of this support was previously added in #407 in an effort to make
wasmtime/cranelift "`no_std` compatible". Unfortunately though this
change comes at a cost:

* The usage of `alloc` and `core` isn't idiomatic. Especially trying to
  dual between types like `HashMap` from `std` as well as from
  `hashbrown` causes imports to be surprising in some cases.
* Unfortunately there was no CI check that crates were `no_std`, so none
  of them actually were. Many crates still imported from `std` or
  depended on crates that used `std`.

It's important to note, however, that **this does not mean that wasmtime
will not run in embedded environments**. The style of the code today and
idioms aren't ready in Rust to support this degree of multiplexing and
makes it somewhat difficult to keep up with the style of `wasmtime`.
Instead it's intended that embedded runtime support will be added as
necessary. Currently only `std` is necessary to build `wasmtime`, and
platforms that natively need to execute `wasmtime` will need to use a
Rust target that supports `std`. Note though that not all of `std` needs
to be supported, but instead much of it could be configured off to
return errors, and `wasmtime` would be configured to gracefully handle
errors.

The goal of this PR is to move `wasmtime` back to idiomatic usage of
features/`std`/imports/etc and help development in the short-term.
Long-term when platform concerns arise (if any) they can be addressed by
moving back to `no_std` crates (but fixing the issues mentioned above)
or ensuring that the target in Rust has `std` available.

* Start filling out platform support doc
This commit is contained in:
Alex Crichton
2019-11-19 00:04:06 -06:00
committed by Dan Gohman
parent c423a1c2f0
commit 39e57e3e9a
99 changed files with 271 additions and 444 deletions

View File

@@ -10,9 +10,8 @@ use super::{
HostInfo, HostRef, ImportType, Instance, Limits, Memory, MemoryType, Module, Name, Store,
Table, TableType, Trap, Val, ValType,
};
use alloc::boxed::Box;
use alloc::rc::Rc;
use core::{mem, ptr, slice};
use std::rc::Rc;
use std::{mem, ptr, slice};
macro_rules! declare_vec {
($name:ident, $elem_ty:path) => {
@@ -343,12 +342,12 @@ pub struct wasm_func_t {
func: HostRef<Func>,
ext: Option<Box<wasm_extern_t>>,
}
pub type wasm_func_callback_t = ::core::option::Option<
pub type wasm_func_callback_t = std::option::Option<
unsafe extern "C" fn(args: *const wasm_val_t, results: *mut wasm_val_t) -> *mut wasm_trap_t,
>;
pub type wasm_func_callback_with_env_t = ::core::option::Option<
pub type wasm_func_callback_with_env_t = std::option::Option<
unsafe extern "C" fn(
env: *mut ::core::ffi::c_void,
env: *mut std::ffi::c_void,
args: *const wasm_val_t,
results: *mut wasm_val_t,
) -> *mut wasm_trap_t,
@@ -567,8 +566,8 @@ impl Into<HostRef<Trap>> for wasm_trap_t {
struct CallbackWithEnv {
callback: wasm_func_callback_with_env_t,
env: *mut ::core::ffi::c_void,
finalizer: ::core::option::Option<unsafe extern "C" fn(env: *mut ::core::ffi::c_void)>,
env: *mut std::ffi::c_void,
finalizer: std::option::Option<unsafe extern "C" fn(env: *mut std::ffi::c_void)>,
}
impl Callable for CallbackWithEnv {
@@ -799,8 +798,8 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
store: *mut wasm_store_t,
ty: *const wasm_functype_t,
callback: wasm_func_callback_with_env_t,
env: *mut ::core::ffi::c_void,
finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
env: *mut std::ffi::c_void,
finalizer: std::option::Option<unsafe extern "C" fn(arg1: *mut std::ffi::c_void)>,
) -> *mut wasm_func_t {
let store = &(*store).store;
let ty = (*ty).functype.clone();
@@ -1614,8 +1613,8 @@ pub unsafe extern "C" fn wasm_tabletype_new(
}
struct HostInfoState {
info: *mut ::core::ffi::c_void,
finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
info: *mut std::ffi::c_void,
finalizer: std::option::Option<unsafe extern "C" fn(arg1: *mut std::ffi::c_void)>,
}
impl HostInfo for HostInfoState {
@@ -1631,8 +1630,8 @@ impl HostInfo for HostInfoState {
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_set_host_info_with_finalizer(
instance: *mut wasm_instance_t,
info: *mut ::core::ffi::c_void,
finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
info: *mut std::ffi::c_void,
finalizer: std::option::Option<unsafe extern "C" fn(arg1: *mut std::ffi::c_void)>,
) {
let info = if info.is_null() && finalizer.is_none() {
None