jhorstmann opened a new pull request, #10172:
URL: https://github.com/apache/arrow-rs/pull/10172
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax.
-->
- Closes #10164.
# Rationale for this change
The `FromBitpacked` trait was introduced in #9662 as a marker for types that
could be decoded from bitpacked data, but the implementation still mostly used
methods from its `FromBytes` super-trait. The implementation of
`BitReader::get_batch` that dispatched on the size of the type then required a
complex safety contract, which meant that `FromBytes` had to be an `unsafe`
trait.
Instead of that size dispatch, we can move the unsafe code into a method of
the `FromBitpacked` trait, which makes `BitReader::get_batch` completely safe.
This also removes the need to make any of those traits sealed as proposed in
#10166.
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
The responsibilities of the `FromBytes` and `FromBitpacked` traits should be
much clearer now:
- `FromBytes` is used for plain encoded data
- `FromBitpacked` is used for bitpacked data
Unsafe code is moved from `BitReader::get_batch` into some of the
`FromBitpacked` implementations.
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
# Are these changes tested?
All existing tests pass.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
If this PR claims a performance improvement, please include evidence such as
benchmark results.
-->
# Are there any user-facing changes?
`FromBitpacked` gains a new method and is no longer a sub-trait of
`FromBytes`, so this might be breaking change. Code that previously implemented
`FromBytes` will need to change to remove the `unsafe` keyword and
`BIT_CAPACITY` constant.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]