-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add change detection that swaps between &/&mut and Ref/Mut when disabled/enabled #7344
Conversation
Totally busted as I wanted to focus on the core concept here is a more concrete form than a comment. I did not fix all of the many pattern matches our unit tests do on Additionally I didn't do any of the minute work that #6659 did like ensuring that a Future work includes adding an explicit Also I removed Could in theory have been based off #6659 directly but my local environment happened to go haywire when I rebased/merged that PR so I started from scratch out of fear of something breaking. I can rejigger my history to point there if the credit needs to be more explicit. |
I really like the core concept! How would it work with runtime configured change detection? |
You would return |
I actually don't really like the solution that #6659 currently has with the associated type, especially with how it impacts it's use in generic functions and systems. I've been meaning to update it, but haven't had the time. Would it be possible to just replace |
Generic functions and systems could use |
Well that was a lot. I believe this now has what work needs to be done to fix up all of the existing breakages from |
bc36996
to
9ec6820
Compare
Assuming generic code uses Going to leave this open as a template for how Note of course that my changes were super rough so all of these might be solvable with some more finesse. |
- Fixes bevyengine#7732 - Based extensively off bevyengine#6659 - Completely broken as I didn't change any of the ~100 or so assumptions that &T == &T while it now is Ref<T>
… didn't work, reverting
2943174
to
2bb2ce7
Compare
The main issue here is that you cannot rely on |
I added support for using Ref/Mut as Query arguments which would work in generic contexts. Rather than saying There may be some details that need to be done to ensure that the change detection deletion works properly there but it would be doable. |
I'm really hesitant to make |
I think this is a non-starter unless / until Rust has nicer support for smart pointer types in general. rust-lang/rust#109939 is along those lines, so perhaps it will happen eventually. |
This PR was mostly "I wonder how that will work" with a bit of "still an ergonomic improvement for non-tracked types". Mostly I was curious how much code clutter it would form. Certainly this version is... Bad. I am curious if I missed anything but don't think it is worth investigating so left it at this. Certainly we can close this since there isn't an appetite. |
Objective
Query<&T>
returnRef<T>
#7322Solution
Changelog
ChangeDetectionless
when queried will return&T
and&mut T
instead of a wrapper type and similarly change detection in general will be disabled for the type.&T
in a similar fashion to&mut T
returningMut<T>
this type isRef<T>
Migration Guide
&T
will be returningRef<T>
unless change detection is disabled via the newchange_detection(false)
attribute on#[derive(Component)]
. While many uses will work the same thanks to theDeref<Target = &T
impl, pattern matching to get a value out will break. Either disable change detection if it is not required or avoid pattern matching and instead explicitly deref to get the underlying value.