Skip to content
Open
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
4 changes: 2 additions & 2 deletions benches/benches/bevy_reflect/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ fn concrete_struct_type_info(criterion: &mut Criterion) {
BenchmarkId::new("NonGeneric", field_count),
&standard,
|bencher, s| {
bencher.iter(|| s.get_represented_type_info());
bencher.iter(|| s.runtime_type_info());
},
);
group.bench_with_input(
BenchmarkId::new("Generic", field_count),
&generic,
|bencher, s| {
bencher.iter(|| s.get_represented_type_info());
bencher.iter(|| s.runtime_type_info());
},
);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_asset/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ impl ReflectSerializerProcessor for HandleSerializeProcessor {
// This is a slow path. Users are unlikely to be intentionally serializing types without
// reflection, especially in production apps, so we can afford to be slow and give
// better diagnostics.
if let Some(type_info) = value_reflect.get_represented_type_info()
&& type_info.type_path().starts_with("bevy_asset::Handle")
if let Some(ty) = value_reflect.runtime_type()
&& ty.path().starts_with("bevy_asset::Handle")
{
warn!(
"HandleSerializeProcessor attempted to serialize a handle type \"{}\" without type data. This likely means the asset type was not registered.",
type_info.type_path()
"HandleSerializeProcessor attempted to serialize a handle type \"{:?}\" without type data. This likely means the asset type was not registered.",
ty
);
}
// Otherwise, fall back to the underlying serializer. Let it handle the error.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/reflect/entity_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn insert_reflect_with_registry_ref(
component: Box<dyn PartialReflect>,
) {
let type_info = component
.get_represented_type_info()
.runtime_type_info()
.expect("component should represent a type.");
let type_path = type_info.type_path();
let Some(type_registration) = type_registry.get(type_info.type_id()) else {
Expand Down
12 changes: 11 additions & 1 deletion crates/bevy_reflect/derive/src/impls/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,17 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream

impl #impl_generics #bevy_reflect_path::PartialReflect for #enum_path #ty_generics #where_reflect_clause {
#[inline]
fn get_represented_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
fn comptime_type(&self) -> #bevy_reflect_path::ty::Type {
#bevy_reflect_path::ty::Type::of::<Self>()
}

#[inline]
fn runtime_type(&self) -> #FQOption<#bevy_reflect_path::ty::Type> {
Some(#bevy_reflect_path::ty::Type::of::<Self>())
}

#[inline]
fn runtime_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

Expand Down
12 changes: 11 additions & 1 deletion crates/bevy_reflect/derive/src/impls/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream {

impl #impl_generics #bevy_reflect_path::PartialReflect for #type_path #ty_generics #where_reflect_clause {
#[inline]
fn get_represented_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
fn comptime_type(&self) -> #bevy_reflect_path::ty::Type {
#bevy_reflect_path::ty::Type::of::<Self>()
}

#[inline]
fn runtime_type(&self) -> #FQOption<#bevy_reflect_path::ty::Type> {
Some(#bevy_reflect_path::ty::Type::of::<Self>())
}

#[inline]
fn runtime_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_reflect/derive/src/impls/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,25 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS

fn to_dynamic_struct(&self) -> #bevy_reflect_path::structs::DynamicStruct {
let mut dynamic: #bevy_reflect_path::structs::DynamicStruct = #FQDefault::default();
dynamic.set_represented_type(#bevy_reflect_path::PartialReflect::get_represented_type_info(self));
dynamic.set_represented_type(#bevy_reflect_path::PartialReflect::runtime_type_info(self));
#(dynamic.insert_boxed(#field_names, #bevy_reflect_path::PartialReflect::to_dynamic(#fields_ref));)*
dynamic
}
}

impl #impl_generics #bevy_reflect_path::PartialReflect for #struct_path #ty_generics #where_reflect_clause {
#[inline]
fn get_represented_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
fn comptime_type(&self) -> #bevy_reflect_path::ty::Type {
#bevy_reflect_path::ty::Type::of::<Self>()
}

#[inline]
fn runtime_type(&self) -> #FQOption<#bevy_reflect_path::ty::Type> {
Some(#bevy_reflect_path::ty::Type::of::<Self>())
}

#[inline]
fn runtime_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_reflect/derive/src/impls/tuple_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,25 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2::

fn to_dynamic_tuple_struct(&self) -> #bevy_reflect_path::tuple_struct::DynamicTupleStruct {
let mut dynamic: #bevy_reflect_path::tuple_struct::DynamicTupleStruct = #FQDefault::default();
dynamic.set_represented_type(#bevy_reflect_path::PartialReflect::get_represented_type_info(self));
dynamic.set_represented_type(#bevy_reflect_path::PartialReflect::runtime_type_info(self));
#(dynamic.insert_boxed(#bevy_reflect_path::PartialReflect::to_dynamic(#fields_ref));)*
dynamic
}
}

impl #impl_generics #bevy_reflect_path::PartialReflect for #struct_path #ty_generics #where_reflect_clause {
#[inline]
fn get_represented_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
fn comptime_type(&self) -> #bevy_reflect_path::ty::Type {
#bevy_reflect_path::ty::Type::of::<Self>()
}

#[inline]
fn runtime_type(&self) -> #FQOption<#bevy_reflect_path::ty::Type> {
Some(#bevy_reflect_path::ty::Type::of::<Self>())
}

#[inline]
fn runtime_type_info(&self) -> #FQOption<&'static #bevy_reflect_path::TypeInfo> {
#FQOption::Some(<Self as #bevy_reflect_path::Typed>::type_info())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/derive/src/impls/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub(crate) fn impl_typed(
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

// The `[inline(never)]` is a binary size optimization, although it may
// slightly increase the cost of calling `get_represented_type_info`.
// slightly increase the cost of calling `runtime_type_info`.
quote! {
impl #impl_generics #bevy_reflect_path::Typed for #type_path #ty_generics #where_reflect_clause {
#[inline(never)]
Expand Down
16 changes: 13 additions & 3 deletions crates/bevy_reflect/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ pub trait Array: PartialReflect {
/// Creates a new [`DynamicArray`] from this array.
fn to_dynamic_array(&self) -> DynamicArray {
DynamicArray {
represented_type: self.get_represented_type_info(),
represented_type: self.runtime_type_info(),
values: self.iter().map(PartialReflect::to_dynamic).collect(),
}
}

/// Will return `None` if [`TypeInfo`] is not available.
fn get_represented_array_info(&self) -> Option<&'static ArrayInfo> {
self.get_represented_type_info()?.as_array().ok()
self.runtime_type_info()?.as_array().ok()
}
}

Expand Down Expand Up @@ -200,10 +200,20 @@ impl DynamicArray {

impl PartialReflect for DynamicArray {
#[inline]
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
fn comptime_type(&self) -> Type {
Type::of::<Self>()
}

#[inline]
fn runtime_type_info(&self) -> Option<&'static TypeInfo> {
self.represented_type
}

#[inline]
fn runtime_type(&self) -> Option<Type> {
self.represented_type.map(TypeInfo::ty).copied()
}

#[inline]
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect> {
self
Expand Down
15 changes: 13 additions & 2 deletions crates/bevy_reflect/src/enums/dynamic_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};

use alloc::{boxed::Box, string::String};
use bevy_reflect::Type;
use core::fmt::Formatter;
use derive_more::derive::From;

Expand Down Expand Up @@ -174,7 +175,7 @@ impl DynamicEnum {
///
/// This is functionally the same as [`DynamicEnum::from`] except it takes a reference.
pub fn from_ref<TEnum: Enum + ?Sized>(value: &TEnum) -> Self {
let type_info = value.get_represented_type_info();
let type_info = value.runtime_type_info();
let mut dyn_enum = match value.variant_type() {
VariantType::Unit => DynamicEnum::new_with_index(
value.variant_index(),
Expand Down Expand Up @@ -291,10 +292,20 @@ impl Enum for DynamicEnum {

impl PartialReflect for DynamicEnum {
#[inline]
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
fn comptime_type(&self) -> Type {
Type::of::<Self>()
}

#[inline]
fn runtime_type_info(&self) -> Option<&'static TypeInfo> {
self.represented_type
}

#[inline]
fn runtime_type(&self) -> Option<Type> {
self.represented_type.map(TypeInfo::ty).copied()
}

#[inline]
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect> {
self
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/src/enums/enum_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait Enum: PartialReflect {
///
/// [`TypeInfo`]: crate::TypeInfo
fn get_represented_enum_info(&self) -> Option<&'static EnumInfo> {
self.get_represented_type_info()?.as_enum().ok()
self.runtime_type_info()?.as_enum().ok()
}
}

Expand Down
14 changes: 13 additions & 1 deletion crates/bevy_reflect/src/func/dynamic_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use alloc::{borrow::Cow, boxed::Box};
use bevy_platform::sync::Arc;
use bevy_reflect::Type;
use bevy_reflect_derive::impl_type_path;
use core::fmt::{Debug, Formatter};

Expand Down Expand Up @@ -364,7 +365,18 @@ impl Function for DynamicFunction<'static> {
}

impl PartialReflect for DynamicFunction<'static> {
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
#[inline]
fn comptime_type(&self) -> Type {
Type::of::<Self>()
}

#[inline]
fn runtime_type_info(&self) -> Option<&'static TypeInfo> {
None
}

#[inline]
fn runtime_type(&self) -> Option<Type> {
None
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_reflect/src/func/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'a, 'b> ArgListSignature<'a, 'b> {
pub fn iter(&self) -> impl ExactSizeIterator<Item = &Type> {
self.0.iter().map(|arg| {
arg.value()
.get_represented_type_info()
.runtime_type_info()
.unwrap_or_else(|| {
panic!("no `TypeInfo` found for argument: {:?}", arg);
})
Expand All @@ -101,7 +101,7 @@ impl Hash for ArgListSignature<'_, '_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.iter().for_each(|arg| {
arg.value()
.get_represented_type_info()
.runtime_type_info()
.unwrap_or_else(|| {
panic!("no `TypeInfo` found for argument: {:?}", arg);
})
Expand Down Expand Up @@ -189,7 +189,7 @@ impl From<&ArgList<'_>> for ArgumentSignature {
args.iter()
.map(|arg| {
arg.value()
.get_represented_type_info()
.runtime_type_info()
.unwrap_or_else(|| {
panic!("no `TypeInfo` found for argument: {:?}", arg);
})
Expand Down
Loading
Loading