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

[enhancement] variant_count!<> builtin #1714

Open
grebe opened this issue Nov 14, 2024 · 2 comments
Open

[enhancement] variant_count!<> builtin #1714

grebe opened this issue Nov 14, 2024 · 2 comments
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request

Comments

@grebe
Copy link
Collaborator

grebe commented Nov 14, 2024

What's hard to do? (limit 100 words)

Similar to u32::MAX, it would be nice to have a way to get the number of elements in an enum. Similar to rust's std::mem::variant_count.

Current best alternative workaround (limit 100 words)

Make a const yourself and hope you keep it up to date.

Your view of the "best case XLS enhancement" (limit 100 words)

A builtin std::variant_count!<> or a colon-ref (like u32::MAX), e.g. EnumType::NUM_VARIANTS.

@grebe grebe added the enhancement New feature or request label Nov 14, 2024
@mikex-oss
Copy link
Collaborator

Surprisingly, it seems Rust does not yet have a robust story for this. variant_count is still not stabilized and the latest comments in the issue seem to indicate going in a different direction with magic constants like MyEnum::enum#VARIANT_COUNT .

@cdleary cdleary added the dslx DSLX (domain specific language) implementation / front-end label Nov 14, 2024
@cdleary
Copy link
Collaborator

cdleary commented Nov 14, 2024

I think this also gets more urgent if we had iota-assigning enums -- right now you have to name all the values by hand so making COUNT with the underlying type is comparatively not so burdensome. I'm not sure if we have an issue for that? We do have #1306 for getting proper sum types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

3 participants