Skip to content

fix(wit-bindgen-rust): derive async-func names from item_name#1355

Merged
rvolosatovs merged 1 commit into
mainfrom
fix/async-func-modifier
Jun 23, 2026
Merged

fix(wit-bindgen-rust): derive async-func names from item_name#1355
rvolosatovs merged 1 commit into
mainfrom
fix/async-func-modifier

Conversation

@rvolosatovs

Copy link
Copy Markdown
Member

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 funcs 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

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
@rvolosatovs rvolosatovs enabled auto-merge June 23, 2026 11:06
@rvolosatovs rvolosatovs added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit fe2745d Jun 23, 2026
38 checks passed
@rvolosatovs rvolosatovs deleted the fix/async-func-modifier branch June 23, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant