Skip to content

Commit 0e8ffef

Browse files
authored
Merge pull request #70897 from apple/es-pkg-fx
Change effectiveAccessLevel of `package` decls from `public` to `package`.
2 parents 8c448a5 + 4b8b708 commit 0e8ffef

File tree

11 files changed

+19
-31
lines changed

11 files changed

+19
-31
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,17 +4157,7 @@ AccessLevel ValueDecl::getEffectiveAccess() const {
41574157
// Handle @testable/@_private(sourceFile:)
41584158
switch (effectiveAccess) {
41594159
case AccessLevel::Open:
4160-
break;
41614160
case AccessLevel::Package:
4162-
if (getModuleContext()->isTestingEnabled() ||
4163-
getModuleContext()->arePrivateImportsEnabled()) {
4164-
effectiveAccess = getMaximallyOpenAccessFor(this);
4165-
} else {
4166-
// Package declarations are effectively public within their
4167-
// package unit.
4168-
effectiveAccess = AccessLevel::Public;
4169-
}
4170-
break;
41714161
case AccessLevel::Public:
41724162
case AccessLevel::Internal:
41734163
if (getModuleContext()->isTestingEnabled() ||
@@ -5900,9 +5890,9 @@ bool ClassDecl::hasResilientMetadata() const {
59005890
if (!getModuleContext()->isResilient())
59015891
return false;
59025892

5903-
// If the class is not public, we can't use it outside the module at all.
5893+
// If the class is not public or package, we can't use it outside the module at all.
59045894
// Take enable testing into account.
5905-
if (getEffectiveAccess() < AccessLevel::Public)
5895+
if (getEffectiveAccess() < AccessLevel::Package)
59065896
return false;
59075897

59085898
// Otherwise we access metadata members, such as vtable entries, resiliently.

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5995,7 +5995,7 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
59955995
ResilienceExpansion
59965996
IRGenModule::getResilienceExpansionForAccess(NominalTypeDecl *decl) {
59975997
if (decl->getModuleContext() == getSwiftModule() &&
5998-
decl->getEffectiveAccess() < AccessLevel::Public)
5998+
decl->getEffectiveAccess() < AccessLevel::Package)
59995999
return ResilienceExpansion::Maximal;
60006000
return ResilienceExpansion::Minimal;
60016001
}

lib/IRGen/GenMeta.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ namespace {
18831883
// Emit method dispatch thunk if the class is resilient.
18841884
auto *func = cast<AbstractFunctionDecl>(fn.getDecl());
18851885

1886-
if ((Resilient && func->getEffectiveAccess() >= AccessLevel::Public) ||
1886+
if ((Resilient && func->getEffectiveAccess() >= AccessLevel::Package) ||
18871887
IGM.getOptions().VirtualFunctionElimination) {
18881888
IGM.emitDispatchThunk(fn);
18891889
}
@@ -6925,7 +6925,7 @@ bool irgen::methodRequiresReifiedVTableEntry(IRGenModule &IGM,
69256925
auto originatingClass =
69266926
cast<ClassDecl>(method.getOverriddenVTableEntry().getDecl()->getDeclContext());
69276927

6928-
if (originatingClass->getEffectiveAccess() >= AccessLevel::Public) {
6928+
if (originatingClass->getEffectiveAccess() >= AccessLevel::Package) {
69296929
// If the class is public,
69306930
// and it's either marked fragile or part of a non-resilient module, then
69316931
// other modules will directly address vtable offsets and we can't remove
@@ -6935,7 +6935,7 @@ bool irgen::methodRequiresReifiedVTableEntry(IRGenModule &IGM,
69356935
<< vtable->getClass()->getName()
69366936
<< " for ";
69376937
method.print(llvm::dbgs());
6938-
llvm::dbgs() << " originates from a public fragile class\n");
6938+
llvm::dbgs() << " originates from a public/package fragile class\n");
69396939
return true;
69406940
}
69416941
}

lib/IRGen/TypeLayoutDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void addYAMLTypeInfoNode(NominalTypeDecl *NTD,
8383
IRGenModule &IGM,
8484
std::vector<YAMLTypeInfoNode> &Result) {
8585
// We only care about public and @usableFromInline declarations.
86-
if (NTD->getEffectiveAccess() < AccessLevel::Public)
86+
if (NTD->getEffectiveAccess() < AccessLevel::Package)
8787
return;
8888

8989
// We don't care about protocols or classes.

lib/SIL/IR/SILWitnessTable.cpp

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

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

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

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void verifyKeyPathComponent(SILModule &M,
251251
case KeyPathPatternComponent::Kind::StoredProperty: {
252252
auto property = component.getStoredPropertyDecl();
253253
if (expansion == ResilienceExpansion::Minimal) {
254-
require(property->getEffectiveAccess() >= AccessLevel::Public,
254+
require(property->getEffectiveAccess() >= AccessLevel::Package,
255255
"Key path in serialized function cannot reference non-public "
256256
"property");
257257
}

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 && !theClass->hasPackageAccess() && !isResilient)
310+
if (classIsPublic && !isResilient)
311311
serialized = IsSerialized;
312312

313313
// Finally, create the vtable.
@@ -1093,7 +1093,7 @@ void SILGenModule::emitNonCopyableTypeDeinitTable(NominalTypeDecl *nom) {
10931093
auto serialized = IsSerialized_t::IsNotSerialized;
10941094
bool nomIsPublic = nom->getEffectiveAccess() >= AccessLevel::Public;
10951095
// We only serialize the deinit if the type is public and not resilient.
1096-
if (nomIsPublic && !nom->hasPackageAccess() && !nom->isResilient())
1096+
if (nomIsPublic && !nom->isResilient())
10971097
serialized = IsSerialized;
10981098
SILMoveOnlyDeinit::create(f->getModule(), nom, serialized, f);
10991099
}

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ bool CrossModuleOptimization::canSerializeInstruction(SILInstruction *inst,
328328
// properties, because that would require to make the field decl public -
329329
// which keeps more metadata alive.
330330
return !conservative ||
331-
REAI->getField()->getEffectiveAccess() >= AccessLevel::Public;
331+
REAI->getField()->getEffectiveAccess() >= AccessLevel::Package;
332332
}
333333
return true;
334334
}
@@ -365,7 +365,7 @@ bool CrossModuleOptimization::canSerializeType(SILType type) {
365365
CanType subType = rawSubType->getCanonicalType();
366366
if (NominalTypeDecl *subNT = subType->getNominalOrBoundGenericNominal()) {
367367

368-
if (conservative && subNT->getEffectiveAccess() < AccessLevel::Public) {
368+
if (conservative && subNT->getEffectiveAccess() < AccessLevel::Package) {
369369
return true;
370370
}
371371

@@ -596,7 +596,7 @@ void CrossModuleOptimization::makeFunctionUsableFromInline(SILFunction *function
596596

597597
/// Make a nominal type, including it's context, usable from inline.
598598
void CrossModuleOptimization::makeDeclUsableFromInline(ValueDecl *decl) {
599-
if (decl->getEffectiveAccess() >= AccessLevel::Public)
599+
if (decl->getEffectiveAccess() >= AccessLevel::Package)
600600
return;
601601

602602
// We must not modify decls which are defined in other modules.

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
28802880
// Do not emit vtables for non-public classes unless everything has to be
28812881
// serialized.
28822882
if (!ShouldSerializeAll &&
2883-
vt.getClass()->getEffectiveAccess() < swift::AccessLevel::Public)
2883+
vt.getClass()->getEffectiveAccess() < swift::AccessLevel::Package)
28842884
return;
28852885

28862886
if (vt.isSpecialized())
@@ -2924,7 +2924,7 @@ void SILSerializer::writeSILMoveOnlyDeinit(const SILMoveOnlyDeinit &deinit) {
29242924
// Do not emit deinit for non-public nominal types unless everything has to be
29252925
// serialized.
29262926
if (!ShouldSerializeAll && deinit.getNominalDecl()->getEffectiveAccess() <
2927-
swift::AccessLevel::Public)
2927+
swift::AccessLevel::Package)
29282928
return;
29292929

29302930
SILFunction *impl = deinit.getImplementation();

test/SILGen/witness_tables_serialized.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal struct UsableFromInlineStruct : PublicProtocol, UsableFromInlineProtoco
5151
// CHECK-NONRESILIENT-DAG: sil_witness_table PublicResilientStruct: PackageProtocol
5252
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PublicResilientStruct: InternalProtocol
5353

54-
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: PublicProtocol
55-
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: UsableFromInlineProtocol
54+
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: PublicProtocol
55+
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: UsableFromInlineProtocol
5656
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: PackageProtocol
5757
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PackageStruct: InternalProtocol

test/Sema/package_resilience_access.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ package class PkgKlass: PkgProto {
143143
// UTILS-COMMON-LABEL: // default argument 0 of PkgKlass.init(data:)
144144
// UTILS-COMMON-NEXT: sil [ossa] @$s5Utils8PkgKlassC4dataACSi_tcfcfA_ : $@convention(thin) () -> Int {
145145

146-
// FIXME: __allocating_init for a `package` class should not be serialized in resilient Utils.
147146
// UTILS-COMMON-LABEL: // PkgKlass.__allocating_init(data:)
148-
// UTILS-COMMON-NEXT: sil [serialized] [exact_self_class] [ossa] @$s5Utils8PkgKlassC4dataACSi_tcfC : $@convention(method) (Int, @thick PkgKlass.Type) -> @owned PkgKlass {
147+
// UTILS-COMMON-NEXT: sil [exact_self_class] [ossa] @$s5Utils8PkgKlassC4dataACSi_tcfC : $@convention(method) (Int, @thick PkgKlass.Type) -> @owned PkgKlass {
149148

150149
// UTILS-COMMON-LABEL: // PkgKlass.init(data:)
151150
// UTILS-COMMON-NEXT: sil [ossa] @$s5Utils8PkgKlassC4dataACSi_tcfc : $@convention(method) (Int, @owned PkgKlass) -> @owned PkgKlass {

0 commit comments

Comments
 (0)