Replace (Partial)Ord for EntityGeneration with corrected standalone method#19432
Conversation
ElliottjPierce
left a comment
There was a problem hiding this comment.
Wow! Good catch, and I like the new constant! Test looks good too. Very helpful.
One is not a real contributor until they break bevy lol.
|
What we also missed is that When
The solution here can be to do the same, add a method that is not an Please tell me if you think this is not a good solution and point out alternatives. 👋 |
|
Ah, that is my mistake, I had misunderstood the impl being an |
|
Yeah, I think a new method is the best. I would personally want The other thing is the |
Based on the raw interger I assume? I think this is controversial. When a type can have different kinds of ordering, like ordering books by their release date or their title, they should not implement
|
We already have precedent for this weirdness though, and that is Meaning we can decide either way! Arguably, Rust floats are a bit similar to this, where If we do not want this generation type to implement Sidenote: I see the |
|
My vote then is to remove the We should fix the bug and unblock avian quickly; then we can debate over if and how it should be implemented in a followup pr. |
Ord for EntityGenerationOrd for EntityGeneration with fixed standalone method
Ord for EntityGeneration with fixed standalone methodPartial)Ord for EntityGeneration with fixed standalone method
|
I removed ( On a personal note, I cannot see how you could guarantee that in some specific context the ordering is correct. But this is probably a close-enough matter for many use cases. |
|
Thinking of it this probably should have the returned ordering reversed or not be called "cmp_age_approx". 🤔 |
That's fair. I don't have a strong opinion. |
ElliottjPierce
left a comment
There was a problem hiding this comment.
Everything looks good to me!
|
Renamed it to |
Partial)Ord for EntityGeneration with fixed standalone methodPartial)Ord for EntityGeneration with corrected standalone method
…lone method (bevyengine#19432) # Objective bevyengine#19421 implemented `Ord` for `EntityGeneration` along the lines of [the impl from slotmap](https://docs.rs/slotmap/latest/src/slotmap/util.rs.html#8): ```rs /// Returns if a is an older version than b, taking into account wrapping of /// versions. pub fn is_older_version(a: u32, b: u32) -> bool { let diff = a.wrapping_sub(b); diff >= (1 << 31) } ``` But that PR and the slotmap impl are different: **slotmap impl** - if `(1u32 << 31)` is greater than `a.wrapping_sub(b)`, then `a` is older than `b` - if `(1u32 << 31)` is equal to `a.wrapping_sub(b)`, then `a` is older than `b` - if `(1u32 << 31)` is less than `a.wrapping_sub(b)`, then `a` is equal or newer than `b` **previous PR impl** - if `(1u32 << 31)` is greater than `a.wrapping_sub(b)`, then `a` is older than `b` - if `(1u32 << 31)` is equal to `a.wrapping_sub(b)`, then `a` is equal to `b`⚠️ - if `(1u32 << 31)` is less than `a.wrapping_sub(b)`, then `a` is newer than `b`⚠️ This ordering is also not transitive, therefore it should not implement `PartialOrd`. ## Solution Fix the impl in a standalone method, remove the `Partialord`/`Ord` implementation. ## Testing Given the first impl was wrong and got past reviews, I think a new unit test is justified.
Objective
#19421 implemented
OrdforEntityGenerationalong the lines of the impl from slotmap:But that PR and the slotmap impl are different:
slotmap impl
(1u32 << 31)is greater thana.wrapping_sub(b), thenais older thanb(1u32 << 31)is equal toa.wrapping_sub(b), thenais older thanb(1u32 << 31)is less thana.wrapping_sub(b), thenais equal or newer thanbprevious PR impl
(1u32 << 31)is greater thana.wrapping_sub(b), thenais older thanb(1u32 << 31)is equal toa.wrapping_sub(b), thenais equal tob(1u32 << 31)is less thana.wrapping_sub(b), thenais newer thanbThis ordering is also not transitive, therefore it should not implement
PartialOrd.Solution
Fix the impl in a standalone method, remove the
Partialord/Ordimplementation.Testing
Given the first impl was wrong and got past reviews, I think a new unit test is justified.