Add unbox_oneof to store non-recursive message oneof variants inline (#126)#151
Open
sam-shridhar1950f wants to merge 1 commit into
Open
Add unbox_oneof to store non-recursive message oneof variants inline (#126)#151sam-shridhar1950f wants to merge 1 commit into
sam-shridhar1950f wants to merge 1 commit into
Conversation
…pics#126) Message and group oneof variants are wrapped in Box<T> unconditionally. That wrapping is needed for recursive types, but for non-recursive variants it adds a heap allocation per variant construction. Add `unbox_oneof_in(paths)` / `unbox_oneof()` to buffa-build, backed by `unboxed_oneof_fields` in CodeGenConfig, matched with the same proto-segment-aware prefix logic as bytes_fields. A single `variant_boxed` helper threads the decision through every site that boxes a variant: the enum declaration, From impls, binary merge, JSON deserialize, text encode and merge, and the view-to-owned conversion. Opting a recursive variant out is rejected when the code is generated, since storing it inline would produce an unsized type.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
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.
Closes #126.
What
Adds an opt-out for the
Box<T>wrapping on message- and group-typed oneofvariants. By default every such variant is boxed so recursive types compile;
this lets a config rule store matching non-recursive variants inline instead.
Config::unbox_oneof_in(&[".pkg.Msg.oneof.variant"])opts specific paths outConfig::unbox_oneof()opts every non-recursive variant outuse_bytes_type_inHow
A single
variant_boxed(ctx, ty, variant_fqn)helper is the source of truth,threaded through each place that boxes a variant: the enum declaration, the
Fromimpls, binary merge, JSON deserialize, text encode and merge, and theview-to-owned conversion.
Opting a recursive variant out is rejected when the code is generated (it would
otherwise emit an enum that fails to compile as unsized), so the downstream
sites can trust the helper.
Tests
Boxfor the matched variant while siblings stayboxed; opting a recursive variant out returns an error
merge semantics, the
Fromimpl, and a still-boxed siblingNet diff is about 250 lines excluding tests.