Skip to content
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
27 changes: 27 additions & 0 deletions _release-content/migration-guides/define_label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: "`define_label!` no longer defines an `Interner`"
pull_requests: [24445]
---

The macro `define_label!()` no longer takes a parameter for the name of an `Interner`,
and that interner is no longer a public `static` item. Calls like

```rust
bevy::ecs::define_label!(
/// Documentation
ThingLabel,
THING_LABEL_INTERNER
);
```

must be changed to

```rust
bevy::ecs::define_label!(
/// Documentation
ThingLabel,
);
```

If you were calling `Interner::intern()` on the defined interner, then replace those calls
with calls to the `.intern()` method of the defined label trait.
1 change: 0 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ bevy_ecs::define_label!(
note = "consider annotating `{Self}` with `#[derive(AppLabel)]`"
)]
AppLabel,
APP_LABEL_INTERNER
);

pub use bevy_ecs::label::DynEq;
Expand Down
22 changes: 7 additions & 15 deletions crates/bevy_ecs/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ where
/// define_label!(
/// /// Documentation of label trait
/// MyNewLabelTrait,
/// MY_NEW_LABEL_TRAIT_INTERNER
/// );
///
/// /// A new label type implementing the new label trait.
Expand All @@ -97,7 +96,6 @@ where
/// define_label!(
/// /// Documentation of another label trait
/// MyNewExtendedLabelTrait,
/// MY_NEW_EXTENDED_LABEL_TRAIT_INTERNER,
/// extra_methods: {
/// // Extra methods for the trait can be defined here
/// fn additional_method(&self) -> i32;
Expand Down Expand Up @@ -135,10 +133,7 @@ where
///
/// ```
/// # use bevy_ecs::define_label;
/// define_label!(
/// Team,
/// TEAM_INTERNER
/// );
/// define_label!(Team);
///
/// macro_rules! define_team {
/// ($name:ident) => {
Expand All @@ -164,23 +159,20 @@ where
macro_rules! define_label {
(
$(#[$label_attr:meta])*
$label_trait_name:ident,
$interner_name:ident
$label_trait_name:ident $(,)?
) => {
$crate::define_label!(
$(#[$label_attr])*
$label_trait_name,
$interner_name,
extra_methods: {},
extra_methods_impl: {}
);
};
(
$(#[$label_attr:meta])*
$label_trait_name:ident,
$interner_name:ident,
extra_methods: { $($trait_extra_methods:tt)* },
extra_methods_impl: { $($interned_extra_methods_impl:tt)* }
extra_methods_impl: { $($interned_extra_methods_impl:tt)* } $(,)?
) => {

$(#[$label_attr])*
Expand All @@ -196,7 +188,10 @@ macro_rules! define_label {
/// Returns an [`Interned`] value corresponding to `self`.
fn intern(&self) -> $crate::intern::Interned<dyn $label_trait_name>
where Self: ::core::marker::Sized {
$interner_name.intern(self)
static INTERNER: $crate::intern::Interner<dyn $label_trait_name> =
$crate::intern::Interner::new();

INTERNER.intern(self)
}
}

Expand Down Expand Up @@ -252,8 +247,5 @@ macro_rules! define_label {
ptr::from_ref::<Self>(self).cast::<()>().hash(state);
}
}

static $interner_name: $crate::intern::Interner<dyn $label_trait_name> =
$crate::intern::Interner::new();
};
}
2 changes: 0 additions & 2 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ define_label!(
note = "consider annotating `{Self}` with `#[derive(ScheduleLabel)]`"
)]
ScheduleLabel,
SCHEDULE_LABEL_INTERNER
);

define_label!(
Expand Down Expand Up @@ -152,7 +151,6 @@ define_label!(
note = "consider annotating `{Self}` with `#[derive(SystemSet)]`"
)]
SystemSet,
SYSTEM_SET_INTERNER,
extra_methods: {
/// Returns `Some` if this system set is a [`SystemTypeSet`].
fn system_type(&self) -> Option<TypeId> {
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_material/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ define_label!(
)]
/// Labels used to uniquely identify types of material shaders
ShaderLabel,
SHADER_LABEL_INTERNER
);

/// A shorthand for `Interned<dyn RenderSubGraph>`.
Expand All @@ -22,7 +21,6 @@ define_label!(
)]
/// Labels used to uniquely identify types of material shaders
DrawFunctionLabel,
DRAW_FUNCTION_LABEL_INTERNER
);

pub type InternedDrawFunctionLabel = Interned<dyn DrawFunctionLabel>;
Expand Down
Loading