Repository navigation
codegen: defer extern message fields in lazy views via lazy_extern_path - #850
Open
abhimanyusinghgaur wants to merge 1 commit into
Open
abhimanyusinghgaur wants to merge 1 commit into
abhimanyusinghgaur wants to merge 1 commit into
Conversation
Lazy views keep every field of an extern type eager, since the extern crate may not ship the lazy view family. A crate generated with lazy_views does ship it, so the new lazy_extern_path option (buffa_build::Config::lazy_extern_path, plugin lazy_extern_path=<proto>) declares it: fields of its types then become LazyMessageFieldView and LazyRepeatedView of the crate's FooLazyView, decoded on access. Without the option, generated output is unchanged. Well-known types mapped to buffa-types stay eager, as buffa-types ships no lazy views. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This branch has not been deployed
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.
Problem
A lazy view defers singular and repeated message fields, except those whose type comes from another crate through
extern_path:is_lazy_fieldreturns false for every extern type (buffa-codegen/src/lazy_view.rs:44-56, line 55), because "the target crate may not ship a lazy family". The guide says the same (docs/guide.md:1457-1458). There is no option to tell codegen that it does.A crate generated with
lazy_views=trueships the family, at the layout codegen already resolves for extern types (resolve_view_family_path,buffa-codegen/src/view.rs:2957). For example, substreams-ethereum 0.12 is generated by buffa with lazy views and shipsLogLazyView(src/pb/sf.ethereum.type.v2.type.__lazy_view.rs). A Substreams package that forwards many logs in its own messages, and reads only some of them, still getsMessageFieldView<…::__buffa::view::LogView<'a>>andRepeatedView<…LogView<'a>>in its lazy views. A repeated field of those is parsed for every reader atdecode_lazy, and a singular one whenever its element is touched, even though the extern crate could decode them on access.Change
CodeGenConfig::lazy_extern_paths: Vec<String>: proto packages or types, named like the proto side ofextern_paths, whose extern crate ships the lazy view family. Documented besideextern_paths; like it,generatedoesn't validate entries.is_lazy_fielddefers an extern type when it falls under an entry (CodeGenConfig::defers_extern_type, which reusesmatches_proto_prefix). The field then becomesLazyMessageFieldVieworLazyRepeatedViewof<extern path>::__buffa::lazy_view::<Name>LazyView, through the existing lazy-field code paths.buffa-typesby default stay eager, even under., sincebuffa-typesships no lazy views. If.google.protobufis mapped to another crate, the same exact-match test aseffective_extern_pathsapplies, and they defer when listed.protoc-gen-buffa: a repeatablelazy_extern_path=<proto>option, normalized withnormalize_extern_path_proto_name, in the usage text and theparse_configdocs.buffa-build:Config::lazy_extern_path(proto_path), stored as given and normalized incompile, likeextern_path.docs/guide.md: the option's row in the plugin table, and a paragraph with an example in "Lazy views".142 net lines outside tests.
Compatibility
is_lazy_fieldreturns what it did before, so generated output is unchanged, the checked-in generated code included.lazy_views; no warning is emitted for that. I'm happy to add one likeLazyViewsRequireViewsif you'd prefer.__buffa::lazy_viewlayout. If it doesn't, the consumer crate fails to compile with an unresolved path.extern_path's own misconfigurations surface the same way.Tests
buffa-codegen, four unit tests intests/view_codegen.rs:LazyMessageFieldViewand a repeated oneLazyRepeatedViewof the externThingLazyView;buffa-typesTimestampstays eager under.;Timestampmapped to another crate defers.protoc-gen-buffa: the option is normalized and repeatable, and invalid names are rejected.buffa-test, compiled and run:protos/lazy_extern.protomapstest.lazyviews(generated with lazy views) throughextern_pathandlazy_extern_path.lazy_extern_path_defers_extern_fieldsdecodes throughPairLazyView, singular and repeated, sees theTimestampstay eager, and round-trips throughto_owned_message.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepass.sf.ethereum.type.v2.Log. It compiles against substreams-ethereum 0.12.1 from crates.io, and a test decodes both fields through itsLogLazyViewand round-trips. This check ran on v0.9.2 becausemain's unreleased runtime requiresViewLifetimeParametric, which views generated by the 0.9.2 release (substreams 0.8's) don't implement.task lint-md;CLAUDE.md, which weren't available to the session that wrote this.🤖 Generated with Claude Code