Skip to content

Commit 2f8e7db

Browse files
committed
Use the same behavior of a non-frozen public decl for a package decl
in a resiliency check, i.e. *Decl::isFormallyResilient. If the defining module is built resiliently, treat the package decl as resilient. Added tests to check for serialization and indirect access with/out resilience enabled. Ref rdar://118947451
1 parent 987756c commit 2f8e7db

File tree

5 files changed

+478
-125
lines changed

5 files changed

+478
-125
lines changed

include/swift/AST/AccessScope.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class AccessScope {
7575
bool isFileScope() const;
7676
bool isInternal() const;
7777
bool isPackage() const;
78+
bool isPublicOrPackage() const { return isPublic() || isPackage(); }
7879

7980
/// Checks if the DeclContext of this (use site) access scope is more
8081
/// restrictive than that of the argument (decl site) based on the DeclContext

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,7 @@ bool AbstractStorageDecl::isFormallyResilient() const {
29862986
// Non-public global and static variables always have a
29872987
// fixed layout.
29882988
if (!getFormalAccessScope(/*useDC=*/nullptr,
2989-
/*treatUsableFromInlineAsPublic=*/true).isPublic())
2989+
/*treatUsableFromInlineAsPublic=*/true).isPublicOrPackage())
29902990
return false;
29912991

29922992
return true;
@@ -4987,10 +4987,10 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
49874987
}
49884988

49894989
bool NominalTypeDecl::isFormallyResilient() const {
4990-
// Private, (unversioned) internal, and package types always have a
4990+
// Private and (unversioned) internal types always have a
49914991
// fixed layout.
49924992
if (!getFormalAccessScope(/*useDC=*/nullptr,
4993-
/*treatUsableFromInlineAsPublic=*/true).isPublic())
4993+
/*treatUsableFromInlineAsPublic=*/true).isPublicOrPackage())
49944994
return false;
49954995

49964996
// Check for an explicit @_fixed_layout or @frozen attribute.

test/SILGen/witness_tables_serialized.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ internal struct UsableFromInlineStruct : PublicProtocol, UsableFromInlineProtoco
2626
// CHECK-DAG: sil_witness_table PublicFrozenStruct: PackageProtocol
2727
// CHECK-DAG: sil_witness_table hidden PublicFrozenStruct: InternalProtocol
2828

29-
// CHECK-DAG: sil_witness_table [serialized] PackageStruct: PublicProtocol
30-
// CHECK-DAG: sil_witness_table [serialized] PackageStruct: UsableFromInlineProtocol
31-
// CHECK-DAG: sil_witness_table PackageStruct: PackageProtocol
32-
// CHECK-DAG: sil_witness_table hidden PackageStruct: InternalProtocol
33-
3429
// CHECK-RESILIENT-DAG: sil_witness_table UsableFromInlineStruct: UsableFromInlineProtocol
3530
// CHECK-RESILIENT-DAG: sil_witness_table UsableFromInlineStruct: PublicProtocol
3631
// CHECK-RESILIENT-DAG: sil_witness_table UsableFromInlineStruct: PackageProtocol
@@ -41,6 +36,11 @@ internal struct UsableFromInlineStruct : PublicProtocol, UsableFromInlineProtoco
4136
// CHECK-RESILIENT-DAG: sil_witness_table PublicResilientStruct: PackageProtocol
4237
// CHECK-RESILIENT-DAG: sil_witness_table hidden PublicResilientStruct: InternalProtocol
4338

39+
// CHECK-RESILIENT-DAG: sil_witness_table PackageStruct: PublicProtocol
40+
// CHECK-RESILIENT-DAG: sil_witness_table PackageStruct: UsableFromInlineProtocol
41+
// CHECK-RESILIENT-DAG: sil_witness_table PackageStruct: PackageProtocol
42+
// CHECK-RESILIENT-DAG: sil_witness_table hidden PackageStruct: InternalProtocol
43+
4444
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] UsableFromInlineStruct: UsableFromInlineProtocol
4545
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] UsableFromInlineStruct: PublicProtocol
4646
// CHECK-NONRESILIENT-DAG: sil_witness_table UsableFromInlineStruct: PackageProtocol
@@ -50,3 +50,8 @@ internal struct UsableFromInlineStruct : PublicProtocol, UsableFromInlineProtoco
5050
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PublicResilientStruct: UsableFromInlineProtocol
5151
// CHECK-NONRESILIENT-DAG: sil_witness_table PublicResilientStruct: PackageProtocol
5252
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PublicResilientStruct: InternalProtocol
53+
54+
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: PublicProtocol
55+
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: UsableFromInlineProtocol
56+
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: PackageProtocol
57+
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PackageStruct: InternalProtocol

0 commit comments

Comments
 (0)