Skip to content

Commit

Permalink
Merge branch 'master' into feature/trampoline-in-artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewycky committed Oct 9, 2020
2 parents 37615b1 + 340419b commit d696171
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 138 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
- build: linux
os: ubuntu-latest
rust: 1.46.0
llvm_url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz'
llvm_url: 'https://github.com/wasmerio/llvm-build/releases/download/10.x/Ubuntu1910_Release.tar.xz'
# llvm_url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz'
artifact_name: 'wasmer-linux-amd64'
run_integration_tests: true
- build: macos
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Exports {

/// Creates a new `Exports` with capacity `n`.
pub fn with_capacity(n: usize) -> Self {
Exports {
Self {
map: Arc::new(IndexMap::with_capacity(n)),
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ where
impl FromIterator<(String, Extern)> for Exports {
fn from_iter<I: IntoIterator<Item = (String, Extern)>>(iter: I) -> Self {
// TODO: Move into IndexMap collect
let mut exports = Exports::new();
let mut exports = Self::new();
for (name, extern_) in iter {
exports.insert(name, extern_);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/api/src/externals/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ pub struct Global {

impl Global {
/// Create a new `Global` with the initial value [`Val`].
pub fn new(store: &Store, val: Val) -> Global {
pub fn new(store: &Store, val: Val) -> Self {
Self::from_value(store, val, Mutability::Const).unwrap()
}

/// Create a mutable `Global` with the initial value [`Val`].
pub fn new_mut(store: &Store, val: Val) -> Global {
pub fn new_mut(store: &Store, val: Val) -> Self {
Self::from_value(store, val, Mutability::Var).unwrap()
}

/// Create a `Global` with the initial value [`Val`] and the provided [`Mutability`].
fn from_value(store: &Store, val: Val, mutability: Mutability) -> Result<Global, RuntimeError> {
fn from_value(store: &Store, val: Val, mutability: Mutability) -> Result<Self, RuntimeError> {
if !val.comes_from_same_store(store) {
return Err(RuntimeError::new("cross-`Store` globals are not supported"));
}
Expand All @@ -47,7 +47,7 @@ impl Global {
.map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?;
};

Ok(Global {
Ok(Self {
store: store.clone(),
global: Arc::new(global),
})
Expand Down Expand Up @@ -87,15 +87,15 @@ impl Global {
Ok(())
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Global {
Global {
pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
Self {
store: store.clone(),
global: wasmer_export.from.clone(),
global: wasmer_export.from,
}
}

/// Returns whether or not these two globals refer to the same data.
pub fn same(&self, other: &Global) -> bool {
pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.global, &other.global)
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/api/src/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ impl Memory {
/// This function will construct the `Memory` using the store [`Tunables`].
///
/// [`Tunables`]: crate::tunables::Tunables
pub fn new(store: &Store, ty: MemoryType) -> Result<Memory, MemoryError> {
pub fn new(store: &Store, ty: MemoryType) -> Result<Self, MemoryError> {
let tunables = store.tunables();
let style = tunables.memory_style(&ty);
let memory = tunables.create_memory(&ty, &style)?;

Ok(Memory {
Ok(Self {
store: store.clone(),
memory,
})
Expand Down Expand Up @@ -148,15 +148,15 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) }
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Memory {
Memory {
pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Self {
Self {
store: store.clone(),
memory: wasmer_export.from,
}
}

/// Returns whether or not these two globals refer to the same data.
pub fn same(&self, other: &Memory) -> bool {
pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.memory, &other.memory)
}
}
Expand Down
44 changes: 22 additions & 22 deletions lib/api/src/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,35 @@ impl Extern {
/// Return the undelying type of the inner `Extern`.
pub fn ty(&self) -> ExternType {
match self {
Extern::Function(ft) => ExternType::Function(ft.ty().clone()),
Extern::Memory(ft) => ExternType::Memory(*ft.ty()),
Extern::Table(tt) => ExternType::Table(*tt.ty()),
Extern::Global(gt) => ExternType::Global(*gt.ty()),
Self::Function(ft) => ExternType::Function(ft.ty().clone()),
Self::Memory(ft) => ExternType::Memory(*ft.ty()),
Self::Table(tt) => ExternType::Table(*tt.ty()),
Self::Global(gt) => ExternType::Global(*gt.ty()),
}
}

/// Create an `Extern` from an `Export`.
pub fn from_export(store: &Store, export: Export) -> Extern {
pub fn from_export(store: &Store, export: Export) -> Self {
match export {
Export::Function(f) => Extern::Function(Function::from_export(store, f)),
Export::Memory(m) => Extern::Memory(Memory::from_export(store, m)),
Export::Global(g) => Extern::Global(Global::from_export(store, g)),
Export::Table(t) => Extern::Table(Table::from_export(store, t)),
Export::Function(f) => Self::Function(Function::from_export(store, f)),
Export::Memory(m) => Self::Memory(Memory::from_export(store, m)),
Export::Global(g) => Self::Global(Global::from_export(store, g)),
Export::Table(t) => Self::Table(Table::from_export(store, t)),
}
}
}

impl<'a> Exportable<'a> for Extern {
fn to_export(&self) -> Export {
match self {
Extern::Function(f) => f.to_export(),
Extern::Global(g) => g.to_export(),
Extern::Memory(m) => m.to_export(),
Extern::Table(t) => t.to_export(),
Self::Function(f) => f.to_export(),
Self::Global(g) => g.to_export(),
Self::Memory(m) => m.to_export(),
Self::Table(t) => t.to_export(),
}
}

fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> {
fn get_self_from_extern(_extern: &'a Self) -> Result<&'a Self, ExportError> {
// Since this is already an extern, we can just return it.
Ok(_extern)
}
Expand All @@ -73,10 +73,10 @@ impl<'a> Exportable<'a> for Extern {
impl StoreObject for Extern {
fn comes_from_same_store(&self, store: &Store) -> bool {
let my_store = match self {
Extern::Function(f) => f.store(),
Extern::Global(g) => g.store(),
Extern::Memory(m) => m.store(),
Extern::Table(t) => t.store(),
Self::Function(f) => f.store(),
Self::Global(g) => g.store(),
Self::Memory(m) => m.store(),
Self::Table(t) => t.store(),
};
Store::same(my_store, store)
}
Expand All @@ -99,24 +99,24 @@ impl fmt::Debug for Extern {

impl From<Function> for Extern {
fn from(r: Function) -> Self {
Extern::Function(r)
Self::Function(r)
}
}

impl From<Global> for Extern {
fn from(r: Global) -> Self {
Extern::Global(r)
Self::Global(r)
}
}

impl From<Memory> for Extern {
fn from(r: Memory) -> Self {
Extern::Memory(r)
Self::Memory(r)
}
}

impl From<Table> for Extern {
fn from(r: Table) -> Self {
Extern::Table(r)
Self::Table(r)
}
}
12 changes: 6 additions & 6 deletions lib/api/src/externals/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Table {
/// This function will construct the `Table` using the store [`Tunables`].
///
/// [`Tunables`]: crate::tunables::Tunables
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table, RuntimeError> {
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Self, RuntimeError> {
let item = init.into_checked_anyfunc(store)?;
let tunables = store.tunables();
let style = tunables.table_style(&ty);
Expand All @@ -51,7 +51,7 @@ impl Table {
set_table_item(table.as_ref(), i, item.clone())?;
}

Ok(Table {
Ok(Self {
store: store.clone(),
table,
})
Expand Down Expand Up @@ -117,9 +117,9 @@ impl Table {
/// Returns an error if the range is out of bounds of either the source or
/// destination tables.
pub fn copy(
dst_table: &Table,
dst_table: &Self,
dst_index: u32,
src_table: &Table,
src_table: &Self,
src_index: u32,
len: u32,
) -> Result<(), RuntimeError> {
Expand All @@ -139,8 +139,8 @@ impl Table {
Ok(())
}

pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Table {
Table {
pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self {
Self {
store: store.clone(),
table: wasmer_export.from,
}
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Instance {
/// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function.
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Instance, InstantiationError> {
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Self, InstantiationError> {
let store = module.store();

let handle = module.instantiate(resolver)?;
Expand All @@ -85,7 +85,7 @@ impl Instance {
})
.collect::<Exports>();

Ok(Instance {
Ok(Self {
handle,
module: module.clone(),
exports,
Expand Down
20 changes: 10 additions & 10 deletions lib/api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Module {
/// # }
/// ```
#[allow(unreachable_code)]
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Module, CompileError> {
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Self, CompileError> {
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
Expand All @@ -106,15 +106,15 @@ impl Module {
)))
})?;

Module::from_binary(store, bytes.as_ref())
Self::from_binary(store, bytes.as_ref())
}

/// Creates a new WebAssembly module from a file path.
pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Module, IoCompileError> {
pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Self, IoCompileError> {
let file_ref = file.as_ref();
let canonical = file_ref.canonicalize()?;
let wasm_bytes = std::fs::read(file_ref)?;
let mut module = Module::new(store, &wasm_bytes)?;
let mut module = Self::new(store, &wasm_bytes)?;
// Set the module name to the absolute path of the filename.
// This is useful for debugging the stack traces.
let filename = canonical.as_path().to_str().unwrap();
Expand All @@ -127,9 +127,9 @@ impl Module {
/// Opposed to [`Module::new`], this function is not compatible with
/// the WebAssembly text format (if the "wat" feature is enabled for
/// this crate).
pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Module, CompileError> {
Module::validate(store, binary)?;
unsafe { Module::from_binary_unchecked(store, binary) }
pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Self, CompileError> {
Self::validate(store, binary)?;
unsafe { Self::from_binary_unchecked(store, binary) }
}

/// Creates a new WebAssembly module skipping any kind of validation.
Expand All @@ -142,8 +142,8 @@ impl Module {
pub unsafe fn from_binary_unchecked(
store: &Store,
binary: &[u8],
) -> Result<Module, CompileError> {
let module = Module::compile(store, binary)?;
) -> Result<Self, CompileError> {
let module = Self::compile(store, binary)?;
Ok(module)
}

Expand Down Expand Up @@ -252,7 +252,7 @@ impl Module {
}

fn from_artifact(store: &Store, artifact: Arc<dyn Artifact>) -> Self {
Module {
Self {
store: store.clone(),
artifact,
}
Expand Down
22 changes: 11 additions & 11 deletions lib/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ pub type Val = Value<Function>;
impl StoreObject for Val {
fn comes_from_same_store(&self, store: &Store) -> bool {
match self {
Val::FuncRef(f) => Store::same(store, f.store()),
Val::ExternRef(ExternRef::Ref(_)) | Val::ExternRef(ExternRef::Other(_)) => false,
Val::ExternRef(ExternRef::Null) => true,
Val::I32(_) | Val::I64(_) | Val::F32(_) | Val::F64(_) | Val::V128(_) => true,
Self::FuncRef(f) => Store::same(store, f.store()),
Self::ExternRef(ExternRef::Ref(_)) | Self::ExternRef(ExternRef::Other(_)) => false,
Self::ExternRef(ExternRef::Null) => true,
Self::I32(_) | Self::I64(_) | Self::F32(_) | Self::F64(_) | Self::V128(_) => true,
}
}
}

impl From<Function> for Val {
fn from(val: Function) -> Val {
Val::FuncRef(val)
fn from(val: Function) -> Self {
Self::FuncRef(val)
}
}

Expand All @@ -53,19 +53,19 @@ impl ValFuncRef for Val {
return Err(RuntimeError::new("cross-`Store` values are not supported"));
}
Ok(match self {
Val::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc {
Self::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc {
func_ptr: ptr::null(),
type_index: wasmer_vm::VMSharedSignatureIndex::default(),
vmctx: ptr::null_mut(),
},
Val::FuncRef(f) => f.checked_anyfunc(),
Self::FuncRef(f) => f.checked_anyfunc(),
_ => return Err(RuntimeError::new("val is not funcref")),
})
}

fn from_checked_anyfunc(item: wasmer_vm::VMCallerCheckedAnyfunc, store: &Store) -> Val {
fn from_checked_anyfunc(item: wasmer_vm::VMCallerCheckedAnyfunc, store: &Store) -> Self {
if item.type_index == wasmer_vm::VMSharedSignatureIndex::default() {
return Val::ExternRef(ExternRef::Null);
return Self::ExternRef(ExternRef::Null);
}
let signature = store
.engine()
Expand All @@ -81,6 +81,6 @@ impl ValFuncRef for Val {
trampoline: None,
};
let f = Function::from_export(store, export);
Val::FuncRef(f)
Self::FuncRef(f)
}
}
2 changes: 1 addition & 1 deletion lib/cli/src/c_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl CType {
w.push_str("const ");
}
inner.generate_c(w);
w.push_str("*");
w.push('*');
}
Self::U8 => {
w.push_str("unsigned char");
Expand Down
Loading

0 comments on commit d696171

Please sign in to comment.