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] - Refactor ResMut/Mut/ReflectMut to remove duplicated code #2217

Closed

Conversation

NathanSWard
Copy link
Contributor

ResMut, Mut and ReflectMut all share very similar code for change detection.
This PR is a first pass at refactoring these implementation and removing a lot of the duplicated code.

Note, this introduces a new trait ChangeDetectable.

Please feel free to comment away and let me know what you think!

@NathanSWard NathanSWard added C-Code-Quality A section of code that is hard to understand or change C-Feature A new feature, making something new possible labels May 19, 2021
@NathanSWard NathanSWard force-pushed the nward/coalesce-resmut-mut-impls branch from ce7004e to ebd7849 Compare May 19, 2021 07:16
@NathanSWard
Copy link
Contributor Author

Note: I can already tell the I'll have to change the get get_mut names since they clash with other function names.

@NathanSWard
Copy link
Contributor Author

I would appreciate if anyone had ideas for better names for
underlying() underlying_mut() and underlying_mut_unchecked() 😅

@bjorn3
Copy link
Contributor

bjorn3 commented May 19, 2021

UnsafeCell uses get as name for getting access to the interior value just like you used. Another option would be inner.

@cart
Copy link
Member

cart commented May 19, 2021

I think get() is probably too common a name for this context. I would expect that to conflict with the pointer type's methods on a regular basis. Getting the underlying value using the underlying function should only really happen when the Deref lifetimes are overly strict. I think long uncommon names (like underlying()) are actually a feature here because they discourage regular use.

@NathanSWard
Copy link
Contributor Author

I think long uncommon names (like underlying()) are actually a feature here because they discourage regular use.

Yep, that's the same thinking I had for chosing underlying.
However, I would ideally like the name to pertain to the trait ChangeDetectable (e.g. incorporate, 'change' 'detect' or something like that in the name.)
But ultimately I'm ok with underlying as well.

@NathanSWard NathanSWard force-pushed the nward/coalesce-resmut-mut-impls branch from 4ef4338 to 0e7999b Compare May 19, 2021 22:10
@NathanSWard NathanSWard requested review from cart and bjorn3 May 20, 2021 00:23
@alice-i-cecile
Copy link
Member

This feels likely to conflict with @BoxyUwU's relation PR (#1627). Would you be willing to help resolve merge conflicts with that @NathanSWard? It is likely to make implementing change detection for relations nicer though, so I personally think we should try and merge this in :)

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some documentation nits, but once those are addressed this LGTM.

@alice-i-cecile alice-i-cecile 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 May 21, 2021
@NathanSWard
Copy link
Contributor Author

Sorry to ping you directly @cart but I would appreciate if you took a look at this :)
Specifically, I might have a use case for getting mutable access to a ResMut without triggering change detection, but I'd only want to build that functionality on top of this PR.

@cart
Copy link
Member

cart commented May 30, 2021

@BoxyUwU how disruptive is this to relations? It seems relatively scoped to me. @NathanSWard: we've been discussing putting ecs work in "slow mode" to make merging the massive relations pr easier / cut down on boxy constantly needing to merge other people's work. Would you be willing to do the merge on boxy's relations branch to help out?

Also, I'm now thinking DetectChanges is probably a more idiomatic name? Ex we call the drop trait Drop not Dropable. (sorry for the back and forth on this).

@BoxyUwU
Copy link
Member

BoxyUwU commented May 30, 2021

looks like it would be pretty simple to rebase relations on top of, shouldn't hurt to merge :)

@NathanSWard
Copy link
Contributor Author

Would you be willing to do the merge on boxy's relations branch to help out?

Yep of course :)

Also, I'm now thinking DetectChanges is probably a more idiomatic name? Ex we call the drop trait Drop not Dropable. (sorry for the back and forth on this).

Oh, I think I like that name more as well :)
And no worries for the back and forth haha :p

@cart
Copy link
Member

cart commented May 30, 2021

bors r+

bors bot pushed a commit that referenced this pull request May 30, 2021
`ResMut`, `Mut` and `ReflectMut` all share very similar code for change detection.
This PR is a first pass at refactoring these implementation and removing a lot of the duplicated code.

Note, this introduces a new trait `ChangeDetectable`.

Please feel free to comment away and let me know what you think!
@bors bors bot changed the title Refactor ResMut/Mut/ReflectMut to remove duplicated code [Merged by Bors] - Refactor ResMut/Mut/ReflectMut to remove duplicated code May 30, 2021
@bors bors bot closed this May 30, 2021
ostwilkens pushed a commit to ostwilkens/bevy that referenced this pull request Jul 27, 2021
…2217)

`ResMut`, `Mut` and `ReflectMut` all share very similar code for change detection.
This PR is a first pass at refactoring these implementation and removing a lot of the duplicated code.

Note, this introduces a new trait `ChangeDetectable`.

Please feel free to comment away and let me know what you think!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Code-Quality A section of code that is hard to understand or change C-Feature A new feature, making something new possible 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.

5 participants