Skip to content

Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() #8764

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

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> TokenStream {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
self
}

#[inline]
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
self
Expand Down
5 changes: 0 additions & 5 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> TokenStream {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
self
}

#[inline]
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> TokenStream {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
self
}

#[inline]
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
self
Expand Down
5 changes: 0 additions & 5 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> TokenStream {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn #bevy_reflect_path::DynamicTypePath {
self
}

#[inline]
fn into_any(self: #FQBox<Self>) -> #FQBox<dyn #FQAny> {
self
Expand Down
12 changes: 3 additions & 9 deletions crates/bevy_reflect/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use bevy_reflect_derive::impl_type_path;

use crate::{
self as bevy_reflect, utility::reflect_hasher, DynamicTypePath, Reflect, ReflectMut,
ReflectOwned, ReflectRef, TypeInfo,
self as bevy_reflect, utility::reflect_hasher, Reflect, ReflectMut, ReflectOwned, ReflectRef,
TypeInfo,
};
use bevy_reflect_derive::impl_type_path;
use std::{
any::{Any, TypeId},
fmt::Debug,
Expand Down Expand Up @@ -226,11 +225,6 @@ impl Reflect for DynamicArray {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down
9 changes: 2 additions & 7 deletions crates/bevy_reflect/src/enums/dynamic_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bevy_reflect_derive::impl_type_path;

use crate::{
self as bevy_reflect, enum_debug, enum_hash, enum_partial_eq, DynamicStruct, DynamicTuple,
DynamicTypePath, Enum, Reflect, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple, TypeInfo,
VariantFieldIter, VariantType,
Enum, Reflect, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple, TypeInfo, VariantFieldIter,
VariantType,
};
use std::any::Any;
use std::fmt::Formatter;
Expand Down Expand Up @@ -300,11 +300,6 @@ impl Reflect for DynamicEnum {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down
11 changes: 3 additions & 8 deletions crates/bevy_reflect/src/impls/smallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::any::Any;

use crate::utility::GenericTypeInfoCell;
use crate::{
self as bevy_reflect, DynamicTypePath, FromReflect, FromType, GetTypeRegistration, List,
ListInfo, ListIter, Reflect, ReflectFromPtr, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
TypePath, TypeRegistration, Typed,
self as bevy_reflect, FromReflect, FromType, GetTypeRegistration, List, ListInfo, ListIter,
Reflect, ReflectFromPtr, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath,
TypeRegistration, Typed,
};

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

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down
38 changes: 2 additions & 36 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::std_traits::ReflectDefault;
use crate::{self as bevy_reflect, ReflectFromPtr, ReflectFromReflect, ReflectOwned};
use crate::{
impl_type_path, map_apply, map_partial_eq, Array, ArrayInfo, ArrayIter, DynamicEnum,
DynamicMap, DynamicTypePath, Enum, EnumInfo, FromReflect, FromType, GetTypeRegistration, List,
ListInfo, ListIter, Map, MapInfo, MapIter, Reflect, ReflectDeserialize, ReflectMut, ReflectRef,
DynamicMap, Enum, EnumInfo, FromReflect, FromType, GetTypeRegistration, List, ListInfo,
ListIter, Map, MapInfo, MapIter, Reflect, ReflectDeserialize, ReflectMut, ReflectRef,
ReflectSerialize, TupleVariantInfo, TypeInfo, TypePath, TypeRegistration, Typed,
UnitVariantInfo, UnnamedField, ValueInfo, VariantFieldIter, VariantInfo, VariantType,
};
Expand Down Expand Up @@ -332,11 +332,6 @@ macro_rules! impl_reflect_for_veclike {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down Expand Up @@ -555,10 +550,6 @@ macro_rules! impl_reflect_for_hashmap {
Some(<Self as Typed>::type_info())
}

fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down Expand Up @@ -721,11 +712,6 @@ impl<T: Reflect + TypePath, const N: usize> Reflect for [T; N] {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down Expand Up @@ -943,11 +929,6 @@ impl<T: FromReflect + TypePath> Reflect for Option<T> {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down Expand Up @@ -1115,11 +1096,6 @@ impl Reflect for Cow<'static, str> {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down Expand Up @@ -1252,11 +1228,6 @@ impl Reflect for &'static Path {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down Expand Up @@ -1366,11 +1337,6 @@ impl Reflect for Cow<'static, Path> {
std::any::type_name::<Self>()
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
Some(<Self as Typed>::type_info())
}
Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_reflect/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use bevy_reflect_derive::impl_type_path;

use crate::utility::reflect_hasher;
use crate::{
self as bevy_reflect, DynamicTypePath, FromReflect, Reflect, ReflectMut, ReflectOwned,
ReflectRef, TypeInfo,
self as bevy_reflect, FromReflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
};

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

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down
9 changes: 1 addition & 8 deletions crates/bevy_reflect/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::hash::Hash;
use bevy_reflect_derive::impl_type_path;
use bevy_utils::{Entry, HashMap};

use crate::{
self as bevy_reflect, DynamicTypePath, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
};
use crate::{self as bevy_reflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo};

/// A trait used to power [map-like] operations via [reflection].
///
Expand Down Expand Up @@ -310,11 +308,6 @@ impl Reflect for DynamicMap {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down
10 changes: 1 addition & 9 deletions crates/bevy_reflect/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum ReflectOwned {
/// [`bevy_reflect`]: crate
/// [derive macro]: bevy_reflect_derive::Reflect
/// [crate-level documentation]: crate
pub trait Reflect: Any + Send + Sync {
pub trait Reflect: DynamicTypePath + Any + Send + Sync {
/// Returns the [type name][std::any::type_name] of the underlying type.
fn type_name(&self) -> &str;

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

/// Returns the [`TypePath`] implementation for the underlying type.
///
/// Methods on [`DynamicTypePath`] suffer the same performance concerns as [`get_represented_type_info`].
///
/// [`TypePath`]: crate::TypePath
/// [`get_represented_type_info`]: Reflect::get_represented_type_info
fn get_type_path(&self) -> &dyn DynamicTypePath;

/// Returns the value as a [`Box<dyn Any>`][std::any::Any].
fn into_any(self: Box<Self>) -> Box<dyn Any>;

Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_reflect/src/struct_trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
self as bevy_reflect, DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned,
ReflectRef, TypeInfo,
self as bevy_reflect, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
};
use bevy_reflect_derive::impl_type_path;
use bevy_utils::{Entry, HashMap};
Expand Down Expand Up @@ -405,11 +404,6 @@ impl Reflect for DynamicStruct {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down
16 changes: 3 additions & 13 deletions crates/bevy_reflect/src/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bevy_reflect_derive::impl_type_path;

use crate::{
self as bevy_reflect, utility::GenericTypePathCell, DynamicTypePath, FromReflect,
GetTypeRegistration, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath,
TypeRegistration, Typed, UnnamedField,
self as bevy_reflect, utility::GenericTypePathCell, FromReflect, GetTypeRegistration, Reflect,
ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypePath, TypeRegistration, Typed,
UnnamedField,
};
use std::any::{Any, TypeId};
use std::borrow::Cow;
Expand Down Expand Up @@ -321,11 +321,6 @@ impl Reflect for DynamicTuple {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down Expand Up @@ -538,11 +533,6 @@ macro_rules! impl_reflect_tuple {
Some(<Self as Typed>::type_info())
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_reflect/src/tuple_struct.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use bevy_reflect_derive::impl_type_path;

use crate::{
self as bevy_reflect, DynamicTypePath, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo,
UnnamedField,
self as bevy_reflect, Reflect, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, UnnamedField,
};
use std::any::{Any, TypeId};
use std::fmt::{Debug, Formatter};
Expand Down Expand Up @@ -308,11 +307,6 @@ impl Reflect for DynamicTupleStruct {
self.represented_type
}

#[inline]
fn get_type_path(&self) -> &dyn DynamicTypePath {
self
}

#[inline]
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_reflect/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fmt::Debug;
///
/// ```
/// # use std::any::Any;
/// # use bevy_reflect::{DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, StructInfo, TypeInfo, ValueInfo};
/// # use bevy_reflect::{DynamicTypePath, NamedField, Reflect, ReflectMut, ReflectOwned, ReflectRef, StructInfo, TypeInfo, TypePath, ValueInfo};
/// # use bevy_reflect::utility::NonGenericTypeInfoCell;
/// use bevy_reflect::Typed;
///
Expand All @@ -51,7 +51,6 @@ use std::fmt::Debug;
/// # impl Reflect for MyStruct {
/// # fn type_name(&self) -> &str { todo!() }
/// # fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { todo!() }
/// # fn get_type_path(&self) -> &dyn DynamicTypePath { todo!() }
/// # fn into_any(self: Box<Self>) -> Box<dyn Any> { todo!() }
/// # fn as_any(&self) -> &dyn Any { todo!() }
/// # fn as_any_mut(&mut self) -> &mut dyn Any { todo!() }
Expand All @@ -65,6 +64,11 @@ use std::fmt::Debug;
/// # fn reflect_owned(self: Box<Self>) -> ReflectOwned { todo!() }
/// # fn clone_value(&self) -> Box<dyn Reflect> { todo!() }
/// # }
/// #
/// # impl TypePath for MyStruct {
/// # fn type_path() -> &'static str { todo!() }
/// # fn short_type_path() -> &'static str { todo!() }
/// # }
/// ```
///
/// [utility]: crate::utility
Expand Down
Loading