descriptor: expose the pool ordinal of MessageIndex, EnumIndex and ExtensionIndex - #438
Open
harshitwandhare wants to merge 1 commit into
Open
harshitwandhare wants to merge 1 commit into
harshitwandhare wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
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 #433.
MessageIndex,EnumIndexandExtensionIndexeach gainindex(self) -> usize, returning the ordinal within the pool that issued them. This is the first of the two options in the issue, which it calls the smaller one and enough on its own.Why the ordinal is safe to document as dense. The pool stores each kind in a
Veckeyed by exactly this newtype (messages,enums,extensionsinpool.rs:610-620), and the existingmessages()/enums()/extensions()accessors already document themselves as returning them "in pool index order". So the ordinal is the slice position, and exposing it publishes a property the pool already holds rather than adding a constraint it now has to maintain. The doc comments say it is meaningless across pools, matching the caveat the types already carry for comparison.The count half of the ask turned out to be unnecessary. The issue also proposes
DescriptorPool::message_count()"and friends so a side table can be sized up front".messages(),enums()andextensions()are already public and return slices, sopool.messages().len()sizes the table today. I left those out rather than adding three accessors that duplicate alen()call. Say the word if you would still rather have them.Scope.
ServiceIndexhas the same shape and the same backingVec, but the issue names three types, so I did not touch it. Happy to add it in this PR if you want the set complete.Verification. Four tests in
buffa-descriptor/tests/pool_e2e.rs, against the realprotoc-built fixture pool (14 messages, 3 enums, 7 extensions, so none of the loops is vacuous). Three walk every descriptor of each kind, resolve its index back by full name, and assertindex()equals the enumerate position. The fourth fills aVecsized frommessages().len()by ordinal and asserts every slot is occupied, which is the dense-over-0..lenclaim the docs make and the thing a future change to index assignment would break.These cannot fail on
main, since the method does not exist there; they fail to compile. What they guard is the density property going forward.Gates run locally on
d02c80f:mainat053fcf3is 2849 passed on the same command, so the delta is exactly the four new tests. The MSRV run used the workflow's own lockfile regeneration step (CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback,cargo generate-lockfile) and the checked-inCargo.lockwas restored afterwards, so it is unchanged here.Changelog fragment added under
.changes/unreleased/rather than editingCHANGELOG.md. I do not have go-task installed, so the fragment was written by hand to match the existing files andchangie mergewas not run; that is the one gate I could not reproduce locally.