Skip to content

Commit 0c78bf3

Browse files
mnmaitajames7132
andauthored
Moves intern and label modules into bevy_ecs (#12772)
# Objective - Attempts to solve two items from #11478. ## Solution - Moved `intern` module from `bevy_utils` into `bevy_ecs` crate and updated all relevant imports. - Moved `label` module from `bevy_utils` into `bevy_ecs` crate and updated all relevant imports. --- ## Migration Guide - Replace `bevy_utils::define_label` imports with `bevy_ecs::define_label` imports. - Replace `bevy_utils::label::DynEq` imports with `bevy_ecs::label::DynEq` imports. - Replace `bevy_utils::label::DynHash` imports with `bevy_ecs::label::DynHash` imports. - Replace `bevy_utils::intern::Interned` imports with `bevy_ecs::intern::Interned` imports. - Replace `bevy_utils::intern::Internable` imports with `bevy_ecs::intern::Internable` imports. - Replace `bevy_utils::intern::Interner` imports with `bevy_ecs::intern::Interner` imports. --------- Co-authored-by: James Liu <[email protected]>
1 parent 3fc0c68 commit 0c78bf3

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

crates/bevy_app/src/app.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@ use crate::{
33
};
44
pub use bevy_derive::AppLabel;
55
use bevy_ecs::{
6+
intern::Interned,
67
prelude::*,
78
schedule::{ScheduleBuildSettings, ScheduleLabel},
89
system::SystemId,
910
};
1011
#[cfg(feature = "trace")]
1112
use bevy_utils::tracing::info_span;
12-
use bevy_utils::{intern::Interned, tracing::debug, HashMap};
13+
use bevy_utils::{tracing::debug, HashMap};
1314
use std::fmt::Debug;
1415
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
1516
use thiserror::Error;
1617

17-
bevy_utils::define_label!(
18+
bevy_ecs::define_label!(
1819
/// A strongly-typed class of labels used to identify an [`App`].
1920
AppLabel,
2021
APP_LABEL_INTERNER
2122
);
2223

23-
pub use bevy_utils::label::DynEq;
24+
pub use bevy_ecs::label::DynEq;
2425

2526
/// A shorthand for `Interned<dyn AppLabel>`.
2627
pub type InternedAppLabel = Interned<dyn AppLabel>;

crates/bevy_utils/src/intern.rs renamed to crates/bevy_ecs/src/intern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
sync::{OnceLock, PoisonError, RwLock},
1212
};
1313

14-
use crate::HashSet;
14+
use bevy_utils::HashSet;
1515

1616
/// An interned value. Will stay valid until the end of the program and will not drop.
1717
///
@@ -26,7 +26,7 @@ use crate::HashSet;
2626
// NOTE: This type must NEVER implement Borrow since it does not obey that trait's invariants.
2727
///
2828
/// ```
29-
/// # use bevy_utils::intern::*;
29+
/// # use bevy_ecs::intern::*;
3030
/// #[derive(PartialEq, Eq, Hash, Debug)]
3131
/// struct Value(i32);
3232
/// impl Internable for Value {

crates/bevy_utils/src/label.rs renamed to crates/bevy_ecs/src/label.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ where
6363
/// # Example
6464
///
6565
/// ```
66-
/// # use bevy_utils::define_label;
66+
/// # use bevy_ecs::define_label;
6767
/// define_label!(
6868
/// /// Documentation of label trait
6969
/// MyNewLabelTrait,
@@ -125,7 +125,7 @@ macro_rules! define_label {
125125
/// Feeds this value into the given [`Hasher`].
126126
fn dyn_hash(&self, state: &mut dyn ::std::hash::Hasher);
127127

128-
/// Returns an [`Interned`](bevy_utils::intern::Interned) value corresponding to `self`.
128+
/// Returns an [`Interned`] value corresponding to `self`.
129129
fn intern(&self) -> $crate::intern::Interned<dyn $label_trait_name>
130130
where Self: Sized {
131131
$interner_name.intern(self)
@@ -175,7 +175,7 @@ macro_rules! define_label {
175175

176176
fn ref_eq(&self, other: &Self) -> bool {
177177
if self.as_dyn_eq().type_id() == other.as_dyn_eq().type_id() {
178-
(self as *const Self as *const ()) == (other as *const Self as *const ())
178+
(self as *const Self).cast::<()>() == (other as *const Self).cast::<()>()
179179
} else {
180180
false
181181
}
@@ -184,7 +184,7 @@ macro_rules! define_label {
184184
fn ref_hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
185185
use ::std::hash::Hash;
186186
self.as_dyn_eq().type_id().hash(state);
187-
(self as *const Self as *const ()).hash(state);
187+
(self as *const Self).cast::<()>().hash(state);
188188
}
189189
}
190190

crates/bevy_ecs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub mod component;
1818
pub mod entity;
1919
pub mod event;
2020
pub mod identifier;
21+
pub mod intern;
22+
pub mod label;
2123
pub mod query;
2224
#[cfg(feature = "bevy_reflect")]
2325
pub mod reflect;

crates/bevy_ecs/src/schedule/set.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ use std::fmt::Debug;
33
use std::hash::{Hash, Hasher};
44
use std::marker::PhantomData;
55

6+
pub use crate::label::DynEq;
67
pub use bevy_ecs_macros::{ScheduleLabel, SystemSet};
7-
use bevy_utils::define_label;
8-
use bevy_utils::intern::Interned;
9-
pub use bevy_utils::label::DynEq;
108

11-
use crate::system::{
12-
ExclusiveFunctionSystem, ExclusiveSystemParamFunction, FunctionSystem,
13-
IsExclusiveFunctionSystem, IsFunctionSystem, SystemParamFunction,
9+
use crate::{
10+
define_label,
11+
intern::Interned,
12+
system::{
13+
ExclusiveFunctionSystem, ExclusiveSystemParamFunction, FunctionSystem,
14+
IsExclusiveFunctionSystem, IsFunctionSystem, SystemParamFunction,
15+
},
1416
};
1517

1618
define_label!(
17-
/// A strongly-typed class of labels used to identify an [`Schedule`].
19+
/// A strongly-typed class of labels used to identify a [`Schedule`](crate::schedule::Schedule).
1820
ScheduleLabel,
1921
SCHEDULE_LABEL_INTERNER
2022
);

crates/bevy_render/src/render_graph/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::{
55
},
66
renderer::RenderContext,
77
};
8-
use bevy_ecs::{prelude::World, system::Resource};
9-
use bevy_utils::{define_label, intern::Interned, HashMap};
8+
use bevy_ecs::{define_label, intern::Interned, prelude::World, system::Resource};
9+
use bevy_utils::HashMap;
1010
use std::fmt::Debug;
1111

1212
use super::{EdgeExistence, InternedRenderLabel, IntoRenderNodeArray};

crates/bevy_render/src/render_graph/node.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ use crate::{
55
},
66
renderer::RenderContext,
77
};
8+
pub use bevy_ecs::label::DynEq;
89
use bevy_ecs::{
10+
define_label,
11+
intern::Interned,
912
query::{QueryItem, QueryState, ReadOnlyQueryData},
1013
world::{FromWorld, World},
1114
};
12-
pub use bevy_utils::label::DynEq;
13-
use bevy_utils::{all_tuples_with_size, define_label, intern::Interned};
15+
use bevy_utils::all_tuples_with_size;
1416
use downcast_rs::{impl_downcast, Downcast};
1517
use std::fmt::Debug;
1618
use thiserror::Error;

crates/bevy_utils/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ pub mod prelude {
1616
}
1717

1818
pub mod futures;
19-
pub mod label;
2019
mod short_names;
2120
pub use short_names::get_short_name;
2221
pub mod synccell;
2322
pub mod syncunsafecell;
2423

2524
mod cow_arc;
2625
mod default;
27-
pub mod intern;
2826
mod once;
2927
mod parallel_queue;
3028

0 commit comments

Comments
 (0)