Skip to content
Closed
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 src/hyperlight_component_util/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
ResourceItemName::Static(mn) => quote! { #mn },
},
};
// Use unmarshal directly since empty TokenStream generates no code
let decl = quote! {
fn #n(&mut self, #(#param_decls),*) -> #result_decl {
let mut args = ::alloc::vec::Vec::new();
Expand All @@ -78,7 +79,6 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
::hyperlight_common::flatbuffer_wrappers::function_types::ReturnType::VecBytes,
);
let ::core::result::Result::Ok(#ret) = #ret else { panic!("bad return from guest {:?}", #ret) };
#[allow(clippy::unused_unit)]
#unmarshal
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_component_util/src/hl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ pub fn emit_hl_unmarshal_param(s: &mut State, id: Ident, pt: &Value) -> TokenStr
/// are no names in it (i.e. a unit type)
pub fn emit_hl_unmarshal_result(s: &mut State, id: Ident, rt: &etypes::Result) -> TokenStream {
match rt {
etypes::Result::Named(rs) if rs.is_empty() => quote! { () },
etypes::Result::Named(rs) if rs.is_empty() => TokenStream::new(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this as a solution, because it changes the contract for this helper to something a lot less intuitive:

The resultant token stream will be an expression which typechecks at the Rust type ...

becomes

The resultant token stream will typecheck at the Rust type of the unnamed type of the result, or the empty stream if named results are used

which means that it can't generally be used to uniformly generate a return value. Right now, this expression is only used in the tail position of a function definition, so it works "by coincidence"---but this change makes the interface more brittle (e.g. if you wanted to refactor the macro to trace the return value, you would need special cases to not accidentally generate an empty let statement).

etypes::Result::Unnamed(vt) => {
let toks = emit_hl_unmarshal_value(s, id, vt);
quote! { { #toks }.0 }
Expand Down
8 changes: 4 additions & 4 deletions src/tests/rust_guests/witguest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/tests/rust_guests/witguest/guest.wit
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ interface roundtrip {
enum-a, enum-b, enum-c
}
roundtrip-enum: func(x: testenum) -> testenum;
// Test case for void return function (no clippy unused_unit warnings)
do-something: func(number: u32);
}

interface host-resource {
Expand Down
3 changes: 3 additions & 0 deletions src/tests/rust_guests/witguest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ impl test::wit::Roundtrip for Guest {
) -> test::wit::roundtrip::Testenum {
(Host {}).roundtrip_enum(x)
}
fn do_something(&mut self, number: u32) {
(Host {}).do_something(number)
}
}

impl test::wit::TestHostResource for Guest {
Expand Down
Loading