Skip to content

Commit 177267c

Browse files
committed
AST: Store the IsSPI bit of AvailableAttr inline in DecAttribute.
Reduces the layout requirements for `AvailableAttr` by one byte.
1 parent 110041b commit 177267c

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

include/swift/AST/Attr.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ class DeclAttribute : public AttributeBase {
147147
Value : 32
148148
);
149149

150+
SWIFT_INLINE_BITFIELD(AvailableAttr, DeclAttribute, 1,
151+
/// Whether this attribute was spelled `@_spi_available`.
152+
IsSPI : 1
153+
);
154+
150155
SWIFT_INLINE_BITFIELD(ClangImporterSynthesizedTypeAttr, DeclAttribute, 1,
151156
kind : 1
152157
);
@@ -690,7 +695,9 @@ class AvailableAttr : public DeclAttribute {
690695
INIT_VER_TUPLE(Introduced), IntroducedRange(IntroducedRange),
691696
INIT_VER_TUPLE(Deprecated), DeprecatedRange(DeprecatedRange),
692697
INIT_VER_TUPLE(Obsoleted), ObsoletedRange(ObsoletedRange),
693-
PlatformAgnostic(PlatformAgnostic), Platform(Platform), IsSPI(IsSPI) {}
698+
PlatformAgnostic(PlatformAgnostic), Platform(Platform) {
699+
Bits.AvailableAttr.IsSPI = IsSPI;
700+
}
694701

695702
#undef INIT_VER_TUPLE
696703

@@ -735,9 +742,6 @@ class AvailableAttr : public DeclAttribute {
735742
/// The platform of the availability.
736743
const PlatformKind Platform;
737744

738-
/// Whether this is available as SPI.
739-
const bool IsSPI;
740-
741745
/// Whether this is a language-version-specific entity.
742746
bool isLanguageVersionSpecific() const;
743747

@@ -753,6 +757,9 @@ class AvailableAttr : public DeclAttribute {
753757
/// Whether this is a noasync attribute.
754758
bool isNoAsync() const;
755759

760+
/// Whether this attribute was spelled `@_spi_available`.
761+
bool isSPI() const { return Bits.AvailableAttr.IsSPI; }
762+
756763
/// Returns the platform-agnostic availability.
757764
PlatformAgnosticAvailabilityKind getPlatformAgnosticAvailability() const {
758765
return PlatformAgnostic;

lib/AST/Attr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static bool isShortAvailable(const DeclAttribute *DA) {
662662
if (!AvailAttr)
663663
return false;
664664

665-
if (AvailAttr->IsSPI)
665+
if (AvailAttr->isSPI())
666666
return false;
667667

668668
if (!AvailAttr->Introduced.has_value())
@@ -1371,7 +1371,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13711371
auto Attr = cast<AvailableAttr>(this);
13721372
if (Options.SuppressNoAsyncAvailabilityAttr && Attr->isNoAsync())
13731373
return false;
1374-
if (Options.printPublicInterface() && Attr->IsSPI) {
1374+
if (Options.printPublicInterface() && Attr->isSPI()) {
13751375
assert(Attr->hasPlatform());
13761376
assert(Attr->Introduced.has_value());
13771377
Printer.printAttrName("@available");
@@ -1380,7 +1380,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13801380
Printer << ", unavailable)";
13811381
break;
13821382
}
1383-
if (Attr->IsSPI) {
1383+
if (Attr->isSPI()) {
13841384
std::string atSPI = (llvm::Twine("@") + SPI_AVAILABLE_ATTRNAME).str();
13851385
Printer.printAttrName(atSPI);
13861386
} else {
@@ -2294,7 +2294,7 @@ AvailableAttr *AvailableAttr::clone(ASTContext &C, bool implicit) const {
22942294
implicit ? SourceRange() : ObsoletedRange,
22952295
PlatformAgnostic,
22962296
implicit,
2297-
IsSPI);
2297+
isSPI());
22982298
}
22992299

23002300
std::optional<OriginallyDefinedInAttr::ActiveVersion>

lib/AST/Availability.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void mergeWithInferredAvailability(const AvailableAttr *Attr,
114114

115115
// The merge of two introduction versions is the maximum of the two versions.
116116
if (mergeIntoInferredVersion(Attr->Introduced, Inferred.Introduced, std::max)) {
117-
Inferred.IsSPI = Attr->IsSPI;
117+
Inferred.IsSPI = Attr->isSPI();
118118
}
119119

120120
// The merge of deprecated and obsoleted versions takes the minimum.
@@ -596,7 +596,7 @@ AvailabilityRange AvailabilityInference::availableRange(const Decl *D) {
596596

597597
bool AvailabilityInference::isAvailableAsSPI(const Decl *D) {
598598
if (auto attr = attrForAvailableRange(D))
599-
return attr->IsSPI;
599+
return attr->isSPI();
600600

601601
return false;
602602
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
21052105
return;
21062106

21072107
// FIXME: This seems like it could be diagnosed during parsing instead.
2108-
while (attr->IsSPI) {
2108+
while (attr->isSPI()) {
21092109
if (attr->hasPlatform() && attr->Introduced.has_value())
21102110
break;
21112111
diagnoseAndRemoveAttr(attr, diag::spi_available_malformed);
@@ -4673,7 +4673,7 @@ void AttributeChecker::checkAvailableAttrs(ArrayRef<AvailableAttr *> Attrs) {
46734673
if (!D->getDeclContext()->getInnermostDeclarationDeclContext()) {
46744674
// If all available are spi available, we should use @_spi instead.
46754675
if (std::all_of(Attrs.begin(), Attrs.end(), [](AvailableAttr *AV) {
4676-
return AV->IsSPI;
4676+
return AV->isSPI();
46774677
})) {
46784678
diagnose(D->getLoc(), diag::spi_preferred_over_spi_available);
46794679
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6604,7 +6604,7 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
66046604
available->Obsoleted.value_or(noVersion), SourceRange(),
66056605
PlatformAgnosticAvailabilityKind::Unavailable,
66066606
/*implicit=*/true,
6607-
available->IsSPI);
6607+
available->isSPI());
66086608
ext->getAttrs().add(attr);
66096609
anyPlatformSpecificAttrs = true;
66106610
}

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
30313031
theAttr->isUnconditionallyDeprecated(),
30323032
theAttr->isNoAsync(),
30333033
theAttr->isPackageDescriptionVersionSpecific(),
3034-
theAttr->IsSPI,
3034+
theAttr->isSPI(),
30353035
LIST_VER_TUPLE_PIECES(Introduced),
30363036
LIST_VER_TUPLE_PIECES(Deprecated),
30373037
LIST_VER_TUPLE_PIECES(Obsoleted),

0 commit comments

Comments
 (0)