Stream: git-wasmtime

Topic: wasmtime / issue #5585 `component-model`: export function...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 17 2023 at 19:48):

ok-nick opened issue #5585:

Wit code:

interface test {
    new: func()
}

world test-world {
    default export test
}

Rust code:

wasmtime::component::bindgen!({
    path: "test.wit",
});

Error:

1. duplicate definitions with name `new`
   duplicate definitions for `new`
2. other definition for `new`

Expanded macro:

pub struct TestWorld {
    new: wasmtime::component::Func,
}
const _: () = {
    use wasmtime::component::__internal::anyhow;
    impl TestWorld {
        #[doc = " Instantiates the provided `module` using the specified"]
        #[doc = " parameters, wrapping up the result in a structure that"]
        #[doc = " translates between wasm and the host."]
        pub fn instantiate<T>(
            mut store: impl wasmtime::AsContextMut<Data = T>,
            component: &wasmtime::component::Component,
            linker: &wasmtime::component::Linker<T>,
        ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {
            let instance = linker.instantiate(&mut store, component)?;
            Ok((Self::new(store, &instance)?, instance))
        }
        #[doc = " Low-level creation wrapper for wrapping up the exports"]
        #[doc = " of the `instance` provided in this structure of wasm"]
        #[doc = " exports."]
        #[doc = ""]
        #[doc = " This function will extract exports from the `instance`"]
        #[doc = " defined within `store` and wrap them all up in the"]
        #[doc = " returned structure which can be used to interact with"]
        #[doc = " the wasm module."]
        pub fn new(
            mut store: impl wasmtime::AsContextMut,
            instance: &wasmtime::component::Instance,
        ) -> anyhow::Result<Self> {
            let mut store = store.as_context_mut();
            let mut exports = instance.exports(&mut store);
            let mut __exports = exports.root();
            let new = *__exports.typed_func::<(), ()>("new")?.func();
            Ok(TestWorld { new })
        }
        pub fn new<S: wasmtime::AsContextMut>(&self, mut store: S) -> anyhow::Result<()> {
            let callee =
                unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) };
            let () = callee.call(store.as_context_mut(), ())?;
            callee.post_return(store.as_context_mut())?;
            Ok(())
        }
    }
};
const _: &str = "";

view this post on Zulip Wasmtime GitHub notifications bot (Jan 17 2023 at 19:48):

ok-nick labeled issue #5585:

Wit code:

interface test {
    new: func()
}

world test-world {
    default export test
}

Rust code:

wasmtime::component::bindgen!({
    path: "test.wit",
});

Error:

1. duplicate definitions with name `new`
   duplicate definitions for `new`
2. other definition for `new`

Expanded macro:

pub struct TestWorld {
    new: wasmtime::component::Func,
}
const _: () = {
    use wasmtime::component::__internal::anyhow;
    impl TestWorld {
        #[doc = " Instantiates the provided `module` using the specified"]
        #[doc = " parameters, wrapping up the result in a structure that"]
        #[doc = " translates between wasm and the host."]
        pub fn instantiate<T>(
            mut store: impl wasmtime::AsContextMut<Data = T>,
            component: &wasmtime::component::Component,
            linker: &wasmtime::component::Linker<T>,
        ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {
            let instance = linker.instantiate(&mut store, component)?;
            Ok((Self::new(store, &instance)?, instance))
        }
        #[doc = " Low-level creation wrapper for wrapping up the exports"]
        #[doc = " of the `instance` provided in this structure of wasm"]
        #[doc = " exports."]
        #[doc = ""]
        #[doc = " This function will extract exports from the `instance`"]
        #[doc = " defined within `store` and wrap them all up in the"]
        #[doc = " returned structure which can be used to interact with"]
        #[doc = " the wasm module."]
        pub fn new(
            mut store: impl wasmtime::AsContextMut,
            instance: &wasmtime::component::Instance,
        ) -> anyhow::Result<Self> {
            let mut store = store.as_context_mut();
            let mut exports = instance.exports(&mut store);
            let mut __exports = exports.root();
            let new = *__exports.typed_func::<(), ()>("new")?.func();
            Ok(TestWorld { new })
        }
        pub fn new<S: wasmtime::AsContextMut>(&self, mut store: S) -> anyhow::Result<()> {
            let callee =
                unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) };
            let () = callee.call(store.as_context_mut(), ())?;
            callee.post_return(store.as_context_mut())?;
            Ok(())
        }
    }
};
const _: &str = "";

view this post on Zulip Wasmtime GitHub notifications bot (Jan 17 2023 at 21:39):

alexcrichton commented on issue #5585:

Thanks! I'll try to work on fixing this soon, probably by renaming new specifically as a bound function to something else or otherwise figuring out a different way of construction that doesn't claim the new identifier.

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

alexcrichton commented on issue #5585:

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 #5585:

Wit code:

interface test {
    new: func()
}

world test-world {
    default export test
}

Rust code:

wasmtime::component::bindgen!({
    path: "test.wit",
});

Error:

1. duplicate definitions with name `new`
   duplicate definitions for `new`
2. other definition for `new`

Expanded macro:

pub struct TestWorld {
    new: wasmtime::component::Func,
}
const _: () = {
    use wasmtime::component::__internal::anyhow;
    impl TestWorld {
        #[doc = " Instantiates the provided `module` using the specified"]
        #[doc = " parameters, wrapping up the result in a structure that"]
        #[doc = " translates between wasm and the host."]
        pub fn instantiate<T>(
            mut store: impl wasmtime::AsContextMut<Data = T>,
            component: &wasmtime::component::Component,
            linker: &wasmtime::component::Linker<T>,
        ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {
            let instance = linker.instantiate(&mut store, component)?;
            Ok((Self::new(store, &instance)?, instance))
        }
        #[doc = " Low-level creation wrapper for wrapping up the exports"]
        #[doc = " of the `instance` provided in this structure of wasm"]
        #[doc = " exports."]
        #[doc = ""]
        #[doc = " This function will extract exports from the `instance`"]
        #[doc = " defined within `store` and wrap them all up in the"]
        #[doc = " returned structure which can be used to interact with"]
        #[doc = " the wasm module."]
        pub fn new(
            mut store: impl wasmtime::AsContextMut,
            instance: &wasmtime::component::Instance,
        ) -> anyhow::Result<Self> {
            let mut store = store.as_context_mut();
            let mut exports = instance.exports(&mut store);
            let mut __exports = exports.root();
            let new = *__exports.typed_func::<(), ()>("new")?.func();
            Ok(TestWorld { new })
        }
        pub fn new<S: wasmtime::AsContextMut>(&self, mut store: S) -> anyhow::Result<()> {
            let callee =
                unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) };
            let () = callee.call(store.as_context_mut(), ())?;
            callee.post_return(store.as_context_mut())?;
            Ok(())
        }
    }
};
const _: &str = "";


Last updated: Dec 23 2024 at 13:07 UTC