Split traits for plain and bitpacked decoding and fix soundness issue in BitReader::get_batch#10172
Open
jhorstmann wants to merge 2 commits into
Open
Split traits for plain and bitpacked decoding and fix soundness issue in BitReader::get_batch#10172jhorstmann wants to merge 2 commits into
jhorstmann wants to merge 2 commits into
Conversation
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.
Which issue does this PR close?
FromBytestrait andBitReader::get_batch#10164.Rationale for this change
The
FromBitpackedtrait was introduced in #9662 as a marker for types that could be decoded from bitpacked data, but the implementation still mostly used methods from itsFromBytessuper-trait. The implementation ofBitReader::get_batchthat dispatched on the size of the type then required a complex safety contract, which meant thatFromByteshad to be anunsafetrait.Instead of that size dispatch, we can move the unsafe code into a method of the
FromBitpackedtrait, which makesBitReader::get_batchcompletely safe. This also removes the need to make any of those traits sealed as proposed in #10166.What changes are included in this PR?
The responsibilities of the
FromBytesandFromBitpackedtraits should be much clearer now:FromBytesis used for plain encoded dataFromBitpackedis used for bitpacked dataUnsafe code is moved from
BitReader::get_batchinto some of theFromBitpackedimplementations.Are these changes tested?
All existing tests pass.
Are there any user-facing changes?
FromBitpackedgains a new method and is no longer a sub-trait ofFromBytes, so this might be breaking change. Code that previously implementedFromByteswill need to change to remove theunsafekeyword andBIT_CAPACITYconstant.