Skip to content

Commit

Permalink
Merge pull request #3078 from wasmerio/fix-lint
Browse files Browse the repository at this point in the history
Fix errors from "make lint"
  • Loading branch information
syrusakbary authored Aug 5, 2022
2 parents ced8378 + 520314b commit 3b67f8d
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 68 deletions.
2 changes: 1 addition & 1 deletion lib/api/src/sys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a> StoreRef<'a> {
self.inner
.trap_handler
.as_ref()
.map(|handler| &*handler as *const _)
.map(|handler| handler as *const _)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Compile {
println!("Target: {}", target.triple());

let module = Module::from_file(&store, &self.path)?;
let _ = module.serialize_to_file(&self.output)?;
module.serialize_to_file(&self.output)?;
eprintln!(
"✔ File compiled successfully to `{}`.",
self.output.display(),
Expand Down
8 changes: 7 additions & 1 deletion lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ use structopt::StructOpt;
use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target};

/// The `prefixer` returns the a String to prefix each of the
/// functions in the static object generated by the
/// so we can assure no collisions.
#[cfg(feature = "static-artifact-create")]
pub type PrefixerFn = Box<dyn Fn(&[u8]) -> String + Send>;

const WASMER_MAIN_C_SOURCE: &[u8] = include_bytes!("wasmer_create_exe_main.c");
#[cfg(feature = "static-artifact-create")]
const WASMER_STATIC_MAIN_C_SOURCE: &[u8] = include_bytes!("wasmer_static_create_exe_main.c");
Expand Down Expand Up @@ -135,7 +141,7 @@ impl CreateExe {
let features = engine_inner.features();
let tunables = store.tunables();
let data: Vec<u8> = fs::read(wasm_module_path)?;
let prefixer: Option<Box<dyn Fn(&[u8]) -> String + Send>> = None;
let prefixer: Option<PrefixerFn> = None;
let (module_info, obj, metadata_length, symbol_registry) =
Artifact::generate_object(
compiler, &data, prefixer, &target, tunables, features,
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/src/commands/create_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Create a standalone native executable for a given Wasm file.

use super::ObjectFormat;
use crate::store::CompilerOptions;
use crate::{commands::PrefixerFn, store::CompilerOptions};
use anyhow::{Context, Result};
use std::env;
use std::fs;
Expand Down Expand Up @@ -114,7 +114,7 @@ impl CreateObj {
let features = engine_inner.features();
let tunables = store.tunables();
let data: Vec<u8> = fs::read(wasm_module_path)?;
let prefixer: Option<Box<dyn Fn(&[u8]) -> String + Send>> = None;
let prefixer: Option<PrefixerFn> = None;
let (module_info, obj, metadata_length, symbol_registry) =
Artifact::generate_object(
compiler, &data, prefixer, &target, tunables, features,
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler-singlepass/src/emitter_arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ impl EmitterARM64 for Assembler {
addr: GPR,
offset: i32,
) -> Result<(), CodegenError> {
assert!((offset >= -255) && (offset <= 255));
assert!((-255..=255).contains(&offset));
match (sz, reg) {
(Size::S64, Location::GPR(reg)) => {
let reg = reg.into_index() as u32;
Expand Down Expand Up @@ -702,7 +702,7 @@ impl EmitterARM64 for Assembler {
addr: GPR,
offset: i32,
) -> Result<(), CodegenError> {
assert!((offset >= -255) && (offset <= 255));
assert!((-255..=255).contains(&offset));
match (sz, reg) {
(Size::S64, Location::GPR(reg)) => {
let reg = reg.into_index() as u32;
Expand Down
5 changes: 4 additions & 1 deletion lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct UniversalArtifact {
finished_function_lengths: BoxedSlice<LocalFunctionIndex, usize>,
}

#[cfg(feature = "static-artifact-create")]
pub type PrefixerFn = Box<dyn Fn(&[u8]) -> String + Send>;

/// Stores functions etc as symbols and data meant to be stored in object files and
/// executables.
#[cfg(feature = "static-artifact-create")]
Expand Down Expand Up @@ -541,7 +544,7 @@ impl Artifact {
pub fn generate_object<'data>(
compiler: &dyn Compiler,
data: &[u8],
prefixer: Option<Box<dyn Fn(&[u8]) -> String + Send>>,
prefixer: Option<PrefixerFn>,
target: &'data Target,
tunables: &dyn Tunables,
features: &Features,
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/src/translator/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ModuleTranslationState {
wasmparser::TypeOrFuncType::FuncType(ty_index) => {
let sig_idx = SignatureIndex::from_u32(ty_index);
let (ref params, ref results) = self.wasm_types[sig_idx];
(&*params, &*results)
(params, results)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ pub fn emscripten_call_main(
.get::<Function>(function_name)
.map_err(|e| RuntimeError::new(e.to_string()))?;
let num_params = main_func.ty(&env).params().len();
let _result = match num_params {
match num_params {
2 => {
let mut new_args = vec![path];
new_args.extend(args);
Expand Down
5 changes: 1 addition & 4 deletions lib/emscripten/src/varargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ impl VarArgs {
// pub fn getStr<'a>(&mut self, ctx: &mut Ctx) -> &'a CStr {
pub fn get_str(&mut self, ctx: &FunctionEnvMut<EmEnv>) -> *const c_char {
let ptr_addr: u32 = self.get(ctx);
let ptr =
emscripten_memory_pointer!(ctx.data().memory_view(0, &ctx), ptr_addr) as *const c_char;
ptr
// unsafe { CStr::from_ptr(ptr) }
emscripten_memory_pointer!(ctx.data().memory_view(0, &ctx), ptr_addr) as *const c_char
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/middlewares/src/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub struct FunctionMetering<F: Fn(&Operator) -> u64 + Send + Sync> {
/// # Example
///
/// See the [`get_remaining_points`] function to get an example.
#[derive(Debug, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub enum MeteringPoints {
/// The given number of metering points is left for the execution.
/// If the value is 0, all points are consumed but the execution
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl Instance {
///
/// This is more or less a public facade of the private `Instance`,
/// providing useful higher-level API.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct InstanceHandle {
/// The layout of `Instance` (which can vary).
instance_layout: Layout,
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use thiserror::Error;
use wasmer_types::{Bytes, MemoryStyle, MemoryType, Pages};

/// Error type describing things that can go wrong when operating on Wasm Memories.
#[derive(Error, Debug, Clone, PartialEq, Hash)]
#[derive(Error, Debug, Clone, Eq, PartialEq, Hash)]
pub enum MemoryError {
/// Low level error with mmap.
#[error("Error when allocating memory: {0}")]
Expand Down
3 changes: 2 additions & 1 deletion lib/vm/src/sig_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl SignatureRegistry {
pub fn register(&self, sig: &FunctionType) -> VMSharedSignatureIndex {
let mut inner = self.inner.write().unwrap();
let len = inner.signature2index.len();
match inner.signature2index.entry(sig.clone()) {
let entry = inner.signature2index.entry(sig.clone());
match entry {
hash_map::Entry::Occupied(entry) => *entry.get(),
hash_map::Entry::Vacant(entry) => {
// Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(std::u32::MAX)
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/src/vmcontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod test_vmdynamicfunction_import_context {
}

/// A function kind is a calling convention into and out of wasm code.
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub enum VMFunctionKind {
/// A static function has the native signature:
Expand Down
3 changes: 2 additions & 1 deletion lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl WasiThread {
/// Waits for the thread to exit (false = timeout)
pub fn join(&self, timeout: Duration) -> bool {
let guard = self.join.lock().unwrap();
match guard.recv_timeout(timeout) {
let timeout = guard.recv_timeout(timeout);
match timeout {
Ok(_) => true,
Err(mpsc::RecvTimeoutError::Disconnected) => true,
Err(mpsc::RecvTimeoutError::Timeout) => false,
Expand Down
7 changes: 3 additions & 4 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ fn validate_mapped_dir_alias(alias: &str) -> Result<(), WasiStateCreationError>
Ok(())
}

pub type SetupFsFn = Box<dyn Fn(&mut WasiInodes, &mut WasiFs) -> Result<(), String> + Send>;

// TODO add other WasiFS APIs here like swapping out stdout, for example (though we need to
// return stdout somehow, it's unclear what that API should look like)
impl WasiStateBuilder {
Expand Down Expand Up @@ -318,10 +320,7 @@ impl WasiStateBuilder {

/// Configure the WASI filesystem before running.
// TODO: improve ergonomics on this function
pub fn setup_fs(
&mut self,
setup_fs_fn: Box<dyn Fn(&mut WasiInodes, &mut WasiFs) -> Result<(), String> + Send>,
) -> &mut Self {
pub fn setup_fs(&mut self, setup_fs_fn: SetupFsFn) -> &mut Self {
self.setup_fs_fn = Some(setup_fs_fn);

self
Expand Down
48 changes: 32 additions & 16 deletions lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ impl WasiFs {
for c in path.components() {
let segment_name = c.as_os_str().to_string_lossy().to_string();
let guard = inodes.arena[cur_inode].read();
match guard.deref() {
let deref = guard.deref();
match deref {
Kind::Dir { ref entries, .. } | Kind::Root { ref entries } => {
if let Some(_entry) = entries.get(&segment_name) {
// TODO: this should be fixed
Expand All @@ -678,7 +679,8 @@ impl WasiFs {
// reborrow to insert
{
let mut guard = inodes.arena[cur_inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::Dir {
ref mut entries, ..
}
Expand Down Expand Up @@ -725,7 +727,8 @@ impl WasiFs {
let base_inode = self.get_fd_inode(base).map_err(fs_error_from_wasi_err)?;

let guard = inodes.arena[base_inode].read();
match guard.deref() {
let deref = guard.deref();
match deref {
Kind::Dir { ref entries, .. } | Kind::Root { ref entries } => {
if let Some(_entry) = entries.get(&name) {
// TODO: eventually change the logic here to allow overwrites
Expand All @@ -745,7 +748,8 @@ impl WasiFs {

{
let mut guard = inodes.arena[base_inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::Dir {
ref mut entries, ..
}
Expand Down Expand Up @@ -790,7 +794,8 @@ impl WasiFs {
_ => {
let base_inode = self.get_fd_inode(fd).map_err(fs_error_from_wasi_err)?;
let mut guard = inodes.arena[base_inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::File { ref mut handle, .. } => {
std::mem::swap(handle, &mut ret);
}
Expand All @@ -810,7 +815,8 @@ impl WasiFs {
) -> Result<__wasi_filesize_t, __wasi_errno_t> {
let inode = self.get_fd_inode(fd)?;
let mut guard = inodes.arena[inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::File { handle, .. } => {
if let Some(h) = handle {
let new_size = h.size();
Expand Down Expand Up @@ -899,7 +905,8 @@ impl WasiFs {
// loading inodes as necessary
'symlink_resolution: while symlink_count < MAX_SYMLINKS {
let mut guard = inodes.arena[cur_inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::Buffer { .. } => unimplemented!("state::get_inode_at_path for buffers"),
Kind::Dir {
ref mut entries,
Expand Down Expand Up @@ -1165,10 +1172,12 @@ impl WasiFs {
let mut res = BaseFdAndRelPath::None;
// for each preopened directory
let preopen_fds = self.preopen_fds.read().unwrap();
for po_fd in preopen_fds.deref() {
let deref = preopen_fds.deref();
for po_fd in deref {
let po_inode = self.fd_map.read().unwrap()[po_fd].inode;
let guard = inodes.arena[po_inode].read();
let po_path = match guard.deref() {
let deref = guard.deref();
let po_path = match deref {
Kind::Dir { path, .. } => &**path,
Kind::Root { .. } => Path::new("/"),
_ => unreachable!("Preopened FD that's not a directory or the root"),
Expand Down Expand Up @@ -1210,7 +1219,8 @@ impl WasiFs {
while cur_inode != base_inode {
counter += 1;
let guard = inodes.arena[cur_inode].read();
match guard.deref() {
let deref = guard.deref();
match deref {
Kind::Dir { parent, .. } => {
if let Some(p) = parent {
cur_inode = *p;
Expand Down Expand Up @@ -1345,8 +1355,9 @@ impl WasiFs {
debug!("fdstat: {:?}", fd);

let guard = inodes.arena[fd.inode].read();
let deref = guard.deref();
Ok(__wasi_fdstat_t {
fs_filetype: match guard.deref() {
fs_filetype: match deref {
Kind::File { .. } => __WASI_FILETYPE_REGULAR_FILE,
Kind::Dir { .. } => __WASI_FILETYPE_DIRECTORY,
Kind::Symlink { .. } => __WASI_FILETYPE_SYMBOLIC_LINK,
Expand Down Expand Up @@ -1408,7 +1419,8 @@ impl WasiFs {
}

let mut guard = inodes.arena[fd.inode].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::File {
handle: Some(file), ..
} => file.flush().map_err(|_| __WASI_EIO)?,
Expand Down Expand Up @@ -1643,7 +1655,8 @@ impl WasiFs {
let base_po_inode = &self.fd_map.read().unwrap()[base_po_dir].inode;
let base_po_inode_v = &inodes.arena[*base_po_inode];
let guard = base_po_inode_v.read();
match guard.deref() {
let deref = guard.deref();
match deref {
Kind::Root { .. } => {
self.fs_backing.symlink_metadata(path_to_symlink).map_err(fs_error_into_wasi_err)?
}
Expand Down Expand Up @@ -1685,7 +1698,8 @@ impl WasiFs {
let is_preopened = inodeval.is_preopened;

let mut guard = inodeval.write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::File { ref mut handle, .. } => {
let mut empty_handle = None;
std::mem::swap(handle, &mut empty_handle);
Expand All @@ -1707,14 +1721,16 @@ impl WasiFs {
if let Some(p) = *parent {
drop(guard);
let mut guard = inodes.arena[p].write();
match guard.deref_mut() {
let deref_mut = guard.deref_mut();
match deref_mut {
Kind::Dir { entries, .. } | Kind::Root { entries } => {
self.fd_map.write().unwrap().remove(&fd).unwrap();
if is_preopened {
let mut idx = None;
{
let preopen_fds = self.preopen_fds.read().unwrap();
for (i, po_fd) in preopen_fds.iter().enumerate() {
let preopen_fds_iter = preopen_fds.iter().enumerate();
for (i, po_fd) in preopen_fds_iter {
if *po_fd == fd {
idx = Some(i);
break;
Expand Down
3 changes: 2 additions & 1 deletion lib/wasi/src/state/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ impl Read for Pipe {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut buffer = self.buffer.lock().unwrap();
let amt = std::cmp::min(buf.len(), buffer.len());
for (i, byte) in buffer.drain(..amt).enumerate() {
let buf_iter = buffer.drain(..amt).enumerate();
for (i, byte) in buf_iter {
buf[i] = byte;
}
Ok(amt)
Expand Down
Loading

0 comments on commit 3b67f8d

Please sign in to comment.