Skip to content

SIL: remove the private_external SILLinkage #39632

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 2 commits into from
Oct 11, 2021
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
15 changes: 1 addition & 14 deletions include/swift/SIL/SILLinkage.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ enum class SILLinkage : uint8_t {
/// shared.
SharedExternal,

/// The same as SharedExternal, except that the definition is private in the
/// other module. This can only occur if an inlined fragile function from
/// another module references a private definition in the other module.
PrivateExternal,

/// The default linkage for a definition.
DefaultForDefinition = Public,

Expand Down Expand Up @@ -138,8 +133,6 @@ inline SILLinkage stripExternalFromLinkage(SILLinkage linkage) {
return SILLinkage::Hidden;
if (linkage == SILLinkage::SharedExternal)
return SILLinkage::Shared;
if (linkage == SILLinkage::PrivateExternal)
return SILLinkage::Private;
return linkage;
}

Expand All @@ -158,10 +151,8 @@ inline SILLinkage addExternalToLinkage(SILLinkage linkage) {
case SILLinkage::Hidden:
return SILLinkage::HiddenExternal;
case SILLinkage::Private:
return SILLinkage::PrivateExternal;
case SILLinkage::PublicExternal:
case SILLinkage::SharedExternal:
case SILLinkage::PrivateExternal:
case SILLinkage::HiddenExternal:
return linkage;
}
Expand Down Expand Up @@ -197,7 +188,6 @@ inline bool hasPublicVisibility(SILLinkage linkage) {
case SILLinkage::Shared:
case SILLinkage::SharedExternal:
case SILLinkage::Private:
case SILLinkage::PrivateExternal:
case SILLinkage::HiddenExternal:
return false;
}
Expand All @@ -216,7 +206,6 @@ inline bool hasSharedVisibility(SILLinkage linkage) {
case SILLinkage::Hidden:
case SILLinkage::HiddenExternal:
case SILLinkage::Private:
case SILLinkage::PrivateExternal:
return false;
}

Expand All @@ -226,7 +215,6 @@ inline bool hasSharedVisibility(SILLinkage linkage) {
inline bool hasPrivateVisibility(SILLinkage linkage) {
switch (linkage) {
case SILLinkage::Private:
case SILLinkage::PrivateExternal:
return true;
case SILLinkage::Public:
case SILLinkage::PublicExternal:
Expand All @@ -247,8 +235,7 @@ inline SILLinkage effectiveLinkageForClassMember(SILLinkage linkage,
case SubclassScope::External:
if (linkage == SILLinkage::Private || linkage == SILLinkage::Hidden)
return SILLinkage::Public;
if (linkage == SILLinkage::PrivateExternal ||
linkage == SILLinkage::HiddenExternal)
if (linkage == SILLinkage::HiddenExternal)
return SILLinkage::PublicExternal;
break;

Expand Down
3 changes: 2 additions & 1 deletion include/swift/SIL/SILWitnessTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
/// The method required.
SILDeclRef Requirement;
/// The witness for the method.
/// This can be null in case dead function elimination has removed the method.
/// This can be null in case dead function elimination has removed the method
/// or if the method was not serialized (for de-serialized witness tables).
SILFunction *Witness;
};

Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,6 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
}

case SILLinkage::HiddenExternal:
case SILLinkage::PrivateExternal:
if (isDefinition)
return RESULT(AvailableExternally, Hidden, Default);

Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,6 @@ namespace {
case SILLinkage::Hidden:
case SILLinkage::HiddenExternal:
case SILLinkage::Private:
case SILLinkage::PrivateExternal:
return true;

case SILLinkage::Shared:
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/Linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
auto *nominal = getType().getAnyNominal();
if (getDeclLinkage(nominal) == FormalLinkage::PublicNonUnique)
return SILLinkage::Shared;
return forDefinition ? SILLinkage::Private : SILLinkage::PrivateExternal;
assert(forDefinition);
return SILLinkage::Private;
}

case Kind::TypeMetadataAccessFunction:
Expand Down
3 changes: 1 addition & 2 deletions lib/SIL/IR/SIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ swift::getLinkageForProtocolConformance(const RootProtocolConformance *C,
switch (access) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:
return (definition ? SILLinkage::Private : SILLinkage::PrivateExternal);
return SILLinkage::Private;

case AccessLevel::Internal:
return (definition ? SILLinkage::Hidden : SILLinkage::HiddenExternal);
Expand Down Expand Up @@ -280,7 +280,6 @@ bool AbstractStorageDecl::exportsPropertyDescriptor() const {
return false;

case SILLinkage::HiddenExternal:
case SILLinkage::PrivateExternal:
case SILLinkage::PublicExternal:
case SILLinkage::SharedExternal:
llvm_unreachable("should be definition linkage?");
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILDeclRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
switch (effectiveAccess) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:
return maybeAddExternal(SILLinkage::Private);
return SILLinkage::Private;

case AccessLevel::Internal:
if (limit == Limit::OnDemand)
Expand Down
6 changes: 4 additions & 2 deletions lib/SIL/IR/SILDefaultWitnessTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ convertToDefinition(ArrayRef<Entry> entries) {
// Bump the reference count of witness functions referenced by this table.
for (auto entry : getEntries()) {
if (entry.isValid() && entry.getKind() == SILWitnessTable::Method) {
entry.getMethodWitness().Witness->incrementRefCount();
if (SILFunction *f = entry.getMethodWitness().Witness)
f->incrementRefCount();
}
}
}
Expand All @@ -105,7 +106,8 @@ SILDefaultWitnessTable::~SILDefaultWitnessTable() {
// Drop the reference count of witness functions referenced by this table.
for (auto entry : getEntries()) {
if (entry.isValid() && entry.getKind() == SILWitnessTable::Method) {
entry.getMethodWitness().Witness->decrementRefCount();
if (SILFunction *f = entry.getMethodWitness().Witness)
f->decrementRefCount();
}
}
}
4 changes: 1 addition & 3 deletions lib/SIL/IR/SILModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ class SILModule::SerializationCallback final
decl->setLinkage(SILLinkage::SharedExternal);
return;
case SILLinkage::Private:
decl->setLinkage(SILLinkage::PrivateExternal);
return;
llvm_unreachable("cannot make a private external symbol");
case SILLinkage::PublicExternal:
case SILLinkage::HiddenExternal:
case SILLinkage::SharedExternal:
case SILLinkage::PrivateExternal:
return;
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,6 @@ static StringRef getLinkageString(SILLinkage linkage) {
case SILLinkage::PublicExternal: return "public_external ";
case SILLinkage::HiddenExternal: return "hidden_external ";
case SILLinkage::SharedExternal: return "shared_external ";
case SILLinkage::PrivateExternal: return "private_external ";
}
llvm_unreachable("bad linkage");
}
Expand Down
1 change: 0 additions & 1 deletion lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ static bool parseSILLinkage(Optional<SILLinkage> &Result, Parser &P) {
.Case("public_external", SILLinkage::PublicExternal)
.Case("hidden_external", SILLinkage::HiddenExternal)
.Case("shared_external", SILLinkage::SharedExternal)
.Case("private_external", SILLinkage::PrivateExternal)
.Default(None);

// If we succeed, consume the token.
Expand Down
2 changes: 2 additions & 0 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5958,6 +5958,8 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
continue;

SILFunction *F = E.getMethodWitness().Witness;
if (!F)
continue;

#if 0
// FIXME: For now, all default witnesses are private.
Expand Down
20 changes: 20 additions & 0 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ SILGenModule::SILGenModule(SILModule &M, ModuleDecl *SM)

SILGenModule::~SILGenModule() {
assert(!TopLevelSGF && "active source file lowering!?");

// Update the linkage of external private functions to public_external,
// because there is no private_external linkage. External private functions
// can occur in the following cases:
//
// * private class methods which are referenced from the vtable of a derived
// class in a different file/module. Such private methods are always
// generated with public linkage in the other file/module.
//
// * in lldb: lldb can access private declarations in other files/modules
//
// * private functions with a @_silgen_name attribute but without a body
//
// * when compiling with -disable-access-control
//
for (SILFunction &f : M.getFunctionList()) {
if (f.getLinkage() == SILLinkage::Private && f.isExternalDeclaration())
f.setLinkage(SILLinkage::PublicExternal);
}

M.verify();
}

Expand Down
1 change: 0 additions & 1 deletion lib/SILOptimizer/IPO/CrossModuleSerializationSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ bool CrossModuleSerializationSetup::canUseFromInline(SILFunction *func,
case SILLinkage::Private:
case SILLinkage::PublicExternal:
case SILLinkage::SharedExternal:
case SILLinkage::PrivateExternal:
case SILLinkage::HiddenExternal:
break;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/SILOptimizer/UtilityPasses/InstCount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ STATISTIC(TotalPrivateFuncs, "Number of private funcs");
STATISTIC(TotalSharedFuncs, "Number of shared funcs");
STATISTIC(TotalPublicExternalFuncs, "Number of public external funcs");
STATISTIC(TotalHiddenExternalFuncs, "Number of hidden external funcs");
STATISTIC(TotalPrivateExternalFuncs, "Number of private external funcs");
STATISTIC(TotalSharedExternalFuncs, "Number of shared external funcs");

// Individual instruction statistics
Expand Down Expand Up @@ -139,9 +138,6 @@ class InstCount : public SILFunctionTransform {
case SILLinkage::SharedExternal:
++TotalSharedExternalFuncs;
break;
case SILLinkage::PrivateExternal:
++TotalPrivateExternalFuncs;
break;
}
}
};
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fromStableSILLinkage(unsigned value) {
case SIL_LINKAGE_PUBLIC_EXTERNAL: return SILLinkage::PublicExternal;
case SIL_LINKAGE_HIDDEN_EXTERNAL: return SILLinkage::HiddenExternal;
case SIL_LINKAGE_SHARED_EXTERNAL: return SILLinkage::SharedExternal;
case SIL_LINKAGE_PRIVATE_EXTERNAL: return SILLinkage::PrivateExternal;
default: return None;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 633; // remove value_buffer insts
const uint16_t SWIFTMODULE_VERSION_MINOR = 634; // remove PrivateExternal

/// A standard hash seed used for all string hashes in a serialized module.
///
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/SILFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ enum SILLinkageEncoding : uint8_t {
SIL_LINKAGE_PUBLIC_EXTERNAL,
SIL_LINKAGE_HIDDEN_EXTERNAL,
SIL_LINKAGE_SHARED_EXTERNAL,
SIL_LINKAGE_PRIVATE_EXTERNAL,
};
using SILLinkageField = BCFixed<4>;

Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static unsigned toStableSILLinkage(SILLinkage linkage) {
case SILLinkage::PublicExternal: return SIL_LINKAGE_PUBLIC_EXTERNAL;
case SILLinkage::HiddenExternal: return SIL_LINKAGE_HIDDEN_EXTERNAL;
case SILLinkage::SharedExternal: return SIL_LINKAGE_SHARED_EXTERNAL;
case SILLinkage::PrivateExternal: return SIL_LINKAGE_PRIVATE_EXTERNAL;
}
llvm_unreachable("bad linkage");
}
Expand Down Expand Up @@ -2666,7 +2665,8 @@ void SILSerializer::writeSILWitnessTableEntry(
SmallVector<ValueID, 4> ListOfValues;
handleSILDeclRef(S, methodWitness.Requirement, ListOfValues);
IdentifierID witnessID = 0;
if (SILFunction *witness = methodWitness.Witness) {
SILFunction *witness = methodWitness.Witness;
if (witness && witness->hasValidLinkageForFragileRef()) {
addReferencedSILFunction(witness, true);
witnessID = S.addUniquedStringRef(witness->getName());
}
Expand Down
8 changes: 0 additions & 8 deletions test/IRGen/sil_linkage.sil
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ sil_stage canonical
// CHECK: declare{{( dllimport)?}} swiftcc void @public_external_fragile_function_def_test()
// CHECK: define{{( protected)?}} available_externally{{ (hidden)?}}{{( dllimport)?}} swiftcc void @hidden_external_fragile_function_def_test() {{.*}} {
// CHECK: define linkonce_odr hidden swiftcc void @shared_external_fragile_function_def_test() {{.*}} {
// CHECK: define{{( protected)?}} available_externally{{ (hidden)?}}{{( dllimport)?}} swiftcc void @private_external_fragile_function_def_test() {{.*}} {
// CHECK: define{{( protected)?}}{{( dllexport)?}} swiftcc void @public_resilient_function_test() {{.*}} {
// CHECK: define hidden swiftcc void @hidden_resilient_function_test() {{.*}} {
// CHECK: define linkonce_odr hidden swiftcc void @shared_resilient_function_test() {{.*}} {
Expand Down Expand Up @@ -75,11 +74,6 @@ sil shared_external [serialized] @shared_external_fragile_function_def_test : $@
return %0 : $()
}

sil private_external [serialized] @private_external_fragile_function_def_test : $@convention(thin) () -> () {
%0 = tuple()
return %0 : $()
}

sil public_external [serialized] @public_external_fragile_function_decl_test : $@convention(thin) () -> ()

sil hidden_external [serialized] @hidden_external_fragile_function_decl_test : $@convention(thin) () -> ()
Expand Down Expand Up @@ -153,7 +147,6 @@ sil public @use_all_symbols : $@convention(thin) () -> () {
%4 = function_ref @public_external_fragile_function_def_test : $@convention(thin) () -> ()
%5 = function_ref @hidden_external_fragile_function_def_test : $@convention(thin) () -> ()
%6 = function_ref @shared_external_fragile_function_def_test : $@convention(thin) () -> ()
%7 = function_ref @private_external_fragile_function_def_test : $@convention(thin) () -> ()
%8 = function_ref @public_external_fragile_function_decl_test : $@convention(thin) () -> ()
%9 = function_ref @hidden_external_fragile_function_decl_test : $@convention(thin) () -> ()
// %10 = function_ref @shared_external_fragile_function_decl_test : $@convention(thin) () -> ()
Expand All @@ -178,7 +171,6 @@ sil public @use_all_symbols : $@convention(thin) () -> () {
apply %4() : $@convention(thin) () -> ()
apply %5() : $@convention(thin) () -> ()
apply %6() : $@convention(thin) () -> ()
apply %7() : $@convention(thin) () -> ()
apply %8() : $@convention(thin) () -> ()
apply %9() : $@convention(thin) () -> ()
// apply %10() : $@convention(thin) () -> ()
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/devirt_try_apply.sil
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public func test6() -> Int32?
sil_global [serialized] @_TZvOs7Process5_argcVs5Int32 : $Int32


sil_global private_external [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word
sil_global [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word


sil_global [serialized] @_TZvOs7Process11_unsafeArgvGVs20UnsafeMutablePointerGS0_Vs4Int8__ : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
Expand Down Expand Up @@ -780,7 +780,7 @@ bb4(%19 : $Error):
}


sil private_external [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()
sil [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()


public class A {
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/devirt_try_apply_ownership.sil
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public func test6() -> Int32?
sil_global [serialized] @_TZvOs7Process5_argcVs5Int32 : $Int32


sil_global private_external [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word
sil_global [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word


sil_global [serialized] @_TZvOs7Process11_unsafeArgvGVs20UnsafeMutablePointerGS0_Vs4Int8__ : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
Expand Down Expand Up @@ -736,7 +736,7 @@ bb4(%19 : @owned $Error):
}


sil private_external [serialized] [ossa] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()
sil [serialized] [ossa] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()


public class A {
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/optimize_never.sil
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public func boo4(c: C) -> Int32
sil_global [serialized] @$ss7ProcessO5_argcs5Int32VvZ : $Int32


sil_global private_external [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word
sil_global [serialized] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word


sil_global [serialized] @$ss7ProcessO11_unsafeArgvSpySpys4Int8VGGvZ : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
Expand Down