Skip to content

Change effectiveAccessLevel of package decls from public to package. #70897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4157,17 +4157,7 @@ AccessLevel ValueDecl::getEffectiveAccess() const {
// Handle @testable/@_private(sourceFile:)
switch (effectiveAccess) {
case AccessLevel::Open:
break;
case AccessLevel::Package:
if (getModuleContext()->isTestingEnabled() ||
getModuleContext()->arePrivateImportsEnabled()) {
effectiveAccess = getMaximallyOpenAccessFor(this);
} else {
// Package declarations are effectively public within their
// package unit.
effectiveAccess = AccessLevel::Public;
}
break;
case AccessLevel::Public:
case AccessLevel::Internal:
if (getModuleContext()->isTestingEnabled() ||
Expand Down Expand Up @@ -5900,9 +5890,9 @@ bool ClassDecl::hasResilientMetadata() const {
if (!getModuleContext()->isResilient())
return false;

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

// Otherwise we access metadata members, such as vtable entries, resiliently.
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5955,7 +5955,7 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
ResilienceExpansion
IRGenModule::getResilienceExpansionForAccess(NominalTypeDecl *decl) {
if (decl->getModuleContext() == getSwiftModule() &&
decl->getEffectiveAccess() < AccessLevel::Public)
decl->getEffectiveAccess() < AccessLevel::Package)
return ResilienceExpansion::Maximal;
return ResilienceExpansion::Minimal;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ namespace {
// Emit method dispatch thunk if the class is resilient.
auto *func = cast<AbstractFunctionDecl>(fn.getDecl());

if ((Resilient && func->getEffectiveAccess() >= AccessLevel::Public) ||
if ((Resilient && func->getEffectiveAccess() >= AccessLevel::Package) ||
IGM.getOptions().VirtualFunctionElimination) {
IGM.emitDispatchThunk(fn);
}
Expand Down Expand Up @@ -6922,7 +6922,7 @@ bool irgen::methodRequiresReifiedVTableEntry(IRGenModule &IGM,
auto originatingClass =
cast<ClassDecl>(method.getOverriddenVTableEntry().getDecl()->getDeclContext());

if (originatingClass->getEffectiveAccess() >= AccessLevel::Public) {
if (originatingClass->getEffectiveAccess() >= AccessLevel::Package) {
// If the class is public,
// and it's either marked fragile or part of a non-resilient module, then
// other modules will directly address vtable offsets and we can't remove
Expand All @@ -6932,7 +6932,7 @@ bool irgen::methodRequiresReifiedVTableEntry(IRGenModule &IGM,
<< vtable->getClass()->getName()
<< " for ";
method.print(llvm::dbgs());
llvm::dbgs() << " originates from a public fragile class\n");
llvm::dbgs() << " originates from a public/package fragile class\n");
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/TypeLayoutDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void addYAMLTypeInfoNode(NominalTypeDecl *NTD,
IRGenModule &IGM,
std::vector<YAMLTypeInfoNode> &Result) {
// We only care about public and @usableFromInline declarations.
if (NTD->getEffectiveAccess() < AccessLevel::Public)
if (NTD->getEffectiveAccess() < AccessLevel::Package)
return;

// We don't care about protocols or classes.
Expand Down
3 changes: 1 addition & 2 deletions lib/SIL/IR/SILWitnessTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ bool SILWitnessTable::conformanceIsSerialized(
if (normalConformance && normalConformance->isResilient())
return false;

if (conformance->getProtocol()->getEffectiveAccess() < AccessLevel::Public ||
conformance->getProtocol()->hasPackageAccess())
if (conformance->getProtocol()->getEffectiveAccess() < AccessLevel::Public)
return false;

auto *nominal = conformance->getDeclContext()->getSelfNominalTypeDecl();
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void verifyKeyPathComponent(SILModule &M,
case KeyPathPatternComponent::Kind::StoredProperty: {
auto property = component.getStoredPropertyDecl();
if (expansion == ResilienceExpansion::Minimal) {
require(property->getEffectiveAccess() >= AccessLevel::Public,
require(property->getEffectiveAccess() >= AccessLevel::Package,
"Key path in serialized function cannot reference non-public "
"property");
}
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class SILGenVTable : public SILVTableVisitor<SILGenVTable> {
IsSerialized_t serialized = IsNotSerialized;
auto classIsPublic = theClass->getEffectiveAccess() >= AccessLevel::Public;
// Only public, fixed-layout classes should have serialized vtables.
if (classIsPublic && !theClass->hasPackageAccess() && !isResilient)
if (classIsPublic && !isResilient)
serialized = IsSerialized;

// Finally, create the vtable.
Expand Down Expand Up @@ -1093,7 +1093,7 @@ void SILGenModule::emitNonCopyableTypeDeinitTable(NominalTypeDecl *nom) {
auto serialized = IsSerialized_t::IsNotSerialized;
bool nomIsPublic = nom->getEffectiveAccess() >= AccessLevel::Public;
// We only serialize the deinit if the type is public and not resilient.
if (nomIsPublic && !nom->hasPackageAccess() && !nom->isResilient())
if (nomIsPublic && !nom->isResilient())
serialized = IsSerialized;
SILMoveOnlyDeinit::create(f->getModule(), nom, serialized, f);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/IPO/CrossModuleOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ bool CrossModuleOptimization::canSerializeInstruction(SILInstruction *inst,
// properties, because that would require to make the field decl public -
// which keeps more metadata alive.
return !conservative ||
REAI->getField()->getEffectiveAccess() >= AccessLevel::Public;
REAI->getField()->getEffectiveAccess() >= AccessLevel::Package;
}
return true;
}
Expand Down Expand Up @@ -365,7 +365,7 @@ bool CrossModuleOptimization::canSerializeType(SILType type) {
CanType subType = rawSubType->getCanonicalType();
if (NominalTypeDecl *subNT = subType->getNominalOrBoundGenericNominal()) {

if (conservative && subNT->getEffectiveAccess() < AccessLevel::Public) {
if (conservative && subNT->getEffectiveAccess() < AccessLevel::Package) {
return true;
}

Expand Down Expand Up @@ -596,7 +596,7 @@ void CrossModuleOptimization::makeFunctionUsableFromInline(SILFunction *function

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

// We must not modify decls which are defined in other modules.
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
// Do not emit vtables for non-public classes unless everything has to be
// serialized.
if (!ShouldSerializeAll &&
vt.getClass()->getEffectiveAccess() < swift::AccessLevel::Public)
vt.getClass()->getEffectiveAccess() < swift::AccessLevel::Package)
return;

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

SILFunction *impl = deinit.getImplementation();
Expand Down
4 changes: 2 additions & 2 deletions test/SILGen/witness_tables_serialized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal struct UsableFromInlineStruct : PublicProtocol, UsableFromInlineProtoco
// CHECK-NONRESILIENT-DAG: sil_witness_table PublicResilientStruct: PackageProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PublicResilientStruct: InternalProtocol

// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: PublicProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table [serialized] PackageStruct: UsableFromInlineProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: PublicProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: UsableFromInlineProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table PackageStruct: PackageProtocol
// CHECK-NONRESILIENT-DAG: sil_witness_table hidden PackageStruct: InternalProtocol
3 changes: 1 addition & 2 deletions test/Sema/package_resilience_access.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ package class PkgKlass: PkgProto {
// UTILS-COMMON-LABEL: // default argument 0 of PkgKlass.init(data:)
// UTILS-COMMON-NEXT: sil [ossa] @$s5Utils8PkgKlassC4dataACSi_tcfcfA_ : $@convention(thin) () -> Int {

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

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