From 1b682bf35335d09b4efc9f62438f48a0ada95d75 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 17 Jan 2020 14:31:00 -0800 Subject: [PATCH 1/2] Delete runtime-core::mono_vec --- lib/runtime-core/src/structures/mono_vec.rs | 85 --------------------- 1 file changed, 85 deletions(-) delete mode 100644 lib/runtime-core/src/structures/mono_vec.rs diff --git a/lib/runtime-core/src/structures/mono_vec.rs b/lib/runtime-core/src/structures/mono_vec.rs deleted file mode 100644 index fe19d2510..000000000 --- a/lib/runtime-core/src/structures/mono_vec.rs +++ /dev/null @@ -1,85 +0,0 @@ -#[derive(Debug, Clone)] -enum MonoVecInner { - None, - Inline(T), - Heap(Vec), -} - -/// A type that can hold zero items, -/// one item, or many items. -#[derive(Debug, Clone)] -pub struct MonoVec { - inner: MonoVecInner, -} - -impl MonoVec { - pub fn new() -> Self { - Self { - inner: MonoVecInner::None, - } - } - - pub fn new_inline(item: T) -> Self { - Self { - inner: MonoVecInner::Inline(item), - } - } - - pub fn with_capacity(capacity: usize) -> Self { - match capacity { - 0 | 1 => Self::new(), - _ => Self { - inner: MonoVecInner::Heap(Vec::with_capacity(capacity)), - }, - } - } - - pub fn push(&mut self, item: T) { - let uninit = MonoVecInner::None; - let prev = mem::replace(&mut self.inner, uninit); - let next = match prev { - MonoVecInner::None => MonoVecInner::Inline(item), - MonoVecInner::Inline(previous_item) => MonoVecInner::Heap(vec![previous_item, item]), - MonoVecInner::Heap(mut v) => { - v.push(item); - MonoVecInner::Heap(v) - } - }; - let uninit = mem::replace(&mut self.inner, next); - mem::forget(uninit); - } - - pub fn pop(&mut self) -> Option { - match self.inner { - MonoVecInner::None => None, - MonoVecInner::Inline(ref mut item) => { - let uninit = unsafe { mem::zeroed() }; - let item = mem::replace(item, uninit); - let uninit = mem::replace(&mut self.inner, MonoVecInner::None); - mem::forget(uninit); - Some(item) - } - MonoVecInner::Heap(ref mut v) => v.pop(), - } - } - - pub fn as_slice(&self) -> &[T] { - match self.inner { - MonoVecInner::None => unsafe { - slice::from_raw_parts(mem::align_of::() as *const T, 0) - }, - MonoVecInner::Inline(ref item) => slice::from_ref(item), - MonoVecInner::Heap(ref v) => &v[..], - } - } - - pub fn as_slice_mut(&mut self) -> &mut [T] { - match self.inner { - MonoVecInner::None => unsafe { - slice::from_raw_parts_mut(mem::align_of::() as *mut T, 0) - }, - MonoVecInner::Inline(ref mut item) => slice::from_mut(item), - MonoVecInner::Heap(ref mut v) => &mut v[..], - } - } -} From c187d1656eeadd525fe373c960d107da968cf9b0 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 17 Jan 2020 14:31:10 -0800 Subject: [PATCH 2/2] Add misc doc improvements to runtime-core --- lib/runtime-core/src/backend.rs | 9 +++++++++ lib/runtime-core/src/lib.rs | 2 +- lib/runtime-core/src/vm.rs | 11 +++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 607e72ee3..4bfb25c15 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -76,9 +76,18 @@ impl Default for MemoryBoundCheckMode { } /// Controls which experimental features will be enabled. +/// Features usually have a corresponding [WebAssembly proposal][wasm-props]. +/// +/// [wasm-props]: https://github.com/WebAssembly/proposals #[derive(Debug, Default)] pub struct Features { + /// Whether support for the [SIMD proposal][simd-prop] is enabled. + /// + /// [simd-prop]: https://github.com/webassembly/simd pub simd: bool, + /// Whether support for the [threads proposal][threads-prop] is enabled. + /// + /// [threads-prop]: https://github.com/webassembly/threads pub threads: bool, } diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 4e7cdcee3..f211e80db 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -173,7 +173,7 @@ pub fn validate_and_report_errors_with_features( } } -/// Creates a new module from the given cache `Artifact` for the specified compiler backend +/// Creates a new module from the given cache [`Artifact`] for the specified compiler backend pub unsafe fn load_cache_with( cache: Artifact, compiler: &dyn backend::Compiler, diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 2864bf8ed..ca7032c87 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -54,11 +54,14 @@ pub struct Ctx { /// This is intended to be user-supplied, per-instance /// contextual data. There are currently some issue with it, /// notably that it cannot be set before running the `start` - /// function in a WebAssembly module. + /// function in a WebAssembly module. Additionally, the `data` + /// field may be taken by another ABI implementation that the user + /// wishes to use in addition to their own, such as WASI. This issue is + /// being discussed at [#1111](https://github.com/wasmerio/wasmer/pull/1111). /// - /// [#219](https://github.com/wasmerio/wasmer/pull/219) fixes that - /// issue, as well as allowing the user to have *per-function* - /// context, instead of just per-instance. + /// Alternatively, per-function data can be used if the function in the + /// [`ImportObject`] is a closure. This cannot duplicate data though, + /// so if data may be shared if the [`ImportObject`] is reused. pub data: *mut c_void, /// If there's a function set in this field, it gets called