Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wasi-http/src/http_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use http_body_util::{BodyExt, Empty};
use hyper::Method;
use wasmtime::component::Resource;

impl<T: WasiHttpView> outgoing_handler::Host for T {
impl outgoing_handler::Host for dyn WasiHttpView + '_ {
fn handle(
&mut self,
request_id: Resource<HostOutgoingRequest>,
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub mod bindings {
trappable_error_type: {
"wasi:http/types/error-code" => crate::HttpError,
},
skip_mut_forwarding_impls: true,
});

pub use wasi::http;
Expand Down
22 changes: 14 additions & 8 deletions crates/wasi-http/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn add_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> anyhow::Resul
where
T: WasiHttpView + wasmtime_wasi::WasiView,
{
let closure = type_annotate::<T, _>(|t| t);
let closure = type_annotate_wasi::<T, _>(|t| t);
wasmtime_wasi::bindings::clocks::wall_clock::add_to_linker_get_host(l, closure)?;
wasmtime_wasi::bindings::clocks::monotonic_clock::add_to_linker_get_host(l, closure)?;
wasmtime_wasi::bindings::io::poll::add_to_linker_get_host(l, closure)?;
Expand All @@ -99,19 +99,25 @@ where

// NB: workaround some rustc inference - a future refactoring may make this
// obsolete.
fn type_annotate<T, F>(val: F) -> F
fn type_annotate_http<T, F>(val: F) -> F
where
F: Fn(&mut T) -> &mut T,
F: Fn(&mut T) -> &mut dyn WasiHttpView,
{
val
}
fn type_annotate_wasi<T, F>(val: F) -> F
where
F: Fn(&mut T) -> &mut dyn wasmtime_wasi::WasiView,
{
val
}

#[doc(hidden)]
pub fn add_only_http_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> anyhow::Result<()>
where
T: WasiHttpView + wasmtime_wasi::WasiView + crate::bindings::http::types::Host,
T: WasiHttpView,
{
let closure = type_annotate::<T, _>(|t| t);
let closure = type_annotate_http::<T, _>(|t| t);
crate::bindings::http::outgoing_handler::add_to_linker_get_host(l, closure)?;
crate::bindings::http::types::add_to_linker_get_host(l, closure)?;

Expand Down Expand Up @@ -196,7 +202,7 @@ pub mod sync {
where
T: WasiHttpView + wasmtime_wasi::WasiView,
{
let closure = super::type_annotate::<T, _>(|t| t);
let closure = super::type_annotate_wasi::<T, _>(|t| t);

wasmtime_wasi::bindings::clocks::wall_clock::add_to_linker_get_host(l, closure)?;
wasmtime_wasi::bindings::clocks::monotonic_clock::add_to_linker_get_host(l, closure)?;
Expand All @@ -217,9 +223,9 @@ pub mod sync {
// TODO: This is temporary solution until the wasmtime_wasi command functions can be removed
pub fn add_only_http_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> anyhow::Result<()>
where
T: WasiHttpView + wasmtime_wasi::WasiView + crate::bindings::http::types::Host,
T: WasiHttpView,
{
let closure = super::type_annotate::<T, _>(|t| t);
let closure = super::type_annotate_http::<T, _>(|t| t);

crate::bindings::http::outgoing_handler::add_to_linker_get_host(l, closure)?;
crate::bindings::http::types::add_to_linker_get_host(l, closure)?;
Expand Down
24 changes: 12 additions & 12 deletions crates/wasi-http/src/types_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use wasmtime_wasi::{
Pollable, ResourceTableError,
};

impl<T: WasiHttpView> crate::bindings::http::types::Host for T {
impl crate::bindings::http::types::Host for dyn WasiHttpView + '_ {
fn convert_error_code(&mut self, err: crate::HttpError) -> wasmtime::Result<types::ErrorCode> {
err.downcast()
}
Expand Down Expand Up @@ -98,7 +98,7 @@ fn get_fields_mut<'a>(
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostFields for T {
impl crate::bindings::http::types::HostFields for dyn WasiHttpView + '_ {
fn new(&mut self) -> wasmtime::Result<Resource<HostFields>> {
let id = self
.table()
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostFields for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingRequest for T {
impl crate::bindings::http::types::HostIncomingRequest for dyn WasiHttpView + '_ {
fn method(&mut self, id: Resource<HostIncomingRequest>) -> wasmtime::Result<Method> {
let method = self.table().get(&id)?.parts.method.clone();
Ok(method.into())
Expand Down Expand Up @@ -370,7 +370,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingRequest for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingRequest for T {
impl crate::bindings::http::types::HostOutgoingRequest for dyn WasiHttpView + '_ {
fn new(
&mut self,
headers: Resource<Headers>,
Expand Down Expand Up @@ -556,7 +556,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingRequest for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostResponseOutparam for T {
impl crate::bindings::http::types::HostResponseOutparam for dyn WasiHttpView + '_ {
fn drop(&mut self, id: Resource<HostResponseOutparam>) -> wasmtime::Result<()> {
let _ = self.table().delete(id)?;
Ok(())
Expand All @@ -579,7 +579,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostResponseOutparam for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingResponse for T {
impl crate::bindings::http::types::HostIncomingResponse for dyn WasiHttpView + '_ {
fn drop(&mut self, response: Resource<HostIncomingResponse>) -> wasmtime::Result<()> {
let _ = self
.table()
Expand Down Expand Up @@ -640,7 +640,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingResponse for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostFutureTrailers for T {
impl crate::bindings::http::types::HostFutureTrailers for dyn WasiHttpView + '_ {
fn drop(&mut self, id: Resource<HostFutureTrailers>) -> wasmtime::Result<()> {
let _ = self
.table()
Expand Down Expand Up @@ -687,7 +687,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostFutureTrailers for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingBody for T {
impl crate::bindings::http::types::HostIncomingBody for dyn WasiHttpView + '_ {
fn stream(
&mut self,
id: Resource<HostIncomingBody>,
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostIncomingBody for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingResponse for T {
impl crate::bindings::http::types::HostOutgoingResponse for dyn WasiHttpView + '_ {
fn new(
&mut self,
headers: Resource<Headers>,
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingResponse for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostFutureIncomingResponse for T {
impl crate::bindings::http::types::HostFutureIncomingResponse for dyn WasiHttpView + '_ {
fn drop(&mut self, id: Resource<HostFutureIncomingResponse>) -> wasmtime::Result<()> {
let _ = self.table().delete(id)?;
Ok(())
Expand Down Expand Up @@ -866,7 +866,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostFutureIncomingResponse f
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingBody for T {
impl crate::bindings::http::types::HostOutgoingBody for dyn WasiHttpView + '_ {
fn write(
&mut self,
id: Resource<HostOutgoingBody>,
Expand Down Expand Up @@ -903,7 +903,7 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostOutgoingBody for T {
}
}

impl<T: WasiHttpView> crate::bindings::http::types::HostRequestOptions for T {
impl crate::bindings::http::types::HostRequestOptions for dyn WasiHttpView + '_ {
fn new(&mut self) -> wasmtime::Result<Resource<types::RequestOptions>> {
let id = self.table().push(types::RequestOptions::default())?;
Ok(id)
Expand Down
2 changes: 0 additions & 2 deletions crates/wasi/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub mod sync {
"wasi:io/streams/input-stream": super::super::io::streams::InputStream,
"wasi:io/streams/output-stream": super::super::io::streams::OutputStream,
},
skip_mut_forwarding_impls: true,
});
}
pub use self::generated::exports;
Expand Down Expand Up @@ -199,7 +198,6 @@ mod async_io {
"wasi:cli/terminal-input/terminal-input": crate::stdio::TerminalInput,
"wasi:cli/terminal-output/terminal-output": crate::stdio::TerminalOutput,
},
skip_mut_forwarding_impls: true,
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/wasi/src/host/clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl TryFrom<SystemTime> for Datetime {
}
}

impl<T: WasiView> wall_clock::Host for T {
impl wall_clock::Host for dyn WasiView + '_ {
fn now(&mut self) -> anyhow::Result<Datetime> {
let now = self.ctx().wall_clock.now();
Ok(Datetime {
Expand Down Expand Up @@ -61,7 +61,7 @@ fn subscribe_to_duration(
subscribe(table, sleep)
}

impl<T: WasiView> monotonic_clock::Host for T {
impl monotonic_clock::Host for dyn WasiView + '_ {
fn now(&mut self) -> anyhow::Result<Instant> {
Ok(self.ctx().monotonic_clock.now())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi/src/host/env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::bindings::cli::environment;
use crate::WasiView;

impl<T: WasiView> environment::Host for T {
impl environment::Host for dyn WasiView + '_ {
fn get_environment(&mut self) -> anyhow::Result<Vec<(String, String)>> {
Ok(self.ctx().env.clone())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi/src/host/exit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{bindings::cli::exit, I32Exit, WasiView};

impl<T: WasiView> exit::Host for T {
impl exit::Host for dyn WasiView + '_ {
fn exit(&mut self, status: Result<(), ()>) -> anyhow::Result<()> {
let status = match status {
Ok(()) => 0,
Expand Down
8 changes: 4 additions & 4 deletions crates/wasi/src/host/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmtime::component::Resource;

mod sync;

impl<T: WasiView> preopens::Host for T {
impl preopens::Host for dyn WasiView + '_ {
fn get_directories(
&mut self,
) -> Result<Vec<(Resource<types::Descriptor>, String)>, anyhow::Error> {
Expand All @@ -30,7 +30,7 @@ impl<T: WasiView> preopens::Host for T {
}

#[async_trait::async_trait]
impl<T: WasiView> types::Host for T {
impl types::Host for dyn WasiView + '_ {
fn convert_error_code(&mut self, err: FsError) -> anyhow::Result<ErrorCode> {
err.downcast()
}
Expand All @@ -52,7 +52,7 @@ impl<T: WasiView> types::Host for T {
}

#[async_trait::async_trait]
impl<T: WasiView> HostDescriptor for T {
impl HostDescriptor for dyn WasiView + '_ {
async fn advise(
&mut self,
fd: Resource<types::Descriptor>,
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<T: WasiView> HostDescriptor for T {
}

#[async_trait::async_trait]
impl<T: WasiView> HostDirectoryEntryStream for T {
impl HostDirectoryEntryStream for dyn WasiView + '_ {
async fn read_directory_entry(
&mut self,
stream: Resource<types::DirectoryEntryStream>,
Expand Down
10 changes: 4 additions & 6 deletions crates/wasi/src/host/filesystem/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::bindings::filesystem::types as async_filesystem;
use crate::bindings::sync::filesystem::types as sync_filesystem;
use crate::bindings::sync::io::streams;
use crate::runtime::in_tokio;
use crate::{FsError, FsResult};
use crate::{FsError, FsResult, WasiView};
use wasmtime::component::Resource;

impl<T: async_filesystem::Host> sync_filesystem::Host for T {
impl sync_filesystem::Host for dyn WasiView + '_ {
fn convert_error_code(&mut self, err: FsError) -> anyhow::Result<sync_filesystem::ErrorCode> {
Ok(async_filesystem::Host::convert_error_code(self, err)?.into())
}
Expand All @@ -18,7 +18,7 @@ impl<T: async_filesystem::Host> sync_filesystem::Host for T {
}
}

impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T {
impl sync_filesystem::HostDescriptor for dyn WasiView + '_ {
fn advise(
&mut self,
fd: Resource<sync_filesystem::Descriptor>,
Expand Down Expand Up @@ -302,9 +302,7 @@ impl<T: async_filesystem::HostDescriptor> sync_filesystem::HostDescriptor for T
}
}

impl<T: async_filesystem::HostDirectoryEntryStream> sync_filesystem::HostDirectoryEntryStream
for T
{
impl sync_filesystem::HostDirectoryEntryStream for dyn WasiView + '_ {
fn read_directory_entry(
&mut self,
stream: Resource<sync_filesystem::DirectoryEntryStream>,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi/src/host/instance_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::network::Network;
use crate::WasiView;
use wasmtime::component::Resource;

impl<T: WasiView> instance_network::Host for T {
impl instance_network::Host for dyn WasiView + '_ {
fn instance_network(&mut self) -> Result<Resource<Network>, anyhow::Error> {
let network = Network {
socket_addr_check: self.ctx().socket_addr_check.clone(),
Expand Down
16 changes: 8 additions & 8 deletions crates/wasi/src/host/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::{
};
use wasmtime::component::Resource;

impl<T: WasiView> error::Host for T {}
impl error::Host for dyn WasiView + '_ {}

impl<T: WasiView> streams::Host for T {
impl streams::Host for dyn WasiView + '_ {
fn convert_stream_error(&mut self, err: StreamError) -> anyhow::Result<streams::StreamError> {
match err {
StreamError::Closed => Ok(streams::StreamError::Closed),
Expand All @@ -20,7 +20,7 @@ impl<T: WasiView> streams::Host for T {
}
}

impl<T: WasiView> error::HostError for T {
impl error::HostError for dyn WasiView + '_ {
fn drop(&mut self, err: Resource<streams::Error>) -> anyhow::Result<()> {
self.table().delete(err)?;
Ok(())
Expand All @@ -32,7 +32,7 @@ impl<T: WasiView> error::HostError for T {
}

#[async_trait::async_trait]
impl<T: WasiView> streams::HostOutputStream for T {
impl streams::HostOutputStream for dyn WasiView + '_ {
fn drop(&mut self, stream: Resource<OutputStream>) -> anyhow::Result<()> {
self.table().delete(stream)?;
Ok(())
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<T: WasiView> streams::HostOutputStream for T {
}

#[async_trait::async_trait]
impl<T: WasiView> streams::HostInputStream for T {
impl streams::HostInputStream for dyn WasiView + '_ {
fn drop(&mut self, stream: Resource<InputStream>) -> anyhow::Result<()> {
self.table().delete(stream)?;
Ok(())
Expand Down Expand Up @@ -246,7 +246,7 @@ pub mod sync {
}
}

impl<T: WasiView> streams::Host for T {
impl streams::Host for dyn WasiView + '_ {
fn convert_stream_error(
&mut self,
err: StreamError,
Expand All @@ -255,7 +255,7 @@ pub mod sync {
}
}

impl<T: WasiView> streams::HostOutputStream for T {
impl streams::HostOutputStream for dyn WasiView + '_ {
fn drop(&mut self, stream: Resource<OutputStream>) -> anyhow::Result<()> {
AsyncHostOutputStream::drop(self, stream)
}
Expand Down Expand Up @@ -332,7 +332,7 @@ pub mod sync {
}
}

impl<T: WasiView> streams::HostInputStream for T {
impl streams::HostInputStream for dyn WasiView + '_ {
fn drop(&mut self, stream: Resource<InputStream>) -> anyhow::Result<()> {
AsyncHostInputStream::drop(self, stream)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi/src/host/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use rustix::io::Errno;
use std::io;
use wasmtime::component::Resource;

impl<T: WasiView> network::Host for T {
impl network::Host for dyn WasiView + '_ {
fn convert_error_code(&mut self, error: SocketError) -> anyhow::Result<ErrorCode> {
error.downcast()
}
}

impl<T: WasiView> crate::bindings::sockets::network::HostNetwork for T {
impl crate::bindings::sockets::network::HostNetwork for dyn WasiView + '_ {
fn drop(&mut self, this: Resource<network::Network>) -> Result<(), anyhow::Error> {
let table = self.table();

Expand Down
Loading