Skip to content
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 by Bors] - move system_param fetch struct into anonymous scope to avoid name collisions #4100

Closed
wants to merge 3 commits into from

Conversation

robtfm
Copy link
Contributor

@robtfm robtfm commented Mar 4, 2022

Objective

avoid naming collisions with user structs when deriving system_param.

Solution

rename the fetch struct created by #[derive(system_param)] from {}State to {}SysParamState.
place the fetch struct into an anonymous scope.

Migration Guide

For code that was using a system param's fetch struct, such as EventReader's EventReaderState, the fetch struct can now be identified via the SystemParam trait associated type Fetch, e.g. for EventReader<T> it can be identified as <EventReader<'static, 'static, T> as SystemParam>::Fetch

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 4, 2022
@DJMcNab
Copy link
Member

DJMcNab commented Mar 4, 2022

Is there a reason we don't use the const _: () = {struct State; } approach here? I believe that's now allowed on stable

I think this code might have been originally written before that technique was known?

@robtfm robtfm changed the title rename system_param fetch struct to avoid user struct name collisions move system_param fetch struct into anonymous scope to avoid name collisions Mar 4, 2022
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior and removed S-Needs-Triage This issue needs to be labelled labels Mar 4, 2022
@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 8, 2022
@alice-i-cecile
Copy link
Member

@robtfm this is a good change that I'd like to merge. Can you rebase?

@robtfm
Copy link
Contributor Author

robtfm commented Apr 27, 2022

just want to flag that this is a public api breaking change that will affect at least one 3rd party crate (bevy-console). i think that doesn't automatically make it "controversial", but i am not up to date on all the new process discussions.

@DJMcNab
Copy link
Member

DJMcNab commented Apr 27, 2022

I disagree that this is a public api breaking change - the implementation details of the SystemParam derive should not be public API.
What does bevy-console need that this PR breaks?

@robtfm
Copy link
Contributor Author

robtfm commented Apr 27, 2022

it uses the fetch struct for manual event reader/writers: https://github.com/RichoDemus/bevy-console/blob/6bfa88d357a45df2ea117d445691fe1dd4dcb8b7/src/console.rs#L301.
it isn't hard to fix, after this pr it can still use <EventReader as SystemParam>::Fetch which is cleaner anyway.

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 27, 2022
@alice-i-cecile
Copy link
Member

@robftm can you add a very short migration guide to the PR description? Very niche, but it's nice to have some insight into why unusual code broke.

@robtfm
Copy link
Contributor Author

robtfm commented Apr 27, 2022

@robftm can you add a very short migration guide to the PR description? Very niche, but it's nice to have some insight into why unusual code broke.

added, largely mirroring the comment

@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors
Copy link
Contributor

bors bot commented May 2, 2022

This PR was included in a batch that was canceled, it will be automatically retried

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors
Copy link
Contributor

bors bot commented May 2, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors
Copy link
Contributor

bors bot commented May 2, 2022

This PR was included in a batch that was canceled, it will be automatically retried

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors
Copy link
Contributor

bors bot commented May 2, 2022

This PR was included in a batch that timed out, it will be automatically retried

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors
Copy link
Contributor

bors bot commented May 2, 2022

This PR was included in a batch that timed out, it will be automatically retried

bors bot pushed a commit that referenced this pull request May 2, 2022
…lisions (#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
@bors bors bot changed the title move system_param fetch struct into anonymous scope to avoid name collisions [Merged by Bors] - move system_param fetch struct into anonymous scope to avoid name collisions May 2, 2022
@bors bors bot closed this May 2, 2022
exjam pushed a commit to exjam/bevy that referenced this pull request May 22, 2022
…lisions (bevyengine#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…lisions (bevyengine#4100)

# Objective

avoid naming collisions with user structs when deriving ``system_param``.

## Solution

~rename the fetch struct created by ``#[derive(system_param)]`` from ``{}State`` to ``{}SysParamState``.~
place the fetch struct into an anonymous scope.

## Migration Guide

For code that was using a system param's fetch struct, such as ``EventReader``'s ``EventReaderState``, the fetch struct can now be identified via the SystemParam trait associated type ``Fetch``, e.g. for ``EventReader<T>`` it can be identified as ``<EventReader<'static, 'static, T> as SystemParam>::Fetch``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants