Skip to content

Commit

Permalink
Merge pull request #4542 from wasmerio/various-fixes
Browse files Browse the repository at this point in the history
Various fixes detected in the build
  • Loading branch information
syrusakbary authored Apr 5, 2024
2 parents ee0e1bd + 80b933c commit 9fe37d2
Show file tree
Hide file tree
Showing 36 changed files with 126 additions and 156 deletions.
1 change: 1 addition & 0 deletions lib/api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::path::Path;
#[cfg(feature = "sys")]
use std::sync::Arc;
#[cfg(feature = "sys")]
#[allow(unused_imports)]
pub use wasmer_compiler::{Artifact, CompilerConfig, EngineInner, Features, Tunables};
#[cfg(feature = "sys")]
use wasmer_types::DeserializeError;
Expand Down
4 changes: 1 addition & 3 deletions lib/compiler-cranelift/src/trampoline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ mod function_call;
pub use self::dynamic_function::make_trampoline_dynamic_function;
pub use self::function_call::make_trampoline_function_call;

pub use cranelift_codegen::print_errors::pretty_error;
pub use cranelift_codegen::Context;
pub use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
pub use cranelift_frontend::FunctionBuilderContext;
6 changes: 2 additions & 4 deletions lib/compiler-cranelift/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ mod func_translator;
mod translation_utils;
mod unwind;

pub use self::func_environ::{FuncEnvironment, GlobalVariable, ReturnMode, TargetEnvironment};
pub use self::func_state::FuncTranslationState;
pub use self::func_environ::{FuncEnvironment, GlobalVariable, TargetEnvironment};
pub use self::func_translator::FuncTranslator;
pub use self::translation_utils::{
get_vmctx_value_label, irlibcall_to_libcall, irreloc_to_relocationkind,
signature_to_cranelift_ir, type_to_irtype,
irlibcall_to_libcall, irreloc_to_relocationkind, signature_to_cranelift_ir, type_to_irtype,
};
pub(crate) use self::unwind::{compiled_function_unwind_info, CraneliftUnwindInfo};
2 changes: 1 addition & 1 deletion lib/compiler/src/engine/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The WebAssembly possible errors
use thiserror::Error;
pub use wasmer_types::{DeserializeError, ImportError, SerializeError};
pub use wasmer_types::ImportError;
#[cfg(not(target_arch = "wasm32"))]
use wasmer_vm::Trap;

Expand Down
1 change: 1 addition & 0 deletions lib/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ compile_error!("Both the `std` and `core` features are disabled. Please enable o
#[cfg(feature = "core")]
extern crate alloc;

#[allow(unused_imports)]
mod lib {
#[cfg(feature = "core")]
pub mod std {
Expand Down
2 changes: 0 additions & 2 deletions lib/journal/src/concrete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ pub(super) use super::*;

pub use aligned_cow_str::*;
pub use aligned_cow_vec::*;
pub use arc::*;
pub use archived::*;
pub use boxed::*;
pub use buffered::*;
pub use compacting::*;
#[cfg(feature = "log-file")]
Expand Down
4 changes: 2 additions & 2 deletions lib/registry/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ impl MultiRegistry {
}

impl WasmerConfig {
pub(crate) const ENV_VAR_WASMER_REGISTRY_TOKEN: &str = "WASMER_TOKEN";
pub(crate) const ENV_VAR_WASMER_REGISTRY_TOKEN_LEGACY: &str = "WAPM_REGISTRY_TOKEN";
pub(crate) const ENV_VAR_WASMER_REGISTRY_TOKEN: &'static str = "WASMER_TOKEN";
pub(crate) const ENV_VAR_WASMER_REGISTRY_TOKEN_LEGACY: &'static str = "WAPM_REGISTRY_TOKEN";

/// Save the config to a file
pub fn save<P: AsRef<Path>>(&self, to: P) -> anyhow::Result<()> {
Expand Down
7 changes: 2 additions & 5 deletions lib/virtual-fs/src/arc_box_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{
};

use derivative::Derivative;
use futures::future::BoxFuture;
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};

use crate::VirtualFile;
Expand Down Expand Up @@ -111,11 +110,9 @@ impl VirtualFile for ArcBoxFile {
let mut inner = self.inner.lock().unwrap();
inner.set_len(new_size)
}
fn unlink(&mut self) -> BoxFuture<'static, crate::Result<()>> {
fn unlink(&mut self) -> crate::Result<()> {
let mut inner = self.inner.lock().unwrap();
let fut = inner.unlink();
drop(inner);
Box::pin(fut)
inner.unlink()
}
fn is_open(&self) -> bool {
let inner = self.inner.lock().unwrap();
Expand Down
7 changes: 2 additions & 5 deletions lib/virtual-fs/src/arc_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::{ClonableVirtualFile, VirtualFile};
use derivative::Derivative;
use futures::future::BoxFuture;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{
Expand Down Expand Up @@ -127,11 +126,9 @@ where
let mut inner = self.inner.lock().unwrap();
inner.set_len(new_size)
}
fn unlink(&mut self) -> BoxFuture<'static, crate::Result<()>> {
fn unlink(&mut self) -> crate::Result<()> {
let mut inner = self.inner.lock().unwrap();
let fut = inner.unlink();
drop(inner);
Box::pin(fut)
inner.unlink()
}
fn is_open(&self) -> bool {
let inner = self.inner.lock().unwrap();
Expand Down
5 changes: 2 additions & 3 deletions lib/virtual-fs/src/buffer_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::io::{self, *};
use std::pin::Pin;
use std::task::{Context, Poll};

use futures::future::BoxFuture;
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};

use crate::VirtualFile;
Expand Down Expand Up @@ -85,8 +84,8 @@ impl VirtualFile for BufferFile {
self.data.get_mut().resize(new_size as usize, 0);
Ok(())
}
fn unlink(&mut self) -> BoxFuture<'static, crate::Result<()>> {
Box::pin(async { Ok(()) })
fn unlink(&mut self) -> crate::Result<()> {
Ok(())
}
fn poll_read_ready(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
let cur = self.data.stream_position().unwrap_or_default();
Expand Down
4 changes: 2 additions & 2 deletions lib/virtual-fs/src/combine_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl VirtualFile for CombineFile {
self.tx.set_len(new_size)
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
Box::pin(self.tx.unlink())
fn unlink(&mut self) -> Result<()> {
self.tx.unlink()
}

fn poll_read_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
Expand Down
6 changes: 2 additions & 4 deletions lib/virtual-fs/src/cow_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Used for /dev/zero - infinitely returns zero
//! which is useful for commands like `dd if=/dev/zero of=bigfile.img size=1G`
use futures::future::BoxFuture;
use replace_with::replace_with_or_abort;
use std::io::{self, *};
use std::pin::Pin;
Expand Down Expand Up @@ -205,9 +204,8 @@ impl VirtualFile for CopyOnWriteFile {
fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
self.buf.set_len(new_size)
}
fn unlink(&mut self) -> BoxFuture<'static, crate::Result<()>> {
let ret = self.buf.set_len(0);
Box::pin(async move { ret })
fn unlink(&mut self) -> crate::Result<()> {
self.buf.set_len(0)
}
fn poll_read_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
match self.poll_copy_progress(cx) {
Expand Down
4 changes: 2 additions & 2 deletions lib/virtual-fs/src/dual_write_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl VirtualFile for DualWriteFile {
self.inner.set_len(new_size)
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
Box::pin(self.inner.unlink())
fn unlink(&mut self) -> Result<()> {
self.inner.unlink()
}

fn poll_read_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
Expand Down
17 changes: 8 additions & 9 deletions lib/virtual-fs/src/host_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@ impl VirtualFile for File {
fs::File::set_len(&self.inner_std, new_size).map_err(Into::into)
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
let path = self.host_path.clone();
Box::pin(async move { fs::remove_file(&path).map_err(Into::into) })
fn unlink(&mut self) -> Result<()> {
fs::remove_file(&self.host_path).map_err(Into::into)
}

fn get_special_fd(&self) -> Option<u32> {
Expand Down Expand Up @@ -589,8 +588,8 @@ impl VirtualFile for Stdout {
Ok(())
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
Box::pin(async { Ok(()) })
fn unlink(&mut self) -> Result<()> {
Ok(())
}

fn get_special_fd(&self) -> Option<u32> {
Expand Down Expand Up @@ -779,8 +778,8 @@ impl VirtualFile for Stderr {
Ok(())
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
Box::pin(async { Ok(()) })
fn unlink(&mut self) -> Result<()> {
Ok(())
}

fn get_special_fd(&self) -> Option<u32> {
Expand Down Expand Up @@ -915,8 +914,8 @@ impl VirtualFile for Stdin {
fn set_len(&mut self, _new_size: u64) -> crate::Result<()> {
Ok(())
}
fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
Box::pin(async { Ok(()) })
fn unlink(&mut self) -> Result<()> {
Ok(())
}
fn get_special_fd(&self) -> Option<u32> {
Some(0)
Expand Down
2 changes: 1 addition & 1 deletion lib/virtual-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub trait VirtualFile:
fn set_len(&mut self, new_size: u64) -> Result<()>;

/// Request deletion of the file
fn unlink(&mut self) -> BoxFuture<'static, Result<()>>;
fn unlink(&mut self) -> Result<()>;

/// Indicates if the file is opened or closed. This function must not block
/// Defaults to a status of being constantly open
Expand Down
79 changes: 39 additions & 40 deletions lib/virtual-fs/src/mem_fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,53 +206,52 @@ impl VirtualFile for FileHandle {
Ok(())
}

fn unlink(&mut self) -> BoxFuture<'static, Result<()>> {
fn unlink(&mut self) -> Result<()> {
let filesystem = self.filesystem.clone();
let inode = self.inode;
Box::pin(async move {
let (inode_of_parent, position, inode_of_file) = {
// Read lock.
let fs = filesystem.inner.read().map_err(|_| FsError::Lock)?;

// The inode of the file.
let inode_of_file = inode;

// Find the position of the file in the parent, and the
// inode of the parent.
let (position, inode_of_parent) = fs
.storage
.iter()
.find_map(|(inode_of_parent, node)| match node {
Node::Directory(DirectoryNode { children, .. }) => {
children.iter().enumerate().find_map(|(nth, inode)| {
if inode == &inode_of_file {
Some((nth, inode_of_parent))
} else {
None
}
})
}

_ => None,
})
.ok_or(FsError::BaseNotDirectory)?;
let (inode_of_parent, position, inode_of_file) = {
// Read lock.
let fs = filesystem.inner.read().map_err(|_| FsError::Lock)?;

// The inode of the file.
let inode_of_file = inode;

// Find the position of the file in the parent, and the
// inode of the parent.
let (position, inode_of_parent) = fs
.storage
.iter()
.find_map(|(inode_of_parent, node)| match node {
Node::Directory(DirectoryNode { children, .. }) => {
children.iter().enumerate().find_map(|(nth, inode)| {
if inode == &inode_of_file {
Some((nth, inode_of_parent))
} else {
None
}
})
}

(inode_of_parent, position, inode_of_file)
};
_ => None,
})
.ok_or(FsError::BaseNotDirectory)?;

{
// Write lock.
let mut fs = filesystem.inner.write().map_err(|_| FsError::Lock)?;
(inode_of_parent, position, inode_of_file)
};

// Remove the file from the storage.
fs.storage.remove(inode_of_file);
{
// Write lock.
let mut fs = filesystem.inner.write().map_err(|_| FsError::Lock)?;

// Remove the child from the parent directory.
fs.remove_child_from_node(inode_of_parent, position)?;
}
// Remove the file from the storage.
fs.storage.remove(inode_of_file);

Ok(())
})
// Remove the child from the parent directory.
fs.remove_child_from_node(inode_of_parent, position)?;
}

Ok(())
}

fn get_special_fd(&self) -> Option<u32> {
Expand Down Expand Up @@ -608,7 +607,7 @@ mod test_virtual_file {
);
}

assert_eq!(file.unlink().await, Ok(()), "unlinking the file");
assert_eq!(file.unlink(), Ok(()), "unlinking the file");

{
let fs_inner = fs.inner.read().unwrap();
Expand Down
6 changes: 2 additions & 4 deletions lib/virtual-fs/src/mem_fs/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ macro_rules! impl_virtualfile_on_std_streams {
Err(FsError::PermissionDenied)
}

fn unlink(&mut self) -> futures::future::BoxFuture<'static, Result<()>> {
Box::pin(async {
Ok(())
})
fn unlink(&mut self) -> Result<()> {
Ok(())
}

fn poll_read_ready(self: std::pin::Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> std::task::Poll<std::io::Result<usize>> {
Expand Down
5 changes: 2 additions & 3 deletions lib/virtual-fs/src/null_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::io::{self, *};
use std::pin::Pin;
use std::task::{Context, Poll};

use futures::future::BoxFuture;
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};

use crate::{ClonableVirtualFile, VirtualFile};
Expand Down Expand Up @@ -74,8 +73,8 @@ impl VirtualFile for NullFile {
fn set_len(&mut self, _new_size: u64) -> crate::Result<()> {
Ok(())
}
fn unlink(&mut self) -> BoxFuture<'static, crate::Result<()>> {
Box::pin(async { Ok(()) })
fn unlink(&mut self) -> crate::Result<()> {
Ok(())
}
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
Poll::Ready(Ok(8192))
Expand Down
Loading

0 comments on commit 9fe37d2

Please sign in to comment.