Skip to content

Conversation

@zygoloid
Copy link
Contributor

Avoid using a large switch that needs to be manually extended when adding a new kind of instruction. Instead, the expression category for an instruction is now specified when defining the InstKind.

In passing, add a distinct expression category value for patterns. This isn't used for much except some error checking at the moment, but it keeps the number of instructions that we need to manually classify as NotExpr despite having a type very low.

Avoid using a large switch that needs to be manually extended when
adding a new kind of instruction. Instead, the expression category for
an instruction is now specified when defining the `InstKind`.
@zygoloid zygoloid requested a review from dwblaikie November 14, 2025 01:39
@zygoloid zygoloid requested a review from a team as a code owner November 14, 2025 01:39
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.

This is very nice, thanks. I have one suggestion below.

// The kind of category for this instruction. This includes all values in
// `ExprCategory`, for the case where the category of the instruction only
// depedns on its kind, plus some additional kinds.
enum Kind : int8_t {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding [[clang::enum_extensibility(open)]] to help explain this enum holds other values too?

Alternatively, consider just using a uint8_t as the storage for the kind_, then casting to either ExprCategory or Kind. It felt a little weird to conceptually say Kind contains all the values of ExprCategory but then the return type of AsInstDependentKind is also Kind when we want to exclude ExprCategory values.

If that sounded good, maybe also consider moving Kind to be DependentExprCategory as an enum outside of this class, a peer of ExprCategory? I found it a bit unclear to see some instructions set ExprCategory::X and others InstExprCategory::Y, as the Inst prefix isn't really differentiating things.

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