Remove the need for HostRef<Store> (#771)

* Remove the need for `HostRef<Store>`

This commit goes through the public API of the `wasmtime` crate and
removes the need for `HostRef<Store>`, as discussed in #708. This commit
is accompanied with a few changes:

* The `Store` type now also implements `Default`, creating a new
  `Engine` with default settings and returning that.

* The `Store` type now implements `Clone`, and is documented as being a
  "cheap clone" aka being reference counted. As before there is no
  supported way to create a deep clone of a `Store`.

* All APIs take/return `&Store` or `Store` instead of `HostRef<Store>`,
  and `HostRef<T>` is left as purely a detail of the C API.

* The `global_exports` function is tagged as `#[doc(hidden)]` for now
  while we await its removal.

* The `Store` type is not yet `Send` nor `Sync` due to the usage of
  `global_exports`, but it is intended to become so eventually.

* Touch up comments on some examples

* Run rustfmt
This commit is contained in:
Alex Crichton
2020-01-07 16:29:44 -06:00
committed by GitHub
parent 296ebc46fd
commit 045d6a7310
31 changed files with 163 additions and 155 deletions

View File

@@ -7,10 +7,7 @@ use wasmtime::{
};
/// Create a set of dummy functions/globals/etc for the given imports.
pub fn dummy_imports(
store: &HostRef<Store>,
import_tys: &[ImportType],
) -> Result<Vec<Extern>, Trap> {
pub fn dummy_imports(store: &Store, import_tys: &[ImportType]) -> Result<Vec<Extern>, Trap> {
let mut imports = Vec::with_capacity(import_tys.len());
for imp in import_tys {
imports.push(match imp.ty() {
@@ -38,7 +35,7 @@ pub struct DummyFunc(FuncType);
impl DummyFunc {
/// Construct a new dummy `Func`.
pub fn new(store: &HostRef<Store>, ty: FuncType) -> Func {
pub fn new(store: &Store, ty: FuncType) -> Func {
let callable = DummyFunc(ty.clone());
Func::new(store, ty, Rc::new(callable) as _)
}
@@ -80,18 +77,18 @@ pub fn dummy_value(val_ty: &ValType) -> Result<Val, Trap> {
}
/// Construct a dummy global for the given global type.
pub fn dummy_global(store: &HostRef<Store>, ty: GlobalType) -> Result<Global, Trap> {
pub fn dummy_global(store: &Store, ty: GlobalType) -> Result<Global, Trap> {
let val = dummy_value(ty.content())?;
Ok(Global::new(store, ty, val))
}
/// Construct a dummy table for the given table type.
pub fn dummy_table(store: &HostRef<Store>, ty: TableType) -> Result<Table, Trap> {
pub fn dummy_table(store: &Store, ty: TableType) -> Result<Table, Trap> {
let init_val = dummy_value(&ty.element())?;
Ok(Table::new(store, ty, init_val))
}
/// Construct a dummy memory for the given memory type.
pub fn dummy_memory(store: &HostRef<Store>, ty: MemoryType) -> Memory {
pub fn dummy_memory(store: &Store, ty: MemoryType) -> Memory {
Memory::new(store, ty)
}