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

Review the use of const and @constCast throughout the library #35

Open
00JCIV00 opened this issue Oct 23, 2023 · 1 comment
Open

Review the use of const and @constCast throughout the library #35

00JCIV00 opened this issue Oct 23, 2023 · 1 comment
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@00JCIV00
Copy link
Owner

The use of @constCast is generally discouraged, but it's used throughout the library in the Command, Option, and Value types. There two main reasons for this:

  1. A desire to use const as a sort of equivalent to val in Kotlin, wherein the data can be made immutable to external users but still be mutated internally.
  2. A lack of understanding of how const works. Namely, the fact that it applies to memory directly instead of the data or Type. Because of this, the compiler can make assumptions about const data and even choose to move it to the rodata section of a program.

While the library ostensibly works fine in its current state, this is an item that's worth reviewing for completeness down the line.

@00JCIV00 00JCIV00 added enhancement New feature or request question Further information is requested labels Oct 23, 2023
@00JCIV00 00JCIV00 added this to the Future milestone Oct 23, 2023
00JCIV00 added a commit that referenced this issue Nov 22, 2023
- Updated all (ostensibly) unmutated variables to constants.
- Updated relevan functions to accept constants. (This forces `@constCast()` in several areas which does not seem optimal. See #35)
@00JCIV00
Copy link
Owner Author

Upon initial inspection, the current usage of const is required to share the same Type between comptime and runtime. With the runtime instances being allocated, the usage of const and @constCast might be ok. That said, it should still be looked at further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant