-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derive trivial is_bit_valid
when possible
#1303
base: main
Are you sure you want to change the base?
Conversation
c4af213
to
5e1948a
Compare
5e1948a
to
e80cb64
Compare
e80cb64
to
c0d052c
Compare
Discussed offline: previous version was unsound; requesting a re-review for the fix
c0d052c
to
d14d132
Compare
When deriving `FromBytes` on a type with no generic parameters, the implied `TryFromBytes` derive's `is_bit_valid` impl is generated as always returning `true`. This is faster to codegen, is faster to compile, and is friendlier on the optimizer. Makes progress on #5
d14d132
to
b8eeb75
Compare
@jswrenn Take a look at the
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1303 +/- ##
=======================================
Coverage 87.84% 87.84%
=======================================
Files 15 15
Lines 5191 5191
=======================================
Hits 4560 4560
Misses 631 631 ☔ View full report in Codecov by Sentry. |
is_bit_valid
when possible
I expected the expansion for this: #[derive(FromBytes)]
struct Foo {
a: u8,
b: u16,
} ...to look like this: unsafe impl ::zerocopy::TryFromBytes for Foo
where
u8: ::zerocopy::FromBytes,
u16: ::zerocopy::FromBytes,
{
fn only_derive_is_allowed_to_implement_this_trait() {}
fn is_bit_valid<A>(candidate: ::zerocopy::Maybe<Self, A>) -> bool
where
A: ::zerocopy::pointer::invariant::Aliasing
+ ::zerocopy::pointer::invariant::AtLeast<
::zerocopy::pointer::invariant::Shared,
>,
{
true
}
} Why doesn't it? Am I missing some subtlety here? |
It's unnecessary. If the top-level trait is I could also see replacing it with |
When deriving
FromBytes
on a type with no generic parameters, the impliedTryFromBytes
derive'sis_bit_valid
impl is generated as always returningtrue
. This is faster to codegen, is faster to compile, and is friendlier on the optimizer.Makes progress on #5