Namespace ancillary codegen output into view:: and ext:: sub-modules#54
Draft
Namespace ancillary codegen output into view:: and ext:: sub-modules#54
Conversation
Moves generated types that previously collided with user-declared proto names into dedicated sub-modules, structurally deconflicting the codegen output from proto-derived names. Layout changes: - Views: `pkg::FooView` → `pkg::view::FooView` (top-level), and `pkg::foo::BarView` → `pkg::view::foo::BarView` (nested). Oneof view enums follow the same tree: `pkg::view::foo::KindView`. The `View` suffix is retained so that owned and view types can be imported into the same scope without renaming. - Extensions: `pkg::FOO` → `pkg::ext::FOO`, and per-file `pkg::register_types` → `pkg::ext::register_types`. - Oneof enums: `foo::KindOneof` → `foo::Kind`. The suffix is no longer needed for disambiguation; the owner message's sub-module provides the namespace. Oneof enums themselves remain in the owner message's sub-module (`pkg::foo::Kind`). The view-tree move makes several previously-illegal proto patterns legal — two regression tests in `naming.rs` capture this. Codegen internals: - `GeneratedFile` gains `kind: GeneratedFileKind` + `package: String` fields. Each generated proto now produces three sibling output files (`.rs`, `.__view.rs`, `.__ext.rs`); `generate_module_tree` coalesces them per package so multiple `.proto` files that share a Rust module (e.g. `google.rpc`) merge their `view::` / `ext::` blocks cleanly. - `generate_module_tree` signature widens from `&[(&str, &str)]` to `&[ModuleTreeEntry<'_>]` to carry the kind. - `MessageScope::deeper()` is used for depth-aware path resolution in the parallel view tree. Checked-in generated code regenerated (WKTs + bootstrap descriptor types). Conformance suite, googleapis stress test, and the existing test suite (1442 tests) all pass.
ae6dd3b to
e46e6b9
Compare
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.
Summary
Ancillary types emitted by
buffa-codegen— borrowed views, top-level extension consts, and the per-file registration fn — previously lived in the same Rust namespace as user-declared proto types and could collide with them. For example, amessage FooViewin a.protowould clash with the generated view type of siblingmessage Foo, and amessage RegisterTypeswould clash with the per-fileregister_typesfn.This PR moves those ancillary types into dedicated sub-modules (
view::,ext::) to structurally deconflict them, and drops theOneofsuffix from oneof enums since the owner message's sub-module already disambiguates them.Layout changes
Views move into a parallel
view::treepkg::FooViewpkg::view::FooViewpkg::foo::BarViewpkg::view::foo::BarViewpkg::foo::KindView(oneof view)pkg::view::foo::KindViewThe
Viewsuffix is retained so that owned and view types can be imported into the same scope without aliasing:Extensions and package housekeeping move into
ext::pkg::FOO(extension const)pkg::ext::FOOpkg::register_typespkg::ext::register_typesOneof enums drop the
Oneofsuffixfoo::KindOneoffoo::KindOneof enums stay in the owner message's sub-module — they don't move to a parallel tree. The suffix was introduced to avoid name conflicts (see #33 / #34); those conflicts are now prevented by the
view::move for view-side names, and by the existing reserved-name machinery for owned-side names. The suffix is therefore redundant and was removed for readability.Codegen internals
GeneratedFilegainskind: GeneratedFileKindandpackage: Stringfields. Each proto produces three sibling output files (.rs,.__view.rs,.__ext.rs).generate_module_treeaccepts&[ModuleTreeEntry<'_>](was&[(&str, &str)]) and coalesces per-package streams across multiple.protofiles so packages that span files (e.g.google.rpc) merge theirview::/ext::blocks into single wrappers.generate_views=false.Deconfliction wins
Two proto patterns that were previously rejected are now legal and covered by regression tests in
buffa-codegen/src/tests/naming.rs:oneof my_fieldalongside nestedmessage MyFieldViewmy_fieldandmy_field_viewMigration for downstream consumers
Test plan
cargo check --workspacecleantask test— 1442 tests pass (18 suites), 0 failurestask test-codegen— 38 snapshot tests passtask lint—cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsboth cleantask conformance— 6CONFORMANCE SUITE PASSEDlines (std binary+JSON + no_std binary+JSON + via-view binary + std/no_std text + via-view text), baseline numbers unchangedtask stress-googleapis— 141 files across ~7 packages compile cleanly (including multi-filegoogle.rpc)tests/naming.rsconfirm the deconfliction winsDiff breakdown by category
Total: 65 files, +4273 / -3326.
buffa-codegen/src/*.rs, non-test)view.rs::rewrite_to_view_path), module-tree coalescing inlib.rs,GeneratedFileKindthreading, oneof-suffix removal. Net +376.buffa-buildAPI adaptationModuleTreeEntry/GeneratedFileKindthrough the build-script path. Net +57.buffa-testconsumer test suitebuffa-typeshand-maintained (lib.rs,value_ext.rs,timestamp_ext.rs, roundtrip test)lib.rshand-stitchespub mod view/pub mod ext; other files adjust paths. Net +29.protoc-gen-buffa-packaginggen_lib_rs.py)owned/__view/__ext) module tree for the stress test. Net +25.buffa-types/src/generated/).rsfiles shrink as inlined view code moves to 14 new.__view.rs/.__ext.rssibling files. Net +41.buffa-descriptor/src/generated/)generate_views=false). Net +12.So of the 4273 / 3326 total, roughly 1643 / 749 (38% / 23%) is human-authored change, and 2630 / 2577 (62% / 77%) is codegen-regenerated output — where the large insertion and deletion counts largely cancel out because content moved between files rather than being added or removed on net.
The "real" change — logic-plus-tests-plus-consumers — is on the order of ~900 net lines, distributed fairly evenly across codegen internals, consumer adaptation, and test updates.
Breaking changes
API-breaking for downstream consumers of generated code. Pre-1.0 this is expected; the migration is mechanical (adjust import paths).