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

const checks #49

Open
4 of 5 tasks
Anders429 opened this issue Feb 12, 2022 · 3 comments
Open
4 of 5 tasks

const checks #49

Anders429 opened this issue Feb 12, 2022 · 3 comments
Labels
C - Enhancement Category: New feature or request. C - Performance Category: Related to performance. P - Low Priority: Not particularly urgent. S - Blocked on Rust Feature Status: Cannot continue without a Rust feature being stabilized. S - Needs Investigation Status: Further investigation is needed.

Comments

@Anders429
Copy link
Owner

Anders429 commented Feb 12, 2022

There are some checks that can be evaluated at compile time, rather than runtime. These are:

  • entity insertion: ensure components are all members of the registry.
  • entry add: ensure component is member of registry.
  • entry remove: ensure component is member of registry.
  • query: ensure components are not borrowed mutably while being borrowed elsewhere within a view.
  • registry: ensure there are no duplicate components.

These are all programmer errors, and should be made known as soon as possible.

These checks can be moved to compile-time using const fns. For example, a check could be run as follows: const _: () = some_check(). However, all of these cases will currently require unstable nightly features. Therefore, I think it best to introduce a unstable_const_checks feature that requires nightly, allowing users to opt-in to these checks instead of the run-time checks.

Related issues: #40 and #27.

@Anders429 Anders429 added the C - Enhancement Category: New feature or request. label Feb 12, 2022
@Anders429
Copy link
Owner Author

As mentioned in #7, a check could also be added to verify that no duplicate Components occur in a Registry.

@Anders429
Copy link
Owner Author

Basically every single one of these is handled by the canonical branch, which is an implementation of what is discussed in #98. The only snag seems to be ensuring that components in a registry are unique. It seems that can't be done without some kind of negative trait bounds, which is currently not possibly in stable Rust. Although I hesitate to say "impossible" about these kinds of things, because nearly everything here I thought was impossible on stable Rust, but it almost all has turned out to be very possible.

@Anders429 Anders429 added S - Needs Investigation Status: Further investigation is needed. C - Performance Category: Related to performance. P - Low Priority: Not particularly urgent. S - Blocked on Rust Feature Status: Cannot continue without a Rust feature being stabilized. labels Sep 15, 2022
@Anders429
Copy link
Owner Author

Checking for uniqueness of Registry components does seem to be possible with some nightly features right now. See WaffleLapkin/minihlist#15 (specifically, the files that are removed by this PR lol) for a way to do this with auto traits and negative impls on heterogeneous lists.

As far as when this would actually be doable on stable, it seems pretty far off. There is a negative impls initiative, but it hasn't seen any real action since last year. The tracking issue does see more action, but stabilization of this one could be a ways out. For auto traits, that seems even more far off: rust-lang/rust#13231. There haven't been updates there since 2020, and I expect we might not get any more updates for a while after.

So, if those features are ever stabilized, I'll at least know exactly how to implement it for Registrys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - Enhancement Category: New feature or request. C - Performance Category: Related to performance. P - Low Priority: Not particularly urgent. S - Blocked on Rust Feature Status: Cannot continue without a Rust feature being stabilized. S - Needs Investigation Status: Further investigation is needed.
Projects
None yet
Development

No branches or pull requests

1 participant