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

Leave World in a consistent state after query borrowck panics #209

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

Conversation

Ralith
Copy link
Owner

@Ralith Ralith commented Nov 26, 2021

Previously, some archetypes might be left permanently borrowed, making the World unusable.

@Ralith Ralith marked this pull request as draft November 26, 2021 23:22
Previously, some archetypes might be left permanently borrowed, making
the World unusable.
@Ralith
Copy link
Owner Author

Ralith commented Nov 26, 2021

TODO: The current draft unwinds borrows of archetypes which the query has already fully borrowed from. We also need a way to unwind the incomplete borrow of the archetype on which borrow checking failed. That'll probably have to be handled in every aggregating Fetch::borrow implementation.

@adamreichold
Copy link
Collaborator

We also need a way to unwind the incomplete borrow of the archetype on which borrow checking failed

I think the cleanest way of doing this would be drop guards like the Ref(Mut) types exposed by RefCell. But this would also imply having a dynamic allocation around to store those in which is probably alright for PreparedQuery but may be too expensive for ad-hoc Query.

@adamreichold
Copy link
Collaborator

@Ralith I think there is another option for using Drop guards but without the requirement for dynamic allocation: Using global instead of per-archetype borrow flags, c.f. adamreichold/rs-ecs#28.

This does reduce borrow checking overhead for queries, but it does also change semantics, e.g.

let foo_bar = world.get_mut::<Foo>(bar);
let foo_qux = world.get_mut::<Foo>(qux);

would work now if it is guaranteed that bar and qux are in distinct archetypes. for example by being distinct kinds of entities which can never have fully overlapping components. On the other hand, archetypes could be viewed as an implementation detail so that user code should not rely on constructs like the above and use e.g. View::get_mut_n.

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.

2 participants