-
Notifications
You must be signed in to change notification settings - Fork 547
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
archive derive of PartialEq for rkyv - 0.4.x #959
Conversation
Thanks for this @mkatychev - sorry to be a pain but do you mind doing a |
@esheppa After testing, I had to introduce a couple of changes to enable safe deserlialization. // You can use the safe API for fast zero-copy deserialization
let archived = rkyv::check_archived_root::<Test>(&bytes[..]).unwrap();
assert_eq!(archived, &value);
// Or you can use the unsafe API for maximum performance
let archived = unsafe { rkyv::archived_root::<Test>(&bytes[..]) };
assert_eq!(archived, &value); This seems like a core part of the way rkyv should work so I added a PR upstream to re-export In the meantime however, it made the most sense to add |
d33f4d0
to
2a985a6
Compare
27ca8dd
to
d37b0be
Compare
chrono/.github/workflows/test.yml Lines 52 to 56 in d37b0be
The |
For the 0.4.x branch, we're sticking with 1.38 for now, so the two optional deps would be the way forward for now. Thanks! |
9bf3815
to
6e46aa3
Compare
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.
I visually reviewed. LGTM. However, I know very little about serde internals so I won't be able to spot serde-specific bugs.
Does this change need new test cases?
For example, I see the rkyv
project implements a some test macros like pub fn test_archive<T>(value: &T)
https://github.com/rkyv/rkyv/blob/master/rkyv_test/src/util.rs#L4
and test cases using those macros like fn archive_containers()
https://github.com/rkyv/rkyv/blob/master/rkyv_test/src/test_alloc.rs#L36
Should the definitions here have test cases that exercise the rkyv
features?
I did a bit of upstream work in |
@jtmoon79 I'm going to wait for
So the Without the
Other than the codeblock here: Lines 553 to 566 in 5658c49
This PR doesn't really introduce any rust code since these derives will fail at compile time. The most you'd have to do is see if This line covers chrono/.github/workflows/test.yml Line 81 in 5658c49
I'll be sure to add |
would you mind adding |
@jtmoon79 |
@mkatychev I have yet to go and read up about rkyv. But can I ask for your opinion/review of #762? |
@pitdicker I'll post my thoughts in this PR, I'm using this current feature branch in my code, and this section does not impact me:
As long as the
In essence, the |
@pitdicker what else is needed to move this review forward? |
Codecov Report
@@ Coverage Diff @@
## 0.4.x #959 +/- ##
==========================================
+ Coverage 91.55% 91.60% +0.04%
==========================================
Files 38 38
Lines 17355 17430 +75
==========================================
+ Hits 15889 15966 +77
+ Misses 1466 1464 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thank you for your work!
Me needing to get a little experience with rkyv, because I don't understand it yet 😄. Or a review from @djc. |
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.
What I am missing with the rkyv
feature is that we don't have any tests. That is not a fault of this PR, but can you please add some?
I don't think it needs to be more than a check that all types round-trip with rkyv::{to_bytes, from_bytes}
.
And maybe include a check that the derived types implement PartialOrd
, PartialEq
and Edit: Better to check (of course) that comparison works against the original type.Debug
similar to https://github.com/chronotope/chrono/blob/v0.4.31/src/datetime/tests.rs#L1132.
That should also make coverage happy.
And can you squash the commits?
@mkatychev No hurry, just a reminder. |
@pitdicker apologies for delay, I will start work on this tomorrow. |
src/offset/utc.rs
Outdated
#[derive(Copy, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))] | ||
#[cfg_attr(feature = "rkyv", archive_attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash)))] | ||
#[derive(Clone, Copy, Eq, Hash, PartialEq)] |
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.
I sorted the derives alphabetically to better compare against the archive_attr
equivalents.
@pitdicker this should be ready for review again |
Tagging related issues for |
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.
Looking good 😄. A few comments, and we have trouble with our MSRV.
Can you squash the commits?
Cargo.toml
Outdated
__internal_bench = [] | ||
|
||
[dependencies] | ||
num-traits = { version = "0.2", default-features = false } | ||
rustc-serialize = { version = "0.3.20", optional = true } | ||
serde = { version = "1.0.99", default-features = false, optional = true } | ||
pure-rust-locales = { version = "0.7", optional = true } | ||
rkyv = { version = "0.7", optional = true } | ||
rkyv = { version = "0.7.42", optional = true } |
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.
rkyv = { version = "0.7.42", optional = true } | |
rkyv = { version = "0.7.41", optional = true } |
I hope that by setting 0.7.41
as the minimum version and with rkyv/bytecheck#33 that we can get things working with our MSRV.
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.
I'm curious why 0.7.42
was not able to be found 🤔 🤔
Thanks for pushing this through @pitdicker ! |
This needs to be rebased and split into clean commits so I can review it. Right now there's too much going on when reviewing all the changes at once (notably reordering of derives while also adding/removing derives) to make this efficient to review. |
@djc I'll rebase the commits later this week, I'll just skip the reordering altogether to make reviewing easier |
* specified latest hotfix version of `rkyv` that includes `bytecheck` reexport
…ature flags * added `archive(check_bytes)` derives `rkyv-validation` feature flags
chrono month::tests::test_rkyv_validation chrono naive::date::tests::test_rkyv_validation chrono duration::tests::test_rkyv_validation chrono naive::datetime::tests::test_rkyv_validation chrono naive::isoweek::tests::test_rkyv_validation chrono naive::time::tests::test_rkyv_validation chrono offset::fixed::tests::test_rkyv_validation chrono offset::local::tests::test_rkyv_validation chrono weekday::tests::test_rkyv_validation
4adeb52
to
4e1734e
Compare
@djc This should be ready for review |
Thanks! |
This PR resolves
PartialEq
compilation errors for types that deriverkyv::Archive
:This PR does not address #762 since a new archived object is created, for example
ArchivedDateTime<Utc>
is derived fromDateTime<Utc>
, but does preserve feature inclusivity.I don't think this change merits tests as the object created is not directly accessible for comparison as shown in the rkyv basic example but happy to discuss.