fix(wit-bindgen-rust): derive async-func names from item_name#1355
Merged
Conversation
wit-parser prefixes async functions in `func.name`: `[async]name`, `[async method]…`, `[async static]…`. Four generated names must agree for the stubs to compile: the client free-fn, the `Handler` trait method, the serve-dispatch `Handler::…` call, and the wire/rpc name. For freestanding async funcs two of those sites derived the Rust identifier from the prefixed `func.name` via `to_rust_ident(&func.name)`, which falls through to `heck::to_snake_case` and turns `[async]one-argument` into `async_one_argument`: - the client free-fn name (the `use_item_name == false` branch of `print_docs_and_params`), and - the serve-dispatch `Handler::…` call (the freestanding arm reused the prefixed local `name`). The `Handler` trait method and the wire name (`rpc_func_name`) already used the prefix-stripped item name, so for an `async func` the names drifted and the bindings failed to compile (E0432 on the client free-fn import, E0782 on the serve glue's `Handler::async_…` call). The `async func` modifier is meant to be a no-op in wRPC, where every func is already async over the transport. Switch both sites to `func.item_name()` (identical to `func.name` for non-async functions), so all four names derive from the same prefix-stripped item name. Resource async methods/statics already used `item_name()` everywhere and were not affected; the internal `serve_interface` local bindings (`f_…`/`m_…`/`s_…`) keep deriving from `func.name` so same-named methods on different resources stay distinct. The Go generator is unaffected: identifiers go through the centralized `go_func_name` and the wire name through `rpc_func_name`, both of which strip all prefixes. Add regression coverage exercising the `async func` modifier: - tests/runtime/rust/async-modifier: freestanding `async func`s exercised client↔server over the transport (fails to compile before this change). - tests/codegen/async-resource.wit: compile-only coverage of `async func` freestanding plus `[async method]`/`[async static]`/constructor on a resource. Assisted-by: claude:claude-opus-4-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wit-parser prefixes async functions in
func.name:[async]name,[async method]…,[async static]…. Four generated names must agree for the stubs to compile: the client free-fn, theHandlertrait method, the serve-dispatchHandler::…call, and the wire/rpc name.For freestanding async funcs two of those sites derived the Rust identifier from the prefixed
func.nameviato_rust_ident(&func.name), which falls through toheck::to_snake_caseand turns[async]one-argumentintoasync_one_argument:use_item_name == falsebranch ofprint_docs_and_params), andHandler::…call (the freestanding arm reused the prefixed localname).The
Handlertrait method and the wire name (rpc_func_name) already used the prefix-stripped item name, so for anasync functhe names drifted and the bindings failed to compile (E0432 on the client free-fn import, E0782 on the serve glue'sHandler::async_…call). Theasync funcmodifier is meant to be a no-op in wRPC, where every func is already async over the transport.Switch both sites to
func.item_name()(identical tofunc.namefor non-async functions), so all four names derive from the same prefix-stripped item name. Resource async methods/statics already useditem_name()everywhere and were not affected; the internalserve_interfacelocal bindings (f_…/m_…/s_…) keep deriving fromfunc.nameso same-named methods on different resources stay distinct.The Go generator is unaffected: identifiers go through the centralized
go_func_nameand the wire name throughrpc_func_name, both of which strip all prefixes.Add regression coverage exercising the
async funcmodifier:async funcs exercised client↔server over the transport (fails to compile before this change).async funcfreestanding plus[async method]/[async static]/constructor on a resource.Assisted-by: claude:claude-opus-4-8