Add an EnumMaskBase type (#6053)

This is a bit of an experiment to see if there's a reasonable way to
write a shared enum type, rather than writing per-case wrappers for
things like `HasTypeQualifiers` or the printing. I think it's a bit
borderline complexity right now, but I'm not sure I can reduce it much
further.

This changes from things like `Internal::EnumClassName##RawEnum` to
`Internal::EnumClassName##Data::RawEnum` so that the enum entries can
have back references to bit shifts without needing to know the
containing type name. Because I'm trying to reduce duplication between
mask and non-mask enums, I did this to non-mask enums too.

This was motivated by #6035 adding another enum mask (which will grow
more entries, and is intended to switch if this is accepted), but I'm
not using that PR as a base here because I didn't want the merge
dependency.
This commit is contained in:
Jon Ross-Perkins
2025-09-12 18:04:10 +00:00
committed by GitHub
parent 508a88e2a9
commit 6cc5d7ed2a
17 changed files with 368 additions and 229 deletions
+6 -6
View File
@@ -138,19 +138,19 @@ auto GetConstType(Context& context, SemIR::TypeInstId inner_type_id)
auto GetQualifiedType(Context& context, SemIR::TypeId type_id,
SemIR::TypeQualifiers quals) -> SemIR::TypeId {
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Const)) {
if (quals.HasAnyOf(SemIR::TypeQualifiers::Const)) {
type_id = GetConstType(context, context.types().GetInstId(type_id));
quals &= ~SemIR::TypeQualifiers::Const;
quals.Remove(SemIR::TypeQualifiers::Const);
}
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::MaybeUnformed)) {
if (quals.HasAnyOf(SemIR::TypeQualifiers::MaybeUnformed)) {
type_id = GetTypeImpl<SemIR::MaybeUnformedType>(
context, context.types().GetInstId(type_id));
quals &= ~SemIR::TypeQualifiers::MaybeUnformed;
quals.Remove(SemIR::TypeQualifiers::MaybeUnformed);
}
if (HasTypeQualifier(quals, SemIR::TypeQualifiers::Partial)) {
if (quals.HasAnyOf(SemIR::TypeQualifiers::Partial)) {
type_id = GetTypeImpl<SemIR::PartialType>(
context, context.types().GetInstId(type_id));
quals &= ~SemIR::TypeQualifiers::Partial;
quals.Remove(SemIR::TypeQualifiers::Partial);
}
CARBON_CHECK(quals == SemIR::TypeQualifiers::None);
return type_id;