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

changed marker struct to const generic parameter #18086

Conversation

mysteriouslyseeing
Copy link
Contributor

@mysteriouslyseeing mysteriouslyseeing commented Feb 28, 2025

Objective

Fixes #18085.

Solution

Implementation as described in issue:

  • Replaced Aligned and Unaligned structs with ALIGNED and UNALIGNED constants
  • Changed A: IsAligned = Aligned to const IS_ALIGNED: bool = ALIGNED in Ptr, PtrMut and OwningPtr

Testing

  • cargo check --workspace --all-targets passes
  • cargo test --workspace --all-targets passes

Migration Guide

  • Replace all uses of bevy_ptr::Aligned and bevy_ptr::Unaligned in the context of Ptr, PtrMut and OwningPtr with ALIGNED and UNALIGNED, respectively.
  • Replace generic type parameters using the now removed IsAligned trait with a const generic parameter of type bool.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide A-Pointers Relating to Bevy pointer abstractions D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 28, 2025
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Feb 28, 2025

I like that the two options are exhaustively enumerated, but I don't like the const ALIGNED = true stuff. Pointer<true> is particularly egregious, and that's the obvious way to use these types. I don't think this is a net improvement after seeing the ultimate effect, but thanks for poking at this.

Maybe with const generic enums and Pointer<Aligned::Yes> or something this would be better, but even that reads pretty poorly.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 28, 2025
@mysteriouslyseeing
Copy link
Contributor Author

Maybe with const generic enums and Pointer<Aligned::Yes> or something this would be better, but even that reads pretty poorly.

I think you would be able to do pub use Aligned::Yes; like how the standard library reexports Some and None. Then it would be Pointer<Yes> - so if you name things carefully (something like IsAligned::Aligned) you could keep the usage almost exactly the same as it is now.

@mysteriouslyseeing
Copy link
Contributor Author

I don't think this is a net improvement after seeing the ultimate effect, but thanks for poking at this.

Makes sense! Good to close it then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Pointers Relating to Bevy pointer abstractions C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace IsAligned marker struct with const generic in bevy_ptr
2 participants