-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
bevy_reflect: Split up the std
module
#18939
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
bevy_reflect: Split up the std
module
#18939
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The files that have only one item could be moved to the modules root, though
Possibly. However that risks growing in size too unless we remember to break things up once it gets too large. It also struggles with discoverability (i.e. it's slightly harder to find an impl based on the folder structure alone). I’m also just of the mindset that |
9e8590b
to
0f7ecf3
Compare
I like this, but I have one suggestion: split into #[cfg(feature ="std")]
mod std; Otherwise, totally agree. I hate large files like that, and git diffs generally do too. Even single-line files are nice IMO, as long as the structure of the modules makes sense (which it does, since it mirrors a particular existing structure). |
You know what, that's a really good idea. I'll try doing that! |
c16aa9c
to
c3ac18c
Compare
Alright, I split it up even further into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments, nothing blocking. LGTM!
@@ -0,0 +1,18 @@ | |||
#[cfg(any(unix, windows))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe move these gates up a level in the module tree:
#[cfg(any(unix, windows))]
mod ffi;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually we can't do this since the other gate is the inverse (i.e. cfg(not(any(unix, windows)))]
).
::core::sync::atomic::AtomicUsize, | ||
::core::sync::atomic::Ordering::SeqCst | ||
); | ||
#[cfg(target_has_atomic = "64")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future PR: It'd be nice to move these to the bevy_platform
implementation module, since we can remove these target_has_atomic
feature gates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh? How so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bevy_platform
has a sync::atomic
module which includes all those target_has_atomic
flags already, and for unsupported types, it uses portable-atomic
as the fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay gotcha. Yeah that might be better served as a followup. I'll try to remember to make an issue or PR once this one lands
@MrGVSV once merge conflicts are fixed I'll get this in so it doesn't accumulate more. |
c3ac18c
to
b7a1c79
Compare
Important
To maintainers: we should wait to merge this one in until after #18944 lands so that cherry-picking the latter for 0.16.1 is simpler.
Objective
The
std
module is where we implement the reflection traits for types that are exported fromstd
(includingcore
andalloc
). Over time, this file has grown increasingly large, making it difficult to navigate and a pain point for merge conflicts.The goal of this PR is to break up the module into smaller chunks.
Solution
The
std
module has been split into many submodules:alloc
bevy_platform
core
std
Each of these new modules is comprised of submodules that closely resemble the actual module. For example, the impls for
::alloc::vec::Vec
have been moved tobevy_reflect::impls::alloc::vec::Vec
.Some liberties were taken. For example,
Cow<'static, Path>
was kept inbevy_reflect::impls::std::path
rather thanbevy_reflect::impls::alloc::borrow
.You may ask: Isn't this a little overkill? Why does the one-line impl for
TypeId
need its own file?And yes, it is partly overkill. But the benefit with this approach is that where an
std
-related type should live is mostly unambiguous. If we wanted to reflect::core::net::Ipv4Addr
, it's very clear that it should be done inbevy_reflect::impls::core::net
.We can discuss better ways of breaking this up if people have other ideas or opinions, but I think this is a pretty straightforward way of doing it.
Note to Reviewers
The code is pretty much copy-paste from the mega module to the new submodules. It's probably best to focus efforts on reviewing the general module structure, as well as maybe which impls are included where.
You can review the code contained within each impl, but I promise you the only thing I touched were the paths in the macros so they could be more hygienic :)
Testing
You can just check that everything compiles still: