refactor: correct nesting depth for nested message type references, and introduce MessageScope to bundle codegen scope parameters#45
Merged
iainmcgin merged 2 commits intoanthropics:mainfrom Apr 16, 2026
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
9e89269 to
f6b115e
Compare
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
f6b115e to
3c9bfcc
Compare
Contributor
Author
|
@iainmcgin If you have time, PTAL |
3c9bfcc to
8b7f27f
Compare
Three bugs fixed: 1. protoc-gen-buffa: expose register_types option (default true). When json=true and using the packaging workflow (multiple files include!'d into the same module), the per-file register_types() functions collide. Setting register_types=false suppresses them. 2. buffa-codegen: thread nesting depth through message and view codegen. Nested messages sit inside a pub mod, so their field type references need additional super:: hops. Previously all fields used nesting=0 regardless of depth. 3. buffa-codegen: use ::core::result::Result in generated serde Deserialize impls. A proto message named "Result" creates a module that shadows std::result::Result, breaking the generated serde code. Replace five repeatedly-threaded parameters (`ctx`, `current_package`, `proto_fqn`, `features`, `nesting`) with a single `MessageScope` struct across ~30 internal functions in `message.rs` and `view.rs`. **Motivation** Every new piece of scope-level state (most recently `nesting` and `oneof_idents`) required touching dozens of function signatures and call sites. `MessageScope` makes adding future scope state a one-field change.
8b7f27f to
37d22eb
Compare
The initial fix plumbed nesting into classify_field and its immediate helpers but left several sibling paths still passing 0 (or 1) regardless of the containing message's actual depth. A nested message that referenced a cross-package enum via any of these paths would emit the wrong number of super:: hops and fail to compile. Remaining sites fixed: - oneof.rs collect_variant_info: oneof variant types now use nesting + 1 instead of the literal 1 (the enum's own module sits one level deeper than its containing message). - message.rs custom_deser_oneof_group: the serde DeserSeed impl for oneof groups now resolves variant types at the enclosing message's nesting instead of 0. - impl_text.rs enum_type_path (and its callers scalar_merge_arm / repeated_merge_arm / oneof_merge_arms / map_merge_arm): textproto enum references now use the impl block's nesting depth. - defaults.rs parse_default_value: proto2 [default = ENUM_VALUE] references now resolve at the consumer's nesting depth. - message.rs generate_extensions call site: extensions declared inside a nested message use nesting + 1, not a hardcoded 1. The dead scalar_or_message_type (nesting-0) wrapper was removed after the last caller moved to scalar_or_message_type_nested. Added a generation-level integration test that exercises nesting=2 through the owned-field, oneof-variant, and textproto enum paths simultaneously, asserting that all cross-package references in a triply-nested message use the correct number of super:: hops.
2448e45 to
ce1e64f
Compare
iainmcgin
approved these changes
Apr 16, 2026
Collaborator
iainmcgin
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Bugs fixed:
protoc-gen-buffa: expose register_types option (default true). When json=true and using the packaging workflow (multiple files
include!'d into the same module), the per-fileregister_types()functions collide. Setting register_types=false suppresses them.buffa-codegen: thread nesting depth through message and view codegen. Nested messages sit inside a pub mod, so their field type references need additional
super:: hops. Previously all fields used nesting=0 regardless of depth.buffa-codegen: use
::core::result::Resultin generated serde Deserialize impls. A proto message named "Result" creates a module that shadowsstd::result::Result, breaking the generated serde code.Refactor:
Replace five repeatedly-threaded parameters (
ctx,current_package,proto_fqn,features,nesting) with a singleMessageScopestructacross ~30 internal functions in
message.rsandview.rs.Motivation
Every new piece of scope-level state (most recently
nestingandoneof_idents) required touching dozens of function signatures and callsites.
MessageScopemakes adding future scope state a one-field change.