Stream: git-wasmtime

Topic: wasmtime / issue #5688 component-model: use same types in...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 02 2023 at 08:40):

fuxiaohei opened issue #5688:

Wit code:

interface http-types{
    // request object
    record request{
        method:string
    }
    // response object
    record response{}
}

default world http-interface {
    export http-handler: interface {
        use self.http-types.{request,response}
        handle-request: func(request: request) -> response
    }
    import http-fetch: interface {
        use self.http-types.{request,response}
        fetch-request: func(request: request) -> response
    }
}

Rust code

wasmtime::component::bindgen!({
    world: "http-interface",
    path: "http-interface.wit",
    async: true,
});

Error:

this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
expected 0 lifetime arguments

Some expanded code maybe:

  pub mod http_types {
      #[allow(unused_imports)]
      use wasmtime::component::__internal::anyhow;
      #[component(record)]
      pub struct Response {}
      #[component(record)]
      pub struct Request {
          #[component(name = "method")]
          pub method: String,
      }
      ....


    pub mod http_fetch {
        #[allow(unused_imports)]
        use wasmtime::component::__internal::anyhow;
        pub type Request = super::http_types::Request;
        pub type Response = super::http_types::Response;
        pub trait HttpFetch: Sized {
            #[must_use]
            #[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
            fn fetch_request<'life0, 'async_trait>(
                &'life0 mut self,
                request: Request,
            ) -> ::core::pin::Pin<
                Box<
                    dyn ::core::future::Future<
                        Output = anyhow::Result<Response>,
                    > + ::core::marker::Send + 'async_trait,
                >,
            >
            where
                'life0: 'async_trait,
                Self: 'async_trait;
        }

   pub mod http_handler {
        #[allow(unused_imports)]
        use wasmtime::component::__internal::anyhow;
        pub type Request<'a> = super::http_types::Request<'a>; // <-- error message show on this line
        pub type Response = super::http_types::Response;
        pub struct HttpHandler {
            handle_request: wasmtime::component::Func,
        }
        impl HttpHandler {
            pub fn new(
                __exports: &mut wasmtime::component::ExportInstance<'_, '_>,
            ) -> anyhow::Result<HttpHandler> {
                let handle_request = *__exports
                    .typed_func::<(Request<'_>,), (Response,)>("handle-request")?
                    .func();
                Ok(HttpHandler { handle_request })
            }
            pub async fn handle_request<S: wasmtime::AsContextMut>(
                &self,
                mut store: S,
                arg0: Request<'_>,
            ) -> anyhow::Result<Response>
            where
                <S as wasmtime::AsContext>::Data: Send,
            {
                let callee = unsafe {
                    wasmtime::component::TypedFunc::<
                        (Request<'_>,),
                        (Response,),
                    >::new_unchecked(self.handle_request)
                };
                let (ret0,) = callee.call_async(store.as_context_mut(), (arg0,)).await?;
                callee.post_return_async(store.as_context_mut()).await?;
                Ok(ret0)
            }
        }
    }
}

It seems that method:string in record request affects this case. if record request{} with no fields, it generates pub type Request = super::http_types::Request without lifetime mark.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 02 2023 at 16:25):

alexcrichton commented on issue #5688:

Thanks for the report! I've posted a fix for this at https://github.com/bytecodealliance/wasmtime/pull/5692

view this post on Zulip Wasmtime GitHub notifications bot (Feb 02 2023 at 17:54):

alexcrichton closed issue #5688:

Wit code:

interface http-types{
    // request object
    record request{
        method:string
    }
    // response object
    record response{}
}

default world http-interface {
    export http-handler: interface {
        use self.http-types.{request,response}
        handle-request: func(request: request) -> response
    }
    import http-fetch: interface {
        use self.http-types.{request,response}
        fetch-request: func(request: request) -> response
    }
}

Rust code

wasmtime::component::bindgen!({
    world: "http-interface",
    path: "http-interface.wit",
    async: true,
});

Error:

this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
expected 0 lifetime arguments

Some expanded code maybe:

  pub mod http_types {
      #[allow(unused_imports)]
      use wasmtime::component::__internal::anyhow;
      #[component(record)]
      pub struct Response {}
      #[component(record)]
      pub struct Request {
          #[component(name = "method")]
          pub method: String,
      }
      ....


    pub mod http_fetch {
        #[allow(unused_imports)]
        use wasmtime::component::__internal::anyhow;
        pub type Request = super::http_types::Request;
        pub type Response = super::http_types::Response;
        pub trait HttpFetch: Sized {
            #[must_use]
            #[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
            fn fetch_request<'life0, 'async_trait>(
                &'life0 mut self,
                request: Request,
            ) -> ::core::pin::Pin<
                Box<
                    dyn ::core::future::Future<
                        Output = anyhow::Result<Response>,
                    > + ::core::marker::Send + 'async_trait,
                >,
            >
            where
                'life0: 'async_trait,
                Self: 'async_trait;
        }

   pub mod http_handler {
        #[allow(unused_imports)]
        use wasmtime::component::__internal::anyhow;
        pub type Request<'a> = super::http_types::Request<'a>; // <-- error message show on this line
        pub type Response = super::http_types::Response;
        pub struct HttpHandler {
            handle_request: wasmtime::component::Func,
        }
        impl HttpHandler {
            pub fn new(
                __exports: &mut wasmtime::component::ExportInstance<'_, '_>,
            ) -> anyhow::Result<HttpHandler> {
                let handle_request = *__exports
                    .typed_func::<(Request<'_>,), (Response,)>("handle-request")?
                    .func();
                Ok(HttpHandler { handle_request })
            }
            pub async fn handle_request<S: wasmtime::AsContextMut>(
                &self,
                mut store: S,
                arg0: Request<'_>,
            ) -> anyhow::Result<Response>
            where
                <S as wasmtime::AsContext>::Data: Send,
            {
                let callee = unsafe {
                    wasmtime::component::TypedFunc::<
                        (Request<'_>,),
                        (Response,),
                    >::new_unchecked(self.handle_request)
                };
                let (ret0,) = callee.call_async(store.as_context_mut(), (arg0,)).await?;
                callee.post_return_async(store.as_context_mut()).await?;
                Ok(ret0)
            }
        }
    }
}

It seems that method:string in record request affects this case. if record request{} with no fields, it generates pub type Request = super::http_types::Request without lifetime mark.


Last updated: Nov 22 2024 at 16:03 UTC