-
Notifications
You must be signed in to change notification settings - Fork 105
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
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
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.46% 87.46%
=======================================
Files 16 16
Lines 6021 6021
=======================================
Hits 5266 5266
Misses 755 755 ☔ 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 |
b8eeb75
to
9c82f0c
Compare
Okay, rebasing this on our recent work makes the error messages much less verbose. See the In #1752, we bubble errors up as errors rather than as |
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
9c82f0c
to
4fb2b11
Compare
zerocopy-derive/src/output_tests.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Add more output tests for this optimization.
4fb2b11
to
d01d187
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
d01d187
to
e99b3ef
Compare
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