Skip to content

IRGen: Actually make use of private linkage #15476

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 4 commits into from
Mar 27, 2018
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
4 changes: 0 additions & 4 deletions include/swift/SIL/FormalLinkage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ enum class FormalLinkage {
/// unique file that is known to define it.
HiddenUnique,

/// This entity is visible in only a single Swift module but does not
/// have a unique file that is known to define it.
HiddenNonUnique,

/// This entity is visible in only a single Swift file. These are by
/// definition unique.
Private,
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "swift/AST/ASTNode.h"
#include "swift/AST/Stmt.h"
#include "swift/Basic/ProfileCounter.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/SILAllocated.h"
#include "llvm/ADT/DenseMap.h"

Expand Down
3 changes: 0 additions & 3 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ bool IRGenerator::tryEnableLazyTypeMetadata(NominalTypeDecl *Nominal) {
// We can't remove metadata for externally visible types.
return false;
case FormalLinkage::HiddenUnique:
case FormalLinkage::HiddenNonUnique:
// In non-whole-module mode, also internal types are visible externally.
if (!SIL.isWholeModule())
return false;
Expand Down Expand Up @@ -1418,7 +1417,6 @@ static SILLinkage getNonUniqueSILLinkage(FormalLinkage linkage,
return (forDefinition ? SILLinkage::Shared : SILLinkage::PublicExternal);

case FormalLinkage::HiddenUnique:
case FormalLinkage::HiddenNonUnique:
return (forDefinition ? SILLinkage::Shared : SILLinkage::HiddenExternal);

case FormalLinkage::Private:
Expand Down Expand Up @@ -1541,7 +1539,6 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
// Resilient classes don't expose field offset symbols.
if (cast<ClassDecl>(varDecl->getDeclContext())->isResilient()) {
assert(linkage != FormalLinkage::PublicNonUnique &&
linkage != FormalLinkage::HiddenNonUnique &&
"Cannot have a resilient class with non-unique linkage");

if (linkage == FormalLinkage::PublicUnique)
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/ExistentialLayout.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/TypeLowering.h"

using namespace swift;
Expand Down Expand Up @@ -635,7 +636,6 @@ MetadataAccessStrategy irgen::getTypeMetadataAccessStrategy(CanType type) {
return MetadataAccessStrategy::PrivateAccessor;

case FormalLinkage::PublicNonUnique:
case FormalLinkage::HiddenNonUnique:
return MetadataAccessStrategy::NonUniqueAccessor;
}
llvm_unreachable("bad formal linkage");
Expand Down
12 changes: 1 addition & 11 deletions lib/SIL/SIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ FormalLinkage swift::getDeclLinkage(const ValueDecl *D) {
if (isa<ClangModuleUnit>(fileContext))
return FormalLinkage::PublicNonUnique;

if (!D->hasAccess()) {
assert(D->getDeclContext()->isLocalContext());
return FormalLinkage::Private;
}

switch (D->getEffectiveAccess()) {
case AccessLevel::Public:
case AccessLevel::Open:
Expand All @@ -57,9 +52,7 @@ FormalLinkage swift::getDeclLinkage(const ValueDecl *D) {
return FormalLinkage::HiddenUnique;
case AccessLevel::FilePrivate:
case AccessLevel::Private:
// Why "hidden" instead of "private"? Because the debugger may need to
// access these symbols.
return FormalLinkage::HiddenUnique;
return FormalLinkage::Private;
}

llvm_unreachable("Unhandled access level in switch.");
Expand All @@ -79,9 +72,6 @@ SILLinkage swift::getSILLinkage(FormalLinkage linkage,
case FormalLinkage::HiddenUnique:
return (forDefinition ? SILLinkage::Hidden : SILLinkage::HiddenExternal);

case FormalLinkage::HiddenNonUnique:
return (forDefinition ? SILLinkage::Shared : SILLinkage::HiddenExternal);

case FormalLinkage::Private:
return SILLinkage::Private;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Decl.h"
#include "swift/Parse/Lexer.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/SILModule.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Intrinsics.h"
Expand Down Expand Up @@ -886,7 +887,6 @@ getEquivalentPGOLinkage(FormalLinkage Linkage) {
return llvm::GlobalValue::ExternalLinkage;

case FormalLinkage::HiddenUnique:
case FormalLinkage::HiddenNonUnique:
case FormalLinkage::Private:
return llvm::GlobalValue::PrivateLinkage;
}
Expand Down
8 changes: 4 additions & 4 deletions test/IRGen/access_control.sil
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ internal struct InternalStruct { var x: Int }
// CHECK: @"$S14access_control14InternalStructVMf" = internal constant

private struct PrivateStruct { var x: Int }
// CHECK: @"$S14access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVMn" = hidden constant
// CHECK: @"$S14access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVMn" = internal constant
// CHECK: @"$S14access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVMf" = internal constant

func local() {
struct LocalStruct { var x: Int }
// CHECK: @"$S14access_control5localyyF11LocalStructL_VMn" = hidden constant
// CHECK: @"$S14access_control5localyyF11LocalStructL_VMn" = internal constant
// CHECK: @"$S14access_control5localyyF11LocalStructL_VMf" = internal constant
}

// CHECK: @"$S14access_control12PublicStructVN" = {{(protected )?}}alias
// CHECK: @"$S14access_control14InternalStructVN" = hidden alias
// CHECK: @"$S14access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVN" = hidden alias
// CHECK: @"$S14access_control5localyyF11LocalStructL_VN" = hidden alias
// CHECK: @"$S14access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVN" = internal alias
// CHECK: @"$S14access_control5localyyF11LocalStructL_VN" = internal alias
4 changes: 2 additions & 2 deletions test/IRGen/decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func test1() {
}

// Check that we emit nominal type descriptors for all types.
// CHECK-DAG: @"$S5decls5test1yyF1aL_CMn" = hidden constant
// CHECK-DAG: @"$S5decls5test1yyF1bL_CMn" = hidden constant
// CHECK-DAG: @"$S5decls5test1yyF1aL_CMn" = internal constant
// CHECK-DAG: @"$S5decls5test1yyF1bL_CMn" = internal constant

8 changes: 4 additions & 4 deletions test/IRGen/local_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public func topLevelIfConfig() {
}
#else
public func topLevelIfConfig() {
// CHECK-DAG: @"$S11local_types16topLevelIfConfigyyF17LocalClassEnabledL_CMm" = hidden global %objc_class
// CHECK-DAG: @"$S11local_types16topLevelIfConfigyyF17LocalClassEnabledL_CMm" = internal global %objc_class
class LocalClassEnabled {}
}
#endif
Expand All @@ -62,7 +62,7 @@ public struct NominalIfConfig {
}
#else
public func method() {
// CHECK-DAG: @"$S11local_types15NominalIfConfigV6methodyyF17LocalClassEnabledL_CMm" = hidden global %objc_class
// CHECK-DAG: @"$S11local_types15NominalIfConfigV6methodyyF17LocalClassEnabledL_CMm" = internal global %objc_class
class LocalClassEnabled {}
}
#endif
Expand All @@ -75,10 +75,10 @@ public func innerIfConfig() {
class LocalClassDisabled {}
}
#else
// CHECK-DAG: @"$S11local_types13innerIfConfigyyF17LocalClassEnabledL_CMm" = hidden global %objc_class
// CHECK-DAG: @"$S11local_types13innerIfConfigyyF17LocalClassEnabledL_CMm" = internal global %objc_class
class LocalClassEnabled {}
func inner() {
// CHECK-DAG: @"$S11local_types13innerIfConfigyyF0C0L0_yyF17LocalClassEnabledL_CMm" = hidden global %objc_class
// CHECK-DAG: @"$S11local_types13innerIfConfigyyF0C0L0_yyF17LocalClassEnabledL_CMm" = internal global %objc_class
class LocalClassEnabled {}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/nested_private_type_context_descriptor.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-swift-frontend -emit-ir -O -wmo %s | %FileCheck %s

// CHECK-DAG: @"$S38nested_private_type_context_descriptor1X33{{.................................}}LLVMn" = hidden constant
// CHECK-DAG: @"$S38nested_private_type_context_descriptor1X33{{.................................}}LLV1YVMn" = hidden constant
// CHECK-DAG: @"$S38nested_private_type_context_descriptor1X33{{.................................}}LLVMn" = internal constant
// CHECK-DAG: @"$S38nested_private_type_context_descriptor1X33{{.................................}}LLV1YVMn" = internal constant

fileprivate struct X {
fileprivate struct Y {}
Expand Down