-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
change not implemation to custom system struct #8105
Conversation
I accidentally removed some of the |
The reason for this is right here:
When using I will do a full review 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.
It's a bit unfortunate to have to add another manual System
impl, but I think it's absolutely worth it to make run conditions just work in more situations.
Essentially, this just means that cloned function systems will have their initialization undone. I think that's acceptable -- however the current implementation does not fully de-initialize the system. You'd need to make it reset the Also, it might be worth adding a Alternatively, we could retain the initialization when cloning, but require the system's state to be |
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.
Thank you for taking my suggestions. Generally I'm on board with this PR, but I'd like more opinions on how to handle the initialization issue.
I'd definitely prefer if this reset the system initialization completely. I don't care about performance here, and I think that not doing so is a correctness footgun. |
Thank you very much for your guidance!
I've changed the |
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 think this safety comment is clearer, but I won't block on it. Other changes look good.
Co-authored-by: Alice Cecile <[email protected]>
// De-initializes the cloned system. | ||
impl<Marker, F> Clone for FunctionSystem<Marker, F> | ||
where | ||
F: SystemParamFunction<Marker> + Clone, |
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.
This behavior, while probably correct, is very subtle. It needs to be documented somewhere visible -- perhaps on the System
trait? Also, maybe it should be documented on distributive_run_if
, since I think that's the only place we're cloning systems right now.
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.
Right now Clone
is implemented specifically for FunctionSystem
, and not necessarily for other System
implementers. I think it makes more sense to call it out on FunctionSystem
. I also added a note on distributive_run_if
.
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.
Right now Clone is implemented specifically for FunctionSystem, and not necessarily for other System implementers.
Right, but users will rarely if ever interact with the FunctionSystem
type directly. I think it's more likely to be seen if the System
trait mentions that systems defined using a fn
have this property.
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.
Why is this resolved?
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.
This was addressed below in 3a98270.
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.
That documented it on FunctionSystem
, but users have little reason to ever interact with that type or read its documentation. Function systems get automagically created through type magic, so many users are probably only vaguely aware of that type's existence because of compiler errors.
// De-initializes the cloned system. | ||
impl<Marker, F> Clone for FunctionSystem<Marker, F> | ||
where | ||
F: SystemParamFunction<Marker> + Clone, |
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.
Right now Clone is implemented specifically for FunctionSystem, and not necessarily for other System implementers.
Right, but users will rarely if ever interact with the FunctionSystem
type directly. I think it's more likely to be seen if the System
trait mentions that systems defined using a fn
have this property.
Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Objective
The function
common_conditions::not
can't be used with the system configurationdistributive_run_if
, because the returned closure is typed asimpl Condition<()>
. Fixes another part of #8058.Solution
Changes to
not
:NotSystem
struct which wraps aCondition
and inverts its output whenever it's run. ImplementsClone
.NotSystem<_, T>
type fromnot<_, T>
, so that the return type isClone
when the input system isClone
.Changes to
FunctionSystem
:Clone
implementation forFunctionSystem<Marker, F>
whereF
isClone
. Note: this implementation does not clone theparam_state
field, so the cloned system instance doesn't have the original's state. Let me know if this is a problem.#[derive(Clone)]
for theIsFunctionSystem
marker. The compiler didn't like it when I tried to remove this. Is it really necessary to implementClone
for the marker types?Changelog
NotSystem
system typecommon_conditions::not
to return a concrete typeFunctionSystem
to implementClone
forClone
functions