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

TaffyTree::set_children: Remove from previous parent #749

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

SpecificProtagonist
Copy link
Contributor

@SpecificProtagonist SpecificProtagonist commented Dec 4, 2024

Objective

TaffyTree::set_children did not remove the children from their previous parent, resulting in an inconsistent hierarchy. Fix this.

Context

Causes a crash in bevyengine/bevy#16639.

This bug was present in previous taffy releases too; backporting it should be simple.

@nicoburns
Copy link
Collaborator

Hmm... I'm sympathetic to the idea that this ought to work like this. But this is a breaking change (of the kind where people might actually have been relying on the current behaviour) so I don't think we can release it as a 0.6 version. And the current behaviour isn't technically wrong, just unexpected.

Summoning the Unofficial Taffy Committee @alice-i-cecile @TimJentzsch @Weibye thoughts?

  • Do we think that "move semantics" (fix up tree to remove from previous parent) are the correct default?
  • Do we think there is any place for "raw" functions that don't attempt any smart behaviour?

@SpecificProtagonist
Copy link
Contributor Author

SpecificProtagonist commented Dec 4, 2024

And the current behaviour isn't technically wrong, just unexpected.

Hmm, I assumed it was unintentional because the type is called TaffyTree, and a node's parent is stored in a Option<NodeId>, not a Vec<NodeId>. As is, the current behavior means that set_children can result in nodes that are not their child's parent. TaffyTree::remove (and maybe other methods?) assumes that isn't the case and panics.

@TimJentzsch
Copy link
Collaborator

Hmm... I'm sympathetic to the idea that this ought to work like this. But this is a breaking change (of the kind where people might actually have been relying on the current behaviour) so I don't think we can release it as a 0.6 version. And the current behaviour isn't technically wrong, just unexpected.

Summoning the Unofficial Taffy Committee @alice-i-cecile @TimJentzsch @Weibye thoughts?

  • Do we think that "move semantics" (fix up tree to remove from previous parent) are the correct default?
  • Do we think there is any place for "raw" functions that don't attempt any smart behaviour?

First thoughts:

  • I'm always a big fan of having the default behavior being as "safe" as possible. While I don't think we explicitly document it, having an invariant that the node structure is a tree and keeping this consistent makes sense to me. Then the "move" behavior would be a sensible way to uphold that invariant.
  • For a low-level library like Taffy, offering "raw" functions that don't uphold internal invariants might make sense. However, I think we should only add them once someone asks us for it and then add a pre or postfix to the name to encourage using the "safe" API instead. E.g. "set_children_unchecked"

@alice-i-cecile
Copy link
Collaborator

Fully agree with @TimJentzsch's analysis here. I like the move semantics. I'm fine with carefully documented raw methods, but only when we actually have users asking for them.

@alice-i-cecile alice-i-cecile added the bug Something isn't working label Dec 11, 2024
@nicoburns
Copy link
Collaborator

Ok, sounds like there's consensus on this change :) Out of an abundance of caution (and a lack of consequences to bumping version numbers) I think I will consider this a breaking change and make the next release 0.7.0.

@nicoburns nicoburns enabled auto-merge (squash) December 12, 2024 02:48
@nicoburns nicoburns merged commit f37efc5 into DioxusLabs:main Dec 12, 2024
20 checks passed
@nicoburns nicoburns added the breaking-change A change that breaks our public interface label Dec 12, 2024
@nicoburns
Copy link
Collaborator

@SpecificProtagonist Released in Taffy 0.7. Bevy upgrade PR here: bevyengine/bevy#16780

github-merge-queue bot pushed a commit to bevyengine/bevy that referenced this pull request Dec 12, 2024
# Objective

- Includes DioxusLabs/taffy#749
- Which should fix #16639

## Solution

- Bump taffy version from `0.6` to `0.7`

## Testing

- I have run a couple of examples, but no extensive testing.

Signed-off-by: Nico Burns <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A change that breaks our public interface bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants