Skip to content

fix(internal/librarian/rust): preserve parent messages of used types - #7170

Merged
suzmue merged 1 commit into
googleapis:mainfrom
suzmue:fix-unused-nonexistent
Aug 5, 2026
Merged

suzmue merged 1 commit into
googleapis:mainfrom
suzmue:fix-unused-nonexistent

Conversation

@suzmue

@suzmue suzmue commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

When generating hybrid Rust crates, unused types are configured with prost_build's extern_path to map to a nonexistent type. When a nested message or enum is used in a streaming RPC, its parent message must not be placed in unusedTypes. Because prost_build uses prefix-based matching for extern_path, marking an unused parent message hides all of its nested child types and replaces references to them with nonexistent_type.

Previously, filterModelToStreaming only tracked types directly referenced by streaming request and response fields without traversing parent pointers. As a result, parent messages without direct field references were marked as unused, causing prost_build to omit nested child structs that were actually used in streaming RPCs.

Fixes #7143

@suzmue
suzmue requested a review from a team as a code owner August 3, 2026 21:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request aims to preserve parent messages of nested types when filtering models to streaming types, preventing them from being incorrectly classified as unused. However, the submitted code contains unresolved git merge conflict markers. Additionally, the feedback highlights a double-enqueuing bug and unnecessary field traversal introduced by the new recursive helper functions enqueueMsg and enqueueEnum. The reviewer suggests resolving the merge conflicts and replacing the recursive helpers with direct parent-marking logic to simplify the code and avoid the bug.

@suzmue
suzmue marked this pull request as draft August 3, 2026 21:14
…ypes

When generating hybrid Rust crates, unused types are configured with prost_build's
extern_path to map to a nonexistent type. When a nested message or enum is used in a
streaming RPC, its parent message must not be placed in unusedTypes. Because prost_build
uses prefix-based matching for extern_path, marking an unused parent message hides all
of its nested child types and replaces references to them with nonexistent_type.

Previously, filterModelToStreaming only tracked types directly referenced by streaming
request and response fields without traversing parent pointers. As a result, parent
messages without direct field references were marked as unused, causing prost_build to
omit nested child structs that were actually used in streaming RPCs.
@suzmue
suzmue force-pushed the fix-unused-nonexistent branch from f67d60e to 186f4e0 Compare August 3, 2026 21:22
@suzmue
suzmue marked this pull request as ready for review August 3, 2026 21:24

@alvarowolfx alvarowolfx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code is not trivial to follow, but I think the tests made things make more sense. I don't have any feedback to improve things further without learning more about the whole generation chain for streaming RPCs

@suzmue
suzmue merged commit e51520c into googleapis:main Aug 5, 2026
38 checks passed
@suzmue

suzmue commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Code is not trivial to follow, but I think the tests made things make more sense. I don't have any feedback to improve things further without learning more about the whole generation chain for streaming RPCs

Unfortunately I have a related bug fix incoming. Will see if I can take that opportunity to make it a little easier.

JoeWang1127 pushed a commit that referenced this pull request Aug 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.34.0](v0.33.0...v0.34.0)
(2026-08-08)


### Features

* **dart:** add a setup skill
([#7193](#7193))
([d322aa0](d322aa0))
* **dart:** implement bump
([#6989](#6989))
([5505997](5505997))
* **internal/librarian/php:** derive component name with config override
in generate
([#7197](#7197))
([557e664](557e664)),
refs [#7025](#7025)
* **internal/librarian/php:** derive lowercase hyphenated php library
names from api path
([#7215](#7215))
([4669112](4669112))
* **internal/librarian/php:** initialize new component before generation
([#7225](#7225))
([b6c50b4](b6c50b4))
* **internal/librarian/ruby:** support deleting output paths after
generation
([#7223](#7223))
([609ffb7](609ffb7)),
refs [#6633](#6633)
* **internal/librarian/rust:** support external type conversions
([#7212](#7212))
([5b72c52](5b72c52)),
refs [#7144](#7144)
* **internal/proto:** add package to gather proto files
([#7218](#7218))
([9646f09](9646f09)),
refs [#7217](#7217)
* **internal/sidekick/rust:** initialize bidi streaming RPCs eagerly
([#7221](#7221))
([cbfa368](cbfa368)),
refs [#6835](#6835)
* **internal/sidekick/rust:** support type-erased streaming handles
([#7229](#7229))
([17f5a3d](17f5a3d)),
refs [#6835](#6835)
* **internal/sidekick/rust:** use builder pattern for bidi methods
([#7203](#7203))
([bc90045](bc90045)),
refs [#6835](#6835)
* **internal/tool/composer:** use entrypoint configuration instead of
package names
([#7156](#7156))
([e33192f](e33192f))
* **sidekick/rust:** bigquery query creation metadata
([#7167](#7167))
([d70f2a2](d70f2a2))
* **swift:** conversions support map fields
([#7222](#7222))
([341f1e5](341f1e5))
* **swift:** protobuf conversions support oneofs
([#7205](#7205))
([40c48df](40c48df))
* **swift:** support skipped_ids in configuration
([#7206](#7206))
([95d3464](95d3464))


### Bug Fixes

* **internal/librarian/php:** remove version suffix from init namespace
([#7227](#7227))
([7fb3b46](7fb3b46))
* **internal/librarian/ruby:** pass gem namespace option to generator
([#7210](#7210))
([817146f](817146f))
* **internal/librarian/ruby:** pass service override option to generator
([#7208](#7208))
([e9886bf](e9886bf)),
refs [#6633](#6633)
* **internal/librarian/ruby:** search proto recursively in API path
([#7220](#7220))
([3d4a4a1](3d4a4a1)),
refs [#7219](#7219)
[#7217](#7217)
* **internal/librarian/rust:** preserve parent messages of used types
([#7170](#7170))
([e51520c](e51520c)),
refs [#7143](#7143)
* **internal/serviceconfig:** update config for compute
([#7200](#7200))
([a08e565](a08e565))
* **internal/sidekick/rust:** use from for repeated enum conversions in
convert-prost
([#7211](#7211))
([ee4fb71](ee4fb71))


### Performance Improvements

* **java:** batch format all libraries using argument file
([#7186](#7186))
([5a7775a](5a7775a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit to sofisl/librarian that referenced this pull request Aug 10, 2026
…oogleapis#7170)

When generating hybrid Rust crates, unused types are configured with
prost_build's extern_path to map to a nonexistent type. When a nested
message or enum is used in a streaming RPC, its parent message must not
be placed in unusedTypes. Because prost_build uses prefix-based matching
for extern_path, marking an unused parent message hides all of its
nested child types and replaces references to them with
nonexistent_type.

Previously, filterModelToStreaming only tracked types directly
referenced by streaming request and response fields without traversing
parent pointers. As a result, parent messages without direct field
references were marked as unused, causing prost_build to omit nested
child structs that were actually used in streaming RPCs.

Fixes googleapis#7143
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.

rust: type is mistakenly being identified as unused

2 participants