Skip to content

Commit 8b9d88f

Browse files
authored
Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() (#8764)
Followup to #7184 This makes `Reflect: DynamicTypePath` which allows us to remove `Reflect::get_type_path`, reducing unnecessary codegen and simplifying `Reflect` implementations.
1 parent 89cbc78 commit 8b9d88f

17 files changed

+36
-143
lines changed

crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs

-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> TokenStream {
199199
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
200200
}
201201

202-
#[inline]
203-
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
204-
self
205-
}
206-
207202
#[inline]
208203
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
209204
self

crates/bevy_reflect/bevy_reflect_derive/src/impls/structs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> TokenStream {
174174
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
175175
}
176176

177-
#[inline]
178-
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
179-
self
180-
}
181-
182177
#[inline]
183178
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
184179
self

crates/bevy_reflect/bevy_reflect_derive/src/impls/tuple_structs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> TokenStream {
144144
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
145145
}
146146

147-
#[inline]
148-
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
149-
self
150-
}
151-
152147
#[inline]
153148
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
154149
self

crates/bevy_reflect/bevy_reflect_derive/src/impls/values.rs

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> TokenStream {
5656
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
5757
}
5858

59-
#[inline]
60-
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
61-
self
62-
}
63-
6459
#[inline]
6560
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
6661
self

crates/bevy_reflect/src/array.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use bevy_reflect_derive::impl_type_path;
2-
31
use crate::{
4-
self as bevy_reflect, utility::reflect_hasher, DynamicTypePath, Reflect, ReflectMut,
5-
ReflectOwned, ReflectRef, TypeInfo,
2+
self as bevy_reflect, utility::reflect_hasher, Reflect, ReflectMut, ReflectOwned, ReflectRef,
3+
TypeInfo,
64
};
5+
use bevy_reflect_derive::impl_type_path;
76
use std::{
87
any::{Any, TypeId},
98
fmt::Debug,
@@ -226,11 +225,6 @@ impl Reflect for DynamicArray {
226225
self.represented_type
227226
}
228227

229-
#[inline]
230-
fn get_type_path(&self) -> &dyn DynamicTypePath {
231-
self
232-
}
233-
234228
#[inline]
235229
fn into_any(self: Box<Self>) -> Box<dyn Any> {
236230
self

crates/bevy_reflect/src/enums/dynamic_enum.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use bevy_reflect_derive::impl_type_path;
22

33
use crate::{
44
self as bevy_reflect, enum_debug, enum_hash, enum_partial_eq, DynamicStruct, DynamicTuple,
5-
DynamicTypePath, Enum, Reflect, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple, TypeInfo,
6-
VariantFieldIter, VariantType,
5+
Enum, Reflect, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple, TypeInfo, VariantFieldIter,
6+
VariantType,
77
};
88
use std::any::Any;
99
use std::fmt::Formatter;
@@ -300,11 +300,6 @@ impl Reflect for DynamicEnum {
300300
self.represented_type
301301
}
302302

303-
#[inline]
304-
fn get_type_path(&self) -> &dyn DynamicTypePath {
305-
self
306-
}
307-
308303
#[inline]
309304
fn into_any(self: Box<Self>) -> Box<dyn Any> {
310305
self

crates/bevy_reflect/src/impls/smallvec.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::any::Any;
44

55
use crate::utility::GenericTypeInfoCell;
66
use crate::{
7-
self as bevy_reflect, DynamicTypePath, FromReflect, FromType, GetTypeRegistration, List,
8-
ListInfo, ListIter, Reflect, ReflectFromPtr, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
9-
TypePath, TypeRegistration, Typed,
7+
self as bevy_reflect, FromReflect, FromType, GetTypeRegistration, List, ListInfo, ListIter,
8+
Reflect, ReflectFromPtr, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath,
9+
TypeRegistration, Typed,
1010
};
1111

1212
impl<T: smallvec::Array + TypePath + Send + Sync> List for SmallVec<T>
@@ -88,11 +88,6 @@ where
8888
Some(<Self as Typed>::type_info())
8989
}
9090

91-
#[inline]
92-
fn get_type_path(&self) -> &dyn DynamicTypePath {
93-
self
94-
}
95-
9691
fn into_any(self: Box<Self>) -> Box<dyn Any> {
9792
self
9893
}

crates/bevy_reflect/src/impls/std.rs

+2-36
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::std_traits::ReflectDefault;
22
use crate::{self as bevy_reflect, ReflectFromPtr, ReflectFromReflect, ReflectOwned};
33
use crate::{
44
impl_type_path, map_apply, map_partial_eq, Array, ArrayInfo, ArrayIter, DynamicEnum,
5-
DynamicMap, DynamicTypePath, Enum, EnumInfo, FromReflect, FromType, GetTypeRegistration, List,
6-
ListInfo, ListIter, Map, MapInfo, MapIter, Reflect, ReflectDeserialize, ReflectMut, ReflectRef,
5+
DynamicMap, Enum, EnumInfo, FromReflect, FromType, GetTypeRegistration, List, ListInfo,
6+
ListIter, Map, MapInfo, MapIter, Reflect, ReflectDeserialize, ReflectMut, ReflectRef,
77
ReflectSerialize, TupleVariantInfo, TypeInfo, TypePath, TypeRegistration, Typed,
88
UnitVariantInfo, UnnamedField, ValueInfo, VariantFieldIter, VariantInfo, VariantType,
99
};
@@ -332,11 +332,6 @@ macro_rules! impl_reflect_for_veclike {
332332
Some(<Self as Typed>::type_info())
333333
}
334334

335-
#[inline]
336-
fn get_type_path(&self) -> &dyn DynamicTypePath {
337-
self
338-
}
339-
340335
fn into_any(self: Box<Self>) -> Box<dyn Any> {
341336
self
342337
}
@@ -555,10 +550,6 @@ macro_rules! impl_reflect_for_hashmap {
555550
Some(<Self as Typed>::type_info())
556551
}
557552

558-
fn get_type_path(&self) -> &dyn DynamicTypePath {
559-
self
560-
}
561-
562553
fn into_any(self: Box<Self>) -> Box<dyn Any> {
563554
self
564555
}
@@ -721,11 +712,6 @@ impl<T: Reflect + TypePath, const N: usize> Reflect for [T; N] {
721712
Some(<Self as Typed>::type_info())
722713
}
723714

724-
#[inline]
725-
fn get_type_path(&self) -> &dyn DynamicTypePath {
726-
self
727-
}
728-
729715
#[inline]
730716
fn into_any(self: Box<Self>) -> Box<dyn Any> {
731717
self
@@ -943,11 +929,6 @@ impl<T: FromReflect + TypePath> Reflect for Option<T> {
943929
Some(<Self as Typed>::type_info())
944930
}
945931

946-
#[inline]
947-
fn get_type_path(&self) -> &dyn DynamicTypePath {
948-
self
949-
}
950-
951932
#[inline]
952933
fn into_any(self: Box<Self>) -> Box<dyn Any> {
953934
self
@@ -1115,11 +1096,6 @@ impl Reflect for Cow<'static, str> {
11151096
Some(<Self as Typed>::type_info())
11161097
}
11171098

1118-
#[inline]
1119-
fn get_type_path(&self) -> &dyn DynamicTypePath {
1120-
self
1121-
}
1122-
11231099
fn into_any(self: Box<Self>) -> Box<dyn Any> {
11241100
self
11251101
}
@@ -1252,11 +1228,6 @@ impl Reflect for &'static Path {
12521228
Some(<Self as Typed>::type_info())
12531229
}
12541230

1255-
#[inline]
1256-
fn get_type_path(&self) -> &dyn DynamicTypePath {
1257-
self
1258-
}
1259-
12601231
fn into_any(self: Box<Self>) -> Box<dyn Any> {
12611232
self
12621233
}
@@ -1366,11 +1337,6 @@ impl Reflect for Cow<'static, Path> {
13661337
std::any::type_name::<Self>()
13671338
}
13681339

1369-
#[inline]
1370-
fn get_type_path(&self) -> &dyn DynamicTypePath {
1371-
self
1372-
}
1373-
13741340
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
13751341
Some(<Self as Typed>::type_info())
13761342
}

