Adopt a Fetch pattern for SystemParams #1074
Merged
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.
Resolves #1032
Unfortunately the SystemParam approach currently used on master suffers from a safety hole. You can annotate system parameters like
Res<'static, X>
and suddenly we have a static pointer to a non-static resource! Thats bad!To resolve this, I have adopted a "Fetch" pattern for SystemParams (the pattern used by WorldQueries).
This accomplishes two things:
There is one major downside to this approach. We can no longer use this syntax:
Instead we must go back to doing this:
Yeah yeah ... I'm not happy about it either. But safety comes first. I'm hoping we find a magic implementation with no compromises, but until then something needs to give. And it can't be safety!
I encourage anyone interested to play around with the "minimal" examples in the link above. Maybe you can discover an ideal implementation.