mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -16,8 +16,8 @@
|
|||||||
namespace swift {
|
namespace swift {
|
||||||
|
|
||||||
class CanType;
|
class CanType;
|
||||||
class Decl;
|
|
||||||
class ProtocolConformance;
|
class ProtocolConformance;
|
||||||
|
class ValueDecl;
|
||||||
enum class SILLinkage : unsigned char;
|
enum class SILLinkage : unsigned char;
|
||||||
enum ForDefinition_t : bool;
|
enum ForDefinition_t : bool;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ inline FormalLinkage &operator^=(FormalLinkage &lhs, FormalLinkage rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormalLinkage getTypeLinkage(CanType type);
|
FormalLinkage getTypeLinkage(CanType type);
|
||||||
FormalLinkage getDeclLinkage(Decl *decl);
|
FormalLinkage getDeclLinkage(const ValueDecl *decl);
|
||||||
SILLinkage getSILLinkage(FormalLinkage linkage,
|
SILLinkage getSILLinkage(FormalLinkage linkage,
|
||||||
ForDefinition_t forDefinition);
|
ForDefinition_t forDefinition);
|
||||||
|
|
||||||
|
|||||||
@@ -419,6 +419,7 @@ VarDecl *Module::getDSOHandle() {
|
|||||||
DSOHandle->setImplicit(true);
|
DSOHandle->setImplicit(true);
|
||||||
DSOHandle->getAttrs().add(
|
DSOHandle->getAttrs().add(
|
||||||
new (Ctx) AsmnameAttr("__dso_handle", /*Implicit=*/true));
|
new (Ctx) AsmnameAttr("__dso_handle", /*Implicit=*/true));
|
||||||
|
DSOHandle->setAccessibility(Accessibility::Internal);
|
||||||
return DSOHandle;
|
return DSOHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1887,6 +1887,7 @@ ClassDecl *IRGenModule::getSwiftRootClass() {
|
|||||||
SwiftRootClass->getAttrs().add(ObjCAttr::createNullary(Context, name,
|
SwiftRootClass->getAttrs().add(ObjCAttr::createNullary(Context, name,
|
||||||
/*implicit=*/true));
|
/*implicit=*/true));
|
||||||
SwiftRootClass->setImplicit();
|
SwiftRootClass->setImplicit();
|
||||||
|
SwiftRootClass->setAccessibility(Accessibility::Public);
|
||||||
return SwiftRootClass;
|
return SwiftRootClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ getGenericClauseLinkage(ArrayRef<GenericTypeParamDecl *> params) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
FormalLinkage swift::getDeclLinkage(Decl *D) {
|
FormalLinkage swift::getDeclLinkage(const ValueDecl *D) {
|
||||||
DeclContext *DC = D->getDeclContext();
|
DeclContext *DC = D->getDeclContext();
|
||||||
while (!DC->isModuleScopeContext()) {
|
while (!DC->isModuleScopeContext()) {
|
||||||
if (DC->isLocalContext())
|
if (DC->isLocalContext())
|
||||||
@@ -75,8 +75,19 @@ FormalLinkage swift::getDeclLinkage(Decl *D) {
|
|||||||
if (isa<ClangModuleUnit>(DC))
|
if (isa<ClangModuleUnit>(DC))
|
||||||
return FormalLinkage::PublicNonUnique;
|
return FormalLinkage::PublicNonUnique;
|
||||||
|
|
||||||
// TODO: access control
|
switch (D->getAccessibility()) {
|
||||||
return FormalLinkage::PublicUnique;
|
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) {
|
FormalLinkage swift::getTypeLinkage(CanType type) {
|
||||||
|
|||||||
19
test/IRGen/access_control.sil
Normal file
19
test/IRGen/access_control.sil
Normal 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
|
||||||
Reference in New Issue
Block a user