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

add dynamic query support from feather-hecs #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jazzay
Copy link

@jazzay jazzay commented Sep 27, 2021

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.

@googlebot
Copy link
Collaborator

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks, this looks like a good start on #69! There are, however, some soundness issues as-is, and I think we'll want to iterate on the API a bit.

///
/// # Panics
/// Panics if `T` is not the type of the components in this slice.
pub fn as_slice<T: 'static>(&self) -> &[T] {
Copy link
Owner

@Ralith Ralith Sep 27, 2021

Choose a reason for hiding this comment

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

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 {
Copy link
Owner

Choose a reason for hiding this comment

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

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 {
Copy link
Owner

Choose a reason for hiding this comment

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

There should be a safe way to get mutable access to the write_types of the query.

@jazzay
Copy link
Author

jazzay commented Sep 28, 2021

Thanks for the feedback @Ralith! Will dig into it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants