Skip to content

Commit d2682f7

Browse files
committed
AST: Import "always enabled" availability domains from Clang.
Resolves rdar://157593409.
1 parent 0647da5 commit d2682f7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

lib/AST/AvailabilityDomain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ getCustomDomainKind(clang::FeatureAvailKind featureAvailKind) {
3333
return CustomAvailabilityDomain::Kind::Disabled;
3434
case clang::FeatureAvailKind::Dynamic:
3535
return CustomAvailabilityDomain::Kind::Dynamic;
36-
// FIXME: [availability] Add support for AlwaysEnabled.
36+
case clang::FeatureAvailKind::AlwaysAvailable:
37+
return CustomAvailabilityDomain::Kind::AlwaysEnabled;
3738
default:
3839
llvm::report_fatal_error("unexpected kind");
3940
}
@@ -54,11 +55,11 @@ customDomainForClangDecl(ValueDecl *decl) {
5455
return nullptr;
5556

5657
// Check that the domain has a supported availability kind.
57-
// FIXME: [availability] Add support for AlwaysEnabled.
5858
switch (featureInfo.second.Kind) {
5959
case clang::FeatureAvailKind::Available:
6060
case clang::FeatureAvailKind::Unavailable:
6161
case clang::FeatureAvailKind::Dynamic:
62+
case clang::FeatureAvailKind::AlwaysAvailable:
6263
break;
6364
default:
6465
return nullptr;

test/ClangImporter/Inputs/availability_custom_domains_other.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,26 @@ func availableInMediterranean() { }
99
func testOtherClangDecls() { // expected-note {{add '@available' attribute to enclosing global function}}
1010
available_in_baltic() // expected-error {{'available_in_baltic()' is only available in Baltic}}
1111
// expected-note@-1 {{add 'if #available' version check}}
12+
available_in_bering() // ok, Bering is always available
13+
unavailable_in_bering() // expected-error {{'unavailable_in_bering()' is unavailable}}
14+
}
15+
16+
@available(Baltic)
17+
func availableInBalticOther() {
18+
available_in_baltic()
19+
available_in_bering() // ok, Bering is always available
20+
unavailable_in_bering() // expected-error {{'unavailable_in_bering()' is unavailable}}
21+
}
22+
23+
@available(Bering)
24+
func availableInBering() { // expected-note {{add '@available' attribute to enclosing global function}}
25+
available_in_baltic() // expected-error {{'available_in_baltic()' is only available in Baltic}}
26+
// expected-note@-1 {{add 'if #available' version check}}
27+
available_in_bering()
28+
unavailable_in_bering() // expected-error {{'unavailable_in_bering()' is unavailable}}
29+
}
30+
31+
@available(Bering, unavailable)
32+
func unavailableInBering() {
33+
unavailable_in_bering()
1234
}

test/Inputs/custom-modules/availability-domains/Seas.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
int aegean_pred(void);
44

55
CLANG_ENABLED_AVAILABILITY_DOMAIN(Baltic);
6+
CLANG_ALWAYS_ENABLED_AVAILABILITY_DOMAIN(Bering);
67
CLANG_DISABLED_AVAILABILITY_DOMAIN(Mediterranean);
78
CLANG_DYNAMIC_AVAILABILITY_DOMAIN(Aegean, aegean_pred);
89

@@ -12,5 +13,11 @@ CLANG_DYNAMIC_AVAILABILITY_DOMAIN(Aegean, aegean_pred);
1213
__attribute__((availability(domain:Baltic, AVAIL)))
1314
void available_in_baltic(void);
1415

16+
__attribute__((availability(domain:Bering, AVAIL)))
17+
void available_in_bering(void);
18+
19+
__attribute__((availability(domain:Bering, UNAVAIL)))
20+
void unavailable_in_bering(void);
21+
1522
#undef UNAVAIL
1623
#undef AVAIL

0 commit comments

Comments
 (0)