-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
SystemParamBuilder - Enable type inference of closure parameter when building dynamic systems #14820
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
alice-i-cecile
merged 2 commits into
bevyengine:main
from
chescock:SystemParamBuilder-type-inference
Aug 28, 2024
Merged
SystemParamBuilder - Enable type inference of closure parameter when building dynamic systems #14820
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So we're implementing
build_system
for a FnMut<Param1, Param2, ...>which calls
build_any_system
, which is implemented forSystemParamFunction
and
SystemParamFunction
is implemented for allFnMut<Param1, Param2...>
I get your overall logic to add type inference, but would there be a way to get rid of
SystemParamFunction
altogether and just use macros everywhere to deal directly withFnMut<Param1, Param2...>
?It seems weird to have this extra indirection.
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.
SystemParamFunction
is the existing trait that powersFunctionSystem
. So I can't get rid of that!I agree it's weird, but given that we need a
SystemParamFunction
to make a system, I think this is the simplest way to make parameter type inference work in the current rust compiler.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.
I feel like someone like @SkiFire13 would have a better opinion than mine
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.
I agree that getting rid of
SystemParamFunction
is likely not an option, as it power all the other system trait machinery. The duplicatedFnMut
bounds on these methods do feel a bit unfortunate given thatSystemParamFunction
'simpl
s already have them (and twice!). However I don't think you can avoid them, as closure type inference is very finicky and requires a directFnMut
bound on the function that the closure is passed to, which in this case isbuild_system
. So in the end:SystemParamFunction
is needed for the existing system machinery (e.g.App::add_systems
)FnMut
bounds here are needed because closure inference won't look at them if they are anywhere else