Skip to content

Commit 18c4ca4

Browse files
committed
Fix CI issues
1 parent 87bd81b commit 18c4ca4

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

crates/bevy_ecs/src/bundle/info.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use alloc::{boxed::Box, vec, vec::Vec};
2-
use bevy_platform::collections::{HashMap, HashSet};
2+
use bevy_platform::{
3+
collections::{HashMap, HashSet},
4+
hash::FixedHasher,
5+
};
36
use bevy_ptr::OwningPtr;
47
use bevy_utils::TypeIdMap;
58
use core::{any::TypeId, ptr::NonNull};
@@ -89,7 +92,10 @@ impl BundleInfo {
8992
mut component_ids: Vec<ComponentId>,
9093
id: BundleId,
9194
) -> BundleInfo {
92-
let explicit_component_ids = component_ids.iter().copied().collect::<IndexSet<_>>();
95+
let explicit_component_ids = component_ids
96+
.iter()
97+
.copied()
98+
.collect::<IndexSet<_, FixedHasher>>();
9399

94100
// check for duplicates
95101
if explicit_component_ids.len() != component_ids.len() {
@@ -113,7 +119,7 @@ impl BundleInfo {
113119
panic!("Bundle {bundle_type_name} has duplicate components: {names:?}");
114120
}
115121

116-
let mut depth_first_components = IndexMap::new();
122+
let mut depth_first_components = IndexMap::<_, _, FixedHasher>::default();
117123
for &component_id in &component_ids {
118124
// SAFETY: caller has verified that all ids are valid
119125
let info = unsafe { components.get_info_unchecked(component_id) };
@@ -155,7 +161,7 @@ impl BundleInfo {
155161
self.id
156162
}
157163

158-
/// Returns the length of the explicit components part of the [contributed_components](Self::contributed_components) list.
164+
/// Returns the length of the explicit components part of the [`contributed_components`](Self::contributed_components) list.
159165
pub(super) fn explicit_components_len(&self) -> usize {
160166
self.contributed_components.len() - self.required_component_constructors.len()
161167
}

crates/bevy_ecs/src/component/info.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloc::{borrow::Cow, vec::Vec};
2-
use bevy_platform::sync::PoisonError;
2+
use bevy_platform::{hash::FixedHasher, sync::PoisonError};
33
use bevy_ptr::OwningPtr;
44
#[cfg(feature = "bevy_reflect")]
55
use bevy_reflect::Reflect;
@@ -34,7 +34,7 @@ pub struct ComponentInfo {
3434
/// The set of components that require this components.
3535
/// Invariant: this is stored in a depth-first order, that is components are stored after the components
3636
/// that they depend on.
37-
pub(super) required_by: IndexSet<ComponentId>,
37+
pub(super) required_by: IndexSet<ComponentId, FixedHasher>,
3838
}
3939

4040
impl ComponentInfo {
@@ -527,7 +527,10 @@ impl Components {
527527
}
528528

529529
#[inline]
530-
pub(crate) fn get_required_by(&self, id: ComponentId) -> Option<&IndexSet<ComponentId>> {
530+
pub(crate) fn get_required_by(
531+
&self,
532+
id: ComponentId,
533+
) -> Option<&IndexSet<ComponentId, FixedHasher>> {
531534
self.components
532535
.get(id.0)
533536
.and_then(|info| info.as_ref().map(|info| &info.required_by))
@@ -537,7 +540,7 @@ impl Components {
537540
pub(crate) fn get_required_by_mut(
538541
&mut self,
539542
id: ComponentId,
540-
) -> Option<&mut IndexSet<ComponentId>> {
543+
) -> Option<&mut IndexSet<ComponentId, FixedHasher>> {
541544
self.components
542545
.get_mut(id.0)
543546
.and_then(|info| info.as_mut().map(|info| &mut info.required_by))

crates/bevy_ecs/src/component/required.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloc::{format, vec::Vec};
2-
use bevy_platform::sync::Arc;
2+
use bevy_platform::{hash::FixedHasher, sync::Arc};
33
use bevy_ptr::OwningPtr;
44
use core::fmt::Debug;
55
use indexmap::{IndexMap, IndexSet};
@@ -119,7 +119,7 @@ pub struct RequiredComponents {
119119
///
120120
/// # Safety
121121
/// The [`RequiredComponent`] instance associated to each ID must be valid for its component.
122-
pub(crate) direct: IndexMap<ComponentId, RequiredComponent>,
122+
pub(crate) direct: IndexMap<ComponentId, RequiredComponent, FixedHasher>,
123123
/// All the components that are required (i.e. including inherited ones), in depth-first order. Most importantly,
124124
/// components in this list always appear after all the components that they require.
125125
///
@@ -128,7 +128,7 @@ pub struct RequiredComponents {
128128
///
129129
/// # Safety
130130
/// The [`RequiredComponent`] instance associated to each ID must be valid for its component.
131-
pub(crate) all: IndexMap<ComponentId, RequiredComponent>,
131+
pub(crate) all: IndexMap<ComponentId, RequiredComponent, FixedHasher>,
132132
}
133133

134134
impl Debug for RequiredComponents {
@@ -149,7 +149,7 @@ impl RequiredComponents {
149149
///
150150
/// # Safety
151151
///
152-
/// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`.
152+
/// - all other components in this [`RequiredComponents`] instance must have been registered in `components`.
153153
pub unsafe fn register<C: Component>(
154154
&mut self,
155155
components: &mut ComponentsRegistrator<'_>,
@@ -171,7 +171,7 @@ impl RequiredComponents {
171171
/// # Safety
172172
///
173173
/// - `component_id` must be a valid component in `components` for the type `C`;
174-
/// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`.
174+
/// - all other components in this [`RequiredComponents`] instance must have been registered in `components`.
175175
pub unsafe fn register_by_id<C: Component>(
176176
&mut self,
177177
component_id: ComponentId,
@@ -198,7 +198,7 @@ impl RequiredComponents {
198198
/// # Safety
199199
///
200200
/// - `component_id` must be a valid component in `components`;
201-
/// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`;
201+
/// - all other components in `self` must have been registered in `components`;
202202
/// - `constructor` must return a [`RequiredComponentConstructor`] that constructs a valid instance for the
203203
/// component with ID `component_id`.
204204
pub unsafe fn register_dynamic_with(
@@ -219,14 +219,17 @@ impl RequiredComponents {
219219
entry.insert(required_component.clone());
220220

221221
// Register inherited required components.
222+
// SAFETY:
223+
// - the caller guarantees all components that were in `self` have been registered in `components`;
224+
// - `component_id` has just been added, but is also guaranteed by the called to be valid in `components`.
222225
unsafe {
223226
Self::register_inherited_required_components_unchecked(
224227
&mut self.all,
225228
component_id,
226229
required_component,
227230
components,
228-
)
229-
};
231+
);
232+
}
230233

231234
true
232235
}
@@ -235,7 +238,7 @@ impl RequiredComponents {
235238
///
236239
/// # Safety
237240
///
238-
/// - all components in this [`RequiredComponents`] instance must have been registrated in `components`.
241+
/// - all components in `self` must have been registered in `components`.
239242
unsafe fn rebuild_inherited_required_components(&mut self, components: &Components) {
240243
// Clear `all`, we are re-initializing it.
241244
self.all.clear();
@@ -252,7 +255,7 @@ impl RequiredComponents {
252255
required_id,
253256
required_component.clone(),
254257
components,
255-
)
258+
);
256259
}
257260
}
258261
}
@@ -265,7 +268,7 @@ impl RequiredComponents {
265268
/// - `required_id` must have been registered in `components`;
266269
/// - `required_component` must hold a valid constructor for the component with id `required_id`.
267270
unsafe fn register_inherited_required_components_unchecked(
268-
all: &mut IndexMap<ComponentId, RequiredComponent>,
271+
all: &mut IndexMap<ComponentId, RequiredComponent, FixedHasher>,
269272
required_id: ComponentId,
270273
required_component: RequiredComponent,
271274
components: &Components,
@@ -281,7 +284,7 @@ impl RequiredComponents {
281284
for (&inherited_id, inherited_required) in &info.required_components().all {
282285
// This is an inherited required component: insert it only if not already present.
283286
// By the invariants of `RequiredComponents`, `info.required_components().all` holds the required
284-
// components in a depth-first order, and this makes us store teh components in `self.all` also
287+
// components in a depth-first order, and this makes us store the components in `self.all` also
285288
// in depth-first order, as long as we don't overwrite existing ones.
286289
//
287290
// SAFETY:
@@ -407,7 +410,7 @@ impl Components {
407410
let new_required_components = required_components.all[old_required_count..]
408411
.keys()
409412
.copied()
410-
.collect::<IndexSet<_>>();
413+
.collect::<IndexSet<_, FixedHasher>>();
411414

412415
// Get all the new requiree components, i.e. `requiree` and all the components that `requiree` is required by.
413416
// SAFETY: The caller ensures that the `requiree` is valid.
@@ -426,7 +429,7 @@ impl Components {
426429
for &indirect_requiree in &new_requiree_components {
427430
// Extract the required components to avoid conflicting borrows. Remember to put this back before continuing!
428431
// SAFETY: `indirect_requiree` comes from `self`, so it must be valid.
429-
let mut required_components = std::mem::take(unsafe {
432+
let mut required_components = core::mem::take(unsafe {
430433
self.get_required_components_mut(indirect_requiree)
431434
.debug_checked_unwrap()
432435
});
@@ -474,7 +477,7 @@ impl Components {
474477
) {
475478
// Extract the required components to avoid conflicting borrows. Remember to put this back before returning!
476479
// SAFETY: The caller ensures that the `requiree` is valid.
477-
let mut required_components = std::mem::take(unsafe {
480+
let mut required_components = core::mem::take(unsafe {
478481
self.get_required_components_mut(requiree)
479482
.debug_checked_unwrap()
480483
});
@@ -537,7 +540,7 @@ pub(super) fn enforce_no_required_components_recursion(
537540

538541
#[cfg(test)]
539542
mod tests {
540-
use std::string::{String, ToString};
543+
use alloc::string::{String, ToString};
541544

542545
use crate::{
543546
bundle::Bundle,
@@ -1251,14 +1254,14 @@ mod tests {
12511254
#[test]
12521255
fn regression_19333() {
12531256
#[derive(Component)]
1254-
struct X(bool);
1257+
struct X(usize);
12551258

12561259
#[derive(Default, Component)]
1257-
#[require(X(false))]
1260+
#[require(X(0))]
12581261
struct Base;
12591262

12601263
#[derive(Default, Component)]
1261-
#[require(X(true), Base)]
1264+
#[require(X(1), Base)]
12621265
struct A;
12631266

12641267
#[derive(Default, Component)]
@@ -1271,7 +1274,7 @@ mod tests {
12711274

12721275
let mut w = World::new();
12731276

1274-
assert_eq!(w.spawn(B).get::<X>().unwrap().0, true);
1275-
assert_eq!(w.spawn(C).get::<X>().unwrap().0, true);
1277+
assert_eq!(w.spawn(B).get::<X>().unwrap().0, 1);
1278+
assert_eq!(w.spawn(C).get::<X>().unwrap().0, 1);
12761279
}
12771280
}

0 commit comments

Comments
 (0)