Skip to content

add dynamic query support from feather-hecs#196

Closed
jazzay wants to merge 1 commit into
Ralith:masterfrom
jazzay:dynamic_queries
Closed

add dynamic query support from feather-hecs#196
jazzay wants to merge 1 commit into
Ralith:masterfrom
jazzay:dynamic_queries

Conversation

@jazzay

@jazzay jazzay commented Sep 27, 2021

Copy link
Copy Markdown

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
Copy Markdown

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.

@Ralith Ralith left a comment

Copy link
Copy Markdown
Owner

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.

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

@Ralith Ralith Sep 27, 2021

Copy link
Copy Markdown
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 &[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.

Comment thread src/dynamic_query.rs
pub fn iter_component_slices<'a>(
&'a self,
component_type: TypeId,
) -> impl Iterator<Item = ComponentSlice> + 'a {

Copy link
Copy Markdown
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.

Comment thread src/dynamic_query.rs
component_layout: Layout,
}

impl ComponentSlice {

Copy link
Copy Markdown
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

jazzay commented Sep 28, 2021

Copy link
Copy Markdown
Author

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

@Ralith

Ralith commented Jun 27, 2025

Copy link
Copy Markdown
Owner

Closing as abandoned.

@Ralith Ralith closed this Jun 27, 2025
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