Skip to content

Make ComponentDescriptor const #3365

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

Open
alice-i-cecile opened this issue Dec 17, 2021 · 3 comments
Open

Make ComponentDescriptor const #3365

alice-i-cecile opened this issue Dec 17, 2021 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Performance A change motivated by improving speed, memory usage or compile times D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Blocked This cannot move forward until something else changes

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Dec 17, 2021

What problem does this solve or what need does it fill?

The ComponentDescriptor is always the same for each component type.

What solution would you like?

Create an associated constant on the Component and Resource trait, which stores the existing information.

Constify all of the methods on ComponentDescriptor, then use those to initialize this information at compile-time.

We can also do this for NonSend resources by creating a simple trait for them.

What alternative(s) have you considered?

Enable the feature flags and do it now!

Additional context

This is blocked by several (!) unstable rustc features.

  1. trait bounds other than Sized on const fn parameters are unstable
  2. std::any::type_name is not yet stable as a const fn
  3. TypeId::of is not yet stable as a const fn
  4. function pointer casts are not allowed in constant functions

rust-lang/rust#57563 is the relevant tracking issue

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times C-Code-Quality A section of code that is hard to understand or change S-Blocked This cannot move forward until something else changes labels Dec 17, 2021
@ItsDoot
Copy link
Contributor

ItsDoot commented Nov 28, 2023

Additional context

This is blocked by several (!) unstable rustc features.

  1. trait bounds other than Sized on const fn parameters are unstable

  2. std::any::type_name is not yet stable as a const fn

  3. TypeId::of is not yet stable as a const fn

  4. function pointer casts are not allowed in constant functions

As of writing, 2. and 3. have been const-ified. 1. is allowed for declaration, but not for usage in the function (until const traits). Unsure of 4..

@alice-i-cecile alice-i-cecile added S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Blocked This cannot move forward until something else changes labels Nov 28, 2023
@james7132
Copy link
Member

const std::any::type_name is still unstable and so is const TypeId::of. Marking this as blocked again.

@james7132 james7132 added S-Blocked This cannot move forward until something else changes and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Mar 10, 2024
@BenjaminBrienen
Copy link
Contributor

Still blocked on rust-lang/rust#77125

@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Performance A change motivated by improving speed, memory usage or compile times D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

No branches or pull requests

4 participants