Skip to content

Commit 7f6a8f8

Browse files
committed
[AST] NFC: Convert InheritedEntry flags to bitfields
1 parent be35394 commit 7f6a8f8

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

include/swift/AST/Decl.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,21 +1599,27 @@ class ImportDecl final : public Decl,
15991599

16001600
/// An entry in the "inherited" list of a type or extension.
16011601
struct InheritedEntry : public TypeLoc {
1602+
private:
16021603
/// Whether there was an @unchecked attribute.
1603-
bool isUnchecked = false;
1604+
bool IsUnchecked : 1;
16041605

16051606
/// Whether there was an @retroactive attribute.
1606-
bool isRetroactive = false;
1607+
bool IsRetroactive : 1;
16071608

16081609
/// Whether there was an @preconcurrency attribute.
1609-
bool isPreconcurrency = false;
1610+
bool IsPreconcurrency : 1;
16101611

1612+
public:
16111613
InheritedEntry(const TypeLoc &typeLoc);
16121614

16131615
InheritedEntry(const TypeLoc &typeLoc, bool isUnchecked, bool isRetroactive,
16141616
bool isPreconcurrency)
1615-
: TypeLoc(typeLoc), isUnchecked(isUnchecked),
1616-
isRetroactive(isRetroactive), isPreconcurrency(isPreconcurrency) {}
1617+
: TypeLoc(typeLoc), IsUnchecked(isUnchecked),
1618+
IsRetroactive(isRetroactive), IsPreconcurrency(isPreconcurrency) {}
1619+
1620+
bool isUnchecked() const { return IsUnchecked; }
1621+
bool isRetroactive() const { return IsRetroactive; }
1622+
bool isPreconcurrency() const { return IsPreconcurrency; }
16171623
};
16181624

16191625
/// A wrapper for the collection of inherited types for either a `TypeDecl` or

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,12 +2727,12 @@ void PrintAST::printInherited(const Decl *decl) {
27272727
Printer << ": ";
27282728

27292729
interleave(TypesToPrint, [&](InheritedEntry inherited) {
2730-
if (inherited.isUnchecked)
2730+
if (inherited.isUnchecked())
27312731
Printer << "@unchecked ";
2732-
if (inherited.isRetroactive &&
2732+
if (inherited.isRetroactive() &&
27332733
!llvm::is_contained(Options.ExcludeAttrList, TAK_retroactive))
27342734
Printer << "@retroactive ";
2735-
if (inherited.isPreconcurrency)
2735+
if (inherited.isPreconcurrency())
27362736
Printer << "@preconcurrency ";
27372737

27382738
printTypeLoc(inherited);
@@ -3221,11 +3221,9 @@ static bool usesFeatureRetroactiveAttribute(Decl *decl) {
32213221
if (!ext)
32223222
return false;
32233223

3224-
ArrayRef<InheritedEntry> entries = ext->getInherited().getEntries();
3225-
return std::find_if(entries.begin(), entries.end(),
3226-
[](const InheritedEntry &entry) {
3227-
return entry.isRetroactive;
3228-
}) != entries.end();
3224+
return llvm::any_of(
3225+
ext->getInherited().getEntries(),
3226+
[](const InheritedEntry &entry) { return entry.isRetroactive(); });
32293227
}
32303228

32313229
static bool usesBuiltinType(Decl *decl, BuiltinTypeKind kind) {
@@ -3912,7 +3910,7 @@ static bool usesFeaturePreconcurrencyConformances(Decl *decl) {
39123910
auto usesPreconcurrencyConformance = [&](const InheritedTypes &inherited) {
39133911
return llvm::any_of(
39143912
inherited.getEntries(),
3915-
[](const InheritedEntry &entry) { return entry.isPreconcurrency; });
3913+
[](const InheritedEntry &entry) { return entry.isPreconcurrency(); });
39163914
};
39173915

39183916
if (auto *T = dyn_cast<TypeDecl>(decl))

lib/AST/Decl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,11 +1588,12 @@ NominalTypeDecl::takeConformanceLoaderSlow() {
15881588
}
15891589

15901590
InheritedEntry::InheritedEntry(const TypeLoc &typeLoc)
1591-
: TypeLoc(typeLoc), isUnchecked(false) {
1591+
: InheritedEntry(typeLoc, /*isUnchecked=*/false, /*isRetroactive=*/false,
1592+
/*isPreconcurrency=*/false) {
15921593
if (auto typeRepr = typeLoc.getTypeRepr()) {
1593-
isUnchecked = typeRepr->findAttrLoc(TAK_unchecked).isValid();
1594-
isRetroactive = typeRepr->findAttrLoc(TAK_retroactive).isValid();
1595-
isPreconcurrency = typeRepr->findAttrLoc(TAK_preconcurrency).isValid();
1594+
IsUnchecked = typeRepr->findAttrLoc(TAK_unchecked).isValid();
1595+
IsRetroactive = typeRepr->findAttrLoc(TAK_retroactive).isValid();
1596+
IsPreconcurrency = typeRepr->findAttrLoc(TAK_preconcurrency).isValid();
15961597
}
15971598
}
15981599

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class InheritedProtocolCollector {
507507
else
508508
ExtraProtocols.push_back(ProtocolAndAvailability(
509509
protoDecl, getAvailabilityAttrs(D, availableAttrs),
510-
inherited.isUnchecked, getOriginallyDefinedInAttrList(D)));
510+
inherited.isUnchecked(), getOriginallyDefinedInAttrList(D)));
511511
}
512512
// FIXME: This ignores layout constraints, but currently we don't support
513513
// any of those besides 'AnyObject'.

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ static void diagnoseRetroactiveConformances(
16731673
// However, if this is the protocol in the inherited type entry,
16741674
// check to make sure it's not erroneously marked @retroactive when it's
16751675
// not actually retroactive.
1676-
if (decl == proto && entry.isRetroactive) {
1676+
if (decl == proto && entry.isRetroactive()) {
16771677
auto loc = entry.getTypeRepr()->findAttrLoc(TAK_retroactive);
16781678
bool typeIsSameModule =
16791679
extTypeModule->isSameModuleLookingThroughOverlays(module);
@@ -1688,7 +1688,7 @@ static void diagnoseRetroactiveConformances(
16881688
}
16891689

16901690
// If it's marked @retroactive, no need to warn.
1691-
if (entry.isRetroactive) {
1691+
if (entry.isRetroactive()) {
16921692
return TypeWalker::Action::Continue;
16931693
}
16941694

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,9 +3819,9 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
38193819
TypeID typeRef = S.addTypeRef(inherited.getType());
38203820

38213821
// Encode "unchecked" in the low bit.
3822-
typeRef = (typeRef << 1) | (inherited.isUnchecked ? 0x01 : 0x00);
3822+
typeRef = (typeRef << 1) | (inherited.isUnchecked() ? 0x01 : 0x00);
38233823
// Encode "preconcurrency" in the low bit.
3824-
typeRef = (typeRef << 1) | (inherited.isPreconcurrency ? 0x01 : 0x00);
3824+
typeRef = (typeRef << 1) | (inherited.isPreconcurrency() ? 0x01 : 0x00);
38253825

38263826
result.push_back(typeRef);
38273827
}

0 commit comments

Comments
 (0)