Skip to content

Commit d144524

Browse files
committed
CustomAvailability: synthesized dynamic availability checking function should be private
When compiling a Swift module in incremental mode, each Swift source file is compiled into an object file and we use linker to link them together. Because the predicate function for checking dynamic feature availability is eagerly synthesized per compilation unit, the linker will complain about duplicated symbols for them. Setting their visibility as private ensures that linker doesn't see them, thus addressing the linker errors. One workaround for this problem is to enable WMO. rdar://164971313
1 parent c337446 commit d144524

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,7 @@ FuncDecl *SwiftDeclSynthesizer::makeAvailabilityDomainPredicate(
31833183
BuiltinIntegerType::get(1, ctx), ImporterImpl.ImportedHeaderUnit);
31843184
funcDecl->setBodySynthesizer(synthesizeAvailabilityDomainPredicateBody,
31853185
(void *)var);
3186-
funcDecl->setAccess(AccessLevel::Internal);
3186+
funcDecl->setAccess(AccessLevel::Private);
31873187

31883188
ImporterImpl.availabilityDomainPredicates[var] = funcDecl;
31893189

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "AvailabilityDomains.h"
2+
3+
int dynamic_domain_pred() {
4+
return 1;
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@available(DynamicDomain)
2+
public struct X {
3+
public init() { }
4+
}
5+
6+
public struct Z {
7+
public init() {
8+
if #available(DynamicDomain) {
9+
print("#available")
10+
print(X())
11+
} else {
12+
print("#unavailable")
13+
}
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public struct Y {
2+
init() {
3+
if #available(DynamicDomain) {
4+
print("#available")
5+
print(X())
6+
print(Z())
7+
} else {
8+
print("#unavailable")
9+
print(Z())
10+
}
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// REQUIRES: swift_feature_CustomAvailability
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-clang -x c %S/Inputs/AvailabilityDomains.c -o %t/AvailabilityDomains.c.o -c
5+
// RUN: %target-build-swift -emit-library %S/Inputs/custom_availability_file1.swift %S/Inputs/custom_availability_file2.swift -module-name main -enable-experimental-feature CustomAvailability -import-bridging-header %S/Inputs/AvailabilityDomains.h -Xlinker %t/AvailabilityDomains.c.o
6+
// RUN: %target-build-swift -wmo -emit-library %S/Inputs/custom_availability_file1.swift %S/Inputs/custom_availability_file2.swift -module-name main -enable-experimental-feature CustomAvailability -import-bridging-header %S/Inputs/AvailabilityDomains.h -Xlinker %t/AvailabilityDomains.c.o

test/SILGen/availability_query_custom_domains_clang.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public func testIfAvailableDynamicDomain() {
101101
}
102102
// CHECK: end sil function '$s4Test28testIfAvailableDynamicDomainyyF'
103103

104-
// CHECK-LABEL: sil hidden [ossa] @$sSC33__swift_DynamicDomain_isAvailableBi1_yF : $@convention(thin) () -> Builtin.Int1
104+
// CHECK-LABEL: sil private [ossa] @$sSC33__swift_DynamicDomain_isAvailableBi1_yF : $@convention(thin) () -> Builtin.Int1
105105
// CHECK: bb0:
106106
// CHECK: [[QUERY_FUNC:%.*]] = function_ref @$sSo27__DynamicDomain_isAvailableSbyFTo : $@convention(c) () -> Bool
107107
// CHECK: [[QUERY_RESULT:%.*]] = apply [[QUERY_FUNC]]() : $@convention(c) () -> Bool

0 commit comments

Comments
 (0)