Skip to content

Commit db28fc8

Browse files
authored
Merge pull request #70100 from CodaFi/cereal-milk
Don't Serialize Declarations with `package` Access
2 parents d909073 + a987ba4 commit db28fc8

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,10 @@ class ValueDecl : public Decl {
29052905
/// if the base declaration is \c open, the override might have to be too.
29062906
bool hasOpenAccess(const DeclContext *useDC) const;
29072907

2908+
/// Returns whether this declaration should be treated as having the \c
2909+
/// package access level.
2910+
bool hasPackageAccess() const;
2911+
29082912
/// FIXME: This is deprecated.
29092913
bool isRecursiveValidation() const;
29102914

lib/AST/Decl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,13 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
42034203
return access == AccessLevel::Open;
42044204
}
42054205

4206+
bool ValueDecl::hasPackageAccess() const {
4207+
AccessLevel access =
4208+
getAdjustedFormalAccess(this, /*useDC*/ nullptr,
4209+
/*treatUsableFromInlineAsPublic*/ false);
4210+
return access == AccessLevel::Package;
4211+
}
4212+
42064213
/// Given the formal access level for using \p VD, compute the scope where
42074214
/// \p VD may be accessed, taking \@usableFromInline, \@testable imports,
42084215
/// \@_spi imports, and enclosing access levels into account.

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ IsSerialized_t SILDeclRef::isSerialized() const {
844844
}
845845

846846
// Anything else that is not public is not serializable.
847-
if (d->getEffectiveAccess() < AccessLevel::Public)
847+
if (d->getEffectiveAccess() < AccessLevel::Public || d->hasPackageAccess())
848848
return IsNotSerialized;
849849

850850
// Enum element constructors are serializable if the enum is

lib/SIL/IR/SILWitnessTable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ bool SILWitnessTable::conformanceIsSerialized(
171171
if (normalConformance && normalConformance->isResilient())
172172
return false;
173173

174-
if (conformance->getProtocol()->getEffectiveAccess() < AccessLevel::Public)
174+
if (conformance->getProtocol()->getEffectiveAccess() < AccessLevel::Public ||
175+
conformance->getProtocol()->hasPackageAccess())
175176
return false;
176177

177178
auto *nominal = conformance->getDeclContext()->getSelfNominalTypeDecl();

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class SILGenVTable : public SILVTableVisitor<SILGenVTable> {
307307
IsSerialized_t serialized = IsNotSerialized;
308308
auto classIsPublic = theClass->getEffectiveAccess() >= AccessLevel::Public;
309309
// Only public, fixed-layout classes should have serialized vtables.
310-
if (classIsPublic && !isResilient)
310+
if (classIsPublic && !theClass->hasPackageAccess() && !isResilient)
311311
serialized = IsSerialized;
312312

313313
// Finally, create the vtable.
@@ -1080,7 +1080,7 @@ void SILGenModule::emitNonCopyableTypeDeinitTable(NominalTypeDecl *nom) {
10801080
auto serialized = IsSerialized_t::IsNotSerialized;
10811081
bool nomIsPublic = nom->getEffectiveAccess() >= AccessLevel::Public;
10821082
// We only serialize the deinit if the type is public and not resilient.
1083-
if (nomIsPublic && !nom->isResilient())
1083+
if (nomIsPublic && !nom->hasPackageAccess() && !nom->isResilient())
10841084
serialized = IsSerialized;
10851085
SILMoveOnlyDeinit::create(f->getModule(), nom, serialized, f);
10861086
}

0 commit comments

Comments
 (0)