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

Avoid redundantly specifying Id::Kind. #4911

Merged

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Feb 6, 2025

When a node kind's Id::Kind is determined from its category, don't also require it to be listed in the switch over all node kinds. This was both redundant and also error prone -- and in practice for several node kinds, the Id::Kind computed in the two different ways was different.

Instead, have the switch over node kinds handle only special cases that can't be handled by their category, and enforce that each node kind has an Id::Kind specified in exactly one way via checks in the .cpp file.

This refines the previous change in #4280 -- we still get the improved errors for missing updates, but now also don't require redundant additions to the switch.

When a node kind's Id::Kind is determined from its category, don't also
require it to be listed in the switch over all node kinds. This was both
redundant and also error prone -- and in practice for several node
kinds, the Id::Kind computed in the two different ways was different.

Instead, have the switch over node kinds handle only special cases that
can't be handled by their category, and enforce that each node kind has
an Id::Kind specified in exactly one way via checks in the .cpp file.
@github-actions github-actions bot requested a review from danakj February 6, 2025 22:57
Copy link
Contributor

@danakj danakj left a comment

Choose a reason for hiding this comment

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

LGTM

NodeCategoryToIdKind(Parse::Name::Kind.category(), true); \
constexpr auto from_kind = \
NodeKindToIdKindSpecialCases(Parse::Name::Kind); \
static_assert(from_category || from_kind, \
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW !!from_category != !!to_category would check that only one exists in a single assertion, but then you don't have two descriptive errors, dunno if you'd prefer that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the extra code is worth it for the improved diagnostic.

@zygoloid zygoloid added this pull request to the merge queue Feb 7, 2025
Merged via the queue into carbon-language:trunk with commit 1917ea2 Feb 7, 2025
10 checks passed
@zygoloid zygoloid deleted the toolchain-simplify-node-stack-list branch February 7, 2025 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants