Skip to content

Fix Go and Rust generator edge cases#1596

Merged
stephentoub merged 1 commit into
mainfrom
stephentoub/runtime-codegen-fix
Jun 7, 2026
Merged

Fix Go and Rust generator edge cases#1596
stephentoub merged 1 commit into
mainfrom
stephentoub/runtime-codegen-fix

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

Summary

The Go generator used discriminator accessor names like Kind, Type, or IsRemote directly. That preserves a useful generated API, but it can collide when a discriminator property is also emitted as a Go struct field. This change keeps the existing accessor name unless an actually emitted variant field would conflict, then uses an unexported union-prefixed method name.

The Rust generator could expose public RPC methods whose params or results resolve to internal generated schemas. This keeps those methods crate-private and allows intentionally unused generated internal support items.

Validation

  • Restored nodejs dependencies from the lockfile and regenerated Go/Rust against @github/copilot 1.0.57.
  • cd go && go test -run '^$' ./...
  • cd rust && cargo +nightly-2026-04-14 fmt --all -- --config-path .rustfmt.nightly.toml
  • cd rust && cargo test --no-run

Generated by Copilot

Update the Go generator to avoid discriminator method collisions only when a generated variant field would otherwise conflict. Update the Rust generator to keep RPC methods using internal schemas crate-private and allow intentionally unused generated internal items.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 7, 2026 16:21
@stephentoub stephentoub requested a review from a team as a code owner June 7, 2026 16:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Go and Rust code generators to handle schema edge cases that previously produced naming collisions (Go discriminated unions) or invalid public API surfaces (Rust typed RPC methods referencing internal-only schemas), and regenerates the affected Rust outputs accordingly.

Changes:

  • Go: choose a discriminator accessor method name that avoids collisions with actually-emitted variant struct fields by falling back to an unexported union-prefixed method name only when needed.
  • Rust: make typed RPC methods pub(crate) when their params/result types resolve to internal schemas, and suppress resulting dead_code warnings in generated modules so Rust CI (clippy/docs with -D warnings) remains clean.
  • Regenerated Rust api_types.rs and rpc.rs to reflect the generator updates.
Show a summary per file
File Description
scripts/codegen/rust.ts Makes typed RPC methods crate-private when they depend on internal schemas; adds dead_code allow to generated Rust modules.
scripts/codegen/go.ts Adds discriminator accessor naming logic to avoid method/field collisions in generated discriminated unions.
rust/src/generated/rpc.rs Regenerated output: adds #![allow(dead_code)] to avoid CI failures from unused crate-private items.
rust/src/generated/api_types.rs Regenerated output: adds #![allow(dead_code)] to avoid CI failures from unused internal generated types.

Copilot's findings

  • Files reviewed: 2/4 changed files
  • Comments generated: 0

@stephentoub stephentoub merged commit f54e3ac into main Jun 7, 2026
18 checks passed
@stephentoub stephentoub deleted the stephentoub/runtime-codegen-fix branch June 7, 2026 16:37
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.

2 participants