bevy/crates
Kanabenki 025e8e639c
Fix Ord and PartialOrd differing for FloatOrd and optimize implementation (#12711)
# Objective

- `FloatOrd` currently has a different comparison behavior between its
derived `PartialOrd` impl and manually implemented `Ord` impl (The
[`Ord` doc](https://doc.rust-lang.org/std/cmp/trait.Ord.html) says this
is a logic error). This might be a problem for some `std`
containers/algorithms if they rely on both matching, and a footgun for
Bevy users.

## Solution

- Replace the `PartialEq` and `Ord` impls of `FloatOrd` with some
equivalent ones producing [better
assembly.](https://godbolt.org/z/jaWbjnMKx)
- Manually derive `PartialOrd` with the same behavior as `Ord`,
implement the comparison operators.
- Add some tests.

I first tried using a match-based implementation similar to the
`PartialOrd` impl [of the
std](https://doc.rust-lang.org/src/core/cmp.rs.html#1457) (with added
NaN ordering) but I couldn't get it to produce non-branching assembly.
The current implementation is based on [the one from the `ordered_float`
crate](3641f59e31/src/lib.rs (L121)),
adapted since it uses a different ordering. Should this be mentionned
somewhere in the code?

---

## Changelog

### Fixed

- `FloatOrd` now uses the same ordering for its `PartialOrd` and `Ord`
implementations.

## Migration Guide

- If you were depending on the `PartialOrd` behaviour of `FloatOrd`, it
has changed from matching `f32` to matching `FloatOrd`'s `Ord` ordering,
never returning `None`.
2024-03-27 00:26:56 +00:00
..
bevy_a11y Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_animation Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_app Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_asset Fix fetching assets in Web Workers (#12134) 2024-03-25 19:09:30 +00:00
bevy_audio Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_color Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_core Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_core_pipeline Meshlet rendering (initial feature) (#10164) 2024-03-25 19:08:27 +00:00
bevy_derive Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_dev_tools rename debug_overlay to ui_debug_overlay in bevy_dev_tools (#12737) 2024-03-26 19:40:55 +00:00
bevy_diagnostic Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_dylib Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_dynamic_plugin Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_ecs Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_ecs_compile_fail_tests Fix Ci failing over dead code in tests (#12623) 2024-03-21 18:08:47 +00:00
bevy_encase_derive Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_gilrs Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_gizmos Remove unnecessary executable flags from Rust source files (#12707) 2024-03-25 20:03:55 +00:00
bevy_gltf Support calculating normals for indexed meshes (#11654) 2024-03-25 19:09:24 +00:00
bevy_hierarchy Add entity id to hierarchy propagation error message (#12733) 2024-03-26 15:20:21 +00:00
bevy_input Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_internal Meshlet rendering (initial feature) (#10164) 2024-03-25 19:08:27 +00:00
bevy_log Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_macro_utils Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_macros_compile_fail_tests Fix Ci failing over dead code in tests (#12623) 2024-03-21 18:08:47 +00:00
bevy_math Add Annulus primitive to bevy_math::primitives (#12706) 2024-03-25 23:13:14 +00:00
bevy_mikktspace Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_panic_handler Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_pbr Meshlet rendering (initial feature) (#10164) 2024-03-25 19:08:27 +00:00
bevy_ptr Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_reflect bevy_reflect: Rename UntypedReflectDeserializer to ReflectDeserializer (#12721) 2024-03-26 19:58:29 +00:00
bevy_reflect_compile_fail_tests Fix Ci failing over dead code in tests (#12623) 2024-03-21 18:08:47 +00:00
bevy_render Fix CI for wasm atomics (#12730) 2024-03-26 14:26:21 +00:00
bevy_scene bevy_reflect: Rename UntypedReflectDeserializer to ReflectDeserializer (#12721) 2024-03-26 19:58:29 +00:00
bevy_sprite Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_tasks Remove unnecessary executable flags from Rust source files (#12707) 2024-03-25 20:03:55 +00:00
bevy_text Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_time Remove unnecessary executable flags from Rust source files (#12707) 2024-03-25 20:03:55 +00:00
bevy_transform Remove unnecessary executable flags from Rust source files (#12707) 2024-03-25 20:03:55 +00:00
bevy_ui Restore pre 0.13.1 Root Node Layout behavior (#12698) 2024-03-25 19:11:50 +00:00
bevy_utils Fix Ord and PartialOrd differing for FloatOrd and optimize implementation (#12711) 2024-03-27 00:26:56 +00:00
bevy_window Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_winit Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00