Treat private type declarations as "hidden" in SIL (rather than public).

Easy cut down on exported symbols. Unless a private type is referenced in
an inlineable function, there's no way to generate a reference to it
outside of the current file, except in the debugger. (That last bit is why
we can't use fully private linkage, which would keep the symbol out of the
symbol table completely.)

We should be doing this for "internal" declarations as well, but the
standard library /does/ have references to internal types in inlineable
functions, and also has tests that directly access these types.

Swift SVN r24838
This commit is contained in:
Jordan Rose
2015-01-30 03:54:04 +00:00
parent fc847e5686
commit 014fd87928
5 changed files with 37 additions and 5 deletions

View File

@@ -16,8 +16,8 @@
namespace swift {
class CanType;
class Decl;
class ProtocolConformance;
class ValueDecl;
enum class SILLinkage : unsigned char;
enum ForDefinition_t : bool;
@@ -88,7 +88,7 @@ inline FormalLinkage &operator^=(FormalLinkage &lhs, FormalLinkage rhs) {
}
FormalLinkage getTypeLinkage(CanType type);
FormalLinkage getDeclLinkage(Decl *decl);
FormalLinkage getDeclLinkage(const ValueDecl *decl);
SILLinkage getSILLinkage(FormalLinkage linkage,
ForDefinition_t forDefinition);

View File

@@ -419,6 +419,7 @@ VarDecl *Module::getDSOHandle() {
DSOHandle->setImplicit(true);
DSOHandle->getAttrs().add(
new (Ctx) AsmnameAttr("__dso_handle", /*Implicit=*/true));
DSOHandle->setAccessibility(Accessibility::Internal);
return DSOHandle;
}

View File

@@ -1887,6 +1887,7 @@ ClassDecl *IRGenModule::getSwiftRootClass() {
SwiftRootClass->getAttrs().add(ObjCAttr::createNullary(Context, name,
/*implicit=*/true));
SwiftRootClass->setImplicit();
SwiftRootClass->setAccessibility(Accessibility::Public);
return SwiftRootClass;
}

View File

@@ -62,7 +62,7 @@ getGenericClauseLinkage(ArrayRef<GenericTypeParamDecl *> params) {
return result;
}
FormalLinkage swift::getDeclLinkage(Decl *D) {
FormalLinkage swift::getDeclLinkage(const ValueDecl *D) {
DeclContext *DC = D->getDeclContext();
while (!DC->isModuleScopeContext()) {
if (DC->isLocalContext())
@@ -75,8 +75,19 @@ FormalLinkage swift::getDeclLinkage(Decl *D) {
if (isa<ClangModuleUnit>(DC))
return FormalLinkage::PublicNonUnique;
// TODO: access control
return FormalLinkage::PublicUnique;
switch (D->getAccessibility()) {
case Accessibility::Public:
return FormalLinkage::PublicUnique;
case Accessibility::Internal:
// FIXME: This ought to be "hidden" as well, but that causes problems when
// inlining code from the standard library, which may reference internal
// declarations.
return FormalLinkage::PublicUnique;
case Accessibility::Private:
// Why "hidden" instead of "private"? Because the debugger may need to
// access these symbols.
return FormalLinkage::HiddenUnique;
}
}
FormalLinkage swift::getTypeLinkage(CanType type) {

View File

@@ -0,0 +1,19 @@
// RUN: %target-swift-frontend -emit-ir %s | FileCheck %s
import Builtin
import Swift
public struct PublicStruct { var x: Int }
// CHECK: @_TWVV14access_control12PublicStruct = constant
// CHECK: @_TMnV14access_control12PublicStruct = constant
// CHECK: @_TMdV14access_control12PublicStruct = constant
internal struct InternalStruct { var x: Int }
// CHECK: @_TWVV14access_control14InternalStruct = constant
// CHECK: @_TMnV14access_control14InternalStruct = constant
// CHECK: @_TMdV14access_control14InternalStruct = constant
private struct PrivateStruct { var x: Int }
// CHECK: @_TWVV14access_controlP33_8F630B0A1EEF3ED34B761E3ED76C95A813PrivateStruct = hidden constant
// CHECK: @_TMnV14access_controlP33_8F630B0A1EEF3ED34B761E3ED76C95A813PrivateStruct = hidden constant
// CHECK: @_TMdV14access_controlP33_8F630B0A1EEF3ED34B761E3ED76C95A813PrivateStruct = hidden constant