add dynamic query support from feather-hecs#196
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
| /// | ||
| /// # Panics | ||
| /// Panics if `T` is not the type of the components in this slice. | ||
| pub fn as_slice<T: 'static>(&self) -> &[T] { |
There was a problem hiding this comment.
This is unsound because &[T] may outlive the query (and indeed the entire World). ComponentSlice should have a lifetime parameter bounded by the lifetime of the query, which should be propagated to this return value.
| pub fn iter_component_slices<'a>( | ||
| &'a self, | ||
| component_type: TypeId, | ||
| ) -> impl Iterator<Item = ComponentSlice> + 'a { |
There was a problem hiding this comment.
This is unsound because no dynamic borrow-checking is performed, and the use of &self here and in World::query_dynamic allows for other outstanding (potentially mutable) borrows. Either something analogous to Fetch::borrow is needed to perform dynamic borrow-checking, or a lot of stuff should be switched to &mut self to statically prevent a dynamic query from coexisting with any other component borrow.
| component_layout: Layout, | ||
| } | ||
|
|
||
| impl ComponentSlice { |
There was a problem hiding this comment.
There should be a safe way to get mutable access to the write_types of the query.
|
Thanks for the feedback @Ralith! Will dig into it soon. |
|
Closing as abandoned. |
This brings over the dynamic query changes from a hard fork of hecs:
https://github.com/feather-rs/feather-hecs
This allows us to build and query components dynamically at runtime.