crates/bevy_reflect/src/list.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use bevy_reflect_derive::impl_type_path;
66

77
use crate::utility::reflect_hasher;
88
use crate::{
9-
self as bevy_reflect, DynamicTypePath, FromReflect, Reflect, ReflectMut, ReflectOwned,
10-
ReflectRef, TypeInfo,
9+
self as bevy_reflect, FromReflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
1110
};
1211

1312
/// A trait used to power [list-like] operations via [reflection].
@@ -276,11 +275,6 @@ impl Reflect for DynamicList {
276275
self.represented_type
277276
}
278277

279-
#[inline]
280-
fn get_type_path(&self) -> &dyn DynamicTypePath {
281-
self
282-
}
283-
284278
#[inline]
285279
fn into_any(self: Box<Self>) -> Box<dyn Any> {
286280
self

crates/bevy_reflect/src/map.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::hash::Hash;
55
use bevy_reflect_derive::impl_type_path;
66
use bevy_utils::{Entry, HashMap};
77

8-
use crate::{
9-
self as bevy_reflect, DynamicTypePath, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
10-
};
8+
use crate::{self as bevy_reflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo};
119

1210
/// A trait used to power [map-like] operations via [reflection].
1311
///
@@ -310,11 +308,6 @@ impl Reflect for DynamicMap {
310308
self.represented_type
311309
}
312310

313-
#[inline]
314-
fn get_type_path(&self) -> &dyn DynamicTypePath {
315-
self
316-
}
317-
318311
fn into_any(self: Box<Self>) -> Box<dyn Any> {
319312
self
320313
}

crates/bevy_reflect/src/reflect.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum ReflectOwned {
7272
/// [`bevy_reflect`]: crate
7373
/// [derive macro]: bevy_reflect_derive::Reflect
7474
/// [crate-level documentation]: crate
75-
pub trait Reflect: Any + Send + Sync {
75+
pub trait Reflect: DynamicTypePath + Any + Send + Sync {
7676
/// Returns the [type name][std::any::type_name] of the underlying type.
7777
fn type_name(&self) -> &str;
7878

@@ -93,14 +93,6 @@ pub trait Reflect: Any + Send + Sync {
9393
/// [`TypeRegistry::get_type_info`]: crate::TypeRegistry::get_type_info
9494
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>;
9595

96-
/// Returns the [`TypePath`] implementation for the underlying type.
97-
///
98-
/// Methods on [`DynamicTypePath`] suffer the same performance concerns as [`get_represented_type_info`].
99-
///
100-
/// [`TypePath`]: crate::TypePath
101-
/// [`get_represented_type_info`]: Reflect::get_represented_type_info
102-
fn get_type_path(&self) -> &dyn DynamicTypePath;
103-
10496
/// Returns the value as a [`Box<dyn Any>`][std::any::Any].
10597
fn into_any(self: Box<Self>) -> Box<dyn Any>;
10698

crates/bevy_reflect/src/struct_trait.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
2-
self as bevy_reflect, DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned,
3-
ReflectRef, TypeInfo,
2+
self as bevy_reflect, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
43
};
54
use bevy_reflect_derive::impl_type_path;
65
use bevy_utils::{Entry, HashMap};
@@ -405,11 +404,6 @@ impl Reflect for DynamicStruct {
405404
self.represented_type
406405
}
407406

408-
#[inline]
409-
fn get_type_path(&self) -> &dyn DynamicTypePath {
410-
self
411-
}
412-
413407
#[inline]
414408
fn into_any(self: Box<Self>) -> Box<dyn Any> {
415409
self

crates/bevy_reflect/src/tuple.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bevy_reflect_derive::impl_type_path;
22

33
use crate::{
4-
self as bevy_reflect, utility::GenericTypePathCell, DynamicTypePath, FromReflect,
5-
GetTypeRegistration, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath,
6-
TypeRegistration, Typed, UnnamedField,
4+
self as bevy_reflect, utility::GenericTypePathCell, FromReflect, GetTypeRegistration, Reflect,
5+
ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath, TypeRegistration, Typed,
6+
UnnamedField,
77
};
88
use std::any::{Any, TypeId};
99
use std::borrow::Cow;
@@ -321,11 +321,6 @@ impl Reflect for DynamicTuple {
321321
self.represented_type
322322
}
323323

324-
#[inline]
325-
fn get_type_path(&self) -> &dyn DynamicTypePath {
326-
self
327-
}
328-
329324
#[inline]
330325
fn into_any(self: Box<Self>) -> Box<dyn Any> {
331326
self
@@ -538,11 +533,6 @@ macro_rules! impl_reflect_tuple {
538533
Some(<Self as Typed>::type_info())
539534
}
540535

541-
#[inline]
542-
fn get_type_path(&self) -> &dyn DynamicTypePath {
543-
self
544-
}
545-
546536
fn into_any(self: Box<Self>) -> Box<dyn Any> {
547537
self
548538
}

crates/bevy_reflect/src/tuple_struct.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use bevy_reflect_derive::impl_type_path;
22

33
use crate::{
4-
self as bevy_reflect, DynamicTypePath, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
5-
UnnamedField,
4+
self as bevy_reflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, UnnamedField,
65
};
76
use std::any::{Any, TypeId};
87
use std::fmt::{Debug, Formatter};
@@ -308,11 +307,6 @@ impl Reflect for DynamicTupleStruct {
308307
self.represented_type
309308
}
310309

311-
#[inline]
312-
fn get_type_path(&self) -> &dyn DynamicTypePath {
313-
self
314-
}
315-
316310
#[inline]
317311
fn into_any(self: Box<Self>) -> Box<dyn Any> {
318312
self

crates/bevy_reflect/src/type_info.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::fmt::Debug;
2424
///
2525
/// ```
2626
/// # use std::any::Any;
27-
/// # use bevy_reflect::{DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, StructInfo, TypeInfo, ValueInfo};
27+
/// # use bevy_reflect::{DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, StructInfo, TypeInfo, TypePath, ValueInfo};
2828
/// # use bevy_reflect::utility::NonGenericTypeInfoCell;
2929
/// use bevy_reflect::Typed;
3030
///
@@ -51,7 +51,6 @@ use std::fmt::Debug;
5151
/// # impl Reflect for MyStruct {
5252
/// # fn type_name(&self) -> &str { todo!() }
5353
/// # fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { todo!() }
54-
/// # fn get_type_path(&self) -> &dyn DynamicTypePath { todo!() }
5554
/// # fn into_any(self: Box<Self>) -> Box<dyn Any> { todo!() }
5655
/// # fn as_any(&self) -> &dyn Any { todo!() }
5756
/// # fn as_any_mut(&mut self) -> &mut dyn Any { todo!() }
@@ -65,6 +64,11 @@ use std::fmt::Debug;
6564
/// # fn reflect_owned(self: Box<Self>) -> ReflectOwned { todo!() }
6665
/// # fn clone_value(&self) -> Box<dyn Reflect> { todo!() }
6766
/// # }
67+
/// #
68+
/// # impl TypePath for MyStruct {
69+
/// # fn type_path() -> &'static str { todo!() }
70+
/// # fn short_type_path() -> &'static str { todo!() }
71+
/// # }
6872
/// ```
6973
///
7074
/// [utility]: crate::utility

0 commit comments

Comments
 (0)