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

Fix required components documentation ambiguity #16539

Closed
wants to merge 1 commit into from

Conversation

IllyStable
Copy link

Objective

Solution

  • Changed depth first to breadth first (forgive me if I'm wrong, this is my first PR here and I'm fairly new to the Bevy codebase)

Testing

  • I don't believe testing was necessary - one word change

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@IllyStable
Copy link
Author

Sorry about the one word change, didn't really know how to rephrase it to represent how required components actually propogate

@IQuick143 IQuick143 added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 28, 2024
@alice-i-cecile
Copy link
Member

I don't think that this is quite the right phrasing; it's quite subtle. I'll try and take a crack at this and make a suggestion here, then you tell me if it makes sense to you? :)

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Nov 28, 2024
@alice-i-cecile alice-i-cecile added S-Needs-Help The author needs help finishing this PR. and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 28, 2024
@alice-i-cecile alice-i-cecile changed the title Fix require documentation ambiguity Fix required components documentation ambiguity Nov 28, 2024
@@ -228,7 +228,7 @@ use derive_more::derive::{Display, Error};
///
/// In general, this shouldn't happen often, but when it does the algorithm is simple and predictable:
/// 1. Use all of the constructors (including default constructors) directly defined in the spawned component's require list
/// 2. In the order the requires are defined in `#[require()]`, recursively visit the require list of each of the components in the list (this is a Depth First Search). When a constructor is found, it will only be used if one has not already been found.
/// 2. In the order the requires are defined in `#[require()]`, recursively visit the require list of each of the components in the list (this is a Breadth First Search). When a constructor is found, it will only be used if one has not already been found.
Copy link
Member

@alice-i-cecile alice-i-cecile Nov 28, 2024

Choose a reason for hiding this comment

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

Suggested change
/// 2. In the order the requires are defined in `#[require()]`, recursively visit the require list of each of the components in the list (this is a Breadth First Search). When a constructor is found, it will only be used if one has not already been found.
/// 2. In the order the requires are defined in `#[require()]`, recursively visit the require list of each of the components in the list. When a constructor is found, it will only be used if one has not already been found.
///
/// This is a Depth First Search, but constructors of a direct requires are evaluated before recursing.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds a bit off. Maybe:

/// The algorithm for choosing the constructor from the tree:
/// 1. A constructor from a direct #[requires()], if one exists, is selected with priority.
/// 2. Otherwise, perform a Depth First Search on the tree of requirements and select the first one found.

Copy link
Contributor

@benfrankel benfrankel Nov 28, 2024

Choose a reason for hiding this comment

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

I think the main issue with the current wording is that step 1 refers to the "spawned component", which seems to suggest that the step only applies to the component you directly spawn (aka the root of the tree), when it actually applies to every component visited during the DFS. I'd reword it to something roughly like this:

  1. Starting with the spawned component, recusively visit the require list of each of the components in the list, in the order the requires are defined in #[require()] (this is a Depth First Search).
  2. Whenever a component is visited, use all of the constructors (including default constructors) directly defined in its require list, except for the components whose constructors have already been found.

@BenjaminBrienen's wording is good.

Copy link
Author

Choose a reason for hiding this comment

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

On my readthrough of it I thought "depth-first" was somewhat misleading, but maybe I'm just misunderstanding the term.

Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation is actually a depth-first search, it just collects the constructors whenever it visits a component.

@alice-i-cecile
Copy link
Member

I've copied the wording from #16494 (comment) directly for now. I think this is clearer and good enough to merge, but @IllyStable or @benfrankel may have a better suggestion.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Needs-Help The author needs help finishing this PR. labels Nov 28, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 28, 2024
Co-authored by: @BenjaminBrienen

# Objective

Fixes #16494. Closes #16539, which this replaces. Suggestions alone
weren't enough, so now we have a new PR!

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
mockersf pushed a commit that referenced this pull request Nov 29, 2024
Co-authored by: @BenjaminBrienen

# Objective

Fixes #16494. Closes #16539, which this replaces. Suggestions alone
weren't enough, so now we have a new PR!

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
mockersf pushed a commit that referenced this pull request Nov 29, 2024
Co-authored by: @BenjaminBrienen

# Objective

Fixes #16494. Closes #16539, which this replaces. Suggestions alone
weren't enough, so now we have a new PR!

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Dec 2, 2024
Co-authored by: @BenjaminBrienen

# Objective

Fixes bevyengine#16494. Closes bevyengine#16539, which this replaces. Suggestions alone
weren't enough, so now we have a new PR!

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading docs on duplicate required component constructors
5 participants