-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix PartialReflect::apply
for maps, remove get_at/_mut
from Map
trait
#19802
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
Conversation
@RobWalt, can I get your review here too? |
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
I'm broadly happy with this, but it needs a migration guide :) |
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.
Looks great! Also really nice docs 💯 It was a pleasant review :)
@@ -1583,7 +1583,6 @@ mod tests { | |||
foo.apply(&foo_patch); | |||
|
|||
let mut hash_map = <HashMap<_, _>>::default(); | |||
hash_map.insert(1, 1); |
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.
Nice catch! How did this not lead to a failed test before? o.O
I mean it kind of makes sense that this code
let mut map = DynamicMap::default();
map.insert(2usize, 3i8);
map.insert(3usize, 4i8);
foo_patch.insert("d", map);
replaces the old map completely and hence doesn't include the (1,1)
entry. The change here makes me wonder how it worked before though. The test makes it seem like previously the (1,1)
entry would have been preserved.
I probably need to look a bit further into the changes..
@@ -615,117 +554,17 @@ pub fn map_try_apply<M: Map>(a: &mut M, b: &dyn PartialReflect) -> Result<(), Ap | |||
a.insert_boxed(key.to_dynamic(), b_value.to_dynamic()); | |||
} | |||
} | |||
a.retain(&mut |key, _| map_value.get(key).is_some()); |
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.
Ahhh I guess that's where the removed entry (1,1)
comes from.
Yeah I also second @alice-i-cecile message. We should really highlight this in a migration guide as, if you're used to the previous behavior, it seems like a big trip wire since it's so implicit.
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.
Thanks for the review! I added the migration guide with all the behavior changes.
I would consider the non-removal of the extra entry a bug so hopefully no one is actually relying on that in the wild! 😅
Objective
get_at
method fromMap
trait (reflection) #14328DynamicMap::drain
was broken (indices weren't cleared, causing a panic when reading later)PartialReflect::apply
was broken for maps and sets, because they don't remove entries from theself
map that aren't in the applied map.HashMap<Entity, _>
. Becauseapply
is used to reapply the changes to the reflected map, the map ended up littered with a ton of outdated entries.Solution
Vec
inDynamicMap
and use theHashTable
directly, like it is inDynamicSet
.MapIter
byBox<dyn Iterator>
(like forDynamicSet
), andMap::get_at
andMap::get_at_mut
which are now unused.DynamicMap
types are unordered and adjust documentation accordingly.DynamicSet
(ordered -> unordered)Map::retain
andSet::retain
, and use them to remove excess entries inPartialReflect::apply
implementations.Testing
map::tests::apply
andset::tests::apply
to validate<DynamicMap as PartialReflect>::apply
and<DynamicSet as PartialReflect>::apply