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

Try harder to disambiguate enum variant identifiers #762

Merged
merged 4 commits into from
Feb 3, 2025
Merged

Conversation

ahl
Copy link
Collaborator

@ahl ahl commented Feb 1, 2025

Previously, conversion from the variant name derived from the schema and the Rust identifier was done for each variant as it was constructed. This change defers that conversion to when we construct the enum (i.e. when we have all variants in hand). This then allows us to check that each variant has a unique name, and try an alternative conversion. This also lets us fail rather than generating code that does not compile.

There's much more we could do to improve name generation, but this is a decent step forward both in terms of organization and resolving an immediate use case.

Copy link

@zeeshanlakhani zeeshanlakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test this (patching it into Omicron w/ typify/progenitor) and it does solve the current issue in relation to dendrite integration: https://github.com/oxidecomputer/omicron/actions/runs/13082114024/job/36507633179?pr=6918#step:11:644.


// If variants still aren't unique, we fail: we'd rather not emit code
// that can't compile
if !variants_unique(&variants) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

@ahl ahl merged commit 54e7e3c into main Feb 3, 2025
4 checks passed
@ahl ahl deleted the variant-collisions branch February 3, 2025 21:51
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