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

@@ -43,8 +43,7 @@ use wasmtime_runtime::Export;
/// "#)?;
///
/// // Initialise environment and our module.
/// let engine = wasmtime::Engine::default();
/// let store = HostRef::new(wasmtime::Store::new(&engine));
/// let store = wasmtime::Store::default();
/// let module = HostRef::new(wasmtime::Module::new(&store, &binary)?);
///
/// // Define the type of the function we're going to call.
@@ -103,13 +102,13 @@ pub(crate) trait WrappedCallable {
}
pub(crate) struct WasmtimeFn {
store: HostRef<Store>,
store: Store,
instance: InstanceHandle,
export: Export,
}
impl WasmtimeFn {
pub fn new(store: &HostRef<Store>, instance: InstanceHandle, export: Export) -> WasmtimeFn {
pub fn new(store: &Store, instance: InstanceHandle, export: Export) -> WasmtimeFn {
WasmtimeFn {
store: store.clone(),
instance,
@@ -146,7 +145,6 @@ impl WrappedCallable for WasmtimeFn {
// Get the trampoline to call for this function.
let exec_code_buf = self
.store
.borrow_mut()
.context()
.compiler()
.get_published_trampoline(body, &signature, value_size)
@@ -191,11 +189,7 @@ pub struct NativeCallable {
}
impl NativeCallable {
pub(crate) fn new(
callable: Rc<dyn Callable + 'static>,
ft: &FuncType,
store: &HostRef<Store>,
) -> Self {
pub(crate) fn new(callable: Rc<dyn Callable + 'static>, ft: &FuncType, store: &Store) -> Self {
let (instance, export) =
generate_func_export(ft, &callable, store).expect("generated func");
NativeCallable {