From 239f8dc7cb9aa4e59b31ee21c04087965eb644e6 Mon Sep 17 00:00:00 2001 From: JoJoJet Date: Mon, 8 Aug 2022 23:49:29 -0400 Subject: [PATCH] =?UTF-8?q?undo=20an=20optimization=20=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIRI is buggy so we can't use fn pointers for comparisons --- crates/bevy_utils/src/label.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/bevy_utils/src/label.rs b/crates/bevy_utils/src/label.rs index 596731bf55478..48a7bd16834a0 100644 --- a/crates/bevy_utils/src/label.rs +++ b/crates/bevy_utils/src/label.rs @@ -81,6 +81,7 @@ macro_rules! define_label { $(#[$id_attr])* #[derive(Clone, Copy)] pub struct $id_name { + ty: ::std::any::TypeId, data: u64, f: fn(u64, &mut ::std::fmt::Formatter) -> ::std::fmt::Result, } @@ -98,7 +99,7 @@ macro_rules! define_label { #[inline] fn as_label(&self) -> $id_name { let data = self.data(); - $id_name { data, f: Self::fmt } + $id_name { data, ty: ::std::any::TypeId::of::(), f: Self::fmt } } /// Returns a number used to distinguish different labels of the same type. fn data(&self) -> u64; @@ -128,7 +129,7 @@ macro_rules! define_label { impl PartialEq for $id_name { #[inline] fn eq(&self, rhs: &Self) -> bool { - (self.f as usize) == (rhs.f as usize) && self.data() == rhs.data() + self.ty == rhs.ty && self.data() == rhs.data() } } impl Eq for $id_name {} @@ -136,7 +137,7 @@ macro_rules! define_label { impl std::hash::Hash for $id_name { fn hash(&self, state: &mut H) { - (self.f as usize).hash(state); + self.ty.hash(state); self.data().hash(state); } } @@ -144,10 +145,7 @@ macro_rules! define_label { impl $id_name { /// Returns true if this label was constructed from an instance of type `L`. pub fn is(self) -> bool { - // FIXME: This is potentially incorrect, due to the - // compiler unifying identical functions. We'll likely - // have to store some kind of hash of the TypeId. - (self.f as usize) == (::fmt as usize) + self.ty == ::std::any::TypeId::of::() } /// Attempts to downcast this label to type `L`. ///