Skip to content

Commit c4e8c52

Browse files
committed
s/isUnavailableInCurrentSwift/isUnavailableInSwiftVersion/, pass version.
1 parent 7183f9c commit c4e8c52

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

include/swift/AST/Attr.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Basic/UUID.h"
2222
#include "swift/Basic/STLExtras.h"
2323
#include "swift/Basic/Range.h"
24+
#include "swift/Basic/Version.h"
2425
#include "swift/AST/Identifier.h"
2526
#include "swift/AST/AttrKind.h"
2627
#include "swift/AST/ConcreteDeclRef.h"
@@ -1081,9 +1082,11 @@ class DeclAttributes {
10811082
return getUnavailable(ctx) != nullptr;
10821083
}
10831084

1084-
/// Determine whether there is an "unavailable in current Swift"
1085-
/// attribute.
1086-
bool isUnavailableInCurrentSwift() const;
1085+
/// Determine whether there is a swiftVersionSpecific attribute that's
1086+
/// unavailable relative to the provided language version (defaulting to
1087+
/// current language version).
1088+
bool isUnavailableInSwiftVersion(const version::Version &effectiveVersion =
1089+
version::Version::getCurrentLanguageVersion()) const;
10871090

10881091
/// Returns the first @available attribute that indicates
10891092
/// a declaration is unavailable, or null otherwise.

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ bool swift::shouldPrint(const Decl *D, PrintOptions &Options) {
14491449
return false;
14501450

14511451
// Skip stub declarations used for prior or later variants of Swift.
1452-
if (D->getAttrs().isUnavailableInCurrentSwift())
1452+
if (D->getAttrs().isUnavailableInSwiftVersion())
14531453
return false;
14541454

14551455
if (Options.ExplodeEnumCaseDecls) {

lib/AST/Attr.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,24 @@ bool DeclAttribute::canAttributeAppearOnDeclKind(DeclAttrKind DAK, DeclKind DK)
8585
llvm_unreachable("bad DeclKind");
8686
}
8787

88-
bool DeclAttributes::isUnavailableInCurrentSwift() const {
88+
bool
89+
DeclAttributes::isUnavailableInSwiftVersion(
90+
const version::Version &effectiveVersion) const {
91+
clang::VersionTuple vers = effectiveVersion;
8992
for (auto attr : *this) {
9093
if (auto available = dyn_cast<AvailableAttr>(attr)) {
9194
if (available->isInvalid())
9295
continue;
9396

9497
if (available->getPlatformAgnosticAvailability() ==
95-
PlatformAgnosticAvailabilityKind::SwiftVersionSpecific)
96-
return true;
98+
PlatformAgnosticAvailabilityKind::SwiftVersionSpecific) {
99+
if (available->Introduced.hasValue() &&
100+
available->Introduced.getValue() > vers)
101+
return true;
102+
if (available->Obsoleted.hasValue() &&
103+
available->Obsoleted.getValue() <= vers)
104+
return true;
105+
}
97106
}
98107
}
99108

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
648648
auto unavailableLookupResult =
649649
[&](const UnqualifiedLookupResult &result) {
650650
return result.getValueDecl()->getAttrs()
651-
.isUnavailableInCurrentSwift();
651+
.isUnavailableInSwiftVersion();
652652
};
653653

654654
// If all of the results we found are unavailable, keep looking.
@@ -849,7 +849,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
849849
auto unavailableLookupResult =
850850
[&](const UnqualifiedLookupResult &result) {
851851
return result.getValueDecl()->getAttrs()
852-
.isUnavailableInCurrentSwift();
852+
.isUnavailableInSwiftVersion();
853853
};
854854

855855
// If all of the results we found are unavailable, keep looking.

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,7 +3595,7 @@ namespace {
35953595
typeResolver->resolveDeclSignature(singleResult);
35963596

35973597
// Skip Swift 2 variants.
3598-
if (singleResult->getAttrs().isUnavailableInCurrentSwift())
3598+
if (singleResult->getAttrs().isUnavailableInSwiftVersion())
35993599
continue;
36003600

36013601
if (found)
@@ -6000,7 +6000,7 @@ void SwiftDeclConverter::importMirroredProtocolMembers(
60006000

60016001
for (auto member : proto->getMembers()) {
60026002
// Skip Swift 2 stubs; there's no reason to mirror them.
6003-
if (member->getAttrs().isUnavailableInCurrentSwift())
6003+
if (member->getAttrs().isUnavailableInSwiftVersion())
60046004
continue;
60056005

60066006
if (auto prop = dyn_cast<VarDecl>(member)) {
@@ -6097,7 +6097,7 @@ void SwiftDeclConverter::importInheritedConstructors(
60976097
continue;
60986098

60996099
// Don't inherit Swift 2 stubs.
6100-
if (ctor->getAttrs().isUnavailableInCurrentSwift())
6100+
if (ctor->getAttrs().isUnavailableInSwiftVersion())
61016101
continue;
61026102

61036103
// Don't inherit (non-convenience) factory initializers.

0 commit comments

Comments
 (0)